program test_element_stiffness use fem_precision use fem_error use fem_database use fem_element_stiffness implicit none integer, parameter :: MAX_TEST_DOF = 60 real(rk), parameter :: TOL = 1.0e-8_rk call check_c3d4_stiff() call check_c3d8_stiff() call check_c3d10_stiff() call check_c3d20_stiff() call check_s3_stiff() call check_s4_stiff() call check_s6_stiff() call check_s8_stiff() call check_bad_stiff_type() contains subroutine check_c3d4_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_c3d4(ierr) if (ierr .ne. FEM_SUCCESS) call fail(1) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) if (n_elem_dof .ne. 12) call fail(3) if (elem_dofs(1) .ne. 1 .or. elem_dofs(12) .ne. 12) call fail(4) call check_symmetric(ke, n_elem_dof, 5) call check_rigid_translation(ke, n_elem_dof, 1, 6) call check_rigid_translation(ke, n_elem_dof, 2, 7) call check_rigid_translation(ke, n_elem_dof, 3, 8) call check_positive_energy(ke, n_elem_dof, 9) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(10) end subroutine check_c3d4_stiff subroutine check_c3d8_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_c3d8(ierr) if (ierr .ne. FEM_SUCCESS) call fail(20) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(21) if (n_elem_dof .ne. 24) call fail(22) if (elem_dofs(1) .ne. 1 .or. elem_dofs(24) .ne. 24) call fail(23) call check_symmetric(ke, n_elem_dof, 24) call check_rigid_translation(ke, n_elem_dof, 1, 25) call check_rigid_translation(ke, n_elem_dof, 2, 26) call check_rigid_translation(ke, n_elem_dof, 3, 27) call check_positive_energy(ke, n_elem_dof, 28) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(29) end subroutine check_c3d8_stiff subroutine check_c3d10_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_c3d10(ierr) if (ierr .ne. FEM_SUCCESS) call fail(30) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(31) if (n_elem_dof .ne. 30) call fail(32) if (elem_dofs(1) .ne. 1 .or. elem_dofs(30) .ne. 30) call fail(33) call check_symmetric(ke, n_elem_dof, 34) call check_rigid_translation(ke, n_elem_dof, 1, 35) call check_rigid_translation(ke, n_elem_dof, 2, 36) call check_rigid_translation(ke, n_elem_dof, 3, 37) call check_positive_energy(ke, n_elem_dof, 38) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(39) end subroutine check_c3d10_stiff subroutine check_c3d20_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_c3d20(ierr) if (ierr .ne. FEM_SUCCESS) call fail(50) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(51) if (n_elem_dof .ne. 60) call fail(52) if (elem_dofs(1) .ne. 1 .or. elem_dofs(60) .ne. 60) call fail(53) call check_symmetric(ke, n_elem_dof, 54) call check_rigid_translation(ke, n_elem_dof, 1, 55) call check_rigid_translation(ke, n_elem_dof, 2, 56) call check_rigid_translation(ke, n_elem_dof, 3, 57) call check_positive_energy(ke, n_elem_dof, 58) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(59) end subroutine check_c3d20_stiff subroutine check_s3_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_s3(ierr) if (ierr .ne. FEM_SUCCESS) call fail(80) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(81) if (n_elem_dof .ne. 18) call fail(82) if (elem_dofs(1) .ne. 1 .or. elem_dofs(18) .ne. 18) call fail(83) call check_symmetric(ke, n_elem_dof, 84) call check_shell_rigid_translation(ke, n_elem_dof, 1, 85) call check_shell_rigid_translation(ke, n_elem_dof, 2, 86) call check_shell_rigid_translation(ke, n_elem_dof, 3, 87) call check_positive_energy(ke, n_elem_dof, 88) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(89) end subroutine check_s3_stiff subroutine check_s4_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_s4(ierr) if (ierr .ne. FEM_SUCCESS) call fail(60) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(61) if (n_elem_dof .ne. 24) call fail(62) if (elem_dofs(1) .ne. 1 .or. elem_dofs(24) .ne. 24) call fail(63) call check_symmetric(ke, n_elem_dof, 64) call check_shell_rigid_translation(ke, n_elem_dof, 1, 65) call check_shell_rigid_translation(ke, n_elem_dof, 2, 66) call check_shell_rigid_translation(ke, n_elem_dof, 3, 67) call check_positive_energy(ke, n_elem_dof, 68) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(69) end subroutine check_s4_stiff subroutine check_s6_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_s6(ierr) if (ierr .ne. FEM_SUCCESS) call fail(90) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(91) if (n_elem_dof .ne. 36) call fail(92) if (elem_dofs(1) .ne. 1 .or. elem_dofs(36) .ne. 36) call fail(93) call check_symmetric(ke, n_elem_dof, 94) call check_shell_rigid_translation(ke, n_elem_dof, 1, 95) call check_shell_rigid_translation(ke, n_elem_dof, 2, 96) call check_shell_rigid_translation(ke, n_elem_dof, 3, 97) call check_positive_energy(ke, n_elem_dof, 98) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(99) end subroutine check_s6_stiff subroutine check_s8_stiff() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call setup_s8(ierr) if (ierr .ne. FEM_SUCCESS) call fail(100) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .ne. FEM_SUCCESS) call fail(101) if (n_elem_dof .ne. 48) call fail(102) if (elem_dofs(1) .ne. 1 .or. elem_dofs(48) .ne. 48) call fail(103) call check_symmetric(ke, n_elem_dof, 104) call check_shell_rigid_translation(ke, n_elem_dof, 1, 105) call check_shell_rigid_translation(ke, n_elem_dof, 2, 106) call check_shell_rigid_translation(ke, n_elem_dof, 3, 107) call check_positive_energy(ke, n_elem_dof, 108) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(109) end subroutine check_s8_stiff subroutine check_bad_stiff_type() integer :: ierr integer :: elem_dofs(MAX_TEST_DOF) integer :: n_elem_dof real(rk) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) call database_allocate_model(4, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) call fail(70) call fill_node_ids(4) elem_id_ext(1) = 1 elem_type(1) = 'BAD' elem_nnode(1) = 4 elem_conn(:,1) = 0 elem_conn(1:4,1) = (/ 1, 2, 3, 4 /) elem_mat(1) = 1 mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk call database_assign_dofs(ierr) if (ierr .ne. FEM_SUCCESS) call fail(71) call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr) if (ierr .eq. FEM_SUCCESS) call fail(72) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(73) end subroutine check_bad_stiff_type subroutine setup_c3d4(ierr) integer, intent(out) :: ierr call database_allocate_model(4, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_node_ids(4) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) coord0(:,4) = (/ ZERO, ZERO, ONE /) elem_id_ext(1) = 1 elem_type(1) = 'C3D4' elem_nnode(1) = 4 elem_conn(:,1) = 0 elem_conn(1:4,1) = (/ 1, 2, 3, 4 /) elem_mat(1) = 1 mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk call database_assign_dofs(ierr) end subroutine setup_c3d4 subroutine setup_c3d8(ierr) integer, intent(out) :: ierr call database_allocate_model(8, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_node_ids(8) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord0(:,5) = (/ ZERO, ZERO, ONE /) coord0(:,6) = (/ ONE, ZERO, ONE /) coord0(:,7) = (/ ONE, ONE, ONE /) coord0(:,8) = (/ ZERO, ONE, ONE /) elem_id_ext(1) = 1 elem_type(1) = 'C3D8' 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 mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk call database_assign_dofs(ierr) end subroutine setup_c3d8 subroutine setup_c3d10(ierr) integer, intent(out) :: ierr call database_allocate_model(10, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_node_ids(10) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) coord0(:,4) = (/ ZERO, ZERO, ONE /) coord0(:,5) = HALF * (coord0(:,1) + coord0(:,2)) coord0(:,6) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,7) = HALF * (coord0(:,3) + coord0(:,1)) coord0(:,8) = HALF * (coord0(:,1) + coord0(:,4)) coord0(:,9) = HALF * (coord0(:,2) + coord0(:,4)) coord0(:,10) = HALF * (coord0(:,3) + coord0(:,4)) elem_id_ext(1) = 1 elem_type(1) = 'C3D10' elem_nnode(1) = 10 elem_conn(:,1) = 0 elem_conn(1:10,1) = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /) elem_mat(1) = 1 mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk call database_assign_dofs(ierr) end subroutine setup_c3d10 subroutine setup_c3d20(ierr) integer, intent(out) :: ierr call database_allocate_model(20, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_node_ids(20) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) coord0(:,5) = (/ ZERO, ZERO, ONE /) coord0(:,6) = (/ ONE, ZERO, ONE /) coord0(:,7) = (/ ONE, ONE, ONE /) coord0(:,8) = (/ ZERO, ONE, ONE /) coord0(:,9) = HALF * (coord0(:,1) + coord0(:,2)) coord0(:,10) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,11) = HALF * (coord0(:,3) + coord0(:,4)) coord0(:,12) = HALF * (coord0(:,4) + coord0(:,1)) coord0(:,13) = HALF * (coord0(:,5) + coord0(:,6)) coord0(:,14) = HALF * (coord0(:,6) + coord0(:,7)) coord0(:,15) = HALF * (coord0(:,7) + coord0(:,8)) coord0(:,16) = HALF * (coord0(:,8) + coord0(:,5)) coord0(:,17) = HALF * (coord0(:,1) + coord0(:,5)) coord0(:,18) = HALF * (coord0(:,2) + coord0(:,6)) coord0(:,19) = HALF * (coord0(:,3) + coord0(:,7)) coord0(:,20) = HALF * (coord0(:,4) + coord0(:,8)) elem_id_ext(1) = 1 elem_type(1) = 'C3D20' elem_nnode(1) = 20 elem_conn(:,1) = 0 call fill_sequence(elem_conn(:,1), 20) elem_mat(1) = 1 mat_e(1) = 30.0_rk mat_nu(1) = 0.25_rk call database_assign_dofs(ierr) end subroutine setup_c3d20 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 call fill_node_ids(3) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) 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) = 30.0_rk mat_nu(1) = 0.25_rk section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = 0.2_rk 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 call fill_node_ids(4) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ONE, ONE, ZERO /) coord0(:,4) = (/ ZERO, ONE, ZERO /) 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) = 30.0_rk mat_nu(1) = 0.25_rk section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = 0.2_rk 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 call fill_node_ids(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)) 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 /) call fill_shell_common() 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 call fill_node_ids(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)) 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 /) call fill_shell_common() call database_assign_dofs(ierr) end subroutine setup_s8 subroutine fill_shell_common() 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) = 30.0_rk mat_nu(1) = 0.25_rk section_type(1) = 'SHELL' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' section_thickness(1) = 0.2_rk end subroutine fill_shell_common subroutine fill_node_ids(count) integer, intent(in) :: count integer :: i do i = 1, count node_id_ext(i) = i coord0(:,i) = ZERO coord(:,i) = ZERO end do end subroutine fill_node_ids subroutine fill_sequence(values, count) integer, intent(out) :: values(MAX_NEN) integer, intent(in) :: count integer :: i values = 0 do i = 1, count values(i) = i end do end subroutine fill_sequence subroutine check_symmetric(ke, n, code) real(rk), intent(in) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) integer, intent(in) :: n integer, intent(in) :: code integer :: i integer :: j do i = 1, n do j = 1, n if (abs(ke(i,j) - ke(j,i)) .gt. TOL) call fail(code) end do end do end subroutine check_symmetric subroutine check_rigid_translation(ke, n, idir, code) real(rk), intent(in) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) integer, intent(in) :: n integer, intent(in) :: idir integer, intent(in) :: code real(rk) :: x(MAX_TEST_DOF) real(rk) :: y(MAX_TEST_DOF) integer :: i x = ZERO y = ZERO do i = idir, n, NDIM x(i) = ONE end do y(1:n) = matmul(ke(1:n,1:n), x(1:n)) if (maxval(abs(y(1:n))) .gt. TOL) call fail(code) end subroutine check_rigid_translation subroutine check_shell_rigid_translation(ke, n, idir, code) real(rk), intent(in) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) integer, intent(in) :: n integer, intent(in) :: idir integer, intent(in) :: code real(rk) :: x(MAX_TEST_DOF) real(rk) :: y(MAX_TEST_DOF) integer :: local_node integer :: pos x = ZERO y = ZERO do local_node = 1, n / NDOF_NODE pos = NDOF_NODE * (local_node - 1) + idir x(pos) = ONE end do y(1:n) = matmul(ke(1:n,1:n), x(1:n)) if (maxval(abs(y(1:n))) .gt. TOL) call fail(code) end subroutine check_shell_rigid_translation subroutine check_positive_energy(ke, n, code) real(rk), intent(in) :: ke(MAX_TEST_DOF,MAX_TEST_DOF) integer, intent(in) :: n integer, intent(in) :: code real(rk) :: x(MAX_TEST_DOF) real(rk) :: y(MAX_TEST_DOF) x = ZERO y = ZERO x(n) = ONE y(1:n) = matmul(ke(1:n,1:n), x(1:n)) if (dot_product(x(1:n), y(1:n)) .le. TOL) call fail(code) end subroutine check_positive_energy subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_element_stiffness failed:', code stop 1 end subroutine fail end program test_element_stiffness