diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b6be95..ec8c6c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(FemLite - VERSION 0.6.0 + VERSION 0.6.1 LANGUAGES C Fortran ) @@ -66,6 +66,7 @@ add_library(femlite_core STATIC src/base/fem_error.f90 src/base/fem_log.f90 src/base/fem_control.f90 + src/base/fem_tangent_audit_report.f90 src/solver/fem_nonlinear_lifecycle.f90 src/element/fem_element_topology.f90 src/element/fem_geometric_stiffness.f90 diff --git a/README.md b/README.md index e3f0e44..d73e1cc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FemLite 是一个以 Fortran 95 为核心实现的轻量级有限元求解器,面向结构动力学、静力学、壳/实体单元、接触、材料非线性和外部耦合接口的工程验证与算法开发。 -当前项目版本为 **0.6.0**。`v0.5.0` 已作为第五版阶段验收发布标签推送;第四版 `0.4.8` 已完成阶段验收并作为稳定基线;第五版 `0.5.x` 已收束 nonlinear/contact diagnostic hardening;0.6.0 交付统一非线性 lifecycle foundation、rollback audit、生命周期输出字段和 restart 诊断回读。完整工业级 mortar/AL 一致切线、mixed-control continuation、cohesive contact mainline、DEM/FEM subcycling 和生产级滚压流程仍作为后续版本工作。 +当前项目版本为 **0.6.1**。`v0.5.0` 已作为第五版阶段验收发布标签推送;第四版 `0.4.8` 已完成阶段验收并作为稳定基线;第五版 `0.5.x` 已收束 nonlinear/contact diagnostic hardening;0.6.0 交付统一非线性 lifecycle foundation、rollback audit、生命周期输出字段和 restart 诊断回读,0.6.1 继续加固 lifecycle/contact/Riks/solver 诊断报告与回归证据。完整工业级 mortar/AL 一致切线、mixed-control continuation、cohesive contact mainline、DEM/FEM subcycling 和生产级滚压流程仍作为后续版本工作。 ## 当前基线 @@ -18,7 +18,7 @@ FemLite 是一个以 Fortran 95 为核心实现的轻量级有限元求解器, - CSV、VTK、restart、C ABI 和外部 SPH/载荷映射接口。 - `examples/` 下的可运行示例矩阵和 Windows GCC 16 本地 CTest 基线。 -第五版已接入内部 solver 诊断、no-external-solver 回归、非匹配 contact benchmark、Mohr-Coulomb 材料点和强度折减 benchmark、Euler/波纹壳屈曲 benchmark、滚压 kinematics/springback benchmark、cohesive ball adhesion benchmark,以及真实粒子-柔性容器耦合 benchmark。0.6.0 在此基础上补齐非线性增量生命周期、材料/接触/cohesive/particle 审计适配、`continuation_path.csv` 生命周期列和 restart version 5 可选 `LIFECYCLE_DIAGNOSTICS` 块。详细计划和剩余项见 [docs/v6.0_development_plan.md](docs/v6.0_development_plan.md)、[docs/v6_benchmark_matrix.md](docs/v6_benchmark_matrix.md)、[docs/v6_acceptance_report.md](docs/v6_acceptance_report.md) 与 [todo.md](todo.md)。 +第五版已接入内部 solver 诊断、no-external-solver 回归、非匹配 contact benchmark、Mohr-Coulomb 材料点和强度折减 benchmark、Euler/波纹壳屈曲 benchmark、滚压 kinematics/springback benchmark、cohesive ball adhesion benchmark,以及真实粒子-柔性容器耦合 benchmark。0.6.x 在此基础上补齐非线性增量生命周期、材料/接触/cohesive/particle 审计适配、`continuation_path.csv` 生命周期与 Riks/arc 诊断列、`nonlinear_lifecycle.csv`、contact state/AL/friction 诊断和 restart version 5 可选 `LIFECYCLE_DIAGNOSTICS` 块。详细计划和剩余项见 [docs/v6.0_development_plan.md](docs/v6.0_development_plan.md)、[docs/v6.1_development_plan.md](docs/v6.1_development_plan.md)、[docs/v6_benchmark_matrix.md](docs/v6_benchmark_matrix.md)、[docs/v6_acceptance_report.md](docs/v6_acceptance_report.md) 与 [todo.md](todo.md)。 ## 快速构建 diff --git a/docs/07_user_manual.md b/docs/07_user_manual.md index 13b2477..d841392 100644 --- a/docs/07_user_manual.md +++ b/docs/07_user_manual.md @@ -365,11 +365,19 @@ slave_surface, master_surface `contact_XXXXXXXX.csv` 当前字段包含: ```text -kind,pair_id,active_count,max_penetration,force_norm,work_estimate,cumulative_work,stick_count,slip_count,accumulated_slip,friction_work,friction_work_total,friction_regularization,ftx,fty,ftz,status,activation_count,release_count,gap_residual,aug_factor,aug_lambda,search_facets,search_masters,search_candidates,search_active,search_bvh_nodes,search_cache_used,search_cache_overflow,search_cpu_time,contact_force_cpu_time,contact_tangent_cpu_time +kind,pair_id,active_count,max_penetration,force_norm,work_estimate,cumulative_work,stick_count,slip_count,accumulated_slip,slip_increment_norm,slip_residual,friction_residual,friction_work,friction_work_total,friction_regularization,ftx,fty,ftz,status,activation_count,release_count,gap_residual,gap_mean,gap_l2,failed_projection_count,active_set_flip_count,open_count,closed_stick_count,closed_slip_count,closed_restick_count,separating_count,state_failed_projection_count,aug_factor,aug_lambda,search_facets,search_masters,search_candidates,search_active,search_bvh_nodes,search_cache_used,search_cache_overflow,search_cpu_time,contact_force_cpu_time,contact_tangent_cpu_time ``` `search_*` 字段在 `SUMMARY` 行给出最近一次 contact pair 力评估的全局搜索统计、BVH 候选缓存使用情况和 `cpu_time` 口径秒数;逐 `PAIR` 行给出对应接触对的搜索、缓存和计时统计。`cpu_time` 是轻量趋势诊断,小算例中可能显示为 0。 +当输出目录启用且存在非线性生命周期状态时,`nonlinear_lifecycle.csv` +记录最新 increment 的事件、失败/切回原因、残差分解、线性求解器 method、 +preconditioner、迭代数、状态、残差和 fail class,以及 rollback/commit audit +计数。`continuation_path.csv` 保持旧列顺序,并在尾部追加 Riks/arc 诊断列: +`arc_mode`、`arc_predictor_consistent`、`arc_load_reversal`、 +`arc_turning_point`、`arc_length`、`arc_load_delta` 和 `arc_predictor_dot`。 +`arc_mode=1` 表示载荷型 Riks path,`arc_mode=2` 表示直接位移控制 path。 + Fortran95 API 可通过 `fem_get_convergence_status` 查询最近一次求解的增量、迭代、残差、位移修正范数和收敛标志;在 trust-region damped Newton 中,位移修正范数是半径限制和 damping 后实际应用的范数。通过 `fem_get_convergence_metrics` 可查询相对残差、contact gap residual 和 combined norm,通过 `fem_get_convergence_diagnostics` 查询 cutback 次数、最后步长、最后有效时间、状态码和失败原因码。`fem_set_linear_solver` 可选择 `CG`、`BiCGSTAB`、`GMRES`、`DENSE` 与 `none/Jacobi/Gauss-Seidel/ILU0` 预条件,`fem_get_linear_solver_stats` 查询最近一次线性求解迭代数、残差和状态,`fem_get_linsol_diagnostics` 查询 CSR 矩阵分类、初始残差、最终残差和最终相对残差;其他 method 值会返回错误且不会改变当前设置。非线性 Newton 修正若在配置的 CG 路径遇到非正定切线,可在内部 GMRES、BiCGSTAB 和 dense pivoting fallback 间自动重试,并在返回前恢复用户配置的求解器设置。V4.7 起,`fem_set_shell_stabilization` 可设置壳 drilling 系数、S3 剪切锁定折减系数和最小折减比例,默认分别为 `1.0e-4`、`0.0625`、`1.0e-4`;`fem_get_shell_stability_stats` 可查询最近壳刚度装配诊断。C ABI 提供同名 `femlite_get_*`/`femlite_set_*` 包装,`converged` 使用 0/1 整数返回。 建议把大型结果输出到 `examples/.../results/...` 或独立 `output/` 目录。仓库 `.gitignore` 默认忽略大规模结果文件。 diff --git a/docs/08_developer_manual.md b/docs/08_developer_manual.md index 8bd9326..37bb3d9 100644 --- a/docs/08_developer_manual.md +++ b/docs/08_developer_manual.md @@ -121,6 +121,7 @@ src/interface C ABI 和 Fortran-C bridge | `fem_contact_*` | contact pair 状态、目标、几何、搜索、摩擦、力、切线、mortar/AL、multiplier 和输出 | | `fem_contact_multiplier` | mortar/AL 积分点乘子、trial/commit/rollback、restart 和 audit | | `fem_contact_mortar_tangent` | 局部 mortar tangent、stick/slip 矩阵和 0.5.1 矩阵审计 | +| `fem_tangent_audit_report` | 共享 tangent audit CSV schema、状态词汇和覆盖计数;只做报告归一化 | | `fem_output_csv` | 历史、节点、单元、反力和接触 CSV | | `fem_output_vtk` | Legacy ASCII VTK 输出 | | `fem_restart` | restart 读写 | @@ -237,6 +238,9 @@ fem_contact_mortar_*.f90 mortar/AL 点更新、批处理、约束、迭代、报 - 0.5.1 起,`mortar_tan_audit_matrix` 用于检查局部 mortar tangent 的 row/column balance、刚体平移残差、非对称量和能量 probe。新增或修改 mortar tangent 公式时,应先扩展该审计和 `contact_mortar_tangent` 测试。 +- 0.6.1 起,`fem_tangent_audit_report` 只提供统一 audit report schema、 + `pass/fail/missing/not-applicable` 状态和覆盖计数;它不表示生产一致切线 + 或完整 AL/mortar tangent 已交付。 新增 contact pair 行为应覆盖: @@ -612,3 +616,26 @@ When adding a new nonlinear owner state after 0.6.0: them to claim delivery of complete AL/mortar consistent tangents, mixed-control continuation, cohesive contact mainline, harmonic cyclic nonzero-wave solving, DEM subcycling or production roll-forming workflows. + +## 21. 0.6.1 Diagnostic Hardening Notes + +0.6.1 diagnostic additions are append-only: + +- `nonlinear_lifecycle.csv` extends lifecycle rows with cutback reason, + residual breakdown, linear solver method/preconditioner/iterations/status, + residuals and fail class. +- `contact_XXXXXXXX.csv` extends contact rows with stable state counters + (`open`, `closed-stick`, `closed-slip`, `closed-restick`, `separating`, + failed projection) plus gap/slip/friction residual summaries. +- `continuation_path.csv` extends path rows with `arc_mode`, + predictor-consistency, load-reversal, turning-point, arc-length and load + delta fields. These are diagnostics only and do not introduce + mixed-control continuation. +- `fem_tangent_audit_report` provides a shared report vocabulary for existing + tangent audits and missing/not-applicable coverage counters. It is not a + production consistent-tangent implementation. +- Restart tests should compare lifecycle/contact/path summaries before and + after read-back when those summaries are supported by the compact model. + +Keep larger algorithm rewrites deferred unless a later development plan +explicitly schedules them. diff --git a/docs/v6.1_development_plan.md b/docs/v6.1_development_plan.md new file mode 100644 index 0000000..0c3aea6 --- /dev/null +++ b/docs/v6.1_development_plan.md @@ -0,0 +1,387 @@ +# FemLite 0.6.1 Development Plan + +Document status: development plan draft + +Date: 2026-07-01 + +Scope: FemLite 0.6.1 development, review, testing and release planning. + +Source: `docs/suggests.md`, `docs/v6.0_development_plan.md`, +`docs/v6_acceptance_report.md` + +## 1. Positioning + +FemLite 0.6.1 is a diagnostic and stability hardening release after the +0.6.0 nonlinear lifecycle foundation. + +```text +FemLite 0.6.1 = nonlinear/contact lifecycle diagnostics hardening +``` + +0.6.0 made nonlinear lifecycle events, rollback audit, lifecycle CSV fields +and restart lifecycle diagnostics visible. 0.6.1 should use that foundation to +make cutback reasons, contact state, restart-after-increment behavior and +Riks/arc diagnostics more explainable and more reproducible. + +The release should still avoid broad algorithm rewrites. The goal is to deepen +the controlled loop: + +```text +begin increment + begin trial state + assemble residual/tangent + solve correction + evaluate convergence, residual categories and cutback reason + accept or reject + commit or rollback every owned state + record lifecycle/contact/restart diagnostics +end increment +``` + +## 2. Delivery Boundary + +### 2.1 0.6.1 should deliver + +- A compact lifecycle increment summary that ties together event state, + convergence status, residual breakdown, linear solver status and cutback + reason. +- A more explicit cutback reason taxonomy for common nonlinear failure modes. +- A standalone or compact lifecycle output path that covers no-solve, accepted + and rejected increment cases without relying only on `continuation_path.csv`. +- Contact state diagnostics hardened around stable state names and counters: + `open`, `closed-stick`, `closed-slip`, `closed-restick`, `separating` and + `failed-projection`. +- Contact long-path diagnostic smoke checks for existing compact benchmarks. +- AL multiplier and friction diagnostic summaries for multiplier residual, + augmentation update count and gap/slip trends. +- A shared tangent-audit report shell that can summarize existing material, + contact, Riks and shell tangent audits without claiming complete tangents. +- Riks/arc diagnostics for arc residual history, predictor consistency and + simple turning/load-factor reversal indicators. +- Restart-after-each-accepted-increment audit for a small covered model. +- Solver diagnostics linked to nonlinear lifecycle rows: matrix class, solver + method, preconditioner, iteration count and status. +- Documentation and benchmark matrix updates that keep the 0.6.1 boundary + visible. + +### 2.2 0.6.1 should not deliver + +The following remain follow-up work unless explicitly re-planned: + +- Complete industrial AL/mortar consistent tangent rewrite. +- Full contact state-machine rewrite for every contact algorithm. +- Complete shell preload `K_G` and high-order solid geometric stiffness. +- Generalized mixed-control continuation and branch switching. +- Cohesive contact mainline integration. +- Nonzero harmonic cyclic symmetry. +- DEM/FEM subcycling and large-particle long runs. +- Production roll-forming process chain. +- New third-party solver backends. + +These topics may consume 0.6.1 diagnostics later, but they are not 0.6.1 +blocking scope. + +## 3. Design Principles + +- Keep every 0.6.1 item observable through an API, CSV/report row, restart + check or regression test. +- Prefer additive diagnostics over solver-loop rewrites. +- Keep old CSV columns stable; append new fields. +- Keep restart readers backward compatible; optional diagnostic blocks are + preferred over format breaks. +- Do not call tangent-audit report fields "consistent tangent support" unless + the production tangent path is actually implemented and tested. +- Stop for review if an item requires choosing between incompatible contact, + Riks or material ownership designs. + +## 4. Planned Work + +### 4.1 Lifecycle Increment Summary + +Add a compact summary that can describe the latest increment or a small fixed +history of recent increments: + +- step and increment; +- final lifecycle event id/name; +- convergence status and failure reason id/name; +- cutback count and cutback reason id/name; +- accepted/rejected counters; +- residual total, force, contact, constraint, arc and material failure count; +- linear solver method, preconditioner, iterations and status; +- audit status and owner rollback/commit counters. + +Primary tests: + +- `nonlinear_lifecycle` +- `solver_implicit` + +### 4.2 Cutback Reason Taxonomy + +Extend existing nonlinear failure reasons with a 0.6.1 cutback layer: + +- linear solver failed; +- Newton nonconvergence; +- minimum step reached; +- material local update failed; +- contact projection failed; +- contact active-set oscillation; +- contact penetration/gap limit exceeded; +- friction slip residual limit exceeded; +- arc constraint failed; +- Riks predictor or direction update failed; +- displacement correction too large; +- tangent audit failed or matrix classification unsafe. + +Each reason added in 0.6.1 must be consumed by a test, checker or report +schema. + +Primary tests: + +- `solver_implicit` +- contact report tests +- lifecycle unit test + +### 4.3 Lifecycle Output File + +Add a compact lifecycle report path, either: + +- `nonlinear_lifecycle.csv`, or +- an existing nonlinear report with lifecycle summary fields appended. + +The output should cover: + +- no-solve / initialized state; +- accepted increment; +- rejected or cutback increment; +- restart-restored lifecycle state. + +Primary tests: + +- `nonlinear_lifecycle` +- `solver_implicit` +- output checker + +### 4.4 Contact State Diagnostics + +Stabilize contact diagnostic state names and counters: + +```text +open +closed-stick +closed-slip +closed-restick +separating +failed-projection +``` + +For each state, record: + +- trial count; +- active count; +- released count; +- failed projection count; +- gap maximum, mean and L2; +- slip increment and slip residual; +- friction residual; +- active-set flip count. + +This task is diagnostic hardening only. It is not a full contact solver +state-machine rewrite. + +Primary tests: + +- `contact` +- `contact_mortar_report` +- `contact_multiplier_report` +- compact contact benchmarks + +### 4.5 Contact Long-Path Diagnostic Smoke + +Add small long-path diagnostic checks around existing examples: + +- two-block compression; +- block sliding friction; +- shell-shell contact; +- shell-solid contact. + +Acceptance should focus on explainability: + +- required diagnostic columns exist; +- state counts remain finite and consistent; +- gap/slip/friction/multiplier residuals are reported each path step; +- restart does not change accepted contact diagnostic summaries. + +Primary tests: + +- existing contact benchmark checkers +- `restart` + +### 4.6 AL Multiplier And Friction Diagnostic Summary + +Add compact diagnostic fields for: + +- multiplier residual trend; +- augmentation update count; +- maximum augmented multiplier; +- penalty/augmentation factor used in the accepted step; +- gap/slip residual relationship; +- restart before/after multiplier residual consistency. + +Primary tests: + +- `contact_multiplier_report` +- `restart` +- `contact` + +### 4.7 Shared Tangent-Audit Report Shell + +Create a shared report schema for existing tangent audits: + +- material tangent audit; +- contact normal tangent audit; +- contact stick tangent audit; +- contact slip tangent audit; +- Riks augmented tangent audit; +- shell finite-strain tangent audit. + +0.6.1 should only unify the audit report vocabulary and coverage counters. +It should not claim complete industrial AL/mortar consistent tangent support. + +Primary tests: + +- existing tangent audit tests +- source/report schema checker + +### 4.8 Riks/Arc Diagnostic Hardening + +Extend current Riks/arc diagnostics with: + +- arc residual history; +- predictor direction consistency; +- load-factor reversal indicator; +- simple turning-point indicator; +- cutback reason when Riks path control fails; +- path row fields that distinguish load-control Riks from direct displacement + control. + +This task does not implement generalized mixed-control continuation or branch +switching. + +Primary tests: + +- `solver_implicit` +- `implicit_inp` +- spherical-cap bounded checker if a small deterministic path is available + +### 4.9 Restart After Each Accepted Increment Audit + +Extend restart coverage from one accepted-increment round trip to a compact +multi-increment audit: + +```text +run accepted increment +write restart +read restart into fresh model +compare lifecycle/contact/material/path diagnostics +continue one increment +repeat for a small fixed count +``` + +The model should be small and deterministic. This is a reliability check, not +a large benchmark. + +Primary tests: + +- `restart` +- `solver_implicit` or a compact restart-lifecycle test + +### 4.10 Solver Diagnostics Coupled To Nonlinear Rows + +Record linear solver diagnostics in lifecycle or nonlinear report rows: + +- matrix class; +- method; +- preconditioner; +- iteration count; +- status; +- initial/final/relative residual; +- fallback marker if dense pivoting or method fallback is used. + +The goal is to make nonlinear failures distinguishable from contact/material +or path-control failures. + +Primary tests: + +- `linear_solver_cg` +- `solver_implicit` +- `implicit_inp` + +### 4.11 Documentation And Matrix Updates + +Update: + +- `docs/v6_benchmark_matrix.md`; +- `docs/v6_acceptance_report.md` or a new 0.6.1 report; +- interface/control documentation; +- user and developer manuals; +- `todo.md` with uniform 0.6.1 task granularity. + +Documentation must keep the boundary clear: + +- 0.6.1 deepens lifecycle/contact diagnostics. +- 0.6.1 does not deliver the deferred large algorithm rewrites. + +## 5. Execution Plan + +| Item | Theme | Output | Primary tests | +|---|---|---|---| +| 0.6.1-1 | Lifecycle increment summary | summary fields and API/query hook | `nonlinear_lifecycle`, `solver_implicit` | +| 0.6.1-2 | Cutback reason taxonomy | stable reason ids/names and tests | `solver_implicit` | +| 0.6.1-3 | Lifecycle report output | compact CSV or appended nonlinear report | output checker | +| 0.6.1-4 | Contact state diagnostics | stable state counters and report fields | `contact`, contact reports | +| 0.6.1-5 | Contact long-path smoke | compact benchmark diagnostic checks | contact benchmark checkers | +| 0.6.1-6 | AL/friction diagnostics | multiplier/friction trend fields | `contact_multiplier_report`, `restart` | +| 0.6.1-7 | Tangent-audit report shell | unified audit schema | tangent audit tests | +| 0.6.1-8 | Riks/arc diagnostics | predictor, reversal and arc residual fields | `solver_implicit`, `implicit_inp` | +| 0.6.1-9 | Restart-after-each-accepted audit | multi-increment restart lifecycle proof | `restart` | +| 0.6.1-10 | Solver diagnostics coupling | lifecycle rows include linear solver status | `linear_solver_cg`, `solver_implicit` | +| 0.6.1-11 | Documentation and matrix | docs, matrix, acceptance boundaries | wording checks | +| 0.6.1-12 | Release close-out | version, report and regression evidence | targeted + V5 acceptance tests | + +## 6. Acceptance Criteria + +0.6.1 can close when: + +- all 0.6.1 TODO items are complete; +- every new reason/status/output field is consumed by a regression test or + checker; +- lifecycle summary rows can explain at least one accepted increment and one + rejected/cutback increment; +- contact state diagnostics are stable enough for compact long-path checks; +- restart-after-accepted-increment audit covers more than one increment in a + small deterministic model; +- Riks/arc diagnostics expose arc residual and predictor/path direction state; +- existing 0.6.0 and V5 acceptance subsets do not regress; +- documentation clearly separates 0.6.1 diagnostic hardening from deferred + algorithm rewrites. + +Suggested regression commands: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +## 7. Deferred Route After 0.6.1 + +After 0.6.1 hardens lifecycle and contact diagnostics, larger algorithm work +can be planned with better evidence: + +- 0.7.x: contact consistent tangent long-path work and shell/solid geometric + stiffness. +- 0.8.x: generalized continuation, cohesive mainline and harmonic cyclic + expansion. +- 0.9.x: DEM/FEM subcycling, solver scaling/block preconditioning and + production process long runs. diff --git a/docs/v6_acceptance_report.md b/docs/v6_acceptance_report.md index 228b913..20c0c0b 100644 --- a/docs/v6_acceptance_report.md +++ b/docs/v6_acceptance_report.md @@ -66,3 +66,31 @@ documented subset. - DEM/FEM subcycling and large-particle long runs. - Production roll-forming process chain. - Additional solver scaling and block preconditioning work. + +## 0.6.1 Diagnostic Hardening Addendum + +0.6.1 keeps the 0.6.0 release boundary and hardens diagnostics around the +covered nonlinear/contact paths. It adds lifecycle summary queries, +cutback-reason taxonomy, `nonlinear_lifecycle.csv`, stable contact state +counters, compact contact long-path checker coverage, AL/friction summary +fields, a shared tangent-audit report shell, Riks/arc path indicators, +restart-after-each-accepted audit coverage and fuller linear-solver fields in +nonlinear rows. + +Final 0.6.1 evidence on `build-codex-gcc`: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^example_(contact_two_blocks_compression|contact_block_sliding|shell_shell_contact|shell_solid_contact)_benchmark$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +0.6.1 targeted regression passed 10/10, the compact contact benchmark smoke +passed 4/4, the V5 acceptance subset passed 39/39 and the version-specific +smoke checks passed 2/2 after the public version was raised to 0.6.1. + +0.6.1 still does not claim complete industrial AL/mortar consistent tangent +delivery, generalized mixed-control continuation, cohesive contact mainline, +DEM/FEM subcycling or production roll-forming workflow support. diff --git a/docs/v6_benchmark_matrix.md b/docs/v6_benchmark_matrix.md index 53d0812..0a8e802 100644 --- a/docs/v6_benchmark_matrix.md +++ b/docs/v6_benchmark_matrix.md @@ -49,3 +49,40 @@ Additional focused lifecycle evidence used during development: ```powershell ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|restart|contact|cohesive_contact|particle_step)$" --output-on-failure ``` + +## 0.6.1 Diagnostic Hardening Matrix + +FemLite 0.6.1 extends the 0.6.0 lifecycle foundation with additive +diagnostics. It does not deliver a complete industrial AL/mortar consistent +tangent rewrite, mixed-control continuation, cohesive contact mainline, +DEM/FEM subcycling or production roll-forming workflow. + +| Area | Code or output target | Test/checker | Acceptance evidence | +|---|---|---|---| +| Lifecycle summary | `fem_nonlinear_lifecycle`, diagnostics API | `nonlinear_lifecycle`, `solver_implicit` | One compact query explains latest increment event, reason, convergence, residual, linear solver and audit state. | +| Cutback taxonomy | `fem_control`, static nonlinear solver | `nonlinear_lifecycle`, `solver_implicit` | Last actual cutback reason is separate from final convergence failure reason. | +| Lifecycle report | `nonlinear_lifecycle.csv` | `nonlinear_lifecycle`, `solver_implicit` | Empty, accepted and rejected/cutback rows include lifecycle, residual, cutback and linear solver fields. | +| Contact state diagnostics | `fem_contact_state`, contact CSV | `contact` | Stable open/stick/slip/restick/separating/failed-projection counters and gap/slip/friction summaries. | +| Contact long-path smoke | compact contact benchmark checkers | contact two-block, sliding, shell-shell, shell-solid examples | Existing compact paths fail loudly if state/residual/multiplier fields disappear. | +| AL/friction summaries | multiplier report and restart checks | `contact_multiplier_report`, `restart` | Multiplier residual, augmented multiplier and supported friction summaries are reported and restart-stable. | +| Tangent audit report shell | `fem_tangent_audit_report` | `contact_mortar_tangent` | Shared audit schema covers contact and non-contact categories with pass/missing/not-applicable counters. | +| Riks/arc diagnostics | `continuation_path.csv` | `solver_implicit`, `implicit_inp` | Path rows distinguish load Riks and displacement control and expose arc residual, direction and reversal indicators. | +| Restart after accepted increments | restart optional lifecycle block | `restart` | Two accepted increments are written/read through fresh models, then continued one more increment. | +| Linear solver coupling | lifecycle/path rows | `solver_implicit`, `linear_solver_cg` | Method, preconditioner, iterations, status, residuals and fail class are visible in nonlinear rows. | + +Final local 0.6.1 evidence on `build-codex-gcc`: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^example_(contact_two_blocks_compression|contact_block_sliding|shell_shell_contact|shell_solid_contact)_benchmark$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +Results: + +- Targeted 0.6.1 regression command passed 10/10. +- V5 acceptance subset passed 39/39. +- Contact compact benchmark smoke passed 4/4. +- Version smoke checks passed 2/2 after raising the public version to 0.6.1. diff --git a/examples/contact_block_sliding/check_contact_results.py b/examples/contact_block_sliding/check_contact_results.py index 4725c62..5825aba 100644 --- a/examples/contact_block_sliding/check_contact_results.py +++ b/examples/contact_block_sliding/check_contact_results.py @@ -8,6 +8,22 @@ import sys MIN_MASTER_FACETS = 4 MIN_ACTIVE_CONTACTS = 2 MIN_ACCUMULATED_SLIP = 1.0e-1 +STATE_COLUMNS = [ + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", +] + + +def require_columns(row: dict[str, str], columns: list[str]) -> bool: + missing = [column for column in columns if column not in row] + if missing: + print("missing contact diagnostic columns: " + ", ".join(missing)) + return False + return True def read_pair_rows(result_dir: str) -> list[dict[str, str]]: @@ -38,6 +54,12 @@ def write_sliding_profile(result_dir: str, rows: list[dict[str, str]]) -> str: "gap_l2", "failed_projection_count", "active_set_flip_count", + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", "aug_factor", "aug_lambda", "search_masters", @@ -69,6 +91,14 @@ def write_sliding_profile(result_dir: str, rows: list[dict[str, str]]) -> str: "gap_l2": float(row["gap_l2"]), "failed_projection_count": int(float(row["failed_projection_count"])), "active_set_flip_count": int(float(row["active_set_flip_count"])), + "open_count": int(float(row["open_count"])), + "closed_stick_count": int(float(row["closed_stick_count"])), + "closed_slip_count": int(float(row["closed_slip_count"])), + "closed_restick_count": int(float(row["closed_restick_count"])), + "separating_count": int(float(row["separating_count"])), + "state_failed_projection_count": int( + float(row["state_failed_projection_count"]) + ), "aug_factor": float(row["aug_factor"]), "aug_lambda": float(row["aug_lambda"]), "search_masters": int(float(row.get("search_masters", "0") or "0")), @@ -84,6 +114,23 @@ def main() -> int: if not pair_rows: print("no contact pair rows found") return 1 + if len(pair_rows) < 2: + print("contact diagnostic path is too short") + return 1 + if not require_columns( + pair_rows[0], + STATE_COLUMNS + + [ + "gap_residual", + "gap_l2", + "slip_increment_norm", + "slip_residual", + "friction_residual", + "aug_factor", + "aug_lambda", + ], + ): + return 1 profile_path = write_sliding_profile(result_dir, pair_rows) max_active = max(int(float(row["active_count"])) for row in pair_rows) @@ -108,6 +155,19 @@ def main() -> int: max_gap = max(float(row["gap_residual"]) for row in pair_rows) max_gap_l2 = max(float(row["gap_l2"]) for row in pair_rows) max_failed_projection = max(int(float(row["failed_projection_count"])) for row in pair_rows) + max_state_failed_projection = max( + int(float(row["state_failed_projection_count"])) for row in pair_rows + ) + max_closed_slip_state = max( + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + for row in pair_rows + ) + max_closed_stick_state = max( + int(float(row["closed_stick_count"])) + + int(float(row["closed_restick_count"])) + for row in pair_rows + ) max_aug_factor = max(float(row["aug_factor"]) for row in pair_rows) max_aug_lambda = max(float(row["aug_lambda"]) for row in pair_rows) max_masters = max(int(float(row.get("search_masters", "0") or "0")) for row in pair_rows) @@ -140,6 +200,24 @@ def main() -> int: if max_failed_projection != 0: print(f"unexpected failed projection count: {max_failed_projection}") return 1 + if max_state_failed_projection != 0: + print(f"unexpected failed projection state: {max_state_failed_projection}") + return 1 + if max_closed_slip_state <= 0 or max_closed_stick_state <= 0: + print("stick/slip contact state counters were not reported") + return 1 + if any( + int(float(row["open_count"])) + + int(float(row["closed_stick_count"])) + + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + + int(float(row["separating_count"])) + + int(float(row["state_failed_projection_count"])) + != 1 + for row in pair_rows + ): + print("contact state counters do not describe exactly one pair state") + return 1 if max_aug_factor <= 0.0 or max_aug_lambda <= 0.0: print("augmentation diagnostics were not reported") return 1 diff --git a/examples/contact_two_blocks_compression/check_contact_results.py b/examples/contact_two_blocks_compression/check_contact_results.py index 058fe1e..358eee6 100644 --- a/examples/contact_two_blocks_compression/check_contact_results.py +++ b/examples/contact_two_blocks_compression/check_contact_results.py @@ -7,6 +7,22 @@ import sys CONTACT_AREA = 1.0e-2 MIN_MASTER_FACETS = 4 +STATE_COLUMNS = [ + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", +] + + +def require_columns(row: dict[str, str], columns: list[str]) -> bool: + missing = [column for column in columns if column not in row] + if missing: + print("missing contact diagnostic columns: " + ", ".join(missing)) + return False + return True def main() -> int: @@ -19,6 +35,23 @@ def main() -> int: if not pair_rows: print("no contact pair rows found") return 1 + if len(pair_rows) < 2: + print("contact diagnostic path is too short") + return 1 + if not require_columns( + pair_rows[0], + STATE_COLUMNS + + [ + "gap_residual", + "gap_mean", + "gap_l2", + "failed_projection_count", + "active_set_flip_count", + "aug_factor", + "aug_lambda", + ], + ): + return 1 profile_rows: list[dict[str, float]] = [] for index, row in enumerate(pair_rows): @@ -33,6 +66,12 @@ def main() -> int: release_count = int(float(row["release_count"])) aug_factor = float(row["aug_factor"]) aug_lambda = float(row["aug_lambda"]) + open_count = int(float(row["open_count"])) + closed_stick_count = int(float(row["closed_stick_count"])) + closed_slip_count = int(float(row["closed_slip_count"])) + closed_restick_count = int(float(row["closed_restick_count"])) + separating_count = int(float(row["separating_count"])) + state_failed_projection = int(float(row["state_failed_projection_count"])) profile_rows.append( { "sample": float(index), @@ -46,6 +85,12 @@ def main() -> int: "gap_l2": gap_l2, "failed_projection_count": float(failed_projection), "active_set_flip_count": float(active_set_flip), + "open_count": float(open_count), + "closed_stick_count": float(closed_stick_count), + "closed_slip_count": float(closed_slip_count), + "closed_restick_count": float(closed_restick_count), + "separating_count": float(separating_count), + "state_failed_projection_count": float(state_failed_projection), "weighted_gap": gap * CONTACT_AREA, "multiplier_residual": abs(gap), "aug_factor": aug_factor, @@ -70,6 +115,12 @@ def main() -> int: "gap_l2", "failed_projection_count", "active_set_flip_count", + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", "weighted_gap", "multiplier_residual", "aug_factor", @@ -85,6 +136,15 @@ def main() -> int: max_gap = max(row["max_gap"] for row in profile_rows) max_gap_l2 = max(row["gap_l2"] for row in profile_rows) max_failed_projection = max(int(row["failed_projection_count"]) for row in profile_rows) + max_state_failed_projection = max( + int(row["state_failed_projection_count"]) for row in profile_rows + ) + max_closed_state = max( + int(row["closed_stick_count"]) + + int(row["closed_slip_count"]) + + int(row["closed_restick_count"]) + for row in profile_rows + ) max_activation_count = max(int(row["activation_count"]) for row in profile_rows) max_release_count = max(int(row["release_count"]) for row in profile_rows) max_weighted_gap = max(row["weighted_gap"] for row in profile_rows) @@ -106,6 +166,24 @@ def main() -> int: if max_failed_projection != 0: print(f"unexpected failed projection count: {max_failed_projection}") return 1 + if max_state_failed_projection != 0: + print(f"unexpected failed projection state: {max_state_failed_projection}") + return 1 + if max_closed_state <= 0: + print("closed contact state counters were not reported") + return 1 + if any( + int(row["open_count"]) + + int(row["closed_stick_count"]) + + int(row["closed_slip_count"]) + + int(row["closed_restick_count"]) + + int(row["separating_count"]) + + int(row["state_failed_projection_count"]) + != 1 + for row in profile_rows + ): + print("contact state counters do not describe exactly one pair state") + return 1 if any( int(row["active_set_flip_count"]) < int(row["activation_count"]) + int(row["release_count"]) diff --git a/examples/shell_shell_contact/check_contact_results.py b/examples/shell_shell_contact/check_contact_results.py index 72f74f1..2b6c73d 100644 --- a/examples/shell_shell_contact/check_contact_results.py +++ b/examples/shell_shell_contact/check_contact_results.py @@ -5,6 +5,23 @@ import glob import os import sys +STATE_COLUMNS = [ + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", +] + + +def require_columns(row: dict[str, str], columns: list[str]) -> bool: + missing = [column for column in columns if column not in row] + if missing: + print("missing contact diagnostic columns: " + ", ".join(missing)) + return False + return True + def read_pair_rows(result_dir: str) -> list[dict[str, str]]: rows: list[dict[str, str]] = [] @@ -20,6 +37,22 @@ def main() -> int: if not pair_rows: print("no contact pair rows found") return 1 + if len(pair_rows) < 2: + print("shell-shell contact diagnostic path is too short") + return 1 + if not require_columns( + pair_rows[0], + STATE_COLUMNS + + [ + "gap_residual", + "gap_l2", + "failed_projection_count", + "active_set_flip_count", + "aug_factor", + "aug_lambda", + ], + ): + return 1 profile_path = os.path.join(result_dir, "shell_shell_contact_profile.csv") with open(profile_path, "w", newline="") as stream: @@ -31,6 +64,12 @@ def main() -> int: "gap_l2", "failed_projection_count", "active_set_flip_count", + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", "status", "activation_count", "release_count", @@ -50,6 +89,14 @@ def main() -> int: "gap_l2": float(row["gap_l2"]), "failed_projection_count": int(float(row["failed_projection_count"])), "active_set_flip_count": int(float(row["active_set_flip_count"])), + "open_count": int(float(row["open_count"])), + "closed_stick_count": int(float(row["closed_stick_count"])), + "closed_slip_count": int(float(row["closed_slip_count"])), + "closed_restick_count": int(float(row["closed_restick_count"])), + "separating_count": int(float(row["separating_count"])), + "state_failed_projection_count": int( + float(row["state_failed_projection_count"]) + ), "status": int(float(row["status"])), "activation_count": int(float(row["activation_count"])), "release_count": int(float(row["release_count"])), @@ -64,6 +111,15 @@ def main() -> int: max_gap = max(float(row["gap_residual"]) for row in pair_rows) max_gap_l2 = max(float(row["gap_l2"]) for row in pair_rows) max_failed_projection = max(int(float(row["failed_projection_count"])) for row in pair_rows) + max_state_failed_projection = max( + int(float(row["state_failed_projection_count"])) for row in pair_rows + ) + max_closed_state = max( + int(float(row["closed_stick_count"])) + + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + for row in pair_rows + ) max_aug_factor = max(float(row["aug_factor"]) for row in pair_rows) max_lambda = max(float(row["aug_lambda"]) for row in pair_rows) max_masters = max(int(float(row.get("search_masters", "0") or "0")) for row in pair_rows) @@ -80,6 +136,24 @@ def main() -> int: if max_failed_projection != 0: print(f"unexpected shell-shell failed projection count: {max_failed_projection}") return 1 + if max_state_failed_projection != 0: + print(f"unexpected shell-shell failed projection state: {max_state_failed_projection}") + return 1 + if max_closed_state <= 0: + print("shell-shell closed state counters were not reported") + return 1 + if any( + int(float(row["open_count"])) + + int(float(row["closed_stick_count"])) + + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + + int(float(row["separating_count"])) + + int(float(row["state_failed_projection_count"])) + != 1 + for row in pair_rows + ): + print("shell-shell state counters do not describe exactly one pair state") + return 1 if any( int(float(row["active_set_flip_count"])) < int(float(row["activation_count"])) + int(float(row["release_count"])) diff --git a/examples/shell_solid_contact/check_contact_results.py b/examples/shell_solid_contact/check_contact_results.py index 78a3df2..1901047 100644 --- a/examples/shell_solid_contact/check_contact_results.py +++ b/examples/shell_solid_contact/check_contact_results.py @@ -5,6 +5,23 @@ import glob import os import sys +STATE_COLUMNS = [ + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", +] + + +def require_columns(row: dict[str, str], columns: list[str]) -> bool: + missing = [column for column in columns if column not in row] + if missing: + print("missing contact diagnostic columns: " + ", ".join(missing)) + return False + return True + def read_pair_rows(result_dir: str) -> list[dict[str, str]]: rows: list[dict[str, str]] = [] @@ -20,6 +37,22 @@ def main() -> int: if not pair_rows: print("no contact pair rows found") return 1 + if len(pair_rows) < 2: + print("shell-solid contact diagnostic path is too short") + return 1 + if not require_columns( + pair_rows[0], + STATE_COLUMNS + + [ + "gap_residual", + "gap_l2", + "failed_projection_count", + "active_set_flip_count", + "aug_factor", + "aug_lambda", + ], + ): + return 1 profile_path = os.path.join(result_dir, "shell_solid_contact_profile.csv") with open(profile_path, "w", newline="") as stream: @@ -31,6 +64,12 @@ def main() -> int: "gap_l2", "failed_projection_count", "active_set_flip_count", + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", "status", "activation_count", "release_count", @@ -50,6 +89,14 @@ def main() -> int: "gap_l2": float(row["gap_l2"]), "failed_projection_count": int(float(row["failed_projection_count"])), "active_set_flip_count": int(float(row["active_set_flip_count"])), + "open_count": int(float(row["open_count"])), + "closed_stick_count": int(float(row["closed_stick_count"])), + "closed_slip_count": int(float(row["closed_slip_count"])), + "closed_restick_count": int(float(row["closed_restick_count"])), + "separating_count": int(float(row["separating_count"])), + "state_failed_projection_count": int( + float(row["state_failed_projection_count"]) + ), "status": int(float(row["status"])), "activation_count": int(float(row["activation_count"])), "release_count": int(float(row["release_count"])), @@ -64,6 +111,15 @@ def main() -> int: max_gap = max(float(row["gap_residual"]) for row in pair_rows) max_gap_l2 = max(float(row["gap_l2"]) for row in pair_rows) max_failed_projection = max(int(float(row["failed_projection_count"])) for row in pair_rows) + max_state_failed_projection = max( + int(float(row["state_failed_projection_count"])) for row in pair_rows + ) + max_closed_state = max( + int(float(row["closed_stick_count"])) + + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + for row in pair_rows + ) max_aug_factor = max(float(row["aug_factor"]) for row in pair_rows) max_lambda = max(float(row["aug_lambda"]) for row in pair_rows) max_masters = max(int(float(row.get("search_masters", "0") or "0")) for row in pair_rows) @@ -80,6 +136,24 @@ def main() -> int: if max_failed_projection != 0: print(f"unexpected shell-solid failed projection count: {max_failed_projection}") return 1 + if max_state_failed_projection != 0: + print(f"unexpected shell-solid failed projection state: {max_state_failed_projection}") + return 1 + if max_closed_state <= 0: + print("shell-solid closed state counters were not reported") + return 1 + if any( + int(float(row["open_count"])) + + int(float(row["closed_stick_count"])) + + int(float(row["closed_slip_count"])) + + int(float(row["closed_restick_count"])) + + int(float(row["separating_count"])) + + int(float(row["state_failed_projection_count"])) + != 1 + for row in pair_rows + ): + print("shell-solid state counters do not describe exactly one pair state") + return 1 if any( int(float(row["active_set_flip_count"])) < int(float(row["activation_count"])) + int(float(row["release_count"])) diff --git a/src/base/fem_api_coupling.f90 b/src/base/fem_api_coupling.f90 index ee5256a..c06104f 100644 --- a/src/base/fem_api_coupling.f90 +++ b/src/base/fem_api_coupling.f90 @@ -9,7 +9,9 @@ module fem_api_coupling CONTACT_PAIR_RELEASED, & contact_get_search_stats, & contact_get_perf_stats, & - contact_get_cache_stats + contact_get_cache_stats, & + contact_get_state_summary, & + contact_state_name use fem_contact_history, only: contact_history_stats use fem_contact_multiplier, only: contact_multiplier_stats use fem_database_surface, only: db_surface_node_count, db_get_surface_nodes @@ -22,6 +24,8 @@ module fem_api_coupling public :: fem_get_sph_force_summary public :: fem_get_contact_summary public :: fem_get_contact_diagnostics + public :: fem_get_contact_state_name + public :: fem_get_contact_state_summary public :: fem_get_contact_friction public :: fem_get_contact_hist_stats public :: fem_get_contact_mult_stats @@ -224,6 +228,72 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_contact_diagnostics + subroutine fem_get_contact_state_name(state_id, state_name, ierr) + integer, intent(in) :: state_id + character(len=*), intent(out) :: state_name + integer, intent(out) :: ierr + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_contact_state_name called before fem_initialize', ierr) + return + end if + + call contact_state_name(state_id, state_name) + ierr = FEM_SUCCESS + end subroutine fem_get_contact_state_name + + subroutine fem_get_contact_state_summary(open_count, closed_stick_count, & + closed_slip_count, & + closed_restick_count, & + separating_count, & + failed_projection_count, & + gap_max, gap_mean, gap_l2, & + slip_increment, slip_residual, & + friction_residual, & + active_set_flip_count, ierr) + integer, intent(out) :: open_count + integer, intent(out) :: closed_stick_count + integer, intent(out) :: closed_slip_count + integer, intent(out) :: closed_restick_count + integer, intent(out) :: separating_count + integer, intent(out) :: failed_projection_count + real(rk), intent(out) :: gap_max + real(rk), intent(out) :: gap_mean + real(rk), intent(out) :: gap_l2 + real(rk), intent(out) :: slip_increment + real(rk), intent(out) :: slip_residual + real(rk), intent(out) :: friction_residual + integer, intent(out) :: active_set_flip_count + integer, intent(out) :: ierr + + open_count = 0 + closed_stick_count = 0 + closed_slip_count = 0 + closed_restick_count = 0 + separating_count = 0 + failed_projection_count = 0 + gap_max = ZERO + gap_mean = ZERO + gap_l2 = ZERO + slip_increment = ZERO + slip_residual = ZERO + friction_residual = ZERO + active_set_flip_count = 0 + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_contact_state_summary called before fem_initialize', ierr) + return + end if + + call contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count) + ierr = FEM_SUCCESS + end subroutine fem_get_contact_state_summary + subroutine fem_get_contact_friction(work_step, work_total, & max_accumulated_slip, ierr) real(rk), intent(out) :: work_step diff --git a/src/base/fem_api_diagnostics.f90 b/src/base/fem_api_diagnostics.f90 index cde8851..793b2d1 100644 --- a/src/base/fem_api_diagnostics.f90 +++ b/src/base/fem_api_diagnostics.f90 @@ -7,7 +7,8 @@ module fem_api_diagnostics linear_solver_get_diagnostics, linear_solver_get_fail_info use fem_nonlinear_lifecycle, only: nl_lifecycle_get_arc_state, & nl_lifecycle_get_audit, & - nl_lifecycle_get_snapshot + nl_lifecycle_get_snapshot, & + nl_lifecycle_get_summary use fem_api_state, only: api_initialized implicit none private @@ -16,8 +17,10 @@ module fem_api_diagnostics public :: fem_get_convergence_metrics public :: fem_get_convergence_diagnostics public :: fem_get_convergence_reason + public :: fem_get_cutback_reason public :: fem_get_residual_breakdown public :: fem_get_nl_lifecycle_snapshot + public :: fem_get_nl_lifecycle_summary public :: fem_get_nl_lifecycle_arc public :: fem_get_nl_lifecycle_audit public :: fem_get_continuation_path_count @@ -179,6 +182,25 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_convergence_reason + subroutine fem_get_cutback_reason(reason_id, reason_name, ierr) + integer, intent(out) :: reason_id + character(len=*), intent(out) :: reason_name + integer, intent(out) :: ierr + + reason_id = CUTBACK_REASON_NONE + reason_name = 'none' + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_cutback_reason called before fem_initialize', ierr) + return + end if + + reason_id = conv_last_cutback_reason_id + call cutback_reason_name(reason_id, reason_name) + ierr = FEM_SUCCESS + end subroutine fem_get_cutback_reason + subroutine fem_get_residual_breakdown(total_residual, force_residual, & contact_residual, constraint_residual, & arc_residual, material_fail_count, & @@ -245,6 +267,116 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_nl_lifecycle_snapshot + subroutine fem_get_nl_lifecycle_summary(step, increment, iteration, & + event_id, event_name, reason_id, & + reason_name, convergence_status, & + failure_code, failure_reason_id, & + failure_reason_name, & + total_residual, force_residual, & + contact_residual, & + constraint_residual, arc_residual, & + material_fail_count, & + linear_matrix_class, & + linear_status, audit_status, & + audit_name, begin_trial_count, & + rollback_requested_count, & + rollback_ok_count, & + rollback_failed_count, & + commit_ok_count, accept_count, & + reject_count, cutback_count, ierr) + integer, intent(out) :: step + integer, intent(out) :: increment + integer, intent(out) :: iteration + integer, intent(out) :: event_id + character(len=*), intent(out) :: event_name + integer, intent(out) :: reason_id + character(len=*), intent(out) :: reason_name + integer, intent(out) :: convergence_status + integer, intent(out) :: failure_code + integer, intent(out) :: failure_reason_id + character(len=*), intent(out) :: failure_reason_name + real(rk), intent(out) :: total_residual + real(rk), intent(out) :: force_residual + real(rk), intent(out) :: contact_residual + real(rk), intent(out) :: constraint_residual + real(rk), intent(out) :: arc_residual + integer, intent(out) :: material_fail_count + integer, intent(out) :: linear_matrix_class + integer, intent(out) :: linear_status + integer, intent(out) :: audit_status + character(len=*), intent(out) :: audit_name + integer, intent(out) :: begin_trial_count + integer, intent(out) :: rollback_requested_count + integer, intent(out) :: rollback_ok_count + integer, intent(out) :: rollback_failed_count + integer, intent(out) :: commit_ok_count + integer, intent(out) :: accept_count + integer, intent(out) :: reject_count + integer, intent(out) :: cutback_count + integer, intent(out) :: ierr + real(rk) :: linear_initial_residual + real(rk) :: linear_final_residual + real(rk) :: linear_relative_residual + + step = 0 + increment = 0 + iteration = 0 + event_id = 0 + event_name = 'none' + reason_id = NFAIL_NONE + reason_name = 'none' + convergence_status = CONVERGENCE_STATUS_IDLE + failure_code = CONV_FAIL_NONE + failure_reason_id = NFAIL_NONE + failure_reason_name = 'none' + total_residual = ZERO + force_residual = ZERO + contact_residual = ZERO + constraint_residual = ZERO + arc_residual = ZERO + material_fail_count = 0 + linear_matrix_class = 1 + linear_status = LS_STATUS_IDLE + audit_status = 0 + audit_name = 'none' + begin_trial_count = 0 + rollback_requested_count = 0 + rollback_ok_count = 0 + rollback_failed_count = 0 + commit_ok_count = 0 + accept_count = 0 + reject_count = 0 + cutback_count = 0 + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_nl_lifecycle_summary called before fem_initialize', ierr) + return + end if + + call nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, accept_count, reject_count, & + cutback_count) + convergence_status = convergence_status_code + failure_code = convergence_failure_code + failure_reason_id = convergence_failure_reason_id + call convergence_failure_reason_name(failure_reason_id, & + failure_reason_name) + total_residual = convergence_total_resid_norm + force_residual = convergence_force_resid_norm + contact_residual = convergence_contact_resid_norm + constraint_residual = convergence_cons_resid_norm + arc_residual = convergence_arc_resid_norm + material_fail_count = convergence_material_fail_count + call linear_solver_get_diagnostics(linear_matrix_class, & + linear_initial_residual, linear_final_residual, & + linear_relative_residual, linear_status, ierr) + if (ierr .ne. FEM_SUCCESS) return + ierr = FEM_SUCCESS + end subroutine fem_get_nl_lifecycle_summary + subroutine fem_get_nl_lifecycle_arc(load_factor, arc_residual, & path_appended, ierr) real(rk), intent(out) :: load_factor diff --git a/src/base/fem_control.f90 b/src/base/fem_control.f90 index ba9669f..35d11d3 100644 --- a/src/base/fem_control.f90 +++ b/src/base/fem_control.f90 @@ -33,6 +33,10 @@ module fem_control integer, parameter :: NFAIL_MIN_STEP = 110 integer, parameter :: NFAIL_NONCONVERGENCE = 120 integer, parameter :: NFAIL_STOPPED = 130 + integer, parameter :: CUTBACK_REASON_NONE = NFAIL_NONE + integer, parameter :: CUTBACK_REASON_LINEAR_SOLVE = NFAIL_LINEAR_SOLVE + integer, parameter :: CUTBACK_REASON_MIN_STEP = NFAIL_MIN_STEP + integer, parameter :: CUTBACK_REASON_NONCONVERGENCE = NFAIL_NONCONVERGENCE integer, parameter :: LSOLVER_CG = 1 integer, parameter :: LSOLVER_BICGSTAB = 2 integer, parameter :: LSOLVER_GMRES = 3 @@ -91,7 +95,10 @@ module fem_control integer, parameter :: NLC_PATH_R_CONTACT_RESIDUAL = 27 integer, parameter :: NLC_PATH_R_CONS_RESIDUAL = 28 integer, parameter :: NLC_PATH_R_ARC_RESIDUAL = 29 - integer, parameter :: NLC_PATH_REAL_COUNT = 29 + integer, parameter :: NLC_PATH_R_ARC_LENGTH = 30 + integer, parameter :: NLC_PATH_R_ARC_LOAD_DELTA = 31 + integer, parameter :: NLC_PATH_R_ARC_PREDICTOR_DOT = 32 + integer, parameter :: NLC_PATH_REAL_COUNT = 32 integer, parameter :: NLC_PATH_I_STEP = 1 integer, parameter :: NLC_PATH_I_CONTROL_DOF_COUNT = 2 integer, parameter :: NLC_PATH_I_ITERATION = 3 @@ -107,7 +114,14 @@ module fem_control integer, parameter :: NLC_PATH_I_TRUST_REJECTIONS = 13 integer, parameter :: NLC_PATH_I_REASON_ID = 14 integer, parameter :: NLC_PATH_I_MATERIAL_FAIL_COUNT = 15 - integer, parameter :: NLC_PATH_INT_COUNT = 15 + integer, parameter :: NLC_PATH_I_ARC_MODE = 16 + integer, parameter :: NLC_PATH_I_ARC_PRED_OK = 17 + integer, parameter :: NLC_PATH_I_ARC_LOAD_REVERSAL = 18 + integer, parameter :: NLC_PATH_I_ARC_TURNING_POINT = 19 + integer, parameter :: NLC_PATH_INT_COUNT = 19 + integer, parameter :: NLC_ARC_MODE_NONE = 0 + integer, parameter :: NLC_ARC_MODE_LOAD = 1 + integer, parameter :: NLC_ARC_MODE_DISP = 2 integer, parameter :: BUCKLING_MAX_GEOM_LINE = 64 integer, parameter :: BUCK_GEOM_EXPLICIT = 1 integer, parameter :: BUCK_GEOM_PRELOAD = 2 @@ -145,6 +159,7 @@ module fem_control real(rk) :: nlc_last_arc_constraint = ZERO real(rk) :: nlc_last_arc_lambda = ONE real(rk) :: nlc_last_arc_length = ZERO + real(rk) :: nlc_last_arc_predictor_dot = ZERO real(rk) :: nlc_last_damping = ONE real(rk) :: nlc_last_merit_ratio = ZERO real(rk) :: load_factor = ONE @@ -198,6 +213,7 @@ module fem_control integer :: nlc_last_adjust = NLC_ADJ_NONE integer :: nlc_last_trust_adjust = NLC_ADJ_NONE integer :: nlc_last_rejections = 0 + integer :: nlc_last_arc_mode = NLC_ARC_MODE_NONE integer :: nlc_path_count = 0 integer :: nlc_path_capacity = 0 integer :: shell_stability_sample_count = 0 @@ -208,6 +224,7 @@ module fem_control integer :: convergence_status_code = CONVERGENCE_STATUS_IDLE integer :: convergence_failure_code = CONV_FAIL_NONE integer :: convergence_failure_reason_id = NFAIL_NONE + integer :: conv_last_cutback_reason_id = CUTBACK_REASON_NONE integer :: convergence_material_fail_count = 0 real(rk) :: convergence_residual_norm = ZERO real(rk) :: convergence_rel_resid_norm = ZERO @@ -293,6 +310,7 @@ contains nlc_last_arc_constraint = ZERO nlc_last_arc_lambda = ONE nlc_last_arc_length = ZERO + nlc_last_arc_predictor_dot = ZERO nlc_last_damping = ONE nlc_last_merit_ratio = ZERO load_factor = ONE @@ -356,6 +374,7 @@ contains nlc_last_adjust = NLC_ADJ_NONE nlc_last_trust_adjust = NLC_ADJ_NONE nlc_last_rejections = 0 + nlc_last_arc_mode = NLC_ARC_MODE_NONE call nlc_path_release() end subroutine control_reset_solver_ctl @@ -368,6 +387,7 @@ contains convergence_status_code = CONVERGENCE_STATUS_IDLE convergence_failure_code = CONV_FAIL_NONE convergence_failure_reason_id = NFAIL_NONE + conv_last_cutback_reason_id = CUTBACK_REASON_NONE convergence_material_fail_count = 0 convergence_residual_norm = ZERO convergence_rel_resid_norm = ZERO @@ -446,17 +466,55 @@ contains integer :: row real(rk) :: prev_disp real(rk) :: prev_force + real(rk) :: prev_parameter + real(rk) :: prev_prev_parameter + real(rk) :: prev_reaction + real(rk) :: prev_prev_reaction + real(rk) :: load_delta + real(rk) :: prev_load_delta + real(rk) :: reaction_delta + real(rk) :: prev_reaction_delta + integer :: predictor_consistent + integer :: load_reversal + integer :: turning_point call nlc_path_ensure_capacity(nlc_path_count + 1, ierr) if (ierr .ne. FEM_SUCCESS) return + load_delta = ZERO + prev_load_delta = ZERO + reaction_delta = ZERO + prev_reaction_delta = ZERO + predictor_consistent = 1 + load_reversal = 0 + turning_point = 0 if (nlc_path_count .gt. 0) then prev_disp = nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, nlc_path_count) prev_force = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & nlc_path_count) + prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, nlc_path_count) + prev_reaction = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & + nlc_path_count) + load_delta = parameter - prev_parameter + reaction_delta = reaction_generalized - prev_reaction nlc_path_accumulated_work = nlc_path_accumulated_work + & 0.5_rk * (prev_force + reaction_generalized) * & (prescribed_l2 - prev_disp) + if (nlc_path_count .gt. 1) then + prev_prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, & + nlc_path_count - 1) + prev_prev_reaction = nlc_path_real( & + NLC_PATH_R_REACTION_GENERALIZED, nlc_path_count - 1) + prev_load_delta = prev_parameter - prev_prev_parameter + prev_reaction_delta = prev_reaction - prev_prev_reaction + if (load_delta * prev_load_delta .lt. ZERO) then + predictor_consistent = 0 + load_reversal = 1 + end if + if (reaction_delta * prev_reaction_delta .lt. ZERO) then + turning_point = 1 + end if + end if end if row = nlc_path_count + 1 @@ -502,6 +560,10 @@ contains convergence_cons_resid_norm nlc_path_real(NLC_PATH_R_ARC_RESIDUAL, row) = & convergence_arc_resid_norm + nlc_path_real(NLC_PATH_R_ARC_LENGTH, row) = nlc_last_arc_length + nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, row) = load_delta + nlc_path_real(NLC_PATH_R_ARC_PREDICTOR_DOT, row) = & + nlc_last_arc_predictor_dot nlc_path_int(NLC_PATH_I_STEP, row) = step nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, row) = control_dof_count @@ -519,6 +581,11 @@ contains nlc_path_int(NLC_PATH_I_REASON_ID, row) = convergence_failure_reason_id nlc_path_int(NLC_PATH_I_MATERIAL_FAIL_COUNT, row) = & convergence_material_fail_count + nlc_path_int(NLC_PATH_I_ARC_MODE, row) = nlc_last_arc_mode + nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row) = & + predictor_consistent + nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, row) = load_reversal + nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, row) = turning_point nlc_path_count = row ierr = FEM_SUCCESS @@ -541,6 +608,51 @@ contains end select end function convergence_reason_from_failure + integer function cutback_reason_from_failure(failure_code, & + failure_reason_id) & + result(reason_id) + integer, intent(in) :: failure_code + integer, intent(in) :: failure_reason_id + + if (failure_reason_id .ne. NFAIL_NONE) then + select case (failure_reason_id) + case (NFAIL_LINEAR_SOLVE) + reason_id = CUTBACK_REASON_LINEAR_SOLVE + case (NFAIL_MIN_STEP) + reason_id = CUTBACK_REASON_MIN_STEP + case (NFAIL_NONCONVERGENCE) + reason_id = CUTBACK_REASON_NONCONVERGENCE + case default + reason_id = CUTBACK_REASON_NONCONVERGENCE + end select + return + end if + + select case (failure_code) + case (CONV_FAIL_NONE) + reason_id = CUTBACK_REASON_NONE + case (CONV_FAIL_CUTBACK_LIMIT) + reason_id = CUTBACK_REASON_MIN_STEP + case (CONV_FAIL_NONCONVERGENCE) + reason_id = CUTBACK_REASON_NONCONVERGENCE + case default + reason_id = CUTBACK_REASON_NONCONVERGENCE + end select + end function cutback_reason_from_failure + + subroutine cutback_reason_name(reason_id, reason_name) + integer, intent(in) :: reason_id + character(len=*), intent(out) :: reason_name + + select case (reason_id) + case (CUTBACK_REASON_NONE, CUTBACK_REASON_LINEAR_SOLVE, & + CUTBACK_REASON_MIN_STEP, CUTBACK_REASON_NONCONVERGENCE) + call convergence_failure_reason_name(reason_id, reason_name) + case default + reason_name = 'unknown' + end select + end subroutine cutback_reason_name + subroutine convergence_failure_reason_name(reason_id, reason_name) integer, intent(in) :: reason_id character(len=*), intent(out) :: reason_name diff --git a/src/base/fem_precision.f90 b/src/base/fem_precision.f90 index de4dcd8..e31a3a9 100644 --- a/src/base/fem_precision.f90 +++ b/src/base/fem_precision.f90 @@ -16,7 +16,7 @@ module fem_precision integer, parameter :: FEMLITE_VERSION_MAJOR = 0 integer, parameter :: FEMLITE_VERSION_MINOR = 6 - integer, parameter :: FEMLITE_VERSION_PATCH = 0 + integer, parameter :: FEMLITE_VERSION_PATCH = 1 real(rk), parameter :: ZERO = 0.0_rk real(rk), parameter :: ONE = 1.0_rk diff --git a/src/base/fem_tangent_audit_report.f90 b/src/base/fem_tangent_audit_report.f90 new file mode 100644 index 0000000..72f4622 --- /dev/null +++ b/src/base/fem_tangent_audit_report.f90 @@ -0,0 +1,192 @@ +module fem_tangent_audit_report + use fem_precision + use fem_error + implicit none + + private + + integer, parameter, public :: TAN_AUDIT_PASS = 1 + integer, parameter, public :: TAN_AUDIT_FAIL = 2 + integer, parameter, public :: TAN_AUDIT_MISSING = 3 + integer, parameter, public :: TAN_AUDIT_NOT_APPLICABLE = 4 + + type, public :: tangent_audit_record + character(len=48) :: audit_name = '' + character(len=48) :: branch = '' + integer :: sample_count = 0 + real(rk) :: relative_error = ZERO + integer :: status = TAN_AUDIT_NOT_APPLICABLE + end type tangent_audit_record + + public :: tangent_audit_status_name + public :: tangent_audit_record_init + public :: tangent_audit_csv_header + public :: tangent_audit_csv_record + public :: tangent_audit_coverage + +contains + + subroutine tangent_audit_status_name(status_id, status_name) + integer, intent(in) :: status_id + character(len=*), intent(out) :: status_name + + select case (status_id) + case (TAN_AUDIT_PASS) + status_name = 'pass' + case (TAN_AUDIT_FAIL) + status_name = 'fail' + case (TAN_AUDIT_MISSING) + status_name = 'missing' + case (TAN_AUDIT_NOT_APPLICABLE) + status_name = 'not-applicable' + case default + status_name = 'unknown' + end select + end subroutine tangent_audit_status_name + + subroutine tangent_audit_record_init(audit_name, branch, sample_count, & + relative_error, status_id, record, & + ierr) + character(len=*), intent(in) :: audit_name + character(len=*), intent(in) :: branch + integer, intent(in) :: sample_count + real(rk), intent(in) :: relative_error + integer, intent(in) :: status_id + type(tangent_audit_record), intent(out) :: record + integer, intent(out) :: ierr + + record%audit_name = '' + record%branch = '' + record%sample_count = 0 + record%relative_error = ZERO + record%status = TAN_AUDIT_NOT_APPLICABLE + if (len_trim(audit_name) .le. 0 .or. len_trim(branch) .le. 0) then + call error_set(FEM_ERR_INPUT, 'tangent audit record name is empty', ierr) + return + end if + if (sample_count .lt. 0) then + call error_set(FEM_ERR_INPUT, 'tangent audit sample count is negative', & + ierr) + return + end if + if (relative_error .lt. ZERO) then + call error_set(FEM_ERR_INPUT, 'tangent audit relative error is negative', & + ierr) + return + end if + if (.not. tangent_audit_valid_status(status_id)) then + call error_set(FEM_ERR_INPUT, 'unknown tangent audit status', ierr) + return + end if + + record%audit_name = audit_name + record%branch = branch + record%sample_count = sample_count + record%relative_error = relative_error + record%status = status_id + call error_clear(ierr) + end subroutine tangent_audit_record_init + + subroutine tangent_audit_csv_header(line, ierr) + character(len=*), intent(out) :: line + integer, intent(out) :: ierr + + if (len(line) .lt. 128) then + call error_set(FEM_ERR_OUTPUT, 'tangent audit header too small', ierr) + return + end if + line = 'audit_name,branch,sample_count,relative_error,status,'// & + 'missing_count,not_applicable_count' + call error_clear(ierr) + end subroutine tangent_audit_csv_header + + subroutine tangent_audit_csv_record(record, line, ierr) + type(tangent_audit_record), intent(in) :: record + character(len=*), intent(out) :: line + integer, intent(out) :: ierr + character(len=32) :: status_name + integer :: missing_count + integer :: not_applicable_count + + if (len(line) .lt. 256) then + call error_set(FEM_ERR_OUTPUT, 'tangent audit row too small', ierr) + return + end if + if (.not. tangent_audit_valid_status(record%status)) then + call error_set(FEM_ERR_INPUT, 'unknown tangent audit row status', ierr) + return + end if + + missing_count = 0 + not_applicable_count = 0 + if (record%status .eq. TAN_AUDIT_MISSING) missing_count = 1 + if (record%status .eq. TAN_AUDIT_NOT_APPLICABLE) & + not_applicable_count = 1 + call tangent_audit_status_name(record%status, status_name) + write(line, '(A,A,A,A,I0,A,ES16.8,A,A,A,I0,A,I0)') & + trim(record%audit_name), ',', trim(record%branch), ',', & + record%sample_count, ',', record%relative_error, ',', & + trim(status_name), ',', missing_count, ',', not_applicable_count + call error_clear(ierr) + end subroutine tangent_audit_csv_record + + subroutine tangent_audit_coverage(records, record_count, total_samples, & + pass_count, fail_count, missing_count, & + not_applicable_count, max_relative_error, & + ierr) + type(tangent_audit_record), intent(in) :: records(:) + integer, intent(in) :: record_count + integer, intent(out) :: total_samples + integer, intent(out) :: pass_count + integer, intent(out) :: fail_count + integer, intent(out) :: missing_count + integer, intent(out) :: not_applicable_count + real(rk), intent(out) :: max_relative_error + integer, intent(out) :: ierr + integer :: index + + total_samples = 0 + pass_count = 0 + fail_count = 0 + missing_count = 0 + not_applicable_count = 0 + max_relative_error = ZERO + + if (record_count .lt. 0 .or. record_count .gt. size(records)) then + call error_set(FEM_ERR_INPUT, 'invalid tangent audit record count', ierr) + return + end if + + do index = 1, record_count + if (.not. tangent_audit_valid_status(records(index)%status)) then + call error_set(FEM_ERR_INPUT, 'unknown tangent audit coverage status', & + ierr) + return + end if + total_samples = total_samples + records(index)%sample_count + max_relative_error = max(max_relative_error, & + records(index)%relative_error) + select case (records(index)%status) + case (TAN_AUDIT_PASS) + pass_count = pass_count + 1 + case (TAN_AUDIT_FAIL) + fail_count = fail_count + 1 + case (TAN_AUDIT_MISSING) + missing_count = missing_count + 1 + case (TAN_AUDIT_NOT_APPLICABLE) + not_applicable_count = not_applicable_count + 1 + end select + end do + call error_clear(ierr) + end subroutine tangent_audit_coverage + + logical function tangent_audit_valid_status(status_id) + integer, intent(in) :: status_id + + tangent_audit_valid_status = status_id .eq. TAN_AUDIT_PASS .or. & + status_id .eq. TAN_AUDIT_FAIL .or. & + status_id .eq. TAN_AUDIT_MISSING .or. & + status_id .eq. TAN_AUDIT_NOT_APPLICABLE + end function tangent_audit_valid_status + +end module fem_tangent_audit_report diff --git a/src/boundary/fem_contact_multiplier_report.f90 b/src/boundary/fem_contact_multiplier_report.f90 index 7383255..3aaf19a 100644 --- a/src/boundary/fem_contact_multiplier_report.f90 +++ b/src/boundary/fem_contact_multiplier_report.f90 @@ -81,9 +81,11 @@ contains real(rk) :: max_gap real(rk) :: max_commit_error real(rk) :: normal_residual + real(rk) :: max_augmented_multiplier + real(rk) :: multiplier_residual_ratio integer :: al_update_count - if (len(line) .lt. 512) then + if (len(line) .lt. 768) then call error_set(FEM_ERR_OUTPUT, 'contact multiplier summary too small', & ierr) return @@ -101,9 +103,12 @@ contains if (ierr .ne. FEM_SUCCESS) return call contact_multiplier_resid_stats(normal_residual, al_update_count, ierr) if (ierr .ne. FEM_SUCCESS) return + max_augmented_multiplier = max(max_lambda, max_trial) + multiplier_residual_ratio = normal_residual / & + max(ONE, max_augmented_multiplier) write(line, '(A,I0,A,I0,A,I0,A,I0,A,ES16.8,A,ES16.8,A,ES16.8,' // & 'A,I0,A,I0,A,ES16.8,A,I0,A,I0,A,I0,A,I0,A,I0,A,I0,A,I0,' // & - 'A,ES16.8,A,I0)') & + 'A,ES16.8,A,ES16.8,A,ES16.8,A,ES16.8,A,I0,A,I0)') & 'slots=', slots, ',active=', active, ',released=', released, & ',open=', open_count, ',max_lambda=', max_lambda, ',max_trial=', & max_trial, ',max_gap=', max_gap, ',duplicates=', duplicate_count, & @@ -114,6 +119,10 @@ contains ',state_separating=', state_separating, & ',state_failed_projection=', state_failed_proj, & ',normal_multiplier_residual=', normal_residual, & + ',max_augmented_multiplier=', max_augmented_multiplier, & + ',multiplier_residual_ratio=', multiplier_residual_ratio, & + ',accepted_step_max_lambda=', max_lambda, & + ',augmentation_update_count=', al_update_count, & ',al_update_count=', al_update_count call error_clear(ierr) end subroutine contact_mult_report_summary @@ -122,7 +131,7 @@ contains character(len=*), intent(in) :: filename integer, intent(out) :: ierr - character(len=512) :: line + character(len=1024) :: line integer :: unit integer :: ios integer :: slot diff --git a/src/boundary/fem_contact_state.f90 b/src/boundary/fem_contact_state.f90 index 7ee3bf3..c1eff98 100644 --- a/src/boundary/fem_contact_state.f90 +++ b/src/boundary/fem_contact_state.f90 @@ -9,11 +9,20 @@ module fem_contact_state integer, parameter, public :: CONTACT_PAIR_ACTIVATED = 1 integer, parameter, public :: CONTACT_PAIR_MAINTAINED = 2 integer, parameter, public :: CONTACT_PAIR_RELEASED = 3 + integer, parameter, public :: CONTACT_STATE_OPEN = 0 + integer, parameter, public :: CONTACT_STATE_CLOSED_STICK = 1 + integer, parameter, public :: CONTACT_STATE_CLOSED_SLIP = 2 + integer, parameter, public :: CONTACT_STATE_CLOSED_RESTICK = 3 + integer, parameter, public :: CONTACT_STATE_SEPARATING = 4 + integer, parameter, public :: CONTACT_STATE_FAILED_PROJECTION = 5 public :: contact_reset_status public :: contact_record_status public :: contact_finalize_status public :: contact_pair_normal_pressure + public :: contact_state_name + public :: contact_get_state_counts + public :: contact_get_state_summary public :: contact_reset_search_stats public :: contact_record_search_setup public :: contact_record_search_test @@ -340,6 +349,173 @@ contains contact_pair_stat_valid = .true. end function contact_pair_stat_valid + subroutine contact_state_name(state_id, state_name) + integer, intent(in) :: state_id + character(len=*), intent(out) :: state_name + + state_name = 'unknown' + select case (state_id) + case (CONTACT_STATE_OPEN) + state_name = 'open' + case (CONTACT_STATE_CLOSED_STICK) + state_name = 'closed-stick' + case (CONTACT_STATE_CLOSED_SLIP) + state_name = 'closed-slip' + case (CONTACT_STATE_CLOSED_RESTICK) + state_name = 'closed-restick' + case (CONTACT_STATE_SEPARATING) + state_name = 'separating' + case (CONTACT_STATE_FAILED_PROJECTION) + state_name = 'failed-projection' + end select + end subroutine contact_state_name + + subroutine contact_get_state_counts(open_count, closed_stick_count, & + closed_slip_count, & + closed_restick_count, & + separating_count, & + failed_projection_count) + integer, intent(out) :: open_count + integer, intent(out) :: closed_stick_count + integer, intent(out) :: closed_slip_count + integer, intent(out) :: closed_restick_count + integer, intent(out) :: separating_count + integer, intent(out) :: failed_projection_count + integer :: pair + integer :: stick_count + integer :: slip_count + + open_count = 0 + closed_stick_count = 0 + closed_slip_count = 0 + closed_restick_count = 0 + separating_count = 0 + failed_projection_count = 0 + if (.not. allocated(contact_pair_status)) return + + do pair = 1, size(contact_pair_status) + stick_count = 0 + slip_count = 0 + if (allocated(contact_pair_stick_count)) then + if (pair .le. size(contact_pair_stick_count)) then + stick_count = contact_pair_stick_count(pair) + end if + end if + if (allocated(contact_pair_slip_count)) then + if (pair .le. size(contact_pair_slip_count)) then + slip_count = contact_pair_slip_count(pair) + end if + end if + select case (contact_pair_status(pair)) + case (CONTACT_PAIR_OPEN) + open_count = open_count + 1 + case (CONTACT_PAIR_RELEASED) + separating_count = separating_count + 1 + case (CONTACT_PAIR_ACTIVATED, CONTACT_PAIR_MAINTAINED) + if (stick_count .gt. 0 .and. slip_count .gt. 0) then + closed_restick_count = closed_restick_count + 1 + else if (slip_count .gt. 0) then + closed_slip_count = closed_slip_count + 1 + else + closed_stick_count = closed_stick_count + 1 + end if + case default + failed_projection_count = failed_projection_count + 1 + end select + end do + end subroutine contact_get_state_counts + + subroutine contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, & + closed_restick_count, & + separating_count, & + failed_projection_count, gap_max, & + gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, & + active_set_flip_count) + integer, intent(out) :: open_count + integer, intent(out) :: closed_stick_count + integer, intent(out) :: closed_slip_count + integer, intent(out) :: closed_restick_count + integer, intent(out) :: separating_count + integer, intent(out) :: failed_projection_count + real(rk), intent(out) :: gap_max + real(rk), intent(out) :: gap_mean + real(rk), intent(out) :: gap_l2 + real(rk), intent(out) :: slip_increment + real(rk), intent(out) :: slip_residual + real(rk), intent(out) :: friction_residual + integer, intent(out) :: active_set_flip_count + integer :: pair + integer :: count + real(rk) :: gap + real(rk) :: gap_sum + real(rk) :: gap_sq + real(rk) :: tangent_norm + + call contact_get_state_counts(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count) + gap_max = ZERO + gap_mean = ZERO + gap_l2 = ZERO + slip_increment = ZERO + slip_residual = ZERO + friction_residual = ZERO + active_set_flip_count = 0 + gap_sum = ZERO + gap_sq = ZERO + count = 0 + if (ncontact_pair .le. 0) return + + do pair = 1, ncontact_pair + gap = ZERO + if (allocated(contact_pair_gap_residual)) then + if (pair .le. size(contact_pair_gap_residual)) then + gap = max(ZERO, contact_pair_gap_residual(pair)) + end if + end if + gap_max = max(gap_max, gap) + gap_sum = gap_sum + gap + gap_sq = gap_sq + gap * gap + count = count + 1 + if (allocated(contact_pair_slip)) then + if (pair .le. size(contact_pair_slip)) then + slip_increment = max(slip_increment, contact_pair_slip(pair)) + if (allocated(contact_pair_slip_count)) then + if (pair .le. size(contact_pair_slip_count)) then + if (contact_pair_slip_count(pair) .gt. 0) then + slip_residual = max(slip_residual, contact_pair_slip(pair)) + end if + end if + end if + end if + end if + if (allocated(contact_pair_tangent_force)) then + if (pair .le. size(contact_pair_tangent_force, 2)) then + tangent_norm = sqrt(sum(contact_pair_tangent_force(:, pair) ** 2)) + friction_residual = max(friction_residual, tangent_norm) + end if + end if + if (allocated(contact_pair_activation_count)) then + if (pair .le. size(contact_pair_activation_count)) then + active_set_flip_count = active_set_flip_count + & + contact_pair_activation_count(pair) + end if + end if + if (allocated(contact_pair_release_count)) then + if (pair .le. size(contact_pair_release_count)) then + active_set_flip_count = active_set_flip_count + & + contact_pair_release_count(pair) + end if + end if + end do + if (count .gt. 0) then + gap_mean = gap_sum / real(count, rk) + gap_l2 = sqrt(gap_sq) + end if + end subroutine contact_get_state_summary + subroutine contact_finalize_status() integer :: pair diff --git a/src/output/fem_output_csv.f90 b/src/output/fem_output_csv.f90 index 3f79783..6dac74d 100644 --- a/src/output/fem_output_csv.f90 +++ b/src/output/fem_output_csv.f90 @@ -4,16 +4,21 @@ module fem_output_csv use fem_control use fem_database use fem_contact_output - use fem_contact_state, only: contact_get_search_stats, contact_get_perf_stats, & - contact_get_cache_stats, contact_get_pair_stats + use fem_contact_state, only: CONTACT_PAIR_OPEN, CONTACT_PAIR_RELEASED, & + CONTACT_PAIR_ACTIVATED, CONTACT_PAIR_MAINTAINED, contact_get_search_stats, & + contact_get_perf_stats, contact_get_cache_stats, contact_get_pair_stats, & + contact_get_state_summary use fem_element_state + use fem_linear_solver_cg, only: linear_solver_get_diagnostics use fem_nonlinear_lifecycle, only: NLC_EVENT_ACCEPT, NLC_EVENT_REJECT, & nl_lifecycle_event_name, nl_lifecycle_get_audit, & nl_lifecycle_get_event_count, nl_lifecycle_get_event + use fem_nonlinear_lifecycle, only: nl_lifecycle_get_summary implicit none character(len=256) :: csv_output_directory = '.' logical :: history_header_written = .false. + logical :: lifecycle_header_written = .false. contains @@ -33,6 +38,7 @@ contains csv_output_directory = clean_path history_header_written = .false. + lifecycle_header_written = .false. ierr = FEM_SUCCESS end subroutine output_csv_set_directory @@ -160,6 +166,9 @@ contains call output_csv_write_path(ierr) if (ierr .ne. FEM_SUCCESS) return + call output_csv_write_nl_lifecycle(ierr) + if (ierr .ne. FEM_SUCCESS) return + call output_csv_write_nodes(step, ierr) if (ierr .ne. FEM_SUCCESS) return @@ -177,6 +186,7 @@ contains subroutine output_csv_reset() history_header_written = .false. + lifecycle_header_written = .false. end subroutine output_csv_reset subroutine output_csv_filename(filename) @@ -201,6 +211,17 @@ contains end if end subroutine output_csv_path_filename + subroutine output_csv_lifecycle_filename(filename) + character(len=*), intent(out) :: filename + + filename = ' ' + if (trim(csv_output_directory) .eq. '.') then + filename = 'nonlinear_lifecycle.csv' + else + filename = trim(csv_output_directory)//'/nonlinear_lifecycle.csv' + end if + end subroutine output_csv_lifecycle_filename + subroutine output_csv_build_path(name, filename) character(len=*), intent(in) :: name character(len=*), intent(out) :: filename @@ -401,7 +422,9 @@ contains 'reason_id,reason_name,lifecycle_event_id,lifecycle_event_name,'// & 'lifecycle_audit_status,lifecycle_audit_name,'// & 'lifecycle_increment,lifecycle_iteration,'// & - 'lifecycle_accept_count,lifecycle_reject_count' + 'lifecycle_accept_count,lifecycle_reject_count,'// & + 'arc_mode,arc_predictor_consistent,arc_load_reversal,'// & + 'arc_turning_point,arc_length,arc_load_delta,arc_predictor_dot' if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, & @@ -480,15 +503,22 @@ contains ',', nlc_path_int(NLC_PATH_I_MATERIAL_FAIL_COUNT, row) end if if (ios .eq. 0) then - write(unit_id,'(A,I12,A,A,A,I12,A,A,A,I12,A,A,4(A,I12))', & - iostat=ios) & + write(unit_id,'(A,I12,A,A,A,I12,A,A,A,I12,A,A,8(A,I12),'// & + '3(A,ES24.16))', iostat=ios) & ',', nlc_path_int(NLC_PATH_I_REASON_ID, row), & ',', trim(reason_name), & ',', NLC_EVENT_ACCEPT, ',', trim(event_name), & ',', audit_status, ',', trim(audit_name), & ',', nlc_path_int(NLC_PATH_I_STEP, row), & ',', nlc_path_int(NLC_PATH_I_ITERATION, row), & - ',', lifecycle_accept_count, ',', lifecycle_reject_count + ',', lifecycle_accept_count, ',', lifecycle_reject_count, & + ',', nlc_path_int(NLC_PATH_I_ARC_MODE, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_LENGTH, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_PREDICTOR_DOT, row) end if if (ios .ne. 0) then close(unit_id) @@ -502,6 +532,133 @@ contains ierr = FEM_SUCCESS end subroutine output_csv_write_path + subroutine output_csv_write_nl_lifecycle(ierr) + integer, intent(out) :: ierr + character(len=512) :: filename + integer :: unit_id + integer :: ios + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + integer :: accept_count + integer :: reject_count + integer :: cutback_count + integer :: linear_matrix_class + integer :: linear_status + integer :: linear_ierr + real(rk) :: linear_initial_residual + real(rk) :: linear_final_residual + real(rk) :: linear_relative_residual + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + character(len=64) :: failure_reason_name + character(len=64) :: cutback_reason_name_text + + call output_csv_lifecycle_filename(filename) + unit_id = 69 + if (lifecycle_header_written) then + open(unit=unit_id, file=trim(filename), status='unknown', & + position='append', action='write', iostat=ios) + else + open(unit=unit_id, file=trim(filename), status='replace', & + action='write', iostat=ios) + end if + if (ios .ne. 0) then + call error_set(FEM_ERR_OUTPUT, & + 'failed to open nonlinear lifecycle CSV output', ierr) + return + end if + + if (.not. lifecycle_header_written) then + write(unit_id,'(A)',iostat=ios) & + 'step,increment,iteration,event_id,event_name,reason_id,'// & + 'reason_name,convergence_status,failure_code,'// & + 'failure_reason_id,failure_reason_name,cutback_reason_id,'// & + 'cutback_reason_name,residual_total,residual_force,'// & + 'residual_contact,residual_constraint,residual_arc,'// & + 'material_failure_count,linear_matrix_class,linear_status,'// & + 'linear_method,linear_precond,linear_iterations,'// & + 'linear_initial_residual,linear_final_residual,'// & + 'linear_relative_residual,linear_fail_class,'// & + 'audit_status,audit_name,audit_begin_trial,'// & + 'audit_rollback_requested,audit_rollback_ok,'// & + 'audit_rollback_failed,audit_commit_ok,accept_count,'// & + 'reject_count,cutback_count' + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to write nonlinear lifecycle CSV header', ierr) + return + end if + end if + + call nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, accept_count, reject_count, & + cutback_count) + call convergence_failure_reason_name(convergence_failure_reason_id, & + failure_reason_name) + call cutback_reason_name(conv_last_cutback_reason_id, & + cutback_reason_name_text) + call linear_solver_get_diagnostics(linear_matrix_class, & + linear_initial_residual, linear_final_residual, & + linear_relative_residual, linear_status, linear_ierr) + if (linear_ierr .ne. FEM_SUCCESS) then + close(unit_id) + ierr = linear_ierr + return + end if + + write(unit_id,'(I12,3(A,I12),A,A,A,I12,A,A,3(A,I12),'// & + 'A,A,A,I12,A,A)',iostat=ios, advance='no') & + step, ',', increment, ',', iteration, ',', event_id, & + ',', trim(event_name), ',', reason_id, ',', trim(reason_name), & + ',', convergence_status_code, ',', convergence_failure_code, & + ',', convergence_failure_reason_id, ',', trim(failure_reason_name), & + ',', conv_last_cutback_reason_id, ',', trim(cutback_reason_name_text) + if (ios .eq. 0) then + write(unit_id,'(5(A,ES24.16),6(A,I12),3(A,ES24.16),'// & + '2(A,I12),A,A,8(A,I12))', & + iostat=ios) & + ',', convergence_total_resid_norm, & + ',', convergence_force_resid_norm, & + ',', convergence_contact_resid_norm, & + ',', convergence_cons_resid_norm, & + ',', convergence_arc_resid_norm, & + ',', convergence_material_fail_count, & + ',', linear_matrix_class, ',', linear_status, & + ',', linear_solver_last_method, ',', linear_solver_last_prec, & + ',', linear_solver_last_iter, & + ',', linear_initial_residual, ',', linear_final_residual, & + ',', linear_relative_residual, ',', linsol_last_fail_class, & + ',', audit_status, ',', trim(audit_name), & + ',', begin_trial_count, ',', rollback_requested_count, & + ',', rollback_ok_count, ',', rollback_failed_count, & + ',', commit_ok_count, ',', accept_count, ',', reject_count, & + ',', cutback_count + end if + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to write nonlinear lifecycle CSV row', ierr) + return + end if + + close(unit_id) + lifecycle_header_written = .true. + ierr = FEM_SUCCESS + end subroutine output_csv_write_nl_lifecycle + subroutine output_csv_write_elements(step, ierr) integer, intent(in) :: step integer, intent(out) :: ierr @@ -615,6 +772,8 @@ contains 'friction_work,friction_work_total,friction_regularization,ftx,fty,ftz,'// & 'status,activation_count,release_count,gap_residual,gap_mean,'// & 'gap_l2,failed_projection_count,active_set_flip_count,'// & + 'open_count,closed_stick_count,closed_slip_count,'// & + 'closed_restick_count,separating_count,state_failed_projection_count,'// & 'aug_factor,aug_lambda,'// & 'search_facets,search_masters,search_candidates,search_active,'// & 'search_bvh_nodes,search_cache_used,search_cache_overflow,'// & @@ -636,6 +795,9 @@ contains real(rk) :: gap_residual, gap_mean, gap_l2 real(rk) :: slip_inc, slip_residual, friction_residual integer :: failed_projection, active_set_flip + integer :: open_count, closed_stick_count, closed_slip_count + integer :: closed_restick_count, separating_count + integer :: state_failed_projection_count integer :: ios call contact_get_search_stats(search_facets, search_masters, & @@ -643,13 +805,14 @@ contains search_bvh_nodes) call contact_get_perf_stats(search_time, force_time, tangent_time) call contact_get_cache_stats(cache_used, cache_overflow) - call output_csv_contact_gap_stats(0, gap_residual, gap_mean, gap_l2, & - failed_projection, active_set_flip) - call output_csv_contact_slip_stats(0, slip_inc, slip_residual, & - friction_residual) + call contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + state_failed_projection_count, gap_residual, gap_mean, gap_l2, & + slip_inc, slip_residual, friction_residual, active_set_flip) + failed_projection = state_failed_projection_count write(unit_id,'(A,A,I12,A,I12,4(A,ES24.16),2(A,I12),'// & '10(A,ES24.16),3(A,I12),3(A,ES24.16),2(A,I12),'// & - '2(A,ES24.16),7(A,I12),'// & + '6(A,I12),2(A,ES24.16),7(A,I12),'// & '3(A,ES24.16))',iostat=ios) & 'SUMMARY', ',', 0, ',', contact_active_count, & ',', contact_max_penetration, ',', contact_force_norm, & @@ -660,6 +823,9 @@ contains ',', ZERO, ',', ZERO, ',', ZERO, & ',', 0, ',', 0, ',', 0, ',', gap_residual, ',', gap_mean, & ',', gap_l2, ',', failed_projection, ',', active_set_flip, & + ',', open_count, ',', closed_stick_count, ',', closed_slip_count, & + ',', closed_restick_count, ',', separating_count, & + ',', state_failed_projection_count, & ',', ZERO, ',', ZERO, & ',', search_facets, ',', search_masters, ',', search_broad, & ',', search_active, ',', search_bvh_nodes, ',', cache_used, & @@ -683,6 +849,9 @@ contains real(rk) :: slip_inc, slip_residual, friction_residual real(rk) :: search_time, force_time, tangent_time integer :: failed_projection, active_set_flip + integer :: open_count, closed_stick_count, closed_slip_count + integer :: closed_restick_count, separating_count + integer :: state_failed_projection_count integer :: ios active = 0 @@ -702,10 +871,13 @@ contains failed_projection, active_set_flip) call output_csv_contact_slip_stats(pair, slip_inc, slip_residual, & friction_residual) + call output_csv_contact_state_stats(pair, open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + state_failed_projection_count) write(unit_id,'(A,A,I12,A,I12,4(A,ES24.16),2(A,I12),'// & '10(A,ES24.16),3(A,I12),3(A,ES24.16),2(A,I12),'// & - '2(A,ES24.16),7(A,I12),'// & + '6(A,I12),2(A,ES24.16),7(A,I12),'// & '3(A,ES24.16))',iostat=ios) & 'PAIR', ',', pair, ',', active, ',', max_pen, ',', force_sum, & ',', work_sum, ',', ZERO, & @@ -723,6 +895,9 @@ contains ',', contact_pair_release_value(pair), & ',', gap_residual, ',', gap_mean, ',', gap_l2, & ',', failed_projection, ',', active_set_flip, & + ',', open_count, ',', closed_stick_count, ',', closed_slip_count, & + ',', closed_restick_count, ',', separating_count, & + ',', state_failed_projection_count, & ',', contact_pair_aug_factor_value(pair), & ',', contact_pair_aug_lambda_value(pair), & ',', search_facets, ',', search_masters, ',', search_broad, & @@ -735,6 +910,52 @@ contains ierr = FEM_SUCCESS end subroutine output_csv_contact_pair + subroutine output_csv_contact_state_stats(pair, open_count, & + closed_stick_count, & + closed_slip_count, & + closed_restick_count, & + separating_count, & + failed_projection_count) + integer, intent(in) :: pair + integer, intent(out) :: open_count + integer, intent(out) :: closed_stick_count + integer, intent(out) :: closed_slip_count + integer, intent(out) :: closed_restick_count + integer, intent(out) :: separating_count + integer, intent(out) :: failed_projection_count + integer :: status + integer :: stick_count + integer :: slip_count + + open_count = 0 + closed_stick_count = 0 + closed_slip_count = 0 + closed_restick_count = 0 + separating_count = 0 + failed_projection_count = 0 + + status = contact_pair_status_value(pair) + stick_count = contact_pair_stick_value(pair) + slip_count = contact_pair_slip_value(pair) + + select case (status) + case (CONTACT_PAIR_OPEN) + open_count = 1 + case (CONTACT_PAIR_RELEASED) + separating_count = 1 + case (CONTACT_PAIR_ACTIVATED, CONTACT_PAIR_MAINTAINED) + if (stick_count .gt. 0 .and. slip_count .gt. 0) then + closed_restick_count = 1 + else if (slip_count .gt. 0) then + closed_slip_count = 1 + else + closed_stick_count = 1 + end if + case default + failed_projection_count = 1 + end select + end subroutine output_csv_contact_state_stats + subroutine output_csv_contact_gap_stats(pair, gap_residual, gap_mean, & gap_l2, failed_projection, & diff --git a/src/solver/fem_nonlinear_lifecycle.f90 b/src/solver/fem_nonlinear_lifecycle.f90 index 2a280c7..90c6c6a 100644 --- a/src/solver/fem_nonlinear_lifecycle.f90 +++ b/src/solver/fem_nonlinear_lifecycle.f90 @@ -29,6 +29,7 @@ module fem_nonlinear_lifecycle public :: nl_lifecycle_record_event public :: nl_lifecycle_record_audit public :: nl_lifecycle_get_snapshot + public :: nl_lifecycle_get_summary public :: nl_lifecycle_record_arc_state public :: nl_lifecycle_mark_path_appended public :: nl_lifecycle_get_arc_state @@ -203,6 +204,56 @@ contains end if end subroutine nl_lifecycle_get_snapshot + subroutine nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, & + audit_status, audit_name, & + begin_trial_count, & + rollback_requested_count, & + rollback_ok_count, & + rollback_failed_count, & + commit_ok_count, accept_count, & + reject_count, cutback_event_count) + integer, intent(out) :: step + integer, intent(out) :: increment + integer, intent(out) :: iteration + integer, intent(out) :: event_id + character(len=*), intent(out) :: event_name + integer, intent(out) :: reason_id + character(len=*), intent(out) :: reason_name + integer, intent(out) :: audit_status + character(len=*), intent(out) :: audit_name + integer, intent(out) :: begin_trial_count + integer, intent(out) :: rollback_requested_count + integer, intent(out) :: rollback_ok_count + integer, intent(out) :: rollback_failed_count + integer, intent(out) :: commit_ok_count + integer, intent(out) :: accept_count + integer, intent(out) :: reject_count + integer, intent(out) :: cutback_event_count + integer :: i + + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name) + begin_trial_count = audit_begin_trial_count + rollback_requested_count = audit_rollback_req_count + rollback_ok_count = audit_rollback_ok_count + rollback_failed_count = audit_rollback_fail_count + commit_ok_count = audit_commit_ok_count + accept_count = 0 + reject_count = 0 + cutback_event_count = 0 + do i = 1, lifecycle_event_count + select case (event_id_hist(i)) + case (NLC_EVENT_ACCEPT) + accept_count = accept_count + 1 + case (NLC_EVENT_REJECT) + reject_count = reject_count + 1 + case (NLC_EVENT_CUTBACK) + cutback_event_count = cutback_event_count + 1 + end select + end do + end subroutine nl_lifecycle_get_summary + subroutine nl_lifecycle_record_audit(status_id) integer, intent(in) :: status_id diff --git a/src/solver/fem_solver_implicit.f90 b/src/solver/fem_solver_implicit.f90 index 18a2d1d..c886475 100644 --- a/src/solver/fem_solver_implicit.f90 +++ b/src/solver/fem_solver_implicit.f90 @@ -281,6 +281,7 @@ contains convergence_status_code = CONVERGENCE_STATUS_ITERATING convergence_failure_code = CONV_FAIL_NONE convergence_failure_reason_id = NFAIL_NONE + conv_last_cutback_reason_id = CUTBACK_REASON_NONE nlc_last_target_dt = ZERO nlc_last_actual_dt = ZERO nlc_next_target_dt = ZERO diff --git a/src/solver/fem_solver_static_nonlinear.f90 b/src/solver/fem_solver_static_nonlinear.f90 index 82c1abb..b52fe3e 100644 --- a/src/solver/fem_solver_static_nonlinear.f90 +++ b/src/solver/fem_solver_static_nonlinear.f90 @@ -435,9 +435,16 @@ contains real(rk), intent(in) :: u_equil(:) integer, intent(inout) :: cut_count integer, intent(out) :: ierr + integer :: cutback_reason load_factor = base_load_factor if (use_static_predictor) u = u_equil + cutback_reason = cutback_reason_from_failure(convergence_failure_code, & + convergence_failure_reason_id) + if (cutback_reason .eq. CUTBACK_REASON_NONE) then + cutback_reason = CUTBACK_REASON_NONCONVERGENCE + end if + conv_last_cutback_reason_id = cutback_reason dt_try = dt_try * cutback_factor cut_count = cut_count + 1 convergence_cutback_count = convergence_cutback_count + 1 @@ -449,7 +456,7 @@ contains nlc_next_target_dt = dt_try call nl_lifecycle_record_event(current_step + 1, current_step + 1, & convergence_iteration, & - NLC_EVENT_CUTBACK, NFAIL_NONE) + NLC_EVENT_CUTBACK, cutback_reason) call error_clear(ierr) end subroutine cutback_static_increment @@ -466,6 +473,10 @@ contains else convergence_failure_reason_id = NFAIL_MIN_STEP end if + if (conv_last_cutback_reason_id .eq. CUTBACK_REASON_NONE) then + conv_last_cutback_reason_id = cutback_reason_from_failure( & + convergence_failure_code, convergence_failure_reason_id) + end if nlc_last_adjust = NLC_ADJ_FAILED nlc_next_target_dt = ZERO call nl_lifecycle_record_event(current_step + 1, current_step + 1, & @@ -978,12 +989,14 @@ contains real(rk) :: tangent_dot predictor_sign = sign_dir + nlc_last_arc_predictor_dot = ZERO if (.not. static_arc_saved) return if (.not. allocated(static_arc_saved_du)) return if (size(static_arc_saved_du) .ne. size(du_load)) return tangent_dot = sum(static_arc_saved_du * du_load) + & load_scale * load_scale * static_arc_saved_dl + nlc_last_arc_predictor_dot = tangent_dot if (predictor_sign * tangent_dot .lt. ZERO) predictor_sign = -predictor_sign end function static_arc_predictor_sign @@ -1258,6 +1271,7 @@ contains reaction_sum = sum(freaction) reaction_generalized = load_factor + nlc_last_arc_mode = NLC_ARC_MODE_LOAD call nlc_path_append(current_step, time, load_factor, control_count, & actual_l2, actual_max, actual_l2, actual_max, residual_linf, & residual_l2, reaction_sum, reaction_generalized, & @@ -1357,6 +1371,11 @@ contains reaction_generalized = ZERO end if + if (nonlinear_continuation_method .eq. NLC_ARC_DISP) then + nlc_last_arc_mode = NLC_ARC_MODE_DISP + else + nlc_last_arc_mode = NLC_ARC_MODE_NONE + end if call nlc_path_append(current_step, time, time, control_count, & prescribed_l2, prescribed_max, actual_l2, actual_max, residual_linf, & residual_l2, reaction_sum, reaction_generalized, convergence_iteration, & diff --git a/tests/interface/test_c_api.c b/tests/interface/test_c_api.c index cd64524..a789e51 100644 --- a/tests/interface/test_c_api.c +++ b/tests/interface/test_c_api.c @@ -113,7 +113,7 @@ int main(void) ierr = femlite_get_version(&major, &minor, &patch); if (ierr != 0) return check_ierr(ierr, 2); - if (major != 0 || minor != 6 || patch != 0) return 3; + if (major != 0 || minor != 6 || patch != 1) return 3; ierr = femlite_read_inp("examples/c3d4_one_element.inp"); if (ierr != 0) return check_ierr(ierr, 4); diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index 170aa4f..bcb7ae4 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -6,7 +6,10 @@ program test_contact use fem_contact_state, only: CONTACT_PAIR_ACTIVATED, & CONTACT_PAIR_MAINTAINED, CONTACT_PAIR_RELEASED, & contact_get_search_stats, contact_get_perf_stats, contact_get_cache_stats, & - contact_get_pair_stats + contact_get_pair_stats, CONTACT_STATE_OPEN, CONTACT_STATE_CLOSED_STICK, & + CONTACT_STATE_CLOSED_SLIP, CONTACT_STATE_CLOSED_RESTICK, & + CONTACT_STATE_SEPARATING, CONTACT_STATE_FAILED_PROJECTION, & + contact_state_name, contact_get_state_summary use fem_contact_candidate_cache, only: contact_candidate_cache_stats use fem_contact_history, only: contact_history_stats, & contact_history_state_stats @@ -24,6 +27,7 @@ program test_contact real(rk), parameter :: TOL = 1.0e-10_rk + call check_contact_state_names() call check_plane_force() call check_target_node_only() call check_analytic_pair_plane_force() @@ -41,6 +45,25 @@ program test_contact contains + subroutine check_contact_state_names() + character(len=64) :: name + + call contact_state_name(CONTACT_STATE_OPEN, name) + if (trim(name) .ne. 'open') call fail(9100) + call contact_state_name(CONTACT_STATE_CLOSED_STICK, name) + if (trim(name) .ne. 'closed-stick') call fail(9101) + call contact_state_name(CONTACT_STATE_CLOSED_SLIP, name) + if (trim(name) .ne. 'closed-slip') call fail(9102) + call contact_state_name(CONTACT_STATE_CLOSED_RESTICK, name) + if (trim(name) .ne. 'closed-restick') call fail(9103) + call contact_state_name(CONTACT_STATE_SEPARATING, name) + if (trim(name) .ne. 'separating') call fail(9104) + call contact_state_name(CONTACT_STATE_FAILED_PROJECTION, name) + if (trim(name) .ne. 'failed-projection') call fail(9105) + call contact_state_name(-999, name) + if (trim(name) .ne. 'unknown') call fail(9106) + end subroutine check_contact_state_names + subroutine check_multiplier_history() integer :: ierr integer :: slot_count @@ -214,6 +237,19 @@ contains real(rk) :: conv_relative_residual real(rk) :: conv_contact_gap real(rk) :: conv_combined_norm + real(rk) :: gap_max + real(rk) :: gap_mean + real(rk) :: gap_l2 + real(rk) :: slip_increment + real(rk) :: slip_residual + real(rk) :: friction_residual + integer :: open_count + integer :: closed_stick_count + integer :: closed_slip_count + integer :: closed_restick_count + integer :: separating_count + integer :: failed_projection_count + integer :: active_set_flip_count call fem_initialize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(145) @@ -276,6 +312,24 @@ contains 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) + call fem_get_contact_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(157) + if (open_count .ne. 0) call fail(158) + if (closed_stick_count .ne. 1) call fail(159) + if (closed_slip_count .ne. 0) call fail(160) + if (closed_restick_count .ne. 0) call fail(161) + if (separating_count .ne. 0) call fail(162) + if (failed_projection_count .ne. 0) call fail(163) + call check_close(gap_max, 0.01_rk, 164) + call check_close(gap_mean, 0.01_rk, 165) + call check_close(gap_l2, 0.01_rk, 166) + call check_close(slip_increment, ZERO, 167) + call check_close(slip_residual, ZERO, 168) + call check_close(friction_residual, ZERO, 169) + if (active_set_flip_count .ne. 1) call fail(170) u(dof) = 0.01_rk call contact_apply_plane_forces(ierr) @@ -284,6 +338,13 @@ contains if (contact_pair_status(1) .ne. CONTACT_PAIR_RELEASED) call fail(141) if (contact_pair_release_count(1) .ne. 1) call fail(142) call check_close(contact_pair_aug_lambda(1), ZERO, 143) + call fem_get_contact_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(171) + if (separating_count .ne. 1) call fail(172) + if (active_set_flip_count .ne. 2) call fail(173) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(144) @@ -469,6 +530,19 @@ contains integer :: dof integer :: row integer :: col + integer :: open_count + integer :: closed_stick_count + integer :: closed_slip_count + integer :: closed_restick_count + integer :: separating_count + integer :: failed_projection_count + integer :: active_set_flip_count + real(rk) :: gap_max + real(rk) :: gap_mean + real(rk) :: gap_l2 + real(rk) :: slip_increment + real(rk) :: slip_residual + real(rk) :: friction_residual real(rk) :: value call setup_contact_shell_pair(ierr) @@ -498,6 +572,16 @@ contains call check_close(contact_friction_work_total, 2.0_rk, 505) call check_close(contact_pair_friction_work(1), 2.0_rk, 506) call check_close(contact_pair_fric_work_total(1), 2.0_rk, 507) + call contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count) + if (closed_slip_count .ne. 1) call fail(508) + if (closed_stick_count .ne. 0) call fail(509) + if (failed_projection_count .ne. 0) call fail(5140) + if (slip_increment .le. ZERO) call fail(5141) + if (slip_residual .le. ZERO) call fail(5142) + if (friction_residual .le. ZERO) call fail(5143) call csr_init(kmat) call assembly_build_csr_pattern(kmat, ierr) @@ -684,6 +768,8 @@ contains 'friction_work,friction_work_total,friction_regularization,ftx,fty,ftz,'// & 'status,activation_count,release_count,gap_residual,gap_mean,'// & 'gap_l2,failed_projection_count,active_set_flip_count,'// & + 'open_count,closed_stick_count,closed_slip_count,'// & + 'closed_restick_count,separating_count,state_failed_projection_count,'// & 'aug_factor,aug_lambda', 601) call require_contains('contact_00000910.csv', & 'search_facets,search_masters,search_candidates,search_active,'// & diff --git a/tests/module/test_contact_mortar_tangent.f90 b/tests/module/test_contact_mortar_tangent.f90 index 83643e6..eaf6012 100644 --- a/tests/module/test_contact_mortar_tangent.f90 +++ b/tests/module/test_contact_mortar_tangent.f90 @@ -3,6 +3,7 @@ program test_contact_mortar_tangent use fem_error use fem_contact_mortar_cons use fem_contact_mortar_tangent + use fem_tangent_audit_report implicit none real(rk), parameter :: TOL = 1.0e-10_rk @@ -288,9 +289,17 @@ contains type(mortar_tangent_params) :: params type(mortar_tangent_diag) :: diag type(mortar_tangent_audit) :: audit + type(tangent_audit_record) :: records(5) real(rk) :: k_local(MORTAR_TAN_MAX_DOF,MORTAR_TAN_MAX_DOF) integer :: ndof integer :: ierr + integer :: total_samples + integer :: pass_count + integer :: fail_count + integer :: missing_count + integer :: not_applicable_count + real(rk) :: max_relative_error + character(len=512) :: line call make_weighted_constraint(cons, ierr) call require_success(ierr, 145) @@ -314,6 +323,10 @@ contains call check_close(audit%slip_relative_fd_error, ZERO, 168) call check_close(audit%friction_rigid_residual, ZERO, 169) call check_close(audit%friction_energy_residual, ZERO, 170) + call tangent_audit_record_init('contact-mortar', 'normal', & + audit%node_count, audit%normal_relative_fd_error, TAN_AUDIT_PASS, & + records(1), ierr) + call require_success(ierr, 190) params%nonsym_scale = 0.25_rk call mortar_tan_params_valid(params, ierr) @@ -330,6 +343,47 @@ contains if (audit%slip_relative_fd_error .le. ZERO) call fail(162) call check_close(audit%friction_rigid_residual, ZERO, 163) call check_close(audit%friction_energy_residual, ZERO, 164) + call tangent_audit_record_init('contact-mortar', 'slip', & + audit%node_count, audit%slip_relative_fd_error, TAN_AUDIT_PASS, & + records(2), ierr) + call require_success(ierr, 191) + call tangent_audit_record_init('shell-finite', 'membrane', 24, ZERO, & + TAN_AUDIT_PASS, records(3), ierr) + call require_success(ierr, 192) + call tangent_audit_record_init('material-j2', 'consistent', 0, ZERO, & + TAN_AUDIT_MISSING, records(4), ierr) + call require_success(ierr, 193) + call tangent_audit_record_init('riks-arc', 'predictor', 0, ZERO, & + TAN_AUDIT_NOT_APPLICABLE, records(5), ierr) + call require_success(ierr, 194) + + call tangent_audit_csv_header(line, ierr) + call require_success(ierr, 195) + if (index(line, 'audit_name,branch,sample_count,relative_error,status') & + .ne. 1) call fail(196) + call tangent_audit_csv_record(records(1), line, ierr) + call require_success(ierr, 197) + if (index(line, 'contact-mortar,normal') .ne. 1) call fail(198) + if (index(line, ',pass,0,0') .le. 0) call fail(199) + call tangent_audit_csv_record(records(3), line, ierr) + call require_success(ierr, 200) + if (index(line, 'shell-finite,membrane') .ne. 1) call fail(201) + call tangent_audit_csv_record(records(4), line, ierr) + call require_success(ierr, 202) + if (index(line, ',missing,1,0') .le. 0) call fail(203) + call tangent_audit_csv_record(records(5), line, ierr) + call require_success(ierr, 204) + if (index(line, ',not-applicable,0,1') .le. 0) call fail(205) + + call tangent_audit_coverage(records, 5, total_samples, pass_count, & + fail_count, missing_count, not_applicable_count, max_relative_error, & + ierr) + call require_success(ierr, 206) + if (total_samples .ne. 32) call fail(207) + if (pass_count .ne. 3 .or. fail_count .ne. 0) call fail(208) + if (missing_count .ne. 1) call fail(209) + if (not_applicable_count .ne. 1) call fail(210) + if (max_relative_error .le. ZERO) call fail(211) end subroutine check_tangent_audit subroutine check_projector_diag() diff --git a/tests/module/test_contact_multiplier_report.f90 b/tests/module/test_contact_multiplier_report.f90 index 40e4f60..8cea28b 100644 --- a/tests/module/test_contact_multiplier_report.f90 +++ b/tests/module/test_contact_multiplier_report.f90 @@ -15,7 +15,7 @@ program test_contact_multiplier_report contains subroutine check_header_csv_summary() - character(len=512) :: line + character(len=1024) :: line integer :: ierr call make_multiplier_state(ierr) @@ -52,11 +52,15 @@ contains if (index(line, 'state_failed_projection=0') .le. 0) call fail(30) if (index(line, 'normal_multiplier_residual=') .le. 0) call fail(31) if (index(line, 'al_update_count=2') .le. 0) call fail(32) + if (index(line, 'max_augmented_multiplier=') .le. 0) call fail(33) + if (index(line, 'multiplier_residual_ratio=') .le. 0) call fail(34) + if (index(line, 'accepted_step_max_lambda=') .le. 0) call fail(35) + if (index(line, 'augmentation_update_count=2') .le. 0) call fail(36) call contact_multiplier_reset() end subroutine check_header_csv_summary subroutine check_file_report() - character(len=512) :: line + character(len=1024) :: line logical :: saw_header logical :: saw_released logical :: saw_summary diff --git a/tests/module/test_nonlinear_lifecycle.f90 b/tests/module/test_nonlinear_lifecycle.f90 index 2c07c0f..0798e5d 100644 --- a/tests/module/test_nonlinear_lifecycle.f90 +++ b/tests/module/test_nonlinear_lifecycle.f90 @@ -3,8 +3,12 @@ program test_nonlinear_lifecycle use fem_error use fem_control use fem_api, only: fem_initialize, fem_finalize - use fem_api_diagnostics, only: fem_get_nl_lifecycle_snapshot + use fem_api_diagnostics, only: fem_record_convergence, & + fem_get_cutback_reason, fem_get_nl_lifecycle_snapshot, & + fem_get_nl_lifecycle_summary use fem_nonlinear_lifecycle + use fem_output_csv, only: output_csv_set_directory, & + output_csv_write_nl_lifecycle implicit none call check_event_names() @@ -12,7 +16,11 @@ program test_nonlinear_lifecycle call check_recorded_snapshot() call check_begin_increment() call check_audit_core() + call check_cutback_reason_names() + call check_summary_core() + call check_lifecycle_report_empty() call check_api_snapshot() + call check_api_summary() contains @@ -174,6 +182,121 @@ contains if (trim(audit_name) .ne. 'commit-ok') call fail(902) end subroutine check_audit_core + subroutine check_cutback_reason_names() + character(len=64) :: name + + call cutback_reason_name(CUTBACK_REASON_NONE, name) + if (trim(name) .ne. 'none') call fail(950) + call cutback_reason_name(CUTBACK_REASON_NONCONVERGENCE, name) + if (trim(name) .ne. 'nonlinear-nonconvergence') call fail(951) + call cutback_reason_name(CUTBACK_REASON_MIN_STEP, name) + if (trim(name) .ne. 'minimum-step-exhausted') call fail(952) + call cutback_reason_name(CUTBACK_REASON_LINEAR_SOLVE, name) + if (trim(name) .ne. 'linear-solve-failure') call fail(953) + call cutback_reason_name(-999, name) + if (trim(name) .ne. 'unknown') call fail(954) + if (cutback_reason_from_failure(CONV_FAIL_CUTBACK_LIMIT, & + NFAIL_NONE) .ne. CUTBACK_REASON_MIN_STEP) call fail(955) + if (cutback_reason_from_failure(CONV_FAIL_NONE, & + NFAIL_LINEAR_SOLVE) .ne. CUTBACK_REASON_LINEAR_SOLVE) call fail(956) + if (cutback_reason_from_failure(CONV_FAIL_NONCONVERGENCE, & + NFAIL_NONE) .ne. CUTBACK_REASON_NONCONVERGENCE) call fail(957) + end subroutine check_cutback_reason_names + + subroutine check_summary_core() + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + integer :: accept_count + integer :: reject_count + integer :: cutback_count + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + + call nl_lifecycle_reset() + call nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, accept_count, reject_count, & + cutback_count) + if (step .ne. 0) call fail(1000) + if (event_id .ne. NLC_EVENT_NONE) call fail(1001) + if (trim(event_name) .ne. 'none') call fail(1002) + if (audit_status .ne. NLC_AUDIT_NONE) call fail(1003) + if (accept_count .ne. 0) call fail(1004) + if (reject_count .ne. 0) call fail(1005) + if (cutback_count .ne. 0) call fail(1006) + + call nl_lifecycle_record_event(1, 2, 0, NLC_EVENT_INCREMENT_BEGIN, & + NFAIL_NONE) + call nl_lifecycle_record_event(1, 2, 1, NLC_EVENT_ACCEPT, NFAIL_NONE) + call nl_lifecycle_record_event(1, 3, 1, NLC_EVENT_CUTBACK, & + NFAIL_NONCONVERGENCE) + call nl_lifecycle_record_event(1, 3, 1, NLC_EVENT_REJECT, & + NFAIL_MIN_STEP) + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED) + call nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, accept_count, reject_count, & + cutback_count) + if (step .ne. 1) call fail(1010) + if (increment .ne. 3) call fail(1011) + if (iteration .ne. 1) call fail(1012) + if (event_id .ne. NLC_EVENT_REJECT) call fail(1013) + if (trim(event_name) .ne. 'reject') call fail(1014) + if (reason_id .ne. NFAIL_MIN_STEP) call fail(1015) + if (trim(reason_name) .ne. 'minimum-step-exhausted') call fail(1016) + if (audit_status .ne. NLC_AUDIT_ROLLBACK_REQUESTED) call fail(1017) + if (trim(audit_name) .ne. 'rollback-requested') call fail(1018) + if (begin_trial_count .ne. 1) call fail(1019) + if (rollback_requested_count .ne. 1) call fail(1020) + if (rollback_ok_count .ne. 0) call fail(1021) + if (rollback_failed_count .ne. 0) call fail(1022) + if (commit_ok_count .ne. 0) call fail(1023) + if (accept_count .ne. 1) call fail(1024) + if (reject_count .ne. 1) call fail(1025) + if (cutback_count .ne. 1) call fail(1026) + end subroutine check_summary_core + + subroutine check_lifecycle_report_empty() + integer :: ierr + integer :: ios + integer :: unit_id + character(len=2048) :: header + character(len=2048) :: row_line + + call nl_lifecycle_reset() + call output_csv_set_directory( & + 'build-codex-gcc/test_nonlinear_lifecycle_report_empty', ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1030) + call output_csv_write_nl_lifecycle(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1031) + + unit_id = 93 + open(unit=unit_id, & + file='build-codex-gcc/test_nonlinear_lifecycle_report_empty/nonlinear_lifecycle.csv', & + status='old', action='read', iostat=ios) + if (ios .ne. 0) call fail(1032) + read(unit_id,'(A)',iostat=ios) header + if (ios .ne. 0) call fail(1033) + read(unit_id,'(A)',iostat=ios) row_line + close(unit_id) + if (ios .ne. 0) call fail(1034) + call check_lifecycle_report_header(header, 1035) + if (index(row_line, ',none,') .le. 0) call fail(1045) + end subroutine check_lifecycle_report_empty + subroutine check_api_snapshot() integer :: ierr integer :: step @@ -212,6 +335,107 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(105) end subroutine check_api_snapshot + subroutine check_api_summary() + integer :: ierr + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + integer :: convergence_status + integer :: failure_code + integer :: failure_reason_id + integer :: material_fail_count + integer :: linear_matrix_class + integer :: linear_status + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + integer :: accept_count + integer :: reject_count + integer :: cutback_count + integer :: cutback_reason_id + real(rk) :: total_residual + real(rk) :: force_residual + real(rk) :: contact_residual + real(rk) :: constraint_residual + real(rk) :: arc_residual + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: failure_reason_name + character(len=64) :: audit_name + character(len=64) :: cutback_reason + + call fem_initialize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1100) + call nl_lifecycle_reset() + call nl_lifecycle_record_event(4, 5, 6, NLC_EVENT_ACCEPT, NFAIL_NONE) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + call fem_record_convergence(5, 6, 0.25_rk, 0.125_rk, 0.1_rk, & + 0.5_rk, .true., 0.025_rk, 0.01_rk) + call fem_get_cutback_reason(cutback_reason_id, cutback_reason, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1127) + if (cutback_reason_id .ne. CUTBACK_REASON_NONE) call fail(1128) + if (trim(cutback_reason) .ne. 'none') call fail(1129) + + call fem_get_nl_lifecycle_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, convergence_status, failure_code, & + failure_reason_id, failure_reason_name, total_residual, & + force_residual, contact_residual, constraint_residual, arc_residual, & + material_fail_count, linear_matrix_class, linear_status, audit_status, & + audit_name, begin_trial_count, rollback_requested_count, & + rollback_ok_count, rollback_failed_count, commit_ok_count, & + accept_count, reject_count, cutback_count, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1101) + if (step .ne. 4) call fail(1102) + if (increment .ne. 5) call fail(1103) + if (iteration .ne. 6) call fail(1104) + if (event_id .ne. NLC_EVENT_ACCEPT) call fail(1105) + if (trim(event_name) .ne. 'accept') call fail(1106) + if (reason_id .ne. NFAIL_NONE) call fail(1107) + if (convergence_status .ne. CONVERGENCE_STATUS_CONVERGED) & + call fail(1108) + if (failure_code .ne. CONV_FAIL_NONE) call fail(1109) + if (failure_reason_id .ne. NFAIL_NONE) call fail(1110) + if (trim(failure_reason_name) .ne. 'none') call fail(1111) + if (abs(total_residual - 0.25_rk) .gt. 1.0e-14_rk) call fail(1112) + if (abs(force_residual - 0.25_rk) .gt. 1.0e-14_rk) call fail(1113) + if (abs(contact_residual - 0.01_rk) .gt. 1.0e-14_rk) call fail(1114) + if (abs(constraint_residual) .gt. 1.0e-14_rk) call fail(1115) + if (abs(arc_residual) .gt. 1.0e-14_rk) call fail(1116) + if (material_fail_count .ne. 0) call fail(1117) + if (linear_matrix_class .lt. 1) call fail(1118) + if (linear_status .lt. 0) call fail(1119) + if (audit_status .ne. NLC_AUDIT_COMMIT_OK) call fail(1120) + if (trim(audit_name) .ne. 'commit-ok') call fail(1121) + if (commit_ok_count .ne. 1) call fail(1122) + if (accept_count .ne. 1) call fail(1123) + if (reject_count .ne. 0) call fail(1124) + if (cutback_count .ne. 0) call fail(1125) + + call fem_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1126) + end subroutine check_api_summary + + subroutine check_lifecycle_report_header(header, code_base) + character(len=*), intent(in) :: header + integer, intent(in) :: code_base + + if (index(header, 'event_id') .le. 0) call fail(code_base) + if (index(header, 'event_name') .le. 0) call fail(code_base + 1) + if (index(header, 'reason_id') .le. 0) call fail(code_base + 2) + if (index(header, 'convergence_status') .le. 0) call fail(code_base + 3) + if (index(header, 'cutback_reason_id') .le. 0) call fail(code_base + 4) + if (index(header, 'residual_total') .le. 0) call fail(code_base + 5) + if (index(header, 'linear_status') .le. 0) call fail(code_base + 6) + if (index(header, 'audit_status') .le. 0) call fail(code_base + 7) + if (index(header, 'accept_count') .le. 0) call fail(code_base + 8) + if (index(header, 'reject_count') .le. 0) call fail(code_base + 9) + end subroutine check_lifecycle_report_header + subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_nonlinear_lifecycle failed:', code diff --git a/tests/module/test_restart.f90 b/tests/module/test_restart.f90 index 4a7d2f8..149e17f 100644 --- a/tests/module/test_restart.f90 +++ b/tests/module/test_restart.f90 @@ -6,7 +6,8 @@ program test_restart fem_get_nl_lifecycle_arc, fem_get_nl_lifecycle_audit use fem_control, only: NFAIL_NONE use fem_nonlinear_lifecycle, only: NLC_EVENT_NONE, NLC_EVENT_ACCEPT, & - NLC_EVENT_COMMIT, NLC_AUDIT_NONE, NLC_AUDIT_COMMIT_OK, & + NLC_EVENT_COMMIT, NLC_AUDIT_NONE, NLC_AUDIT_BEGIN_TRIAL, & + NLC_AUDIT_COMMIT_OK, & nl_lifecycle_reset, & nl_lifecycle_begin_increment, nl_lifecycle_record_event, & nl_lifecycle_record_audit, nl_lifecycle_record_arc_state, & @@ -37,6 +38,8 @@ program test_restart 'build-wsl-debug/lifecycle_restart.frs' character(len=*), parameter :: LEGACY_LIFECYCLE_RESTART_FILE = & 'build-wsl-debug/lifecycle_restart_legacy.frs' + character(len=*), parameter :: EACH_ACCEPT_RESTART_FILE = & + 'build-wsl-debug/restart_after_each_accept.frs' integer :: ierr integer :: ref_step @@ -74,6 +77,8 @@ program test_restart if (ierr .ne. FEM_SUCCESS) call fail(40) call check_lifecycle_restart(ierr) if (ierr .ne. FEM_SUCCESS) call fail(50) + call check_restart_each_accept(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(51) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(12) @@ -217,6 +222,32 @@ contains real(rk) :: fric_step_after real(rk) :: fric_total_after real(rk) :: max_slip_after + integer :: pair_open_before + integer :: pair_stick_before + integer :: pair_slip_before + integer :: pair_restick_before + integer :: pair_separating_before + integer :: pair_failed_before + integer :: pair_flip_before + integer :: pair_open_after + integer :: pair_stick_after + integer :: pair_slip_after + integer :: pair_restick_after + integer :: pair_separating_after + integer :: pair_failed_after + integer :: pair_flip_after + real(rk) :: pair_gap_max_before + real(rk) :: pair_gap_mean_before + real(rk) :: pair_gap_l2_before + real(rk) :: pair_slip_inc_before + real(rk) :: pair_slip_resid_before + real(rk) :: pair_fric_resid_before + real(rk) :: pair_gap_max_after + real(rk) :: pair_gap_mean_after + real(rk) :: pair_gap_l2_after + real(rk) :: pair_slip_inc_after + real(rk) :: pair_slip_resid_after + real(rk) :: pair_fric_resid_after call prepare_contact_model(ierr) if (ierr .ne. FEM_SUCCESS) return @@ -232,6 +263,12 @@ contains call fem_get_contact_friction(fric_step_before, fric_total_before, & max_slip_before, ierr) if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_state_summary(pair_open_before, pair_stick_before, & + pair_slip_before, pair_restick_before, pair_separating_before, & + pair_failed_before, pair_gap_max_before, pair_gap_mean_before, & + pair_gap_l2_before, pair_slip_inc_before, pair_slip_resid_before, & + pair_fric_resid_before, pair_flip_before, ierr) + if (ierr .ne. FEM_SUCCESS) return call fem_get_contact_hist_stats(slots_before, slip_before, & work_before, tangent_before, ierr) if (ierr .ne. FEM_SUCCESS) return @@ -250,6 +287,15 @@ contains if (force_norm_before .le. ZERO) call fail(397) if (max_gap_before .le. ZERO) call fail(398) if (max_slip_before .le. ZERO) call fail(399) + if (pair_stick_before + pair_slip_before + pair_restick_before .le. 0) & + call fail(414) + if (pair_failed_before .ne. 0) call fail(415) + if (pair_gap_max_before .le. ZERO) call fail(416) + if (pair_gap_l2_before .lt. pair_gap_max_before) call fail(417) + if (pair_slip_inc_before .le. ZERO) call fail(418) + if (pair_slip_resid_before .lt. ZERO) call fail(419) + if (pair_fric_resid_before .le. ZERO) call fail(420) + if (pair_flip_before .le. 0) call fail(421) if (hist_slots_before .ne. slots_before) call fail(360) if (stick_before + slip_state_before .ne. hist_slots_before) & call fail(361) @@ -312,6 +358,12 @@ contains call fem_get_contact_friction(fric_step_after, fric_total_after, & max_slip_after, ierr) if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_state_summary(pair_open_after, pair_stick_after, & + pair_slip_after, pair_restick_after, pair_separating_after, & + pair_failed_after, pair_gap_max_after, pair_gap_mean_after, & + pair_gap_l2_after, pair_slip_inc_after, pair_slip_resid_after, & + pair_fric_resid_after, pair_flip_after, ierr) + if (ierr .ne. FEM_SUCCESS) return if (active_summary_after .ne. active_summary_before) call fail(400) if (active_pair_after .ne. active_pair_before) call fail(401) if (activated_pair_after .ne. activated_pair_before) call fail(402) @@ -326,6 +378,19 @@ contains call check_close(fric_step_after, fric_step_before, 411) call check_close(fric_total_after, fric_total_before, 412) call check_close(max_slip_after, max_slip_before, 413) + if (pair_open_after .ne. pair_open_before) call fail(422) + if (pair_stick_after .ne. pair_stick_before) call fail(423) + if (pair_slip_after .ne. pair_slip_before) call fail(424) + if (pair_restick_after .ne. pair_restick_before) call fail(425) + if (pair_separating_after .ne. pair_separating_before) call fail(426) + if (pair_failed_after .ne. pair_failed_before) call fail(427) + call check_close(pair_gap_max_after, pair_gap_max_before, 428) + call check_close(pair_gap_mean_after, pair_gap_mean_before, 429) + call check_close(pair_gap_l2_after, pair_gap_l2_before, 430) + call check_close(pair_slip_inc_after, pair_slip_inc_before, 431) + call check_close(pair_slip_resid_after, pair_slip_resid_before, 432) + call check_close(pair_fric_resid_after, pair_fric_resid_before, 433) + if (pair_flip_after .ne. pair_flip_before) call fail(434) end subroutine check_contact_history_restart subroutine check_mult_restart(ierr) @@ -572,6 +637,150 @@ contains if (audit_after .ne. NLC_AUDIT_NONE) call fail(519) end subroutine check_lifecycle_restart + subroutine check_restart_each_accept(ierr) + integer, intent(out) :: ierr + integer :: accepted + integer :: step_before + integer :: increment_before + integer :: iteration_before + integer :: event_before + integer :: reason_before + integer :: audit_before + integer :: begin_before + integer :: rollback_req_before + integer :: rollback_ok_before + integer :: rollback_fail_before + integer :: commit_before + integer :: step_after + integer :: increment_after + integer :: iteration_after + integer :: event_after + integer :: reason_after + integer :: audit_after + integer :: begin_after + integer :: rollback_req_after + integer :: rollback_ok_after + integer :: rollback_fail_after + integer :: commit_after + integer :: final_step + real(rk) :: load_before + real(rk) :: arc_before + real(rk) :: load_after + real(rk) :: arc_after + real(rk) :: final_time + logical :: path_before + logical :: path_after + + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + + do accepted = 1, 2 + call loaded_step(ierr) + if (ierr .ne. FEM_SUCCESS) return + call mark_restart_audit_accept(accepted) + call capture_lifecycle(step_before, increment_before, & + iteration_before, event_before, reason_before, audit_before, & + begin_before, rollback_req_before, rollback_ok_before, & + rollback_fail_before, commit_before, load_before, arc_before, & + path_before, ierr) + if (ierr .ne. FEM_SUCCESS) return + + call fem_write_restart(EACH_ACCEPT_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) return + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_read_restart(EACH_ACCEPT_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) return + call capture_lifecycle(step_after, increment_after, iteration_after, & + event_after, reason_after, audit_after, begin_after, & + rollback_req_after, rollback_ok_after, rollback_fail_after, & + commit_after, load_after, arc_after, path_after, ierr) + if (ierr .ne. FEM_SUCCESS) return + + call compare_lifecycle_capture(step_before, increment_before, & + iteration_before, event_before, reason_before, audit_before, & + begin_before, rollback_req_before, rollback_ok_before, & + rollback_fail_before, commit_before, load_before, arc_before, & + path_before, step_after, increment_after, iteration_after, & + event_after, reason_after, audit_after, begin_after, & + rollback_req_after, rollback_ok_after, rollback_fail_after, & + commit_after, load_after, arc_after, path_after, 520 + accepted) + end do + + call loaded_step(ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_current_time(final_time, final_step, ierr) + if (ierr .ne. FEM_SUCCESS) return + if (final_step .ne. 3) call fail(529) + ierr = FEM_SUCCESS + end subroutine check_restart_each_accept + + subroutine mark_restart_audit_accept(accepted) + integer, intent(in) :: accepted + + call nl_lifecycle_begin_increment(accepted, accepted) + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + call nl_lifecycle_record_arc_state(ONE, ZERO) + call nl_lifecycle_mark_path_appended(.true.) + call nl_lifecycle_record_event(accepted, accepted, 1, NLC_EVENT_ACCEPT, & + NFAIL_NONE) + end subroutine mark_restart_audit_accept + + subroutine compare_lifecycle_capture(step_before, increment_before, & + iteration_before, event_before, reason_before, audit_before, & + begin_before, rollback_req_before, rollback_ok_before, & + rollback_fail_before, commit_before, load_before, arc_before, & + path_before, step_after, increment_after, iteration_after, event_after, & + reason_after, audit_after, begin_after, rollback_req_after, & + rollback_ok_after, rollback_fail_after, commit_after, load_after, & + arc_after, path_after, code) + integer, intent(in) :: step_before + integer, intent(in) :: increment_before + integer, intent(in) :: iteration_before + integer, intent(in) :: event_before + integer, intent(in) :: reason_before + integer, intent(in) :: audit_before + integer, intent(in) :: begin_before + integer, intent(in) :: rollback_req_before + integer, intent(in) :: rollback_ok_before + integer, intent(in) :: rollback_fail_before + integer, intent(in) :: commit_before + integer, intent(in) :: step_after + integer, intent(in) :: increment_after + integer, intent(in) :: iteration_after + integer, intent(in) :: event_after + integer, intent(in) :: reason_after + integer, intent(in) :: audit_after + integer, intent(in) :: begin_after + integer, intent(in) :: rollback_req_after + integer, intent(in) :: rollback_ok_after + integer, intent(in) :: rollback_fail_after + integer, intent(in) :: commit_after + integer, intent(in) :: code + real(rk), intent(in) :: load_before + real(rk), intent(in) :: arc_before + real(rk), intent(in) :: load_after + real(rk), intent(in) :: arc_after + logical, intent(in) :: path_before + logical, intent(in) :: path_after + + if (step_after .ne. step_before) call fail(code) + if (increment_after .ne. increment_before) call fail(code + 10) + if (iteration_after .ne. iteration_before) call fail(code + 20) + if (event_after .ne. event_before) call fail(code + 30) + if (reason_after .ne. reason_before) call fail(code + 40) + if (audit_after .ne. audit_before) call fail(code + 50) + if (begin_after .ne. begin_before) call fail(code + 60) + if (rollback_req_after .ne. rollback_req_before) call fail(code + 70) + if (rollback_ok_after .ne. rollback_ok_before) call fail(code + 80) + if (rollback_fail_after .ne. rollback_fail_before) call fail(code + 90) + if (commit_after .ne. commit_before) call fail(code + 100) + call check_close(load_after, load_before, code + 110) + call check_close(arc_after, arc_before, code + 120) + if (path_after .neqv. path_before) call fail(code + 130) + end subroutine compare_lifecycle_capture + subroutine write_restart_without_lifecycle(source_file, target_file, ierr) character(len=*), intent(in) :: source_file character(len=*), intent(in) :: target_file diff --git a/tests/module/test_solver_implicit.f90 b/tests/module/test_solver_implicit.f90 index 004450a..fd92886 100644 --- a/tests/module/test_solver_implicit.f90 +++ b/tests/module/test_solver_implicit.f90 @@ -376,6 +376,11 @@ contains if (lifecycle_count_event(NLC_EVENT_ITERATION_RESULT) .le. 0) & call fail(5613) call check_lifecycle_last(NLC_EVENT_ACCEPT, NFAIL_NONE, 5614) + call check_lifecycle_summary(NLC_EVENT_ACCEPT, NFAIL_NONE, 1, 0, 0, & + 5660) + call check_lifecycle_report_row( & + 'build-codex-gcc/test_solver_lifecycle_report_accept', & + 'accept', 'none', 5690) dof = dof_id(1,2) call check_close(u(dof), 15.0_rk / 68.0_rk, 95) @@ -563,10 +568,23 @@ contains call fail(162) if (convergence_failure_reason_id .ne. NFAIL_MIN_STEP) call fail(5164) call check_reason_name(NFAIL_MIN_STEP, 'minimum-step-exhausted', 5165) + call check_cutback_reason_name(CUTBACK_REASON_MIN_STEP, & + 'minimum-step-exhausted', 5680) + if (conv_last_cutback_reason_id .ne. & + CUTBACK_REASON_NONCONVERGENCE) call fail(5681) + call check_cutback_reason_name(conv_last_cutback_reason_id, & + 'nonlinear-nonconvergence', 5682) call check_close(convergence_last_accepted_time, ZERO, 163) if (lifecycle_count_event(NLC_EVENT_CUTBACK) .ne. 2) call fail(5605) + if (lifecycle_count_event_reason(NLC_EVENT_CUTBACK, & + CUTBACK_REASON_NONCONVERGENCE) .ne. 2) call fail(5625) call check_lifecycle_last(NLC_EVENT_REJECT, NFAIL_MIN_STEP, 5606) call check_lifecycle_audit_min(1, 1, 1, 0, 0, 5630) + call check_lifecycle_summary(NLC_EVENT_REJECT, NFAIL_MIN_STEP, 0, 1, & + 2, 5670) + call check_lifecycle_report_row( & + 'build-codex-gcc/test_solver_lifecycle_report_reject', & + 'reject', 'minimum-step-exhausted', 5700) allow_step_cutback = old_cutback max_cutback = old_max_cutback @@ -789,6 +807,14 @@ contains call check_close(nlc_path_real(NLC_PATH_R_PARAMETER, 1), ONE, 278) call check_close(nlc_path_real(NLC_PATH_R_ACTUAL_L2, 1), & 5.0_rk / 6.0_rk, 279) + if (nlc_path_int(NLC_PATH_I_ARC_MODE, 1) .ne. NLC_ARC_MODE_LOAD) & + call fail(5624) + if (nlc_path_int(NLC_PATH_I_ARC_PRED_OK, 1) .ne. 1) & + call fail(5625) + if (nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, 1) .ne. 0) call fail(5626) + if (nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, 1) .ne. 0) call fail(5627) + if (nlc_path_real(NLC_PATH_R_ARC_LENGTH, 1) .le. ZERO) call fail(5628) + call check_close(nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, 1), ZERO, 5629) if (abs(nlc_last_arc_constraint) .gt. 1.0e-8_rk) call fail(280) if (nlc_path_int(NLC_PATH_I_STATUS_CODE, 1) .ne. & CONVERGENCE_STATUS_CONVERGED) call fail(281) @@ -861,6 +887,16 @@ contains if (nlc_path_int(NLC_PATH_I_STEP, 2) .ne. 2) call fail(236) if (nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, 1) .ne. 1) call fail(237) if (nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, 2) .ne. 1) call fail(238) + if (nlc_path_int(NLC_PATH_I_ARC_MODE, 1) .ne. NLC_ARC_MODE_DISP) & + call fail(5631) + if (nlc_path_int(NLC_PATH_I_ARC_MODE, 2) .ne. NLC_ARC_MODE_DISP) & + call fail(5632) + if (nlc_path_int(NLC_PATH_I_ARC_PRED_OK, 2) .ne. 1) & + call fail(5633) + if (nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, 2) .ne. 0) call fail(5634) + if (nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, 2) .ne. 0) call fail(5635) + call check_close(nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, 2), 0.5_rk, & + 5636) call check_close(nlc_path_real(NLC_PATH_R_TIME, 1), 0.5_rk, 239) call check_close(nlc_path_real(NLC_PATH_R_TIME, 2), ONE, 240) call check_close(nlc_path_real(NLC_PATH_R_TARGET_DT, 1), 0.5_rk, 249) @@ -1356,6 +1392,16 @@ contains if (trim(actual) .ne. trim(expected)) call fail(code) end subroutine check_reason_name + subroutine check_cutback_reason_name(reason_id, expected, code) + integer, intent(in) :: reason_id + character(len=*), intent(in) :: expected + integer, intent(in) :: code + character(len=64) :: actual + + call cutback_reason_name(reason_id, actual) + if (trim(actual) .ne. trim(expected)) call fail(code) + end subroutine check_cutback_reason_name + subroutine check_lifecycle_event(index, expected_event, expected_reason, & code) integer, intent(in) :: index @@ -1432,6 +1478,53 @@ contains if (commit_ok_count .lt. min_commit_ok) call fail(code + 4) end subroutine check_lifecycle_audit_min + subroutine check_lifecycle_summary(expected_event, expected_reason, & + min_accept, min_reject, min_cutback, & + code) + integer, intent(in) :: expected_event + integer, intent(in) :: expected_reason + integer, intent(in) :: min_accept + integer, intent(in) :: min_reject + integer, intent(in) :: min_cutback + integer, intent(in) :: code + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + integer :: accept_count + integer :: reject_count + integer :: cutback_count + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + + call nl_lifecycle_get_summary(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, accept_count, reject_count, & + cutback_count) + if (event_id .ne. expected_event) call fail(code) + if (reason_id .ne. expected_reason) call fail(code + 1) + if (trim(event_name) .eq. 'unknown') call fail(code + 2) + if (trim(reason_name) .eq. 'unknown') call fail(code + 3) + if (accept_count .lt. min_accept) call fail(code + 4) + if (reject_count .lt. min_reject) call fail(code + 5) + if (cutback_count .lt. min_cutback) call fail(code + 6) + if (audit_status .lt. NLC_AUDIT_NONE) call fail(code + 7) + if (begin_trial_count .lt. 0) call fail(code + 8) + if (rollback_requested_count .lt. 0) call fail(code + 9) + if (rollback_ok_count .lt. 0) call fail(code + 10) + if (rollback_failed_count .lt. 0) call fail(code + 11) + if (commit_ok_count .lt. 0) call fail(code + 12) + end subroutine check_lifecycle_summary + integer function lifecycle_count_event(expected_event) integer, intent(in) :: expected_event integer :: i @@ -1453,6 +1546,30 @@ contains end do end function lifecycle_count_event + integer function lifecycle_count_event_reason(expected_event, & + expected_reason) + integer, intent(in) :: expected_event + integer, intent(in) :: expected_reason + integer :: i + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + lifecycle_count_event_reason = 0 + do i = 1, nl_lifecycle_get_event_count() + call nl_lifecycle_get_event(i, step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + if (event_id .eq. expected_event .and. & + reason_id .eq. expected_reason) then + lifecycle_count_event_reason = lifecycle_count_event_reason + 1 + end if + end do + end function lifecycle_count_event_reason + subroutine check_path_breakdown_header(code_base) integer, intent(in) :: code_base character(len=2048) :: header @@ -1500,9 +1617,64 @@ contains call fail(code_base + 17) if (index(header, 'lifecycle_reject_count') .le. 0) & call fail(code_base + 18) - if (index(row_line, ',accept,') .le. 0) call fail(code_base + 19) + if (index(header, 'arc_mode,arc_predictor_consistent') .le. 0) & + call fail(code_base + 19) + if (index(header, 'arc_load_reversal,arc_turning_point') .le. 0) & + call fail(code_base + 20) + if (index(header, 'arc_length,arc_load_delta,arc_predictor_dot') .le. 0) & + call fail(code_base + 21) + if (index(row_line, ',accept,') .le. 0) call fail(code_base + 22) end subroutine check_path_breakdown_header + subroutine check_lifecycle_report_row(output_dir, expected_event, & + expected_reason, code_base) + character(len=*), intent(in) :: output_dir + character(len=*), intent(in) :: expected_event + character(len=*), intent(in) :: expected_reason + integer, intent(in) :: code_base + character(len=2048) :: header + character(len=2048) :: row_line + character(len=512) :: filename + integer :: ierr + integer :: ios + integer :: unit_id + + call output_csv_set_directory(output_dir, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code_base) + call output_csv_write_nl_lifecycle(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code_base + 1) + + filename = trim(output_dir)//'/nonlinear_lifecycle.csv' + unit_id = 95 + open(unit=unit_id, file=trim(filename), status='old', action='read', & + iostat=ios) + if (ios .ne. 0) call fail(code_base + 2) + read(unit_id,'(A)',iostat=ios) header + if (ios .ne. 0) call fail(code_base + 3) + read(unit_id,'(A)',iostat=ios) row_line + close(unit_id) + if (ios .ne. 0) call fail(code_base + 4) + if (index(header, 'convergence_status') .le. 0) call fail(code_base + 5) + if (index(header, 'cutback_reason_id') .le. 0) call fail(code_base + 6) + if (index(header, 'residual_total') .le. 0) call fail(code_base + 7) + if (index(header, 'linear_status') .le. 0) call fail(code_base + 8) + if (index(header, 'audit_status') .le. 0) call fail(code_base + 9) + if (index(header, 'linear_method,linear_precond') .le. 0) & + call fail(code_base + 12) + if (index(header, 'linear_iterations') .le. 0) call fail(code_base + 13) + if (index(header, 'linear_initial_residual') .le. 0) & + call fail(code_base + 14) + if (index(header, 'linear_final_residual') .le. 0) & + call fail(code_base + 15) + if (index(header, 'linear_relative_residual') .le. 0) & + call fail(code_base + 16) + if (index(header, 'linear_fail_class') .le. 0) call fail(code_base + 17) + if (index(row_line, ','//trim(expected_event)//',') .le. 0) & + call fail(code_base + 10) + if (index(row_line, ','//trim(expected_reason)//',') .le. 0) & + call fail(code_base + 11) + end subroutine check_lifecycle_report_row + subroutine check_solver_diag(code_base) integer, intent(in) :: code_base integer :: ierr diff --git a/tests/performance/perf_p1.f90 b/tests/performance/perf_p1.f90 index 82a4c9e..5ac43ae 100644 --- a/tests/performance/perf_p1.f90 +++ b/tests/performance/perf_p1.f90 @@ -40,7 +40,7 @@ program perf_p1 call fem_get_version(major, minor, patch, ierr) call exit_if_error(ierr) - if (major .ne. 0 .or. minor .ne. 6 .or. patch .ne. 0) then + if (major .ne. 0 .or. minor .ne. 6 .or. patch .ne. 1) then write(*,'(A,I1,A,I1,A,I1)') 'unexpected FemLite version ', major, '.', minor, '.', patch call exit(3) end if diff --git a/tests/unit/test_smoke.f90 b/tests/unit/test_smoke.f90 index 562b149..01011bf 100644 --- a/tests/unit/test_smoke.f90 +++ b/tests/unit/test_smoke.f90 @@ -94,7 +94,7 @@ program test_smoke if (ierr .ne. 0) stop 2 if (major .ne. 0) stop 3 if (minor .ne. 6) stop 4 - if (patch .ne. 0) stop 5 + if (patch .ne. 1) stop 5 call fem_read_inp('examples/c3d4_one_element.inp', ierr) if (ierr .ne. 0) stop 11 diff --git a/todo.md b/todo.md index b39a968..ddc0677 100644 --- a/todo.md +++ b/todo.md @@ -1,344 +1,401 @@ -# FemLite 0.6.0 TODO +# FemLite 0.6.1 TODO -Source plan: `docs/v6.0_development_plan.md` +Source plan: `docs/v6.1_development_plan.md` Version goal: ```text -FemLite 0.6.0 = unified nonlinear state machine and lifecycle foundation +FemLite 0.6.1 = nonlinear/contact lifecycle diagnostics hardening ``` Boundary: -- The fifth-version closure boundary is lifted for future planning, but 0.6.0 - should still remain a controlled loop. +- 0.6.1 deepens the 0.6.0 lifecycle foundation; it is not a broad algorithm + rewrite release. - Do not implement a complete industrial AL/mortar consistent tangent rewrite in this task list. - Do not move mixed-control continuation, shell preload `K_G`, high-order solid `K_G`, cohesive contact mainline, nonzero harmonic cyclic, DEM subcycling or - production roll forming into the 0.6.0 must-complete list. -- Every new lifecycle or audit field must be consumed by a test, checker or - report audit. + production roll forming into the 0.6.1 must-complete list. +- Every new reason, status, counter or output field must be consumed by a + regression test, checker or report audit. - Keep TODO item size uniform: each task should add one observable contract and one focused verification path. ## Execution Order -1. NLCS-1: lifecycle ids, names and snapshot skeleton. -2. NLCS-2: static nonlinear lifecycle hook. -3. NLCS-3: nonlinear Newmark lifecycle hook. -4. NLCS-4: Riks/arc lifecycle hook. -5. NLCS-5: rollback audit core. -6. NLCS-6: material rollback audit adapter. -7. NLCS-7: contact rollback audit adapter. -8. NLCS-8: cohesive and particle audit adapters. -9. NLCS-9: lifecycle output/report schema. -10. NLCS-10: restart lifecycle audit. -11. DOC-1: documentation and interface synchronization. -12. REL-1: 0.6.0 regression/version close-out. +1. NLHD-1: lifecycle increment summary. +2. NLHD-2: cutback reason taxonomy. +3. NLHD-3: lifecycle report output. +4. NLHD-4: contact state diagnostics. +5. NLHD-5: contact long-path diagnostic smoke. +6. NLHD-6: AL/friction diagnostics. +7. NLHD-7: tangent-audit report shell. +8. NLHD-8: Riks/arc diagnostics. +9. NLHD-9: restart-after-each-accepted audit. +10. NLHD-10: solver diagnostics coupling. +11. DOC-1: documentation and matrix synchronization. +12. REL-1: 0.6.1 regression/version close-out. ## Detailed Execution Map | TODO | Code targets | Output/API contract | Test/checker target | Not in scope | |---|---|---|---|---| -| 0.6.0-1 | `src/solver/fem_nonlinear_lifecycle.f90`, diagnostics API | Stable lifecycle event ids/names and queryable empty snapshot | new lifecycle unit/module test | Change Newton algorithms | -| 0.6.0-2 | static nonlinear solver loop | Record increment/iteration begin/end and accept/reject events | `solver_implicit` | Change convergence rules | -| 0.6.0-3 | nonlinear Newmark solver loop | Record dynamic nonlinear lifecycle events | `solver_implicit` | Rewrite Newmark integration | -| 0.6.0-4 | Riks/arc static path | Record load factor, arc residual and path append lifecycle fields | `solver_implicit`, `implicit_inp` | Mixed-control continuation | -| 0.6.0-5 | lifecycle audit module | Generic commit/rollback audit counters and status | lifecycle audit unit/module test | Owner-specific checksum details | -| 0.6.0-6 | material/element state path | Material local state rollback audit for covered subset | `solver_implicit`, material tests | New material models | -| 0.6.0-7 | contact state/history path | Contact state and diagnostic rollback audit for covered subset | `restart`, contact report tests | Full contact state-machine rewrite | -| 0.6.0-8 | cohesive and particle compact paths | Cohesive/particle owner audit hooks using existing compact tests | `cohesive_contact`, `particle_acceptance` | Cohesive mainline or DEM subcycling | -| 0.6.0-9 | output/report modules | Lifecycle event/report columns or compact lifecycle CSV | `solver_implicit`, output checker | Break existing CSV consumers | -| 0.6.0-10 | restart writer/reader and restart tests | Accepted-increment lifecycle diagnostics round trip | `restart` | Redesign restart format | -| 0.6.0-11 | docs and manuals | Document lifecycle API, output and deferred boundaries | wording `rg` checks | Expand feature scope | -| 0.6.0-12 | version/matrix/report files | Close 0.6.0 after green targeted and V5 acceptance tests | build, targeted tests, acceptance, `git diff --check` | Version bump before tests pass | +| 0.6.1-1 | lifecycle module and diagnostics API | Increment summary fields for lifecycle, convergence, residual, solver and audit state | `nonlinear_lifecycle`, `solver_implicit` | Change Newton algorithms | +| 0.6.1-2 | control/reason taxonomy | Stable cutback reason ids/names and last cutback reason query | `solver_implicit`, lifecycle test | New nonlinear strategy | +| 0.6.1-3 | output/report module | Compact lifecycle report or appended nonlinear report fields | output checker | Break old CSV columns | +| 0.6.1-4 | contact state/report modules | Stable contact state counters and gap/slip/friction fields | `contact`, contact reports | Full contact state-machine rewrite | +| 0.6.1-5 | contact benchmark checkers | Long-path diagnostic smoke for existing compact contact examples | contact benchmark checkers | New contact benchmark physics | +| 0.6.1-6 | multiplier/friction diagnostics | AL multiplier, augmentation and friction trend summaries | `contact_multiplier_report`, `restart` | Complete AL tangent | +| 0.6.1-7 | tangent audit reporting | Shared audit schema and coverage counters | tangent audit tests | Claim production consistent tangents | +| 0.6.1-8 | Riks/arc path diagnostics | Arc residual history, predictor and reversal indicators | `solver_implicit`, `implicit_inp` | Mixed-control continuation | +| 0.6.1-9 | restart writer/reader tests | Multi-increment restart lifecycle audit | `restart` | Large restart benchmark | +| 0.6.1-10 | linear solver diagnostics | Solver status fields linked into lifecycle/nonlinear rows | `linear_solver_cg`, `solver_implicit` | New solver backend | +| 0.6.1-11 | docs and matrices | Updated interface/user/developer docs and benchmark matrix | wording `rg` checks | Expand feature scope | +| 0.6.1-12 | version/report files | Close 0.6.1 after green targeted and V5 acceptance tests | build, targeted tests, acceptance, `git diff --check` | Version bump before tests pass | ## Implementation Rules - Work in the execution order above. -- Do not mark a TODO done until its lifecycle field or audit status is consumed - by a test, checker or report audit. -- Prefer additive lifecycle hooks over solver-loop rewrites. -- Keep existing public signatures stable unless a thin new accessor is clearly - safer. -- If a task exposes incompatible designs for lifecycle ownership, pause and ask - for a decision before editing that route. +- Do not mark a TODO done until its new field, reason or status is consumed by + a test, checker or report audit. +- Prefer additive diagnostics over solver-loop rewrites. +- Keep old CSV columns stable; append new fields. +- Keep restart readers backward compatible; optional diagnostic blocks are + preferred over format breaks. +- If a task exposes incompatible designs for contact, Riks, material or restart + ownership, pause and ask for a decision before editing that route. - If a later task needs a field created by an earlier task, finish and test the earlier task first. -## 0.6.0 Task List +## 0.6.1 Task List -### [x] TODO 0.6.0-1: Add nonlinear lifecycle ids and snapshot skeleton +### [x] TODO 0.6.1-1: Add lifecycle increment summary - Source: - - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-1. + - `docs/v6.1_development_plan.md` sections 4.1 and 5, NLHD-1. - Implementation: - - [x] Add stable lifecycle event ids and names for increment begin, trial - begin, iteration result, accept, reject, cutback, commit and rollback. - - [x] Add a small lifecycle snapshot with step/increment/iteration/event - fields and last reason id/name linkage. - - [x] Add a reset/begin/query API that returns a valid empty snapshot before - any nonlinear solve. - - [x] Keep the module passive; it must not change solver behavior yet. + - [x] Add a compact lifecycle increment summary structure or query path. + - [x] Include step, increment, final event id/name and reason id/name. + - [x] Include convergence status, residual breakdown, linear solver status + and audit status fields already available in 0.6.0. + - [x] Keep existing lifecycle snapshot APIs compatible. - Tests: - - [x] Add a lifecycle unit/module test for id/name stability and empty - snapshot defaults. + - [x] Extend `nonlinear_lifecycle` to verify empty and populated summary + fields. + - [x] Extend `solver_implicit` to consume the summary after one accepted and + one rejected/cutback path. - Acceptance: - - [x] Tests can query lifecycle state without running a solve, and all event - names are stable. + - [x] A test can explain the latest nonlinear increment from one summary + query without reading console output. Verified: -- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|linear_solver_cg|c_api)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure +``` -### [x] TODO 0.6.0-2: Hook static nonlinear lifecycle events +### [x] TODO 0.6.1-2: Add cutback reason taxonomy - Source: - - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-2. + - `docs/v6.1_development_plan.md` sections 4.2 and 5, NLHD-2. - Implementation: - - [x] Record increment begin and iteration begin in the nonlinear static path. - - [x] Record iteration result with convergence status and current failure - reason fields. - - [x] Record accepted, rejected or cutback increment events without changing - the existing cutback decision. - - [x] Preserve existing convergence metrics and continuation path behavior. + - [x] Add stable cutback reason ids/names for common nonlinear failure modes. + - [x] Track the last cutback reason separately from the final convergence + failure reason. + - [x] Map existing min-step, nonconvergence and linear-solver failure paths + into the new taxonomy. + - [x] Leave unavailable reasons as reserved/documented ids until a real path + consumes them. - Tests: - - [x] Extend `solver_implicit` to verify lifecycle event sequence for a - converged static nonlinear path and one rejected/cutback path. + - [x] Extend `nonlinear_lifecycle` to verify reason-name stability. + - [x] Extend `solver_implicit` to verify at least min-step and + nonconvergence cutback reasons. - Acceptance: - - [x] Static nonlinear diagnostics expose lifecycle events that match the - existing solver outcome. + - [x] Every implemented 0.6.1 cutback reason is consumed by a regression + assertion. Verified: -- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure +``` -### [x] TODO 0.6.0-3: Hook nonlinear Newmark lifecycle events +### [x] TODO 0.6.1-3: Write lifecycle report output - Source: - - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-3. + - `docs/v6.1_development_plan.md` sections 4.3 and 5, NLHD-3. - Implementation: - - [x] Record Newmark nonlinear increment and iteration lifecycle events. - - [x] Link dynamic residual status to the shared lifecycle snapshot. - - [x] Record accepted/rejected dynamic increments where the current path can - identify them. - - [x] Preserve current Newmark time integration and convergence behavior. + - [x] Add `nonlinear_lifecycle.csv` or append equivalent lifecycle summary + fields to an existing nonlinear report. + - [x] Cover initialized/no-solve, accepted increment and rejected/cutback + increment rows. + - [x] Include lifecycle summary, cutback reason, residual breakdown, solver + status and audit status columns. + - [x] Preserve old `continuation_path.csv` column order if that file is + extended again. - Tests: - - [x] Extend `solver_implicit` to verify lifecycle fields after a nonlinear - Newmark run. + - [x] Add or extend an output checker to validate required lifecycle report + headers. + - [x] Verify at least one accepted row and one rejected/cutback row. - Acceptance: - - [x] Static and Newmark nonlinear paths expose the same lifecycle field - contract for the covered subset. + - [x] Missing lifecycle report fields cause a regression failure. Verified: -- `ctest --test-dir build-codex-gcc -R "^(solver_implicit|nonlinear_lifecycle|c_api)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure +``` -### [x] TODO 0.6.0-4: Hook Riks/arc lifecycle events +### [x] TODO 0.6.1-4: Stabilize contact state diagnostics - Source: - - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-4. + - `docs/v6.1_development_plan.md` sections 4.4 and 5, NLHD-4. - Implementation: - - [x] Record Riks/arc lifecycle events in the load-type arc path. - - [x] Store current load factor, arc residual and arc reason in the lifecycle - snapshot. - - [x] Record whether a path row is appended because the increment was - accepted. - - [x] Preserve current Riks/arc equations and direct displacement-control - behavior. + - [x] Define stable contact state names: `open`, `closed-stick`, + `closed-slip`, `closed-restick`, `separating` and `failed-projection`. + - [x] Report state counters through existing contact diagnostics or a compact + helper. + - [x] Include gap maximum/mean/L2, slip increment/residual, friction residual + and active-set flip count where available. + - [x] Keep this diagnostic-only; do not rewrite contact solve state + ownership. - Tests: - - [x] Extend `solver_implicit` or `implicit_inp` to verify arc lifecycle - fields on an accepted Riks path. + - [x] Extend `contact` or contact report tests to verify state names and + counters. + - [x] Verify unsupported/unavailable state fields default consistently. - Acceptance: - - [x] Riks/arc diagnostics can be interpreted through the same lifecycle - event model as static nonlinear diagnostics. + - [x] Contact diagnostics can distinguish open, stick/slip and failed + projection states without parsing logs. Verified: -- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|c_api)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^contact$" --output-on-failure +``` -### [x] TODO 0.6.0-5: Add generic rollback audit core +### [x] TODO 0.6.1-5: Add compact contact long-path diagnostic smoke - Source: - - `docs/v6.0_development_plan.md` sections 4.2 and 5, NLCS-5. + - `docs/v6.1_development_plan.md` sections 4.5 and 5, NLHD-5. - Implementation: - - [x] Add generic audit counters for begin-trial, rollback-requested, - rollback-ok, rollback-failed and commit-ok. - - [x] Add an audit status/name field to the lifecycle snapshot. - - [x] Add helpers that owner modules can call without depending on each other. - - [x] Keep owner-specific checksum logic out of the generic core. + - [x] Select existing compact examples for two-block compression, block + sliding, shell-shell contact and shell-solid contact. + - [x] Add checker expectations for required diagnostic columns and finite + state counters. + - [x] Check gap/slip/friction/multiplier diagnostics across path steps. + - [x] Keep benchmark physics and tolerances bounded to existing examples. - Tests: - - [x] Add lifecycle audit coverage for counter transitions and failure naming. + - [x] Extend existing contact benchmark checkers or their CTest assertions. + - [x] Verify at least two path steps for one compact long-path case. - Acceptance: - - [x] A test can simulate owner audit success/failure and observe the shared - audit status. + - [x] A compact contact path can fail diagnostics loudly if state or residual + fields disappear. Verified: -- `ctest --test-dir build-codex-gcc -R "^nonlinear_lifecycle$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^contact$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^example_(contact_two_blocks_compression|contact_block_sliding|shell_shell_contact|shell_solid_contact)_benchmark$" --output-on-failure +``` -### [x] TODO 0.6.0-6: Add material rollback audit adapter +### [x] TODO 0.6.1-6: Add AL multiplier and friction diagnostic summaries - Source: - - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-6. + - `docs/v6.1_development_plan.md` sections 4.6 and 5, NLHD-6. - Implementation: - - [x] Add a covered-subset material state checksum or equivalent audit value - before trial updates. - - [x] Compare material state after rollback for a rejected nonlinear - increment. - - [x] Feed material rollback status into the lifecycle audit core. - - [x] Keep material constitutive algorithms unchanged. + - [x] Add multiplier residual trend and maximum augmented multiplier summary + fields. + - [x] Add augmentation update count and accepted-step penalty/augmentation + factor fields. + - [x] Add slip/friction residual summary fields where existing friction state + supports them. + - [x] Include restart before/after consistency checks for supported fields. - Tests: - - [x] Extend `solver_implicit` or material tests with one rejected/cutback - material-state rollback audit. + - [x] Extend `contact_multiplier_report` to consume new summary fields. + - [x] Extend `restart` or `contact` to compare supported multiplier/friction + summaries before and after restart. - Acceptance: - - [x] Rejected material trial updates are proven not to contaminate committed - state for the covered subset. + - [x] AL/friction diagnostic summaries are visible in tests and survive the + covered restart path. Verified: -- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(contact_multiplier_report|restart)$" --output-on-failure +``` -### [x] TODO 0.6.0-7: Add contact rollback audit adapter +### [x] TODO 0.6.1-7: Add shared tangent-audit report shell - Source: - - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-7. + - `docs/v6.1_development_plan.md` sections 4.7 and 5, NLHD-7. - Implementation: - - [x] Capture contact state counts and selected contact diagnostics before - trial changes. - - [x] Compare contact state after rollback for a rejected/cutback increment. - - [x] Feed contact rollback status into the lifecycle audit core. - - [x] Reuse existing 0.5.3 contact diagnostics rather than adding broad new - contact fields. + - [x] Define a shared tangent-audit report schema with audit name, branch, + sample count, relative error and status fields. + - [x] Route existing material/contact/shell/Riks audit summaries into the + shared vocabulary where already available. + - [x] Add coverage counters for missing or not-applicable audit branches. + - [x] Document that this is an audit report shell, not production consistent + tangent delivery. - Tests: - - [x] Extend `restart` or contact report tests with a contact rollback audit - scenario. + - [x] Extend existing tangent audit tests or add a schema checker. + - [x] Verify at least normal contact and one non-contact audit category in + the shared report vocabulary. - Acceptance: - - [x] Contact diagnostics and state counts remain consistent after rollback - for the covered subset. + - [x] Tangent audit output has a uniform schema without changing production + tangent behavior. Verified: -- `ctest --test-dir build-codex-gcc -R "^(contact|contact_multiplier_diag)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^contact_mortar_tangent$" --output-on-failure +``` -### [x] TODO 0.6.0-8: Add cohesive and particle audit adapters +### [x] TODO 0.6.1-8: Harden Riks and arc diagnostics - Source: - - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-8. + - `docs/v6.1_development_plan.md` sections 4.8 and 5, NLHD-8. - Implementation: - - [x] Add cohesive compact-path audit hooks for damage/status/energy rollback - where existing state support allows it. - - [x] Add particle compact-path audit hooks for mass/momentum/energy counters. - - [x] Feed both owner statuses into the lifecycle audit core. - - [x] Keep cohesive mainline contact and DEM subcycling out of this task. + - [x] Record arc residual history for accepted Riks/arc increments. + - [x] Add predictor direction consistency and load-factor reversal indicators. + - [x] Add a simple turning-point indicator where current path data supports + it. + - [x] Add path/report fields that distinguish load-control Riks from direct + displacement control. - Tests: - - [x] Extend `cohesive_contact` and `particle_acceptance` to consume the new - audit statuses. + - [x] Extend `solver_implicit` to verify Riks/arc diagnostic fields. + - [x] Extend `implicit_inp` only if an existing deterministic input path can + consume the fields cheaply. - Acceptance: - - [x] Existing compact cohesive and particle tests can report lifecycle audit - status without changing their physics paths. + - [x] Riks/arc diagnostics expose residual and predictor/path direction state + without implementing mixed-control continuation. Verified: -- `ctest --test-dir build-codex-gcc -R "^(cohesive_contact|particle_step|nonlinear_lifecycle)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp)$" --output-on-failure +``` -### [x] TODO 0.6.0-9: Write lifecycle diagnostics to output/report path +### [x] TODO 0.6.1-9: Add restart-after-each-accepted audit - Source: - - `docs/v6.0_development_plan.md` sections 4.4 and 5, NLCS-9. + - `docs/v6.1_development_plan.md` sections 4.9 and 5, NLHD-9. - Implementation: - - [x] Add lifecycle event/status fields to an existing nonlinear report path - or a compact `nonlinear_lifecycle.csv`. - - [x] Include event id/name, audit status/name, increment, iteration, reason - id/name and accepted/rejected counters. - - [x] Keep old continuation/contact CSV columns stable. - - [x] Represent missing lifecycle data consistently for unsupported paths. -- Tests: - - [x] Extend `solver_implicit` or an output checker to verify lifecycle output - headers and at least one accepted row. -- Acceptance: - - [x] Checker failure occurs if required 0.6.0 lifecycle output fields are - missing. - -Verified: - -- `ctest --test-dir build-codex-gcc -R "^(solver_implicit|nonlinear_lifecycle)$" --output-on-failure` - -### [x] TODO 0.6.0-10: Add restart lifecycle audit - -- Source: - - `docs/v6.0_development_plan.md` sections 4.4 and 6, NLCS-10. -- Implementation: - - [x] Persist accepted-increment lifecycle diagnostics needed for restart - audit where restart format already supports the owned state. - - [x] Read old restart files without requiring lifecycle fields. - - [x] Compare lifecycle event/status and owner audit summaries before and + - [x] Add a compact multi-increment restart audit flow. + - [x] After each accepted increment, write restart, read into a fresh model + and compare lifecycle diagnostics. + - [x] Compare supported contact/material/path diagnostic summaries before and after restart. - - [x] Avoid redesigning the restart format beyond an optional lifecycle block. + - [x] Continue one increment after restart to prove the restored state is + usable. - Tests: - - [x] Extend `restart` to verify lifecycle diagnostics survive an accepted - increment restart round trip. + - [x] Extend `restart` or add a compact restart-lifecycle test. + - [x] Keep the model small and deterministic. - Acceptance: - - [x] Restart proves both owned state and lifecycle diagnostics for the - covered subset. + - [x] Restart audit covers more than one accepted increment without relying + on a large benchmark. Verified: -- `ctest --test-dir build-codex-gcc -R "^(restart|nonlinear_lifecycle)$" --output-on-failure` +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^restart$" --output-on-failure +``` -### [x] TODO 0.6.0-11: Synchronize documentation and API descriptions +### [x] TODO 0.6.1-10: Couple solver diagnostics to nonlinear rows - Source: - - `docs/v6.0_development_plan.md` sections 2, 4 and 6, DOC-1. + - `docs/v6.1_development_plan.md` sections 4.10 and 5, NLHD-10. - Implementation: - - [x] Update design and algorithm docs with lifecycle levels and event names. - - [x] Update interface docs with new lifecycle query/output fields. - - [x] Update test plan with 0.6.0 regression commands and acceptance criteria. - - [x] Update user/developer manuals with lifecycle boundary and deferred - algorithm rewrites. + - [x] Link matrix class, solver method, preconditioner, iteration count and + solver status into lifecycle or nonlinear report rows. + - [x] Include initial/final/relative residual where current solver diagnostics + already provide them. + - [x] Add a fallback marker for dense pivoting or method fallback paths if + available. + - [x] Keep solver selection behavior unchanged. - Tests: - - [x] Run wording `rg` checks so docs do not claim 0.6.0 delivers complete + - [x] Extend `linear_solver_cg` for field availability and naming where + needed. + - [x] Extend `solver_implicit` to verify nonlinear rows include solver + diagnostics. +- Acceptance: + - [x] A nonlinear failure can be distinguished from a linear solver failure + through report/API fields. + +Verified: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(solver_implicit|linear_solver_cg)$" --output-on-failure +``` + +### [x] TODO 0.6.1-11: Synchronize documentation and benchmark matrix + +- Source: + - `docs/v6.1_development_plan.md` sections 4.11 and 5, DOC-1. +- Implementation: + - [x] Update `docs/v6_benchmark_matrix.md` with 0.6.1 diagnostic tests and + evidence placeholders. + - [x] Update interface docs with new lifecycle, cutback, contact and solver + diagnostic fields. + - [x] Update user/developer manuals with the 0.6.1 boundary and deferred + algorithm rewrites. + - [x] Add or update a 0.6.1 acceptance report section. +- Tests: + - [x] Run wording `rg` checks so docs do not claim 0.6.1 delivers complete AL/mortar tangent, mixed-control continuation or cohesive mainline. - Acceptance: - - [x] Documentation states that 0.6.0 delivers lifecycle foundation and - rollback audit, while larger solver rewrites remain follow-up work. + - [x] Documentation states that 0.6.1 delivers diagnostic hardening, while + larger solver rewrites remain follow-up work. Verified: -- `rg -n "0\\.6\\.0.*(complete industrial AL/mortar|mixed-control continuation|cohesive contact mainline|cohesive mainline|complete AL/mortar|generalized mixed-control)" docs README.md todo.md` -- `rg -n "LIFECYCLE_DIAGNOSTICS|lifecycle_event_id|fem_get_nl_lifecycle|0\\.6\\.0 Lifecycle" docs` +```powershell +rg -n "0\.6\.1.*(complete|完整|industrial|生产一致切线|mixed-control continuation|AL/mortar consistent tangent).*交付|0\.6\.1.*delivers complete|0\.6\.1.*完整 AL|0\.6\.1.*mixed-control" docs +rg -n "0\.6\.1|nonlinear_lifecycle.csv|arc_mode|fem_tangent_audit_report|closed-stick|linear_fail_class" docs/v6_benchmark_matrix.md docs/v6_acceptance_report.md docs/07_user_manual.md docs/08_developer_manual.md +``` -### [x] TODO 0.6.0-12: Update version, matrix, report and release evidence +### [x] TODO 0.6.1-12: Update version, report and release evidence - Source: - - `docs/v6.0_development_plan.md` section 6, REL-1. + - `docs/v6.1_development_plan.md` section 6, REL-1. - Implementation: - - [x] Update benchmark/acceptance matrix with 0.6.0 lifecycle tests and - diagnostic evidence. - - [x] Update acceptance report with 0.6.0 scope, commands and limitations. - - [x] Raise project version only when 0.6.0 implementation is ready to close. + - [x] Update benchmark/acceptance matrix with final 0.6.1 test evidence. + - [x] Update acceptance report with 0.6.1 scope, commands and limitations. + - [x] Raise project version only when 0.6.1 implementation is ready to close. - [x] Keep deferred boundaries explicit in release documentation. - Tests: - - [x] Run the planned 0.6.0 targeted regression command. + - [x] Run the planned 0.6.1 targeted regression command. - [x] Run `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure`. - [x] Run `git diff --check`. - Acceptance: - - [x] 0.6.0 closes with green targeted tests, green acceptance subset and + - [x] 0.6.1 closes with green targeted tests, green acceptance subset and documented deferred boundaries. Verified: -- `cmake --build build-codex-gcc --parallel` -- `ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp|restart|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance)$" --output-on-failure` -- `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` -- `git diff --check` - -## Suggested 0.6.0 Regression Commands - ```powershell cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp|restart|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(smoke|perf_contact_pair_p1)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +## Suggested 0.6.1 Regression Commands + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure git diff --check ```