Add lumped mass for shell element family

This commit is contained in:
shenw
2026-06-22 22:37:36 +08:00
parent cd6c6ac4e4
commit fb85739ed3
3 changed files with 270 additions and 4 deletions
+12
View File
@@ -158,6 +158,13 @@ add_executable(test_quadratic_internal
target_link_libraries(test_quadratic_internal PRIVATE femlite_core)
femlite_apply_fortran_options(test_quadratic_internal)
add_executable(test_shell_mass
tests/module/test_shell_mass.f90
)
target_link_libraries(test_shell_mass PRIVATE femlite_core)
femlite_apply_fortran_options(test_shell_mass)
add_executable(test_solver_implicit
tests/module/test_solver_implicit.f90
)
@@ -239,6 +246,11 @@ set_tests_properties(quadratic_internal PROPERTIES
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_test(NAME shell_mass COMMAND test_shell_mass)
set_tests_properties(shell_mass PROPERTIES
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_test(NAME solver_implicit COMMAND test_solver_implicit)
set_tests_properties(solver_implicit PROPERTIES
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+59 -4
View File
@@ -68,17 +68,18 @@ contains
nodal_mass = elem_mass / real(nlocal, rk)
call add_translational_mass(elem, nodal_mass)
case ('S4')
case ('S3', 'S4', 'S6', 'S8')
call element_validate_node_count(etype, nlocal, ierr)
if (ierr .ne. FEM_SUCCESS) return
thickness = section_thickness(sec)
if (thickness .le. ZERO) then
call error_set(FEM_ERR_INPUT, 'S4 section thickness must be positive', ierr)
call error_set(FEM_ERR_INPUT, 'shell section thickness must be positive', ierr)
return
end if
area = shell4_area(elem)
call shell_area_by_quadrature(elem, area, ierr)
if (ierr .ne. FEM_SUCCESS) return
if (area .le. ZERO) then
call error_set(FEM_ERR_MESH, 'S4 element has non-positive area', ierr)
call error_set(FEM_ERR_MESH, 'shell element has non-positive area', ierr)
return
end if
elem_mass = density * area * thickness
@@ -188,6 +189,60 @@ contains
ierr = FEM_SUCCESS
end subroutine solid_volume_by_quadrature
subroutine shell_area_by_quadrature(elem, area, ierr)
integer, intent(in) :: elem
real(rk), intent(out) :: area
integer, intent(out) :: ierr
integer, parameter :: MAX_QP = 16
real(rk) :: xi(NDIM,MAX_QP)
real(rk) :: weight(MAX_QP)
real(rk) :: nshape(MAX_NEN)
real(rk) :: dndr(NDIM,MAX_NEN)
real(rk) :: tangent1(NDIM)
real(rk) :: tangent2(NDIM)
real(rk) :: normal(NDIM)
real(rk) :: jac_area
character(len=ELEM_TYPE_LEN) :: etype
integer :: gp
integer :: npoint
integer :: node
integer :: local_node
etype = adjustl(elem_type(elem))
call quadrature_get_rule(etype, MAX_QP, npoint, xi, weight, ierr)
if (ierr .ne. FEM_SUCCESS) return
area = ZERO
do gp = 1, npoint
call shape_evaluate(etype, xi(:,gp), nshape, dndr, ierr)
if (ierr .ne. FEM_SUCCESS) return
tangent1 = ZERO
tangent2 = ZERO
do local_node = 1, elem_nnode(elem)
node = elem_conn(local_node, elem)
tangent1 = tangent1 + coord0(:,node) * dndr(1,local_node)
tangent2 = tangent2 + coord0(:,node) * dndr(2,local_node)
end do
call cross3(tangent1, tangent2, normal)
jac_area = sqrt(sum(normal * normal))
if (jac_area .le. ZERO) then
call error_set(FEM_ERR_MESH, 'shell element has non-positive surface Jacobian', ierr)
return
end if
area = area + jac_area * weight(gp)
end do
if (area .le. ZERO) then
call error_set(FEM_ERR_MESH, 'shell element has non-positive area', ierr)
return
end if
ierr = FEM_SUCCESS
end subroutine shell_area_by_quadrature
real(rk) function shell4_area(elem)
integer, intent(in) :: elem
real(rk) :: a(NDIM)
+199
View File
@@ -0,0 +1,199 @@
program test_shell_mass
use fem_precision
use fem_error
use fem_database
use fem_element_mass
implicit none
real(rk), parameter :: TOL = 1.0e-10_rk
real(rk), parameter :: DENSITY = 12.0_rk
real(rk), parameter :: THICKNESS = 0.5_rk
call check_shell('S3', 3, HALF, 10)
call check_shell('S4', 4, ONE, 30)
call check_shell('S6', 6, HALF, 50)
call check_shell('S8', 8, ONE, 70)
contains
subroutine check_shell(etype, nlocal, expected_area, code)
character(len=*), intent(in) :: etype
integer, intent(in) :: nlocal
real(rk), intent(in) :: expected_area
integer, intent(in) :: code
integer :: ierr
real(rk) :: elem_mass
real(rk) :: nodal_mass
real(rk) :: rot_inertia
real(rk) :: nodal_inertia
real(rk) :: mass_x
real(rk) :: mass_y
real(rk) :: mass_z
real(rk) :: rot_x
real(rk) :: rot_y
real(rk) :: rot_z
call setup_shell(etype, nlocal, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code)
call element_compute_lumped_mass(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 1)
elem_mass = DENSITY * expected_area * THICKNESS
nodal_mass = elem_mass / real(nlocal, rk)
rot_inertia = DENSITY * expected_area * THICKNESS**3 / 12.0_rk
nodal_inertia = rot_inertia / real(nlocal, rk)
call collect_directional_mass(mass_x, mass_y, mass_z, rot_x, rot_y, rot_z)
call check_close(mass_x, elem_mass, code + 2)
call check_close(mass_y, elem_mass, code + 3)
call check_close(mass_z, elem_mass, code + 4)
call check_close(rot_x, rot_inertia, code + 5)
call check_close(rot_y, rot_inertia, code + 6)
call check_close(rot_z, rot_inertia, code + 7)
call check_close(mass_diag(dof_id(1,1)), nodal_mass, code + 8)
call check_close(mass_diag(dof_id(4,1)), nodal_inertia, code + 9)
call check_close(mass_diag(dof_id(3,nlocal)), nodal_mass, code + 10)
call check_close(mass_diag(dof_id(6,nlocal)), nodal_inertia, code + 11)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 12)
end subroutine check_shell
subroutine setup_shell(etype, nlocal, ierr)
character(len=*), intent(in) :: etype
integer, intent(in) :: nlocal
integer, intent(out) :: ierr
call database_allocate_model(nlocal, 1, 0, 1, 0, 1, 1, 0, 1, &
0, 0, 0, 0, 0, ierr)
if (ierr .ne. FEM_SUCCESS) return
call fill_common_model(etype, nlocal)
call fill_shell_coordinates(etype)
coord = coord0
call database_assign_dofs(ierr)
end subroutine setup_shell
subroutine fill_common_model(etype, nlocal)
character(len=*), intent(in) :: etype
integer, intent(in) :: nlocal
integer :: i
do i = 1, nlocal
node_id_ext(i) = i
coord0(:,i) = ZERO
coord(:,i) = ZERO
elem_conn(i,1) = i
end do
elem_id_ext(1) = 1
elem_type(1) = etype
elem_nnode(1) = nlocal
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) = DENSITY
mat_e(1) = ONE
mat_nu(1) = 0.25_rk
section_type(1) = 'SHELL'
section_elset_name(1) = 'EALL'
section_material_name(1) = 'MAT'
section_thickness(1) = THICKNESS
end subroutine fill_common_model
subroutine fill_shell_coordinates(etype)
character(len=*), intent(in) :: etype
character(len=ELEM_TYPE_LEN) :: local_type
local_type = adjustl(etype)
select case (trim(local_type))
case ('S3')
call fill_triangle3()
case ('S4')
call fill_quad4()
case ('S6')
call fill_triangle6()
case ('S8')
call fill_quad8()
case default
call fail(900)
end select
end subroutine fill_shell_coordinates
subroutine fill_triangle3()
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ZERO, ONE, ZERO /)
end subroutine fill_triangle3
subroutine fill_triangle6()
call fill_triangle3()
coord0(:,4) = HALF * (coord0(:,1) + coord0(:,2))
coord0(:,5) = HALF * (coord0(:,2) + coord0(:,3))
coord0(:,6) = HALF * (coord0(:,3) + coord0(:,1))
end subroutine fill_triangle6
subroutine fill_quad4()
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ONE, ONE, ZERO /)
coord0(:,4) = (/ ZERO, ONE, ZERO /)
end subroutine fill_quad4
subroutine fill_quad8()
call fill_quad4()
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))
end subroutine fill_quad8
subroutine collect_directional_mass(mass_x, mass_y, mass_z, rot_x, rot_y, rot_z)
real(rk), intent(out) :: mass_x
real(rk), intent(out) :: mass_y
real(rk), intent(out) :: mass_z
real(rk), intent(out) :: rot_x
real(rk), intent(out) :: rot_y
real(rk), intent(out) :: rot_z
integer :: node
mass_x = ZERO
mass_y = ZERO
mass_z = ZERO
rot_x = ZERO
rot_y = ZERO
rot_z = ZERO
do node = 1, nnode
mass_x = mass_x + mass_diag(dof_id(1,node))
mass_y = mass_y + mass_diag(dof_id(2,node))
mass_z = mass_z + mass_diag(dof_id(3,node))
rot_x = rot_x + mass_diag(dof_id(4,node))
rot_y = rot_y + mass_diag(dof_id(5,node))
rot_z = rot_z + mass_diag(dof_id(6,node))
end do
end subroutine collect_directional_mass
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))) call fail(code)
end subroutine check_close
subroutine fail(code)
integer, intent(in) :: code
write(*,*) 'test_shell_mass failed:', code
stop 1
end subroutine fail
end program test_shell_mass