diff --git a/CMakeLists.txt b/CMakeLists.txt index fd01145..9b6be95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(FemLite - VERSION 0.5.3 + VERSION 0.6.0 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/solver/fem_nonlinear_lifecycle.f90 src/element/fem_element_topology.f90 src/element/fem_geometric_stiffness.f90 src/mesh/fem_database_state.f90 @@ -380,6 +381,13 @@ add_executable(test_linear_solver_cg target_link_libraries(test_linear_solver_cg PRIVATE femlite_core) femlite_apply_fortran_options(test_linear_solver_cg) +add_executable(test_nonlinear_lifecycle + tests/module/test_nonlinear_lifecycle.f90 +) + +target_link_libraries(test_nonlinear_lifecycle PRIVATE femlite_core) +femlite_apply_fortran_options(test_nonlinear_lifecycle) + add_executable(test_eigensolver tests/module/test_eigensolver.f90 ) @@ -761,6 +769,11 @@ set_tests_properties(linear_solver_cg PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) +add_test(NAME nonlinear_lifecycle COMMAND test_nonlinear_lifecycle) +set_tests_properties(nonlinear_lifecycle PROPERTIES + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +) + add_test(NAME eigensolver COMMAND test_eigensolver) set_tests_properties(eigensolver PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" diff --git a/README.md b/README.md index 77608bc..e3f0e44 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FemLite 是一个以 Fortran 95 为核心实现的轻量级有限元求解器,面向结构动力学、静力学、壳/实体单元、接触、材料非线性和外部耦合接口的工程验证与算法开发。 -当前项目版本为 **0.5.3**。`v0.5.0` 已作为第五版阶段验收发布标签推送;第四版 `0.4.8` 已完成阶段验收并作为稳定基线;第五版 `0.5.x` 继续推进 mortar/AL 接触诊断、无第三方依赖的内部稀疏求解器强化、Mohr-Coulomb、线性屈曲、循环对称、滚压成形、粘附/脱粘和颗粒耦合等后续能力;完整工业级 mortar/AL 一致切线重写不作为 0.5.3 阻塞项。 +当前项目版本为 **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 和生产级滚压流程仍作为后续版本工作。 ## 当前基线 @@ -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。当前 V5 发布计划收口到 V5.11 finite-strain S4 有界能力检查点;球冠完整 PDF 全曲线复现和 V5.12 工程增强留到后续版本。当前 Windows GCC 16 Release 全量 CTest 记录为 `106/106 passed`。详细计划和剩余项见 [docs/v5_development_plan.md](docs/v5_development_plan.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.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)。 ## 快速构建 diff --git a/docs/02_software_architecture_design.md b/docs/02_software_architecture_design.md index 6ae2193..8c900cd 100644 --- a/docs/02_software_architecture_design.md +++ b/docs/02_software_architecture_design.md @@ -526,3 +526,34 @@ V5.8 颗粒层职责: - MPI - 动态库 - 第三方求解器强依赖 + +## 18. 0.6.0 Nonlinear Lifecycle Architecture Addendum + +0.6.0 adds `src/solver/fem_nonlinear_lifecycle.f90` as a small shared +diagnostic state machine. The module is intentionally additive: it records +solver lifecycle state and owner rollback audit results, but it does not own +Newton, Newmark, Riks, contact, cohesive or particle algorithms. + +Lifecycle levels: + +```text +analysis step + increment + trial state + iteration + accept / reject + commit / rollback +``` + +Covered event names are `increment-begin`, `trial-begin`, +`iteration-begin`, `iteration-result`, `accept`, `reject`, `cutback`, +`commit` and `rollback`. + +Audit status names are `begin-trial`, `rollback-requested`, `rollback-ok`, +`rollback-failed` and `commit-ok`. + +Owner adapters currently cover material/element state, contact multiplier +state, compact cohesive state and particle step audit. Static nonlinear, +nonlinear Newmark and Riks/arc paths record lifecycle events for the covered +subset. Larger algorithm rewrites remain outside the 0.6.0 architecture +boundary. diff --git a/docs/04_mathematical_model_and_algorithms.md b/docs/04_mathematical_model_and_algorithms.md index 487e8da..fea32f0 100644 --- a/docs/04_mathematical_model_and_algorithms.md +++ b/docs/04_mathematical_model_and_algorithms.md @@ -1774,3 +1774,33 @@ longrun/研究验证,不作为 V5 PASS 条件。 friction-stick and friction-slip branches are reported separately, with rigid translation and energy probes. This is not a complete production AL/mortar consistent tangent derivation. + +## 21. 0.6.0 Lifecycle Diagnostics Algorithms + +0.6.0 adds a diagnostic lifecycle layer around existing nonlinear algorithms. +It does not change the mathematical update rules for Newton, nonlinear +Newmark, Riks/arc-length, contact, cohesive or particle paths. + +The lifecycle algorithm records a finite-state trace: + +```text +increment-begin -> trial-begin -> iteration-begin + -> iteration-result -> commit -> accept +``` + +Rejected paths may record `cutback`, `reject` and rollback audit statuses. +The audit layer records `begin-trial`, `rollback-requested`, `rollback-ok`, +`rollback-failed` and `commit-ok` counters. The material adapter checks the +covered element state by checksum before and after rollback. Contact, +cohesive and particle adapters report owner-specific compact state audit +results into the same lifecycle status. + +Riks/arc diagnostics add load factor, arc residual and path-append state to +the lifecycle snapshot. These fields are diagnostic state only; 0.6.0 does not +introduce generalized mixed-control continuation, branch switching or a new +arc-length algorithm. + +The lifecycle layer is intended to make accepted/rejected increments and +rollback ownership visible in tests, CSV output and restart. Complete +industrial AL/mortar consistent tangent derivation and cohesive mainline +integration remain deferred algorithm work. diff --git a/docs/05_interface_control_document.md b/docs/05_interface_control_document.md index 67129da..9c9b1f8 100644 --- a/docs/05_interface_control_document.md +++ b/docs/05_interface_control_document.md @@ -1480,3 +1480,48 @@ Boundary: - 0.5.3 documents audit and diagnostic interfaces. It does not claim complete industrial AL/mortar consistent tangent support. + +## 19. 0.6.0 Lifecycle Interface Addendum + +Fortran diagnostic API: + +```fortran +subroutine fem_get_nl_lifecycle_snapshot(step, increment, iteration, & + event_id, event_name, reason_id, reason_name, ierr) + +subroutine fem_get_nl_lifecycle_arc(load_factor, arc_residual, & + path_appended, ierr) + +subroutine fem_get_nl_lifecycle_audit(status_id, status_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, ierr) +``` + +The lifecycle event names are `none`, `increment-begin`, `trial-begin`, +`iteration-begin`, `iteration-result`, `accept`, `reject`, `cutback`, +`commit` and `rollback`. + +The audit status names are `none`, `begin-trial`, `rollback-requested`, +`rollback-ok`, `rollback-failed` and `commit-ok`. + +CSV/output schema: + +- `continuation_path.csv` keeps all previous columns in the same order. +- 0.6.0 appends `lifecycle_event_id`, `lifecycle_event_name`, + `lifecycle_audit_status`, `lifecycle_audit_name`, + `lifecycle_increment`, `lifecycle_iteration`, + `lifecycle_accept_count` and `lifecycle_reject_count`. + +Restart schema: + +- Restart files written by 0.6.0 use restart version 5. +- Version 5 may append an optional `LIFECYCLE_DIAGNOSTICS` line before `END`. +- Readers still accept older files, and also accept restart files that do not + include the lifecycle diagnostics line. + +Boundary: + +- The 0.6.0 lifecycle interface exposes diagnostics and rollback audit state. + It does not expose a new C ABI lifecycle wrapper yet, and it does not claim + complete AL/mortar tangent, mixed-control continuation or cohesive mainline + support. diff --git a/docs/06_test_and_verification_plan.md b/docs/06_test_and_verification_plan.md index dc56492..3ac3415 100644 --- a/docs/06_test_and_verification_plan.md +++ b/docs/06_test_and_verification_plan.md @@ -867,3 +867,32 @@ Acceptance criteria: diagnostics and ignores timing-only differences. - Documentation must keep the explicit boundary that 0.5.3 does not deliver a complete industrial AL/mortar consistent tangent rewrite. + +## 26. 0.6.0 Lifecycle Regression Addendum + +0.6.0 targeted regression commands: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|restart|contact|cohesive_contact|particle_step)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(implicit_inp|contact_mortar_report|contact_multiplier_report)$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +Acceptance criteria: + +- `nonlinear_lifecycle` verifies event names, empty snapshot, event history, + arc defaults and audit status transitions. +- `solver_implicit` verifies static nonlinear, nonlinear Newmark and Riks/arc + lifecycle events, plus accepted path CSV lifecycle columns. +- `restart` verifies restart version 5 lifecycle diagnostics round-trip after + an accepted increment, and verifies that a file without the lifecycle block + still reads. +- Contact, cohesive and particle module tests consume rollback/commit audit + status without changing their physics paths. + +0.6.0 verification is limited to lifecycle foundation and rollback audit for +the covered subset. It must not be used as evidence for complete industrial +AL/mortar tangent, generalized mixed-control continuation or cohesive contact +mainline delivery. diff --git a/docs/07_user_manual.md b/docs/07_user_manual.md index f13d848..13b2477 100644 --- a/docs/07_user_manual.md +++ b/docs/07_user_manual.md @@ -587,3 +587,30 @@ should inspect: These fields are meant to separate geometry/search, normal contact, friction, constraint, linear-solver and material-local causes. They are not a guarantee that every large industrial AL/mortar contact path will converge in 0.5.3. + +## 15. 0.6.0 Lifecycle Diagnostics Notes + +0.6.0 adds lifecycle diagnostics for nonlinear runs. Users can inspect whether +a covered nonlinear path is at increment begin, trial begin, iteration result, +accept, reject, cutback, commit or rollback. + +For accepted continuation/Riks path output, `continuation_path.csv` keeps the +old columns and appends lifecycle fields: + +- `lifecycle_event_id` +- `lifecycle_event_name` +- `lifecycle_audit_status` +- `lifecycle_audit_name` +- `lifecycle_increment` +- `lifecycle_iteration` +- `lifecycle_accept_count` +- `lifecycle_reject_count` + +Restart files written by 0.6.0 preserve lifecycle diagnostics for the covered +accepted-increment subset. Older restart files without lifecycle diagnostics +are still accepted by the reader. + +Current limitation: lifecycle diagnostics improve explainability and rollback +audit coverage. They do not mean FemLite 0.6.0 has complete industrial +AL/mortar consistent tangent support, generalized mixed-control continuation, +cohesive contact mainline integration or DEM/FEM subcycling. diff --git a/docs/08_developer_manual.md b/docs/08_developer_manual.md index 3f6bd44..8bd9326 100644 --- a/docs/08_developer_manual.md +++ b/docs/08_developer_manual.md @@ -592,3 +592,23 @@ When adding or changing diagnostic fields after 0.5.3: AL/mortar consistent tangent rewrite is explicitly scheduled. - Do not mark compact contact benchmarks as proof of complete industrial contact coverage. + +## 20. 0.6.0 Lifecycle Developer Notes + +When adding a new nonlinear owner state after 0.6.0: + +- Record lifecycle events through `fem_nonlinear_lifecycle` instead of creating + a second event vocabulary. +- Use existing event names and add new ids only when a test or output consumer + needs a distinct state. +- Pair every trial-state mutation with an observable commit or rollback audit. +- Extend `nonlinear_lifecycle`, the relevant owner test and one report/output + checker when adding lifecycle fields. +- Keep `continuation_path.csv` append-only for new lifecycle/report columns. +- Add restart state only as an optional block unless a deliberately versioned + format break is approved. + +0.6.0 lifecycle hooks are diagnostics and audit infrastructure. Do not use +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. diff --git a/docs/v6.0_development_plan.md b/docs/v6.0_development_plan.md new file mode 100644 index 0000000..860f862 --- /dev/null +++ b/docs/v6.0_development_plan.md @@ -0,0 +1,247 @@ +# FemLite 0.6.0 Development Plan + +Document status: development plan draft + +Date: 2026-07-01 + +Scope: FemLite 0.6.0 development, review, testing and release planning. + +Source: `docs/suggests.md` + +## 1. Positioning + +FemLite 0.6.0 is the algorithm-foundation release after the 0.5.x V5 +close-out. + +```text +FemLite 0.6.0 = unified nonlinear state machine and lifecycle foundation +``` + +0.5.3 completed nonlinear/contact explainability hardening: stable failure +reasons, residual breakdown fields, contact diagnostics, restart diagnostic +round trips, tangent audit split and OpenMP deterministic contact checks. +0.6.0 should build on that work by making the nonlinear increment lifecycle +explicit and shared. + +The release should improve depth and reliability instead of adding broad new +feature families. The first controlled loop is: + +```text +begin increment + begin trial state + assemble residual/tangent + solve correction + evaluate convergence and events + accept or reject + commit or rollback every owned state + record diagnostics +end increment +``` + +## 2. Delivery Boundary + +### 2.1 0.6.0 must deliver + +- A small, shared nonlinear lifecycle/state-machine module. +- Stable event ids/names for increment begin, trial begin, iteration result, + accept, reject, cutback, commit and rollback. +- A rollback audit that can prove rejected increments do not contaminate + material, contact, cohesive, particle, Newmark or continuation-owned state + for the covered subset. +- Unified per-increment diagnostics that connect reason id, residual + breakdown, linear-solver diagnostics, contact/material counters and lifecycle + event status. +- Static nonlinear, Newmark nonlinear and Riks/arc-length paths using the same + lifecycle recording points for the covered subset. +- Restart-after-accepted-increment evidence that lifecycle diagnostics survive + the round trip where the underlying state is already restart-supported. +- Documentation and checkers that make the new lifecycle contract visible. + +### 2.2 0.6.0 does 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 all contact algorithms. +- General mixed-control continuation and branch switching. +- Complete shell preload `K_G` and high-order solid geometric stiffness. +- 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 the lifecycle interface, but they are not 0.6.0 +blocking scope. + +## 3. Design Principles + +- Keep the first state machine additive and observable. It should not rewrite + every solver loop at once. +- Use thin lifecycle hooks around existing paths before moving ownership of + algorithm decisions. +- Make every new diagnostic field consumed by a test, checker or report audit. +- Preserve existing public APIs and CSV columns unless a versioned change is + documented. +- Treat rollback correctness as a product behavior, not only an internal + implementation detail. +- Pause for review if a task requires choosing between incompatible solver-loop + designs. + +## 4. Proposed Architecture + +### 4.1 Lifecycle levels + +```text +Analysis step + Increment + Iteration + Trial state + Residual assembly + Tangent assembly + Linear solve + Line search / damping / trust region + Accept / reject + Commit / rollback +``` + +### 4.2 Core module + +Recommended new module: + +```text +src/solver/fem_nonlinear_lifecycle.f90 +``` + +Responsibilities: + +- Define lifecycle event ids and names. +- Store the current increment/iteration lifecycle snapshot. +- Provide begin/end/update helpers for solver loops. +- Store rollback/commit audit counters. +- Provide a query API for tests and output modules. + +The module should not own Newton, Riks, contact or material algorithms in +0.6.0. It should first record and verify their lifecycle behavior. + +### 4.3 Owner adapters + +The following owners should initially expose small audit hooks: + +| Owner | 0.6.0 expectation | +|---|---| +| Material state | Record local failure count and state checksum before/after rollback for covered elements. | +| Contact state | Record active/state counters, gap/slip diagnostics and restart-owned contact fields. | +| Cohesive state | Record damage/energy/status checks where existing cohesive state restart exists. | +| Particle state | Record mass/momentum/energy counters for explicit particle step subset. | +| Newmark state | Record displacement/velocity/acceleration trial and rollback checks for the covered nonlinear path. | +| Continuation/Riks path | Record load factor, arc residual and accepted-path append decision. | + +### 4.4 Diagnostics + +0.6.0 should connect, not replace, existing diagnostics: + +- nonlinear reason id/name from 0.5.3; +- residual breakdown from 0.5.3; +- linear solver diagnostics from 0.5.x; +- contact state/residual diagnostics from 0.5.3; +- material local failure count; +- lifecycle event id/name; +- commit/rollback audit status; +- accepted/rejected increment counters. + +## 5. Execution Plan + +| Item | Theme | Output | Primary tests | +|---|---|---|---| +| 0.6.0-1 | Scope and API skeleton | lifecycle ids, names and empty snapshot query | new lifecycle unit test | +| 0.6.0-2 | Static nonlinear hook | increment/iteration begin/end events | `solver_implicit` | +| 0.6.0-3 | Newmark hook | dynamic nonlinear lifecycle events | `solver_implicit` | +| 0.6.0-4 | Riks/arc hook | load-factor/arc event fields | `solver_implicit`, `implicit_inp` | +| 0.6.0-5 | Rollback audit core | generic audit counters and status | lifecycle unit test | +| 0.6.0-6 | Material rollback audit | material state checksum subset | `solver_implicit`, material tests | +| 0.6.0-7 | Contact rollback audit | contact state/diagnostic subset | `restart`, contact report tests | +| 0.6.0-8 | Cohesive/particle audit adapters | existing compact owner checks | `cohesive_contact`, `particle_acceptance` | +| 0.6.0-9 | Lifecycle output | path/report columns or compact lifecycle CSV | `solver_implicit`, checker | +| 0.6.0-10 | Restart audit | accepted-increment lifecycle round trip | `restart` | +| 0.6.0-11 | Documentation | design/interface/manual/test plan sync | wording checks | +| 0.6.0-12 | Release close-out | version, matrix and regression evidence | targeted + acceptance tests | + +## 6. Acceptance Criteria + +0.6.0 can close when: + +- all 0.6.0 TODO items are complete; +- the lifecycle snapshot is queryable from tests; +- static nonlinear, nonlinear Newmark and Riks/arc paths record lifecycle + events consistently for covered paths; +- rollback audit catches at least one intentionally rejected increment scenario; +- accepted-increment restart preserves both state and lifecycle diagnostics for + the covered subset; +- existing V5 acceptance tests do not regress; +- documentation states the boundary between lifecycle foundation and deferred + larger algorithm rewrites. + +Suggested 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 -L v5_acceptance --output-on-failure +git diff --check +``` + +## 7. Follow-up Route After 0.6.0 + +After the lifecycle foundation is proven, the next releases can safely deepen +larger algorithms: + +- 0.6.x: contact state-machine stabilization and AL/mortar tangent long-path + work. +- 0.7.x: shell/solid geometric stiffness and preload-to-buckling workflow. +- 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. + +## 8. Implementation Contract + +The implemented 0.6.0 lifecycle foundation is additive. It records the current +nonlinear step, increment, iteration, event id/name, reason id/name, arc state +and audit status without changing Newton, Newmark, Riks or contact algorithms. + +Stable event names are: + +- `none` +- `increment-begin` +- `trial-begin` +- `iteration-begin` +- `iteration-result` +- `accept` +- `reject` +- `cutback` +- `commit` +- `rollback` + +Stable audit status names are: + +- `none` +- `begin-trial` +- `rollback-requested` +- `rollback-ok` +- `rollback-failed` +- `commit-ok` + +The public diagnostic boundary is: + +- Fortran diagnostics query the latest lifecycle snapshot, arc/path state and + audit counters. +- `continuation_path.csv` keeps older columns in place and appends lifecycle + event/status, lifecycle increment/iteration and accepted/rejected counters. +- Restart version 5 appends an optional `LIFECYCLE_DIAGNOSTICS` block after + contact diagnostics. Readers still accept files that end at `END` without + this block. + +0.6.0 does not implement a complete industrial AL/mortar consistent tangent, +mixed-control continuation or cohesive contact mainline. Those items remain +follow-up work that can consume the lifecycle interface. diff --git a/docs/v6_acceptance_report.md b/docs/v6_acceptance_report.md new file mode 100644 index 0000000..228b913 --- /dev/null +++ b/docs/v6_acceptance_report.md @@ -0,0 +1,68 @@ +# FemLite 0.6.0 Acceptance Report + +Date: 2026-07-01 + +Status: release close-out candidate. + +## Scope + +FemLite 0.6.0 closes the first algorithm-foundation loop after the 0.5.x V5 +diagnostic hardening line. The release adds a shared nonlinear lifecycle +module, lifecycle hooks for the covered static/Newmark/Riks paths, rollback +audit adapters, lifecycle CSV output fields and restart version 5 lifecycle +diagnostics. + +0.6.0 does not claim delivery of complete industrial AL/mortar consistent +tangents, generalized mixed-control continuation, cohesive contact mainline, +DEM/FEM subcycling, nonzero harmonic cyclic solving or production roll-forming +workflow support. + +## Delivered Evidence + +| Item | Evidence | +|---|---| +| Lifecycle ids and snapshot | `nonlinear_lifecycle` covers event names, empty snapshot, history and audit names. | +| Static nonlinear hook | `solver_implicit` covers accepted and rejected/cutback lifecycle paths. | +| Nonlinear Newmark hook | `solver_implicit` covers nonlinear Newmark success and rejection. | +| Riks/arc hook | `solver_implicit` covers lifecycle accept, load factor, arc residual and path append. | +| Rollback audit | Material, contact, cohesive and particle audit adapters feed the shared lifecycle status. | +| Output schema | `continuation_path.csv` appends lifecycle fields without reordering older columns. | +| Restart schema | Restart version 5 writes optional `LIFECYCLE_DIAGNOSTICS`; reader accepts files without the block. | +| Documentation | Design, algorithm, interface, test, user and developer docs state lifecycle boundaries and deferred solver rewrites. | + +## Planned Close-Out 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 -L v5_acceptance --output-on-failure +git diff --check +``` + +## Results + +| Command | Result | +|---|---| +| `cmake --build build-codex-gcc --parallel` | passed; CMake regenerated and full build completed. | +| 0.6.0 targeted regression command | 7/7 passed. | +| `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` | 39/39 passed after updating version assertions to 0.6.0. | +| `git diff --check` | passed; Git reported line-ending normalization warnings only. | + +## Close-Out Conclusion + +FemLite 0.6.0 meets the planned lifecycle foundation acceptance criteria on +the local `build-codex-gcc` configuration. The release remains bounded to +diagnostic lifecycle infrastructure and rollback audit coverage for the +documented subset. + +## Deferred Work + +- Complete industrial AL/mortar consistent tangent and full contact + state-machine rewrite. +- Generalized mixed-control continuation and branch switching. +- Complete shell preload `K_G` and high-order solid geometric stiffness. +- Cohesive contact mainline integration. +- Nonzero harmonic cyclic symmetry. +- DEM/FEM subcycling and large-particle long runs. +- Production roll-forming process chain. +- Additional solver scaling and block preconditioning work. diff --git a/docs/v6_benchmark_matrix.md b/docs/v6_benchmark_matrix.md new file mode 100644 index 0000000..53d0812 --- /dev/null +++ b/docs/v6_benchmark_matrix.md @@ -0,0 +1,51 @@ +# FemLite 0.6.0 Benchmark And Acceptance Matrix + +Date: 2026-07-01 + +Scope: executable evidence for the 0.6.0 nonlinear lifecycle foundation and +rollback audit release. + +Current local 0.6.0 evidence on `build-codex-gcc`: + +- `cmake --build build-codex-gcc --parallel` passed. +- `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` passed 7/7. +- `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` passed 39/39. +- `git diff --check` passed with line-ending normalization warnings only. + +## Release Boundary + +0.6.0 delivers lifecycle diagnostics and rollback audit infrastructure for the +covered nonlinear subset. It does not deliver a complete industrial AL/mortar +consistent tangent rewrite, generalized mixed-control continuation, cohesive +contact mainline integration, DEM/FEM subcycling or a production roll-forming +workflow. + +## 0.6.0 Matrix + +| Area | Code or output target | Test/checker | Acceptance evidence | +|---|---|---|---| +| Lifecycle core | `src/solver/fem_nonlinear_lifecycle.f90` | `nonlinear_lifecycle` | Stable event names, empty snapshot, event history, arc defaults and audit status transitions. | +| Static nonlinear lifecycle | `src/solver/fem_solver_static_nonlinear.f90` | `solver_implicit` | Increment/trial/iteration/result/commit/accept/reject/cutback events are observable without changing convergence rules. | +| Nonlinear Newmark lifecycle | `src/solver/fem_solver_newmark.f90` | `solver_implicit` | Dynamic nonlinear success and rejection paths expose lifecycle state. | +| Riks/arc lifecycle | static nonlinear Riks path | `solver_implicit` | Accepted path records lifecycle accept, load factor, arc residual and path append state. | +| Material rollback audit | `src/element/fem_element_state.f90` | `solver_implicit`, `nonlinear_lifecycle` | Covered material state rollback is audited by checksum and status counters. | +| Contact rollback audit | `src/boundary/fem_contact_multiplier.f90` | `contact`, `restart` | Contact multiplier trial/commit/rollback contributes audit status without changing contact physics. | +| Cohesive audit | `src/boundary/fem_cohesive_state.f90` | `cohesive_contact` | Compact cohesive state rollback/commit emits lifecycle audit status. | +| Particle audit | `src/particle/fem_particle_audit.f90` | `particle_step` | Particle audit pass/fail maps into lifecycle commit/rollback-failed status. | +| Lifecycle CSV output | `continuation_path.csv` | `solver_implicit` | Old path columns remain stable; lifecycle event/status, increment/iteration and accept/reject counters are appended. | +| Lifecycle restart | restart version 5 optional block | `restart` | Accepted-increment lifecycle diagnostics round-trip; files without the optional block still read. | + +## 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 -L v5_acceptance --output-on-failure +git diff --check +``` + +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 +``` diff --git a/src/base/fem_api.f90 b/src/base/fem_api.f90 index 06e0949..a793ccc 100644 --- a/src/base/fem_api.f90 +++ b/src/base/fem_api.f90 @@ -8,6 +8,8 @@ module fem_api use fem_element_mass use fem_element_internal use fem_solver_implicit + use fem_nonlinear_lifecycle, only: NLC_EVENT_CUTBACK, NLC_EVENT_REJECT, & + nl_lifecycle_record_event, nl_lifecycle_reset use fem_coupling use fem_boundary use fem_contact @@ -28,6 +30,7 @@ contains call error_clear(ierr) call control_set_defaults() call contact_reset_search_stats() + call nl_lifecycle_reset() call log_open('femlite.log', log_ierr) if (log_ierr .ne. FEM_SUCCESS) then call error_set(FEM_ERR_OUTPUT, 'failed to open femlite.log', ierr) @@ -42,6 +45,7 @@ contains integer, intent(out) :: ierr call cpl_finalize_facets() call contact_reset_search_stats() + call nl_lifecycle_reset() call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) return call log_info('FemLite finalized') @@ -667,6 +671,8 @@ contains convergence_status_code = CONVERGENCE_STATUS_CUTBACK convergence_failure_code = CONV_FAIL_NONE convergence_failure_reason_id = NFAIL_NONE + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter, NLC_EVENT_CUTBACK, NFAIL_NONE) ierr = FEM_SUCCESS else convergence_cutback_count = total_cutback @@ -677,6 +683,9 @@ contains else convergence_failure_reason_id = NFAIL_MIN_STEP end if + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter, NLC_EVENT_REJECT, & + convergence_failure_reason_id) return end if end do diff --git a/src/base/fem_api_diagnostics.f90 b/src/base/fem_api_diagnostics.f90 index 8a16d6b..cde8851 100644 --- a/src/base/fem_api_diagnostics.f90 +++ b/src/base/fem_api_diagnostics.f90 @@ -5,6 +5,9 @@ module fem_api_diagnostics use fem_linear_solver_cg, only: linear_solver_configure, & linear_solver_get_settings, linear_solver_get_stats, & 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 use fem_api_state, only: api_initialized implicit none private @@ -14,6 +17,9 @@ module fem_api_diagnostics public :: fem_get_convergence_diagnostics public :: fem_get_convergence_reason public :: fem_get_residual_breakdown + public :: fem_get_nl_lifecycle_snapshot + public :: fem_get_nl_lifecycle_arc + public :: fem_get_nl_lifecycle_audit public :: fem_get_continuation_path_count public :: fem_get_continuation_path_row public :: fem_set_linear_solver @@ -207,6 +213,94 @@ contains ierr = FEM_SUCCESS end subroutine fem_get_residual_breakdown + subroutine fem_get_nl_lifecycle_snapshot(step, increment, iteration, & + event_id, event_name, reason_id, & + reason_name, 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) :: ierr + + step = 0 + increment = 0 + iteration = 0 + event_id = 0 + event_name = 'none' + reason_id = NFAIL_NONE + reason_name = 'none' + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_nl_lifecycle_snapshot called before fem_initialize', & + ierr) + return + end if + + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + ierr = FEM_SUCCESS + end subroutine fem_get_nl_lifecycle_snapshot + + subroutine fem_get_nl_lifecycle_arc(load_factor, arc_residual, & + path_appended, ierr) + real(rk), intent(out) :: load_factor + real(rk), intent(out) :: arc_residual + logical, intent(out) :: path_appended + integer, intent(out) :: ierr + + load_factor = ZERO + arc_residual = ZERO + path_appended = .false. + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_nl_lifecycle_arc called before fem_initialize', ierr) + return + end if + + call nl_lifecycle_get_arc_state(load_factor, arc_residual, path_appended) + ierr = FEM_SUCCESS + end subroutine fem_get_nl_lifecycle_arc + + subroutine fem_get_nl_lifecycle_audit(status_id, status_name, & + begin_trial_count, & + rollback_requested_count, & + rollback_ok_count, & + rollback_failed_count, & + commit_ok_count, ierr) + integer, intent(out) :: status_id + character(len=*), intent(out) :: status_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) :: ierr + + status_id = 0 + status_name = 'none' + begin_trial_count = 0 + rollback_requested_count = 0 + rollback_ok_count = 0 + rollback_failed_count = 0 + commit_ok_count = 0 + + if (.not. api_initialized) then + call error_set(FEM_ERR_INTERNAL, & + 'fem_get_nl_lifecycle_audit called before fem_initialize', ierr) + return + end if + + call nl_lifecycle_get_audit(status_id, status_name, begin_trial_count, & + rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + ierr = FEM_SUCCESS + end subroutine fem_get_nl_lifecycle_audit + subroutine fem_get_continuation_path_count(count, ierr) integer, intent(out) :: count integer, intent(out) :: ierr diff --git a/src/base/fem_precision.f90 b/src/base/fem_precision.f90 index 7fbd0b7..de4dcd8 100644 --- a/src/base/fem_precision.f90 +++ b/src/base/fem_precision.f90 @@ -15,8 +15,8 @@ module fem_precision integer, parameter :: NSTATEV_MAX = 32 integer, parameter :: FEMLITE_VERSION_MAJOR = 0 - integer, parameter :: FEMLITE_VERSION_MINOR = 5 - integer, parameter :: FEMLITE_VERSION_PATCH = 3 + integer, parameter :: FEMLITE_VERSION_MINOR = 6 + integer, parameter :: FEMLITE_VERSION_PATCH = 0 real(rk), parameter :: ZERO = 0.0_rk real(rk), parameter :: ONE = 1.0_rk diff --git a/src/boundary/fem_cohesive_state.f90 b/src/boundary/fem_cohesive_state.f90 index ef7e475..4d0db53 100644 --- a/src/boundary/fem_cohesive_state.f90 +++ b/src/boundary/fem_cohesive_state.f90 @@ -2,6 +2,10 @@ module fem_cohesive_state use fem_precision use fem_error use fem_cohesive_law + use fem_nonlinear_lifecycle, only: NLC_AUDIT_BEGIN_TRIAL, & + NLC_AUDIT_COMMIT_OK, NLC_AUDIT_ROLLBACK_FAILED, & + NLC_AUDIT_ROLLBACK_OK, NLC_AUDIT_ROLLBACK_REQUESTED, & + nl_lifecycle_record_audit implicit none private @@ -34,6 +38,7 @@ module fem_cohesive_state real(rk), allocatable :: coh_trial_energy(:) integer :: coh_count = 0 integer :: coh_capacity = 0 + integer :: coh_audit_slot_count = 0 contains @@ -49,9 +54,12 @@ contains end if coh_count = 0 coh_capacity = 0 + coh_audit_slot_count = 0 end subroutine cohesive_state_reset subroutine cohesive_state_begin_trial() + coh_audit_slot_count = coh_count + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) if (coh_count .le. 0 .or. .not. allocated(coh_damage)) return coh_trial_damage(1:coh_count) = coh_damage(1:coh_count) coh_trial_opening(1:coh_count) = coh_max_opening(1:coh_count) @@ -109,16 +117,54 @@ contains coh_max_opening(1:coh_count) = coh_trial_opening(1:coh_count) coh_max_effective(1:coh_count) = coh_trial_effective(1:coh_count) coh_energy(1:coh_count) = coh_trial_energy(1:coh_count) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) end subroutine cohesive_state_commit subroutine cohesive_state_rollback() - if (coh_count .le. 0 .or. .not. allocated(coh_damage)) return + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED) + if (coh_count .le. 0 .or. .not. allocated(coh_damage)) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + return + end if coh_trial_damage(1:coh_count) = coh_damage(1:coh_count) coh_trial_opening(1:coh_count) = coh_max_opening(1:coh_count) coh_trial_effective(1:coh_count) = coh_max_effective(1:coh_count) coh_trial_energy(1:coh_count) = coh_energy(1:coh_count) + if (cohesive_state_rollback_ok()) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + else + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + end if end subroutine cohesive_state_rollback + logical function cohesive_state_rollback_ok() + real(rk) :: max_error + real(rk) :: max_scale + + cohesive_state_rollback_ok = .false. + if (coh_count .ne. coh_audit_slot_count) return + if (coh_count .le. 0) then + cohesive_state_rollback_ok = .true. + return + end if + if (.not. allocated(coh_damage) .or. & + .not. allocated(coh_trial_damage)) return + max_error = max(maxval(abs(coh_trial_damage(1:coh_count) - & + coh_damage(1:coh_count))), & + max(maxval(abs(coh_trial_opening(1:coh_count) - & + coh_max_opening(1:coh_count))), & + max(maxval(abs(coh_trial_effective(1:coh_count) - & + coh_max_effective(1:coh_count))), & + maxval(abs(coh_trial_energy(1:coh_count) - & + coh_energy(1:coh_count)))))) + max_scale = max(ONE, maxval(abs(coh_damage(1:coh_count))), & + maxval(abs(coh_max_opening(1:coh_count))), & + maxval(abs(coh_max_effective(1:coh_count))), & + maxval(abs(coh_energy(1:coh_count)))) + cohesive_state_rollback_ok = max_error .le. & + 100.0_rk * epsilon(ONE) * max_scale + end function cohesive_state_rollback_ok + subroutine cohesive_state_old(pair, selem, sface, melem, mface, point_id, & damage, max_opening, max_effective, energy, & status) diff --git a/src/boundary/fem_contact_multiplier.f90 b/src/boundary/fem_contact_multiplier.f90 index cb5e0a5..69e6d72 100644 --- a/src/boundary/fem_contact_multiplier.f90 +++ b/src/boundary/fem_contact_multiplier.f90 @@ -5,6 +5,10 @@ module fem_contact_multiplier CONTACT_STATE_CLOSED_STICK, CONTACT_STATE_CLOSED_SLIP, & CONTACT_STATE_CLOSED_RESTICK, CONTACT_STATE_SEPARATING, & CONTACT_STATE_FAILED_PROJ + use fem_nonlinear_lifecycle, only: NLC_AUDIT_BEGIN_TRIAL, & + NLC_AUDIT_COMMIT_OK, NLC_AUDIT_ROLLBACK_FAILED, & + NLC_AUDIT_ROLLBACK_OK, NLC_AUDIT_ROLLBACK_REQUESTED, & + nl_lifecycle_record_audit implicit none private @@ -42,6 +46,7 @@ module fem_contact_multiplier real(rk), allocatable :: mult_trial_gap(:) integer :: mult_count = 0 integer :: mult_capacity = 0 + integer :: mult_audit_slot_count = 0 contains @@ -53,9 +58,12 @@ contains mult_trial_gap) mult_count = 0 mult_capacity = 0 + mult_audit_slot_count = 0 end subroutine contact_multiplier_reset subroutine contact_multiplier_begin_trial() + mult_audit_slot_count = mult_count + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) if (mult_count .le. 0 .or. .not. allocated(mult_lambda)) return mult_trial_lambda(1:mult_count) = mult_lambda(1:mult_count) mult_trial_gap(1:mult_count) = ZERO @@ -100,14 +108,43 @@ contains subroutine contact_multiplier_commit() if (mult_count .le. 0 .or. .not. allocated(mult_lambda)) return mult_lambda(1:mult_count) = mult_trial_lambda(1:mult_count) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) end subroutine contact_multiplier_commit subroutine contact_multiplier_rollback() - if (mult_count .le. 0 .or. .not. allocated(mult_lambda)) return + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED) + if (mult_count .le. 0 .or. .not. allocated(mult_lambda)) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + return + end if mult_trial_lambda(1:mult_count) = mult_lambda(1:mult_count) mult_trial_gap(1:mult_count) = ZERO + if (contact_multiplier_rollback_ok()) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + else + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + end if end subroutine contact_multiplier_rollback + logical function contact_multiplier_rollback_ok() + real(rk) :: max_error + + contact_multiplier_rollback_ok = .false. + if (mult_count .ne. mult_audit_slot_count) return + if (mult_count .le. 0) then + contact_multiplier_rollback_ok = .true. + return + end if + if (.not. allocated(mult_lambda) .or. & + .not. allocated(mult_trial_lambda) .or. & + .not. allocated(mult_trial_gap)) return + max_error = max(maxval(abs(mult_trial_lambda(1:mult_count) - & + mult_lambda(1:mult_count))), & + maxval(abs(mult_trial_gap(1:mult_count)))) + contact_multiplier_rollback_ok = max_error .le. & + 100.0_rk * epsilon(ONE) * max(ONE, maxval(abs(mult_lambda(1:mult_count)))) + end function contact_multiplier_rollback_ok + subroutine contact_multiplier_old(pair, selem, sface, melem, mface, & point_id, lambda_value) integer, intent(in) :: pair diff --git a/src/element/fem_element_state.f90 b/src/element/fem_element_state.f90 index 2cf2f06..f1a77f7 100644 --- a/src/element/fem_element_state.f90 +++ b/src/element/fem_element_state.f90 @@ -4,6 +4,10 @@ module fem_element_state use fem_database use fem_element_topology use fem_shell_rotation + use fem_nonlinear_lifecycle, only: NLC_AUDIT_BEGIN_TRIAL, & + NLC_AUDIT_COMMIT_OK, NLC_AUDIT_ROLLBACK_FAILED, & + NLC_AUDIT_ROLLBACK_OK, NLC_AUDIT_ROLLBACK_REQUESTED, & + nl_lifecycle_record_audit implicit none private @@ -17,6 +21,8 @@ module fem_element_state real(rk), allocatable :: shell_layer_statev_backup(:,:) integer, allocatable :: status_trial_backup(:) logical :: trial_backup_active = .false. + logical :: trial_abort_in_progress = .false. + real(rk) :: trial_state_checksum = ZERO integer, parameter :: SHELL_TP_PER_LAYER = 2 public :: element_state_ensure @@ -219,6 +225,8 @@ contains end if status_trial_backup = elem_status trial_backup_active = .true. + trial_state_checksum = element_state_checksum() + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) ierr = FEM_SUCCESS end subroutine element_state_begin_trial @@ -285,6 +293,10 @@ contains subroutine element_state_commit_trial(ierr) integer, intent(out) :: ierr + logical :: should_record_commit + + should_record_commit = trial_backup_active .and. & + (.not. trial_abort_in_progress) if (allocated(stress_trial_backup)) deallocate(stress_trial_backup) if (allocated(strain_trial_backup)) deallocate(strain_trial_backup) if (allocated(statev_trial_backup)) deallocate(statev_trial_backup) @@ -296,17 +308,68 @@ contains call shell_rotation_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) return trial_backup_active = .false. + trial_state_checksum = ZERO + if (should_record_commit) then + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + end if ierr = FEM_SUCCESS end subroutine element_state_commit_trial subroutine element_state_abort_trial(ierr) integer, intent(out) :: ierr + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED) call element_state_restore_trial(ierr) - if (ierr .ne. FEM_SUCCESS) return + if (ierr .ne. FEM_SUCCESS) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + return + end if + if (abs(element_state_checksum() - trial_state_checksum) .le. & + 100.0_rk * epsilon(ONE) * max(ONE, abs(trial_state_checksum))) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + else + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + end if + trial_abort_in_progress = .true. call element_state_commit_trial(ierr) + trial_abort_in_progress = .false. end subroutine element_state_abort_trial + real(rk) function element_state_checksum() + element_state_checksum = ZERO + if (allocated(stress)) then + element_state_checksum = element_state_checksum + sum(abs(stress)) + end if + if (allocated(strain)) then + element_state_checksum = element_state_checksum + 2.0_rk * & + sum(abs(strain)) + end if + if (allocated(statev)) then + element_state_checksum = element_state_checksum + 3.0_rk * & + sum(abs(statev)) + end if + if (allocated(shell_resultant)) then + element_state_checksum = element_state_checksum + 4.0_rk * & + sum(abs(shell_resultant)) + end if + if (allocated(shell_layer_stress)) then + element_state_checksum = element_state_checksum + 5.0_rk * & + sum(abs(shell_layer_stress)) + end if + if (allocated(shell_layer_strain)) then + element_state_checksum = element_state_checksum + 6.0_rk * & + sum(abs(shell_layer_strain)) + end if + if (allocated(shell_layer_statev)) then + element_state_checksum = element_state_checksum + 7.0_rk * & + sum(abs(shell_layer_statev)) + end if + if (allocated(elem_status)) then + element_state_checksum = element_state_checksum + 8.0_rk * & + real(sum(abs(elem_status)), rk) + end if + end function element_state_checksum + subroutine state_count_shell_layers(ierr) integer, intent(out) :: ierr integer :: elem diff --git a/src/output/fem_output_csv.f90 b/src/output/fem_output_csv.f90 index 2c0c73b..3f79783 100644 --- a/src/output/fem_output_csv.f90 +++ b/src/output/fem_output_csv.f90 @@ -7,6 +7,9 @@ module fem_output_csv use fem_contact_state, only: contact_get_search_stats, contact_get_perf_stats, & contact_get_cache_stats, contact_get_pair_stats use fem_element_state + 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 implicit none character(len=256) :: csv_output_directory = '.' @@ -345,7 +348,26 @@ contains integer :: unit_id integer :: ios integer :: row + integer :: audit_status + integer :: audit_begin_trial + integer :: audit_rollback_requested + integer :: audit_rollback_ok + integer :: audit_rollback_failed + integer :: audit_commit_ok + integer :: lifecycle_event_total + integer :: lifecycle_event_index + integer :: lifecycle_step + integer :: lifecycle_increment + integer :: lifecycle_iteration + integer :: lifecycle_event_id + integer :: lifecycle_reason_id + integer :: lifecycle_accept_count + integer :: lifecycle_reject_count character(len=64) :: reason_name + character(len=64) :: event_name + character(len=64) :: audit_name + character(len=64) :: lifecycle_name + character(len=64) :: lifecycle_reason_name if (nlc_path_count .le. 0) then ierr = FEM_SUCCESS @@ -376,7 +398,10 @@ contains 'linear_final_residual,linear_relative_residual,'// & 'residual_total,residual_force,residual_contact,'// & 'residual_constraint,residual_arc,material_failure_count,'// & - 'reason_id,reason_name' + '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' if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, & @@ -384,9 +409,27 @@ contains return end if + lifecycle_accept_count = 0 + lifecycle_reject_count = 0 + lifecycle_event_total = nl_lifecycle_get_event_count() + do lifecycle_event_index = 1, lifecycle_event_total + call nl_lifecycle_get_event(lifecycle_event_index, lifecycle_step, & + lifecycle_increment, lifecycle_iteration, lifecycle_event_id, & + lifecycle_name, lifecycle_reason_id, lifecycle_reason_name) + if (lifecycle_event_id .eq. NLC_EVENT_ACCEPT) then + lifecycle_accept_count = lifecycle_accept_count + 1 + else if (lifecycle_event_id .eq. NLC_EVENT_REJECT) then + lifecycle_reject_count = lifecycle_reject_count + 1 + end if + end do + do row = 1, nlc_path_count call convergence_failure_reason_name( & nlc_path_int(NLC_PATH_I_REASON_ID, row), reason_name) + call nl_lifecycle_event_name(NLC_EVENT_ACCEPT, event_name) + call nl_lifecycle_get_audit(audit_status, audit_name, & + audit_begin_trial, audit_rollback_requested, audit_rollback_ok, & + audit_rollback_failed, audit_commit_ok) write(unit_id,'(I12,2(A,ES24.16),A,I12,9(A,ES24.16),'// & 'A,I12,10(A,ES24.16),10(A,I12),3(A,ES24.16))', & iostat=ios, advance='no') & @@ -437,9 +480,15 @@ 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)',iostat=ios) & + write(unit_id,'(A,I12,A,A,A,I12,A,A,A,I12,A,A,4(A,I12))', & + iostat=ios) & ',', nlc_path_int(NLC_PATH_I_REASON_ID, row), & - ',', trim(reason_name) + ',', 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 end if if (ios .ne. 0) then close(unit_id) diff --git a/src/output/fem_restart.f90 b/src/output/fem_restart.f90 index d19beb8..440f3dd 100644 --- a/src/output/fem_restart.f90 +++ b/src/output/fem_restart.f90 @@ -9,6 +9,9 @@ module fem_restart use fem_contact_history, only: contact_history_write, contact_history_read use fem_contact_multiplier, only: contact_multiplier_write, & contact_multiplier_read + use fem_nonlinear_lifecycle, only: nl_lifecycle_get_snapshot, & + nl_lifecycle_get_arc_state, nl_lifecycle_get_audit, & + nl_lifecycle_restore implicit none private @@ -58,6 +61,8 @@ contains if (ios .ne. 0) go to 900 call write_contact_pair_diag(unit_id, ios) if (ios .ne. 0) go to 900 + call write_lifecycle_diag(unit_id, ios) + if (ios .ne. 0) go to 900 write(unit_id,'(A)',iostat=ios) 'END' if (ios .ne. 0) go to 900 @@ -104,7 +109,7 @@ contains read(unit_id,*,iostat=ios) tag, version if (ios .ne. 0 .or. trim(tag) .ne. 'FEMLITE_RESTART') go to 910 - if (version .lt. 1 .or. version .gt. 4) then + if (version .lt. 1 .or. version .gt. 5) then close(unit_id) call error_set(FEM_ERR_OUTPUT, 'unsupported restart version', ierr) return @@ -170,7 +175,7 @@ contains integer, intent(in) :: unit_id integer, intent(out) :: ios - write(unit_id,'(A,1X,I4)',iostat=ios) 'FEMLITE_RESTART', 4 + write(unit_id,'(A,1X,I4)',iostat=ios) 'FEMLITE_RESTART', 5 if (ios .ne. 0) return write(unit_id,'(A,4(1X,I12))',iostat=ios) 'COUNTS', nnode, nelem, & ndof, ngauss_total @@ -225,6 +230,11 @@ contains else if (trim(tag) .eq. 'END') then call contact_multiplier_read(unit_id, 0, ierr) if (ierr .ne. FEM_SUCCESS) return + else if (trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') then + call contact_multiplier_read(unit_id, 0, ierr) + if (ierr .ne. FEM_SUCCESS) return + call read_lifecycle_then_end(unit_id, line, ierr) + if (ierr .ne. FEM_SUCCESS) return else go to 920 end if @@ -245,6 +255,13 @@ contains if (ierr .ne. FEM_SUCCESS) return call contact_multiplier_read(unit_id, 0, ierr) if (ierr .ne. FEM_SUCCESS) return + else if (trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') then + call contact_history_read(unit_id, 0, ierr) + if (ierr .ne. FEM_SUCCESS) return + call contact_multiplier_read(unit_id, 0, ierr) + if (ierr .ne. FEM_SUCCESS) return + call read_lifecycle_then_end(unit_id, line, ierr) + if (ierr .ne. FEM_SUCCESS) return else call error_set(FEM_ERR_OUTPUT, 'invalid restart file tail', ierr) return @@ -348,6 +365,44 @@ contains end do end subroutine write_contact_pair_diag + subroutine write_lifecycle_diag(unit_id, ios) + integer, intent(in) :: unit_id + integer, intent(out) :: 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 :: path_value + real(rk) :: load_factor + real(rk) :: arc_residual + logical :: path_appended + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name) + call nl_lifecycle_get_arc_state(load_factor, arc_residual, path_appended) + call nl_lifecycle_get_audit(audit_status, audit_name, begin_trial_count, & + rollback_requested_count, rollback_ok_count, rollback_failed_count, & + commit_ok_count) + path_value = 0 + if (path_appended) path_value = 1 + + write(unit_id,'(A,7(1X,I12),2(1X,ES24.16),5(1X,I12))',iostat=ios) & + 'LIFECYCLE_DIAGNOSTICS', step, increment, iteration, event_id, & + reason_id, audit_status, path_value, load_factor, arc_residual, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count + end subroutine write_lifecycle_diag + subroutine read_diag_or_end(unit_id, ierr) integer, intent(in) :: unit_id integer, intent(out) :: ierr @@ -377,6 +432,10 @@ contains ierr = FEM_SUCCESS return end if + if (trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') then + call read_lifecycle_then_end(unit_id, line, ierr) + return + end if if (trim(tag) .ne. 'CONTACT_PAIR_DIAGNOSTICS') then call error_set(FEM_ERR_OUTPUT, 'restart missing END marker', ierr) return @@ -399,13 +458,81 @@ contains call read_contact_pair_diag_rows(unit_id, pair_count, ierr) if (ierr .ne. FEM_SUCCESS) return + read(unit_id,'(A)',iostat=ios) line + if (ios .ne. 0) then + call error_set(FEM_ERR_OUTPUT, 'restart missing END marker', ierr) + return + end if + read(line,*,iostat=ios) tag + if (ios .ne. 0) then + call error_set(FEM_ERR_OUTPUT, 'invalid restart tail marker', ierr) + return + end if + if (trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') then + call read_lifecycle_then_end(unit_id, line, ierr) + return + end if + if (trim(tag) .ne. 'END') then + call error_set(FEM_ERR_OUTPUT, 'restart missing END marker', ierr) + return + end if + ierr = FEM_SUCCESS + end subroutine read_diag_or_end + + subroutine read_lifecycle_then_end(unit_id, line, ierr) + integer, intent(in) :: unit_id + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=32) :: tag + integer :: ios + + call read_lifecycle_diag_line(line, ierr) + if (ierr .ne. FEM_SUCCESS) return + read(unit_id,*,iostat=ios) tag if (ios .ne. 0 .or. trim(tag) .ne. 'END') then call error_set(FEM_ERR_OUTPUT, 'restart missing END marker', ierr) return end if ierr = FEM_SUCCESS - end subroutine read_diag_or_end + end subroutine read_lifecycle_then_end + + subroutine read_lifecycle_diag_line(line, ierr) + character(len=*), intent(in) :: line + integer, intent(out) :: ierr + character(len=32) :: tag + integer :: ios + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + integer :: audit_status + integer :: path_value + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + real(rk) :: load_factor + real(rk) :: arc_residual + + read(line,*,iostat=ios) tag, step, increment, iteration, event_id, & + reason_id, audit_status, path_value, load_factor, arc_residual, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count + if (ios .ne. 0 .or. trim(tag) .ne. 'LIFECYCLE_DIAGNOSTICS') then + call error_set(FEM_ERR_OUTPUT, 'invalid restart lifecycle diagnostics', & + ierr) + return + end if + + call nl_lifecycle_restore(step, increment, iteration, event_id, reason_id, & + load_factor, arc_residual, path_value .ne. 0, audit_status, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + ierr = FEM_SUCCESS + end subroutine read_lifecycle_diag_line subroutine read_contact_pair_diag_rows(unit_id, pair_count, ierr) integer, intent(in) :: unit_id diff --git a/src/particle/fem_particle_audit.f90 b/src/particle/fem_particle_audit.f90 index 5e90a3e..2a32eea 100644 --- a/src/particle/fem_particle_audit.f90 +++ b/src/particle/fem_particle_audit.f90 @@ -3,6 +3,8 @@ module fem_particle_audit use fem_error use fem_particle_state use fem_particle_step + use fem_nonlinear_lifecycle, only: NLC_AUDIT_COMMIT_OK, & + NLC_AUDIT_ROLLBACK_FAILED, nl_lifecycle_record_audit implicit none private @@ -86,6 +88,11 @@ contains audit%energy_change .gt. energy_tol) then audit%status = max(audit%status, PAUDIT_WARN) end if + if (audit%status .eq. PAUDIT_FAIL) then + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + else + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + end if call error_clear(ierr) end subroutine paudit_step diff --git a/src/solver/fem_nonlinear_lifecycle.f90 b/src/solver/fem_nonlinear_lifecycle.f90 new file mode 100644 index 0000000..2a280c7 --- /dev/null +++ b/src/solver/fem_nonlinear_lifecycle.f90 @@ -0,0 +1,359 @@ +module fem_nonlinear_lifecycle + use fem_precision + use fem_control, only: NFAIL_NONE, convergence_failure_reason_name + implicit none + private + + integer, parameter, public :: NLC_EVENT_NONE = 0 + integer, parameter, public :: NLC_EVENT_INCREMENT_BEGIN = 10 + integer, parameter, public :: NLC_EVENT_TRIAL_BEGIN = 20 + integer, parameter, public :: NLC_EVENT_ITERATION_BEGIN = 25 + integer, parameter, public :: NLC_EVENT_ITERATION_RESULT = 30 + integer, parameter, public :: NLC_EVENT_ACCEPT = 40 + integer, parameter, public :: NLC_EVENT_REJECT = 50 + integer, parameter, public :: NLC_EVENT_CUTBACK = 60 + integer, parameter, public :: NLC_EVENT_COMMIT = 70 + integer, parameter, public :: NLC_EVENT_ROLLBACK = 80 + + integer, parameter, public :: NLC_AUDIT_NONE = 0 + integer, parameter, public :: NLC_AUDIT_BEGIN_TRIAL = 10 + integer, parameter, public :: NLC_AUDIT_ROLLBACK_REQUESTED = 20 + integer, parameter, public :: NLC_AUDIT_ROLLBACK_OK = 30 + integer, parameter, public :: NLC_AUDIT_ROLLBACK_FAILED = 40 + integer, parameter, public :: NLC_AUDIT_COMMIT_OK = 50 + + public :: nl_lifecycle_reset + public :: nl_lifecycle_event_name + public :: nl_lifecycle_audit_status_name + public :: nl_lifecycle_begin_increment + public :: nl_lifecycle_record_event + public :: nl_lifecycle_record_audit + public :: nl_lifecycle_get_snapshot + public :: nl_lifecycle_record_arc_state + public :: nl_lifecycle_mark_path_appended + public :: nl_lifecycle_get_arc_state + public :: nl_lifecycle_get_audit + public :: nl_lifecycle_restore + public :: nl_lifecycle_get_event_count + public :: nl_lifecycle_get_event + + integer, parameter :: NLC_EVENT_HISTORY_MAX = 256 + integer :: lifecycle_step = 0 + integer :: lifecycle_increment = 0 + integer :: lifecycle_iteration = 0 + integer :: lifecycle_event_id = NLC_EVENT_NONE + integer :: lifecycle_reason_id = NFAIL_NONE + real(rk) :: lifecycle_load_factor = ZERO + real(rk) :: lifecycle_arc_residual = ZERO + logical :: lifecycle_path_appended = .false. + integer :: lifecycle_audit_status = NLC_AUDIT_NONE + integer :: audit_begin_trial_count = 0 + integer :: audit_rollback_req_count = 0 + integer :: audit_rollback_ok_count = 0 + integer :: audit_rollback_fail_count = 0 + integer :: audit_commit_ok_count = 0 + integer :: lifecycle_event_count = 0 + integer :: event_step(NLC_EVENT_HISTORY_MAX) = 0 + integer :: event_increment(NLC_EVENT_HISTORY_MAX) = 0 + integer :: event_iteration(NLC_EVENT_HISTORY_MAX) = 0 + integer :: event_id_hist(NLC_EVENT_HISTORY_MAX) = NLC_EVENT_NONE + integer :: event_reason_id(NLC_EVENT_HISTORY_MAX) = NFAIL_NONE + +contains + + subroutine nl_lifecycle_reset() + lifecycle_step = 0 + lifecycle_increment = 0 + lifecycle_iteration = 0 + lifecycle_event_id = NLC_EVENT_NONE + lifecycle_reason_id = NFAIL_NONE + lifecycle_load_factor = ZERO + lifecycle_arc_residual = ZERO + lifecycle_path_appended = .false. + lifecycle_audit_status = NLC_AUDIT_NONE + audit_begin_trial_count = 0 + audit_rollback_req_count = 0 + audit_rollback_ok_count = 0 + audit_rollback_fail_count = 0 + audit_commit_ok_count = 0 + lifecycle_event_count = 0 + event_step = 0 + event_increment = 0 + event_iteration = 0 + event_id_hist = NLC_EVENT_NONE + event_reason_id = NFAIL_NONE + end subroutine nl_lifecycle_reset + + subroutine nl_lifecycle_event_name(event_id, event_name) + integer, intent(in) :: event_id + character(len=*), intent(out) :: event_name + + event_name = 'unknown' + select case (event_id) + case (NLC_EVENT_NONE) + event_name = 'none' + case (NLC_EVENT_INCREMENT_BEGIN) + event_name = 'increment-begin' + case (NLC_EVENT_TRIAL_BEGIN) + event_name = 'trial-begin' + case (NLC_EVENT_ITERATION_BEGIN) + event_name = 'iteration-begin' + case (NLC_EVENT_ITERATION_RESULT) + event_name = 'iteration-result' + case (NLC_EVENT_ACCEPT) + event_name = 'accept' + case (NLC_EVENT_REJECT) + event_name = 'reject' + case (NLC_EVENT_CUTBACK) + event_name = 'cutback' + case (NLC_EVENT_COMMIT) + event_name = 'commit' + case (NLC_EVENT_ROLLBACK) + event_name = 'rollback' + end select + end subroutine nl_lifecycle_event_name + + subroutine nl_lifecycle_audit_status_name(status_id, status_name) + integer, intent(in) :: status_id + character(len=*), intent(out) :: status_name + + status_name = 'unknown' + select case (status_id) + case (NLC_AUDIT_NONE) + status_name = 'none' + case (NLC_AUDIT_BEGIN_TRIAL) + status_name = 'begin-trial' + case (NLC_AUDIT_ROLLBACK_REQUESTED) + status_name = 'rollback-requested' + case (NLC_AUDIT_ROLLBACK_OK) + status_name = 'rollback-ok' + case (NLC_AUDIT_ROLLBACK_FAILED) + status_name = 'rollback-failed' + case (NLC_AUDIT_COMMIT_OK) + status_name = 'commit-ok' + end select + end subroutine nl_lifecycle_audit_status_name + + subroutine nl_lifecycle_begin_increment(step, increment) + integer, intent(in) :: step + integer, intent(in) :: increment + + call nl_lifecycle_record_event(step, increment, 0, & + NLC_EVENT_INCREMENT_BEGIN, NFAIL_NONE) + end subroutine nl_lifecycle_begin_increment + + subroutine nl_lifecycle_record_event(step, increment, iteration, event_id, & + reason_id) + integer, intent(in) :: step + integer, intent(in) :: increment + integer, intent(in) :: iteration + integer, intent(in) :: event_id + integer, intent(in), optional :: reason_id + integer :: slot + + lifecycle_step = step + lifecycle_increment = increment + lifecycle_iteration = iteration + lifecycle_event_id = event_id + if (present(reason_id)) then + lifecycle_reason_id = reason_id + else + lifecycle_reason_id = NFAIL_NONE + end if + if (event_id .eq. NLC_EVENT_INCREMENT_BEGIN) then + lifecycle_path_appended = .false. + end if + if (lifecycle_event_count .lt. NLC_EVENT_HISTORY_MAX) then + lifecycle_event_count = lifecycle_event_count + 1 + slot = lifecycle_event_count + else + slot = NLC_EVENT_HISTORY_MAX + end if + event_step(slot) = lifecycle_step + event_increment(slot) = lifecycle_increment + event_iteration(slot) = lifecycle_iteration + event_id_hist(slot) = lifecycle_event_id + event_reason_id(slot) = lifecycle_reason_id + end subroutine nl_lifecycle_record_event + + subroutine nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, & + audit_status, audit_status_name) + 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), optional :: audit_status + character(len=*), intent(out), optional :: audit_status_name + + step = lifecycle_step + increment = lifecycle_increment + iteration = lifecycle_iteration + event_id = lifecycle_event_id + call nl_lifecycle_event_name(lifecycle_event_id, event_name) + reason_id = lifecycle_reason_id + call convergence_failure_reason_name(lifecycle_reason_id, reason_name) + if (present(audit_status)) audit_status = lifecycle_audit_status + if (present(audit_status_name)) then + call nl_lifecycle_audit_status_name(lifecycle_audit_status, & + audit_status_name) + end if + end subroutine nl_lifecycle_get_snapshot + + subroutine nl_lifecycle_record_audit(status_id) + integer, intent(in) :: status_id + + lifecycle_audit_status = status_id + select case (status_id) + case (NLC_AUDIT_BEGIN_TRIAL) + audit_begin_trial_count = audit_begin_trial_count + 1 + case (NLC_AUDIT_ROLLBACK_REQUESTED) + audit_rollback_req_count = audit_rollback_req_count + 1 + case (NLC_AUDIT_ROLLBACK_OK) + audit_rollback_ok_count = audit_rollback_ok_count + 1 + case (NLC_AUDIT_ROLLBACK_FAILED) + audit_rollback_fail_count = audit_rollback_fail_count + 1 + case (NLC_AUDIT_COMMIT_OK) + audit_commit_ok_count = audit_commit_ok_count + 1 + end select + end subroutine nl_lifecycle_record_audit + + subroutine nl_lifecycle_get_audit(status_id, status_name, begin_trial_count, & + rollback_requested_count, & + rollback_ok_count, rollback_failed_count, & + commit_ok_count) + integer, intent(out) :: status_id + character(len=*), intent(out) :: status_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 + + status_id = lifecycle_audit_status + call nl_lifecycle_audit_status_name(status_id, status_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 + end subroutine nl_lifecycle_get_audit + + subroutine nl_lifecycle_restore(step, increment, iteration, event_id, & + reason_id, load_factor, arc_residual, & + path_appended, audit_status, & + begin_trial_count, & + rollback_requested_count, & + rollback_ok_count, rollback_failed_count, & + commit_ok_count) + integer, intent(in) :: step + integer, intent(in) :: increment + integer, intent(in) :: iteration + integer, intent(in) :: event_id + integer, intent(in) :: reason_id + real(rk), intent(in) :: load_factor + real(rk), intent(in) :: arc_residual + logical, intent(in) :: path_appended + integer, intent(in) :: audit_status + integer, intent(in) :: begin_trial_count + integer, intent(in) :: rollback_requested_count + integer, intent(in) :: rollback_ok_count + integer, intent(in) :: rollback_failed_count + integer, intent(in) :: commit_ok_count + + lifecycle_step = step + lifecycle_increment = increment + lifecycle_iteration = iteration + lifecycle_event_id = event_id + lifecycle_reason_id = reason_id + lifecycle_load_factor = load_factor + lifecycle_arc_residual = arc_residual + lifecycle_path_appended = path_appended + lifecycle_audit_status = audit_status + audit_begin_trial_count = begin_trial_count + audit_rollback_req_count = rollback_requested_count + audit_rollback_ok_count = rollback_ok_count + audit_rollback_fail_count = rollback_failed_count + audit_commit_ok_count = commit_ok_count + + lifecycle_event_count = 0 + event_step = 0 + event_increment = 0 + event_iteration = 0 + event_id_hist = NLC_EVENT_NONE + event_reason_id = NFAIL_NONE + if (event_id .ne. NLC_EVENT_NONE) then + lifecycle_event_count = 1 + event_step(1) = step + event_increment(1) = increment + event_iteration(1) = iteration + event_id_hist(1) = event_id + event_reason_id(1) = reason_id + end if + end subroutine nl_lifecycle_restore + + subroutine nl_lifecycle_record_arc_state(load_factor, arc_residual) + real(rk), intent(in) :: load_factor + real(rk), intent(in) :: arc_residual + + lifecycle_load_factor = load_factor + lifecycle_arc_residual = arc_residual + end subroutine nl_lifecycle_record_arc_state + + subroutine nl_lifecycle_mark_path_appended(appended) + logical, intent(in) :: appended + + lifecycle_path_appended = appended + end subroutine nl_lifecycle_mark_path_appended + + subroutine nl_lifecycle_get_arc_state(load_factor, arc_residual, & + path_appended) + real(rk), intent(out) :: load_factor + real(rk), intent(out) :: arc_residual + logical, intent(out) :: path_appended + + load_factor = lifecycle_load_factor + arc_residual = lifecycle_arc_residual + path_appended = lifecycle_path_appended + end subroutine nl_lifecycle_get_arc_state + + integer function nl_lifecycle_get_event_count() + nl_lifecycle_get_event_count = lifecycle_event_count + end function nl_lifecycle_get_event_count + + subroutine nl_lifecycle_get_event(index, step, increment, iteration, & + event_id, event_name, reason_id, & + reason_name) + integer, intent(in) :: index + 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 + + if (index .lt. 1 .or. index .gt. lifecycle_event_count) then + step = 0 + increment = 0 + iteration = 0 + event_id = NLC_EVENT_NONE + event_name = 'none' + reason_id = NFAIL_NONE + reason_name = 'none' + return + end if + + step = event_step(index) + increment = event_increment(index) + iteration = event_iteration(index) + event_id = event_id_hist(index) + call nl_lifecycle_event_name(event_id, event_name) + reason_id = event_reason_id(index) + call convergence_failure_reason_name(reason_id, reason_name) + end subroutine nl_lifecycle_get_event + +end module fem_nonlinear_lifecycle diff --git a/src/solver/fem_solver_newmark.f90 b/src/solver/fem_solver_newmark.f90 index c031d26..fbb9291 100644 --- a/src/solver/fem_solver_newmark.f90 +++ b/src/solver/fem_solver_newmark.f90 @@ -12,6 +12,10 @@ module fem_solver_newmark use fem_implicit_constraints, only: apply_nl_external_tangent, & apply_implicit_dirichlet_zero, apply_implicit_dirichlet, & apply_implicit_robin, apply_implicit_mpc + use fem_nonlinear_lifecycle, only: NLC_EVENT_ACCEPT, NLC_EVENT_COMMIT, & + NLC_EVENT_ITERATION_BEGIN, NLC_EVENT_ITERATION_RESULT, & + NLC_EVENT_REJECT, NLC_EVENT_TRIAL_BEGIN, & + nl_lifecycle_begin_increment, nl_lifecycle_record_event use fem_solver_implicit_support, only: begin_newmark_convergence, & record_convergence_iteration, record_convergence_correction, & record_line_search_metrics, mark_convergence_success, & @@ -273,8 +277,13 @@ contains call element_state_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(current_step + 1, current_step + 1, 0, & + NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE) do iter = 1, max_iter + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter, NLC_EVENT_ITERATION_BEGIN, & + NFAIL_NONE) call element_state_restore_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 @@ -288,6 +297,9 @@ contains if (res_norm .le. tol .or. res_norm / ref_norm .le. tol) then call finish_newmark_nl_success(kmat, external, damping_force, & converged, stat) + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter, NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) exit end if @@ -298,6 +310,9 @@ contains ref_norm, trial_res_norm, & trial_ref_norm, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter, NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) end do if (.not. converged) then @@ -307,11 +322,21 @@ contains call element_state_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter_used, NLC_EVENT_COMMIT, NFAIL_NONE) + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter_used, NLC_EVENT_ACCEPT, NFAIL_NONE) ierr = FEM_SUCCESS 900 continue if (ierr .ne. FEM_SUCCESS) then + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter_used, NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + iter_used, NLC_EVENT_REJECT, & + convergence_failure_reason_id) call newmark_nl_restore_state(u_start, v_start, a_start, vhalf_start) call element_state_abort_trial(state_ierr) end if @@ -369,6 +394,7 @@ contains 'nonlinear Newmark tolerance must be positive', ierr) return end if + call nl_lifecycle_begin_increment(current_step + 1, current_step + 1) call error_clear(ierr) end subroutine begin_newmark_nl_step diff --git a/src/solver/fem_solver_static_nonlinear.f90 b/src/solver/fem_solver_static_nonlinear.f90 index e3aa414..82c1abb 100644 --- a/src/solver/fem_solver_static_nonlinear.f90 +++ b/src/solver/fem_solver_static_nonlinear.f90 @@ -11,6 +11,11 @@ module fem_solver_static_nonlinear use fem_implicit_constraints, only: apply_nl_external_tangent, & collect_dirichlet_constraints use fem_output_csv, only: output_csv_write_path + use fem_nonlinear_lifecycle, only: NLC_EVENT_ACCEPT, NLC_EVENT_COMMIT, & + NLC_EVENT_CUTBACK, NLC_EVENT_ITERATION_BEGIN, & + NLC_EVENT_ITERATION_RESULT, NLC_EVENT_REJECT, NLC_EVENT_TRIAL_BEGIN, & + nl_lifecycle_begin_increment, nl_lifecycle_mark_path_appended, & + nl_lifecycle_record_arc_state, nl_lifecycle_record_event use fem_solver_implicit_support, only: zero_fixed_rhs, & begin_static_convergence, record_convergence_iteration, & record_convergence_correction, record_line_search_metrics, & @@ -350,6 +355,8 @@ contains if (nonlinear_continuation_method .ne. NLC_ARC_DISP) then load_factor = base_load_factor end if + call nl_lifecycle_record_event(current_step, current_step, iter_inc, & + NLC_EVENT_ACCEPT, NFAIL_NONE) call error_clear(ierr) end subroutine accept_static_increment @@ -440,6 +447,9 @@ contains convergence_failure_reason_id = NFAIL_NONE nlc_last_adjust = NLC_ADJ_CUTBACK nlc_next_target_dt = dt_try + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + convergence_iteration, & + NLC_EVENT_CUTBACK, NFAIL_NONE) call error_clear(ierr) end subroutine cutback_static_increment @@ -458,6 +468,10 @@ contains end if nlc_last_adjust = NLC_ADJ_FAILED nlc_next_target_dt = ZERO + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + convergence_iteration, & + NLC_EVENT_REJECT, & + convergence_failure_reason_id) end subroutine fail_static_increment subroutine implicit_solve_static_arc(final_time, num_increment, max_iter, & @@ -517,6 +531,10 @@ contains nlc_last_actual_dt = dt_try call record_static_arc_path(sub_target_time, ierr) if (ierr .ne. FEM_SUCCESS) return + call nl_lifecycle_mark_path_appended(.true.) + call nl_lifecycle_record_event(current_step, current_step, & + iter_inc, NLC_EVENT_ACCEPT, & + NFAIL_NONE) remaining_time = final_time - current_time call adapt_static_next_dt(iter_inc, dt_try, dt_min_eff, & dt_max_eff, remaining_time, dt_next) @@ -533,6 +551,9 @@ contains convergence_failure_reason_id = NFAIL_NONE nlc_last_adjust = NLC_ADJ_CUTBACK nlc_next_target_dt = dt_try + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + convergence_iteration, & + NLC_EVENT_CUTBACK, NFAIL_NONE) ierr = FEM_SUCCESS else convergence_status_code = CONVERGENCE_STATUS_FAILED @@ -544,6 +565,10 @@ contains end if nlc_last_adjust = NLC_ADJ_FAILED nlc_next_target_dt = ZERO + call nl_lifecycle_record_event(current_step + 1, current_step + 1, & + convergence_iteration, & + NLC_EVENT_REJECT, & + convergence_failure_reason_id) return end if end do @@ -785,8 +810,12 @@ contains sign_dir, residual, fref, du_res, & du_load, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(increment_id, increment_id, 0, & + NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE) do iter = 1, max_iter + call nl_lifecycle_record_event(increment_id, increment_id, iter, & + NLC_EVENT_ITERATION_BEGIN, NFAIL_NONE) call eval_static_arc_iteration(target_time, dt_inc, tol, iter, u_start, & lambda_start, load_scale, arc_radius, & arc_tol, residual, external, u_arc, & @@ -794,6 +823,10 @@ contains correction_norm, iter_used, res_norm, & ref_norm, converged, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_arc_state(load_factor, arc_residual) + call nl_lifecycle_record_event(increment_id, increment_id, iter, & + NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) if (converged) exit call apply_static_arc_correction(target_time, max_iter, tol, residual, & @@ -812,6 +845,8 @@ contains call element_state_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(increment_id, increment_id, iter_used, & + NLC_EVENT_COMMIT, NFAIL_NONE) call store_static_arc_direction(u_start, lambda_start, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 ierr = FEM_SUCCESS @@ -874,6 +909,8 @@ contains end if arc_tol = max(tol, tol * max(ONE, arc_radius * arc_radius)) call begin_static_convergence(increment_id, dt_inc) + call nl_lifecycle_begin_increment(increment_id, increment_id) + call nl_lifecycle_record_arc_state(load_factor, ZERO) call error_clear(ierr) end subroutine init_static_arc_state @@ -1390,8 +1427,12 @@ contains call element_state_begin_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(increment_id, increment_id, 0, & + NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE) do iter = 1, max_iter + call nl_lifecycle_record_event(increment_id, increment_id, iter, & + NLC_EVENT_ITERATION_BEGIN, NFAIL_NONE) call element_state_restore_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 @@ -1404,6 +1445,9 @@ contains if (res_norm .le. tol .or. res_norm / ref_norm .le. tol) then converged = .true. call mark_convergence_success() + call nl_lifecycle_record_event(increment_id, increment_id, iter, & + NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) if (allocated(freaction)) freaction = fint - external exit end if @@ -1415,6 +1459,9 @@ contains damping_alpha, trust_scale, & line_rejections, trust_mode, ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(increment_id, increment_id, iter, & + NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) end do if (.not. converged) then @@ -1424,6 +1471,8 @@ contains call element_state_commit_trial(ierr) if (ierr .ne. FEM_SUCCESS) go to 900 + call nl_lifecycle_record_event(increment_id, increment_id, iter_used, & + NLC_EVENT_COMMIT, NFAIL_NONE) ierr = FEM_SUCCESS @@ -1431,6 +1480,9 @@ contains if (ierr .ne. FEM_SUCCESS) then if (allocated(u_start)) u = u_start call mark_convergence_failure(CONV_FAIL_NONCONVERGENCE) + call nl_lifecycle_record_event(increment_id, increment_id, iter_used, & + NLC_EVENT_ITERATION_RESULT, & + convergence_failure_reason_id) call element_state_abort_trial(state_ierr) end if if (allocated(residual)) deallocate(residual) @@ -1473,6 +1525,7 @@ contains (nonlinear_continuation_method .eq. NLC_ARC_DISP .and. & nlc_trust_radius .gt. ZERO) call begin_static_convergence(increment_id, dt_inc) + call nl_lifecycle_begin_increment(increment_id, increment_id) end subroutine init_static_inc_state subroutine apply_static_newton_step(target_time, dt_inc, max_iter, tol, & diff --git a/tests/interface/test_c_api.c b/tests/interface/test_c_api.c index ef235a6..cd64524 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 != 5 || patch != 3) return 3; + if (major != 0 || minor != 6 || patch != 0) 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_cohesive_contact.f90 b/tests/module/test_cohesive_contact.f90 index 1fcf10a..862b59a 100644 --- a/tests/module/test_cohesive_contact.f90 +++ b/tests/module/test_cohesive_contact.f90 @@ -4,6 +4,8 @@ program test_cohesive_contact use fem_cohesive_law use fem_cohesive_state use fem_cohesive_metrics + use fem_nonlinear_lifecycle, only: nl_lifecycle_get_audit, & + nl_lifecycle_reset implicit none real(rk), parameter :: TOL = 1.0e-10_rk @@ -360,9 +362,17 @@ contains integer :: ierr integer :: ios integer :: unit_id + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count character(len=64) :: header + character(len=64) :: audit_name integer :: count_in + call nl_lifecycle_reset() call cohesive_state_reset() call cohesive_state_begin_trial() call cohesive_state_store_trial(1, 10, 2, 20, 3, 4, 0.2_rk, & @@ -393,6 +403,14 @@ contains energy, status) call check_close(damage, 0.2_rk, 99) call check_close(energy, 0.03_rk, 100) + call nl_lifecycle_get_audit(audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + if (begin_trial_count .lt. 2) call fail(119) + if (rollback_requested_count .ne. 1) call fail(120) + if (rollback_ok_count .ne. 1) call fail(121) + if (rollback_failed_count .ne. 0) call fail(122) + if (commit_ok_count .lt. 2) call fail(123) call cohesive_state_store_trial(1, 10, 2, 20, 3, 5, ONE, & 0.10_rk, 0.20_rk, 0.50_rk, & diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index 337dc89..170aa4f 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -14,6 +14,8 @@ program test_contact contact_multiplier_begin_trial, contact_multiplier_store_trial, & contact_multiplier_commit, contact_multiplier_rollback, & contact_multiplier_old, contact_multiplier_stats + use fem_nonlinear_lifecycle, only: NLC_AUDIT_ROLLBACK_OK, & + nl_lifecycle_get_audit, nl_lifecycle_reset use fem_api use fem_assembly_csr use fem_sparse_csr @@ -43,10 +45,18 @@ contains integer :: ierr integer :: slot_count integer :: active_count + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count real(rk) :: old_lambda real(rk) :: max_lambda real(rk) :: max_gap + character(len=64) :: audit_name + call nl_lifecycle_reset() call contact_multiplier_reset() call contact_multiplier_begin_trial() call contact_multiplier_store_trial(1, 10, 2, 20, 3, 1, 5.0_rk, & @@ -70,6 +80,15 @@ contains call contact_multiplier_rollback() call contact_multiplier_old(1, 10, 2, 20, 3, 1, old_lambda) call check_close(old_lambda, 5.0_rk, 9008) + call nl_lifecycle_get_audit(audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + if (audit_status .ne. NLC_AUDIT_ROLLBACK_OK) call fail(9009) + if (begin_trial_count .lt. 2) call fail(9010) + if (rollback_requested_count .ne. 1) call fail(9011) + if (rollback_ok_count .ne. 1) call fail(9012) + if (rollback_failed_count .ne. 0) call fail(9013) + if (commit_ok_count .lt. 1) call fail(9014) call contact_multiplier_reset() end subroutine check_multiplier_history diff --git a/tests/module/test_nonlinear_lifecycle.f90 b/tests/module/test_nonlinear_lifecycle.f90 new file mode 100644 index 0000000..2c07c0f --- /dev/null +++ b/tests/module/test_nonlinear_lifecycle.f90 @@ -0,0 +1,221 @@ +program test_nonlinear_lifecycle + use fem_precision + 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_nonlinear_lifecycle + implicit none + + call check_event_names() + call check_empty_snapshot() + call check_recorded_snapshot() + call check_begin_increment() + call check_audit_core() + call check_api_snapshot() + +contains + + subroutine check_event_names() + character(len=64) :: name + + call nl_lifecycle_event_name(NLC_EVENT_NONE, name) + if (trim(name) .ne. 'none') call fail(10) + call nl_lifecycle_event_name(NLC_EVENT_INCREMENT_BEGIN, name) + if (trim(name) .ne. 'increment-begin') call fail(11) + call nl_lifecycle_event_name(NLC_EVENT_TRIAL_BEGIN, name) + if (trim(name) .ne. 'trial-begin') call fail(12) + call nl_lifecycle_event_name(NLC_EVENT_ITERATION_BEGIN, name) + if (trim(name) .ne. 'iteration-begin') call fail(120) + call nl_lifecycle_event_name(NLC_EVENT_ITERATION_RESULT, name) + if (trim(name) .ne. 'iteration-result') call fail(13) + call nl_lifecycle_event_name(NLC_EVENT_ACCEPT, name) + if (trim(name) .ne. 'accept') call fail(14) + call nl_lifecycle_event_name(NLC_EVENT_REJECT, name) + if (trim(name) .ne. 'reject') call fail(15) + call nl_lifecycle_event_name(NLC_EVENT_CUTBACK, name) + if (trim(name) .ne. 'cutback') call fail(16) + call nl_lifecycle_event_name(NLC_EVENT_COMMIT, name) + if (trim(name) .ne. 'commit') call fail(17) + call nl_lifecycle_event_name(NLC_EVENT_ROLLBACK, name) + if (trim(name) .ne. 'rollback') call fail(18) + call nl_lifecycle_event_name(-999, name) + if (trim(name) .ne. 'unknown') call fail(19) + end subroutine check_event_names + + subroutine check_empty_snapshot() + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + real(rk) :: load_factor + real(rk) :: arc_residual + logical :: path_appended + + call nl_lifecycle_reset() + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + call nl_lifecycle_get_arc_state(load_factor, arc_residual, path_appended) + if (nl_lifecycle_get_event_count() .ne. 0) call fail(29) + if (step .ne. 0) call fail(30) + if (increment .ne. 0) call fail(31) + if (iteration .ne. 0) call fail(32) + if (event_id .ne. NLC_EVENT_NONE) call fail(33) + if (trim(event_name) .ne. 'none') call fail(34) + if (reason_id .ne. NFAIL_NONE) call fail(35) + if (trim(reason_name) .ne. 'none') call fail(36) + if (abs(load_factor) .gt. 1.0e-14_rk) call fail(37) + if (abs(arc_residual) .gt. 1.0e-14_rk) call fail(38) + if (path_appended) call fail(39) + end subroutine check_empty_snapshot + + subroutine check_recorded_snapshot() + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + call nl_lifecycle_record_event(2, 3, 4, NLC_EVENT_TRIAL_BEGIN, & + NFAIL_LINE_SEARCH) + if (nl_lifecycle_get_event_count() .ne. 1) call fail(49) + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + if (step .ne. 2) call fail(50) + if (increment .ne. 3) call fail(51) + if (iteration .ne. 4) call fail(52) + if (event_id .ne. NLC_EVENT_TRIAL_BEGIN) call fail(53) + if (trim(event_name) .ne. 'trial-begin') call fail(54) + if (reason_id .ne. NFAIL_LINE_SEARCH) call fail(55) + if (trim(reason_name) .ne. 'line-search-failure') call fail(56) + call nl_lifecycle_get_event(1, step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + if (step .ne. 2) call fail(57) + if (increment .ne. 3) call fail(58) + if (iteration .ne. 4) call fail(59) + if (event_id .ne. NLC_EVENT_TRIAL_BEGIN) call fail(60) + if (trim(event_name) .ne. 'trial-begin') call fail(61) + end subroutine check_recorded_snapshot + + subroutine check_begin_increment() + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + call nl_lifecycle_begin_increment(5, 6) + if (nl_lifecycle_get_event_count() .ne. 2) call fail(69) + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + if (step .ne. 5) call fail(70) + if (increment .ne. 6) call fail(71) + if (iteration .ne. 0) call fail(72) + if (event_id .ne. NLC_EVENT_INCREMENT_BEGIN) call fail(73) + if (trim(event_name) .ne. 'increment-begin') call fail(74) + if (reason_id .ne. NFAIL_NONE) call fail(75) + if (trim(reason_name) .ne. 'none') call fail(76) + end subroutine check_begin_increment + + subroutine check_audit_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 + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + + call nl_lifecycle_reset() + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name) + if (audit_status .ne. NLC_AUDIT_NONE) call fail(80) + if (trim(audit_name) .ne. 'none') call fail(81) + + call nl_lifecycle_audit_status_name(NLC_AUDIT_ROLLBACK_FAILED, & + audit_name) + if (trim(audit_name) .ne. 'rollback-failed') call fail(82) + call nl_lifecycle_audit_status_name(-999, audit_name) + if (trim(audit_name) .ne. 'unknown') call fail(83) + + call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL) + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED) + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK) + call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + call nl_lifecycle_get_audit(audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + if (audit_status .ne. NLC_AUDIT_COMMIT_OK) call fail(84) + if (trim(audit_name) .ne. 'commit-ok') call fail(85) + if (begin_trial_count .ne. 1) call fail(86) + if (rollback_requested_count .ne. 1) call fail(87) + if (rollback_ok_count .ne. 1) call fail(88) + if (rollback_failed_count .ne. 1) call fail(89) + if (commit_ok_count .ne. 1) call fail(900) + + call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, audit_status, audit_name) + if (audit_status .ne. NLC_AUDIT_COMMIT_OK) call fail(901) + if (trim(audit_name) .ne. 'commit-ok') call fail(902) + end subroutine check_audit_core + + subroutine check_api_snapshot() + integer :: ierr + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + call fem_initialize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(90) + call fem_get_nl_lifecycle_snapshot(step, increment, iteration, & + event_id, event_name, reason_id, reason_name, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(91) + if (step .ne. 0) call fail(92) + if (increment .ne. 0) call fail(93) + if (iteration .ne. 0) call fail(94) + if (event_id .ne. NLC_EVENT_NONE) call fail(95) + if (trim(event_name) .ne. 'none') call fail(96) + + call nl_lifecycle_record_event(7, 8, 9, NLC_EVENT_CUTBACK, & + NFAIL_MIN_STEP) + call fem_get_nl_lifecycle_snapshot(step, increment, iteration, & + event_id, event_name, reason_id, reason_name, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(97) + if (step .ne. 7) call fail(98) + if (increment .ne. 8) call fail(99) + if (iteration .ne. 9) call fail(100) + if (event_id .ne. NLC_EVENT_CUTBACK) call fail(101) + if (trim(event_name) .ne. 'cutback') call fail(102) + if (reason_id .ne. NFAIL_MIN_STEP) call fail(103) + if (trim(reason_name) .ne. 'minimum-step-exhausted') call fail(104) + + call fem_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(105) + end subroutine check_api_snapshot + + subroutine fail(code) + integer, intent(in) :: code + write(*,*) 'test_nonlinear_lifecycle failed:', code + stop 1 + end subroutine fail + +end program test_nonlinear_lifecycle diff --git a/tests/module/test_particle_step.f90 b/tests/module/test_particle_step.f90 index 02322f3..9a3cb9b 100644 --- a/tests/module/test_particle_step.f90 +++ b/tests/module/test_particle_step.f90 @@ -5,6 +5,8 @@ program test_particle_step use fem_particle_contact use fem_particle_step use fem_particle_audit + use fem_nonlinear_lifecycle, only: nl_lifecycle_get_audit, & + nl_lifecycle_reset implicit none real(rk), parameter :: TOL = 1.0e-10_rk @@ -217,7 +219,14 @@ contains integer :: ierr integer :: status integer :: checked_steps + integer :: audit_status + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count character(len=16) :: name + character(len=64) :: audit_name real(rk) :: mass_error real(rk) :: mom_change real(rk) :: energy_change @@ -242,8 +251,14 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(144) call paudit_reset(audit) + call nl_lifecycle_reset() call paudit_step(diag, 1.0e-12_rk, 10.0_rk, 10.0_rk, audit, ierr) if (ierr .ne. FEM_SUCCESS) call fail(145) + call nl_lifecycle_get_audit(audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count) + if (commit_ok_count .ne. 1) call fail(157) + if (rollback_failed_count .ne. 0) call fail(158) call paudit_overlap(diag, 0.50_rk, 0.3_rk, 0.6_rk, audit, ierr) if (ierr .ne. FEM_SUCCESS) call fail(146) if (audit%status .ne. PAUDIT_WARN) call fail(147) diff --git a/tests/module/test_restart.f90 b/tests/module/test_restart.f90 index e1ebe52..4a7d2f8 100644 --- a/tests/module/test_restart.f90 +++ b/tests/module/test_restart.f90 @@ -2,6 +2,15 @@ program test_restart use fem_precision use fem_error use fem_api + use fem_api_diagnostics, only: fem_get_nl_lifecycle_snapshot, & + 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, & + nl_lifecycle_reset, & + nl_lifecycle_begin_increment, nl_lifecycle_record_event, & + nl_lifecycle_record_audit, nl_lifecycle_record_arc_state, & + nl_lifecycle_mark_path_appended use fem_shell_rotation, only: shell_rotation_ensure, & shell_rotation_set_committed, shell_rotation_get_committed, & shell_rotation_rotate_vector @@ -24,6 +33,10 @@ program test_restart 'build-wsl-debug/contact_multiplier_restart.frs' character(len=*), parameter :: ROT_RESTART_FILE = & 'build-wsl-debug/shell_rotation_restart.frs' + character(len=*), parameter :: LIFECYCLE_RESTART_FILE = & + 'build-wsl-debug/lifecycle_restart.frs' + character(len=*), parameter :: LEGACY_LIFECYCLE_RESTART_FILE = & + 'build-wsl-debug/lifecycle_restart_legacy.frs' integer :: ierr integer :: ref_step @@ -59,6 +72,8 @@ program test_restart if (ierr .ne. FEM_SUCCESS) call fail(22) call check_shell_rotation_restart(ierr) if (ierr .ne. FEM_SUCCESS) call fail(40) + call check_lifecycle_restart(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(50) call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(12) @@ -460,6 +475,187 @@ contains call check_close(rotated(3), cos(theta), 44) end subroutine check_shell_rotation_restart + subroutine check_lifecycle_restart(ierr) + integer, intent(out) :: ierr + 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 + real(rk) :: load_before + real(rk) :: arc_before + real(rk) :: load_after + real(rk) :: arc_after + logical :: path_before + logical :: path_after + + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + call loaded_step(ierr) + if (ierr .ne. FEM_SUCCESS) return + + call nl_lifecycle_reset() + call nl_lifecycle_begin_increment(7, 2) + call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK) + call nl_lifecycle_record_arc_state(1.25_rk, 2.5e-3_rk) + call nl_lifecycle_mark_path_appended(.true.) + call nl_lifecycle_record_event(7, 2, 3, NLC_EVENT_COMMIT, NFAIL_NONE) + call nl_lifecycle_record_event(7, 2, 3, NLC_EVENT_ACCEPT, NFAIL_NONE) + 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 + if (event_before .ne. NLC_EVENT_ACCEPT) call fail(501) + if (audit_before .ne. NLC_AUDIT_COMMIT_OK) call fail(502) + if (commit_before .ne. 1) call fail(503) + + call fem_write_restart(LIFECYCLE_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(520) + call write_restart_without_lifecycle(LIFECYCLE_RESTART_FILE, & + LEGACY_LIFECYCLE_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(521) + call nl_lifecycle_reset() + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_read_restart(LIFECYCLE_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(522) + 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 + + if (step_after .ne. step_before) call fail(504) + if (increment_after .ne. increment_before) call fail(505) + if (iteration_after .ne. iteration_before) call fail(506) + if (event_after .ne. event_before) call fail(507) + if (reason_after .ne. reason_before) call fail(508) + if (audit_after .ne. audit_before) call fail(509) + if (begin_after .ne. begin_before) call fail(510) + if (rollback_req_after .ne. rollback_req_before) call fail(511) + if (rollback_ok_after .ne. rollback_ok_before) call fail(512) + if (rollback_fail_after .ne. rollback_fail_before) call fail(513) + if (commit_after .ne. commit_before) call fail(514) + call check_close(load_after, load_before, 515) + call check_close(arc_after, arc_before, 516) + if (path_after .neqv. path_before) call fail(517) + + call nl_lifecycle_reset() + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_read_restart(LEGACY_LIFECYCLE_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail_with_last_error(523) + 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 + if (event_after .ne. NLC_EVENT_NONE) call fail(518) + if (audit_after .ne. NLC_AUDIT_NONE) call fail(519) + end subroutine check_lifecycle_restart + + subroutine write_restart_without_lifecycle(source_file, target_file, ierr) + character(len=*), intent(in) :: source_file + character(len=*), intent(in) :: target_file + integer, intent(out) :: ierr + character(len=4096) :: line + character(len=32) :: tag + integer :: read_unit + integer :: write_unit + integer :: ios_read + integer :: ios_write + integer :: ios_tag + + read_unit = 72 + write_unit = 73 + open(unit=read_unit, file=trim(source_file), status='old', & + action='read', iostat=ios_read) + if (ios_read .ne. 0) then + ierr = FEM_ERR_OUTPUT + return + end if + open(unit=write_unit, file=trim(target_file), status='replace', & + action='write', iostat=ios_write) + if (ios_write .ne. 0) then + close(read_unit) + ierr = FEM_ERR_OUTPUT + return + end if + + do + read(read_unit,'(A)',iostat=ios_read) line + if (ios_read .ne. 0) exit + tag = ' ' + read(line,*,iostat=ios_tag) tag + if (ios_tag .eq. 0 .and. trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') cycle + write(write_unit,'(A)',iostat=ios_write) trim(line) + if (ios_write .ne. 0) exit + end do + + close(read_unit) + close(write_unit) + if (ios_write .ne. 0) then + ierr = FEM_ERR_OUTPUT + else if (ios_read .lt. 0) then + ierr = FEM_SUCCESS + else + ierr = FEM_ERR_OUTPUT + end if + end subroutine write_restart_without_lifecycle + + subroutine capture_lifecycle(step, increment, iteration, event_id, & + reason_id, audit_status, begin_trial_count, & + rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, & + load_factor, arc_residual, path_appended, ierr) + integer, intent(out) :: step + integer, intent(out) :: increment + integer, intent(out) :: iteration + integer, intent(out) :: event_id + integer, intent(out) :: reason_id + integer, intent(out) :: audit_status + 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 + real(rk), intent(out) :: load_factor + real(rk), intent(out) :: arc_residual + logical, intent(out) :: path_appended + integer, intent(out) :: ierr + character(len=64) :: event_name + character(len=64) :: reason_name + character(len=64) :: audit_name + + call fem_get_nl_lifecycle_snapshot(step, increment, iteration, event_id, & + event_name, reason_id, reason_name, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_nl_lifecycle_arc(load_factor, arc_residual, path_appended, & + ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_nl_lifecycle_audit(audit_status, audit_name, & + begin_trial_count, rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, ierr) + end subroutine capture_lifecycle + subroutine prepare_contact_model(ierr) integer, intent(out) :: ierr @@ -516,6 +712,17 @@ contains if (abs(actual - expected) .gt. 1.0e-8_rk * scale) call fail(code) end subroutine check_close + subroutine fail_with_last_error(code) + integer, intent(in) :: code + integer :: ierr + integer :: err_code + character(len=256) :: message + + call fem_get_last_error(err_code, message, ierr) + write(*,*) 'last error:', err_code, trim(message) + call fail(code) + end subroutine fail_with_last_error + subroutine fail(code) integer, intent(in) :: code diff --git a/tests/module/test_solver_implicit.f90 b/tests/module/test_solver_implicit.f90 index 3a64f7d..004450a 100644 --- a/tests/module/test_solver_implicit.f90 +++ b/tests/module/test_solver_implicit.f90 @@ -10,6 +10,7 @@ program test_solver_implicit use fem_linear_solver_cg, only: linear_solver_configure, & linear_solver_get_diagnostics, linear_solver_get_settings, & linear_solver_get_stats, linear_solver_get_fail_info + use fem_nonlinear_lifecycle use fem_sparse_csr_diagnostics, only: CSR_CLASS_GENERAL, & CSR_CLASS_SPD_CAND implicit none @@ -355,6 +356,7 @@ contains current_time = ZERO rayleigh_alpha_mass = ZERO rayleigh_beta_stiffness = ZERO + call nl_lifecycle_reset() call implicit_newmark_nonlinear_step(0.1_rk, 0.25_rk, 0.5_rk, & 50, 1.0e-12_rk, iter, res_norm, ierr) @@ -368,6 +370,12 @@ contains call check_close(convergence_cons_resid_norm, ZERO, 5503) call check_close(convergence_arc_resid_norm, ZERO, 5504) if (convergence_material_fail_count .ne. 0) call fail(5505) + call check_lifecycle_event(1, NLC_EVENT_INCREMENT_BEGIN, NFAIL_NONE, 5610) + call check_lifecycle_event(2, NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE, 5611) + call check_lifecycle_event(3, NLC_EVENT_ITERATION_BEGIN, NFAIL_NONE, 5612) + if (lifecycle_count_event(NLC_EVENT_ITERATION_RESULT) .le. 0) & + call fail(5613) + call check_lifecycle_last(NLC_EVENT_ACCEPT, NFAIL_NONE, 5614) dof = dof_id(1,2) call check_close(u(dof), 15.0_rk / 68.0_rk, 95) @@ -531,6 +539,7 @@ contains static_min_increment = 0.2_rk cutback_factor = 0.5_rk current_time = ZERO + call nl_lifecycle_reset() call implicit_solve_nonlinear_static(ONE, 1, 1, 1.0e-30_rk, & iter, res_norm, ierr) @@ -555,6 +564,9 @@ contains 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_close(convergence_last_accepted_time, ZERO, 163) + if (lifecycle_count_event(NLC_EVENT_CUTBACK) .ne. 2) call fail(5605) + call check_lifecycle_last(NLC_EVENT_REJECT, NFAIL_MIN_STEP, 5606) + call check_lifecycle_audit_min(1, 1, 1, 0, 0, 5630) allow_step_cutback = old_cutback max_cutback = old_max_cutback @@ -576,6 +588,7 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(5167) current_time = ZERO + call nl_lifecycle_reset() call implicit_newmark_nonlinear_step(0.1_rk, 0.25_rk, 0.5_rk, & 1, 1.0e-30_rk, iter, res_norm, ierr) @@ -588,6 +601,7 @@ contains call fail(5171) call check_reason_name(NFAIL_NONCONVERGENCE, & 'nonlinear-nonconvergence', 5172) + call check_lifecycle_last(NLC_EVENT_REJECT, NFAIL_NONCONVERGENCE, 5615) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(5173) @@ -624,6 +638,7 @@ contains static_min_increment = 0.01_rk static_max_increment = 0.5_rk current_time = ZERO + call nl_lifecycle_reset() call implicit_solve_nonlinear_static(ONE, 4, 50, 1.0e-12_rk, & iter, res_norm, ierr) @@ -645,6 +660,13 @@ contains call check_close(convergence_cons_resid_norm, ZERO, 5513) call check_close(convergence_arc_resid_norm, ZERO, 5514) if (convergence_material_fail_count .ne. 0) call fail(5515) + call check_lifecycle_event(1, NLC_EVENT_INCREMENT_BEGIN, NFAIL_NONE, 5600) + call check_lifecycle_event(2, NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE, 5601) + call check_lifecycle_event(3, NLC_EVENT_ITERATION_BEGIN, NFAIL_NONE, 5602) + if (lifecycle_count_event(NLC_EVENT_ITERATION_RESULT) .le. 0) & + call fail(5603) + call check_lifecycle_last(NLC_EVENT_ACCEPT, NFAIL_NONE, 5604) + call check_lifecycle_audit_min(1, 0, 0, 0, 1, 5631) nonlinear_continuation_method = old_method nlc_target_newton = old_target @@ -754,6 +776,7 @@ contains load_factor = ONE current_time = ZERO current_step = 0 + call nl_lifecycle_reset() call implicit_solve_nonlinear_static(ONE, 1, 50, 1.0e-12_rk, & iter, res_norm, ierr) if (ierr .ne. FEM_SUCCESS) call fail(271) @@ -771,6 +794,8 @@ contains CONVERGENCE_STATUS_CONVERGED) call fail(281) if (nlc_path_int(NLC_PATH_I_FAILURE_CODE, 1) .ne. CONV_FAIL_NONE) & call fail(282) + call check_lifecycle_last(NLC_EVENT_ACCEPT, NFAIL_NONE, 5620) + call check_lifecycle_arc(ONE, 1.0e-8_rk, .true., 5621) nonlinear_continuation_method = old_method nlc_arc_length_radius = old_arc_radius @@ -1331,9 +1356,107 @@ contains if (trim(actual) .ne. trim(expected)) call fail(code) end subroutine check_reason_name + subroutine check_lifecycle_event(index, expected_event, expected_reason, & + code) + integer, intent(in) :: index + integer, intent(in) :: expected_event + integer, intent(in) :: expected_reason + integer, intent(in) :: code + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + call nl_lifecycle_get_event(index, step, increment, iteration, event_id, & + event_name, reason_id, reason_name) + if (event_id .ne. expected_event) call fail(code) + if (reason_id .ne. expected_reason) call fail(code + 100) + end subroutine check_lifecycle_event + + subroutine check_lifecycle_last(expected_event, expected_reason, code) + integer, intent(in) :: expected_event + integer, intent(in) :: expected_reason + integer, intent(in) :: code + integer :: count + + count = nl_lifecycle_get_event_count() + if (count .le. 0) call fail(code) + call check_lifecycle_event(count, expected_event, expected_reason, code) + end subroutine check_lifecycle_last + + subroutine check_lifecycle_arc(expected_load, max_arc_residual, & + expected_appended, code) + real(rk), intent(in) :: expected_load + real(rk), intent(in) :: max_arc_residual + logical, intent(in) :: expected_appended + integer, intent(in) :: code + real(rk) :: load_snapshot + real(rk) :: arc_residual + logical :: path_appended + + call nl_lifecycle_get_arc_state(load_snapshot, arc_residual, & + path_appended) + call check_close(load_snapshot, expected_load, code) + if (abs(arc_residual) .gt. max_arc_residual) call fail(code + 1) + if (path_appended .neqv. expected_appended) call fail(code + 2) + end subroutine check_lifecycle_arc + + subroutine check_lifecycle_audit_min(min_begin, min_rollback_requested, & + min_rollback_ok, max_rollback_failed, & + min_commit_ok, code) + integer, intent(in) :: min_begin + integer, intent(in) :: min_rollback_requested + integer, intent(in) :: min_rollback_ok + integer, intent(in) :: max_rollback_failed + integer, intent(in) :: min_commit_ok + integer, intent(in) :: code + integer :: status_id + integer :: begin_trial_count + integer :: rollback_requested_count + integer :: rollback_ok_count + integer :: rollback_failed_count + integer :: commit_ok_count + character(len=64) :: status_name + + call nl_lifecycle_get_audit(status_id, status_name, begin_trial_count, & + rollback_requested_count, rollback_ok_count, rollback_failed_count, & + commit_ok_count) + if (begin_trial_count .lt. min_begin) call fail(code) + if (rollback_requested_count .lt. min_rollback_requested) & + call fail(code + 1) + if (rollback_ok_count .lt. min_rollback_ok) call fail(code + 2) + if (rollback_failed_count .gt. max_rollback_failed) call fail(code + 3) + if (commit_ok_count .lt. min_commit_ok) call fail(code + 4) + end subroutine check_lifecycle_audit_min + + integer function lifecycle_count_event(expected_event) + integer, intent(in) :: expected_event + 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 = 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) then + lifecycle_count_event = lifecycle_count_event + 1 + end if + end do + end function lifecycle_count_event + subroutine check_path_breakdown_header(code_base) integer, intent(in) :: code_base character(len=2048) :: header + character(len=2048) :: row_line integer :: ierr integer :: ios integer :: unit_id @@ -1350,15 +1473,34 @@ contains status='old', action='read', iostat=ios) if (ios .ne. 0) call fail(code_base + 2) read(unit_id,'(A)',iostat=ios) header - close(unit_id) if (ios .ne. 0) call fail(code_base + 3) - if (index(header, 'residual_total') .le. 0) call fail(code_base + 4) - if (index(header, 'residual_force') .le. 0) call fail(code_base + 5) - if (index(header, 'residual_contact') .le. 0) call fail(code_base + 6) - if (index(header, 'residual_constraint') .le. 0) call fail(code_base + 7) - if (index(header, 'residual_arc') .le. 0) call fail(code_base + 8) + read(unit_id,'(A)',iostat=ios) row_line + close(unit_id) + if (ios .ne. 0) call fail(code_base + 4) + if (index(header, 'residual_total') .le. 0) call fail(code_base + 5) + if (index(header, 'residual_force') .le. 0) call fail(code_base + 6) + if (index(header, 'residual_contact') .le. 0) call fail(code_base + 7) + if (index(header, 'residual_constraint') .le. 0) call fail(code_base + 8) + if (index(header, 'residual_arc') .le. 0) call fail(code_base + 9) if (index(header, 'material_failure_count') .le. 0) & - call fail(code_base + 9) + call fail(code_base + 10) + if (index(header, 'lifecycle_event_id') .le. 0) & + call fail(code_base + 11) + if (index(header, 'lifecycle_event_name') .le. 0) & + call fail(code_base + 12) + if (index(header, 'lifecycle_audit_status') .le. 0) & + call fail(code_base + 13) + if (index(header, 'lifecycle_audit_name') .le. 0) & + call fail(code_base + 14) + if (index(header, 'lifecycle_increment') .le. 0) & + call fail(code_base + 15) + if (index(header, 'lifecycle_iteration') .le. 0) & + call fail(code_base + 16) + if (index(header, 'lifecycle_accept_count') .le. 0) & + 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) end subroutine check_path_breakdown_header subroutine check_solver_diag(code_base) diff --git a/tests/performance/perf_p1.f90 b/tests/performance/perf_p1.f90 index b566f85..82a4c9e 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. 5 .or. patch .ne. 3) then + if (major .ne. 0 .or. minor .ne. 6 .or. patch .ne. 0) 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 019be8e..562b149 100644 --- a/tests/unit/test_smoke.f90 +++ b/tests/unit/test_smoke.f90 @@ -93,8 +93,8 @@ program test_smoke call fem_get_version(major, minor, patch, ierr) if (ierr .ne. 0) stop 2 if (major .ne. 0) stop 3 - if (minor .ne. 5) stop 4 - if (patch .ne. 3) stop 5 + if (minor .ne. 6) stop 4 + if (patch .ne. 0) 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 0874be7..b39a968 100644 --- a/todo.md +++ b/todo.md @@ -1,377 +1,344 @@ -# FemLite 0.5.3 TODO +# FemLite 0.6.0 TODO -Source plan: `docs/v5.3_development_plan.md` +Source plan: `docs/v6.0_development_plan.md` Version goal: ```text -FemLite 0.5.3 = 接触与非线性诊断加固版 +FemLite 0.6.0 = unified nonlinear state machine and lifecycle foundation ``` Boundary: -- Do not add broad new feature families in 0.5.3. -- Do not claim complete industrial AL/mortar consistent tangent. -- Do not move deferred shell preload buckling, high-order solid `K_G`, mixed-control - Riks, cohesive contact mainline, nonzero harmonic cyclic, DEM subcycling or - production roll forming into the 0.5.3 must-complete list. -- Every new diagnostic field must be consumed by a test, checker or report audit. +- The fifth-version closure boundary is lifted for future planning, but 0.6.0 + should still remain a controlled loop. +- 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. +- Keep TODO item size uniform: each task should add one observable contract and + one focused verification path. ## Execution Order -1. NL-1: failure reason taxonomy. -2. LS-1: linear solver nonlinear-diagnostic bridge. -3. CT-1: contact state count standardization. -4. CT-2: contact residual diagnostics. -5. CT-3: mortar/friction tangent audit enhancement. -6. CT-4: OpenMP contact path consistency enhancement. -7. NL-2: nonlinear residual breakdown output. -8. DOC-1: documentation and benchmark matrix synchronization. -9. REL-1: 0.5.3 build/regression/version close-out. +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. ## Detailed Execution Map | TODO | Code targets | Output/API contract | Test/checker target | Not in scope | |---|---|---|---|---| -| 0.5.3-1 | `src/base/fem_control.f90`, `src/base/fem_api_diagnostics.f90`, nonlinear solver failure markers | Add stable `NFAIL_*` id/name while keeping existing `CONV_FAIL_*` status codes | `solver_implicit`, `implicit_inp` | Rewrite cutback/Newton algorithms | -| 0.5.3-2 | `src/solver/fem_solver_implicit_support.f90`, `src/solver/fem_linear_solver_dispatch.f90` | Map linear-solver failure diagnostics into nonlinear reason id/name | `linear_solver_cg`, `solver_implicit` | Add new linear solver backends | -| 0.5.3-3 | `src/boundary/fem_contact_history.f90`, `src/boundary/fem_contact_multiplier.f90`, contact report writers | Standard contact state counts: open/stick/slip/restick/separating/failed projection | `restart`, contact report module tests | Full contact state-machine rewrite | -| 0.5.3-4 | Contact search/history diagnostics and contact CSV/report output | Add max penetration, mean gap, gap L2, failed projection and active-set flip fields | `contact_mortar_report`, compression checker | Change contact enforcement method | -| 0.5.3-5 | Friction history diagnostics and sliding/contact report output | Add slip increment/residual and tangential residual fields | friction/contact module tests, sliding checker | Retune friction law | -| 0.5.3-6 | Multiplier and mortar AL diagnostics/report paths | Add multiplier residual and augmentation/update count fields | `contact_multiplier_report`, `restart` | Industrial AL/mortar consistent tangent rewrite | -| 0.5.3-7 | Mortar tangent audit helpers/output | Split normal tangent finite-difference audit fields | `contact_mortar_tangent` | Replace production normal-contact tangent | -| 0.5.3-8 | Friction tangent audit helpers/output | Split stick/slip tangent finite-difference audit fields | `contact_mortar_tangent` | Replace production friction tangent | -| 0.5.3-9 | `perf_contact_pair` and `tools/testing/check_perf_contact_pair_omp.py` | Compare deterministic force/tangent/cache/state/residual fields across threads | `perf_contact_pair_omp_consistency` | Treat timing differences as failures | -| 0.5.3-10 | Nonlinear static/Newmark diagnostic storage | Store total/force/contact/constraint/arc/material residual breakdown | `solver_implicit` | Add new nonlinear control family | -| 0.5.3-11 | Path CSV/contact summary writers and schema comments | Write residual breakdown columns without removing old columns | continuation/contact checkers | Break old CSV consumers | -| 0.5.3-12 | Restart writer/reader and restart contact audit test | Verify contact diagnostics before/after restart after an accepted increment | `restart`, compact INP restart if needed | Redesign restart format | -| 0.5.3-13 | Contact example checkers and README field notes | Check explainable diagnostic fields in compression/sliding/shell contact examples | four contact benchmark CTest entries | Overfit exact nonlinear values | -| 0.5.3-14 | V5 docs, interface docs, manuals, example docs | Document new diagnostic boundary and deferred items | wording `rg` checks | Claim full industrial AL/mortar tangent | -| 0.5.3-15 | V5 matrix/report/version files | Close 0.5.3 only after green targeted and V5 acceptance tests | build, targeted tests, V5 acceptance, `git diff --check` | Release/version bump before tests pass | +| 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 | ## Implementation Rules -- Work in the execution order above; do not mark a TODO done until its tests or - checker target consumes the new field. -- Prefer additive fields and thin accessors over changing existing public - signatures. -- If a task exposes multiple incompatible implementation routes, pause and ask +- 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. - If a later task needs a field created by an earlier task, finish and test the - earlier task first rather than partially implementing both. + earlier task first. -## 0.5.3 Task List +## 0.6.0 Task List -### [x] TODO 0.5.3-1: Define nonlinear failure reason taxonomy +### [x] TODO 0.6.0-1: Add nonlinear lifecycle ids and snapshot skeleton - Source: - - `docs/v5.3_development_plan.md` section 4.1, NL-1. + - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-1. - Implementation: - - [x] Add stable reason ids and names for nonlinear/cutback failures. - - [x] Cover at least these categories: linear solve failure, residual - stagnation, correction norm too large, line-search failure, trust rejection, - contact active-set oscillation, projection failure, excessive penetration, - material return failure, Riks/arc constraint failure, constraint residual - failure and minimum step exhaustion. - - [x] Keep existing solver status codes compatible; add mapping rather than - replacing public status values abruptly. - - [x] Expose the last reason id/name through the existing nonlinear diagnostic - path or a thin new accessor. + - [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. - Tests: - - [x] Add `solver_implicit` coverage for at least three distinct failure - reasons. - - [x] Add `implicit_inp` coverage that reason fields remain stable through - INP-driven nonlinear failure. + - [x] Add a lifecycle unit/module test for id/name stability and empty + snapshot defaults. - Acceptance: - - [x] Failure summaries no longer report only a generic solver error when a - known nonlinear/cutback cause is available. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp)$" --output-on-failure` passed. + - [x] Tests can query lifecycle state without running a solve, and all event + names are stable. -### [x] TODO 0.5.3-2: Map linear solver failures into nonlinear failure reasons +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|linear_solver_cg|c_api)$" --output-on-failure` + +### [x] TODO 0.6.0-2: Hook static nonlinear lifecycle events - Source: - - `docs/v5.3_development_plan.md` sections 4.7 and 5, LS-1 before CT tasks. + - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-2. - Implementation: - - [x] Extend linear-solver diagnostics with selected method, preconditioner, - matrix class, initial/final/relative residual and failure class. - - [x] Map linear solver nonconvergence, invalid matrix class and dense fallback - failure into nonlinear failure reason ids. - - [x] Preserve current CG/BiCGSTAB/GMRES/dense behavior; this task must not add - a new solver backend. - - [x] Add a selected-solver reason string for nonlinear contexts. + - [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. - Tests: - - [x] Extend `linear_solver_cg` failure-state coverage. - - [x] Extend `solver_implicit` to verify linear failure becomes a nonlinear - failure reason. + - [x] Extend `solver_implicit` to verify lifecycle event sequence for a + converged static nonlinear path and one rejected/cutback path. - Acceptance: - - [x] A nonlinear solve that fails because the linear solve failed reports both - linear residual diagnostics and the mapped nonlinear reason. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(linear_solver_cg|solver_implicit|implicit_inp)$" --output-on-failure` passed. + - [x] Static nonlinear diagnostics expose lifecycle events that match the + existing solver outcome. -### [x] TODO 0.5.3-3: Standardize contact state count fields +Verified: + +- `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 - Source: - - `docs/v5.3_development_plan.md` section 4.3, CT-1. + - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-3. - Implementation: - - [x] Define stable contact state names or ids for the 0.5.3 subset: - `open`, `closed-stick`, `closed-slip`, `closed-restick`, `separating` and - `failed-projection`. - - [x] Map existing contact history and active/released/open multiplier states - onto the stable subset without rewriting the full contact solver. - - [x] Add aggregate state counts to contact report/summary data. - - [x] Ensure state counts are available after trial, commit and restart paths. + - [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. - Tests: - - [x] Extend `restart` to check active/open and stick/slip state count - preservation. - - [x] Extend a contact report/module test to validate state count totals. + - [x] Extend `solver_implicit` to verify lifecycle fields after a nonlinear + Newmark run. - Acceptance: - - [x] Contact benchmark summaries expose stable state counts that survive - restart round trips. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(restart|contact_multiplier_report)$" --output-on-failure` passed. + - [x] Static and Newmark nonlinear paths expose the same lifecycle field + contract for the covered subset. -### [x] TODO 0.5.3-4: Add contact gap and penetration residual diagnostics +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(solver_implicit|nonlinear_lifecycle|c_api)$" --output-on-failure` + +### [x] TODO 0.6.0-4: Hook Riks/arc lifecycle events - Source: - - `docs/v5.3_development_plan.md` section 4.4, CT-2. + - `docs/v6.0_development_plan.md` sections 4.1 and 5, NLCS-4. - Implementation: - - [x] Add max penetration, mean gap and gap L2 norm to contact diagnostics. - - [x] Track failed projection count where the current search/projection path - can identify it. - - [x] Add active-set flip count for multi-step contact paths where previous - contact state is available. - - [x] Write these fields to contact report/summary output. + - [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. - Tests: - - [x] Extend `contact_mortar_report` or adjacent contact tests for gap fields. - - [x] Update `example_contact_two_blocks_compression_benchmark` checker to - consume at least max penetration and gap norm fields. + - [x] Extend `solver_implicit` or `implicit_inp` to verify arc lifecycle + fields on an accepted Riks path. - Acceptance: - - [x] Compression contact failures can be distinguished as penetration/gap - issues rather than opaque nonlinear failures. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(contact|example_contact_two_blocks_compression_benchmark)$" --output-on-failure` passed. + - [x] Riks/arc diagnostics can be interpreted through the same lifecycle + event model as static nonlinear diagnostics. -### [x] TODO 0.5.3-5: Add contact slip and friction residual diagnostics +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|c_api)$" --output-on-failure` + +### [x] TODO 0.6.0-5: Add generic rollback audit core - Source: - - `docs/v5.3_development_plan.md` section 4.4, CT-2. + - `docs/v6.0_development_plan.md` sections 4.2 and 5, NLCS-5. - Implementation: - - [x] Add slip increment norm and slip residual to contact/friction - diagnostics. - - [x] Add tangential/friction residual summary where friction history is - active. - - [x] Keep friction work and accumulated slip fields backward compatible. - - [x] Write slip/friction diagnostic fields to sliding benchmark output or - contact report output. + - [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. - Tests: - - [x] Extend friction/contact module tests for slip residual fields. - - [x] Update `example_contact_block_sliding_benchmark` checker to consume at - least one slip/friction diagnostic field. + - [x] Add lifecycle audit coverage for counter transitions and failure naming. - Acceptance: - - [x] Sliding contact output can distinguish normal contact problems from - tangential stick/slip residual problems. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(contact|example_contact_block_sliding_benchmark)$" --output-on-failure` passed. + - [x] A test can simulate owner audit success/failure and observe the shared + audit status. -### [x] TODO 0.5.3-6: Add multiplier and AL augmentation diagnostics +Verified: + +- `ctest --test-dir build-codex-gcc -R "^nonlinear_lifecycle$" --output-on-failure` + +### [x] TODO 0.6.0-6: Add material rollback audit adapter - Source: - - `docs/v5.3_development_plan.md` section 4.4, CT-2. + - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-6. - Implementation: - - [x] Add normal multiplier residual summary. - - [x] Add AL augmentation count or equivalent update count where available. - - [x] Preserve existing multiplier duplicate/invalid/max commit error audit - fields. - - [x] Include multiplier/AL fields in report summary output. + - [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. - Tests: - - [x] Extend `contact_multiplier_report` coverage for new fields. - - [x] Extend restart or contact report coverage to verify committed multiplier - diagnostics are stable after restart. + - [x] Extend `solver_implicit` or material tests with one rejected/cutback + material-state rollback audit. - Acceptance: - - [x] Multiplier-related contact failures can be separated from geometry/gap - and friction/slip failures. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(contact_multiplier_report|restart)$" --output-on-failure` passed. + - [x] Rejected material trial updates are proven not to contaminate committed + state for the covered subset. -### [x] TODO 0.5.3-7: Enhance normal-contact tangent audit +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure` + +### [x] TODO 0.6.0-7: Add contact rollback audit adapter - Source: - - `docs/v5.3_development_plan.md` section 4.5, CT-3. + - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-7. - Implementation: - - [x] Split tangent audit output so normal-only tangent error is explicit. - - [x] Keep rigid translation residual and row/column balance diagnostics. - - [x] Add a relative finite-difference error summary for normal contact. - - [x] Avoid replacing the production contact tangent with a broad new - consistent tangent implementation in this task. + - [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. - Tests: - - [x] Extend `contact_mortar_tangent` to verify normal-only tangent audit - fields. + - [x] Extend `restart` or contact report tests with a contact rollback audit + scenario. - Acceptance: - - [x] Tangent audit output can identify normal-contact tangent error - independently from friction tangent error. - - Evidence: `ctest --test-dir build-codex-gcc -R "^contact_mortar_tangent$" --output-on-failure` passed. + - [x] Contact diagnostics and state counts remain consistent after rollback + for the covered subset. -### [x] TODO 0.5.3-8: Enhance friction stick/slip tangent audit +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(contact|contact_multiplier_diag)$" --output-on-failure` + +### [x] TODO 0.6.0-8: Add cohesive and particle audit adapters - Source: - - `docs/v5.3_development_plan.md` section 4.5, CT-3. + - `docs/v6.0_development_plan.md` sections 4.3 and 5, NLCS-8. - Implementation: - - [x] Add separate stick tangent audit metrics. - - [x] Add separate slip tangent audit metrics. - - [x] Preserve energy probe and non-symmetry diagnostics. - - [x] Report tangent error, rigid residual and energy residual as distinct - quantities. + - [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. - Tests: - - [x] Extend `contact_mortar_tangent` to cover both stick and slip audit - branches. + - [x] Extend `cohesive_contact` and `particle_acceptance` to consume the new + audit statuses. - Acceptance: - - [x] Friction tangent audit can say whether failure comes from stick branch, - slip branch, rigid residual or energy probe. - - Evidence: `ctest --test-dir build-codex-gcc -R "^contact_mortar_tangent$" --output-on-failure` passed. + - [x] Existing compact cohesive and particle tests can report lifecycle audit + status without changing their physics paths. -### [x] TODO 0.5.3-9: Strengthen OpenMP contact path consistency +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(cohesive_contact|particle_step|nonlinear_lifecycle)$" --output-on-failure` + +### [x] TODO 0.6.0-9: Write lifecycle diagnostics to output/report path - Source: - - `docs/v5.3_development_plan.md` section 4.6, CT-4. + - `docs/v6.0_development_plan.md` sections 4.4 and 5, NLCS-9. - Implementation: - - [x] Extend `perf_contact_pair` or its checker to compare force path, tangent - path, candidate cache path and multi-step active-set statistics. - - [x] Compare contact state counts and gap/slip diagnostics across thread - counts. - - [x] Prefer 1/2/4 thread coverage if practical; otherwise keep 1/4 coverage - and add the new state/residual fields. - - [x] Keep timing data non-blocking; compare deterministic/non-timing fields. + - [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] Update `perf_contact_pair_omp_consistency` and - `tools/testing/check_perf_contact_pair_omp.py`. + - [x] Extend `solver_implicit` or an output checker to verify lifecycle output + headers and at least one accepted row. - Acceptance: - - [x] OpenMP contact checks verify state, force, active set, cache and - residual diagnostics, not only basic force/tangent totals. - - Evidence: `ctest --test-dir build-codex-gcc -R "^perf_contact_pair_omp_consistency$" --output-on-failure` passed. + - [x] Checker failure occurs if required 0.6.0 lifecycle output fields are + missing. -### [x] TODO 0.5.3-10: Add nonlinear residual breakdown storage +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/v5.3_development_plan.md` section 4.2, NL-2. + - `docs/v6.0_development_plan.md` sections 4.4 and 6, NLCS-10. - Implementation: - - [x] Add storage for total residual, force residual, contact residual, - constraint residual, arc residual and material local failure count. - - [x] Populate the fields in nonlinear static paths where data already exists. - - [x] Populate the fields in nonlinear Newmark paths for the available subset. - - [x] Preserve existing scalar residual fields for backward compatibility. + - [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 + after restart. + - [x] Avoid redesigning the restart format beyond an optional lifecycle block. - Tests: - - [x] Extend `solver_implicit` to check residual breakdown values or presence - in static and Newmark-Newton paths. + - [x] Extend `restart` to verify lifecycle diagnostics survive an accepted + increment restart round trip. - Acceptance: - - [x] Nonlinear diagnostics can report at least total, contact and constraint - residual categories without breaking existing residual queries. - - Evidence: `ctest --test-dir build-codex-gcc -R "^solver_implicit$" --output-on-failure` passed. + - [x] Restart proves both owned state and lifecycle diagnostics for the + covered subset. -### [x] TODO 0.5.3-11: Write residual breakdown to CSV/report outputs +Verified: + +- `ctest --test-dir build-codex-gcc -R "^(restart|nonlinear_lifecycle)$" --output-on-failure` + +### [x] TODO 0.6.0-11: Synchronize documentation and API descriptions - Source: - - `docs/v5.3_development_plan.md` sections 4.2 and 6. + - `docs/v6.0_development_plan.md` sections 2, 4 and 6, DOC-1. - Implementation: - - [x] Add residual breakdown columns to `continuation_path.csv` or the - appropriate nonlinear/contact summary output. - - [x] Ensure missing data is represented consistently for paths that do not - have a category. - - [x] Update output headers and schema comments in code/docs. - - [x] Keep old output columns stable where existing checkers depend on them. + - [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. - Tests: - - [x] Update spherical-cap or continuation checker to verify residual - breakdown columns exist. - - [x] Update contact checker to verify contact residual columns exist. + - [x] Run wording `rg` checks so docs do not claim 0.6.0 delivers complete + AL/mortar tangent, mixed-control continuation or cohesive mainline. - Acceptance: - - [x] Checker failure occurs if required 0.5.3 residual columns are absent. - - Evidence: `ctest --test-dir build-codex-gcc -R "^solver_implicit$" --output-on-failure` passed; `python -m py_compile examples\spherical_cap_with_central_point_load\check_spherical_cap_results.py` passed. + - [x] Documentation states that 0.6.0 delivers lifecycle foundation and + rollback audit, while larger solver rewrites remain follow-up work. -### [x] TODO 0.5.3-12: Add restart-after-increment audit for contact diagnostics +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` + +### [x] TODO 0.6.0-12: Update version, matrix, report and release evidence - Source: - - `docs/v5.3_development_plan.md` sections 4.3 and 6. + - `docs/v6.0_development_plan.md` section 6, REL-1. - Implementation: - - [x] Add a restart audit scenario that writes restart after an accepted - contact increment and resumes from it. - - [x] Compare contact state counts, friction history, multiplier diagnostics, - gap/slip diagnostics and residual summaries before and after restart. - - [x] Keep existing restart format compatibility checks intact. + - [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] Keep deferred boundaries explicit in release documentation. - Tests: - - [x] Extend `restart` module test for the new audit. - - [x] Add or update a compact INP/CLI restart scenario if module coverage is - insufficient. -- Acceptance: - - [x] Contact diagnostics are reproducible across restart, not only contact - forces and displacement state. - - Evidence: `ctest --test-dir build-codex-gcc -R "^restart$" --output-on-failure` passed. - -### [x] TODO 0.5.3-13: Update contact benchmark checkers for explainable diagnostics - -- Source: - - `docs/v5.3_development_plan.md` sections 4.4, 4.6 and 6. -- Implementation: - - [x] Update `examples/contact_two_blocks_compression` checker for gap, - penetration, state count and multiplier diagnostics. - - [x] Update `examples/contact_block_sliding` checker for slip/friction - diagnostics and state counts. - - [x] Update shell-shell and shell-solid checkers where shared contact summary - fields are available. - - [x] Keep numerical tolerances focused on existence, sign, nonnegativity, - boundedness and consistency; avoid overfitting complex nonlinear values. -- Tests: - - [x] Run the four contact benchmark CTest entries after checker updates. -- Acceptance: - - [x] Contact benchmark failures point to a missing/invalid diagnostic field - or a clear contact residual category. - - Evidence: `ctest --test-dir build-codex-gcc -R "^(example_contact_two_blocks_compression_benchmark|example_contact_block_sliding_benchmark|example_shell_shell_contact_benchmark|example_shell_solid_contact_benchmark)$" --output-on-failure` passed. - -### [x] TODO 0.5.3-14: Synchronize documentation and API descriptions - -- Source: - - `docs/v5.3_development_plan.md` section 4.8, DOC-1. -- Implementation: - - [x] Update mathematical/algorithm documentation for failure reasons, - residual breakdown and contact state/residual diagnostics. - - [x] Update interface documentation for any new API/query/output fields. - - [x] Update test plan with new 0.5.3 regression commands and acceptance - criteria. - - [x] Update user/developer manuals with the 0.5.3 diagnostic boundary. - - [x] Update contact example README files with new output fields. -- Tests: - - [x] Run `rg` checks to ensure old wording does not claim 0.5.3 delivers full - industrial AL/mortar consistent tangent. -- Acceptance: - - [x] Documentation states that 0.5.3 improves explainability and diagnostics - while deferring complete AL/mortar tangent rewrite. - - Evidence: documentation addenda added to design, algorithm, interface, - test plan, user/developer manuals and four contact example READMEs; wording - `rg` check found only explicit non-delivery boundary statements. - -### [x] TODO 0.5.3-15: Update V5 matrix, acceptance report and version close-out - -- Source: - - `docs/v5.3_development_plan.md` sections 6 and 8. -- Implementation: - - [x] Update `docs/v5_benchmark_matrix.md` with 0.5.3 tests and diagnostic - evidence. - - [x] Update `docs/v5_acceptance_report.md` with 0.5.3 scope, commands and - limitations. - - [x] Update `docs/v5_development_plan.md` status lines if 0.5.3 changes V5.3 - contact status or evidence. - - [x] Raise project version only when 0.5.3 implementation is ready to close. -- Tests: - - [x] Run the planned 0.5.3 targeted regression command. + - [x] Run the planned 0.6.0 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.5.3 closes with green targeted tests, green V5 acceptance subset and + - [x] 0.6.0 closes with green targeted tests, green acceptance subset and documented deferred boundaries. - - Evidence: `cmake --build build-codex-gcc --parallel` passed; - 0.5.3 targeted nonlinear/contact diagnostics passed 8/8; contact benchmark - diagnostic checker subset passed 4/4; V5 acceptance passed 39/39; - `git diff --check` passed with line-ending warnings only. -## Suggested 0.5.3 Regression Commands +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|linear_solver_cg|restart|contact_mortar_report|contact_mortar_tangent|contact_multiplier_report|perf_contact_pair_omp_consistency)$" --output-on-failure -ctest --test-dir build-codex-gcc -R "^(example_contact_two_blocks_compression_benchmark|example_contact_block_sliding_benchmark|example_shell_shell_contact_benchmark|example_shell_solid_contact_benchmark)$" --output-on-failure +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 ```