Files
FemLite/tests/module/test_quadratic_internal.f90
T
2026-06-22 22:29:29 +08:00

236 lines
6.8 KiB
Fortran

program test_quadratic_internal
use fem_precision
use fem_error
use fem_database
use fem_element_internal
implicit none
real(rk), parameter :: TOL = 1.0e-8_rk
real(rk), parameter :: EXX = 0.01_rk
call check_c3d10_internal()
call check_c3d20_internal()
contains
subroutine check_c3d10_internal()
integer :: ierr
call setup_c3d10(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(1)
call apply_x_extension(EXX)
call element_compute_internal_force(ierr, 1.0e-4_rk)
if (ierr .ne. FEM_SUCCESS) call fail(2)
if (elem_status(1) .ne. 0) call fail(3)
call check_state_shape(4, 4)
call check_gp_values(4, 10)
call check_force_balance(20)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(29)
end subroutine check_c3d10_internal
subroutine check_c3d20_internal()
integer :: ierr
call setup_c3d20(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(30)
call apply_x_extension(EXX)
call element_compute_internal_force(ierr, 1.0e-4_rk)
if (ierr .ne. FEM_SUCCESS) call fail(31)
if (elem_status(1) .ne. 0) call fail(32)
call check_state_shape(27, 33)
call check_gp_values(27, 40)
call check_force_balance(50)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(59)
end subroutine check_c3d20_internal
subroutine setup_c3d10(ierr)
integer, intent(out) :: ierr
call database_allocate_model(10, 1, 0, 1, 0, 1, 1, 0, 1, &
0, 0, 0, 0, 0, ierr)
if (ierr .ne. FEM_SUCCESS) return
call fill_common_model('C3D10', 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))
coord = coord0
call database_assign_dofs(ierr)
end subroutine setup_c3d10
subroutine setup_c3d20(ierr)
integer, intent(out) :: ierr
call database_allocate_model(20, 1, 0, 1, 0, 1, 1, 0, 1, &
0, 0, 0, 0, 0, ierr)
if (ierr .ne. FEM_SUCCESS) return
call fill_common_model('C3D20', 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))
coord = coord0
call database_assign_dofs(ierr)
end subroutine setup_c3d20
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
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) = ONE
mat_e(1) = 30.0_rk
mat_nu(1) = 0.25_rk
mat_plastic_model(1) = 'ELASTIC'
section_type(1) = 'SOLID'
section_elset_name(1) = 'EALL'
section_material_name(1) = 'MAT'
end subroutine fill_common_model
subroutine apply_x_extension(exx)
real(rk), intent(in) :: exx
integer :: node
integer :: dof
u = ZERO
do node = 1, nnode
dof = dof_id(1,node)
if (dof .gt. 0) u(dof) = exx * coord0(1,node)
end do
end subroutine apply_x_extension
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_gp_values(npoint, code)
integer, intent(in) :: npoint
integer, intent(in) :: code
real(rk) :: lambda
real(rk) :: mu
real(rk) :: expected_stress(NSTRESS)
real(rk) :: expected_strain(NSTRESS)
integer :: gp
lambda = mat_e(1) * mat_nu(1) / &
((ONE + mat_nu(1)) * (ONE - 2.0_rk * mat_nu(1)))
mu = mat_e(1) / (2.0_rk * (ONE + mat_nu(1)))
expected_strain = ZERO
expected_strain(1) = EXX
expected_stress = ZERO
expected_stress(1) = (lambda + 2.0_rk * mu) * EXX
expected_stress(2) = lambda * EXX
expected_stress(3) = lambda * 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(4,gp)) .gt. TOL) call fail(code + 2)
end do
end subroutine check_gp_values
subroutine check_force_balance(code)
integer, intent(in) :: code
real(rk) :: balance(NDIM)
real(rk) :: max_force
integer :: node
integer :: idir
integer :: dof
balance = ZERO
max_force = ZERO
do node = 1, nnode
do idir = 1, NDIM
dof = dof_id(idir,node)
if (dof .gt. 0) then
balance(idir) = balance(idir) + fint(dof)
max_force = max(max_force, abs(fint(dof)))
end if
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_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_quadratic_internal failed:', code
stop 1
end subroutine fail
end program test_quadratic_internal