From 410d60ab9cd7997511fb56cd1fa68ff28ec83961 Mon Sep 17 00:00:00 2001 From: shenw Date: Mon, 22 Jun 2026 22:14:39 +0800 Subject: [PATCH] Add quadratic solid linear stiffness support --- src/element/fem_element_stiffness.f90 | 2 +- tests/module/test_element_stiffness.f90 | 149 ++++++++++++++++++++++-- 2 files changed, 141 insertions(+), 10 deletions(-) diff --git a/src/element/fem_element_stiffness.f90 b/src/element/fem_element_stiffness.f90 index 8556b5e..93b18f0 100644 --- a/src/element/fem_element_stiffness.f90 +++ b/src/element/fem_element_stiffness.f90 @@ -36,7 +36,7 @@ contains etype = adjustl(elem_type(elem)) select case (trim(etype)) - case ('C3D4', 'C3D8') + case ('C3D4', 'C3D8', 'C3D10', 'C3D20') call solid_linear_stiffness(elem, elem_dofs, n_elem_dof, ke, ierr) case default call error_set(FEM_ERR_MESH, 'linear stiffness element type is not implemented', ierr) diff --git a/tests/module/test_element_stiffness.f90 b/tests/module/test_element_stiffness.f90 index df6af30..8d1100d 100644 --- a/tests/module/test_element_stiffness.f90 +++ b/tests/module/test_element_stiffness.f90 @@ -10,6 +10,8 @@ program test_element_stiffness call check_c3d4_stiff() call check_c3d8_stiff() + call check_c3d10_stiff() + call check_c3d20_stiff() call check_bad_stiff_type() contains @@ -60,32 +62,78 @@ contains 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_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(10, 1, 0, 0, 0, 0, 1, 0, 0, & + 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(40) - call fill_node_ids(10) + if (ierr .ne. FEM_SUCCESS) call fail(70) + call fill_node_ids(4) elem_id_ext(1) = 1 - elem_type(1) = 'C3D10' - elem_nnode(1) = 10 + elem_type(1) = 'S4' + elem_nnode(1) = 4 elem_conn(:,1) = 0 - elem_conn(1:10,1) = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /) + 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(41) + 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(42) + if (ierr .eq. FEM_SUCCESS) call fail(72) call database_finalize(ierr) - if (ierr .ne. FEM_SUCCESS) call fail(43) + if (ierr .ne. FEM_SUCCESS) call fail(73) end subroutine check_bad_stiff_type subroutine setup_c3d4(ierr) @@ -142,6 +190,78 @@ contains 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 fill_node_ids(count) integer, intent(in) :: count integer :: i @@ -153,6 +273,17 @@ contains 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