243 lines
6.0 KiB
Fortran
243 lines
6.0 KiB
Fortran
program test_solver_implicit
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_database
|
|
use fem_boundary
|
|
use fem_solver_implicit
|
|
implicit none
|
|
|
|
real(rk), parameter :: TOL = 1.0e-10_rk
|
|
|
|
call check_single_dof_pull()
|
|
call check_prescribed_value()
|
|
call check_robin_explicit_force()
|
|
call check_robin_implicit_spring()
|
|
|
|
contains
|
|
|
|
subroutine check_single_dof_pull()
|
|
integer :: ierr
|
|
integer :: iter
|
|
real(rk) :: res_norm
|
|
real(rk) :: expected
|
|
integer :: dof
|
|
|
|
call setup_pull_model(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(1)
|
|
|
|
call implicit_solve_linear_static(ZERO, 50, 1.0e-12_rk, iter, res_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(2)
|
|
if (iter .le. 0 .or. iter .gt. 5) call fail(3)
|
|
if (res_norm .gt. TOL) call fail(4)
|
|
|
|
dof = dof_id(1,2)
|
|
expected = 5.0_rk / 6.0_rk
|
|
call check_close(u(dof), expected, 5)
|
|
call check_close(u(dof_id(2,2)), ZERO, 6)
|
|
call check_close(u(dof_id(3,2)), ZERO, 7)
|
|
call check_close(maxval(abs(v)), ZERO, 8)
|
|
call check_close(maxval(abs(a)), ZERO, 9)
|
|
|
|
call database_finalize(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(10)
|
|
end subroutine check_single_dof_pull
|
|
|
|
subroutine check_prescribed_value()
|
|
integer :: ierr
|
|
integer :: iter
|
|
real(rk) :: res_norm
|
|
integer :: dof
|
|
|
|
call setup_prescribed_model(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(20)
|
|
|
|
call implicit_solve_linear_static(ZERO, 50, 1.0e-12_rk, iter, res_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(21)
|
|
if (res_norm .gt. TOL) call fail(22)
|
|
|
|
dof = dof_id(1,2)
|
|
call check_close(u(dof), 0.25_rk, 23)
|
|
call check_close(maxval(abs(v)), ZERO, 24)
|
|
call check_close(maxval(abs(a)), ZERO, 25)
|
|
|
|
call database_finalize(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(26)
|
|
end subroutine check_prescribed_value
|
|
|
|
subroutine check_robin_explicit_force()
|
|
integer :: ierr
|
|
integer :: dof
|
|
|
|
call setup_base_tet(0, 0, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(30)
|
|
call database_allocate_robin(1, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(31)
|
|
|
|
robin_target(1) = '2'
|
|
robin_dof(1) = 1
|
|
robin_stiffness(1) = 10.0_rk
|
|
robin_damping(1) = 2.0_rk
|
|
robin_reference(1) = 0.25_rk
|
|
robin_amp(1) = 0
|
|
|
|
dof = dof_id(1,2)
|
|
u(dof) = 0.5_rk
|
|
v(dof) = -0.1_rk
|
|
fext = ZERO
|
|
|
|
call boundary_apply_robin_forces(ZERO, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(32)
|
|
call check_close(fext(dof), -2.3_rk, 33)
|
|
|
|
call database_finalize(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(34)
|
|
end subroutine check_robin_explicit_force
|
|
|
|
subroutine check_robin_implicit_spring()
|
|
integer :: ierr
|
|
integer :: iter
|
|
real(rk) :: res_norm
|
|
integer :: dof
|
|
|
|
call setup_pull_model(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(40)
|
|
call database_allocate_robin(1, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(41)
|
|
|
|
robin_target(1) = '2'
|
|
robin_dof(1) = 1
|
|
robin_stiffness(1) = 6.0_rk
|
|
robin_damping(1) = ZERO
|
|
robin_reference(1) = 0.25_rk
|
|
robin_amp(1) = 0
|
|
|
|
call implicit_solve_linear_static(ZERO, 50, 1.0e-12_rk, iter, res_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(42)
|
|
if (res_norm .gt. TOL) call fail(43)
|
|
|
|
dof = dof_id(1,2)
|
|
call check_close(u(dof), 13.0_rk / 24.0_rk, 44)
|
|
call check_close(u(dof_id(2,2)), ZERO, 45)
|
|
call check_close(u(dof_id(3,2)), ZERO, 46)
|
|
|
|
call database_finalize(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(47)
|
|
end subroutine check_robin_implicit_spring
|
|
|
|
subroutine setup_pull_model(ierr)
|
|
integer, intent(out) :: ierr
|
|
|
|
call setup_base_tet(4, 1, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
bc_target(1) = '1'
|
|
bc_dof_start(1) = 1
|
|
bc_dof_end(1) = 3
|
|
bc_value(1) = ZERO
|
|
|
|
bc_target(2) = '2'
|
|
bc_dof_start(2) = 2
|
|
bc_dof_end(2) = 3
|
|
bc_value(2) = ZERO
|
|
|
|
bc_target(3) = '3'
|
|
bc_dof_start(3) = 1
|
|
bc_dof_end(3) = 3
|
|
bc_value(3) = ZERO
|
|
|
|
bc_target(4) = '4'
|
|
bc_dof_start(4) = 1
|
|
bc_dof_end(4) = 3
|
|
bc_value(4) = ZERO
|
|
|
|
cload_target(1) = '2'
|
|
cload_dof(1) = 1
|
|
cload_value(1) = 5.0_rk
|
|
ierr = FEM_SUCCESS
|
|
end subroutine setup_pull_model
|
|
|
|
subroutine setup_prescribed_model(ierr)
|
|
integer, intent(out) :: ierr
|
|
|
|
call setup_base_tet(5, 0, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
bc_target(1) = '1'
|
|
bc_dof_start(1) = 1
|
|
bc_dof_end(1) = 3
|
|
bc_value(1) = ZERO
|
|
|
|
bc_target(2) = '2'
|
|
bc_dof_start(2) = 1
|
|
bc_dof_end(2) = 1
|
|
bc_value(2) = 0.25_rk
|
|
|
|
bc_target(3) = '2'
|
|
bc_dof_start(3) = 2
|
|
bc_dof_end(3) = 3
|
|
bc_value(3) = ZERO
|
|
|
|
bc_target(4) = '3'
|
|
bc_dof_start(4) = 1
|
|
bc_dof_end(4) = 3
|
|
bc_value(4) = ZERO
|
|
|
|
bc_target(5) = '4'
|
|
bc_dof_start(5) = 1
|
|
bc_dof_end(5) = 3
|
|
bc_value(5) = ZERO
|
|
ierr = FEM_SUCCESS
|
|
end subroutine setup_prescribed_model
|
|
|
|
subroutine setup_base_tet(num_bc, num_cload, ierr)
|
|
integer, intent(in) :: num_bc
|
|
integer, intent(in) :: num_cload
|
|
integer, intent(out) :: ierr
|
|
integer :: i
|
|
|
|
call database_allocate_model(4, 1, 0, 0, 0, 0, 1, 0, 0, &
|
|
0, 0, num_bc, num_cload, 0, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
do i = 1, 4
|
|
node_id_ext(i) = i
|
|
coord0(:,i) = ZERO
|
|
coord(:,i) = ZERO
|
|
end do
|
|
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
|
|
elem_sec(1) = 1
|
|
|
|
mat_name(1) = 'MAT'
|
|
mat_density(1) = ONE
|
|
mat_e(1) = 30.0_rk
|
|
mat_nu(1) = 0.25_rk
|
|
|
|
call database_assign_dofs(ierr)
|
|
end subroutine setup_base_tet
|
|
|
|
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) call fail(code)
|
|
end subroutine check_close
|
|
|
|
subroutine fail(code)
|
|
integer, intent(in) :: code
|
|
|
|
write(*,*) 'test_solver_implicit failed:', code
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_solver_implicit
|