program test_contact_mortar_report use fem_precision use fem_error use fem_contact_mortar_al use fem_contact_mortar_batch use fem_contact_mortar_iter use fem_contact_mortar_report implicit none character(len=*), parameter :: REPORT_FILE = & 'test_contact_mortar_report.csv' call check_point_report() call check_iteration_report() call check_file_report() call check_error_paths() contains subroutine check_point_report() type(mortar_al_params) :: params type(mortar_al_point) :: point character(len=512) :: line integer :: ierr call make_params(params, ierr) call require_success(ierr, 10) call mortar_al_update_point(params, 1, 10, 1, 20, 2, 3, 0.02_rk, & ONE, ONE, ZERO, point, ierr) call require_success(ierr, 11) call mortar_report_point_header(line, ierr) call require_success(ierr, 12) if (index(line, 'pair,slave_elem') .ne. 1) call fail(13) if (index(line, 'lambda,update') .le. 0) call fail(14) call mortar_report_point_csv(point, line, ierr) call require_success(ierr, 15) if (index(line, '1,10,1,20,2,3,ACTIVE') .ne. 1) call fail(16) if (index(line, '2.00000000E+00') .le. 0) call fail(17) end subroutine check_point_report subroutine check_iteration_report() type(mortar_iter_state) :: state character(len=512) :: line integer :: ierr call make_converged_state(state, ierr) call require_success(ierr, 30) call mortar_report_iter_header(line, ierr) call require_success(ierr, 31) if (index(line, 'iteration,status,action') .ne. 1) call fail(32) if (index(line, 'pressure_avg') .le. 0) call fail(33) call mortar_report_iter_csv(state%records(1), line, ierr) call require_success(ierr, 34) if (index(line, 'RUNNING,GROW') .le. 0) call fail(35) if (index(line, '1,') .ne. 1) call fail(36) call mortar_report_iter_csv(state%records(2), line, ierr) call require_success(ierr, 37) if (index(line, 'CONVERGED,KEEP') .le. 0) call fail(38) call mortar_report_iter_summary(state, line, ierr) call require_success(ierr, 39) if (index(line, 'status=CONVERGED') .ne. 1) call fail(40) if (index(line, 'iterations=2') .le. 0) call fail(41) end subroutine check_iteration_report subroutine check_file_report() type(mortar_iter_state) :: state character(len=512) :: line logical :: saw_header logical :: saw_converged integer :: unit integer :: ios integer :: ierr call make_converged_state(state, ierr) call require_success(ierr, 60) call mortar_report_write_iterations(REPORT_FILE, state, ierr) call require_success(ierr, 61) saw_header = .false. saw_converged = .false. unit = 97 open(unit=unit, file=REPORT_FILE, status='old', action='read', & iostat=ios) if (ios .ne. 0) call fail(62) do read(unit, '(A)', iostat=ios) line if (ios .ne. 0) exit if (index(line, 'iteration,status,action') .eq. 1) saw_header = .true. if (index(line, 'CONVERGED') .gt. 0) saw_converged = .true. end do close(unit, status='delete') if (.not. saw_header) call fail(63) if (.not. saw_converged) call fail(64) end subroutine check_file_report subroutine check_error_paths() type(mortar_iter_state) :: state character(len=16) :: tiny_line integer :: ierr call make_converged_state(state, ierr) call require_success(ierr, 80) call mortar_report_point_header(tiny_line, ierr) if (ierr .eq. FEM_SUCCESS) call fail(81) call mortar_report_iter_csv(state%records(1), tiny_line, ierr) if (ierr .eq. FEM_SUCCESS) call fail(82) call mortar_report_write_iterations('', state, ierr) if (ierr .eq. FEM_SUCCESS) call fail(83) end subroutine check_error_paths subroutine make_converged_state(state, ierr) type(mortar_iter_state), intent(out) :: state integer, intent(out) :: ierr type(mortar_al_params) :: params type(mortar_al_params) :: next_params type(mortar_iter_options) :: options type(mortar_al_summary) :: summary type(mortar_batch_diag) :: diag call make_params(params, ierr) if (ierr .ne. FEM_SUCCESS) return call mortar_iter_options_init(3, 0.01_rk, 0.05_rk, options, ierr) if (ierr .ne. FEM_SUCCESS) return call mortar_iter_begin(params, options, state, ierr) if (ierr .ne. FEM_SUCCESS) return call build_batch(params, 0.02_rk, summary, diag, ierr) if (ierr .ne. FEM_SUCCESS) return call mortar_iter_record_batch(params, options, summary, diag, state, & next_params, ierr) if (ierr .ne. FEM_SUCCESS) return params = next_params call build_batch(params, ZERO, summary, diag, ierr) if (ierr .ne. FEM_SUCCESS) return call mortar_iter_record_batch(params, options, summary, diag, state, & next_params, ierr) end subroutine make_converged_state subroutine make_params(params, ierr) type(mortar_al_params), intent(out) :: params integer, intent(out) :: ierr call mortar_al_params_init(100.0_rk, 0.01_rk, params, ierr) if (ierr .ne. FEM_SUCCESS) return params%lambda_tolerance = 0.05_rk call mortar_al_params_validate(params, ierr) end subroutine make_params 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, 2, 11, 1, 21, 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 fail(code) integer, intent(in) :: code write(*,*) 'test_contact_mortar_report failed:', code stop 1 end subroutine fail end program test_contact_mortar_report