diff --git a/docs/03_detailed_design.md b/docs/03_detailed_design.md index d5a55d6..e2b7c45 100644 --- a/docs/03_detailed_design.md +++ b/docs/03_detailed_design.md @@ -780,10 +780,32 @@ subroutine fem_solve_static_nonlinear(max_increment, max_iter, tol, & integer, intent(out) :: ierr end subroutine -subroutine fem_get_static_convergence(nincrement, niter, residual, ierr) - integer, intent(out) :: nincrement - integer, intent(out) :: niter - real(rk), intent(out) :: residual +subroutine fem_get_convergence_status(increment, iteration, residual_norm, & + correction_norm, converged, ierr) + integer, intent(out) :: increment + integer, intent(out) :: iteration + real(rk), intent(out) :: residual_norm + real(rk), intent(out) :: correction_norm + logical, intent(out) :: converged + integer, intent(out) :: ierr +end subroutine + +subroutine fem_get_convergence_metrics(relative_residual_norm, & + contact_gap_norm, combined_norm, ierr) + real(rk), intent(out) :: relative_residual_norm + real(rk), intent(out) :: contact_gap_norm + real(rk), intent(out) :: combined_norm + integer, intent(out) :: ierr +end subroutine + +subroutine fem_get_convergence_diagnostics(cutback_count, last_dt, & + last_accepted_time, status_code, & + failure_code, ierr) + integer, intent(out) :: cutback_count + real(rk), intent(out) :: last_dt + real(rk), intent(out) :: last_accepted_time + integer, intent(out) :: status_code + integer, intent(out) :: failure_code integer, intent(out) :: ierr end subroutine ``` @@ -839,6 +861,7 @@ end subroutine - 每个非线性增量保存材料状态和单元状态备份,迭代试算前恢复,收敛后提交,失败后回滚。 - Robin、MPC、刚性平面 penalty contact 和面-面 contact pair 的切线进入 Newton 有效刚度。 - 静力和非线性 Newmark 均支持线搜索;可选步长缩减在失败时恢复增量起点状态后重试。 +- V4.5 起,`fem_control` 保存最近一次求解收敛快照、relative residual、contact gap residual、combined norm、cutback 诊断、最后有效时间和失败原因码,供 Fortran API、C ABI 和测试直接查询。 ## 17. 稀疏矩阵模块 diff --git a/docs/04_mathematical_model_and_algorithms.md b/docs/04_mathematical_model_and_algorithms.md index de6f1ec..f70fcef 100644 --- a/docs/04_mathematical_model_and_algorithms.md +++ b/docs/04_mathematical_model_and_algorithms.md @@ -758,6 +758,17 @@ K_eff Delta_u = R 当前实现中 `K_eff` 使用当前实体材料算法切线、壳 section 塑性算法切线、集中质量矩阵、Rayleigh 阻尼和外部约束/接触切线形成。收敛判据使用绝对力残差和相对力残差,Dirichlet 约束自由度的位移增量残差置零。非线性 Newmark 支持线搜索;可选步长缩减在单步失败时恢复运动学量和材料 trial 状态后重试。 +V4.5 起,静力和隐式求解共享最近一次收敛诊断状态: + +- `increment / iteration` 记录当前增量和 Newton 迭代。 +- `residual_norm / relative_residual_norm / correction_norm` 记录最近一次绝对力残差、相对力残差和位移修正范数。 +- `contact_gap_norm` 记录最近一次接触力评估中的最大 contact gap residual;面-面 contact pair 当前使用已有 gap residual/mortar 权重诊断源。 +- `combined_norm` 取相对力残差、位移修正范数和 contact gap residual 的最大值,作为统一多准则诊断量。 +- `cutback_count / last_dt / last_accepted_time` 记录累计步长缩减次数、最后尝试步长和最后有效求解时间。 +- `status_code` 区分 idle、iterating、converged、cutback 和 failed。 +- `failure_code` 区分无失败、Newton 不收敛、cutback 耗尽和运行未到终点。 +- 当前硬停止条件仍使用绝对/相对力残差;contact gap residual 先进入 diagnostics 和测试覆盖,后续可在接触算例标定后升级为可选硬准则。 + 当前限制: - Rayleigh 阻尼已在线性 Newmark 和非线性 Newmark-Newton 骨架中接入。 diff --git a/docs/05_interface_control_document.md b/docs/05_interface_control_document.md index 2b6d1d5..98b61fd 100644 --- a/docs/05_interface_control_document.md +++ b/docs/05_interface_control_document.md @@ -543,6 +543,25 @@ subroutine fem_get_convergence_status(increment, iteration, residual_norm, & logical, intent(out) :: converged integer, intent(out) :: ierr end subroutine + +subroutine fem_get_convergence_metrics(relative_residual_norm, & + contact_gap_norm, combined_norm, ierr) + real(rk), intent(out) :: relative_residual_norm + real(rk), intent(out) :: contact_gap_norm + real(rk), intent(out) :: combined_norm + integer, intent(out) :: ierr +end subroutine + +subroutine fem_get_convergence_diagnostics(cutback_count, last_dt, & + last_accepted_time, status_code, & + failure_code, ierr) + integer, intent(out) :: cutback_count + real(rk), intent(out) :: last_dt + real(rk), intent(out) :: last_accepted_time + integer, intent(out) :: status_code + integer, intent(out) :: failure_code + integer, intent(out) :: ierr +end subroutine ``` 说明: @@ -552,7 +571,15 @@ end subroutine - `residual_norm` 为最近一次力残差范数。 - `correction_norm` 为最近一次位移修正范数;线性路径或尚未形成修正时为 0。 - `converged` 表示最近一次记录的增量是否已满足收敛准则。 -- V4.5 起,非线性静力 Newton 迭代会实时更新该状态;后续 cutback 和多准则收敛诊断沿用同一查询口径。 +- `relative_residual_norm` 为力残差相对参考外力范数的比值。 +- `contact_gap_norm` 为最近一次接触力评估中的最大 contact gap residual。 +- `combined_norm` 为相对力残差、位移修正范数和 contact gap residual 的最大值,用于统一诊断多准则收敛状态。 +- `cutback_count` 为最近一次静力/非线性 Newmark 运行累计触发的步长缩减次数。 +- `last_dt` 为最近一次记录的静力增量长度或 Newmark 时间步长。 +- `last_accepted_time` 为最近一次已提交成功的求解时间;失败并回滚时保持为最后有效时间。 +- `status_code` 使用 `CONVERGENCE_STATUS_IDLE=0`、`ITERATING=1`、`CONVERGED=2`、`CUTBACK=3`、`FAILED=-1`。 +- `failure_code` 使用 `CONV_FAIL_NONE=0`、`CONV_FAIL_NONCONVERGENCE=1`、`CONV_FAIL_CUTBACK_LIMIT=2`、`CONV_FAIL_STOPPED=3`。 +- V4.5 起,非线性静力 Newton 迭代、静力 cutback 失败路径、非线性 Newmark cutback 运行和接触力评估会更新该状态;contact gap/mortar residual 当前作为 diagnostics 进入多准则统计,硬收敛判据仍以力残差为主。 ### 12.6 接触状态 @@ -914,4 +941,6 @@ fem_finalize - C ABI 追加 `femlite_get_contact_perf_stats`,返回 contact search/force/tangent CPU 时间统计。 - C ABI 追加 `femlite_get_contact_cache_stats`,返回 BVH 候选缓存使用和溢出统计。 - C ABI 暴露 `femlite_get_convergence_status`,其中 `converged` 使用 `int` 返回 0/1。 +- C ABI 暴露 `femlite_get_convergence_metrics`,返回相对力残差、contact gap residual 和 combined norm。 +- C ABI 暴露 `femlite_get_convergence_diagnostics`,返回 cutback 次数、最后步长、最后有效时间、收敛状态码和失败原因码。 - 上述函数只追加新符号,不改变 `femlite_get_contact_summary` 的签名和含义。 diff --git a/docs/06_test_and_verification_plan.md b/docs/06_test_and_verification_plan.md index dc326b0..0f69496 100644 --- a/docs/06_test_and_verification_plan.md +++ b/docs/06_test_and_verification_plan.md @@ -251,7 +251,7 @@ SPH总力映射测试 relative tolerance 1.0e-10 to 1.0e-8 - 线性静力实体 patch test。 - 线性静力壳 patch test。 - 非线性静力 Newton 收敛。 -- 非线性静力收敛状态查询,检查最新增量、迭代号、残差范数、修正范数和收敛标志。 +- 非线性静力收敛状态查询,检查最新增量、迭代号、残差范数、修正范数、cutback 次数、最后步长、最后有效时间、状态码、失败原因码和收敛标志。 - 非线性静力步长缩减。 - 非线性静力线搜索和失败回滚测试。 - 隐式 Newmark 单步预测校正。 @@ -298,7 +298,7 @@ SPH总力映射测试 relative tolerance 1.0e-10 to 1.0e-8 - `fem_get_contact_search_stats` 和 C ABI `femlite_get_contact_search_stats` 返回 contact pair 搜索 facet/master/candidate/active/BVH 节点统计。 - `fem_get_contact_perf_stats` 和 C ABI `femlite_get_contact_perf_stats` 返回 contact search/force/tangent CPU 时间统计。 - `fem_get_contact_cache_stats` 和 C ABI `femlite_get_contact_cache_stats` 返回 BVH 候选缓存使用和溢出统计。 -- `fem_get_convergence_status` 和 C ABI `femlite_get_convergence_status` 返回最近一次求解的增量、迭代、残差、修正范数和收敛标志;空模型零状态和非线性静力收敛状态均需覆盖。 +- `fem_get_convergence_status` / `fem_get_convergence_metrics` / `fem_get_convergence_diagnostics` 和 C ABI 对应包装返回最近一次求解的增量、迭代、残差、相对残差、修正范数、contact gap residual、combined norm、cutback 次数、最后步长、最后有效时间、状态码、失败原因码和收敛标志;空模型零状态、非线性静力收敛状态、contact gap 非零状态和 cutback 失败状态均需覆盖。 - 删除单元状态可输出。 示例结果留存策略: diff --git a/docs/07_user_manual.md b/docs/07_user_manual.md index a3d764c..d7a8dd2 100644 --- a/docs/07_user_manual.md +++ b/docs/07_user_manual.md @@ -16,6 +16,7 @@ FemLite 0.4.3 是船舶接触爆炸结构响应 FEM 软件的第四版接触增 - Abaqus inp 输入子集。 - element/node/analytical surface 子集、contact property 子集、刚性平面接触和面-面 contact pair 阶段能力。 - contact pair active set、gap residual 和 augmented penalty 诊断输出。 +- 静力/隐式求解的收敛状态和 cutback 诊断查询接口。 - CSV、VTK、restart 和 contact CSV 输出。 - Fortran95 原生接口、C ABI 子集和 Python 调试脚本。 @@ -238,6 +239,8 @@ kind,pair_id,active_count,max_penetration,force_norm,work_estimate,cumulative_wo `search_*` 字段在 `SUMMARY` 行给出最近一次 contact pair 力评估的全局搜索统计、BVH 候选缓存使用情况和 `cpu_time` 口径秒数;逐 `PAIR` 行给出对应接触对的搜索、缓存和计时统计。`cpu_time` 是轻量趋势诊断,小算例中可能显示为 0。 +Fortran95 API 可通过 `fem_get_convergence_status` 查询最近一次求解的增量、迭代、残差、位移修正范数和收敛标志,通过 `fem_get_convergence_metrics` 查询相对残差、contact gap residual 和 combined norm,通过 `fem_get_convergence_diagnostics` 查询 cutback 次数、最后步长、最后有效时间、状态码和失败原因码。C ABI 提供同名 `femlite_get_*` 包装,`converged` 使用 0/1 整数返回。 + 建议把大型结果输出到 `examples/.../results/...` 或独立 `output/` 目录。仓库 `.gitignore` 默认忽略大规模结果文件。 ## 10. 示例算例 diff --git a/docs/08_developer_manual.md b/docs/08_developer_manual.md index cf858ba..afef229 100644 --- a/docs/08_developer_manual.md +++ b/docs/08_developer_manual.md @@ -76,7 +76,7 @@ src/interface C ABI 和 Fortran-C bridge |---|---| | `fem_precision` | 全局精度、维度、版本常量 | | `fem_error` | 错误码和错误消息 | -| `fem_control` | 时间步、求解控制、输出控制 | +| `fem_control` | 时间步、求解控制、输出控制和 V4.5 收敛/接触 gap 诊断快照 | | `fem_api` | Fortran95 公共 API | | `fem_inp_reader` | 两遍 INP 读取主流程 | | `fem_inp_defs` | INP 模式常量 | diff --git a/docs/v4_development_plan.md b/docs/v4_development_plan.md index 1af113a..60e2d9d 100644 --- a/docs/v4_development_plan.md +++ b/docs/v4_development_plan.md @@ -676,7 +676,7 @@ FemLite 0.4.x 定位为: 后续: -- 将 gap/mortar 残差接入非线性求解统计和收敛准则。 +- gap/mortar 残差已在 V4.5 接入非线性求解统计;后续继续标定接触穿透硬收敛准则。 - 增强 contact tangent 对 active set 状态和增广路径的诊断输出。 - 将 pair 级 augmented penalty 乘子推进到 mortar 积分点级历史,并在后续 V4.x 中与摩擦历史统一调试输出。 @@ -775,24 +775,38 @@ FemLite 0.4.x 定位为: ## 26. 0.4.5 开发记录 -### V4.5 隐式非线性收敛诊断起步 +### V4.5 隐式非线性收敛诊断完善 -完成状态:V4.5 起步,新增求解收敛状态查询底座;完整自适应步长、多准则收敛和失败诊断仍继续推进。 +完成状态:V4.5 收敛诊断和 cutback 失败诊断已形成阶段完善基线;contact gap/mortar residual 已纳入多准则统计,硬接触穿透停止准则保留为后续标定项。 已完成: -- `fem_control` 新增最近一次收敛状态快照,记录增量号、Newton 迭代号、力残差范数、位移修正范数和收敛标志。 +- `fem_control` 新增最近一次收敛状态快照,记录增量号、Newton 迭代号、力残差范数、相对力残差、位移修正范数、contact gap residual、combined norm 和收敛标志。 +- `fem_control` 新增收敛状态码、失败原因码、累计 cutback 次数、最后尝试步长和最后有效时间诊断。 - 非线性静力 Newton 迭代在每次残差评估后更新收敛状态,修正方程求解后同步记录位移修正范数。 +- 非线性 Newmark 单步在每次残差评估和位移修正后更新同一收敛状态快照。 +- contact force 评估将 contact pair gap residual 同步到收敛 metrics。 - 新增 Fortran API `fem_get_convergence_status`,补齐接口文档中第三版已承诺的静力/隐式收敛状态查询。 +- 新增 Fortran API `fem_get_convergence_metrics`,查询相对残差、contact gap residual 和 combined norm。 +- 新增 Fortran API `fem_get_convergence_diagnostics`,查询 cutback 次数、最后步长、最后有效时间、状态码和失败原因码。 - C ABI 新增 `femlite_get_convergence_status`,以 `int` 形式返回 `converged` 的 0/1 状态。 +- C ABI 新增 `femlite_get_convergence_metrics`。 +- C ABI 新增 `femlite_get_convergence_diagnostics`。 +- 静力 cutback 成功/失败路径和非线性 Newmark cutback 运行路径更新累计 cutback 诊断。 已补充测试: - `implicit_inp` 回归在非线性静力弹性算例后查询收敛状态,检查最后增量已收敛、残差在容限内并且迭代号有效。 +- `implicit_inp` 回归检查非线性静力成功路径 cutback 次数为 0、最后步长为 0.25、状态码为 converged。 +- `implicit_inp` 回归检查非线性静力成功路径相对残差在容限内、contact gap residual 为 0,并且 combined norm 覆盖分项 metrics。 +- `contact` 回归检查 contact pair active-set 小算例将非零 gap residual 写入 convergence metrics。 +- `solver_implicit` 回归检查非线性 Newmark 线弹性算例写出非零位移修正范数。 +- `solver_implicit` 回归检查非线性静力 cutback 失败路径累计 2 次 cutback、最后尝试步长为 0.25、最后有效时间保持为 0、状态码为 failed、失败原因为 cutback limit,且试算状态回滚。 - `c_api` 回归检查初始化和建模后、尚未求解时的收敛状态为零值且未收敛。 +- `c_api` 回归检查初始化和建模后的收敛 diagnostics 为 idle 零值。 +- `c_api` 回归检查初始化和建模后的 convergence metrics 为零值。 后续: -- 将非线性 Newmark Newton 的修正范数和失败状态接入同一查询口径。 -- 在 cutback 失败路径中补充失败原因、cutback 次数和最后有效时间步诊断。 -- 将 contact gap/mortar residual 纳入 V4.5 多准则收敛统计。 +- 标定 contact gap residual 作为可选硬收敛准则时的量纲、容限和默认开关。 +- 补充更长时间的非线性静力/非线性 Newmark 接触长跑基准。 diff --git a/include/femlite_c_api.h b/include/femlite_c_api.h index 0141834..a68a448 100644 --- a/include/femlite_c_api.h +++ b/include/femlite_c_api.h @@ -22,6 +22,14 @@ int femlite_get_convergence_status(int *increment, double *residual_norm, double *correction_norm, int *converged); +int femlite_get_convergence_metrics(double *relative_residual_norm, + double *contact_gap_norm, + double *combined_norm); +int femlite_get_convergence_diagnostics(int *cutback_count, + double *last_dt, + double *last_accepted_time, + int *status_code, + int *failure_code); int femlite_get_contact_summary(int *active_count, double *work_step, double *work_total, diff --git a/src/base/fem_api.f90 b/src/base/fem_api.f90 index d1a4cc2..1051fb0 100644 --- a/src/base/fem_api.f90 +++ b/src/base/fem_api.f90 @@ -494,18 +494,43 @@ contains end subroutine fem_get_contact_cache_stats subroutine fem_record_convergence(increment, iteration, residual_norm, & - correction_norm, converged) + correction_norm, last_dt, accepted_time, & + converged, relative_residual_norm, & + contact_gap_norm) integer, intent(in) :: increment integer, intent(in) :: iteration real(rk), intent(in) :: residual_norm real(rk), intent(in) :: correction_norm + real(rk), intent(in) :: last_dt + real(rk), intent(in) :: accepted_time logical, intent(in) :: converged + real(rk), intent(in), optional :: relative_residual_norm + real(rk), intent(in), optional :: contact_gap_norm convergence_increment = increment convergence_iteration = iteration convergence_residual_norm = residual_norm convergence_correction_norm = correction_norm + if (present(relative_residual_norm)) then + convergence_rel_resid_norm = relative_residual_norm + else + convergence_rel_resid_norm = residual_norm + end if + if (present(contact_gap_norm)) then + convergence_contact_gap_norm = contact_gap_norm + end if + convergence_combined_norm = max(convergence_rel_resid_norm, & + max(convergence_correction_norm, convergence_contact_gap_norm)) + convergence_last_dt = last_dt + convergence_last_accepted_time = accepted_time convergence_converged = converged + if (converged) then + convergence_status_code = CONVERGENCE_STATUS_CONVERGED + convergence_failure_code = CONV_FAIL_NONE + else + convergence_status_code = CONVERGENCE_STATUS_FAILED + convergence_failure_code = CONV_FAIL_NONCONVERGENCE + end if end subroutine fem_record_convergence subroutine fem_get_convergence_status(increment, iteration, residual_norm, & @@ -537,6 +562,59 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_convergence_status + subroutine fem_get_convergence_metrics(relative_residual_norm, & + contact_gap_norm, combined_norm, ierr) + real(rk), intent(out) :: relative_residual_norm + real(rk), intent(out) :: contact_gap_norm + real(rk), intent(out) :: combined_norm + integer, intent(out) :: ierr + + relative_residual_norm = ZERO + contact_gap_norm = ZERO + combined_norm = ZERO + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_convergence_metrics called before fem_initialize', ierr) + return + end if + + relative_residual_norm = convergence_rel_resid_norm + contact_gap_norm = convergence_contact_gap_norm + combined_norm = convergence_combined_norm + ierr = FEM_SUCCESS + end subroutine fem_get_convergence_metrics + + subroutine fem_get_convergence_diagnostics(cutback_count, last_dt, & + last_accepted_time, status_code, & + failure_code, ierr) + integer, intent(out) :: cutback_count + real(rk), intent(out) :: last_dt + real(rk), intent(out) :: last_accepted_time + integer, intent(out) :: status_code + integer, intent(out) :: failure_code + integer, intent(out) :: ierr + + cutback_count = 0 + last_dt = ZERO + last_accepted_time = ZERO + status_code = CONVERGENCE_STATUS_IDLE + failure_code = CONV_FAIL_NONE + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_convergence_diagnostics called before fem_initialize', ierr) + return + end if + + cutback_count = convergence_cutback_count + last_dt = convergence_last_dt + last_accepted_time = convergence_last_accepted_time + status_code = convergence_status_code + failure_code = convergence_failure_code + ierr = FEM_SUCCESS + end subroutine fem_get_convergence_diagnostics + subroutine fem_get_boundary_facet_count(num_facets, max_face_nodes, ierr) integer, intent(out) :: num_facets integer, intent(out) :: max_face_nodes @@ -1277,10 +1355,12 @@ contains return end if + convergence_cutback_count = 0 call implicit_solve_linear_static(current_time, max_iter, tol, iter, res_norm, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, .true.) + call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, & + ZERO, current_time, .true., res_norm, ZERO) current_step = current_step + 1 call log_info('implicit linear solve completed') end subroutine fem_solve_implicit_linear @@ -1302,10 +1382,13 @@ contains solve_time = current_time if (time_end .gt. ZERO) solve_time = time_end + convergence_cutback_count = 0 call implicit_solve_linear_static(solve_time, max_iter, tol, iter, res_norm, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, .true.) + call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, & + solve_time - current_time, solve_time, & + .true., res_norm, ZERO) call element_compute_internal_force(ierr, ZERO) if (ierr .ne. FEM_SUCCESS) return @@ -1366,11 +1449,13 @@ contains end if analysis_type = ANALYSIS_IMPLICIT_DYNAMIC + convergence_cutback_count = 0 call implicit_advance_newmark_linear(dt, newmark_beta, newmark_gamma, & max_iter, tol, iter, res_norm, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, .true.) + call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, & + dt, current_time + dt, .true., res_norm, ZERO) current_step = current_step + 1 current_time = current_time + dt call log_info('implicit Newmark step completed') @@ -1404,11 +1489,23 @@ contains end if analysis_type = ANALYSIS_IMPLICIT_DYNAMIC + convergence_cutback_count = 0 call implicit_newmark_nonlinear_step(dt, newmark_beta, newmark_gamma, & max_iter, tol, iter, res_norm, ierr) - if (ierr .ne. FEM_SUCCESS) return + if (ierr .ne. FEM_SUCCESS) then + call fem_record_convergence(current_step + 1, iter, res_norm, & + convergence_correction_norm, dt, & + current_time, .false., & + convergence_rel_resid_norm, & + convergence_contact_gap_norm) + return + end if - call fem_record_convergence(current_step + 1, iter, res_norm, ZERO, .true.) + call fem_record_convergence(current_step + 1, iter, res_norm, & + convergence_correction_norm, dt, & + current_time + dt, .true., & + convergence_rel_resid_norm, & + convergence_contact_gap_norm) current_step = current_step + 1 current_time = current_time + dt call log_info('nonlinear Newmark step completed') @@ -1513,6 +1610,7 @@ contains integer :: run_steps integer :: step_limit integer :: cut_count + integer :: total_cutback iter_total = 0 res_norm = ZERO @@ -1564,6 +1662,10 @@ contains dt_min_eff = dt * 1.0e-8_rk end if dt_min_eff = max(dt_min_eff, time_tol) + total_cutback = 0 + convergence_cutback_count = 0 + convergence_failure_code = CONV_FAIL_NONE + convergence_last_accepted_time = current_time do remaining = time_end - current_time @@ -1580,11 +1682,21 @@ contains dt_step * cutback_factor .ge. dt_min_eff) then dt_step = dt_step * cutback_factor cut_count = cut_count + 1 + total_cutback = total_cutback + 1 + convergence_cutback_count = total_cutback + convergence_last_dt = dt_step + convergence_status_code = CONVERGENCE_STATUS_CUTBACK + convergence_failure_code = CONV_FAIL_NONE ierr = FEM_SUCCESS else + convergence_cutback_count = total_cutback + convergence_status_code = CONVERGENCE_STATUS_FAILED + convergence_failure_code = CONV_FAIL_CUTBACK_LIMIT return end if end do + convergence_cutback_count = total_cutback + convergence_last_accepted_time = current_time iter_total = iter_total + iter run_steps = run_steps + 1 @@ -1600,6 +1712,8 @@ contains if (time_end - current_time .gt. time_tol) then call error_set(FEM_ERR_SOLVER, & 'nonlinear Newmark run stopped before end time', ierr) + convergence_status_code = CONVERGENCE_STATUS_FAILED + convergence_failure_code = CONV_FAIL_STOPPED return end if diff --git a/src/base/fem_control.f90 b/src/base/fem_control.f90 index 857ddf9..4d506e9 100644 --- a/src/base/fem_control.f90 +++ b/src/base/fem_control.f90 @@ -6,6 +6,15 @@ module fem_control integer, parameter :: ANALYSIS_STATIC_LINEAR = 2 integer, parameter :: ANALYSIS_STATIC_NONLINEAR = 3 integer, parameter :: ANALYSIS_IMPLICIT_DYNAMIC = 4 + integer, parameter :: CONVERGENCE_STATUS_IDLE = 0 + integer, parameter :: CONVERGENCE_STATUS_ITERATING = 1 + integer, parameter :: CONVERGENCE_STATUS_CONVERGED = 2 + integer, parameter :: CONVERGENCE_STATUS_CUTBACK = 3 + integer, parameter :: CONVERGENCE_STATUS_FAILED = -1 + integer, parameter :: CONV_FAIL_NONE = 0 + integer, parameter :: CONV_FAIL_NONCONVERGENCE = 1 + integer, parameter :: CONV_FAIL_CUTBACK_LIMIT = 2 + integer, parameter :: CONV_FAIL_STOPPED = 3 real(rk) :: time_start = ZERO real(rk) :: time_end = ZERO @@ -36,8 +45,16 @@ module fem_control integer :: output_interval = 1 integer :: convergence_increment = 0 integer :: convergence_iteration = 0 + integer :: convergence_cutback_count = 0 + integer :: convergence_status_code = CONVERGENCE_STATUS_IDLE + integer :: convergence_failure_code = CONV_FAIL_NONE real(rk) :: convergence_residual_norm = ZERO + real(rk) :: convergence_rel_resid_norm = ZERO real(rk) :: convergence_correction_norm = ZERO + real(rk) :: convergence_contact_gap_norm = ZERO + real(rk) :: convergence_combined_norm = ZERO + real(rk) :: convergence_last_dt = ZERO + real(rk) :: convergence_last_accepted_time = ZERO logical :: convergence_converged = .false. logical :: use_sph_coupling = .false. logical :: use_user_dt = .false. @@ -77,8 +94,16 @@ contains output_interval = 1 convergence_increment = 0 convergence_iteration = 0 + convergence_cutback_count = 0 + convergence_status_code = CONVERGENCE_STATUS_IDLE + convergence_failure_code = CONV_FAIL_NONE convergence_residual_norm = ZERO + convergence_rel_resid_norm = ZERO convergence_correction_norm = ZERO + convergence_contact_gap_norm = ZERO + convergence_combined_norm = ZERO + convergence_last_dt = ZERO + convergence_last_accepted_time = ZERO convergence_converged = .false. use_sph_coupling = .false. use_user_dt = .false. diff --git a/src/boundary/fem_contact.f90 b/src/boundary/fem_contact.f90 index 54131e1..44ae373 100644 --- a/src/boundary/fem_contact.f90 +++ b/src/boundary/fem_contact.f90 @@ -1,6 +1,7 @@ module fem_contact use fem_precision use fem_error + use fem_control use fem_database use fem_sparse_csr use fem_coupling @@ -53,6 +54,7 @@ contains return end if call contact_finalize_status() + call contact_update_convergence_gap() call cpu_time(time_finish) call contact_record_force_time(time_finish - time_start) @@ -372,6 +374,15 @@ contains pair_has_analytic_master = trim(surface_type(surface_id)) .eq. 'ANALYTICAL' end function pair_has_analytic_master + subroutine contact_update_convergence_gap() + convergence_contact_gap_norm = ZERO + if (allocated(contact_pair_gap_residual)) then + convergence_contact_gap_norm = maxval(contact_pair_gap_residual) + end if + convergence_combined_norm = max(convergence_rel_resid_norm, & + max(convergence_correction_norm, convergence_contact_gap_norm)) + end subroutine contact_update_convergence_gap + subroutine pair_analytic_plane(pair, normal, offset, ierr) integer, intent(in) :: pair real(rk), intent(out) :: normal(NDIM) diff --git a/src/interface/fem_c_api.c b/src/interface/fem_c_api.c index dc49931..fbebad1 100644 --- a/src/interface/fem_c_api.c +++ b/src/interface/fem_c_api.c @@ -21,6 +21,8 @@ #define F_GET_TIME FC_GLOBAL(femlite_f_get_time, FEMLITE_F_GET_TIME) #define F_GET_SIZE FC_GLOBAL(femlite_f_get_size, FEMLITE_F_GET_SIZE) #define F_GET_CONVERGENCE FC_GLOBAL(femlite_f_get_convergence, FEMLITE_F_GET_CONVERGENCE) +#define F_GET_CONV_METRICS FC_GLOBAL(femlite_f_get_conv_metrics, FEMLITE_F_GET_CONV_METRICS) +#define F_GET_CONV_DIAG FC_GLOBAL(femlite_f_get_conv_diag, FEMLITE_F_GET_CONV_DIAG) #define F_GET_CONTACT_SUMMARY FC_GLOBAL(femlite_f_get_contact_summary, FEMLITE_F_GET_CONTACT_SUMMARY) #define F_GET_CONTACT_DIAG FC_GLOBAL(femlite_f_get_contact_diag, FEMLITE_F_GET_CONTACT_DIAG) #define F_GET_CONTACT_FRICTION FC_GLOBAL(femlite_f_get_contact_friction, FEMLITE_F_GET_CONTACT_FRICTION) @@ -55,6 +57,16 @@ extern void F_GET_CONVERGENCE(int *increment, double *correction_norm, int *converged, int *ierr); +extern void F_GET_CONV_METRICS(double *relative_residual_norm, + double *contact_gap_norm, + double *combined_norm, + int *ierr); +extern void F_GET_CONV_DIAG(int *cutback_count, + double *last_dt, + double *last_accepted_time, + int *status_code, + int *failure_code, + int *ierr); extern void F_GET_CONTACT_SUMMARY(int *active_count, double *work_step, double *work_total, @@ -263,6 +275,35 @@ int femlite_get_convergence_status(int *increment, return ierr; } +int femlite_get_convergence_metrics(double *relative_residual_norm, + double *contact_gap_norm, + double *combined_norm) +{ + int ierr = 0; + if (!relative_residual_norm || !contact_gap_norm || !combined_norm) { + return -1; + } + F_GET_CONV_METRICS(relative_residual_norm, contact_gap_norm, + combined_norm, &ierr); + return ierr; +} + +int femlite_get_convergence_diagnostics(int *cutback_count, + double *last_dt, + double *last_accepted_time, + int *status_code, + int *failure_code) +{ + int ierr = 0; + if (!cutback_count || !last_dt || !last_accepted_time || + !status_code || !failure_code) { + return -1; + } + F_GET_CONV_DIAG(cutback_count, last_dt, last_accepted_time, + status_code, failure_code, &ierr); + return ierr; +} + int femlite_get_contact_summary(int *active_count, double *work_step, double *work_total, diff --git a/src/interface/fem_fortran_bridge.f90 b/src/interface/fem_fortran_bridge.f90 index d11a7d7..7b9126a 100644 --- a/src/interface/fem_fortran_bridge.f90 +++ b/src/interface/fem_fortran_bridge.f90 @@ -180,6 +180,38 @@ subroutine femlite_f_get_convergence(increment, iteration, residual_norm, & end if end subroutine femlite_f_get_convergence +subroutine femlite_f_get_conv_metrics(relative_residual_norm, & + contact_gap_norm, combined_norm, ierr) + use fem_api + use fem_precision + implicit none + real(rk), intent(out) :: relative_residual_norm + real(rk), intent(out) :: contact_gap_norm + real(rk), intent(out) :: combined_norm + integer, intent(out) :: ierr + + call fem_get_convergence_metrics(relative_residual_norm, & + contact_gap_norm, combined_norm, ierr) +end subroutine femlite_f_get_conv_metrics + +subroutine femlite_f_get_conv_diag(cutback_count, last_dt, & + last_accepted_time, status_code, & + failure_code, ierr) + use fem_api + use fem_precision + implicit none + integer, intent(out) :: cutback_count + real(rk), intent(out) :: last_dt + real(rk), intent(out) :: last_accepted_time + integer, intent(out) :: status_code + integer, intent(out) :: failure_code + integer, intent(out) :: ierr + + call fem_get_convergence_diagnostics(cutback_count, last_dt, & + last_accepted_time, status_code, & + failure_code, ierr) +end subroutine femlite_f_get_conv_diag + subroutine femlite_f_clear_sph(ierr) use fem_api implicit none diff --git a/src/solver/fem_solver_implicit.f90 b/src/solver/fem_solver_implicit.f90 index 8647e56..4a4c82a 100644 --- a/src/solver/fem_solver_implicit.f90 +++ b/src/solver/fem_solver_implicit.f90 @@ -143,6 +143,11 @@ contains iter_total = 0 res_norm = ZERO + convergence_cutback_count = 0 + convergence_last_dt = ZERO + convergence_last_accepted_time = current_time + convergence_status_code = CONVERGENCE_STATUS_ITERATING + convergence_failure_code = CONV_FAIL_NONE if (ndof .le. 0) then call error_set(FEM_ERR_SOLVER, 'nonlinear static solve requires positive ndof', ierr) @@ -209,6 +214,8 @@ contains if (ierr .eq. FEM_SUCCESS) then iter_total = iter_total + iter_inc current_time = sub_target_time + convergence_last_accepted_time = current_time + convergence_failure_code = CONV_FAIL_NONE current_step = current_step + 1 dt_try = target_time - current_time cut_count = 0 @@ -216,8 +223,14 @@ contains abs(dt_try * cutback_factor) .ge. dt_min_eff) then dt_try = dt_try * cutback_factor cut_count = cut_count + 1 + convergence_cutback_count = convergence_cutback_count + 1 + convergence_last_dt = dt_try + convergence_status_code = CONVERGENCE_STATUS_CUTBACK + convergence_failure_code = CONV_FAIL_NONE ierr = FEM_SUCCESS else + convergence_status_code = CONVERGENCE_STATUS_FAILED + convergence_failure_code = CONV_FAIL_CUTBACK_LIMIT return end if end do @@ -447,6 +460,7 @@ contains iter_used = 0 res_norm = ZERO + call begin_newmark_convergence(dt) ref_norm = ONE trial_res_norm = ZERO trial_ref_norm = ONE @@ -490,8 +504,11 @@ contains kdamp, res_norm, ref_norm, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 iter_used = iter + call record_convergence_iteration(iter, res_norm, ref_norm, & + convergence_correction_norm) if (res_norm .le. tol .or. res_norm / ref_norm .le. tol) then converged = .true. + call mark_convergence_success() if (allocated(freaction)) then freaction = fint + mass_diag * a + damping_force - external end if @@ -503,24 +520,19 @@ contains call newmark_nl_solve_corr(kmat, target_time, a0, a1, residual, & rhs_corr, du, max_iter, tol, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call record_convergence_correction(sqrt(sum(du * du)), res_norm, & + ref_norm) u_base = u - if (use_line_search) then - call nonlinear_newmark_line_search(target_time, dt, a0, a1, & - u_pred, v_pred, u_base, du, & - res_norm, residual, external, & - damping_force, kdamp, & - trial_res_norm, trial_ref_norm, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - else - u = u + du - call boundary_apply_dirichlet(target_time, ierr) - if (ierr .ne. FEM_SUCCESS) go to 900 - end if + call nonlinear_newmark_apply_update(target_time, dt, a0, a1, u_pred, & + v_pred, u_base, du, res_norm, ref_norm, residual, external, & + damping_force, kdamp, trial_res_norm, trial_ref_norm, ierr) + if (ierr .ne. FEM_SUCCESS) go to 900 end do if (.not. converged) then call error_set(FEM_ERR_SOLVER, 'nonlinear Newmark Newton iteration did not converge', ierr) + call mark_convergence_failure(CONV_FAIL_NONCONVERGENCE) go to 900 end if @@ -745,6 +757,46 @@ contains ierr = FEM_SUCCESS end subroutine nonlinear_newmark_line_search + subroutine nonlinear_newmark_apply_update(target_time, dt, a0, a1, & + u_pred, v_pred, u_base, du, & + res_norm, ref_norm, residual, & + external, damping_force, kdamp, & + trial_res_norm, trial_ref_norm, & + ierr) + real(rk), intent(in) :: target_time + real(rk), intent(in) :: dt + real(rk), intent(in) :: a0 + real(rk), intent(in) :: a1 + real(rk), intent(in) :: u_pred(ndof) + real(rk), intent(in) :: v_pred(ndof) + real(rk), intent(in) :: u_base(ndof) + real(rk), intent(in) :: du(ndof) + real(rk), intent(inout) :: res_norm + real(rk), intent(inout) :: ref_norm + real(rk), intent(inout) :: residual(ndof) + real(rk), intent(inout) :: external(ndof) + real(rk), intent(inout) :: damping_force(ndof) + real(rk), intent(inout) :: kdamp(ndof) + real(rk), intent(out) :: trial_res_norm + real(rk), intent(out) :: trial_ref_norm + integer, intent(out) :: ierr + + if (use_line_search) then + call nonlinear_newmark_line_search(target_time, dt, a0, a1, & + u_pred, v_pred, u_base, du, res_norm, residual, external, & + damping_force, kdamp, trial_res_norm, trial_ref_norm, ierr) + if (ierr .ne. FEM_SUCCESS) return + call record_line_search_metrics(res_norm, ref_norm, trial_res_norm, & + trial_ref_norm) + else + u = u + du + call boundary_apply_dirichlet(target_time, ierr) + if (ierr .ne. FEM_SUCCESS) return + end if + + ierr = FEM_SUCCESS + end subroutine nonlinear_newmark_apply_update + subroutine evaluate_newmark_trial_residual(target_time, dt, a0, a1, & u_pred, v_pred, residual, external, & damping_force, kdamp, res_norm, & @@ -852,11 +904,7 @@ contains trial_ref_norm = ONE correction_norm = ZERO converged = .false. - convergence_increment = increment_id - convergence_iteration = 0 - convergence_residual_norm = ZERO - convergence_correction_norm = ZERO - convergence_converged = .false. + call begin_static_convergence(increment_id, dt_inc) allocate(residual(ndof), external(ndof), rhs_corr(ndof), du(ndof), & u_start(ndof), u_base(ndof), stat=stat) if (stat .ne. 0) then @@ -880,13 +928,11 @@ contains res_norm, ref_norm, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 iter_used = iter - convergence_iteration = iter - convergence_residual_norm = res_norm - convergence_correction_norm = correction_norm - convergence_converged = .false. + call record_convergence_iteration(iter, res_norm, ref_norm, & + correction_norm) if (res_norm .le. tol .or. res_norm / ref_norm .le. tol) then converged = .true. - convergence_converged = .true. + call mark_convergence_success() if (allocated(freaction)) freaction = fint - external exit end if @@ -896,7 +942,7 @@ contains max_iter, tol, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 correction_norm = sqrt(sum(du * du)) - convergence_correction_norm = correction_norm + call record_convergence_correction(correction_norm, res_norm, ref_norm) u_base = u if (use_line_search) then @@ -909,6 +955,10 @@ contains call boundary_apply_dirichlet(target_time, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 end if + if (use_line_search) then + call record_line_search_metrics(res_norm, ref_norm, trial_res_norm, & + trial_ref_norm) + end if end do if (.not. converged) then @@ -924,6 +974,7 @@ contains 900 continue if (ierr .ne. FEM_SUCCESS) then if (allocated(u_start)) u = u_start + call mark_convergence_failure(CONV_FAIL_NONCONVERGENCE) call element_state_abort_trial(state_ierr) end if if (allocated(residual)) deallocate(residual) @@ -956,9 +1007,110 @@ contains res_norm = sqrt(sum(residual * residual)) ref_norm = max(ONE, sqrt(sum(external * external))) + call update_convergence_metrics(res_norm, ref_norm) ierr = FEM_SUCCESS end subroutine static_eval_residual + subroutine begin_newmark_convergence(dt) + real(rk), intent(in) :: dt + + convergence_increment = current_step + 1 + convergence_iteration = 0 + convergence_residual_norm = ZERO + convergence_rel_resid_norm = ZERO + convergence_correction_norm = ZERO + convergence_contact_gap_norm = ZERO + convergence_combined_norm = ZERO + convergence_last_dt = dt + convergence_converged = .false. + convergence_status_code = CONVERGENCE_STATUS_ITERATING + convergence_failure_code = CONV_FAIL_NONE + end subroutine begin_newmark_convergence + + subroutine begin_static_convergence(increment_id, dt_inc) + integer, intent(in) :: increment_id + real(rk), intent(in) :: dt_inc + + convergence_increment = increment_id + convergence_iteration = 0 + convergence_residual_norm = ZERO + convergence_rel_resid_norm = ZERO + convergence_correction_norm = ZERO + convergence_contact_gap_norm = ZERO + convergence_combined_norm = ZERO + convergence_last_dt = dt_inc + convergence_converged = .false. + convergence_status_code = CONVERGENCE_STATUS_ITERATING + convergence_failure_code = CONV_FAIL_NONE + end subroutine begin_static_convergence + + subroutine record_convergence_iteration(iter, res_norm, ref_norm, & + correction_norm) + integer, intent(in) :: iter + real(rk), intent(in) :: res_norm + real(rk), intent(in) :: ref_norm + real(rk), intent(in) :: correction_norm + + convergence_iteration = iter + convergence_residual_norm = res_norm + convergence_correction_norm = correction_norm + call update_convergence_metrics(res_norm, ref_norm) + convergence_converged = .false. + end subroutine record_convergence_iteration + + subroutine record_convergence_correction(correction_norm, res_norm, ref_norm) + real(rk), intent(in) :: correction_norm + real(rk), intent(in) :: res_norm + real(rk), intent(in) :: ref_norm + + convergence_correction_norm = correction_norm + call update_convergence_metrics(res_norm, ref_norm) + end subroutine record_convergence_correction + + subroutine record_line_search_metrics(res_norm, ref_norm, trial_res_norm, & + trial_ref_norm) + real(rk), intent(inout) :: res_norm + real(rk), intent(inout) :: ref_norm + real(rk), intent(in) :: trial_res_norm + real(rk), intent(in) :: trial_ref_norm + + res_norm = trial_res_norm + ref_norm = trial_ref_norm + convergence_residual_norm = res_norm + call update_convergence_metrics(res_norm, ref_norm) + end subroutine record_line_search_metrics + + subroutine mark_convergence_success() + convergence_converged = .true. + convergence_status_code = CONVERGENCE_STATUS_CONVERGED + convergence_failure_code = CONV_FAIL_NONE + end subroutine mark_convergence_success + + subroutine mark_convergence_failure(failure_code) + integer, intent(in) :: failure_code + + convergence_converged = .false. + convergence_status_code = CONVERGENCE_STATUS_FAILED + convergence_failure_code = failure_code + end subroutine mark_convergence_failure + + subroutine update_convergence_metrics(res_norm, ref_norm) + real(rk), intent(in) :: res_norm + real(rk), intent(in) :: ref_norm + + if (ref_norm .gt. tiny(ONE)) then + convergence_rel_resid_norm = res_norm / ref_norm + else + convergence_rel_resid_norm = res_norm + end if + convergence_contact_gap_norm = ZERO + if (allocated(contact_pair_gap_residual)) then + convergence_contact_gap_norm = maxval(contact_pair_gap_residual) + end if + convergence_combined_norm = max(convergence_rel_resid_norm, & + max(convergence_correction_norm, convergence_contact_gap_norm)) + end subroutine update_convergence_metrics + subroutine static_solve_correction(target_time, residual, rhs_corr, du, & max_iter, tol, ierr) real(rk), intent(in) :: target_time diff --git a/tests/interface/test_c_api.c b/tests/interface/test_c_api.c index be63e08..f2798e4 100644 --- a/tests/interface/test_c_api.c +++ b/tests/interface/test_c_api.c @@ -44,6 +44,9 @@ int main(void) int conv_increment = -1; int conv_iteration = -1; int conv_converged = -1; + int conv_cutback_count = -1; + int conv_status_code = -999; + int conv_failure_code = -999; int node_ids[1] = {2}; int facet_id[8]; int elem_id[8]; @@ -78,6 +81,11 @@ int main(void) double contact_tangent_time = -1.0; double conv_residual_norm = -1.0; double conv_correction_norm = -1.0; + double conv_last_dt = -1.0; + double conv_last_accepted_time = -1.0; + double conv_relative_residual = -1.0; + double conv_contact_gap = -1.0; + double conv_combined_norm = -1.0; ierr = femlite_initialize(); if (ierr != 0) return check_ierr(ierr, 1); @@ -104,6 +112,23 @@ int main(void) conv_residual_norm != 0.0 || conv_correction_norm != 0.0 || conv_converged != 0) return 39; + ierr = femlite_get_convergence_diagnostics(&conv_cutback_count, + &conv_last_dt, + &conv_last_accepted_time, + &conv_status_code, + &conv_failure_code); + if (ierr != 0) return check_ierr(ierr, 40); + if (conv_cutback_count != 0 || conv_last_dt != 0.0 || + conv_last_accepted_time != 0.0 || + conv_status_code != 0 || conv_failure_code != 0) return 41; + + ierr = femlite_get_convergence_metrics(&conv_relative_residual, + &conv_contact_gap, + &conv_combined_norm); + if (ierr != 0) return check_ierr(ierr, 42); + if (conv_relative_residual != 0.0 || conv_contact_gap != 0.0 || + conv_combined_norm != 0.0) return 43; + ierr = femlite_get_contact_summary(&active_contact, &contact_work_step, &contact_work_total, &contact_max_penetration, diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index 31e5e33..e326cb0 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -152,6 +152,9 @@ contains integer :: released_pair_count real(rk) :: max_gap_residual real(rk) :: max_aug_lambda + real(rk) :: conv_relative_residual + real(rk) :: conv_contact_gap + real(rk) :: conv_combined_norm call fem_initialize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(145) @@ -208,6 +211,12 @@ contains if (released_pair_count .ne. 0) call fail(150) call check_close(max_gap_residual, 0.01_rk, 151) call check_close(max_aug_lambda, ONE, 152) + call fem_get_convergence_metrics(conv_relative_residual, & + conv_contact_gap, conv_combined_norm, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(153) + call check_close(conv_relative_residual, ZERO, 154) + call check_close(conv_contact_gap, 0.01_rk, 155) + call check_close(conv_combined_norm, 0.01_rk, 156) u(dof) = 0.01_rk call contact_apply_plane_forces(ierr) diff --git a/tests/module/test_implicit_inp.f90 b/tests/module/test_implicit_inp.f90 index a54b01e..934ecc0 100644 --- a/tests/module/test_implicit_inp.f90 +++ b/tests/module/test_implicit_inp.f90 @@ -185,11 +185,19 @@ contains integer :: step integer :: conv_increment integer :: conv_iteration + integer :: conv_cutback_count + integer :: conv_status_code + integer :: conv_failure_code integer :: query_nodes(4) integer :: query_elems(1) real(rk) :: res_norm real(rk) :: conv_residual_norm real(rk) :: conv_correction_norm + real(rk) :: conv_last_dt + real(rk) :: conv_last_accepted_time + real(rk) :: conv_relative_residual + real(rk) :: conv_contact_gap + real(rk) :: conv_combined_norm real(rk) :: time real(rk) :: displacement(NDIM) real(rk) :: velocity(NDIM) @@ -226,6 +234,23 @@ contains if (conv_residual_norm .gt. TOL) call fail(281) if (conv_correction_norm .lt. ZERO) call fail(282) + call fem_get_convergence_diagnostics(conv_cutback_count, conv_last_dt, & + conv_last_accepted_time, conv_status_code, conv_failure_code, ierr) + if (ierr .ne. 0) call fail(283) + if (conv_cutback_count .ne. 0) call fail(284) + call check_close(conv_last_dt, 0.25_rk, 285) + if (conv_status_code .ne. CONVERGENCE_STATUS_CONVERGED) call fail(286) + call check_close(conv_last_accepted_time, ONE, 287) + if (conv_failure_code .ne. CONV_FAIL_NONE) call fail(288) + + call fem_get_convergence_metrics(conv_relative_residual, & + conv_contact_gap, conv_combined_norm, ierr) + if (ierr .ne. 0) call fail(289) + if (conv_relative_residual .gt. TOL) call fail(290) + call check_close(conv_contact_gap, ZERO, 291) + if (conv_combined_norm .lt. conv_relative_residual .or. & + conv_combined_norm .lt. conv_contact_gap) call fail(292) + call fem_get_node_kinematics(2, displacement, velocity, acceleration, ierr) if (ierr .ne. 0) call fail(257) call check_close(displacement(1), 5.0_rk / 6.0_rk, 258) diff --git a/tests/module/test_solver_implicit.f90 b/tests/module/test_solver_implicit.f90 index b80abd7..4c88458 100644 --- a/tests/module/test_solver_implicit.f90 +++ b/tests/module/test_solver_implicit.f90 @@ -257,6 +257,7 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(92) if (iter .le. 0 .or. iter .gt. 5) call fail(93) if (res_norm .gt. TOL) call fail(94) + if (convergence_correction_norm .le. ZERO) call fail(101) dof = dof_id(1,2) call check_close(u(dof), 15.0_rk / 68.0_rk, 95) @@ -434,6 +435,13 @@ contains if (allocated(statev)) then if (maxval(abs(statev)) .gt. TOL) call fail(156) end if + if (convergence_cutback_count .ne. 2) call fail(158) + if (convergence_status_code .ne. CONVERGENCE_STATUS_FAILED) call fail(159) + if (convergence_converged) call fail(160) + call check_close(convergence_last_dt, 0.25_rk, 161) + if (convergence_failure_code .ne. CONV_FAIL_CUTBACK_LIMIT) & + call fail(162) + call check_close(convergence_last_accepted_time, ZERO, 163) allow_step_cutback = old_cutback max_cutback = old_max_cutback