program test_shell_internal use fem_precision use fem_error use fem_database use fem_element_internal implicit none real(rk), parameter :: TOL = 1.0e-10_rk real(rk), parameter :: YOUNG = 30.0_rk real(rk), parameter :: POISSON = 0.25_rk real(rk), parameter :: THICKNESS = 0.2_rk real(rk), parameter :: EXX = 0.01_rk real(rk), parameter :: GAMMA_XZ = 0.02_rk call check_s3_membrane_patch() call check_s4_membrane_patch() call check_s6_membrane_patch() call check_s8_membrane_patch() call check_shear_patch('S3', 1, 200) call check_shear_patch('S4', 4, 230) call check_shear_patch('S6', 3, 260) call check_shear_patch('S8', 9, 290) contains subroutine check_s3_membrane_patch() integer :: ierr call setup_s3(ierr) if (ierr .ne. FEM_SUCCESS) call fail(1) call apply_x_extension(EXX) call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) if (elem_status(1) .ne. 0) call fail(3) call check_state_shape(1, 4) call check_membrane_state(1, 10) call check_force_balance(20) call check_no_normal_or_rotation(30) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(40) end subroutine check_s3_membrane_patch subroutine check_s4_membrane_patch() integer :: ierr call setup_s4(ierr) if (ierr .ne. FEM_SUCCESS) call fail(151) call apply_x_extension(EXX) call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(152) if (elem_status(1) .ne. 0) call fail(153) call check_state_shape(4, 154) call check_membrane_state(4, 160) call check_force_balance(170) call check_no_normal_or_rotation(180) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(190) end subroutine check_s4_membrane_patch subroutine check_s6_membrane_patch() integer :: ierr call setup_s6(ierr) if (ierr .ne. FEM_SUCCESS) call fail(51) call apply_x_extension(EXX) call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(52) if (elem_status(1) .ne. 0) call fail(53) call check_state_shape(3, 54) call check_membrane_state(3, 60) call check_force_balance(70) call check_no_normal_or_rotation(80) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(90) end subroutine check_s6_membrane_patch subroutine check_s8_membrane_patch() integer :: ierr call setup_s8(ierr) if (ierr .ne. FEM_SUCCESS) call fail(101) call apply_x_extension(EXX) call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(102) if (elem_status(1) .ne. 0) call fail(103) call check_state_shape(9, 104) call check_membrane_state(9, 110) call check_force_balance(120) call check_no_normal_or_rotation(130) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(140) end subroutine check_s8_membrane_patch subroutine check_shear_patch(etype, expected_ngp, code) character(len=*), intent(in) :: etype integer, intent(in) :: expected_ngp integer, intent(in) :: code integer :: ierr call setup_shell_by_type(etype, ierr) if (ierr .ne. FEM_SUCCESS) call fail(code) call apply_xz_shear(GAMMA_XZ) call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(code + 1) if (elem_status(1) .ne. 0) call fail(code + 2) call check_state_shape(expected_ngp, code + 3) call check_shear_state(expected_ngp, code + 10) call check_translational_balance(code + 20) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(code + 21) end subroutine check_shear_patch subroutine setup_shell_by_type(etype, ierr) character(len=*), intent(in) :: etype integer, intent(out) :: ierr character(len=ELEM_TYPE_LEN) :: local_type local_type = adjustl(etype) select case (trim(local_type)) case ('S3') call setup_s3(ierr) case ('S4') call setup_s4(ierr) case ('S6') call setup_s6(ierr) case ('S8') call setup_s8(ierr) case default call fail(900) end select end subroutine setup_shell_by_type subroutine setup_s3(ierr) integer, intent(out) :: ierr call database_allocate_model(3, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1) = 1 node_id_ext(2) = 2 node_id_ext(3) = 3 coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) coord = coord0 elem_id_ext(1) = 1 elem_type(1) = 'S3' elem_nnode(1) = 3 elem_conn(:,1) = 0 elem_conn(1:3,1) = (/ 1, 2, 3 /) elem_mat(1) = 1 elem_sec(1) = 1 elset_name(1) = 'EALL' elset_start(1) = 1 elset_count(1) = 1 elset_items(1) = 1 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = YOUNG mat_nu(1) = POISSON section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = THICKNESS call database_assign_dofs(ierr) end subroutine setup_s3 subroutine setup_s4(ierr) integer, intent(out) :: ierr call database_allocate_model(4, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1) = 1 node_id_ext(2) = 2 node_id_ext(3) = 3 node_id_ext(4) = 4 coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord = coord0 elem_id_ext(1) = 1 elem_type(1) = 'S4' elem_nnode(1) = 4 elem_conn(:,1) = 0 elem_conn(1:4,1) = (/ 1, 2, 3, 4 /) elem_mat(1) = 1 elem_sec(1) = 1 elset_name(1) = 'EALL' elset_start(1) = 1 elset_count(1) = 1 elset_items(1) = 1 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = YOUNG mat_nu(1) = POISSON section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = THICKNESS call database_assign_dofs(ierr) end subroutine setup_s4 subroutine setup_s6(ierr) integer, intent(out) :: ierr call database_allocate_model(6, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1) = 1 node_id_ext(2) = 2 node_id_ext(3) = 3 node_id_ext(4) = 4 node_id_ext(5) = 5 node_id_ext(6) = 6 coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) coord0(:,4) = HALF * (coord0(:,1) + coord0(:,2)) coord0(:,5) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,6) = HALF * (coord0(:,3) + coord0(:,1)) coord = coord0 elem_id_ext(1) = 1 elem_type(1) = 'S6' elem_nnode(1) = 6 elem_conn(:,1) = 0 elem_conn(1:6,1) = (/ 1, 2, 3, 4, 5, 6 /) elem_mat(1) = 1 elem_sec(1) = 1 elset_name(1) = 'EALL' elset_start(1) = 1 elset_count(1) = 1 elset_items(1) = 1 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = YOUNG mat_nu(1) = POISSON section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = THICKNESS call database_assign_dofs(ierr) end subroutine setup_s6 subroutine setup_s8(ierr) integer, intent(out) :: ierr call database_allocate_model(8, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return node_id_ext(1) = 1 node_id_ext(2) = 2 node_id_ext(3) = 3 node_id_ext(4) = 4 node_id_ext(5) = 5 node_id_ext(6) = 6 node_id_ext(7) = 7 node_id_ext(8) = 8 coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord0(:,5) = HALF * (coord0(:,1) + coord0(:,2)) coord0(:,6) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,7) = HALF * (coord0(:,3) + coord0(:,4)) coord0(:,8) = HALF * (coord0(:,4) + coord0(:,1)) coord = coord0 elem_id_ext(1) = 1 elem_type(1) = 'S8' elem_nnode(1) = 8 elem_conn(:,1) = 0 elem_conn(1:8,1) = (/ 1, 2, 3, 4, 5, 6, 7, 8 /) elem_mat(1) = 1 elem_sec(1) = 1 elset_name(1) = 'EALL' elset_start(1) = 1 elset_count(1) = 1 elset_items(1) = 1 mat_name(1) = 'MAT' mat_density(1) = ONE mat_e(1) = YOUNG mat_nu(1) = POISSON section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = THICKNESS call database_assign_dofs(ierr) end subroutine setup_s8 subroutine apply_x_extension(exx) real(rk), intent(in) :: exx integer :: node u = ZERO do node = 1, nnode u(dof_id(1,node)) = exx * coord0(1,node) end do end subroutine apply_x_extension subroutine apply_xz_shear(gamma_xz) real(rk), intent(in) :: gamma_xz integer :: node u = ZERO do node = 1, nnode u(dof_id(3,node)) = gamma_xz * coord0(1,node) end do end subroutine apply_xz_shear subroutine check_state_shape(expected_ngp, code) integer, intent(in) :: expected_ngp integer, intent(in) :: code if (elem_gp_start(1) .ne. 1) call fail(code) if (elem_ngp(1) .ne. expected_ngp) call fail(code + 1) if (ngauss_total .ne. expected_ngp) call fail(code + 2) if (.not. allocated(stress)) call fail(code + 3) if (.not. allocated(strain)) call fail(code + 4) end subroutine check_state_shape subroutine check_membrane_state(npoint, code) integer, intent(in) :: npoint integer, intent(in) :: code real(rk) :: coeff real(rk) :: expected_stress(NSTRESS) real(rk) :: expected_strain(NSTRESS) integer :: gp coeff = YOUNG / (ONE - POISSON * POISSON) expected_strain = ZERO expected_strain(1) = EXX expected_stress = ZERO expected_stress(1) = coeff * EXX expected_stress(2) = coeff * POISSON * EXX do gp = 1, npoint call check_vector_close(strain(:,gp), expected_strain, code) call check_vector_close(stress(:,gp), expected_stress, code + 1) if (abs(statev(10,gp)) .gt. TOL) call fail(code + 2) if (abs(statev(11,gp)) .gt. TOL) call fail(code + 3) if (abs(statev(12,gp)) .gt. TOL) call fail(code + 4) end do end subroutine check_membrane_state subroutine check_shear_state(npoint, code) integer, intent(in) :: npoint integer, intent(in) :: code real(rk) :: shear_mod real(rk) :: expected_stress(NSTRESS) real(rk) :: expected_strain(NSTRESS) integer :: gp shear_mod = YOUNG / (2.0_rk * (ONE + POISSON)) expected_strain = ZERO expected_strain(5) = GAMMA_XZ expected_stress = ZERO expected_stress(5) = (5.0_rk / 6.0_rk) * shear_mod * GAMMA_XZ do gp = 1, npoint call check_vector_close(strain(:,gp), expected_strain, code) call check_vector_close(stress(:,gp), expected_stress, code + 1) if (abs(statev(10,gp)) .gt. TOL) call fail(code + 2) if (abs(statev(11,gp)) .gt. TOL) call fail(code + 3) if (abs(statev(12,gp)) .gt. TOL) call fail(code + 4) end do end subroutine check_shear_state subroutine check_force_balance(code) integer, intent(in) :: code real(rk) :: balance(NDOF_NODE) real(rk) :: max_force integer :: node integer :: idir balance = ZERO max_force = ZERO do node = 1, nnode do idir = 1, NDOF_NODE balance(idir) = balance(idir) + fint(dof_id(idir,node)) max_force = max(max_force, abs(fint(dof_id(idir,node)))) end do end do if (maxval(abs(balance)) .gt. TOL) call fail(code) if (max_force .le. TOL) call fail(code + 1) end subroutine check_force_balance subroutine check_translational_balance(code) integer, intent(in) :: code real(rk) :: balance(NDIM) real(rk) :: max_force integer :: node integer :: idir balance = ZERO max_force = ZERO do node = 1, nnode do idir = 1, NDIM balance(idir) = balance(idir) + fint(dof_id(idir,node)) end do do idir = 1, NDOF_NODE max_force = max(max_force, abs(fint(dof_id(idir,node)))) end do end do if (maxval(abs(balance)) .gt. TOL) call fail(code) if (max_force .le. TOL) call fail(code + 1) end subroutine check_translational_balance subroutine check_no_normal_or_rotation(code) integer, intent(in) :: code integer :: node integer :: idir do node = 1, nnode if (abs(fint(dof_id(3,node))) .gt. TOL) call fail(code) do idir = 4, NDOF_NODE if (abs(fint(dof_id(idir,node))) .gt. TOL) call fail(code + 1) end do end do end subroutine check_no_normal_or_rotation subroutine check_vector_close(actual, expected, code) real(rk), intent(in) :: actual(NSTRESS) real(rk), intent(in) :: expected(NSTRESS) integer, intent(in) :: code integer :: i do i = 1, NSTRESS if (abs(actual(i) - expected(i)) .gt. TOL * max(ONE, abs(expected(i)))) then call fail(code) end if end do end subroutine check_vector_close subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_shell_internal failed:', code stop 1 end subroutine fail end program test_shell_internal