program test_element_state use fem_precision use fem_error use fem_database use fem_element_state use fem_shell_rotation, only: shell_rotation_ensure, & shell_rotation_begin_trial, shell_rotation_update_trial, & shell_rotation_commit_trial, shell_rotation_restore_trial, & shell_rotation_abort_trial, shell_rotation_get_committed, & shell_rotation_get_trial, shell_rotation_rotate_vector, & shell_rotation_sync_trial implicit none real(rk), parameter :: TOL = 1.0e-10_rk call check_state_map() call check_shell_rotation_state() call check_shell_rotation_dof_sync() call check_rot_increment_sync() call check_unsupported_element() contains subroutine check_state_map() integer :: ierr call database_allocate_model(1, 5, 0, 0, 0, 0, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) call fail(1) mat_plastic_model(1) = 'ELASTIC' section_type(1) = 'SHELL' section_thickness(1) = ONE elem_type(1) = 'C3D4' elem_type(2) = 'C3D8' elem_type(3) = 'S4' elem_type(4) = 'C3D10' elem_type(5) = 'S8' elem_mat = 1 elem_sec = 1 call element_state_ensure(ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) if (.not. element_state_is_available()) call fail(3) if (ngauss_total .ne. 26) call fail(4) if (elem_gp_start(1) .ne. 1) call fail(5) if (elem_gp_start(2) .ne. 2) call fail(6) if (elem_gp_start(3) .ne. 10) call fail(7) if (elem_gp_start(4) .ne. 14) call fail(8) if (elem_gp_start(5) .ne. 18) call fail(9) if (elem_ngp(1) .ne. 1) call fail(10) if (elem_ngp(2) .ne. 8) call fail(11) if (elem_ngp(3) .ne. 4) call fail(12) if (elem_ngp(4) .ne. 4) call fail(13) if (elem_ngp(5) .ne. 9) call fail(14) if (size(stress,2) .ne. 26) call fail(15) if (size(strain,2) .ne. 26) call fail(16) if (size(statev,2) .ne. 26) call fail(17) stress = ONE strain = ONE statev = ONE call element_state_reset_values(ierr) if (ierr .ne. FEM_SUCCESS) call fail(18) if (maxval(abs(stress)) .gt. ZERO) call fail(19) if (maxval(abs(strain)) .gt. ZERO) call fail(20) if (maxval(abs(statev)) .gt. ZERO) call fail(21) call element_state_ensure(ierr) if (ierr .ne. FEM_SUCCESS) call fail(22) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(23) end subroutine check_state_map subroutine check_shell_rotation_state() integer :: ierr real(rk) :: theta real(rk) :: dtheta(NDIM) real(rk) :: q(4) real(rk) :: vec(NDIM) real(rk) :: rotated(NDIM) call database_allocate_mesh(2, 0, ierr) if (ierr .ne. FEM_SUCCESS) call fail(40) call shell_rotation_ensure(ierr) if (ierr .ne. FEM_SUCCESS) call fail(41) if (.not. allocated(shell_rotation_committed)) call fail(42) if (.not. allocated(shell_rotation_trial)) call fail(43) if (size(shell_rotation_committed,2) .ne. 2) call fail(44) call shell_rotation_get_committed(1, q, ierr) if (ierr .ne. FEM_SUCCESS) call fail(45) call check_close(q(1), ONE, 46) call check_close(maxval(abs(q(2:4))), ZERO, 47) theta = HALF * 4.0_rk * atan(ONE) dtheta = ZERO dtheta(3) = theta call shell_rotation_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(48) call shell_rotation_update_trial(1, dtheta, ierr) if (ierr .ne. FEM_SUCCESS) call fail(49) vec = (/ ONE, ZERO, ZERO /) call shell_rotation_rotate_vector(1, vec, rotated, ierr) if (ierr .ne. FEM_SUCCESS) call fail(50) call check_close(rotated(1), ZERO, 51) call check_close(rotated(2), ONE, 52) call check_close(rotated(3), ZERO, 53) call shell_rotation_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(54) call shell_rotation_rotate_vector(1, vec, rotated, ierr, .false.) if (ierr .ne. FEM_SUCCESS) call fail(55) call check_close(rotated(1), ZERO, 56) call check_close(rotated(2), ONE, 57) call shell_rotation_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(58) dtheta = ZERO dtheta(3) = -theta call shell_rotation_update_trial(1, dtheta, ierr) if (ierr .ne. FEM_SUCCESS) call fail(59) call shell_rotation_restore_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(60) call shell_rotation_get_trial(1, q, ierr) if (ierr .ne. FEM_SUCCESS) call fail(61) call shell_rotation_rotate_vector(1, vec, rotated, ierr) if (ierr .ne. FEM_SUCCESS) call fail(62) call check_close(rotated(1), ZERO, 63) call check_close(rotated(2), ONE, 64) dtheta = ZERO dtheta(1) = theta call shell_rotation_update_trial(1, dtheta, ierr) if (ierr .ne. FEM_SUCCESS) call fail(65) call shell_rotation_abort_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(66) call shell_rotation_rotate_vector(1, vec, rotated, ierr, .false.) if (ierr .ne. FEM_SUCCESS) call fail(67) call check_close(rotated(1), ZERO, 68) call check_close(rotated(2), ONE, 69) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(70) end subroutine check_shell_rotation_state subroutine check_shell_rotation_dof_sync() integer :: ierr integer :: node integer :: idir real(rk) :: theta real(rk) :: vec(NDIM) real(rk) :: rotated(NDIM) call database_allocate_basic(2, 0, 12, ierr) if (ierr .ne. FEM_SUCCESS) call fail(80) do node = 1, 2 do idir = 1, 6 dof_id(idir,node) = 6 * (node - 1) + idir end do end do u = ZERO theta = HALF * 4.0_rk * atan(ONE) u(dof_id(6,1)) = 0.20_rk call shell_rotation_ensure(ierr) if (ierr .ne. FEM_SUCCESS) call fail(81) call shell_rotation_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(82) u(dof_id(6,1)) = 0.20_rk + theta call shell_rotation_sync_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(83) vec = (/ ONE, ZERO, ZERO /) call shell_rotation_rotate_vector(1, vec, rotated, ierr) if (ierr .ne. FEM_SUCCESS) call fail(84) call check_close(rotated(1), ZERO, 85) call check_close(rotated(2), ONE, 86) call check_close(rotated(3), ZERO, 87) call shell_rotation_restore_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(88) u(dof_id(6,1)) = 0.20_rk + HALF * theta call shell_rotation_sync_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(89) call shell_rotation_rotate_vector(1, vec, rotated, ierr) if (ierr .ne. FEM_SUCCESS) call fail(90) call check_close(rotated(1), sqrt(HALF), 91) call check_close(rotated(2), sqrt(HALF), 92) call check_close(rotated(3), ZERO, 93) call shell_rotation_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(94) call shell_rotation_rotate_vector(1, vec, rotated, ierr, .false.) if (ierr .ne. FEM_SUCCESS) call fail(95) call check_close(rotated(1), sqrt(HALF), 96) call check_close(rotated(2), sqrt(HALF), 97) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(98) end subroutine check_shell_rotation_dof_sync subroutine check_rot_increment_sync() integer :: ierr integer :: idir real(rk) :: theta real(rk) :: vec(NDIM) real(rk) :: rotated(NDIM) call database_allocate_basic(1, 0, 6, ierr) if (ierr .ne. FEM_SUCCESS) call fail(110) do idir = 1, 6 dof_id(idir,1) = idir end do u = ZERO theta = HALF * 4.0_rk * atan(ONE) call shell_rotation_ensure(ierr) if (ierr .ne. FEM_SUCCESS) call fail(111) call shell_rotation_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(112) u(dof_id(4,1)) = theta call shell_rotation_sync_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(113) u(dof_id(6,1)) = theta call shell_rotation_sync_trial(ierr) if (ierr .ne. FEM_SUCCESS) call fail(114) vec = (/ ZERO, ONE, ZERO /) call shell_rotation_rotate_vector(1, vec, rotated, ierr) if (ierr .ne. FEM_SUCCESS) call fail(115) call check_close(rotated(1), ZERO, 116) call check_close(rotated(2), ZERO, 117) call check_close(rotated(3), ONE, 118) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(119) end subroutine check_rot_increment_sync subroutine check_unsupported_element() integer :: ierr call database_allocate_mesh(1, 1, ierr) if (ierr .ne. FEM_SUCCESS) call fail(30) elem_type(1) = 'B31' call element_state_ensure(ierr) if (ierr .eq. FEM_SUCCESS) call fail(31) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(32) end subroutine check_unsupported_element subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_element_state failed:', code stop 1 end subroutine fail subroutine check_close(actual, expected, code) real(rk), intent(in) :: actual real(rk), intent(in) :: expected integer, intent(in) :: code if (abs(actual - expected) .gt. TOL * max(ONE, abs(expected))) then write(*,'(A,I0,A,ES16.8,A,ES16.8)') & 'test_element_state failed:', code, ' actual=', actual, & ' expected=', expected stop 1 end if end subroutine check_close end program test_element_state