This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
module fem_linear_solver_cg
|
||||
use fem_linear_solver_dispatch, only: linear_solver_solve, &
|
||||
linear_solver_configure, linear_solver_get_settings, &
|
||||
linear_solver_get_stats, linear_solver_get_diagnostics
|
||||
linear_solver_get_stats, linear_solver_get_diagnostics, &
|
||||
linear_solver_get_fail_info
|
||||
use fem_linear_solver_iterative, only: linear_cg_solve, &
|
||||
linear_bicgstab_solve, linear_gmres_solve
|
||||
implicit none
|
||||
@@ -11,6 +12,7 @@ module fem_linear_solver_cg
|
||||
public :: linear_solver_get_settings
|
||||
public :: linear_solver_get_stats
|
||||
public :: linear_solver_get_diagnostics
|
||||
public :: linear_solver_get_fail_info
|
||||
public :: linear_cg_solve
|
||||
public :: linear_bicgstab_solve
|
||||
public :: linear_gmres_solve
|
||||
|
||||
@@ -4,7 +4,7 @@ module fem_linear_solver_dispatch
|
||||
use fem_control
|
||||
use fem_sparse_csr
|
||||
use fem_sparse_csr_diagnostics, only: csr_profile, csr_analyze, &
|
||||
csr_residual_norm
|
||||
csr_residual_norm, CSR_CLASS_SPD_CAND
|
||||
use fem_linear_solver_iterative
|
||||
use fem_linear_solver_dense
|
||||
implicit none
|
||||
@@ -16,6 +16,7 @@ module fem_linear_solver_dispatch
|
||||
public :: linear_solver_get_settings
|
||||
public :: linear_solver_get_stats
|
||||
public :: linear_solver_get_diagnostics
|
||||
public :: linear_solver_get_fail_info
|
||||
|
||||
contains
|
||||
|
||||
@@ -37,12 +38,16 @@ contains
|
||||
real(rk) :: final_resid
|
||||
real(rk) :: final_rel_resid
|
||||
integer :: matrix_class
|
||||
integer :: failure_class
|
||||
integer :: audit_ierr
|
||||
character(len=64) :: reason_text
|
||||
|
||||
method = linear_solver_method
|
||||
preconditioner = linear_precond_method
|
||||
status = LS_STATUS_FAILED
|
||||
matrix_class = 1
|
||||
failure_class = LS_FAIL_NONE
|
||||
reason_text = 'selected'
|
||||
initial_resid = ZERO
|
||||
initial_rel_resid = ZERO
|
||||
final_resid = ZERO
|
||||
@@ -52,9 +57,11 @@ contains
|
||||
if (ierr .ne. FEM_SUCCESS) then
|
||||
iter = 0
|
||||
res_norm = ZERO
|
||||
failure_class = LS_FAIL_DIAGNOSTIC
|
||||
reason_text = 'csr-analysis-failure'
|
||||
call linear_solver_record(method, preconditioner, iter, res_norm, &
|
||||
status, matrix_class, initial_resid, &
|
||||
final_rel_resid)
|
||||
final_rel_resid, failure_class, reason_text)
|
||||
return
|
||||
end if
|
||||
matrix_class = profile%class_id
|
||||
@@ -63,9 +70,11 @@ contains
|
||||
if (ierr .ne. FEM_SUCCESS) then
|
||||
iter = 0
|
||||
res_norm = ZERO
|
||||
failure_class = LS_FAIL_DIAGNOSTIC
|
||||
reason_text = 'initial-residual-audit-failure'
|
||||
call linear_solver_record(method, preconditioner, iter, res_norm, &
|
||||
status, matrix_class, initial_resid, &
|
||||
final_rel_resid)
|
||||
final_rel_resid, failure_class, reason_text)
|
||||
return
|
||||
end if
|
||||
|
||||
@@ -84,26 +93,34 @@ contains
|
||||
case default
|
||||
iter = 0
|
||||
res_norm = ZERO
|
||||
failure_class = LS_FAIL_CONFIGURATION
|
||||
reason_text = 'unknown-linear-solver-method'
|
||||
call error_set(FEM_ERR_SOLVER, 'unknown linear solver method', ierr)
|
||||
end select
|
||||
|
||||
if (ierr .ne. FEM_SUCCESS) then
|
||||
if (failure_class .eq. LS_FAIL_NONE) then
|
||||
failure_class = linear_solver_classify_failure(method, matrix_class)
|
||||
call linear_solver_reason_text(method, failure_class, reason_text)
|
||||
end if
|
||||
call csr_residual_norm(a, b, x, final_resid, final_rel_resid, &
|
||||
audit_ierr)
|
||||
if (audit_ierr .eq. FEM_SUCCESS) res_norm = final_resid
|
||||
call linear_solver_record(method, preconditioner, iter, res_norm, &
|
||||
status, matrix_class, initial_resid, &
|
||||
final_rel_resid)
|
||||
final_rel_resid, failure_class, reason_text)
|
||||
return
|
||||
end if
|
||||
|
||||
status = LS_STATUS_CONVERGED
|
||||
failure_class = LS_FAIL_NONE
|
||||
call linear_solver_reason_text(method, failure_class, reason_text)
|
||||
call csr_residual_norm(a, b, x, final_resid, final_rel_resid, &
|
||||
audit_ierr)
|
||||
if (audit_ierr .eq. FEM_SUCCESS) res_norm = final_resid
|
||||
call linear_solver_record(method, preconditioner, iter, res_norm, &
|
||||
status, matrix_class, initial_resid, &
|
||||
final_rel_resid)
|
||||
final_rel_resid, failure_class, reason_text)
|
||||
end subroutine linear_solver_solve
|
||||
|
||||
subroutine linear_solver_configure(method, preconditioner, ierr)
|
||||
@@ -174,9 +191,20 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine linear_solver_get_diagnostics
|
||||
|
||||
subroutine linear_solver_get_fail_info(failure_class, reason, ierr)
|
||||
integer, intent(out) :: failure_class
|
||||
character(len=*), intent(out) :: reason
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
failure_class = linsol_last_fail_class
|
||||
reason = linear_solver_last_reason
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine linear_solver_get_fail_info
|
||||
|
||||
subroutine linear_solver_record(method, preconditioner, iteration, &
|
||||
residual_norm, status_code, matrix_class, &
|
||||
initial_residual, relative_residual)
|
||||
initial_residual, relative_residual, &
|
||||
failure_class, reason)
|
||||
integer, intent(in) :: method
|
||||
integer, intent(in) :: preconditioner
|
||||
integer, intent(in) :: iteration
|
||||
@@ -185,6 +213,8 @@ contains
|
||||
integer, intent(in) :: matrix_class
|
||||
real(rk), intent(in) :: initial_residual
|
||||
real(rk), intent(in) :: relative_residual
|
||||
integer, intent(in) :: failure_class
|
||||
character(len=*), intent(in) :: reason
|
||||
|
||||
linear_solver_last_method = method
|
||||
linear_solver_last_prec = preconditioner
|
||||
@@ -194,6 +224,57 @@ contains
|
||||
linear_solver_last_matrix_class = matrix_class
|
||||
linear_solver_initial_resid = initial_residual
|
||||
linear_solver_relative_resid = relative_residual
|
||||
linsol_last_fail_class = failure_class
|
||||
linear_solver_last_reason = reason
|
||||
end subroutine linear_solver_record
|
||||
|
||||
integer function linear_solver_classify_failure(method, matrix_class) &
|
||||
result(failure_class)
|
||||
integer, intent(in) :: method
|
||||
integer, intent(in) :: matrix_class
|
||||
|
||||
select case (method)
|
||||
case (LSOLVER_CG)
|
||||
if (matrix_class .lt. CSR_CLASS_SPD_CAND) then
|
||||
failure_class = LS_FAIL_INVALID_MATRIX
|
||||
else
|
||||
failure_class = LS_FAIL_NONCONVERGENCE
|
||||
end if
|
||||
case (LSOLVER_DENSE)
|
||||
failure_class = LS_FAIL_DENSE_FALLBACK
|
||||
case (LSOLVER_BICGSTAB, LSOLVER_GMRES)
|
||||
failure_class = LS_FAIL_NONCONVERGENCE
|
||||
case default
|
||||
failure_class = LS_FAIL_CONFIGURATION
|
||||
end select
|
||||
end function linear_solver_classify_failure
|
||||
|
||||
subroutine linear_solver_reason_text(method, failure_class, reason)
|
||||
integer, intent(in) :: method
|
||||
integer, intent(in) :: failure_class
|
||||
character(len=*), intent(out) :: reason
|
||||
character(len=24) :: method_name
|
||||
character(len=40) :: class_name
|
||||
|
||||
select case (method)
|
||||
case (LSOLVER_CG)
|
||||
method_name = 'cg'
|
||||
case (LSOLVER_BICGSTAB)
|
||||
method_name = 'bicgstab'
|
||||
case (LSOLVER_GMRES)
|
||||
method_name = 'gmres'
|
||||
case (LSOLVER_DENSE)
|
||||
method_name = 'dense'
|
||||
case default
|
||||
method_name = 'unknown'
|
||||
end select
|
||||
|
||||
call linsol_fail_class_name(failure_class, class_name)
|
||||
if (failure_class .eq. LS_FAIL_NONE) then
|
||||
reason = trim(method_name)//'-selected'
|
||||
else
|
||||
reason = trim(method_name)//'-'//trim(class_name)
|
||||
end if
|
||||
end subroutine linear_solver_reason_text
|
||||
|
||||
end module fem_linear_solver_dispatch
|
||||
|
||||
@@ -280,6 +280,7 @@ contains
|
||||
convergence_last_accepted_time = current_time
|
||||
convergence_status_code = CONVERGENCE_STATUS_ITERATING
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
nlc_last_target_dt = ZERO
|
||||
nlc_last_actual_dt = ZERO
|
||||
nlc_next_target_dt = ZERO
|
||||
|
||||
@@ -64,10 +64,17 @@ contains
|
||||
convergence_correction_norm = ZERO
|
||||
convergence_contact_gap_norm = ZERO
|
||||
convergence_combined_norm = ZERO
|
||||
convergence_total_resid_norm = ZERO
|
||||
convergence_force_resid_norm = ZERO
|
||||
convergence_contact_resid_norm = ZERO
|
||||
convergence_cons_resid_norm = ZERO
|
||||
convergence_arc_resid_norm = ZERO
|
||||
convergence_material_fail_count = 0
|
||||
convergence_last_dt = dt
|
||||
convergence_converged = .false.
|
||||
convergence_status_code = CONVERGENCE_STATUS_ITERATING
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
end subroutine begin_newmark_convergence
|
||||
|
||||
subroutine begin_static_convergence(increment_id, dt_inc)
|
||||
@@ -81,10 +88,17 @@ contains
|
||||
convergence_correction_norm = ZERO
|
||||
convergence_contact_gap_norm = ZERO
|
||||
convergence_combined_norm = ZERO
|
||||
convergence_total_resid_norm = ZERO
|
||||
convergence_force_resid_norm = ZERO
|
||||
convergence_contact_resid_norm = ZERO
|
||||
convergence_cons_resid_norm = ZERO
|
||||
convergence_arc_resid_norm = ZERO
|
||||
convergence_material_fail_count = 0
|
||||
convergence_last_dt = dt_inc
|
||||
convergence_converged = .false.
|
||||
convergence_status_code = CONVERGENCE_STATUS_ITERATING
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
nlc_last_damping = ONE
|
||||
nlc_last_merit_ratio = ZERO
|
||||
nlc_last_rejections = 0
|
||||
@@ -131,14 +145,25 @@ contains
|
||||
convergence_converged = .true.
|
||||
convergence_status_code = CONVERGENCE_STATUS_CONVERGED
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
end subroutine mark_convergence_success
|
||||
|
||||
subroutine mark_convergence_failure(failure_code)
|
||||
subroutine mark_convergence_failure(failure_code, reason_id)
|
||||
integer, intent(in) :: failure_code
|
||||
integer, intent(in), optional :: reason_id
|
||||
|
||||
convergence_converged = .false.
|
||||
convergence_status_code = CONVERGENCE_STATUS_FAILED
|
||||
convergence_failure_code = failure_code
|
||||
if (present(reason_id)) then
|
||||
convergence_failure_reason_id = reason_id
|
||||
else if (failure_code .eq. CONV_FAIL_NONCONVERGENCE .and. &
|
||||
linear_solver_last_status .eq. LS_STATUS_FAILED) then
|
||||
convergence_failure_reason_id = NFAIL_LINEAR_SOLVE
|
||||
else
|
||||
convergence_failure_reason_id = &
|
||||
convergence_reason_from_failure(failure_code)
|
||||
end if
|
||||
end subroutine mark_convergence_failure
|
||||
|
||||
subroutine update_convergence_metrics(res_norm, ref_norm)
|
||||
@@ -154,6 +179,10 @@ contains
|
||||
if (allocated(contact_pair_gap_residual)) then
|
||||
convergence_contact_gap_norm = maxval(contact_pair_gap_residual)
|
||||
end if
|
||||
convergence_total_resid_norm = res_norm
|
||||
convergence_force_resid_norm = res_norm
|
||||
convergence_contact_resid_norm = convergence_contact_gap_norm
|
||||
convergence_cons_resid_norm = ZERO
|
||||
convergence_combined_norm = max(convergence_rel_resid_norm, &
|
||||
max(convergence_correction_norm, convergence_contact_gap_norm))
|
||||
end subroutine update_convergence_metrics
|
||||
|
||||
@@ -60,6 +60,7 @@ contains
|
||||
if (.not. arc_disp_mode) then
|
||||
convergence_status_code = CONVERGENCE_STATUS_FAILED
|
||||
convergence_failure_code = CONV_FAIL_STOPPED
|
||||
convergence_failure_reason_id = NFAIL_ARC_CONSTRAINT
|
||||
nlc_last_adjust = NLC_ADJ_FAILED
|
||||
call error_set(FEM_ERR_SOLVER, &
|
||||
'METHOD=ARC_LENGTH_OR_DISPLACEMENT_CONTROL requires a nonzero '// &
|
||||
@@ -342,6 +343,7 @@ contains
|
||||
current_time = sub_target_time
|
||||
convergence_last_accepted_time = current_time
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
current_step = current_step + 1
|
||||
nlc_last_iter = iter_inc
|
||||
nlc_last_actual_dt = dt_try
|
||||
@@ -435,6 +437,7 @@ contains
|
||||
convergence_last_dt = dt_try
|
||||
convergence_status_code = CONVERGENCE_STATUS_CUTBACK
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
nlc_last_adjust = NLC_ADJ_CUTBACK
|
||||
nlc_next_target_dt = dt_try
|
||||
call error_clear(ierr)
|
||||
@@ -448,6 +451,11 @@ contains
|
||||
if (use_static_predictor) u = u_equil
|
||||
convergence_status_code = CONVERGENCE_STATUS_FAILED
|
||||
convergence_failure_code = CONV_FAIL_CUTBACK_LIMIT
|
||||
if (linear_solver_last_status .eq. LS_STATUS_FAILED) then
|
||||
convergence_failure_reason_id = NFAIL_LINEAR_SOLVE
|
||||
else
|
||||
convergence_failure_reason_id = NFAIL_MIN_STEP
|
||||
end if
|
||||
nlc_last_adjust = NLC_ADJ_FAILED
|
||||
nlc_next_target_dt = ZERO
|
||||
end subroutine fail_static_increment
|
||||
@@ -503,6 +511,7 @@ contains
|
||||
current_time = sub_target_time
|
||||
convergence_last_accepted_time = current_time
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
current_step = current_step + 1
|
||||
nlc_last_iter = iter_inc
|
||||
nlc_last_actual_dt = dt_try
|
||||
@@ -521,12 +530,18 @@ contains
|
||||
convergence_last_dt = dt_try
|
||||
convergence_status_code = CONVERGENCE_STATUS_CUTBACK
|
||||
convergence_failure_code = CONV_FAIL_NONE
|
||||
convergence_failure_reason_id = NFAIL_NONE
|
||||
nlc_last_adjust = NLC_ADJ_CUTBACK
|
||||
nlc_next_target_dt = dt_try
|
||||
ierr = FEM_SUCCESS
|
||||
else
|
||||
convergence_status_code = CONVERGENCE_STATUS_FAILED
|
||||
convergence_failure_code = CONV_FAIL_CUTBACK_LIMIT
|
||||
if (linear_solver_last_status .eq. LS_STATUS_FAILED) then
|
||||
convergence_failure_reason_id = NFAIL_LINEAR_SOLVE
|
||||
else
|
||||
convergence_failure_reason_id = NFAIL_MIN_STEP
|
||||
end if
|
||||
nlc_last_adjust = NLC_ADJ_FAILED
|
||||
nlc_next_target_dt = ZERO
|
||||
return
|
||||
@@ -999,6 +1014,7 @@ contains
|
||||
iter_used = iter
|
||||
call record_convergence_iteration(iter, res_norm, ref_norm, &
|
||||
correction_norm)
|
||||
convergence_arc_resid_norm = abs(arc_residual)
|
||||
if ((res_norm .le. tol .or. res_norm / ref_norm .le. tol) .and. &
|
||||
abs(arc_residual) .le. arc_tol) then
|
||||
converged = .true.
|
||||
|
||||
Reference in New Issue
Block a user