Files
FemLite/tests/module/test_element_stiffness.f90
T
2026-06-22 21:55:56 +08:00

210 lines
5.9 KiB
Fortran

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_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_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, &
0, 0, 0, 0, 0, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(40)
call fill_node_ids(10)
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)
if (ierr .ne. FEM_SUCCESS) call fail(41)
call element_linear_stiffness(1, elem_dofs, n_elem_dof, ke, ierr)
if (ierr .eq. FEM_SUCCESS) call fail(42)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(43)
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 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 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_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