### 7.6.5. Access to Nodal Variables within an Element

The following is an example of how to retrieve the nodes of an element and obtain the nodal values, using a user subroutine EXEDIT. The example calculates and stores the average z-coordinate of an element as the average z-location of its nodes.

The local variable arrays RVL and IVL are used for the storage of element variables as well as nodal variables. This routine highlights that a call to get_node_var in the internal loop over the eight nodes of the element overwrites/replaces the element values in the RVL array by nodal values. In order to store the time and average element z-location a new call to get_element_var is required first to retrieve the element variables in the RVL array again before a call to put_elem_var can store the new values in permanent element storage.

          SUBROUTINE EXEDIT3

          USE kindef
          USE wrapup
          USE mdpart
          USE mdvar_all
          USE cycvar
          USE mdgrid3
          USE mdsolv
          USE cycvar
          USE mdstring

          IMPLICIT NONE

          ! ************************************************************************

          ! THIS IS A USER SUPPLIED SUBROUTINE WHICH CAN BE USED TO PROVIDE
          ! SPECIAL CUSTOM EDITING. THE FREQUENCY AT WHICH THIS SUBROUTINE
          ! IS CALLED IS DEFINED THROUGH INPUT (GLOBAL-EDIT-USER). WHEN
          ! REQUESTED, IT IS CALLED BY THE EDIT PROCESSOR AT THE END OF A
          ! COMPUTATIONAL CYCLE. THE ROUTINE IS CALLED BEFORE ANY OTHER
          ! TYPES OF STANDARD EDITS ARE CALLED FOR THAT CYCLE (EG. PRINT,
          ! SAVE, HISTORY, DISPLAY, ETC), SO IT MAY ALSO BE USED TO SET UP
          ! DATA TO BE PROCESSED BY OTHER EDIT TYPES.

          ! ************************************************************************

          INTEGER (INT4) :: NP, NE, NENUM, INTPOI, ELTYPE, I
          INTEGER (INT4), DIMENSION(8) :: NODENM
          REAL (REAL8), DIMENSION(8) :: NODE_Z_VALUE
          REAL (REAL8) :: ELEMENT_Z_VALUE

            DO NP = 1, NUM_PARTS
              DO NE = 1, PARTS(NP)%P%NUMELM
                NENUM = PARTS(NP)%P%ELEMENT_LIST(NE)
                INTPOI = 0
                CALL GET_ELEM_VAR(NENUM,INTPOI)
                ELTYPE = DATA_STR(NSTRING)%P%OPT(EL_SOPT_ELEMTYPE)
                if(ELTYPE == ELTYPE_HEX8) then
                  NODENM(1) = IVL(IVI_CON1)
                  NODENM(2) = IVL(IVI_CON2)
                  NODENM(3) = IVL(IVI_CON3)
                  NODENM(4) = IVL(IVI_CON4)
                  NODENM(5) = IVL(IVI_CON5)
                  NODENM(6) = IVL(IVI_CON6)
                  NODENM(7) = IVL(IVI_CON7)
                  NODENM(8) = IVL(IVI_CON8)
                  DO I=1,8
                    CALL GET_NODE_VAR(NODENM(I),0)
                    NODE_Z_VALUE(I) = RVL(IVR_Z)
                  END DO
                  ELEMENT_Z_VALUE = SUM(NODE_Z_VALUE)/8.0
                  CALL GET_ELEM_VAR(NENUM,INTPOI)
                  RVL(IVR_VAR01) = TIME
                  RVL(IVR_VAR02) = ELEMENT_Z_VALUE
                end if
                CALL PUT_ELEM_VAR(NENUM,INTPOI)
              END DO
            END DO

          RETURN

          END SUBROUTINE EXEDIT3

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