Add penalty MPC constraint support
This commit is contained in:
@@ -19,6 +19,8 @@ module fem_database
|
||||
integer :: ncload = 0
|
||||
integer :: ndload = 0
|
||||
integer :: nrobin = 0
|
||||
integer :: nmpc = 0
|
||||
integer :: nmpc_term = 0
|
||||
|
||||
real(rk), allocatable :: coord0(:,:)
|
||||
real(rk), allocatable :: coord(:,:)
|
||||
@@ -123,6 +125,14 @@ module fem_database
|
||||
real(rk), allocatable :: robin_reference(:)
|
||||
integer, allocatable :: robin_amp(:)
|
||||
|
||||
integer, allocatable :: mpc_start(:)
|
||||
integer, allocatable :: mpc_count(:)
|
||||
real(rk), allocatable :: mpc_rhs(:)
|
||||
real(rk), allocatable :: mpc_penalty(:)
|
||||
integer, allocatable :: mpc_node(:)
|
||||
integer, allocatable :: mpc_dof(:)
|
||||
real(rk), allocatable :: mpc_coeff(:)
|
||||
|
||||
contains
|
||||
|
||||
subroutine database_allocate_mesh(num_nodes, num_elems, ierr)
|
||||
@@ -474,6 +484,68 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine database_allocate_robin
|
||||
|
||||
subroutine database_allocate_mpc(num_mpc, num_terms, ierr)
|
||||
integer, intent(in) :: num_mpc
|
||||
integer, intent(in) :: num_terms
|
||||
integer, intent(out) :: ierr
|
||||
integer :: stat
|
||||
|
||||
if (num_mpc .lt. 0 .or. num_terms .lt. 0) then
|
||||
call error_set(FEM_ERR_INPUT, 'number of MPC equations and terms must be non-negative', ierr)
|
||||
return
|
||||
end if
|
||||
if (num_mpc .eq. 0 .and. num_terms .ne. 0) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC terms require at least one equation', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
if (allocated(mpc_start)) deallocate(mpc_start)
|
||||
if (allocated(mpc_count)) deallocate(mpc_count)
|
||||
if (allocated(mpc_rhs)) deallocate(mpc_rhs)
|
||||
if (allocated(mpc_penalty)) deallocate(mpc_penalty)
|
||||
if (allocated(mpc_node)) deallocate(mpc_node)
|
||||
if (allocated(mpc_dof)) deallocate(mpc_dof)
|
||||
if (allocated(mpc_coeff)) deallocate(mpc_coeff)
|
||||
|
||||
nmpc = num_mpc
|
||||
nmpc_term = num_terms
|
||||
|
||||
if (num_mpc .gt. 0) then
|
||||
allocate(mpc_start(num_mpc), mpc_count(num_mpc), mpc_rhs(num_mpc), &
|
||||
mpc_penalty(num_mpc), stat=stat)
|
||||
if (stat .ne. 0) then
|
||||
nmpc = 0
|
||||
nmpc_term = 0
|
||||
call error_set(FEM_ERR_INTERNAL, 'failed to allocate MPC headers', ierr)
|
||||
return
|
||||
end if
|
||||
mpc_start = 0
|
||||
mpc_count = 0
|
||||
mpc_rhs = ZERO
|
||||
mpc_penalty = ZERO
|
||||
end if
|
||||
|
||||
if (num_terms .gt. 0) then
|
||||
allocate(mpc_node(num_terms), mpc_dof(num_terms), &
|
||||
mpc_coeff(num_terms), stat=stat)
|
||||
if (stat .ne. 0) then
|
||||
if (allocated(mpc_start)) deallocate(mpc_start)
|
||||
if (allocated(mpc_count)) deallocate(mpc_count)
|
||||
if (allocated(mpc_rhs)) deallocate(mpc_rhs)
|
||||
if (allocated(mpc_penalty)) deallocate(mpc_penalty)
|
||||
nmpc = 0
|
||||
nmpc_term = 0
|
||||
call error_set(FEM_ERR_INTERNAL, 'failed to allocate MPC terms', ierr)
|
||||
return
|
||||
end if
|
||||
mpc_node = 0
|
||||
mpc_dof = 0
|
||||
mpc_coeff = ZERO
|
||||
end if
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine database_allocate_mpc
|
||||
|
||||
subroutine database_allocate_basic(num_nodes, num_elems, num_dof, ierr)
|
||||
integer, intent(in) :: num_nodes
|
||||
integer, intent(in) :: num_elems
|
||||
@@ -642,6 +714,13 @@ contains
|
||||
if (allocated(robin_damping)) robin_damping = ZERO
|
||||
if (allocated(robin_reference)) robin_reference = ZERO
|
||||
if (allocated(robin_amp)) robin_amp = 0
|
||||
if (allocated(mpc_start)) mpc_start = 0
|
||||
if (allocated(mpc_count)) mpc_count = 0
|
||||
if (allocated(mpc_rhs)) mpc_rhs = ZERO
|
||||
if (allocated(mpc_penalty)) mpc_penalty = ZERO
|
||||
if (allocated(mpc_node)) mpc_node = 0
|
||||
if (allocated(mpc_dof)) mpc_dof = 0
|
||||
if (allocated(mpc_coeff)) mpc_coeff = ZERO
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine database_initialize
|
||||
@@ -867,6 +946,9 @@ contains
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
|
||||
call validate_robin_data(ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
|
||||
call validate_mpc_data(ierr)
|
||||
end subroutine database_validate_model
|
||||
|
||||
subroutine validate_materials(ierr)
|
||||
@@ -1157,6 +1239,50 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine validate_robin_data
|
||||
|
||||
subroutine validate_mpc_data(ierr)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: eqn
|
||||
integer :: item
|
||||
integer :: start_pos
|
||||
integer :: stop_pos
|
||||
integer :: node
|
||||
|
||||
do eqn = 1, nmpc
|
||||
start_pos = mpc_start(eqn)
|
||||
stop_pos = start_pos + mpc_count(eqn) - 1
|
||||
if (mpc_count(eqn) .le. 0) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC equation has no terms', ierr)
|
||||
return
|
||||
end if
|
||||
if (start_pos .lt. 1 .or. stop_pos .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC equation term range is invalid', ierr)
|
||||
return
|
||||
end if
|
||||
if (mpc_penalty(eqn) .le. ZERO) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC penalty must be positive', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
do item = start_pos, stop_pos
|
||||
node = database_find_node(mpc_node(item))
|
||||
if (node .eq. 0) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC term references unknown node', ierr)
|
||||
return
|
||||
end if
|
||||
if (mpc_dof(item) .lt. 1 .or. mpc_dof(item) .gt. NDOF_NODE) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC term dof is outside 1..6', ierr)
|
||||
return
|
||||
end if
|
||||
if (abs(mpc_coeff(item)) .le. tiny(ONE)) then
|
||||
call error_set(FEM_ERR_INPUT, 'MPC term coefficient must be non-zero', ierr)
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine validate_mpc_data
|
||||
|
||||
logical function node_or_nset_exists(target)
|
||||
character(len=*), intent(in) :: target
|
||||
integer :: id
|
||||
@@ -1277,6 +1403,13 @@ contains
|
||||
if (allocated(robin_damping)) deallocate(robin_damping)
|
||||
if (allocated(robin_reference)) deallocate(robin_reference)
|
||||
if (allocated(robin_amp)) deallocate(robin_amp)
|
||||
if (allocated(mpc_start)) deallocate(mpc_start)
|
||||
if (allocated(mpc_count)) deallocate(mpc_count)
|
||||
if (allocated(mpc_rhs)) deallocate(mpc_rhs)
|
||||
if (allocated(mpc_penalty)) deallocate(mpc_penalty)
|
||||
if (allocated(mpc_node)) deallocate(mpc_node)
|
||||
if (allocated(mpc_dof)) deallocate(mpc_dof)
|
||||
if (allocated(mpc_coeff)) deallocate(mpc_coeff)
|
||||
|
||||
nnode = 0
|
||||
nelem = 0
|
||||
@@ -1293,6 +1426,8 @@ contains
|
||||
ncload = 0
|
||||
ndload = 0
|
||||
nrobin = 0
|
||||
nmpc = 0
|
||||
nmpc_term = 0
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine database_finalize
|
||||
|
||||
|
||||
Reference in New Issue
Block a user