306 lines
11 KiB
Fortran
306 lines
11 KiB
Fortran
program test_contact_mortar_iter
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_contact_mortar_al
|
|
use fem_contact_mortar_batch
|
|
use fem_contact_mortar_iter
|
|
implicit none
|
|
|
|
real(rk), parameter :: TOL = 1.0e-10_rk
|
|
|
|
call check_options_and_names()
|
|
call check_summary_iteration()
|
|
call check_batch_iteration()
|
|
call check_pressure_limit()
|
|
call check_error_paths()
|
|
|
|
contains
|
|
|
|
subroutine check_options_and_names()
|
|
type(mortar_iter_options) :: options
|
|
integer :: ierr
|
|
|
|
call mortar_iter_options_init(4, 0.01_rk, 0.10_rk, options, ierr)
|
|
call require_success(ierr, 10)
|
|
if (options%max_iterations .ne. 4) call fail(11)
|
|
call check_close(options%gap_tolerance, 0.01_rk, 12)
|
|
call check_close(options%lambda_tolerance, 0.10_rk, 13)
|
|
if (.not. options%adapt_penalty) call fail(14)
|
|
if (trim(mortar_iter_status_name(MORTAR_ITER_RUNNING)) .ne. 'RUNNING') &
|
|
call fail(15)
|
|
if (trim(mortar_iter_status_name(MORTAR_ITER_CONVERGED)) .ne. &
|
|
'CONVERGED') call fail(16)
|
|
if (trim(mortar_iter_status_name(MORTAR_ITER_LIMITED)) .ne. 'LIMITED') &
|
|
call fail(17)
|
|
if (trim(mortar_iter_status_name(MORTAR_ITER_INVALID)) .ne. 'INVALID') &
|
|
call fail(18)
|
|
|
|
options%max_iterations = MORTAR_ITER_MAX_RECORDS + 1
|
|
call mortar_iter_options_valid(options, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(19)
|
|
end subroutine check_options_and_names
|
|
|
|
subroutine check_summary_iteration()
|
|
type(mortar_al_params) :: params
|
|
type(mortar_al_params) :: next_params
|
|
type(mortar_iter_options) :: options
|
|
type(mortar_iter_state) :: state
|
|
type(mortar_al_summary) :: summary
|
|
integer :: iterations
|
|
integer :: status
|
|
integer :: converged_iteration
|
|
integer :: iteration
|
|
integer :: action
|
|
integer :: active
|
|
real(rk) :: current_penalty
|
|
real(rk) :: final_penalty
|
|
real(rk) :: penalty
|
|
real(rk) :: next_penalty
|
|
real(rk) :: max_gap
|
|
real(rk) :: max_lambda
|
|
integer :: ierr
|
|
|
|
call make_params(100.0_rk, params, ierr)
|
|
call require_success(ierr, 30)
|
|
call mortar_iter_options_init(3, 0.01_rk, 0.05_rk, options, ierr)
|
|
call require_success(ierr, 31)
|
|
call mortar_iter_begin(params, options, state, ierr)
|
|
call require_success(ierr, 32)
|
|
|
|
call make_summary(2, 1, 0, 0.04_rk, 4.0_rk, 0.20_rk, summary)
|
|
call mortar_iter_record_summary(params, options, summary, state, &
|
|
next_params, ierr)
|
|
call require_success(ierr, 33)
|
|
call mortar_iter_record_values(state, 1, iteration, status, action, &
|
|
penalty, next_penalty, max_gap, max_lambda, active, ierr)
|
|
call require_success(ierr, 34)
|
|
if (iteration .ne. 1) call fail(35)
|
|
if (status .ne. MORTAR_ITER_RUNNING) call fail(36)
|
|
if (action .ne. MORTAR_AL_ADAPT_GROW) call fail(37)
|
|
call check_close(next_penalty, 200.0_rk, 38)
|
|
call check_close(max_gap, 0.04_rk, 39)
|
|
call check_close(max_lambda, 4.0_rk, 40)
|
|
if (active .ne. 1) call fail(41)
|
|
|
|
params = next_params
|
|
call make_summary(2, 0, 0, ZERO, ZERO, ZERO, summary)
|
|
call mortar_iter_record_summary(params, options, summary, state, &
|
|
next_params, ierr)
|
|
call require_success(ierr, 42)
|
|
call mortar_iter_summary(state, iterations, status, current_penalty, &
|
|
final_penalty, converged_iteration, ierr)
|
|
call require_success(ierr, 43)
|
|
if (iterations .ne. 2) call fail(44)
|
|
if (status .ne. MORTAR_ITER_CONVERGED) call fail(45)
|
|
if (converged_iteration .ne. 2) call fail(46)
|
|
call check_close(current_penalty, 200.0_rk, 47)
|
|
call check_close(final_penalty, 200.0_rk, 48)
|
|
call mortar_iter_require_converged(state, iteration, penalty, ierr)
|
|
call require_success(ierr, 49)
|
|
if (iteration .ne. 2) call fail(50)
|
|
call check_close(penalty, 200.0_rk, 51)
|
|
end subroutine check_summary_iteration
|
|
|
|
subroutine check_batch_iteration()
|
|
type(mortar_al_params) :: params
|
|
type(mortar_al_params) :: next_params
|
|
type(mortar_iter_options) :: options
|
|
type(mortar_iter_state) :: state
|
|
type(mortar_al_summary) :: summary
|
|
type(mortar_batch_diag) :: diag
|
|
integer :: iterations
|
|
integer :: status
|
|
integer :: converged_iteration
|
|
real(rk) :: current_penalty
|
|
real(rk) :: final_penalty
|
|
integer :: ierr
|
|
|
|
call make_params(80.0_rk, params, ierr)
|
|
call require_success(ierr, 60)
|
|
call mortar_iter_options_init(4, 0.01_rk, 0.10_rk, options, ierr)
|
|
call require_success(ierr, 61)
|
|
options%max_pressure = 10.0_rk
|
|
call mortar_iter_begin(params, options, state, ierr)
|
|
call require_success(ierr, 62)
|
|
call build_batch(params, 0.02_rk, summary, diag, ierr)
|
|
call require_success(ierr, 63)
|
|
call mortar_iter_record_batch(params, options, summary, diag, state, &
|
|
next_params, ierr)
|
|
call require_success(ierr, 64)
|
|
if (.not. state%records(1)%pressure_ok) call fail(65)
|
|
if (state%records(1)%pressure_avg .le. ZERO) call fail(66)
|
|
if (state%records(1)%gap_l2 .le. ZERO) call fail(67)
|
|
if (state%records(1)%lambda_l2 .le. ZERO) call fail(68)
|
|
|
|
params = next_params
|
|
call build_batch(params, ZERO, summary, diag, ierr)
|
|
call require_success(ierr, 69)
|
|
call mortar_iter_record_batch(params, options, summary, diag, state, &
|
|
next_params, ierr)
|
|
call require_success(ierr, 70)
|
|
call mortar_iter_summary(state, iterations, status, current_penalty, &
|
|
final_penalty, converged_iteration, ierr)
|
|
call require_success(ierr, 71)
|
|
if (iterations .ne. 2) call fail(72)
|
|
if (status .ne. MORTAR_ITER_CONVERGED) call fail(73)
|
|
if (converged_iteration .ne. 2) call fail(74)
|
|
end subroutine check_batch_iteration
|
|
|
|
subroutine check_pressure_limit()
|
|
type(mortar_al_params) :: params
|
|
type(mortar_al_params) :: next_params
|
|
type(mortar_iter_options) :: options
|
|
type(mortar_iter_state) :: state
|
|
type(mortar_al_summary) :: summary
|
|
type(mortar_batch_diag) :: diag
|
|
integer :: iterations
|
|
integer :: status
|
|
integer :: converged_iteration
|
|
real(rk) :: current_penalty
|
|
real(rk) :: final_penalty
|
|
integer :: ierr
|
|
|
|
call make_params(50.0_rk, params, ierr)
|
|
call require_success(ierr, 90)
|
|
call mortar_iter_options_init(1, 0.10_rk, 0.10_rk, options, ierr)
|
|
call require_success(ierr, 91)
|
|
options%min_pressure = 5.0_rk
|
|
call mortar_iter_begin(params, options, state, ierr)
|
|
call require_success(ierr, 92)
|
|
call build_batch(params, ZERO, summary, diag, ierr)
|
|
call require_success(ierr, 93)
|
|
call mortar_iter_record_batch(params, options, summary, diag, state, &
|
|
next_params, ierr)
|
|
call require_success(ierr, 94)
|
|
if (state%records(1)%pressure_ok) call fail(95)
|
|
call mortar_iter_summary(state, iterations, status, current_penalty, &
|
|
final_penalty, converged_iteration, ierr)
|
|
call require_success(ierr, 96)
|
|
if (iterations .ne. 1) call fail(97)
|
|
if (status .ne. MORTAR_ITER_LIMITED) call fail(98)
|
|
if (converged_iteration .ne. 0) call fail(99)
|
|
call mortar_iter_require_converged(state, iterations, final_penalty, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(100)
|
|
end subroutine check_pressure_limit
|
|
|
|
subroutine check_error_paths()
|
|
type(mortar_al_params) :: params
|
|
type(mortar_al_params) :: next_params
|
|
type(mortar_iter_options) :: options
|
|
type(mortar_iter_state) :: state
|
|
type(mortar_al_summary) :: summary
|
|
integer :: iteration
|
|
integer :: status
|
|
integer :: action
|
|
integer :: active
|
|
real(rk) :: penalty
|
|
real(rk) :: next_penalty
|
|
real(rk) :: max_gap
|
|
real(rk) :: max_lambda
|
|
integer :: ierr
|
|
|
|
call make_params(100.0_rk, params, ierr)
|
|
call require_success(ierr, 120)
|
|
call mortar_iter_options_init(2, 0.01_rk, 0.01_rk, options, ierr)
|
|
call require_success(ierr, 121)
|
|
options%min_pressure = 2.0_rk
|
|
options%max_pressure = ONE
|
|
call mortar_iter_options_valid(options, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(122)
|
|
|
|
call mortar_iter_options_init(1, 0.01_rk, 0.01_rk, options, ierr)
|
|
call require_success(ierr, 123)
|
|
call mortar_iter_begin(params, options, state, ierr)
|
|
call require_success(ierr, 124)
|
|
call make_summary(2, 1, 0, 0.02_rk, 2.0_rk, 0.50_rk, summary)
|
|
summary%open_count = 0
|
|
call mortar_iter_record_summary(params, options, summary, state, &
|
|
next_params, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(125)
|
|
|
|
call make_summary(2, 1, 0, 0.02_rk, 2.0_rk, 0.50_rk, summary)
|
|
call mortar_iter_record_values(state, 1, iteration, status, action, &
|
|
penalty, next_penalty, max_gap, max_lambda, active, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(126)
|
|
end subroutine check_error_paths
|
|
|
|
subroutine make_params(penalty, params, ierr)
|
|
real(rk), intent(in) :: penalty
|
|
type(mortar_al_params), intent(out) :: params
|
|
integer, intent(out) :: ierr
|
|
|
|
call mortar_al_params_init(penalty, 0.01_rk, params, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
params%lambda_tolerance = 0.05_rk
|
|
params%max_lambda_update = huge(ONE)
|
|
call mortar_al_params_validate(params, ierr)
|
|
end subroutine make_params
|
|
|
|
subroutine make_summary(count, active, released, gap, lambda_value, update, &
|
|
summary)
|
|
integer, intent(in) :: count
|
|
integer, intent(in) :: active
|
|
integer, intent(in) :: released
|
|
real(rk), intent(in) :: gap
|
|
real(rk), intent(in) :: lambda_value
|
|
real(rk), intent(in) :: update
|
|
type(mortar_al_summary), intent(out) :: summary
|
|
|
|
call mortar_al_summary_reset(summary)
|
|
summary%point_count = count
|
|
summary%active_count = active
|
|
summary%released_count = released
|
|
summary%open_count = count - active - released
|
|
summary%max_gap = gap
|
|
summary%max_lambda = lambda_value
|
|
summary%max_update = update
|
|
summary%max_residual = gap
|
|
summary%weighted_gap_sum = gap
|
|
summary%contact_area = real(max(active, 1), rk)
|
|
end subroutine make_summary
|
|
|
|
subroutine build_batch(params, gap, summary, diag, ierr)
|
|
type(mortar_al_params), intent(in) :: params
|
|
real(rk), intent(in) :: gap
|
|
type(mortar_al_summary), intent(out) :: summary
|
|
type(mortar_batch_diag), intent(out) :: diag
|
|
integer, intent(out) :: ierr
|
|
|
|
type(mortar_al_point) :: points(2)
|
|
real(rk) :: gaps(2)
|
|
real(rk) :: areas(2)
|
|
real(rk) :: weights(2)
|
|
real(rk) :: old_lambdas(2)
|
|
|
|
gaps = (/ gap, ZERO /)
|
|
areas = (/ ONE, ONE /)
|
|
weights = (/ 0.50_rk, 0.50_rk /)
|
|
old_lambdas = ZERO
|
|
call mortar_batch_update(params, 1, 10, 1, 20, 1, 2, gaps, areas, &
|
|
weights, old_lambdas, points, summary, diag, ierr)
|
|
end subroutine build_batch
|
|
|
|
subroutine require_success(ierr, code)
|
|
integer, intent(in) :: ierr
|
|
integer, intent(in) :: code
|
|
|
|
if (ierr .ne. FEM_SUCCESS) call fail(code)
|
|
end subroutine require_success
|
|
|
|
subroutine check_close(value, expected, code)
|
|
real(rk), intent(in) :: value
|
|
real(rk), intent(in) :: expected
|
|
integer, intent(in) :: code
|
|
|
|
if (abs(value - expected) .gt. TOL) call fail(code)
|
|
end subroutine check_close
|
|
|
|
subroutine fail(code)
|
|
integer, intent(in) :: code
|
|
|
|
write(*,*) 'test_contact_mortar_iter failed:', code
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_contact_mortar_iter
|