### 7.6.3. Access to All Elements in a Component

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

          USE mdpart
          USE mdvar_all
          USE mdsolv
          USE mdcomponents
          USE mdgrid3

          IMPLICIT NONE

          INTEGER(INT4) :: NPART, NEL, NINST, N, NN, NNN
          INTEGER(INT4) :: I, J, K, IJK

          DO N = 1, NUM_COMPONENTS
            COMP => COMPONENTS(N)%P
            IF (COMP%NAME/='Solid') CYCLE

            DO NN = 1, COMP%NUM_PART
              NPART = COMP%PART_LIST(NN)

              IF (NPART>NUMSUB) THEN
                ! UNSTRUCTURED PART
                NPART = NPART-NUMSUB
                PART => PARTS(NPART)%P

                ! LOOP OVER ELEMENTS IN PART
                DO NNN = 1, PART%NUMELM
                  NEL = PART%ELEMENT_LIST(NNN) ! OBTAIN GLOBAL INTERNAL INDEX IF ELEMENT

                  ! 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)

                END DO ! END LOOP ON ELEMENTS
              ELSE
                ! STRUCTURED (IJK) PART
                NSUB = NPART
                CALL GETSUB3

                ! LOOP OVER ELEMENTS IN PART
                DO I = 1, IMAX
                  DO J = 1, JMAX
                    DO K = 1, KMAX
                      IJK = IJKSET3(I,J,K)
                      IF (ASSOCIATED(VAR01)) THEN
                        VAR01(IJK) = DEN(IJK)*SSPD(IJK)
                      END IF
                    END DO
                  END DO
                END DO
              END IF
            END DO ! END LOOP ON PARTS
          END DO ! END LOOP ON COMPONENTS

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