### 7.6.4. Access to All Elements in a Group

The following code loops over all Groups in a model, and for element Group Proj defines and stores the impedance of each element in the group in user variable VAR01. The code works for both Structured and Unstructured Parts/Solvers.

          USE mdvar_all
          USE mdsolv
          USE mdgrid3
          USE mdgroups

          IMPLICIT NONE

          INTEGER(INT4) ::  NEL, NINST, N, NN
          INTEGER(INT4) :: I, J, K, IJK, IJKS, M

          DO N = 1, NUM_GROUPS
            GRP => GROUPS(N)%P
            IF (GRP%NAME/='Proj') CYCLE

            ! SKIP ALL BUT ELEMENT GROUPS (OPTIONS: GRPTYP_NODE, GRPTYP_ELEM, GRPTYP_FACE)
            IF (GRP%GRPTYP/=GRPTYP_ELEM) CYCLE

            ! LOOP OVER ELEMENTS IN GROUP
            DO NN = 1, GRP%GRP_SIZE

              ! CHECK IF ELEMENT IS FROM STRUCTURED OR UNSTRUCTURED SOLVER
              IF (GRP%IJKS_LIST(NN)>IJKBAS(NUMSUB+1)) THEN
                ! GET UNSTRUCTURED ELEMENT INDEX
                NEL = GRP%IJKS_LIST(NN) - IJKBAS(NUMSUB+1)

                ! COPY ELEMENT VARIABLES INTO LOCAL VARIABLE VECTOR
                NINST = 0
                CALL GET_ELEM_VAR(NEL,NINST)

                ! CALCULATE IMPEDANCE
                RVL(IVR_VAR01) = RVL(IVR_DENSITY)*RVL(IVR_SOUNDSPEED)

                ! COPY UPDATED LOCAL ELEMENT DATA BACK TO MAIN STORAGE
                CALL PUT_ELEM_VAR(NEL,NINST)

              ELSE
                ! GET STRUCTURED IJK INDEX
                IJKS = GRP%IJKS_LIST(NN)
                CALL IJANDKS3 (IJKS,I,J,K,M)
                NSUB = M
                CALL GETSUB3
                IJK = IJKSET3(I,J,K)
                IF (ASSOCIATED(VAR01)) THEN
                  VAR01(IJK) = DEN(IJK)*SSPD(IJK)
                END IF

              END IF
            END DO ! END LOOP ON ELEMENTS
         END DO ! END LOOP ON GROUPS

Release 18.2 - © ANSYS, Inc. All rights reserved.