Add penalty MPC constraint support
This commit is contained in:
@@ -125,6 +125,9 @@ contains
|
||||
end do
|
||||
end do
|
||||
|
||||
call count_mpc_pattern_entries(raw_count, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) go to 900
|
||||
|
||||
max_raw = maxval(raw_count)
|
||||
allocate(row_cols(max_raw, ndof), stat=stat)
|
||||
if (stat .ne. 0) then
|
||||
@@ -156,6 +159,9 @@ contains
|
||||
end do
|
||||
end do
|
||||
|
||||
call append_mpc_pattern_columns(row_cols, row_count, max_raw, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) go to 900
|
||||
|
||||
do row = 1, ndof
|
||||
call sort_row_columns(row_cols, row_count(row), row)
|
||||
end do
|
||||
@@ -294,6 +300,99 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine append_unique_column
|
||||
|
||||
subroutine count_mpc_pattern_entries(raw_count, ierr)
|
||||
integer, intent(inout) :: raw_count(:)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: eqn
|
||||
integer :: item
|
||||
integer :: start_pos
|
||||
integer :: stop_pos
|
||||
integer :: dof
|
||||
|
||||
do eqn = 1, nmpc
|
||||
start_pos = mpc_start(eqn)
|
||||
stop_pos = start_pos + mpc_count(eqn) - 1
|
||||
if (start_pos .lt. 1 .or. stop_pos .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_SOLVER, 'MPC pattern term range is invalid', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
do item = start_pos, stop_pos
|
||||
call mpc_term_dof(item, dof, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (dof .gt. 0) raw_count(dof) = raw_count(dof) + mpc_count(eqn)
|
||||
end do
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine count_mpc_pattern_entries
|
||||
|
||||
subroutine append_mpc_pattern_columns(row_cols, row_count, max_raw, ierr)
|
||||
integer, intent(inout) :: row_cols(:,:)
|
||||
integer, intent(inout) :: row_count(:)
|
||||
integer, intent(in) :: max_raw
|
||||
integer, intent(out) :: ierr
|
||||
integer :: eqn
|
||||
integer :: row_item
|
||||
integer :: col_item
|
||||
integer :: start_pos
|
||||
integer :: stop_pos
|
||||
integer :: row
|
||||
integer :: col
|
||||
|
||||
do eqn = 1, nmpc
|
||||
start_pos = mpc_start(eqn)
|
||||
stop_pos = start_pos + mpc_count(eqn) - 1
|
||||
if (start_pos .lt. 1 .or. stop_pos .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_SOLVER, 'MPC pattern term range is invalid', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
do row_item = start_pos, stop_pos
|
||||
call mpc_term_dof(row_item, row, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (row .le. 0) cycle
|
||||
|
||||
do col_item = start_pos, stop_pos
|
||||
call mpc_term_dof(col_item, col, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (col .gt. 0) then
|
||||
call append_unique_column(row_cols, row_count, max_raw, row, col, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine append_mpc_pattern_columns
|
||||
|
||||
subroutine mpc_term_dof(item, dof, ierr)
|
||||
integer, intent(in) :: item
|
||||
integer, intent(out) :: dof
|
||||
integer, intent(out) :: ierr
|
||||
integer :: node
|
||||
|
||||
dof = 0
|
||||
if (item .lt. 1 .or. item .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_SOLVER, 'MPC term index is out of range', ierr)
|
||||
return
|
||||
end if
|
||||
if (mpc_dof(item) .lt. 1 .or. mpc_dof(item) .gt. NDOF_NODE) then
|
||||
call error_set(FEM_ERR_SOLVER, 'MPC term dof is outside 1..6', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
node = database_find_node(mpc_node(item))
|
||||
if (node .eq. 0) then
|
||||
call error_set(FEM_ERR_SOLVER, 'MPC term references unknown node', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
dof = dof_id(mpc_dof(item),node)
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine mpc_term_dof
|
||||
|
||||
subroutine sort_row_columns(row_cols, count, row)
|
||||
integer, intent(inout) :: row_cols(:,:)
|
||||
integer, intent(in) :: count
|
||||
|
||||
@@ -62,6 +62,9 @@ contains
|
||||
call apply_implicit_robin(kmat, rhs, time, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) go to 900
|
||||
|
||||
call apply_implicit_mpc(kmat, rhs, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) go to 900
|
||||
|
||||
call apply_implicit_dirichlet(kmat, rhs, time, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) go to 900
|
||||
|
||||
@@ -219,6 +222,92 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine apply_robin_node
|
||||
|
||||
subroutine apply_implicit_mpc(kmat, rhs, ierr)
|
||||
type(csr_matrix), intent(inout) :: kmat
|
||||
real(rk), intent(inout) :: rhs(:)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: eqn
|
||||
|
||||
do eqn = 1, nmpc
|
||||
call apply_mpc_equation_implicit(kmat, rhs, eqn, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine apply_implicit_mpc
|
||||
|
||||
subroutine apply_mpc_equation_implicit(kmat, rhs, eqn, ierr)
|
||||
type(csr_matrix), intent(inout) :: kmat
|
||||
real(rk), intent(inout) :: rhs(:)
|
||||
integer, intent(in) :: eqn
|
||||
integer, intent(out) :: ierr
|
||||
integer :: row_item
|
||||
integer :: col_item
|
||||
integer :: start_pos
|
||||
integer :: stop_pos
|
||||
integer :: row
|
||||
integer :: col
|
||||
real(rk) :: penalty
|
||||
|
||||
start_pos = mpc_start(eqn)
|
||||
stop_pos = start_pos + mpc_count(eqn) - 1
|
||||
if (start_pos .lt. 1 .or. stop_pos .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_INPUT, 'implicit MPC equation term range is invalid', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
penalty = mpc_penalty(eqn)
|
||||
if (penalty .le. ZERO) then
|
||||
call error_set(FEM_ERR_INPUT, 'implicit MPC penalty must be positive', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
do row_item = start_pos, stop_pos
|
||||
call mpc_term_global_dof(row_item, row, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (row .le. 0) cycle
|
||||
|
||||
rhs(row) = rhs(row) + penalty * mpc_rhs(eqn) * mpc_coeff(row_item)
|
||||
do col_item = start_pos, stop_pos
|
||||
call mpc_term_global_dof(col_item, col, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (col .gt. 0) then
|
||||
call csr_add_value(kmat, row, col, &
|
||||
penalty * mpc_coeff(row_item) * mpc_coeff(col_item), ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine apply_mpc_equation_implicit
|
||||
|
||||
subroutine mpc_term_global_dof(item, dof, ierr)
|
||||
integer, intent(in) :: item
|
||||
integer, intent(out) :: dof
|
||||
integer, intent(out) :: ierr
|
||||
integer :: node
|
||||
|
||||
dof = 0
|
||||
if (item .lt. 1 .or. item .gt. nmpc_term) then
|
||||
call error_set(FEM_ERR_INPUT, 'implicit MPC term index is out of range', ierr)
|
||||
return
|
||||
end if
|
||||
if (mpc_dof(item) .lt. 1 .or. mpc_dof(item) .gt. NDOF_NODE) then
|
||||
call error_set(FEM_ERR_INPUT, 'implicit MPC term dof is outside 1..6', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
node = database_find_node(mpc_node(item))
|
||||
if (node .eq. 0) then
|
||||
call error_set(FEM_ERR_INPUT, 'implicit MPC term references unknown node', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
dof = dof_id(mpc_dof(item),node)
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine mpc_term_global_dof
|
||||
|
||||
subroutine apply_bc_target(kmat, rhs, target, dof_num, value, ierr)
|
||||
type(csr_matrix), intent(inout) :: kmat
|
||||
real(rk), intent(inout) :: rhs(:)
|
||||
|
||||
Reference in New Issue
Block a user