Add penalty MPC constraint support

This commit is contained in:
shenw
2026-06-22 23:25:35 +08:00
parent 81ba21af55
commit 473d97891c
6 changed files with 484 additions and 0 deletions
+98
View File
@@ -12,6 +12,8 @@ program test_solver_implicit
call check_prescribed_value()
call check_robin_explicit_force()
call check_robin_implicit_spring()
call check_mpc_explicit_force()
call check_mpc_implicit_penalty()
contains
@@ -124,6 +126,74 @@ contains
if (ierr .ne. FEM_SUCCESS) call fail(47)
end subroutine check_robin_implicit_spring
subroutine check_mpc_explicit_force()
integer :: ierr
integer :: dof2
integer :: dof3
call setup_base_tet(0, 0, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(50)
call database_allocate_mpc(1, 2, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(51)
mpc_start(1) = 1
mpc_count(1) = 2
mpc_rhs(1) = 0.05_rk
mpc_penalty(1) = 10.0_rk
mpc_node(1) = 2
mpc_dof(1) = 1
mpc_coeff(1) = ONE
mpc_node(2) = 3
mpc_dof(2) = 1
mpc_coeff(2) = -2.0_rk
dof2 = dof_id(1,2)
dof3 = dof_id(1,3)
u(dof2) = 0.4_rk
u(dof3) = 0.1_rk
fext = ZERO
call boundary_apply_mpc_forces(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(52)
call check_close(fext(dof2), -1.5_rk, 53)
call check_close(fext(dof3), 3.0_rk, 54)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(55)
end subroutine check_mpc_explicit_force
subroutine check_mpc_implicit_penalty()
integer :: ierr
integer :: iter
real(rk) :: res_norm
integer :: dof
call setup_single_free_dof_model(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(60)
call database_allocate_mpc(1, 1, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(61)
mpc_start(1) = 1
mpc_count(1) = 1
mpc_rhs(1) = 0.25_rk
mpc_penalty(1) = 6.0_rk
mpc_node(1) = 2
mpc_dof(1) = 1
mpc_coeff(1) = ONE
call implicit_solve_linear_static(ZERO, 50, 1.0e-12_rk, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(62)
if (res_norm .gt. TOL) call fail(63)
dof = dof_id(1,2)
call check_close(u(dof), 0.125_rk, 64)
call check_close(u(dof_id(2,2)), ZERO, 65)
call check_close(u(dof_id(3,2)), ZERO, 66)
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(67)
end subroutine check_mpc_implicit_penalty
subroutine setup_pull_model(ierr)
integer, intent(out) :: ierr
@@ -156,6 +226,34 @@ contains
ierr = FEM_SUCCESS
end subroutine setup_pull_model
subroutine setup_single_free_dof_model(ierr)
integer, intent(out) :: ierr
call setup_base_tet(4, 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) = 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
ierr = FEM_SUCCESS
end subroutine setup_single_free_dof_model
subroutine setup_prescribed_model(ierr)
integer, intent(out) :: ierr