From ee18a9b75746380b2120dbe703eb553a90d6c6e4 Mon Sep 17 00:00:00 2001 From: shenw Date: Thu, 2 Jul 2026 08:26:46 +0800 Subject: [PATCH] Release FemLite 0.6.2 stability hardening --- .gitattributes | 7 + .gitignore | 1 + CMakeLists.txt | 13 +- README.md | 102 +-- docs/07_user_manual.md | 14 +- docs/08_developer_manual.md | 8 +- docs/v6_acceptance_report.md | 44 +- docs/v6_benchmark_matrix.md | 34 +- .../check_contact_results.py | 48 +- examples/contact_schema.py | 58 ++ .../check_contact_results.py | 40 +- .../check_contact_results.py | 39 +- .../check_contact_results.py | 39 +- src/base/fem_control.f90 | 163 +++-- src/base/fem_precision.f90 | 2 +- src/output/fem_output_csv.f90 | 642 +++++++++++++---- src/solver/fem_linear_solver_dispatch.f90 | 10 + .../s3_static_finite_strain_unsupported.inp | 27 + tests/interface/test_c_api.c | 2 +- tests/module/test_contact.f90 | 89 +++ tests/module/test_implicit_inp.f90 | 45 ++ tests/module/test_linear_solver_cg.f90 | 29 + tests/module/test_nonlinear_lifecycle.f90 | 38 + tests/module/test_restart.f90 | 454 ++++++------ tests/module/test_solver_implicit.f90 | 104 +++ tests/performance/perf_contact_pair.f90 | 7 + tests/performance/perf_p1.f90 | 2 +- tests/unit/test_smoke.f90 | 2 +- todo.md | 672 ++++++++---------- tools/testing/check_cli_output_dir.py | 83 +++ tools/testing/check_perf_contact_pair_omp.py | 63 +- 31 files changed, 1862 insertions(+), 1019 deletions(-) create mode 100644 examples/contact_schema.py create mode 100644 tests/data/s3_static_finite_strain_unsupported.inp create mode 100644 tools/testing/check_cli_output_dir.py diff --git a/.gitattributes b/.gitattributes index 2b83c5d..9d0229d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,8 @@ * text=auto +.gitattributes text eol=lf +.gitignore text eol=lf + *.f90 text eol=lf *.F90 text eol=lf *.cmake text eol=lf @@ -8,3 +11,7 @@ CMakeLists.txt text eol=lf *.inp text eol=lf *.txt text eol=lf *.py text eol=lf +*.c text eol=lf +*.h text eol=lf +*.cpp text eol=lf +*.hpp text eol=lf diff --git a/.gitignore b/.gitignore index 8913c13..1437b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,5 +36,6 @@ restart_*.frs /output/ examples/*/results/ /continuation_path.csv +/nonlinear_lifecycle.csv /every tmp/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ec8c6c2..cc6794e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(FemLite - VERSION 0.6.1 + VERSION 0.6.2 LANGUAGES C Fortran ) @@ -1057,6 +1057,17 @@ if(Python3_Interpreter_FOUND) WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) + add_test(NAME cli_output_dir_boundary + COMMAND "${Python3_EXECUTABLE}" + "${CMAKE_SOURCE_DIR}/tools/testing/check_cli_output_dir.py" + "${CMAKE_SOURCE_DIR}" + "$" + "${CMAKE_BINARY_DIR}" + ) + set_tests_properties(cli_output_dir_boundary PROPERTIES + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + ) + add_test(NAME example_shell_patch_s3_smoke COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tools/testing/run_example_smoke.py" diff --git a/README.md b/README.md index d73e1cc..0649267 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,40 @@ # FemLite -FemLite 是一个以 Fortran 95 为核心实现的轻量级有限元求解器,面向结构动力学、静力学、壳/实体单元、接触、材料非线性和外部耦合接口的工程验证与算法开发。 +FemLite is a lightweight finite element solver with a Fortran core. It is used +for structural dynamics, static and nonlinear analysis, shell/solid elements, +contact, material nonlinearity and compact engineering benchmark development. -当前项目版本为 **0.6.1**。`v0.5.0` 已作为第五版阶段验收发布标签推送;第四版 `0.4.8` 已完成阶段验收并作为稳定基线;第五版 `0.5.x` 已收束 nonlinear/contact diagnostic hardening;0.6.0 交付统一非线性 lifecycle foundation、rollback audit、生命周期输出字段和 restart 诊断回读,0.6.1 继续加固 lifecycle/contact/Riks/solver 诊断报告与回归证据。完整工业级 mortar/AL 一致切线、mixed-control continuation、cohesive contact mainline、DEM/FEM subcycling 和生产级滚压流程仍作为后续版本工作。 +Current project version: **0.6.2**. -## 当前基线 +`v0.5.0` remains the fifth-version acceptance checkpoint. The 0.6.x line builds +on that baseline with nonlinear lifecycle diagnostics, restart diagnostics, +contact/solver/path output hardening and release stability checks. Version +0.6.2 is a stability release: it does not add new user-facing algorithms or +broaden the 0.6.1 feature boundary. -`0.4.8` 第四版验收基线已具备: +## Current Baseline -- 显式动力学、线性/非线性静力和隐式 Newmark 主流程。 -- C3D4、C3D8、C3D10、C3D20 实体单元。 -- S3、S4、S6、S8 壳单元基础动力、静力和输出能力。 -- 线弹性、J2/J2_JC 小应变弹塑性和壳代表性 section plasticity。 -- 面-面 contact pair、analytical rigid plane、mortar 权重、Coulomb/正则化 Coulomb 摩擦历史、接触输出和 restart。 -- 内部 CG、BiCGSTAB、GMRES、dense pivoting fallback 线性求解器和 - none/Jacobi/Gauss-Seidel/ILU0 预条件器。 -- CSV、VTK、restart、C ABI 和外部 SPH/载荷映射接口。 -- `examples/` 下的可运行示例矩阵和 Windows GCC 16 本地 CTest 基线。 +FemLite currently includes: -第五版已接入内部 solver 诊断、no-external-solver 回归、非匹配 contact benchmark、Mohr-Coulomb 材料点和强度折减 benchmark、Euler/波纹壳屈曲 benchmark、滚压 kinematics/springback benchmark、cohesive ball adhesion benchmark,以及真实粒子-柔性容器耦合 benchmark。0.6.x 在此基础上补齐非线性增量生命周期、材料/接触/cohesive/particle 审计适配、`continuation_path.csv` 生命周期与 Riks/arc 诊断列、`nonlinear_lifecycle.csv`、contact state/AL/friction 诊断和 restart version 5 可选 `LIFECYCLE_DIAGNOSTICS` 块。详细计划和剩余项见 [docs/v6.0_development_plan.md](docs/v6.0_development_plan.md)、[docs/v6.1_development_plan.md](docs/v6.1_development_plan.md)、[docs/v6_benchmark_matrix.md](docs/v6_benchmark_matrix.md)、[docs/v6_acceptance_report.md](docs/v6_acceptance_report.md) 与 [todo.md](todo.md)。 +- Explicit dynamics, linear static, nonlinear static and implicit Newmark paths. +- C3D4/C3D8/C3D10/C3D20 solid elements and S3/S4/S6/S8 shell elements. +- Elastic, J2/J2_JC and Mohr-Coulomb material paths with compact regression + coverage. +- Internal CG, BiCGSTAB, GMRES and dense pivoting linear solvers with + diagnostics and preconditioner options. +- Contact-pair, analytical-plane, mortar/AL, friction, cohesive and particle + coupling diagnostic infrastructure used by the covered benchmarks. +- CSV, VTK, restart, Fortran API and C ABI output/query surfaces. +- `continuation_path.csv`, `nonlinear_lifecycle.csv` and restart version 5 + optional lifecycle diagnostics. -## 快速构建 +Deferred items remain explicit: complete industrial AL/mortar consistent +tangents, generalized mixed-control continuation, cohesive contact mainline, +DEM/FEM subcycling, complete shell preload/high-order geometric stiffness, +nonzero harmonic cyclic solving and production roll-forming workflows are not +claimed by 0.6.2. + +## Build ```powershell cmake -S . -B build-win-gcc-16 -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release @@ -28,48 +42,40 @@ cmake --build build-win-gcc-16 --config Release ctest --test-dir build-win-gcc-16 --output-on-failure ``` -如果使用已有构建目录,可直接执行: +For the current local GCC build directory used during 0.6.x hardening: ```powershell -ctest --test-dir build-win-gcc-16 --output-on-failure +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc --output-on-failure ``` -## 运行示例 +## Release Gate -示例统一放在 `examples/` 下。每个案例使用独立文件夹,并提供 README、输入文件和 Windows 双击运行脚本。 - -例如: +The 0.6.2 stability release gate is: ```powershell -examples\contact_two_blocks_compression\run_case.bat -examples\contact_block_sliding\run_case.bat -examples\roll_forming\run_case.bat -examples\Dynamic_Grain_Packing_of_a_Flexible_Container\run_case.bat +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api)$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check ``` -部分第五版目标案例仍保留第四版 smoke 作为快速回归,同时新增独立 benchmark 输入和 checker。每个案例 README 会标明当前覆盖范围、输出指标和限制。 +## Documentation -## 文档入口 +- [0.6 development plan](docs/v6.0_development_plan.md) +- [0.6.1 development plan](docs/v6.1_development_plan.md) +- [0.6 benchmark matrix](docs/v6_benchmark_matrix.md) +- [0.6 acceptance report](docs/v6_acceptance_report.md) +- [V5 benchmark matrix](docs/v5_benchmark_matrix.md) +- [User manual](docs/07_user_manual.md) +- [Developer manual](docs/08_developer_manual.md) +- [TODO](todo.md) -- [第四版验收报告](docs/v4_acceptance_report.md) -- [第五版开发计划](docs/v5_development_plan.md) -- [第五版验收报告](docs/v5_acceptance_report.md) -- [第五版 benchmark 矩阵](docs/v5_benchmark_matrix.md) -- [用户手册](docs/07_user_manual.md) -- [开发者手册](docs/08_developer_manual.md) -- [数学模型与算法](docs/04_mathematical_model_and_algorithms.md) -- [测试与验证计划](docs/06_test_and_verification_plan.md) +## Development Rules -## 开发约束 - -- 新增算法必须同步更新需求、架构、详细设计、算法、接口、测试、用户和开发者文档。 -- 第五版不接受 mini/demo/smoke 替代核心能力验收。 -- 如果同一算法同时存在前期遗留简化版和后期补强完整版,必须删除简化版或隔离到非生产调试入口,不能继续作为生产 fallback。 -- 大型结果文件不直接提交到 git,只提交小型参考指标、检查脚本和生成说明。 -- 已验收的 V1-V4 能力必须保持回归通过。 - -## 联系方式 - -这是用CODEX开发的软件,实现了一些有趣的功能,大部分功能已经推进到稳定的工程级别。如果有什么问题或者想法,可以通过邮箱联系我: - -```wenhao.shen@pkuncii.cn``` +- Keep accepted V1-V5 behavior under regression. +- Prefer focused stability checks over broad solver rewrites in 0.6.2. +- Do not commit generated result files, large CSV/VTK outputs or temporary + benchmark artifacts. +- New behavior should be paired with a small, repeatable test or checker. diff --git a/docs/07_user_manual.md b/docs/07_user_manual.md index d841392..6b1d521 100644 --- a/docs/07_user_manual.md +++ b/docs/07_user_manual.md @@ -1,12 +1,12 @@ -# FemLite 0.5.x 用户手册 +# FemLite 0.6.x 用户手册 日期:2026-06-26 ## 1. 适用范围 -本文档面向 FemLite 0.5.x 的使用者,说明如何编译、运行、准备输入文件、查看结果和复现实例。 +本文档面向 FemLite 0.6.x 的使用者,说明如何编译、运行、准备输入文件、查看结果和复现实例。 -FemLite 0.5.x 是船舶接触爆炸结构响应 FEM 软件的第五版开发线,当前支持: +FemLite 0.6.x 继承第五版 `0.5.x` 验收基线,并在其上加固生命周期、接触、求解器和输出诊断;当前支持: - 三维实体和壳单元结构分析。 - 显式瞬态动力学。 @@ -23,7 +23,7 @@ FemLite 0.5.x 是船舶接触爆炸结构响应 FEM 软件的第五版开发线 - CSV、VTK、restart 和 contact CSV 输出。 - Fortran95 原生接口、C ABI 子集和 Python 调试脚本。 -0.5.x 当前开发态不等价于完整 Abaqus 兼容求解器,也不等价于全部 V5 高保真 benchmark 已完成的最终版。 +0.6.x 当前开发态不等价于完整 Abaqus 兼容求解器,也不等价于全部 V5 高保真 benchmark 已完成的最终版。 ## 2. 目录概览 @@ -622,3 +622,9 @@ 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. +> Current version note: FemLite 0.6.2 is a stability release. It keeps the +> 0.6.1 feature boundary and hardens CSV schemas, restart diagnostics, +> contact/solver reports, INP error handling and CLI output-directory behavior. +> It does not add new user-facing algorithms. Complete industrial AL/mortar +> consistent tangents, mixed-control continuation, cohesive contact mainline, +> DEM/FEM subcycling and production roll-forming workflows remain deferred. diff --git a/docs/08_developer_manual.md b/docs/08_developer_manual.md index 37bb3d9..9d5375b 100644 --- a/docs/08_developer_manual.md +++ b/docs/08_developer_manual.md @@ -1,4 +1,4 @@ -# FemLite 0.5.x 开发者手册 +# FemLite 0.6.x 开发者手册 日期:2026-06-26 @@ -6,7 +6,7 @@ 本文档面向 FemLite 开发者,说明代码结构、构建测试、模块职责、接口扩展、编码约束和发布检查流程。 -FemLite 核心代码采用 Fortran 95 非面向对象风格,使用集中式 `fem_database` 保存模型、状态和求解数据。当前版本线为 0.5.x。 +FemLite 核心代码采用 Fortran 95 非面向对象风格,使用集中式 `fem_database` 保存模型、状态和求解数据。当前版本线为 0.6.x,当前发布目标为 0.6.2 稳定性加固。 ## 2. 开发原则 @@ -639,3 +639,7 @@ nonzero-wave solving, DEM subcycling or production roll-forming workflows. Keep larger algorithm rewrites deferred unless a later development plan explicitly schedules them. +> Current version note: FemLite 0.6.2 is a release-hardening line. Development +> work in this version should preserve existing algorithms, keep diagnostics +> schema-stable, maintain restart backward compatibility and pass the 0.6.2 +> release gate documented in `docs/v6_acceptance_report.md`. diff --git a/docs/v6_acceptance_report.md b/docs/v6_acceptance_report.md index 20c0c0b..c1e8f16 100644 --- a/docs/v6_acceptance_report.md +++ b/docs/v6_acceptance_report.md @@ -1,4 +1,4 @@ -# FemLite 0.6.0 Acceptance Report +# FemLite 0.6.x Acceptance Report Date: 2026-07-01 @@ -94,3 +94,45 @@ smoke checks passed 2/2 after the public version was raised to 0.6.1. 0.6.1 still does not claim complete industrial AL/mortar consistent tangent delivery, generalized mixed-control continuation, cohesive contact mainline, DEM/FEM subcycling or production roll-forming workflow support. + +## 0.6.2 Stability Close-Out Addendum + +0.6.2 is a stability hardening release. It does not add user-facing algorithms +or broaden the 0.6.1 feature boundary. The release stabilizes the existing +diagnostic surface by hardening CSV schemas, path storage reset/capacity, +restart compatibility, contact state defaults, OpenMP contact determinism, +linear-solver fallback diagnostics and INP/CLI error boundaries. + +Required 0.6.2 gate on `build-codex-gcc`: + +```powershell +cmake --build build-codex-gcc --parallel +ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api|cli_output_dir_boundary|vtk_output)$" --output-on-failure +ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure +git diff --check +``` + +The `source_size` command is a mandatory 0.6.2 release blocker. It would have +caught the hard failures in `nlc_path_append`, `output_csv_write_path` and the +restart contact-history test before release. + +0.6.2 remains bounded to release hardening: CSV schema stability, restart +compatibility, deterministic contact diagnostics, solver fallback reporting, +INP/CLI error boundaries and documentation/version consistency. + +Final local 0.6.2 evidence on `build-codex-gcc`: + +- `cmake --build build-codex-gcc --parallel` passed. +- `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + passed 1/1. +- Targeted stability regression passed 13/13. +- `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` + passed 39/39. +- Version smoke checks passed 2/2 after raising the public version to 0.6.2. +- `git diff --check` passed with line-ending normalization warnings only. + +0.6.2 explicitly defers complete industrial AL/mortar consistent tangent +delivery, generalized mixed-control continuation, cohesive contact mainline, +DEM/FEM subcycling, complete shell/high-order geometric stiffness expansion, +nonzero harmonic cyclic solving and production roll-forming workflows. diff --git a/docs/v6_benchmark_matrix.md b/docs/v6_benchmark_matrix.md index 0a8e802..2dff941 100644 --- a/docs/v6_benchmark_matrix.md +++ b/docs/v6_benchmark_matrix.md @@ -1,4 +1,4 @@ -# FemLite 0.6.0 Benchmark And Acceptance Matrix +# FemLite 0.6.x Benchmark And Acceptance Matrix Date: 2026-07-01 @@ -86,3 +86,35 @@ Results: - V5 acceptance subset passed 39/39. - Contact compact benchmark smoke passed 4/4. - Version smoke checks passed 2/2 after raising the public version to 0.6.1. + +## 0.6.2 Stability Gate Matrix + +FemLite 0.6.2 is a stability release for the 0.6.1 diagnostic surface. It +does not add new algorithms. The release gate is intentionally small enough to +run locally and broad enough to catch source-size regressions, schema breaks, +restart incompatibilities and stale solver/contact diagnostics. + +| Gate item | Required command | Stability coverage | +|---|---|---| +| Build | `cmake --build build-codex-gcc --parallel` | Confirms all modules and tests still compile after hardening refactors. | +| Source-size hard gate | `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` | Blocks oversized routines and would catch the 0.6.2 entry failures before release. | +| Targeted stability regression | `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api|cli_output_dir_boundary|vtk_output)$" --output-on-failure` | Covers lifecycle/path output, restart, contact diagnostics, solver fallback, INP/CLI boundaries, output directory behavior and public API stability. | +| V5 acceptance subset | `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` | Guards the established V5 executable acceptance set while 0.6.2 hardens diagnostics. | +| Diff hygiene | `git diff --check` | Rejects whitespace and merge-marker mistakes before release. | + +The 0.6.2 gate is not a replacement for future long-run research validation. +It is the required local quality bar for the release hardening scope. + +Final local 0.6.2 evidence on `build-codex-gcc`: + +- Build passed. +- `source_size` passed 1/1. +- Targeted stability regression passed 13/13. +- V5 acceptance subset passed 39/39. +- Version smoke checks passed 2/2. +- `git diff --check` passed with line-ending normalization warnings only. + +0.6.2 does not claim new algorithms. Complete industrial AL/mortar consistent +tangents, mixed-control continuation, cohesive contact mainline, DEM/FEM +subcycling, full shell/high-order geometric stiffness expansion, nonzero +harmonic cyclic solving and production roll-forming workflows remain deferred. diff --git a/examples/contact_block_sliding/check_contact_results.py b/examples/contact_block_sliding/check_contact_results.py index 5825aba..fa01070 100644 --- a/examples/contact_block_sliding/check_contact_results.py +++ b/examples/contact_block_sliding/check_contact_results.py @@ -5,33 +5,12 @@ import glob import os import sys +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +from contact_schema import FRICTION_CONTACT_COLUMNS, read_pair_rows, require_pair_schema + MIN_MASTER_FACETS = 4 MIN_ACTIVE_CONTACTS = 2 MIN_ACCUMULATED_SLIP = 1.0e-1 -STATE_COLUMNS = [ - "open_count", - "closed_stick_count", - "closed_slip_count", - "closed_restick_count", - "separating_count", - "state_failed_projection_count", -] - - -def require_columns(row: dict[str, str], columns: list[str]) -> bool: - missing = [column for column in columns if column not in row] - if missing: - print("missing contact diagnostic columns: " + ", ".join(missing)) - return False - return True - - -def read_pair_rows(result_dir: str) -> list[dict[str, str]]: - rows: list[dict[str, str]] = [] - for path in sorted(glob.glob(os.path.join(result_dir, "contact_*.csv"))): - with open(path, newline="") as stream: - rows.extend(row for row in csv.DictReader(stream) if row["kind"] == "PAIR") - return rows def write_sliding_profile(result_dir: str, rows: list[dict[str, str]]) -> str: @@ -117,17 +96,18 @@ def main() -> int: if len(pair_rows) < 2: print("contact diagnostic path is too short") return 1 - if not require_columns( - pair_rows[0], - STATE_COLUMNS + if not require_pair_schema( + pair_rows, + FRICTION_CONTACT_COLUMNS + [ - "gap_residual", - "gap_l2", - "slip_increment_norm", - "slip_residual", - "friction_residual", - "aug_factor", - "aug_lambda", + "accumulated_slip", + "friction_work_total", + "friction_regularization", + "stick_count", + "slip_count", + "ftx", + "fty", + "ftz", ], ): return 1 diff --git a/examples/contact_schema.py b/examples/contact_schema.py new file mode 100644 index 0000000..bf63f70 --- /dev/null +++ b/examples/contact_schema.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +import csv +import glob +import os + +STATE_COLUMNS = [ + "open_count", + "closed_stick_count", + "closed_slip_count", + "closed_restick_count", + "separating_count", + "state_failed_projection_count", +] + +COMPACT_CONTACT_COLUMNS = STATE_COLUMNS + [ + "gap_residual", + "gap_l2", + "failed_projection_count", + "active_set_flip_count", + "aug_factor", + "aug_lambda", +] + +FRICTION_CONTACT_COLUMNS = [ + "slip_increment_norm", + "slip_residual", + "friction_residual", +] + + +def require_columns(row: dict[str, str], columns: list[str]) -> bool: + missing = [column for column in columns if column not in row] + if missing: + print("missing contact diagnostic columns: " + ", ".join(missing)) + return False + return True + + +def read_pair_rows(result_dir: str) -> list[dict[str, str]]: + rows: list[dict[str, str]] = [] + for path in sorted(glob.glob(os.path.join(result_dir, "contact_*.csv"))): + with open(path, newline="") as stream: + rows.extend(row for row in csv.DictReader(stream) if row["kind"] == "PAIR") + return rows + + +def require_pair_schema( + rows: list[dict[str, str]], + extra_columns: list[str] | None = None, +) -> bool: + if not rows: + print("no contact pair rows found") + return False + columns = list(COMPACT_CONTACT_COLUMNS) + if extra_columns: + columns.extend(extra_columns) + return require_columns(rows[0], columns) diff --git a/examples/contact_two_blocks_compression/check_contact_results.py b/examples/contact_two_blocks_compression/check_contact_results.py index 358eee6..9df4e31 100644 --- a/examples/contact_two_blocks_compression/check_contact_results.py +++ b/examples/contact_two_blocks_compression/check_contact_results.py @@ -5,32 +5,16 @@ import glob import os import sys +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +from contact_schema import read_pair_rows, require_pair_schema + + CONTACT_AREA = 1.0e-2 MIN_MASTER_FACETS = 4 -STATE_COLUMNS = [ - "open_count", - "closed_stick_count", - "closed_slip_count", - "closed_restick_count", - "separating_count", - "state_failed_projection_count", -] - - -def require_columns(row: dict[str, str], columns: list[str]) -> bool: - missing = [column for column in columns if column not in row] - if missing: - print("missing contact diagnostic columns: " + ", ".join(missing)) - return False - return True - def main() -> int: result_dir = sys.argv[1] if len(sys.argv) > 1 else "results" - pair_rows: list[dict[str, str]] = [] - for path in sorted(glob.glob(os.path.join(result_dir, "contact_*.csv"))): - with open(path, newline="") as stream: - pair_rows.extend(row for row in csv.DictReader(stream) if row["kind"] == "PAIR") + pair_rows = read_pair_rows(result_dir) if not pair_rows: print("no contact pair rows found") @@ -38,19 +22,7 @@ def main() -> int: if len(pair_rows) < 2: print("contact diagnostic path is too short") return 1 - if not require_columns( - pair_rows[0], - STATE_COLUMNS - + [ - "gap_residual", - "gap_mean", - "gap_l2", - "failed_projection_count", - "active_set_flip_count", - "aug_factor", - "aug_lambda", - ], - ): + if not require_pair_schema(pair_rows, ["gap_mean"]): return 1 profile_rows: list[dict[str, float]] = [] diff --git a/examples/shell_shell_contact/check_contact_results.py b/examples/shell_shell_contact/check_contact_results.py index 2b6c73d..e8d6816 100644 --- a/examples/shell_shell_contact/check_contact_results.py +++ b/examples/shell_shell_contact/check_contact_results.py @@ -5,30 +5,8 @@ import glob import os import sys -STATE_COLUMNS = [ - "open_count", - "closed_stick_count", - "closed_slip_count", - "closed_restick_count", - "separating_count", - "state_failed_projection_count", -] - - -def require_columns(row: dict[str, str], columns: list[str]) -> bool: - missing = [column for column in columns if column not in row] - if missing: - print("missing contact diagnostic columns: " + ", ".join(missing)) - return False - return True - - -def read_pair_rows(result_dir: str) -> list[dict[str, str]]: - rows: list[dict[str, str]] = [] - for path in sorted(glob.glob(os.path.join(result_dir, "contact_*.csv"))): - with open(path, newline="") as stream: - rows.extend(row for row in csv.DictReader(stream) if row["kind"] == "PAIR") - return rows +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +from contact_schema import read_pair_rows, require_pair_schema def main() -> int: @@ -40,18 +18,7 @@ def main() -> int: if len(pair_rows) < 2: print("shell-shell contact diagnostic path is too short") return 1 - if not require_columns( - pair_rows[0], - STATE_COLUMNS - + [ - "gap_residual", - "gap_l2", - "failed_projection_count", - "active_set_flip_count", - "aug_factor", - "aug_lambda", - ], - ): + if not require_pair_schema(pair_rows): return 1 profile_path = os.path.join(result_dir, "shell_shell_contact_profile.csv") diff --git a/examples/shell_solid_contact/check_contact_results.py b/examples/shell_solid_contact/check_contact_results.py index 1901047..c58ec2a 100644 --- a/examples/shell_solid_contact/check_contact_results.py +++ b/examples/shell_solid_contact/check_contact_results.py @@ -5,30 +5,8 @@ import glob import os import sys -STATE_COLUMNS = [ - "open_count", - "closed_stick_count", - "closed_slip_count", - "closed_restick_count", - "separating_count", - "state_failed_projection_count", -] - - -def require_columns(row: dict[str, str], columns: list[str]) -> bool: - missing = [column for column in columns if column not in row] - if missing: - print("missing contact diagnostic columns: " + ", ".join(missing)) - return False - return True - - -def read_pair_rows(result_dir: str) -> list[dict[str, str]]: - rows: list[dict[str, str]] = [] - for path in sorted(glob.glob(os.path.join(result_dir, "contact_*.csv"))): - with open(path, newline="") as stream: - rows.extend(row for row in csv.DictReader(stream) if row["kind"] == "PAIR") - return rows +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +from contact_schema import read_pair_rows, require_pair_schema def main() -> int: @@ -40,18 +18,7 @@ def main() -> int: if len(pair_rows) < 2: print("shell-solid contact diagnostic path is too short") return 1 - if not require_columns( - pair_rows[0], - STATE_COLUMNS - + [ - "gap_residual", - "gap_l2", - "failed_projection_count", - "active_set_flip_count", - "aug_factor", - "aug_lambda", - ], - ): + if not require_pair_schema(pair_rows): return 1 profile_path = os.path.join(result_dir, "shell_solid_contact_profile.csv") diff --git a/src/base/fem_control.f90 b/src/base/fem_control.f90 index 35d11d3..0a46ba1 100644 --- a/src/base/fem_control.f90 +++ b/src/base/fem_control.f90 @@ -464,16 +464,7 @@ contains real(rk), intent(in) :: correction_norm integer, intent(out) :: ierr integer :: row - real(rk) :: prev_disp - real(rk) :: prev_force - real(rk) :: prev_parameter - real(rk) :: prev_prev_parameter - real(rk) :: prev_reaction - real(rk) :: prev_prev_reaction real(rk) :: load_delta - real(rk) :: prev_load_delta - real(rk) :: reaction_delta - real(rk) :: prev_reaction_delta integer :: predictor_consistent integer :: load_reversal integer :: turning_point @@ -481,46 +472,89 @@ contains call nlc_path_ensure_capacity(nlc_path_count + 1, ierr) if (ierr .ne. FEM_SUCCESS) return - load_delta = ZERO - prev_load_delta = ZERO - reaction_delta = ZERO - prev_reaction_delta = ZERO - predictor_consistent = 1 - load_reversal = 0 - turning_point = 0 - if (nlc_path_count .gt. 0) then - prev_disp = nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, nlc_path_count) - prev_force = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & - nlc_path_count) - prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, nlc_path_count) - prev_reaction = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & - nlc_path_count) - load_delta = parameter - prev_parameter - reaction_delta = reaction_generalized - prev_reaction - nlc_path_accumulated_work = nlc_path_accumulated_work + & - 0.5_rk * (prev_force + reaction_generalized) * & - (prescribed_l2 - prev_disp) - if (nlc_path_count .gt. 1) then - prev_prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, & - nlc_path_count - 1) - prev_prev_reaction = nlc_path_real( & - NLC_PATH_R_REACTION_GENERALIZED, nlc_path_count - 1) - prev_load_delta = prev_parameter - prev_prev_parameter - prev_reaction_delta = prev_reaction - prev_prev_reaction - if (load_delta * prev_load_delta .lt. ZERO) then - predictor_consistent = 0 - load_reversal = 1 - end if - if (reaction_delta * prev_reaction_delta .lt. ZERO) then - turning_point = 1 - end if - end if - end if + call nlc_path_arc_indicators(parameter, prescribed_l2, & + reaction_generalized, load_delta, predictor_consistent, & + load_reversal, turning_point) row = nlc_path_count + 1 nlc_path_real(:, row) = ZERO nlc_path_int(:, row) = 0 + call nlc_path_store_real(row, time, parameter, prescribed_l2, & + prescribed_max, actual_l2, actual_max, residual_linf, residual_l2, & + reaction_sum, reaction_generalized, residual_norm, relative_residual, & + correction_norm, load_delta) + call nlc_path_store_int(row, step, control_dof_count, iteration, & + status_code, failure_code, predictor_consistent, load_reversal, & + turning_point) + + nlc_path_count = row + ierr = FEM_SUCCESS + end subroutine nlc_path_append + + subroutine nlc_path_arc_indicators(parameter, prescribed_l2, reaction, & + load_delta, predictor_ok, load_reversal, & + turning_point) + real(rk), intent(in) :: parameter + real(rk), intent(in) :: prescribed_l2 + real(rk), intent(in) :: reaction + real(rk), intent(out) :: load_delta + integer, intent(out) :: predictor_ok + integer, intent(out) :: load_reversal + integer, intent(out) :: turning_point + real(rk) :: prev_disp + real(rk) :: prev_force + real(rk) :: prev_parameter + real(rk) :: prev_prev_parameter + real(rk) :: prev_reaction + real(rk) :: prev_prev_reaction + real(rk) :: reaction_delta + + load_delta = ZERO + reaction_delta = ZERO + predictor_ok = 1 + load_reversal = 0 + turning_point = 0 + if (nlc_path_count .le. 0) return + + prev_disp = nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, nlc_path_count) + prev_force = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & + nlc_path_count) + prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, nlc_path_count) + prev_reaction = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & + nlc_path_count) + load_delta = parameter - prev_parameter + reaction_delta = reaction - prev_reaction + nlc_path_accumulated_work = nlc_path_accumulated_work + & + 0.5_rk * (prev_force + reaction) * (prescribed_l2 - prev_disp) + if (nlc_path_count .le. 1) return + + prev_prev_parameter = nlc_path_real(NLC_PATH_R_PARAMETER, & + nlc_path_count - 1) + prev_prev_reaction = nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, & + nlc_path_count - 1) + if (load_delta * (prev_parameter - prev_prev_parameter) .lt. ZERO) then + predictor_ok = 0 + load_reversal = 1 + end if + if (reaction_delta * (prev_reaction - prev_prev_reaction) .lt. ZERO) then + turning_point = 1 + end if + end subroutine nlc_path_arc_indicators + + subroutine nlc_path_store_real(row, time, parameter, prescribed_l2, & + prescribed_max, actual_l2, actual_max, & + residual_linf, residual_l2, reaction_sum, & + reaction_generalized, residual_norm, & + relative_residual, correction_norm, & + load_delta) + integer, intent(in) :: row + real(rk), intent(in) :: time, parameter, prescribed_l2, prescribed_max + real(rk), intent(in) :: actual_l2, actual_max, residual_linf, residual_l2 + real(rk), intent(in) :: reaction_sum, reaction_generalized + real(rk), intent(in) :: residual_norm, relative_residual, correction_norm + real(rk), intent(in) :: load_delta + nlc_path_real(NLC_PATH_R_TIME, row) = time nlc_path_real(NLC_PATH_R_PARAMETER, row) = parameter nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, row) = prescribed_l2 @@ -530,40 +564,49 @@ contains nlc_path_real(NLC_PATH_R_RESIDUAL_LINF, row) = residual_linf nlc_path_real(NLC_PATH_R_RESIDUAL_L2, row) = residual_l2 nlc_path_real(NLC_PATH_R_REACTION_SUM, row) = reaction_sum - nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, row) = & - reaction_generalized + nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, row) = reaction_generalized nlc_path_real(NLC_PATH_R_WORK, row) = nlc_path_accumulated_work nlc_path_real(NLC_PATH_R_RESIDUAL_NORM, row) = residual_norm nlc_path_real(NLC_PATH_R_RELATIVE_RESIDUAL, row) = relative_residual nlc_path_real(NLC_PATH_R_CORRECTION_NORM, row) = correction_norm + call nlc_path_store_real_diagnostics(row, load_delta) + end subroutine nlc_path_store_real + + subroutine nlc_path_store_real_diagnostics(row, load_delta) + integer, intent(in) :: row + real(rk), intent(in) :: load_delta + nlc_path_real(NLC_PATH_R_LIN_INIT_RESID, row) = & linear_solver_initial_resid - nlc_path_real(NLC_PATH_R_LIN_FINAL_RESID, row) = & - linear_solver_last_resid - nlc_path_real(NLC_PATH_R_LIN_REL_RESID, row) = & - linear_solver_relative_resid + nlc_path_real(NLC_PATH_R_LIN_FINAL_RESID, row) = linear_solver_last_resid + nlc_path_real(NLC_PATH_R_LIN_REL_RESID, row) = linear_solver_relative_resid nlc_path_real(NLC_PATH_R_TARGET_DT, row) = nlc_last_target_dt nlc_path_real(NLC_PATH_R_ACTUAL_DT, row) = nlc_last_actual_dt nlc_path_real(NLC_PATH_R_NEXT_DT, row) = nlc_next_target_dt nlc_path_real(NLC_PATH_R_TRUST_RADIUS, row) = nlc_last_trust_radius nlc_path_real(NLC_PATH_R_NEXT_TRUST_RADIUS, row) = nlc_next_trust_radius nlc_path_real(NLC_PATH_R_TRUST_DAMPING, row) = nlc_last_damping - nlc_path_real(NLC_PATH_R_TRUST_MERIT_RATIO, row) = & - nlc_last_merit_ratio + nlc_path_real(NLC_PATH_R_TRUST_MERIT_RATIO, row) = nlc_last_merit_ratio nlc_path_real(NLC_PATH_R_TOTAL_RESIDUAL, row) = & convergence_total_resid_norm nlc_path_real(NLC_PATH_R_FORCE_RESIDUAL, row) = & convergence_force_resid_norm nlc_path_real(NLC_PATH_R_CONTACT_RESIDUAL, row) = & convergence_contact_resid_norm - nlc_path_real(NLC_PATH_R_CONS_RESIDUAL, row) = & - convergence_cons_resid_norm - nlc_path_real(NLC_PATH_R_ARC_RESIDUAL, row) = & - convergence_arc_resid_norm + nlc_path_real(NLC_PATH_R_CONS_RESIDUAL, row) = convergence_cons_resid_norm + nlc_path_real(NLC_PATH_R_ARC_RESIDUAL, row) = convergence_arc_resid_norm nlc_path_real(NLC_PATH_R_ARC_LENGTH, row) = nlc_last_arc_length nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, row) = load_delta nlc_path_real(NLC_PATH_R_ARC_PREDICTOR_DOT, row) = & nlc_last_arc_predictor_dot + end subroutine nlc_path_store_real_diagnostics + + subroutine nlc_path_store_int(row, step, control_dof_count, iteration, & + status_code, failure_code, predictor_ok, & + load_reversal, turning_point) + integer, intent(in) :: row, step, control_dof_count, iteration + integer, intent(in) :: status_code, failure_code, predictor_ok + integer, intent(in) :: load_reversal, turning_point nlc_path_int(NLC_PATH_I_STEP, row) = step nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, row) = control_dof_count @@ -582,14 +625,10 @@ contains nlc_path_int(NLC_PATH_I_MATERIAL_FAIL_COUNT, row) = & convergence_material_fail_count nlc_path_int(NLC_PATH_I_ARC_MODE, row) = nlc_last_arc_mode - nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row) = & - predictor_consistent + nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row) = predictor_ok nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, row) = load_reversal nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, row) = turning_point - - nlc_path_count = row - ierr = FEM_SUCCESS - end subroutine nlc_path_append + end subroutine nlc_path_store_int integer function convergence_reason_from_failure(failure_code) result(reason_id) integer, intent(in) :: failure_code diff --git a/src/base/fem_precision.f90 b/src/base/fem_precision.f90 index e31a3a9..66eb284 100644 --- a/src/base/fem_precision.f90 +++ b/src/base/fem_precision.f90 @@ -16,7 +16,7 @@ module fem_precision integer, parameter :: FEMLITE_VERSION_MAJOR = 0 integer, parameter :: FEMLITE_VERSION_MINOR = 6 - integer, parameter :: FEMLITE_VERSION_PATCH = 1 + integer, parameter :: FEMLITE_VERSION_PATCH = 2 real(rk), parameter :: ZERO = 0.0_rk real(rk), parameter :: ONE = 1.0_rk diff --git a/src/output/fem_output_csv.f90 b/src/output/fem_output_csv.f90 index 6dac74d..c0ffe1c 100644 --- a/src/output/fem_output_csv.f90 +++ b/src/output/fem_output_csv.f90 @@ -19,6 +19,8 @@ module fem_output_csv character(len=256) :: csv_output_directory = '.' logical :: history_header_written = .false. logical :: lifecycle_header_written = .false. + integer, parameter :: PATH_CSV_COLUMN_COUNT = 60 + integer, parameter :: LIFE_CSV_COLUMN_COUNT = 38 contains @@ -369,26 +371,8 @@ 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 @@ -405,8 +389,47 @@ contains return end if - write(unit_id,'(A)',iostat=ios) & - 'step,time,control_parameter,control_dof_count,'// & + call write_path_header(unit_id, ios) + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to write continuation path CSV header', ierr) + return + end if + + call path_life_counts(lifecycle_accept_count, & + lifecycle_reject_count) + + do row = 1, nlc_path_count + call write_path_row(unit_id, row, lifecycle_accept_count, & + lifecycle_reject_count, ios) + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to write continuation path CSV row', ierr) + return + end if + end do + + close(unit_id) + call validate_path_csv(filename, ierr) + if (ierr .ne. FEM_SUCCESS) return + ierr = FEM_SUCCESS + end subroutine output_csv_write_path + + subroutine write_path_header(unit_id, ios) + integer, intent(in) :: unit_id + integer, intent(out) :: ios + character(len=2048) :: header + + call path_schema_header(header) + write(unit_id,'(A)',iostat=ios) trim(header) + end subroutine write_path_header + + subroutine path_schema_header(header) + character(len=*), intent(out) :: header + + header = 'step,time,control_parameter,control_dof_count,'// & 'prescribed_l2,prescribed_max,actual_l2,actual_max,'// & 'constraint_residual_linf,constraint_residual_l2,'// & 'control_reaction_sum,control_reaction_generalized,control_work,'// & @@ -425,112 +448,272 @@ contains 'lifecycle_accept_count,lifecycle_reject_count,'// & 'arc_mode,arc_predictor_consistent,arc_load_reversal,'// & 'arc_turning_point,arc_length,arc_load_delta,arc_predictor_dot' + end subroutine path_schema_header + + subroutine validate_path_csv(filename, ierr) + character(len=*), intent(in) :: filename + integer, intent(out) :: ierr + character(len=2048) :: expected + character(len=4096) :: line + integer :: unit_id + integer :: ios + integer :: expected_count + integer :: row_count + + call path_schema_header(expected) + unit_id = 70 + open(unit=unit_id, file=trim(filename), status='old', action='read', & + iostat=ios) if (ios .ne. 0) then - close(unit_id) call error_set(FEM_ERR_OUTPUT, & - 'failed to write continuation path CSV header', ierr) + 'failed to reopen continuation path CSV output', ierr) 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 + read(unit_id,'(A)',iostat=ios) line + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to read continuation path CSV header', ierr) + return + end if + if (trim(line) .ne. trim(expected)) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'continuation path CSV header does not match schema', ierr) + return + end if + if (.not. path_schema_required_ok(line)) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'continuation path CSV is missing required diagnostics', ierr) + return + end if - 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') & - nlc_path_int(NLC_PATH_I_STEP, row), & - ',', nlc_path_real(NLC_PATH_R_TIME, row), & - ',', nlc_path_real(NLC_PATH_R_PARAMETER, row), & - ',', nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, row), & - ',', nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, row), & - ',', nlc_path_real(NLC_PATH_R_PRESCRIBED_MAX, row), & - ',', nlc_path_real(NLC_PATH_R_ACTUAL_L2, row), & - ',', nlc_path_real(NLC_PATH_R_ACTUAL_MAX, row), & - ',', nlc_path_real(NLC_PATH_R_RESIDUAL_LINF, row), & - ',', nlc_path_real(NLC_PATH_R_RESIDUAL_L2, row), & - ',', nlc_path_real(NLC_PATH_R_REACTION_SUM, row), & - ',', nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, row), & - ',', nlc_path_real(NLC_PATH_R_WORK, row), & - ',', nlc_path_int(NLC_PATH_I_ITERATION, row), & - ',', nlc_path_real(NLC_PATH_R_RESIDUAL_NORM, row), & - ',', nlc_path_real(NLC_PATH_R_RELATIVE_RESIDUAL, row), & - ',', nlc_path_real(NLC_PATH_R_CORRECTION_NORM, row), & - ',', nlc_path_real(NLC_PATH_R_TARGET_DT, row), & - ',', nlc_path_real(NLC_PATH_R_ACTUAL_DT, row), & - ',', nlc_path_real(NLC_PATH_R_NEXT_DT, row), & - ',', nlc_path_real(NLC_PATH_R_TRUST_RADIUS, row), & - ',', nlc_path_real(NLC_PATH_R_NEXT_TRUST_RADIUS, row), & - ',', nlc_path_real(NLC_PATH_R_TRUST_DAMPING, row), & - ',', nlc_path_real(NLC_PATH_R_TRUST_MERIT_RATIO, row), & - ',', nlc_path_int(NLC_PATH_I_ADAPT_ADJUST, row), & - ',', nlc_path_int(NLC_PATH_I_CUTBACK_COUNT, row), & - ',', nlc_path_int(NLC_PATH_I_TRUST_ADJUST, row), & - ',', nlc_path_int(NLC_PATH_I_TRUST_REJECTIONS, row), & - ',', nlc_path_int(NLC_PATH_I_STATUS_CODE, row), & - ',', nlc_path_int(NLC_PATH_I_FAILURE_CODE, row), & - ',', nlc_path_int(NLC_PATH_I_LIN_METHOD, row), & - ',', nlc_path_int(NLC_PATH_I_LIN_PRECOND, row), & - ',', nlc_path_int(NLC_PATH_I_LIN_ITER, row), & - ',', nlc_path_int(NLC_PATH_I_LIN_STATUS, row), & - ',', nlc_path_real(NLC_PATH_R_LIN_INIT_RESID, row), & - ',', nlc_path_real(NLC_PATH_R_LIN_FINAL_RESID, row), & - ',', nlc_path_real(NLC_PATH_R_LIN_REL_RESID, row) - if (ios .eq. 0) then - write(unit_id,'(5(A,ES24.16),A,I12)',iostat=ios, advance='no') & - ',', nlc_path_real(NLC_PATH_R_TOTAL_RESIDUAL, row), & - ',', nlc_path_real(NLC_PATH_R_FORCE_RESIDUAL, row), & - ',', nlc_path_real(NLC_PATH_R_CONTACT_RESIDUAL, row), & - ',', nlc_path_real(NLC_PATH_R_CONS_RESIDUAL, row), & - ',', nlc_path_real(NLC_PATH_R_ARC_RESIDUAL, row), & - ',', nlc_path_int(NLC_PATH_I_MATERIAL_FAIL_COUNT, row) - end if - if (ios .eq. 0) then - write(unit_id,'(A,I12,A,A,A,I12,A,A,A,I12,A,A,8(A,I12),'// & - '3(A,ES24.16))', iostat=ios) & - ',', nlc_path_int(NLC_PATH_I_REASON_ID, row), & - ',', trim(reason_name), & - ',', NLC_EVENT_ACCEPT, ',', trim(event_name), & - ',', audit_status, ',', trim(audit_name), & - ',', nlc_path_int(NLC_PATH_I_STEP, row), & - ',', nlc_path_int(NLC_PATH_I_ITERATION, row), & - ',', lifecycle_accept_count, ',', lifecycle_reject_count, & - ',', nlc_path_int(NLC_PATH_I_ARC_MODE, row), & - ',', nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row), & - ',', nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, row), & - ',', nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, row), & - ',', nlc_path_real(NLC_PATH_R_ARC_LENGTH, row), & - ',', nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, row), & - ',', nlc_path_real(NLC_PATH_R_ARC_PREDICTOR_DOT, row) - end if + expected_count = csv_field_count(line) + if (expected_count .ne. PATH_CSV_COLUMN_COUNT) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'continuation path CSV schema column count changed', ierr) + return + end if + + row_count = 0 + do + read(unit_id,'(A)',iostat=ios) line + if (ios .lt. 0) exit if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, & - 'failed to write continuation path CSV row', ierr) + 'failed to read continuation path CSV row', ierr) + return + end if + row_count = row_count + 1 + if (csv_field_count(line) .ne. expected_count) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'continuation path CSV row does not match schema', ierr) return end if end do close(unit_id) + if (row_count .ne. nlc_path_count) then + call error_set(FEM_ERR_OUTPUT, & + 'continuation path CSV row count does not match path storage', ierr) + return + end if ierr = FEM_SUCCESS - end subroutine output_csv_write_path + end subroutine validate_path_csv + + logical function path_schema_required_ok(header) + character(len=*), intent(in) :: header + + path_schema_required_ok = & + index(header, 'linear_method') .gt. 0 .and. & + index(header, 'linear_precond') .gt. 0 .and. & + index(header, 'linear_iterations') .gt. 0 .and. & + index(header, 'linear_status') .gt. 0 .and. & + index(header, 'linear_initial_residual') .gt. 0 .and. & + index(header, 'linear_final_residual') .gt. 0 .and. & + index(header, 'linear_relative_residual') .gt. 0 .and. & + index(header, 'lifecycle_event_id') .gt. 0 .and. & + index(header, 'lifecycle_event_name') .gt. 0 .and. & + index(header, 'lifecycle_audit_status') .gt. 0 .and. & + index(header, 'lifecycle_audit_name') .gt. 0 .and. & + index(header, 'lifecycle_increment') .gt. 0 .and. & + index(header, 'lifecycle_iteration') .gt. 0 .and. & + index(header, 'lifecycle_accept_count') .gt. 0 .and. & + index(header, 'lifecycle_reject_count') .gt. 0 .and. & + index(header, 'residual_arc') .gt. 0 .and. & + index(header, 'arc_mode') .gt. 0 .and. & + index(header, 'arc_predictor_consistent') .gt. 0 .and. & + index(header, 'arc_load_reversal') .gt. 0 .and. & + index(header, 'arc_turning_point') .gt. 0 .and. & + index(header, 'arc_length') .gt. 0 .and. & + index(header, 'arc_load_delta') .gt. 0 .and. & + index(header, 'arc_predictor_dot') .gt. 0 + end function path_schema_required_ok + + integer function csv_field_count(line) + character(len=*), intent(in) :: line + integer :: i + integer :: n + + n = len_trim(line) + if (n .le. 0) then + csv_field_count = 0 + return + end if + csv_field_count = 1 + do i = 1, n + if (line(i:i) .eq. ',') csv_field_count = csv_field_count + 1 + end do + end function csv_field_count + + subroutine path_life_counts(accept_count, reject_count) + integer, intent(out) :: accept_count + integer, intent(out) :: reject_count + integer :: event_total + integer :: event_index + integer :: step + integer :: increment + integer :: iteration + integer :: event_id + integer :: reason_id + character(len=64) :: event_name + character(len=64) :: reason_name + + accept_count = 0 + reject_count = 0 + event_total = nl_lifecycle_get_event_count() + do event_index = 1, event_total + call nl_lifecycle_get_event(event_index, step, increment, iteration, & + event_id, event_name, reason_id, reason_name) + if (event_id .eq. NLC_EVENT_ACCEPT) then + accept_count = accept_count + 1 + else if (event_id .eq. NLC_EVENT_REJECT) then + reject_count = reject_count + 1 + end if + end do + end subroutine path_life_counts + + subroutine write_path_row(unit_id, row, lifecycle_accept_count, & + lifecycle_reject_count, ios) + integer, intent(in) :: unit_id + integer, intent(in) :: row + integer, intent(in) :: lifecycle_accept_count + integer, intent(in) :: lifecycle_reject_count + integer, intent(out) :: ios + integer :: audit_status + integer :: audit_begin_trial + integer :: audit_rollback_requested + integer :: audit_rollback_ok + integer :: audit_rollback_failed + integer :: audit_commit_ok + character(len=64) :: reason_name + character(len=64) :: event_name + character(len=64) :: audit_name + + 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) + call write_path_prefix(unit_id, row, ios) + if (ios .eq. 0) call write_path_resid(unit_id, row, ios) + if (ios .eq. 0) call write_path_tail(unit_id, row, & + lifecycle_accept_count, lifecycle_reject_count, audit_status, & + reason_name, event_name, audit_name, ios) + end subroutine write_path_row + + subroutine write_path_prefix(unit_id, row, ios) + integer, intent(in) :: unit_id + integer, intent(in) :: row + integer, intent(out) :: ios + + 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') & + nlc_path_int(NLC_PATH_I_STEP, row), & + ',', nlc_path_real(NLC_PATH_R_TIME, row), & + ',', nlc_path_real(NLC_PATH_R_PARAMETER, row), & + ',', nlc_path_int(NLC_PATH_I_CONTROL_DOF_COUNT, row), & + ',', nlc_path_real(NLC_PATH_R_PRESCRIBED_L2, row), & + ',', nlc_path_real(NLC_PATH_R_PRESCRIBED_MAX, row), & + ',', nlc_path_real(NLC_PATH_R_ACTUAL_L2, row), & + ',', nlc_path_real(NLC_PATH_R_ACTUAL_MAX, row), & + ',', nlc_path_real(NLC_PATH_R_RESIDUAL_LINF, row), & + ',', nlc_path_real(NLC_PATH_R_RESIDUAL_L2, row), & + ',', nlc_path_real(NLC_PATH_R_REACTION_SUM, row), & + ',', nlc_path_real(NLC_PATH_R_REACTION_GENERALIZED, row), & + ',', nlc_path_real(NLC_PATH_R_WORK, row), & + ',', nlc_path_int(NLC_PATH_I_ITERATION, row), & + ',', nlc_path_real(NLC_PATH_R_RESIDUAL_NORM, row), & + ',', nlc_path_real(NLC_PATH_R_RELATIVE_RESIDUAL, row), & + ',', nlc_path_real(NLC_PATH_R_CORRECTION_NORM, row), & + ',', nlc_path_real(NLC_PATH_R_TARGET_DT, row), & + ',', nlc_path_real(NLC_PATH_R_ACTUAL_DT, row), & + ',', nlc_path_real(NLC_PATH_R_NEXT_DT, row), & + ',', nlc_path_real(NLC_PATH_R_TRUST_RADIUS, row), & + ',', nlc_path_real(NLC_PATH_R_NEXT_TRUST_RADIUS, row), & + ',', nlc_path_real(NLC_PATH_R_TRUST_DAMPING, row), & + ',', nlc_path_real(NLC_PATH_R_TRUST_MERIT_RATIO, row), & + ',', nlc_path_int(NLC_PATH_I_ADAPT_ADJUST, row), & + ',', nlc_path_int(NLC_PATH_I_CUTBACK_COUNT, row), & + ',', nlc_path_int(NLC_PATH_I_TRUST_ADJUST, row), & + ',', nlc_path_int(NLC_PATH_I_TRUST_REJECTIONS, row), & + ',', nlc_path_int(NLC_PATH_I_STATUS_CODE, row), & + ',', nlc_path_int(NLC_PATH_I_FAILURE_CODE, row), & + ',', nlc_path_int(NLC_PATH_I_LIN_METHOD, row), & + ',', nlc_path_int(NLC_PATH_I_LIN_PRECOND, row), & + ',', nlc_path_int(NLC_PATH_I_LIN_ITER, row), & + ',', nlc_path_int(NLC_PATH_I_LIN_STATUS, row), & + ',', nlc_path_real(NLC_PATH_R_LIN_INIT_RESID, row), & + ',', nlc_path_real(NLC_PATH_R_LIN_FINAL_RESID, row), & + ',', nlc_path_real(NLC_PATH_R_LIN_REL_RESID, row) + end subroutine write_path_prefix + + subroutine write_path_resid(unit_id, row, ios) + integer, intent(in) :: unit_id + integer, intent(in) :: row + integer, intent(out) :: ios + + write(unit_id,'(5(A,ES24.16),A,I12)',iostat=ios, advance='no') & + ',', nlc_path_real(NLC_PATH_R_TOTAL_RESIDUAL, row), & + ',', nlc_path_real(NLC_PATH_R_FORCE_RESIDUAL, row), & + ',', nlc_path_real(NLC_PATH_R_CONTACT_RESIDUAL, row), & + ',', nlc_path_real(NLC_PATH_R_CONS_RESIDUAL, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_RESIDUAL, row), & + ',', nlc_path_int(NLC_PATH_I_MATERIAL_FAIL_COUNT, row) + end subroutine write_path_resid + + subroutine write_path_tail(unit_id, row, accept_count, reject_count, & + audit_status, reason_name, event_name, & + audit_name, ios) + integer, intent(in) :: unit_id, row, accept_count, reject_count + integer, intent(in) :: audit_status + character(len=*), intent(in) :: reason_name, event_name, audit_name + integer, intent(out) :: ios + + write(unit_id,'(A,I12,A,A,A,I12,A,A,A,I12,A,A,8(A,I12),'// & + '3(A,ES24.16))', iostat=ios) & + ',', nlc_path_int(NLC_PATH_I_REASON_ID, row), & + ',', trim(reason_name), & + ',', NLC_EVENT_ACCEPT, ',', trim(event_name), & + ',', audit_status, ',', trim(audit_name), & + ',', nlc_path_int(NLC_PATH_I_STEP, row), & + ',', nlc_path_int(NLC_PATH_I_ITERATION, row), & + ',', accept_count, ',', reject_count, & + ',', nlc_path_int(NLC_PATH_I_ARC_MODE, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_PRED_OK, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, row), & + ',', nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_LENGTH, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, row), & + ',', nlc_path_real(NLC_PATH_R_ARC_PREDICTOR_DOT, row) + end subroutine write_path_tail subroutine output_csv_write_nl_lifecycle(ierr) integer, intent(out) :: ierr @@ -579,20 +762,7 @@ contains end if if (.not. lifecycle_header_written) then - write(unit_id,'(A)',iostat=ios) & - 'step,increment,iteration,event_id,event_name,reason_id,'// & - 'reason_name,convergence_status,failure_code,'// & - 'failure_reason_id,failure_reason_name,cutback_reason_id,'// & - 'cutback_reason_name,residual_total,residual_force,'// & - 'residual_contact,residual_constraint,residual_arc,'// & - 'material_failure_count,linear_matrix_class,linear_status,'// & - 'linear_method,linear_precond,linear_iterations,'// & - 'linear_initial_residual,linear_final_residual,'// & - 'linear_relative_residual,linear_fail_class,'// & - 'audit_status,audit_name,audit_begin_trial,'// & - 'audit_rollback_requested,audit_rollback_ok,'// & - 'audit_rollback_failed,audit_commit_ok,accept_count,'// & - 'reject_count,cutback_count' + call write_life_header(unit_id, ios) if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, & @@ -619,34 +789,13 @@ contains return end if - write(unit_id,'(I12,3(A,I12),A,A,A,I12,A,A,3(A,I12),'// & - 'A,A,A,I12,A,A)',iostat=ios, advance='no') & - step, ',', increment, ',', iteration, ',', event_id, & - ',', trim(event_name), ',', reason_id, ',', trim(reason_name), & - ',', convergence_status_code, ',', convergence_failure_code, & - ',', convergence_failure_reason_id, ',', trim(failure_reason_name), & - ',', conv_last_cutback_reason_id, ',', trim(cutback_reason_name_text) - if (ios .eq. 0) then - write(unit_id,'(5(A,ES24.16),6(A,I12),3(A,ES24.16),'// & - '2(A,I12),A,A,8(A,I12))', & - iostat=ios) & - ',', convergence_total_resid_norm, & - ',', convergence_force_resid_norm, & - ',', convergence_contact_resid_norm, & - ',', convergence_cons_resid_norm, & - ',', convergence_arc_resid_norm, & - ',', convergence_material_fail_count, & - ',', linear_matrix_class, ',', linear_status, & - ',', linear_solver_last_method, ',', linear_solver_last_prec, & - ',', linear_solver_last_iter, & - ',', linear_initial_residual, ',', linear_final_residual, & - ',', linear_relative_residual, ',', linsol_last_fail_class, & - ',', audit_status, ',', trim(audit_name), & - ',', begin_trial_count, ',', rollback_requested_count, & - ',', rollback_ok_count, ',', rollback_failed_count, & - ',', commit_ok_count, ',', accept_count, ',', reject_count, & - ',', cutback_count - end if + call write_life_row(unit_id, step, increment, iteration, event_id, & + reason_id, audit_status, begin_trial_count, rollback_requested_count, & + rollback_ok_count, rollback_failed_count, commit_ok_count, & + accept_count, reject_count, cutback_count, linear_matrix_class, & + linear_status, linear_initial_residual, linear_final_residual, & + linear_relative_residual, event_name, reason_name, audit_name, & + failure_reason_name, cutback_reason_name_text, ios) if (ios .ne. 0) then close(unit_id) call error_set(FEM_ERR_OUTPUT, & @@ -656,9 +805,196 @@ contains close(unit_id) lifecycle_header_written = .true. + call validate_life_csv(filename, ierr) + if (ierr .ne. FEM_SUCCESS) return ierr = FEM_SUCCESS end subroutine output_csv_write_nl_lifecycle + subroutine write_life_header(unit_id, ios) + integer, intent(in) :: unit_id + integer, intent(out) :: ios + character(len=2048) :: header + + call life_schema_header(header) + write(unit_id,'(A)',iostat=ios) trim(header) + end subroutine write_life_header + + subroutine life_schema_header(header) + character(len=*), intent(out) :: header + + header = 'step,increment,iteration,event_id,event_name,reason_id,'// & + 'reason_name,convergence_status,failure_code,'// & + 'failure_reason_id,failure_reason_name,cutback_reason_id,'// & + 'cutback_reason_name,residual_total,residual_force,'// & + 'residual_contact,residual_constraint,residual_arc,'// & + 'material_failure_count,linear_matrix_class,linear_status,'// & + 'linear_method,linear_precond,linear_iterations,'// & + 'linear_initial_residual,linear_final_residual,'// & + 'linear_relative_residual,linear_fail_class,'// & + 'audit_status,audit_name,audit_begin_trial,'// & + 'audit_rollback_requested,audit_rollback_ok,'// & + 'audit_rollback_failed,audit_commit_ok,accept_count,'// & + 'reject_count,cutback_count' + end subroutine life_schema_header + + subroutine write_life_row(unit_id, step, increment, iteration, event_id, & + reason_id, audit_status, begin_trial_count, & + rollback_requested_count, rollback_ok_count, & + rollback_failed_count, commit_ok_count, & + accept_count, reject_count, cutback_count, & + linear_matrix_class, linear_status, & + linear_initial_residual, linear_final_residual, & + linear_relative_residual, event_name, & + reason_name, audit_name, failure_reason_name, & + cutback_reason_name_text, ios) + integer, intent(in) :: unit_id + integer, intent(in) :: step, increment, iteration, event_id, reason_id + integer, intent(in) :: audit_status + integer, intent(in) :: begin_trial_count, rollback_requested_count + integer, intent(in) :: rollback_ok_count, rollback_failed_count + integer, intent(in) :: commit_ok_count, accept_count, reject_count + integer, intent(in) :: cutback_count, linear_matrix_class, linear_status + real(rk), intent(in) :: linear_initial_residual, linear_final_residual + real(rk), intent(in) :: linear_relative_residual + character(len=*), intent(in) :: event_name, reason_name, audit_name + character(len=*), intent(in) :: failure_reason_name + character(len=*), intent(in) :: cutback_reason_name_text + integer, intent(out) :: ios + + write(unit_id,'(I12,3(A,I12),A,A,A,I12,A,A,3(A,I12),'// & + 'A,A,A,I12,A,A)',iostat=ios, advance='no') & + step, ',', increment, ',', iteration, ',', event_id, & + ',', trim(event_name), ',', reason_id, ',', trim(reason_name), & + ',', convergence_status_code, ',', convergence_failure_code, & + ',', convergence_failure_reason_id, ',', trim(failure_reason_name), & + ',', conv_last_cutback_reason_id, ',', trim(cutback_reason_name_text) + if (ios .ne. 0) return + write(unit_id,'(5(A,ES24.16),6(A,I12),3(A,ES24.16),'// & + '2(A,I12),A,A,8(A,I12))', iostat=ios) & + ',', convergence_total_resid_norm, & + ',', convergence_force_resid_norm, & + ',', convergence_contact_resid_norm, & + ',', convergence_cons_resid_norm, & + ',', convergence_arc_resid_norm, & + ',', convergence_material_fail_count, & + ',', linear_matrix_class, ',', linear_status, & + ',', linear_solver_last_method, ',', linear_solver_last_prec, & + ',', linear_solver_last_iter, & + ',', linear_initial_residual, ',', linear_final_residual, & + ',', linear_relative_residual, ',', linsol_last_fail_class, & + ',', audit_status, ',', trim(audit_name), & + ',', begin_trial_count, ',', rollback_requested_count, & + ',', rollback_ok_count, ',', rollback_failed_count, & + ',', commit_ok_count, ',', accept_count, ',', reject_count, & + ',', cutback_count + end subroutine write_life_row + + subroutine validate_life_csv(filename, ierr) + character(len=*), intent(in) :: filename + integer, intent(out) :: ierr + character(len=2048) :: expected + character(len=4096) :: line + integer :: unit_id + integer :: ios + integer :: expected_count + + call life_schema_header(expected) + unit_id = 71 + open(unit=unit_id, file=trim(filename), status='old', action='read', & + iostat=ios) + if (ios .ne. 0) then + call error_set(FEM_ERR_OUTPUT, & + 'failed to reopen nonlinear lifecycle CSV output', ierr) + return + end if + + read(unit_id,'(A)',iostat=ios) line + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to read nonlinear lifecycle CSV header', ierr) + return + end if + if (trim(line) .ne. trim(expected)) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'nonlinear lifecycle CSV header does not match schema', ierr) + return + end if + if (.not. life_schema_required_ok(line)) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'nonlinear lifecycle CSV is missing required diagnostics', ierr) + return + end if + + expected_count = csv_field_count(line) + if (expected_count .ne. LIFE_CSV_COLUMN_COUNT) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'nonlinear lifecycle CSV schema column count changed', ierr) + return + end if + + do + read(unit_id,'(A)',iostat=ios) line + if (ios .lt. 0) exit + if (ios .ne. 0) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'failed to read nonlinear lifecycle CSV row', ierr) + return + end if + if (csv_field_count(line) .ne. expected_count) then + close(unit_id) + call error_set(FEM_ERR_OUTPUT, & + 'nonlinear lifecycle CSV row does not match schema', ierr) + return + end if + end do + + close(unit_id) + ierr = FEM_SUCCESS + end subroutine validate_life_csv + + logical function life_schema_required_ok(header) + character(len=*), intent(in) :: header + + life_schema_required_ok = & + index(header, 'event_id') .gt. 0 .and. & + index(header, 'event_name') .gt. 0 .and. & + index(header, 'reason_id') .gt. 0 .and. & + index(header, 'reason_name') .gt. 0 .and. & + index(header, 'convergence_status') .gt. 0 .and. & + index(header, 'failure_code') .gt. 0 .and. & + index(header, 'failure_reason_id') .gt. 0 .and. & + index(header, 'cutback_reason_id') .gt. 0 .and. & + index(header, 'residual_total') .gt. 0 .and. & + index(header, 'residual_force') .gt. 0 .and. & + index(header, 'residual_contact') .gt. 0 .and. & + index(header, 'residual_constraint') .gt. 0 .and. & + index(header, 'residual_arc') .gt. 0 .and. & + index(header, 'linear_matrix_class') .gt. 0 .and. & + index(header, 'linear_status') .gt. 0 .and. & + index(header, 'linear_method') .gt. 0 .and. & + index(header, 'linear_precond') .gt. 0 .and. & + index(header, 'linear_iterations') .gt. 0 .and. & + index(header, 'linear_initial_residual') .gt. 0 .and. & + index(header, 'linear_final_residual') .gt. 0 .and. & + index(header, 'linear_relative_residual') .gt. 0 .and. & + index(header, 'linear_fail_class') .gt. 0 .and. & + index(header, 'audit_status') .gt. 0 .and. & + index(header, 'audit_name') .gt. 0 .and. & + index(header, 'audit_begin_trial') .gt. 0 .and. & + index(header, 'audit_rollback_requested') .gt. 0 .and. & + index(header, 'audit_rollback_ok') .gt. 0 .and. & + index(header, 'audit_rollback_failed') .gt. 0 .and. & + index(header, 'audit_commit_ok') .gt. 0 .and. & + index(header, 'accept_count') .gt. 0 .and. & + index(header, 'reject_count') .gt. 0 .and. & + index(header, 'cutback_count') .gt. 0 + end function life_schema_required_ok + subroutine output_csv_write_elements(step, ierr) integer, intent(in) :: step integer, intent(out) :: ierr diff --git a/src/solver/fem_linear_solver_dispatch.f90 b/src/solver/fem_linear_solver_dispatch.f90 index 6c11eaa..ca170b2 100644 --- a/src/solver/fem_linear_solver_dispatch.f90 +++ b/src/solver/fem_linear_solver_dispatch.f90 @@ -130,6 +130,7 @@ contains if (method .ne. LSOLVER_CG .and. method .ne. LSOLVER_BICGSTAB .and. & method .ne. LSOLVER_GMRES .and. method .ne. LSOLVER_DENSE) then + call record_config_fail('invalid-method') call error_set(FEM_ERR_SOLVER, 'invalid linear solver method', ierr) return end if @@ -137,6 +138,7 @@ contains preconditioner .ne. LPRECOND_JACOBI .and. & preconditioner .ne. LPRECOND_GAUSS_SEIDEL .and. & preconditioner .ne. LPRECOND_ILU0) then + call record_config_fail('invalid-preconditioner') call error_set(FEM_ERR_SOLVER, 'invalid linear preconditioner', ierr) return end if @@ -146,6 +148,14 @@ contains ierr = FEM_SUCCESS end subroutine linear_solver_configure + subroutine record_config_fail(context) + character(len=*), intent(in) :: context + + linear_solver_last_status = LS_STATUS_FAILED + linsol_last_fail_class = LS_FAIL_CONFIGURATION + linear_solver_last_reason = trim(context)//'-linear-configuration-failure' + end subroutine record_config_fail + subroutine linear_solver_get_settings(method, preconditioner, ierr) integer, intent(out) :: method integer, intent(out) :: preconditioner diff --git a/tests/data/s3_static_finite_strain_unsupported.inp b/tests/data/s3_static_finite_strain_unsupported.inp new file mode 100644 index 0000000..b2f7913 --- /dev/null +++ b/tests/data/s3_static_finite_strain_unsupported.inp @@ -0,0 +1,27 @@ +*HEADING +FemLite S3 finite-strain shell unsupported boundary check +*NODE +1, 0.0, 0.0, 0.0 +2, 1.0, 0.0, 0.0 +3, 0.0, 1.0, 0.0 +*ELEMENT, TYPE=S3, ELSET=EALL +1, 1, 2, 3 +*MATERIAL, NAME=MAT +*DENSITY +1.0 +*ELASTIC +30.0, 0.25 +*SHELL SECTION, ELSET=EALL, MATERIAL=MAT +0.2 +*BOUNDARY +1, 1, 1, 0.0 +1, 2, 6, 0.0 +2, 1, 1, 0.01 +2, 2, 6, 0.0 +3, 1, 1, 0.0 +3, 2, 6, 0.0 +*STEP +*NONLINEAR CONTINUATION, METHOD=ADAPTIVE_TARGET_NEWTON, SHELL_GEOMETRIC=FINITE_STRAIN +*STATIC +1.0, 1.0, 0.1, 1.0 +*END STEP diff --git a/tests/interface/test_c_api.c b/tests/interface/test_c_api.c index a789e51..9f4f690 100644 --- a/tests/interface/test_c_api.c +++ b/tests/interface/test_c_api.c @@ -113,7 +113,7 @@ int main(void) ierr = femlite_get_version(&major, &minor, &patch); if (ierr != 0) return check_ierr(ierr, 2); - if (major != 0 || minor != 6 || patch != 1) return 3; + if (major != 0 || minor != 6 || patch != 2) return 3; ierr = femlite_read_inp("examples/c3d4_one_element.inp"); if (ierr != 0) return check_ierr(ierr, 4); diff --git a/tests/module/test_contact.f90 b/tests/module/test_contact.f90 index bcb7ae4..12f0d8c 100644 --- a/tests/module/test_contact.f90 +++ b/tests/module/test_contact.f90 @@ -28,6 +28,7 @@ program test_contact real(rk), parameter :: TOL = 1.0e-10_rk call check_contact_state_names() + call check_contact_state_edges() call check_plane_force() call check_target_node_only() call check_analytic_pair_plane_force() @@ -64,6 +65,57 @@ contains if (trim(name) .ne. 'unknown') call fail(9106) end subroutine check_contact_state_names + subroutine check_contact_state_edges() + integer :: ierr + integer :: open_count + integer :: closed_stick_count + integer :: closed_slip_count + integer :: closed_restick_count + integer :: separating_count + integer :: failed_projection_count + integer :: active_set_flip_count + real(rk) :: gap_max + real(rk) :: gap_mean + real(rk) :: gap_l2 + real(rk) :: slip_increment + real(rk) :: slip_residual + real(rk) :: friction_residual + + call contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count) + if (open_count + closed_stick_count + closed_slip_count + & + closed_restick_count + separating_count + failed_projection_count & + .ne. 0) call fail(9110) + call check_close(gap_max, ZERO, 9111) + call check_close(gap_mean, ZERO, 9112) + call check_close(gap_l2, ZERO, 9113) + call check_close(slip_increment, ZERO, 9114) + call check_close(slip_residual, ZERO, 9115) + call check_close(friction_residual, ZERO, 9116) + if (active_set_flip_count .ne. 0) call fail(9117) + + call fem_initialize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(9120) + call setup_basic_nodes(1, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(9121) + call database_allocate_contact_pair(1, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(9122) + contact_pair_status(1) = -999 + call contact_get_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count) + if (failed_projection_count .ne. 1) call fail(9123) + if (open_count + closed_stick_count + closed_slip_count + & + closed_restick_count + separating_count .ne. 0) call fail(9124) + call check_close(gap_max, ZERO, 9125) + if (active_set_flip_count .ne. 0) call fail(9126) + call fem_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(9127) + end subroutine check_contact_state_edges + subroutine check_multiplier_history() integer :: ierr integer :: slot_count @@ -346,10 +398,47 @@ contains if (separating_count .ne. 1) call fail(172) if (active_set_flip_count .ne. 2) call fail(173) + call check_pair_recontact_state(dof, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(144) end subroutine check_pair_active_set_augmented + subroutine check_pair_recontact_state(dof, ierr) + integer, intent(in) :: dof + integer, intent(out) :: ierr + integer :: open_count + integer :: closed_stick_count + integer :: closed_slip_count + integer :: closed_restick_count + integer :: separating_count + integer :: failed_projection_count + integer :: active_set_flip_count + real(rk) :: gap_max + real(rk) :: gap_mean + real(rk) :: gap_l2 + real(rk) :: slip_increment + real(rk) :: slip_residual + real(rk) :: friction_residual + + u(dof) = -0.01_rk + call contact_apply_plane_forces(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(174) + if (contact_pair_status(1) .ne. CONTACT_PAIR_ACTIVATED) call fail(175) + if (contact_pair_activation_count(1) .ne. 2) call fail(176) + if (contact_pair_release_count(1) .ne. 1) call fail(177) + call fem_get_contact_state_summary(open_count, closed_stick_count, & + closed_slip_count, closed_restick_count, separating_count, & + failed_projection_count, gap_max, gap_mean, gap_l2, slip_increment, & + slip_residual, friction_residual, active_set_flip_count, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(178) + if (separating_count .ne. 0) call fail(179) + if (closed_stick_count .ne. 1) call fail(180) + if (failed_projection_count .ne. 0) call fail(181) + if (active_set_flip_count .ne. 3) call fail(182) + end subroutine check_pair_recontact_state + subroutine check_explicit_contact_step() integer :: ierr integer :: dof diff --git a/tests/module/test_implicit_inp.f90 b/tests/module/test_implicit_inp.f90 index fc85f8d..e094861 100644 --- a/tests/module/test_implicit_inp.f90 +++ b/tests/module/test_implicit_inp.f90 @@ -53,6 +53,7 @@ program test_implicit_inp call check_nlc_inp() call check_arc_disp_continuation_api() call check_sph_zero_int() + call check_shell_finite_unsupported() call check_implicit_newmark_inp() call check_contact_pair_inp() @@ -807,6 +808,8 @@ contains nlc_trust_shrink_factor = 0.35_rk nlc_trust_accept_ratio = 0.1_rk nlc_trust_good_ratio = 0.7_rk + nlc_arc_length_radius = 0.25_rk + nlc_arc_load_scale = 2.0_rk call parse_nlc_header( & '*NONLINEAR CONTINUATION, METHOD=ADAPTIVE_TARGET_NEWTON,'// & ' TARGET_NEWTON=0', ierr) @@ -827,6 +830,20 @@ contains call check_close(nlc_trust_accept_ratio, 0.1_rk, 1216) call check_close(nlc_trust_good_ratio, 0.7_rk, 1217) + call parse_nlc_header( & + '*NONLINEAR CONTINUATION, METHOD=ARC_LENGTH_OR_DISPLACEMENT_CONTROL,'// & + ' ARC_LENGTH=-0.1', ierr) + if (ierr .eq. 0) call fail(1282) + call check_close(nlc_arc_length_radius, 0.25_rk, 1283) + call check_close(nlc_arc_load_scale, 2.0_rk, 1284) + + call parse_nlc_header( & + '*NONLINEAR CONTINUATION, METHOD=ARC_LENGTH_OR_DISPLACEMENT_CONTROL,'// & + ' ARC_LOAD_SCALE=0.0', ierr) + if (ierr .eq. 0) call fail(1285) + call check_close(nlc_arc_length_radius, 0.25_rk, 1286) + call check_close(nlc_arc_load_scale, 2.0_rk, 1287) + nlc_mc_min_substeps = 4 nlc_mc_max_substeps = 16 nlc_mc_target_strain = 1.0e-3_rk @@ -950,6 +967,34 @@ contains if (ierr .ne. 0) call fail(1255) end subroutine check_arc_disp_continuation_api + subroutine check_shell_finite_unsupported() + integer :: ierr + integer :: iter + integer :: error_code + real(rk) :: res_norm + character(len=256) :: message + + call fem_initialize(ierr) + if (ierr .ne. 0) call fail(1450) + call fem_read_inp('tests/data/s3_static_finite_strain_unsupported.inp', & + ierr) + if (ierr .ne. 0) call fail(1451) + if (.not. shell_finite_strain_requested) call fail(1452) + + call fem_build_model(ierr) + if (ierr .ne. 0) call fail(1453) + call fem_solve_static_nonlinear(1, 10, 1.0e-12_rk, iter, res_norm, ierr) + if (ierr .eq. 0) call fail(1454) + call fem_get_last_error(error_code, message, ierr) + if (ierr .ne. 0) call fail(1455) + if (index(trim(message), 'supports S4 elements only') .le. 0) & + call fail(1456) + if (.not. shell_finite_strain_requested) call fail(1457) + + call fem_finalize(ierr) + if (ierr .ne. 0) call fail(1458) + end subroutine check_shell_finite_unsupported + subroutine check_sph_zero_int() integer :: ierr real(rk) :: max_force diff --git a/tests/module/test_linear_solver_cg.f90 b/tests/module/test_linear_solver_cg.f90 index c6ccf1e..0f1659d 100644 --- a/tests/module/test_linear_solver_cg.f90 +++ b/tests/module/test_linear_solver_cg.f90 @@ -409,6 +409,7 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(92) if (method .ne. LSOLVER_CG) call fail(93) if (preconditioner .ne. LPRECOND_JACOBI) call fail(94) + call check_configuration_failure('invalid-method', 9001) call linear_solver_configure(LSOLVER_BICGSTAB, -99, ierr) if (ierr .eq. FEM_SUCCESS) call fail(95) @@ -416,6 +417,7 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(96) if (method .ne. LSOLVER_CG) call fail(97) if (preconditioner .ne. LPRECOND_JACOBI) call fail(98) + call check_configuration_failure('invalid-preconditioner', 9011) call linear_solver_configure(100, LPRECOND_JACOBI, ierr) if (ierr .eq. FEM_SUCCESS) call fail(99) @@ -423,8 +425,35 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(100) if (method .ne. LSOLVER_CG) call fail(101) if (preconditioner .ne. LPRECOND_JACOBI) call fail(102) + call check_configuration_failure('invalid-method', 9021) + end subroutine check_invalid_configuration + subroutine check_configuration_failure(expected_context, code_base) + character(len=*), intent(in) :: expected_context + integer, intent(in) :: code_base + integer :: ierr + integer :: matrix_class + integer :: status_code + integer :: failure_class + real(rk) :: initial_resid + real(rk) :: final_resid + real(rk) :: relative_resid + character(len=64) :: failure_reason + + call linear_solver_get_diagnostics(matrix_class, initial_resid, & + final_resid, relative_resid, status_code, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code_base) + if (status_code .ne. LS_STATUS_FAILED) call fail(code_base + 1) + call linear_solver_get_fail_info(failure_class, failure_reason, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code_base + 2) + if (failure_class .ne. LS_FAIL_CONFIGURATION) call fail(code_base + 3) + if (index(trim(failure_reason), trim(expected_context)) .le. 0) & + call fail(code_base + 4) + if (index(trim(failure_reason), & + 'linear-configuration-failure') .le. 0) call fail(code_base + 5) + end subroutine check_configuration_failure + subroutine make_tridiagonal(a, ierr) type(csr_matrix), intent(inout) :: a integer, intent(out) :: ierr diff --git a/tests/module/test_nonlinear_lifecycle.f90 b/tests/module/test_nonlinear_lifecycle.f90 index 0798e5d..b074d43 100644 --- a/tests/module/test_nonlinear_lifecycle.f90 +++ b/tests/module/test_nonlinear_lifecycle.f90 @@ -294,6 +294,8 @@ contains close(unit_id) if (ios .ne. 0) call fail(1034) call check_lifecycle_report_header(header, 1035) + if (csv_life_fields(header) .ne. 38) call fail(1046) + if (csv_life_fields(row_line) .ne. 38) call fail(1047) if (index(row_line, ',none,') .le. 0) call fail(1045) end subroutine check_lifecycle_report_empty @@ -434,8 +436,44 @@ contains if (index(header, 'audit_status') .le. 0) call fail(code_base + 7) if (index(header, 'accept_count') .le. 0) call fail(code_base + 8) if (index(header, 'reject_count') .le. 0) call fail(code_base + 9) + if (index(header, 'failure_reason_id') .le. 0) call fail(code_base + 10) + if (index(header, 'failure_reason_name') .le. 0) call fail(code_base + 11) + if (index(header, 'cutback_reason_name') .le. 0) call fail(code_base + 12) + if (index(header, 'residual_force') .le. 0) call fail(code_base + 13) + if (index(header, 'residual_contact') .le. 0) call fail(code_base + 14) + if (index(header, 'residual_constraint') .le. 0) call fail(code_base + 15) + if (index(header, 'residual_arc') .le. 0) call fail(code_base + 16) + if (index(header, 'linear_matrix_class') .le. 0) call fail(code_base + 17) + if (index(header, 'linear_method') .le. 0) call fail(code_base + 18) + if (index(header, 'linear_precond') .le. 0) call fail(code_base + 19) + if (index(header, 'linear_iterations') .le. 0) call fail(code_base + 20) + if (index(header, 'linear_initial_residual') .le. 0) & + call fail(code_base + 21) + if (index(header, 'linear_final_residual') .le. 0) & + call fail(code_base + 22) + if (index(header, 'linear_relative_residual') .le. 0) & + call fail(code_base + 23) + if (index(header, 'linear_fail_class') .le. 0) call fail(code_base + 24) + if (index(header, 'audit_rollback_failed') .le. 0) & + call fail(code_base + 25) end subroutine check_lifecycle_report_header + integer function csv_life_fields(line) + character(len=*), intent(in) :: line + integer :: i + integer :: n + + n = len_trim(line) + if (n .le. 0) then + csv_life_fields = 0 + return + end if + csv_life_fields = 1 + do i = 1, n + if (line(i:i) .eq. ',') csv_life_fields = csv_life_fields + 1 + end do + end function csv_life_fields + subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_nonlinear_lifecycle failed:', code diff --git a/tests/module/test_restart.f90 b/tests/module/test_restart.f90 index 149e17f..2e7b7e6 100644 --- a/tests/module/test_restart.f90 +++ b/tests/module/test_restart.f90 @@ -38,9 +38,55 @@ program test_restart 'build-wsl-debug/lifecycle_restart.frs' character(len=*), parameter :: LEGACY_LIFECYCLE_RESTART_FILE = & 'build-wsl-debug/lifecycle_restart_legacy.frs' + character(len=*), parameter :: BAD_LIFECYCLE_RESTART_FILE = & + 'build-wsl-debug/lifecycle_restart_bad.frs' character(len=*), parameter :: EACH_ACCEPT_RESTART_FILE = & 'build-wsl-debug/restart_after_each_accept.frs' + type contact_restart_snapshot + integer :: slots = 0 + integer :: hist_slots = 0 + integer :: stick = 0 + integer :: slip_state = 0 + integer :: stable_slots = 0 + integer :: state_open = 0 + integer :: state_stick = 0 + integer :: state_slip = 0 + integer :: state_restick = 0 + integer :: state_separating = 0 + integer :: state_failed = 0 + integer :: active_summary = 0 + integer :: active_pair = 0 + integer :: activated_pair = 0 + integer :: maintained_pair = 0 + integer :: released_pair = 0 + integer :: pair_open = 0 + integer :: pair_stick = 0 + integer :: pair_slip = 0 + integer :: pair_restick = 0 + integer :: pair_separating = 0 + integer :: pair_failed = 0 + integer :: pair_flip = 0 + real(rk) :: slip = ZERO + real(rk) :: work = ZERO + real(rk) :: tangent = ZERO + real(rk) :: work_step = ZERO + real(rk) :: work_total = ZERO + real(rk) :: max_pen = ZERO + real(rk) :: force_norm = ZERO + real(rk) :: max_gap = ZERO + real(rk) :: max_aug = ZERO + real(rk) :: fric_step = ZERO + real(rk) :: fric_total = ZERO + real(rk) :: max_slip = ZERO + real(rk) :: pair_gap_max = ZERO + real(rk) :: pair_gap_mean = ZERO + real(rk) :: pair_gap_l2 = ZERO + real(rk) :: pair_slip_inc = ZERO + real(rk) :: pair_slip_resid = ZERO + real(rk) :: pair_fric_resid = ZERO + end type contact_restart_snapshot + integer :: ierr integer :: ref_step integer :: rst_step @@ -166,233 +212,184 @@ contains subroutine check_contact_history_restart(ierr) integer, intent(out) :: ierr - integer :: slots_before - integer :: slots_after - real(rk) :: slip_before - real(rk) :: work_before - real(rk) :: tangent_before - real(rk) :: slip_after - real(rk) :: work_after - real(rk) :: tangent_after - integer :: hist_slots_before - integer :: stick_before - integer :: slip_state_before - integer :: hist_slots_after - integer :: stick_after - integer :: slip_state_after - integer :: stable_slots_before - integer :: state_open_before - integer :: state_stick_before - integer :: state_slip_before - integer :: state_restick_before - integer :: state_separating_before - integer :: state_failed_before - integer :: stable_slots_after - integer :: state_open_after - integer :: state_stick_after - integer :: state_slip_after - integer :: state_restick_after - integer :: state_separating_after - integer :: state_failed_after - integer :: active_summary_before - integer :: active_summary_after - integer :: active_pair_before - integer :: activated_pair_before - integer :: maintained_pair_before - integer :: released_pair_before - integer :: active_pair_after - integer :: activated_pair_after - integer :: maintained_pair_after - integer :: released_pair_after - real(rk) :: work_step_before - real(rk) :: work_total_before - real(rk) :: max_pen_before - real(rk) :: force_norm_before - real(rk) :: work_step_after - real(rk) :: work_total_after - real(rk) :: max_pen_after - real(rk) :: force_norm_after - real(rk) :: max_gap_before - real(rk) :: max_aug_before - real(rk) :: max_gap_after - real(rk) :: max_aug_after - real(rk) :: fric_step_before - real(rk) :: fric_total_before - real(rk) :: max_slip_before - real(rk) :: fric_step_after - real(rk) :: fric_total_after - real(rk) :: max_slip_after - integer :: pair_open_before - integer :: pair_stick_before - integer :: pair_slip_before - integer :: pair_restick_before - integer :: pair_separating_before - integer :: pair_failed_before - integer :: pair_flip_before - integer :: pair_open_after - integer :: pair_stick_after - integer :: pair_slip_after - integer :: pair_restick_after - integer :: pair_separating_after - integer :: pair_failed_after - integer :: pair_flip_after - real(rk) :: pair_gap_max_before - real(rk) :: pair_gap_mean_before - real(rk) :: pair_gap_l2_before - real(rk) :: pair_slip_inc_before - real(rk) :: pair_slip_resid_before - real(rk) :: pair_fric_resid_before - real(rk) :: pair_gap_max_after - real(rk) :: pair_gap_mean_after - real(rk) :: pair_gap_l2_after - real(rk) :: pair_slip_inc_after - real(rk) :: pair_slip_resid_after - real(rk) :: pair_fric_resid_after + type(contact_restart_snapshot) :: before + type(contact_restart_snapshot) :: after call prepare_contact_model(ierr) if (ierr .ne. FEM_SUCCESS) return call run_contact_steps(CONTACT_STEPS, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_summary(active_summary_before, work_step_before, & - work_total_before, max_pen_before, force_norm_before, ierr) + call capture_contact_snap(before, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_diagnostics(active_pair_before, & - activated_pair_before, maintained_pair_before, released_pair_before, & - max_gap_before, max_aug_before, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_friction(fric_step_before, fric_total_before, & - max_slip_before, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_state_summary(pair_open_before, pair_stick_before, & - pair_slip_before, pair_restick_before, pair_separating_before, & - pair_failed_before, pair_gap_max_before, pair_gap_mean_before, & - pair_gap_l2_before, pair_slip_inc_before, pair_slip_resid_before, & - pair_fric_resid_before, pair_flip_before, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_hist_stats(slots_before, slip_before, & - work_before, tangent_before, ierr) - if (ierr .ne. FEM_SUCCESS) return - call contact_history_state_stats(hist_slots_before, stick_before, & - slip_state_before) - call contact_history_stable_counts(stable_slots_before, & - state_open_before, state_stick_before, state_slip_before, & - state_restick_before, state_separating_before, state_failed_before) - - if (slots_before .le. 0) call fail(13) - if (slip_before .le. ZERO) call fail(14) - if (work_before .le. ZERO) call fail(15) - if (tangent_before .le. ZERO) call fail(16) - if (active_summary_before .le. 0) call fail(395) - if (active_pair_before .le. 0) call fail(396) - if (force_norm_before .le. ZERO) call fail(397) - if (max_gap_before .le. ZERO) call fail(398) - if (max_slip_before .le. ZERO) call fail(399) - if (pair_stick_before + pair_slip_before + pair_restick_before .le. 0) & - call fail(414) - if (pair_failed_before .ne. 0) call fail(415) - if (pair_gap_max_before .le. ZERO) call fail(416) - if (pair_gap_l2_before .lt. pair_gap_max_before) call fail(417) - if (pair_slip_inc_before .le. ZERO) call fail(418) - if (pair_slip_resid_before .lt. ZERO) call fail(419) - if (pair_fric_resid_before .le. ZERO) call fail(420) - if (pair_flip_before .le. 0) call fail(421) - if (hist_slots_before .ne. slots_before) call fail(360) - if (stick_before + slip_state_before .ne. hist_slots_before) & - call fail(361) - if (stable_slots_before .ne. hist_slots_before) call fail(367) - if (state_open_before .ne. 0) call fail(368) - if (state_stick_before .ne. stick_before) call fail(369) - if (state_slip_before .ne. slip_state_before) call fail(370) - if (state_restick_before + state_separating_before + & - state_failed_before .ne. 0) call fail(371) + call validate_contact_before(before) call fem_write_restart(CONTACT_RESTART_FILE, ierr) if (ierr .ne. FEM_SUCCESS) return call prepare_contact_model(ierr) if (ierr .ne. FEM_SUCCESS) return - call contact_history_state_stats(hist_slots_after, stick_after, & - slip_state_after) - call contact_history_stable_counts(stable_slots_after, & - state_open_after, state_stick_after, state_slip_after, & - state_restick_after, state_separating_after, state_failed_after) - if (hist_slots_after .ne. 0) call fail(362) - if (stable_slots_after .ne. 0) call fail(372) - call fem_get_contact_hist_stats(slots_after, slip_after, work_after, & - tangent_after, ierr) + call validate_empty_contact(ierr) if (ierr .ne. FEM_SUCCESS) return - if (slots_after .ne. 0) call fail(17) call fem_read_restart(CONTACT_RESTART_FILE, ierr) if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_hist_stats(slots_after, slip_after, work_after, & - tangent_after, ierr) + call capture_contact_snap(after, ierr) if (ierr .ne. FEM_SUCCESS) return - call contact_history_state_stats(hist_slots_after, stick_after, & - slip_state_after) - call contact_history_stable_counts(stable_slots_after, & - state_open_after, state_stick_after, state_slip_after, & - state_restick_after, state_separating_after, state_failed_after) - - if (slots_after .ne. slots_before) call fail(18) - call check_close(slip_after, slip_before, 19) - call check_close(work_after, work_before, 20) - call check_close(tangent_after, tangent_before, 21) - if (hist_slots_after .ne. hist_slots_before) call fail(363) - if (stick_after .ne. stick_before) call fail(364) - if (slip_state_after .ne. slip_state_before) call fail(365) - if (stick_after + slip_state_after .ne. hist_slots_after) call fail(366) - if (stable_slots_after .ne. stable_slots_before) call fail(373) - if (state_open_after .ne. state_open_before) call fail(374) - if (state_stick_after .ne. state_stick_before) call fail(375) - if (state_slip_after .ne. state_slip_before) call fail(376) - if (state_restick_after .ne. state_restick_before) call fail(377) - if (state_separating_after .ne. state_separating_before) call fail(378) - if (state_failed_after .ne. state_failed_before) call fail(379) - call fem_get_contact_summary(active_summary_after, work_step_after, & - work_total_after, max_pen_after, force_norm_after, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_diagnostics(active_pair_after, activated_pair_after, & - maintained_pair_after, released_pair_after, max_gap_after, & - max_aug_after, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_friction(fric_step_after, fric_total_after, & - max_slip_after, ierr) - if (ierr .ne. FEM_SUCCESS) return - call fem_get_contact_state_summary(pair_open_after, pair_stick_after, & - pair_slip_after, pair_restick_after, pair_separating_after, & - pair_failed_after, pair_gap_max_after, pair_gap_mean_after, & - pair_gap_l2_after, pair_slip_inc_after, pair_slip_resid_after, & - pair_fric_resid_after, pair_flip_after, ierr) - if (ierr .ne. FEM_SUCCESS) return - if (active_summary_after .ne. active_summary_before) call fail(400) - if (active_pair_after .ne. active_pair_before) call fail(401) - if (activated_pair_after .ne. activated_pair_before) call fail(402) - if (maintained_pair_after .ne. maintained_pair_before) call fail(403) - if (released_pair_after .ne. released_pair_before) call fail(404) - call check_close(work_step_after, work_step_before, 405) - call check_close(work_total_after, work_total_before, 406) - call check_close(max_pen_after, max_pen_before, 407) - call check_close(force_norm_after, force_norm_before, 408) - call check_close(max_gap_after, max_gap_before, 409) - call check_close(max_aug_after, max_aug_before, 410) - call check_close(fric_step_after, fric_step_before, 411) - call check_close(fric_total_after, fric_total_before, 412) - call check_close(max_slip_after, max_slip_before, 413) - if (pair_open_after .ne. pair_open_before) call fail(422) - if (pair_stick_after .ne. pair_stick_before) call fail(423) - if (pair_slip_after .ne. pair_slip_before) call fail(424) - if (pair_restick_after .ne. pair_restick_before) call fail(425) - if (pair_separating_after .ne. pair_separating_before) call fail(426) - if (pair_failed_after .ne. pair_failed_before) call fail(427) - call check_close(pair_gap_max_after, pair_gap_max_before, 428) - call check_close(pair_gap_mean_after, pair_gap_mean_before, 429) - call check_close(pair_gap_l2_after, pair_gap_l2_before, 430) - call check_close(pair_slip_inc_after, pair_slip_inc_before, 431) - call check_close(pair_slip_resid_after, pair_slip_resid_before, 432) - call check_close(pair_fric_resid_after, pair_fric_resid_before, 433) - if (pair_flip_after .ne. pair_flip_before) call fail(434) + call compare_contact_snaps(after, before) end subroutine check_contact_history_restart + subroutine capture_contact_snap(snap, ierr) + type(contact_restart_snapshot), intent(out) :: snap + integer, intent(out) :: ierr + + call fem_get_contact_summary(snap%active_summary, snap%work_step, & + snap%work_total, snap%max_pen, snap%force_norm, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_diagnostics(snap%active_pair, snap%activated_pair, & + snap%maintained_pair, snap%released_pair, snap%max_gap, snap%max_aug, & + ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_friction(snap%fric_step, snap%fric_total, & + snap%max_slip, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_state_summary(snap%pair_open, snap%pair_stick, & + snap%pair_slip, snap%pair_restick, snap%pair_separating, & + snap%pair_failed, snap%pair_gap_max, snap%pair_gap_mean, & + snap%pair_gap_l2, snap%pair_slip_inc, snap%pair_slip_resid, & + snap%pair_fric_resid, snap%pair_flip, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_get_contact_hist_stats(snap%slots, snap%slip, snap%work, & + snap%tangent, ierr) + if (ierr .ne. FEM_SUCCESS) return + call contact_history_state_stats(snap%hist_slots, snap%stick, & + snap%slip_state) + call contact_history_stable_counts(snap%stable_slots, snap%state_open, & + snap%state_stick, snap%state_slip, snap%state_restick, & + snap%state_separating, snap%state_failed) + end subroutine capture_contact_snap + + subroutine validate_contact_before(snap) + type(contact_restart_snapshot), intent(in) :: snap + + if (snap%slots .le. 0) call fail(13) + if (snap%slip .le. ZERO) call fail(14) + if (snap%work .le. ZERO) call fail(15) + if (snap%tangent .le. ZERO) call fail(16) + if (snap%active_summary .le. 0) call fail(395) + if (snap%active_pair .le. 0) call fail(396) + if (snap%force_norm .le. ZERO) call fail(397) + if (snap%max_gap .le. ZERO) call fail(398) + if (snap%max_slip .le. ZERO) call fail(399) + if (snap%pair_stick + snap%pair_slip + snap%pair_restick .le. 0) & + call fail(414) + if (snap%pair_failed .ne. 0) call fail(415) + if (snap%pair_gap_max .le. ZERO) call fail(416) + if (snap%pair_gap_l2 .lt. snap%pair_gap_max) call fail(417) + if (snap%pair_slip_inc .le. ZERO) call fail(418) + if (snap%pair_slip_resid .lt. ZERO) call fail(419) + if (snap%pair_fric_resid .le. ZERO) call fail(420) + if (snap%pair_flip .le. 0) call fail(421) + call validate_contact_counts(snap) + end subroutine validate_contact_before + + subroutine validate_contact_counts(snap) + type(contact_restart_snapshot), intent(in) :: snap + + if (snap%hist_slots .ne. snap%slots) call fail(360) + if (snap%stick + snap%slip_state .ne. snap%hist_slots) call fail(361) + if (snap%stable_slots .ne. snap%hist_slots) call fail(367) + if (snap%state_open .ne. 0) call fail(368) + if (snap%state_stick .ne. snap%stick) call fail(369) + if (snap%state_slip .ne. snap%slip_state) call fail(370) + if (snap%state_restick + snap%state_separating + & + snap%state_failed .ne. 0) call fail(371) + end subroutine validate_contact_counts + + subroutine validate_empty_contact(ierr) + integer, intent(out) :: ierr + type(contact_restart_snapshot) :: snap + + call contact_history_state_stats(snap%hist_slots, snap%stick, & + snap%slip_state) + call contact_history_stable_counts(snap%stable_slots, snap%state_open, & + snap%state_stick, snap%state_slip, snap%state_restick, & + snap%state_separating, snap%state_failed) + if (snap%hist_slots .ne. 0) call fail(362) + if (snap%stable_slots .ne. 0) call fail(372) + call fem_get_contact_hist_stats(snap%slots, snap%slip, snap%work, & + snap%tangent, ierr) + if (ierr .ne. FEM_SUCCESS) return + if (snap%slots .ne. 0) call fail(17) + end subroutine validate_empty_contact + + subroutine compare_contact_snaps(after, before) + type(contact_restart_snapshot), intent(in) :: after + type(contact_restart_snapshot), intent(in) :: before + + if (after%slots .ne. before%slots) call fail(18) + call check_close(after%slip, before%slip, 19) + call check_close(after%work, before%work, 20) + call check_close(after%tangent, before%tangent, 21) + call compare_contact_counts(after, before) + call compare_contact_summary(after, before) + call compare_contact_pair(after, before) + end subroutine compare_contact_snaps + + subroutine compare_contact_counts(after, before) + type(contact_restart_snapshot), intent(in) :: after + type(contact_restart_snapshot), intent(in) :: before + + if (after%hist_slots .ne. before%hist_slots) call fail(363) + if (after%stick .ne. before%stick) call fail(364) + if (after%slip_state .ne. before%slip_state) call fail(365) + if (after%stick + after%slip_state .ne. after%hist_slots) call fail(366) + if (after%stable_slots .ne. before%stable_slots) call fail(373) + if (after%state_open .ne. before%state_open) call fail(374) + if (after%state_stick .ne. before%state_stick) call fail(375) + if (after%state_slip .ne. before%state_slip) call fail(376) + if (after%state_restick .ne. before%state_restick) call fail(377) + if (after%state_separating .ne. before%state_separating) call fail(378) + if (after%state_failed .ne. before%state_failed) call fail(379) + end subroutine compare_contact_counts + + subroutine compare_contact_summary(after, before) + type(contact_restart_snapshot), intent(in) :: after + type(contact_restart_snapshot), intent(in) :: before + + if (after%active_summary .ne. before%active_summary) call fail(400) + if (after%active_pair .ne. before%active_pair) call fail(401) + if (after%activated_pair .ne. before%activated_pair) call fail(402) + if (after%maintained_pair .ne. before%maintained_pair) call fail(403) + if (after%released_pair .ne. before%released_pair) call fail(404) + call check_close(after%work_step, before%work_step, 405) + call check_close(after%work_total, before%work_total, 406) + call check_close(after%max_pen, before%max_pen, 407) + call check_close(after%force_norm, before%force_norm, 408) + call check_close(after%max_gap, before%max_gap, 409) + call check_close(after%max_aug, before%max_aug, 410) + call check_close(after%fric_step, before%fric_step, 411) + call check_close(after%fric_total, before%fric_total, 412) + call check_close(after%max_slip, before%max_slip, 413) + end subroutine compare_contact_summary + + subroutine compare_contact_pair(after, before) + type(contact_restart_snapshot), intent(in) :: after + type(contact_restart_snapshot), intent(in) :: before + + if (after%pair_open .ne. before%pair_open) call fail(422) + if (after%pair_stick .ne. before%pair_stick) call fail(423) + if (after%pair_slip .ne. before%pair_slip) call fail(424) + if (after%pair_restick .ne. before%pair_restick) call fail(425) + if (after%pair_separating .ne. before%pair_separating) call fail(426) + if (after%pair_failed .ne. before%pair_failed) call fail(427) + call check_close(after%pair_gap_max, before%pair_gap_max, 428) + call check_close(after%pair_gap_mean, before%pair_gap_mean, 429) + call check_close(after%pair_gap_l2, before%pair_gap_l2, 430) + call check_close(after%pair_slip_inc, before%pair_slip_inc, 431) + call check_close(after%pair_slip_resid, before%pair_slip_resid, 432) + call check_close(after%pair_fric_resid, before%pair_fric_resid, 433) + if (after%pair_flip .ne. before%pair_flip) call fail(434) + end subroutine compare_contact_pair + subroutine check_mult_restart(ierr) integer, intent(out) :: ierr integer :: slot_count @@ -597,6 +594,9 @@ contains call write_restart_without_lifecycle(LIFECYCLE_RESTART_FILE, & LEGACY_LIFECYCLE_RESTART_FILE, ierr) if (ierr .ne. FEM_SUCCESS) call fail(521) + call write_restart_bad_lifecycle(LIFECYCLE_RESTART_FILE, & + BAD_LIFECYCLE_RESTART_FILE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(524) call nl_lifecycle_reset() call prepare_model(ierr) if (ierr .ne. FEM_SUCCESS) return @@ -635,6 +635,15 @@ contains 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) + if (step_after .ne. 0 .or. increment_after .ne. 0) call fail(525) + if (path_after) call fail(526) + + call nl_lifecycle_reset() + call prepare_model(ierr) + if (ierr .ne. FEM_SUCCESS) return + call fem_read_restart(BAD_LIFECYCLE_RESTART_FILE, ierr) + if (ierr .eq. FEM_SUCCESS) call fail(527) + call error_clear(ierr) end subroutine check_lifecycle_restart subroutine check_restart_each_accept(ierr) @@ -785,6 +794,23 @@ contains character(len=*), intent(in) :: source_file character(len=*), intent(in) :: target_file integer, intent(out) :: ierr + + call copy_restart_lifecycle(source_file, target_file, 0, ierr) + end subroutine write_restart_without_lifecycle + + subroutine write_restart_bad_lifecycle(source_file, target_file, ierr) + character(len=*), intent(in) :: source_file + character(len=*), intent(in) :: target_file + integer, intent(out) :: ierr + + call copy_restart_lifecycle(source_file, target_file, 1, ierr) + end subroutine write_restart_bad_lifecycle + + subroutine copy_restart_lifecycle(source_file, target_file, mode, ierr) + character(len=*), intent(in) :: source_file + character(len=*), intent(in) :: target_file + integer, intent(in) :: mode + integer, intent(out) :: ierr character(len=4096) :: line character(len=32) :: tag integer :: read_unit @@ -814,7 +840,13 @@ contains 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 + if (ios_tag .eq. 0 .and. trim(tag) .eq. 'LIFECYCLE_DIAGNOSTICS') then + if (mode .eq. 0) cycle + write(write_unit,'(A)',iostat=ios_write) & + 'LIFECYCLE_DIAGNOSTICS 1 2' + if (ios_write .ne. 0) exit + cycle + end if write(write_unit,'(A)',iostat=ios_write) trim(line) if (ios_write .ne. 0) exit end do @@ -828,7 +860,7 @@ contains else ierr = FEM_ERR_OUTPUT end if - end subroutine write_restart_without_lifecycle + end subroutine copy_restart_lifecycle subroutine capture_lifecycle(step, increment, iteration, event_id, & reason_id, audit_status, begin_trial_count, & diff --git a/tests/module/test_solver_implicit.f90 b/tests/module/test_solver_implicit.f90 index fd92886..737f3d5 100644 --- a/tests/module/test_solver_implicit.f90 +++ b/tests/module/test_solver_implicit.f90 @@ -42,6 +42,7 @@ program test_solver_implicit call check_static_arc_amp_path() call check_static_arc_disp_adaptive() call check_static_arc_disp_trust() + call check_path_storage_reset() call check_nonlinear_cg_fallback() call check_nl_linear_failure_reason() @@ -1067,6 +1068,58 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(320) end subroutine check_static_arc_disp_trust + subroutine check_path_storage_reset() + integer :: i + + call nlc_path_release() + call append_storage_row(1, 1.0_rk, 1.0_rk, 5700) + call append_storage_row(2, 2.0_rk, 2.0_rk, 5701) + call append_storage_row(3, 1.5_rk, 1.5_rk, 5702) + if (nlc_path_count .ne. 3) call fail(5703) + if (nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, 3) .ne. 1) & + call fail(5704) + if (nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, 3) .ne. 1) & + call fail(5705) + + call nlc_path_reset() + if (nlc_path_count .ne. 0) call fail(5706) + call append_storage_row(4, 10.0_rk, 10.0_rk, 5707) + if (nlc_path_count .ne. 1) call fail(5708) + if (nlc_path_int(NLC_PATH_I_ARC_LOAD_REVERSAL, 1) .ne. 0) & + call fail(5709) + if (nlc_path_int(NLC_PATH_I_ARC_TURNING_POINT, 1) .ne. 0) & + call fail(5710) + call check_close(nlc_path_real(NLC_PATH_R_ARC_LOAD_DELTA, 1), ZERO, 5711) + call check_close(nlc_path_real(NLC_PATH_R_WORK, 1), ZERO, 5712) + + call nlc_path_release() + if (nlc_path_count .ne. 0) call fail(5713) + if (nlc_path_capacity .ne. 0) call fail(5714) + do i = 1, 10 + call append_storage_row(i, real(i, rk), real(i, rk), 5720 + i) + end do + if (nlc_path_count .ne. 10) call fail(5731) + if (nlc_path_capacity .lt. 10) call fail(5732) + if (nlc_path_int(NLC_PATH_I_STEP, 1) .ne. 1) call fail(5733) + if (nlc_path_int(NLC_PATH_I_STEP, 10) .ne. 10) call fail(5734) + call check_close(nlc_path_real(NLC_PATH_R_PARAMETER, 10), 10.0_rk, 5735) + call nlc_path_release() + end subroutine check_path_storage_reset + + subroutine append_storage_row(step, parameter, reaction, code_base) + integer, intent(in) :: step + integer, intent(in) :: code_base + real(rk), intent(in) :: parameter + real(rk), intent(in) :: reaction + integer :: ierr + + call nlc_path_append(step, real(step, rk), parameter, 1, & + 0.1_rk * parameter, 0.1_rk * parameter, 0.1_rk * parameter, & + 0.1_rk * parameter, ZERO, ZERO, reaction, reaction, step, & + ZERO, ZERO, ZERO, CONVERGENCE_STATUS_CONVERGED, CONV_FAIL_NONE, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code_base) + end subroutine append_storage_row + subroutine check_nonlinear_cg_fallback() integer :: ierr integer :: iter @@ -1076,8 +1129,10 @@ contains integer :: last_method integer :: last_preconditioner integer :: status_code + integer :: failure_class real(rk) :: res_norm real(rk) :: last_residual + character(len=64) :: failure_reason call setup_single_free_dof_model(ierr) if (ierr .ne. FEM_SUCCESS) call fail(249) @@ -1113,6 +1168,11 @@ contains if (last_preconditioner .ne. LPRECOND_JACOBI) call fail(259) if (status_code .ne. LS_STATUS_CONVERGED) call fail(260) if (last_residual .gt. TOL) call fail(261) + call linear_solver_get_fail_info(failure_class, failure_reason, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(5263) + if (failure_class .ne. LS_FAIL_NONE) call fail(5264) + if (index(trim(failure_reason), 'gmres-selected') .le. 0) & + call fail(5265) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(262) @@ -1124,6 +1184,8 @@ contains integer :: old_method integer :: old_preconditioner integer :: old_linear_limit + integer :: method + integer :: preconditioner integer :: failure_class integer :: status_code real(rk) :: res_norm @@ -1164,6 +1226,10 @@ contains if (failure_class .ne. LS_FAIL_DENSE_FALLBACK) call fail(5411) if (index(trim(failure_reason), 'dense-fallback-failure') .le. 0) & call fail(5412) + call linear_solver_get_settings(method, preconditioner, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(5415) + if (method .ne. LSOLVER_DENSE) call fail(5416) + if (preconditioner .ne. LPRECOND_NONE) call fail(5417) nonlinear_linear_iter_limit = old_linear_limit call linear_solver_configure(old_method, old_preconditioner, ierr) @@ -1577,6 +1643,8 @@ contains integer :: ierr integer :: ios integer :: unit_id + integer :: header_fields + integer :: row_fields call output_csv_set_directory('build-codex-gcc/test_solver_implicit_path', & ierr) @@ -1601,6 +1669,16 @@ contains if (index(header, 'residual_arc') .le. 0) call fail(code_base + 9) if (index(header, 'material_failure_count') .le. 0) & call fail(code_base + 10) + if (index(header, 'linear_method,linear_precond') .le. 0) & + call fail(code_base + 23) + if (index(header, 'linear_iterations,linear_status') .le. 0) & + call fail(code_base + 24) + if (index(header, 'linear_initial_residual') .le. 0) & + call fail(code_base + 25) + if (index(header, 'linear_final_residual') .le. 0) & + call fail(code_base + 26) + if (index(header, 'linear_relative_residual') .le. 0) & + call fail(code_base + 27) if (index(header, 'lifecycle_event_id') .le. 0) & call fail(code_base + 11) if (index(header, 'lifecycle_event_name') .le. 0) & @@ -1623,9 +1701,29 @@ contains call fail(code_base + 20) if (index(header, 'arc_length,arc_load_delta,arc_predictor_dot') .le. 0) & call fail(code_base + 21) + header_fields = csv_test_fields(header) + row_fields = csv_test_fields(row_line) + if (header_fields .ne. 60) call fail(code_base + 28) + if (row_fields .ne. header_fields) call fail(code_base + 29) if (index(row_line, ',accept,') .le. 0) call fail(code_base + 22) end subroutine check_path_breakdown_header + integer function csv_test_fields(line) + character(len=*), intent(in) :: line + integer :: i + integer :: n + + n = len_trim(line) + if (n .le. 0) then + csv_test_fields = 0 + return + end if + csv_test_fields = 1 + do i = 1, n + if (line(i:i) .eq. ',') csv_test_fields = csv_test_fields + 1 + end do + end function csv_test_fields + subroutine check_lifecycle_report_row(output_dir, expected_event, & expected_reason, code_base) character(len=*), intent(in) :: output_dir @@ -1638,6 +1736,8 @@ contains integer :: ierr integer :: ios integer :: unit_id + integer :: header_fields + integer :: row_fields call output_csv_set_directory(output_dir, ierr) if (ierr .ne. FEM_SUCCESS) call fail(code_base) @@ -1669,6 +1769,10 @@ contains if (index(header, 'linear_relative_residual') .le. 0) & call fail(code_base + 16) if (index(header, 'linear_fail_class') .le. 0) call fail(code_base + 17) + header_fields = csv_test_fields(header) + row_fields = csv_test_fields(row_line) + if (header_fields .ne. 38) call fail(code_base + 18) + if (row_fields .ne. header_fields) call fail(code_base + 19) if (index(row_line, ','//trim(expected_event)//',') .le. 0) & call fail(code_base + 10) if (index(row_line, ','//trim(expected_reason)//',') .le. 0) & diff --git a/tests/performance/perf_contact_pair.f90 b/tests/performance/perf_contact_pair.f90 index 0cc2f7e..34780d4 100644 --- a/tests/performance/perf_contact_pair.f90 +++ b/tests/performance/perf_contact_pair.f90 @@ -51,10 +51,12 @@ program perf_contact_pair real(rk) :: path_tangent_force_total real(rk) :: path_gap_total real(rk) :: path_slip_total + real(rk) :: path_fric_work_total real(rk) :: final_force_total real(rk) :: final_tangent_force_total real(rk) :: final_gap_total real(rk) :: final_slip_total + real(rk) :: final_fric_work_total real(rk) :: t0 real(rk) :: t1 @@ -77,6 +79,7 @@ program perf_contact_pair path_tangent_force_total = ZERO path_gap_total = ZERO path_slip_total = ZERO + path_fric_work_total = ZERO call cpu_time(t0) do step = 1, step_count call update_slave_path(step, step_count) @@ -97,6 +100,7 @@ program perf_contact_pair path_tangent_force_total = path_tangent_force_total + pair_tan_force_sum() path_gap_total = path_gap_total + pair_gap_sum() path_slip_total = path_slip_total + pair_slip_sum() + path_fric_work_total = path_fric_work_total + contact_friction_work_step path_activated_total = path_activated_total + & count_pair_status(CONTACT_PAIR_ACTIVATED) path_released_total = path_released_total + & @@ -123,6 +127,7 @@ program perf_contact_pair final_tangent_force_total = pair_tan_force_sum() final_gap_total = pair_gap_sum() final_slip_total = pair_slip_sum() + final_fric_work_total = contact_friction_work_total call contact_get_search_stats(search_facets, search_masters, search_broad, & search_active, search_bvh_nodes) call contact_get_cache_stats(cache_used, cache_overflow) @@ -155,6 +160,7 @@ program perf_contact_pair write(*,'(A,ES16.8)') ' path_tan_f_sum: ', path_tangent_force_total write(*,'(A,ES16.8)') ' path_gap_sum: ', path_gap_total write(*,'(A,ES16.8)') ' path_slip_sum: ', path_slip_total + write(*,'(A,ES16.8)') ' path_fric_work: ', path_fric_work_total write(*,'(A,I8)') ' active_count: ', active_count write(*,'(A,I8)') ' state_open: ', state_open_count write(*,'(A,I8)') ' state_activated: ', state_activated_count @@ -173,6 +179,7 @@ program perf_contact_pair write(*,'(A,ES16.8)') ' tan_force_sum: ', final_tangent_force_total write(*,'(A,ES16.8)') ' gap_sum: ', final_gap_total write(*,'(A,ES16.8)') ' slip_sum: ', final_slip_total + write(*,'(A,ES16.8)') ' fric_work: ', final_fric_work_total write(*,'(A,ES12.5)') ' search_cpu: ', search_time write(*,'(A,ES12.5)') ' force_cpu: ', force_time write(*,'(A,ES12.5)') ' tangent_cpu: ', tangent_time diff --git a/tests/performance/perf_p1.f90 b/tests/performance/perf_p1.f90 index 5ac43ae..72e1ca7 100644 --- a/tests/performance/perf_p1.f90 +++ b/tests/performance/perf_p1.f90 @@ -40,7 +40,7 @@ program perf_p1 call fem_get_version(major, minor, patch, ierr) call exit_if_error(ierr) - if (major .ne. 0 .or. minor .ne. 6 .or. patch .ne. 1) then + if (major .ne. 0 .or. minor .ne. 6 .or. patch .ne. 2) 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 01011bf..49d2d8c 100644 --- a/tests/unit/test_smoke.f90 +++ b/tests/unit/test_smoke.f90 @@ -94,7 +94,7 @@ program test_smoke if (ierr .ne. 0) stop 2 if (major .ne. 0) stop 3 if (minor .ne. 6) stop 4 - if (patch .ne. 1) stop 5 + if (patch .ne. 2) 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 ddc0677..f1fbce7 100644 --- a/todo.md +++ b/todo.md @@ -1,401 +1,339 @@ -# FemLite 0.6.1 TODO - -Source plan: `docs/v6.1_development_plan.md` +# FemLite 0.6.2 TODO Version goal: ```text -FemLite 0.6.1 = nonlinear/contact lifecycle diagnostics hardening +FemLite 0.6.2 = release hardening and stability reinforcement ``` Boundary: -- 0.6.1 deepens the 0.6.0 lifecycle foundation; it is not a broad algorithm - rewrite release. -- Do not implement a complete industrial AL/mortar consistent tangent rewrite - in this task list. -- Do not move mixed-control continuation, shell preload `K_G`, high-order solid - `K_G`, cohesive contact mainline, nonzero harmonic cyclic, DEM subcycling or - production roll forming into the 0.6.1 must-complete list. -- Every new reason, status, counter or output field must be consumed by a - regression test, checker or report audit. -- Keep TODO item size uniform: each task should add one observable contract and - one focused verification path. +- 0.6.2 does not add new user-facing algorithms or broaden the feature scope. +- 0.6.2 must stabilize the 0.6.1 lifecycle/contact/Riks/solver diagnostic + work and tighten release gates. +- Do not implement complete industrial AL/mortar consistent tangents, + mixed-control continuation, cohesive contact mainline, DEM/FEM subcycling, + shell preload `K_G`, high-order solid `K_G`, nonzero harmonic cyclic + symmetry or production roll-forming workflow in this task list. +- Each TODO should add one observable stability contract and one focused + verification path. +- Prefer small refactors, schema guards, deterministic tests and error-path + checks over solver-loop rewrites. ## Execution Order -1. NLHD-1: lifecycle increment summary. -2. NLHD-2: cutback reason taxonomy. -3. NLHD-3: lifecycle report output. -4. NLHD-4: contact state diagnostics. -5. NLHD-5: contact long-path diagnostic smoke. -6. NLHD-6: AL/friction diagnostics. -7. NLHD-7: tangent-audit report shell. -8. NLHD-8: Riks/arc diagnostics. -9. NLHD-9: restart-after-each-accepted audit. -10. NLHD-10: solver diagnostics coupling. -11. DOC-1: documentation and matrix synchronization. -12. REL-1: 0.6.1 regression/version close-out. +1. RH-1: source-size hard failure cleanup. +2. RH-2: release quality gate definition. +3. RH-3: `continuation_path.csv` writer/schema hardening. +4. RH-4: `nonlinear_lifecycle.csv` writer/schema hardening. +5. RH-5: nonlinear path storage/reset hardening. +6. RH-6: restart compatibility and test decomposition. +7. RH-7: contact benchmark checker schema consolidation. +8. RH-8: OpenMP contact determinism checks. +9. RH-9: contact state edge/default checks. +10. RH-10: linear-solver fallback state stability. +11. RH-11: INP/CLI error-boundary stability. +12. RH-12: documentation/version close-out. ## Detailed Execution Map -| TODO | Code targets | Output/API contract | Test/checker target | Not in scope | +| TODO | Code targets | Stability contract | Test/checker target | Not in scope | |---|---|---|---|---| -| 0.6.1-1 | lifecycle module and diagnostics API | Increment summary fields for lifecycle, convergence, residual, solver and audit state | `nonlinear_lifecycle`, `solver_implicit` | Change Newton algorithms | -| 0.6.1-2 | control/reason taxonomy | Stable cutback reason ids/names and last cutback reason query | `solver_implicit`, lifecycle test | New nonlinear strategy | -| 0.6.1-3 | output/report module | Compact lifecycle report or appended nonlinear report fields | output checker | Break old CSV columns | -| 0.6.1-4 | contact state/report modules | Stable contact state counters and gap/slip/friction fields | `contact`, contact reports | Full contact state-machine rewrite | -| 0.6.1-5 | contact benchmark checkers | Long-path diagnostic smoke for existing compact contact examples | contact benchmark checkers | New contact benchmark physics | -| 0.6.1-6 | multiplier/friction diagnostics | AL multiplier, augmentation and friction trend summaries | `contact_multiplier_report`, `restart` | Complete AL tangent | -| 0.6.1-7 | tangent audit reporting | Shared audit schema and coverage counters | tangent audit tests | Claim production consistent tangents | -| 0.6.1-8 | Riks/arc path diagnostics | Arc residual history, predictor and reversal indicators | `solver_implicit`, `implicit_inp` | Mixed-control continuation | -| 0.6.1-9 | restart writer/reader tests | Multi-increment restart lifecycle audit | `restart` | Large restart benchmark | -| 0.6.1-10 | linear solver diagnostics | Solver status fields linked into lifecycle/nonlinear rows | `linear_solver_cg`, `solver_implicit` | New solver backend | -| 0.6.1-11 | docs and matrices | Updated interface/user/developer docs and benchmark matrix | wording `rg` checks | Expand feature scope | -| 0.6.1-12 | version/report files | Close 0.6.1 after green targeted and V5 acceptance tests | build, targeted tests, acceptance, `git diff --check` | Version bump before tests pass | +| 0.6.2-1 | `fem_control`, `fem_output_csv`, `test_restart` | `source_size` hard limit passes without changing solver behavior | `source_size`, affected module tests | Add blanket exceptions | +| 0.6.2-2 | docs, release command notes | 0.6.2 release gate always includes build, `source_size`, targeted regression, V5 acceptance and `git diff --check` | documented command replay | New CI service | +| 0.6.2-3 | `fem_output_csv` path writer | `continuation_path.csv` keeps old column order and writes a validated row schema | `solver_implicit`, `implicit_inp` | New path-following algorithm | +| 0.6.2-4 | `fem_output_csv` lifecycle writer | `nonlinear_lifecycle.csv` writes stable columns for empty, accepted, rejected and solver-failure states | `nonlinear_lifecycle`, `solver_implicit` | New lifecycle fields | +| 0.6.2-5 | `fem_control` path storage | path append/reset/release/capacity growth does not leave stale rows or corrupted diagnostics | `nonlinear_lifecycle`, `solver_implicit` | Change continuation math | +| 0.6.2-6 | `fem_restart`, `test_restart` | restart tests are decomposed and cover optional/missing/truncated diagnostic blocks cleanly | `restart` | New restart format | +| 0.6.2-7 | contact example checkers | compact contact benchmark schema checks share one required-field contract | contact benchmark CTests | New benchmark physics | +| 0.6.2-8 | contact OpenMP path | 1-thread and 4-thread compact contact paths remain deterministic for accepted diagnostics | `contact_omp1`, `contact_omp4`, `perf_contact_pair_omp_consistency` | Parallel algorithm rewrite | +| 0.6.2-9 | contact state/report modules | no-pair, release/recontact and failed-projection states report stable defaults/counters | `contact`, contact report tests | Full contact state-machine rewrite | +| 0.6.2-10 | linear solver dispatch/fallback | solver fallback restores user configuration and reports failure class without stale status | `linear_solver_cg`, `solver_implicit`, `c_api` | New solver backend | +| 0.6.2-11 | INP parser, CLI boundary | invalid controls, unsupported shell geometry and output-dir edge cases fail deterministically | `implicit_inp`, CLI CTests, output tests | New keywords | +| 0.6.2-12 | README, manuals, reports, version files | 0.6.2 docs/version match stability scope and do not claim deferred features | wording checks, full release gate | Feature expansion | ## Implementation Rules - Work in the execution order above. -- Do not mark a TODO done until its new field, reason or status is consumed by - a test, checker or report audit. -- Prefer additive diagnostics over solver-loop rewrites. -- Keep old CSV columns stable; append new fields. -- Keep restart readers backward compatible; optional diagnostic blocks are - preferred over format breaks. -- If a task exposes incompatible designs for contact, Riks, material or restart - ownership, pause and ask for a decision before editing that route. -- If a later task needs a field created by an earlier task, finish and test the - earlier task first. +- Do not mark a TODO done until its test/checker target passes. +- If a refactor changes numerical output outside formatting/schema-only + differences, stop and inspect before continuing. +- Keep old CSV columns stable; append-only changes are allowed only when a + specific stability check needs them. +- Keep restart readers backward compatible; optional diagnostic blocks should + remain optional. +- Prefer extracting helper routines over adding `source_size` exceptions. +- If a hard limit cannot be cleared without risky behavior changes, document + the exact reason in `tests/source_size_exceptions.txt` and ask before + accepting the exception. +- Generated CSV/VTK/restart/result files must not be committed. -## 0.6.1 Task List +## 0.6.2 Task List -### [x] TODO 0.6.1-1: Add lifecycle increment summary +### [x] TODO 0.6.2-1: Clear current `source_size` hard failures - Source: - - `docs/v6.1_development_plan.md` sections 4.1 and 5, NLHD-1. + - 0.6.2 stability review P0. - Implementation: - - [x] Add a compact lifecycle increment summary structure or query path. - - [x] Include step, increment, final event id/name and reason id/name. - - [x] Include convergence status, residual breakdown, linear solver status - and audit status fields already available in 0.6.0. - - [x] Keep existing lifecycle snapshot APIs compatible. + - [x] Split `nlc_path_append` in `src/base/fem_control.f90` into focused + helper routines for arc indicators, row initialization and diagnostics copy. + - [x] Split `output_csv_write_path` in `src/output/fem_output_csv.f90` into + header, row-prefix, residual and lifecycle/arc tail helpers. + - [x] Split `check_contact_history_restart` in `tests/module/test_restart.f90` + into smaller contact history, contact state and friction/multiplier + comparison helpers. + - [x] Avoid broad `source_size` exceptions unless a split would alter runtime + behavior. - Tests: - - [x] Extend `nonlinear_lifecycle` to verify empty and populated summary - fields. - - [x] Extend `solver_implicit` to consume the summary after one accepted and - one rejected/cutback path. + - [x] Run `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure`. + - [x] Run affected tests: `nonlinear_lifecycle`, `solver_implicit`, + `restart`. - Acceptance: - - [x] A test can explain the latest nonlinear increment from one summary - query without reading console output. + - [x] `source_size` has no hard failures. + - [x] Refactors are behavior-preserving. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|restart)$" --output-on-failure` -Verified: +### [x] TODO 0.6.2-2: Define the 0.6.2 release quality gate + +- Source: + - 0.6.2 stability review P0. +- Implementation: + - [x] Add/update release notes so 0.6.2 requires build, `source_size`, + targeted stability regression, V5 acceptance and `git diff --check`. + - [x] Add a compact 0.6.2 stability matrix section listing required commands. + - [x] Keep the quality gate focused on stability checks already present in + the repository. +- Tests: + - [x] Replay the documented command list locally once it is written. +- Acceptance: + - [x] The documented gate would have caught the current `source_size` + failure before release. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` + - `git diff --check` + +### [x] TODO 0.6.2-3: Harden `continuation_path.csv` schema and writer + +- Source: + - 0.6.2 stability review P1. +- Implementation: + - [x] Keep existing `continuation_path.csv` column order stable. + - [x] Add a single schema/header helper for path output. + - [x] Add a row check that verifies required lifecycle, linear solver and + arc diagnostic fields are present after writing. + - [x] Preserve existing accepted-path numerical values. +- Tests: + - [x] Extend `solver_implicit` or `implicit_inp` to validate header fields and + a representative row. +- Acceptance: + - [x] Missing or reordered path diagnostic columns fail a regression test. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-4: Harden `nonlinear_lifecycle.csv` schema and writer + +- Source: + - 0.6.2 stability review P1. +- Implementation: + - [x] Factor lifecycle CSV header and row writing into small helpers. + - [x] Verify empty lifecycle, accepted increment, rejected/cutback increment + and linear-solver failure rows use the same column contract. + - [x] Keep field names stable for lifecycle, cutback, residual, linear solver + and audit status. +- Tests: + - [x] Extend `nonlinear_lifecycle` and `solver_implicit` CSV checks. +- Acceptance: + - [x] All covered lifecycle rows have the documented schema and parse without + ad hoc column handling. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-5: Harden nonlinear path storage reset and capacity growth + +- Source: + - 0.6.2 stability review P1. +- Implementation: + - [x] Add focused checks for repeated `nlc_path_reset` and `nlc_path_release`. + - [x] Add a capacity-growth test that appends more rows than the initial + allocation. + - [x] Verify arc reversal/turning-point diagnostics do not read stale prior + row data after reset. +- Tests: + - [x] Extend `nonlinear_lifecycle` or `solver_implicit`. +- Acceptance: + - [x] Repeated path append/reset/release cycles remain deterministic and do + not corrupt existing diagnostics. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-6: Decompose restart tests and add compatibility error paths + +- Source: + - 0.6.2 stability review P1. +- Implementation: + - [x] Split contact restart comparisons into contact history, state summary, + friction summary and multiplier summary helpers. + - [x] Add a missing optional lifecycle block read-back check. + - [x] Add a truncated/corrupt diagnostic block check that returns a clear + error instead of partial silent state. + - [x] Keep current restart version and old-file compatibility behavior. +- Tests: + - [x] Run `ctest --test-dir build-codex-gcc -R "^restart$" --output-on-failure`. +- Acceptance: + - [x] Restart coverage is easier to review and preserves backward-compatible + optional diagnostics. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^restart$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-7: Consolidate compact contact benchmark schema checks + +- Source: + - 0.6.2 stability review P2. +- Implementation: + - [x] Extract shared required-column checks for compact contact benchmark + Python checkers. + - [x] Apply the shared schema to two-block compression, block sliding, + shell-shell contact and shell-solid contact checkers. + - [x] Keep each benchmark's existing physics assertions local to that checker. +- Tests: + - [x] Run contact compact benchmark CTests for the four affected examples. +- Acceptance: + - [x] A missing contact diagnostic column fails consistently in every compact + contact checker. +- Verified: + - `ctest --test-dir build-codex-gcc -R "^example_(contact_two_blocks_compression|contact_block_sliding|shell_shell_contact|shell_solid_contact)_benchmark$" --output-on-failure` + +### [x] TODO 0.6.2-8: Strengthen OpenMP contact determinism checks + +- Source: + - 0.6.2 stability review P2. +- Implementation: + - [x] Compare 1-thread and 4-thread compact contact diagnostics for active + count, force norm, gap summary, friction work and cache statistics. + - [x] Add repeat-run tolerance checks where existing outputs are deterministic. + - [x] Keep OpenMP implementation unchanged unless a race is exposed. +- Tests: + - [x] Run `contact_omp1`, `contact_omp4` and + `perf_contact_pair_omp_consistency`. +- Acceptance: + - [x] OpenMP contact diagnostics are stable across the covered compact path. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(contact_omp1|contact_omp4|perf_contact_pair_omp_consistency)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-9: Add contact state edge/default stability checks + +- Source: + - 0.6.2 stability review P2. +- Implementation: + - [x] Verify no-contact-pair diagnostics return stable zero/default state. + - [x] Verify release/recontact transitions preserve expected counters in a + compact path. + - [x] Verify failed projection counters are exposed consistently when the + existing code reports projection failure. +- Tests: + - [x] Extend `contact` or a contact report test. +- Acceptance: + - [x] Contact state diagnostics do not require special-case parsing for + unsupported or inactive paths. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^contact$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-10: Harden linear-solver fallback state reporting + +- Source: + - 0.6.2 stability review P3. +- Implementation: + - [x] Verify CG failure fallback restores the user's configured method and + preconditioner. + - [x] Verify dense fallback failure reports the expected fail class without + stale success status. + - [x] Verify invalid solver/preconditioner configuration does not mutate the + previous valid setting. + - [x] Keep solver algorithms unchanged. +- Tests: + - [x] Extend `linear_solver_cg`, `solver_implicit` or `c_api`. +- Acceptance: + - [x] Solver diagnostics distinguish fallback, configuration error and normal + convergence in a repeatable way. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(linear_solver_cg|solver_implicit|c_api)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-11: Harden INP and CLI error boundaries + +- Source: + - 0.6.2 stability review P3. +- Implementation: + - [x] Verify invalid nonlinear continuation parameters fail before mutating + existing control state. + - [x] Verify unsupported shell finite-strain requests fail clearly and do not + fall back to linear shell behavior. + - [x] Verify CLI output-directory edge cases create directories when allowed + and report clear errors when not allowed. + - [x] Do not add new INP keywords. +- Tests: + - [x] Extend `implicit_inp`, CLI CTests or output tests. +- Acceptance: + - [x] Invalid input and CLI boundaries fail deterministically with stable + error messages/status. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^(implicit_inp|cli_output_dir_boundary|vtk_output)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + +### [x] TODO 0.6.2-12: Close 0.6.2 docs, version and release evidence + +- Source: + - 0.6.2 stability review close-out. +- Implementation: + - [x] Update version files from 0.6.1 to 0.6.2 only after implementation and + regression checks are ready. + - [x] Update README, user manual, developer manual, acceptance report and + benchmark matrix to state that 0.6.2 is a stability release. + - [x] Correct stale document titles that still describe 0.5.x or 0.6.0 when + referring to the current line. + - [x] Keep deferred feature boundaries explicit. +- Tests: + - [x] Run the 0.6.2 release quality gate from TODO 0.6.2-2. + - [x] Run wording checks so docs do not claim new algorithms in 0.6.2. +- Acceptance: + - [x] 0.6.2 closes with green release gate, clean version assertions and + documentation matching the stability-only scope. +- Verified: + - `cmake --build build-codex-gcc --parallel` + - `ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api|cli_output_dir_boundary|vtk_output)$" --output-on-failure` + - `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure` + - `ctest --test-dir build-codex-gcc -R "^(smoke|c_api)$" --output-on-failure` + - `git diff --check` + +## Suggested 0.6.2 Regression Commands ```powershell cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure -``` - -### [x] TODO 0.6.1-2: Add cutback reason taxonomy - -- Source: - - `docs/v6.1_development_plan.md` sections 4.2 and 5, NLHD-2. -- Implementation: - - [x] Add stable cutback reason ids/names for common nonlinear failure modes. - - [x] Track the last cutback reason separately from the final convergence - failure reason. - - [x] Map existing min-step, nonconvergence and linear-solver failure paths - into the new taxonomy. - - [x] Leave unavailable reasons as reserved/documented ids until a real path - consumes them. -- Tests: - - [x] Extend `nonlinear_lifecycle` to verify reason-name stability. - - [x] Extend `solver_implicit` to verify at least min-step and - nonconvergence cutback reasons. -- Acceptance: - - [x] Every implemented 0.6.1 cutback reason is consumed by a regression - assertion. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure -``` - -### [x] TODO 0.6.1-3: Write lifecycle report output - -- Source: - - `docs/v6.1_development_plan.md` sections 4.3 and 5, NLHD-3. -- Implementation: - - [x] Add `nonlinear_lifecycle.csv` or append equivalent lifecycle summary - fields to an existing nonlinear report. - - [x] Cover initialized/no-solve, accepted increment and rejected/cutback - increment rows. - - [x] Include lifecycle summary, cutback reason, residual breakdown, solver - status and audit status columns. - - [x] Preserve old `continuation_path.csv` column order if that file is - extended again. -- Tests: - - [x] Add or extend an output checker to validate required lifecycle report - headers. - - [x] Verify at least one accepted row and one rejected/cutback row. -- Acceptance: - - [x] Missing lifecycle report fields cause a regression failure. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit)$" --output-on-failure -``` - -### [x] TODO 0.6.1-4: Stabilize contact state diagnostics - -- Source: - - `docs/v6.1_development_plan.md` sections 4.4 and 5, NLHD-4. -- Implementation: - - [x] Define stable contact state names: `open`, `closed-stick`, - `closed-slip`, `closed-restick`, `separating` and `failed-projection`. - - [x] Report state counters through existing contact diagnostics or a compact - helper. - - [x] Include gap maximum/mean/L2, slip increment/residual, friction residual - and active-set flip count where available. - - [x] Keep this diagnostic-only; do not rewrite contact solve state - ownership. -- Tests: - - [x] Extend `contact` or contact report tests to verify state names and - counters. - - [x] Verify unsupported/unavailable state fields default consistently. -- Acceptance: - - [x] Contact diagnostics can distinguish open, stick/slip and failed - projection states without parsing logs. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^contact$" --output-on-failure -``` - -### [x] TODO 0.6.1-5: Add compact contact long-path diagnostic smoke - -- Source: - - `docs/v6.1_development_plan.md` sections 4.5 and 5, NLHD-5. -- Implementation: - - [x] Select existing compact examples for two-block compression, block - sliding, shell-shell contact and shell-solid contact. - - [x] Add checker expectations for required diagnostic columns and finite - state counters. - - [x] Check gap/slip/friction/multiplier diagnostics across path steps. - - [x] Keep benchmark physics and tolerances bounded to existing examples. -- Tests: - - [x] Extend existing contact benchmark checkers or their CTest assertions. - - [x] Verify at least two path steps for one compact long-path case. -- Acceptance: - - [x] A compact contact path can fail diagnostics loudly if state or residual - fields disappear. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^contact$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^source_size$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg|c_api|cli_output_dir_boundary|vtk_output)$" --output-on-failure +ctest --test-dir build-codex-gcc -R "^(contact_omp1|contact_omp4|perf_contact_pair_omp_consistency)$" --output-on-failure ctest --test-dir build-codex-gcc -R "^example_(contact_two_blocks_compression|contact_block_sliding|shell_shell_contact|shell_solid_contact)_benchmark$" --output-on-failure -``` - -### [x] TODO 0.6.1-6: Add AL multiplier and friction diagnostic summaries - -- Source: - - `docs/v6.1_development_plan.md` sections 4.6 and 5, NLHD-6. -- Implementation: - - [x] Add multiplier residual trend and maximum augmented multiplier summary - fields. - - [x] Add augmentation update count and accepted-step penalty/augmentation - factor fields. - - [x] Add slip/friction residual summary fields where existing friction state - supports them. - - [x] Include restart before/after consistency checks for supported fields. -- Tests: - - [x] Extend `contact_multiplier_report` to consume new summary fields. - - [x] Extend `restart` or `contact` to compare supported multiplier/friction - summaries before and after restart. -- Acceptance: - - [x] AL/friction diagnostic summaries are visible in tests and survive the - covered restart path. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(contact_multiplier_report|restart)$" --output-on-failure -``` - -### [x] TODO 0.6.1-7: Add shared tangent-audit report shell - -- Source: - - `docs/v6.1_development_plan.md` sections 4.7 and 5, NLHD-7. -- Implementation: - - [x] Define a shared tangent-audit report schema with audit name, branch, - sample count, relative error and status fields. - - [x] Route existing material/contact/shell/Riks audit summaries into the - shared vocabulary where already available. - - [x] Add coverage counters for missing or not-applicable audit branches. - - [x] Document that this is an audit report shell, not production consistent - tangent delivery. -- Tests: - - [x] Extend existing tangent audit tests or add a schema checker. - - [x] Verify at least normal contact and one non-contact audit category in - the shared report vocabulary. -- Acceptance: - - [x] Tangent audit output has a uniform schema without changing production - tangent behavior. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^contact_mortar_tangent$" --output-on-failure -``` - -### [x] TODO 0.6.1-8: Harden Riks and arc diagnostics - -- Source: - - `docs/v6.1_development_plan.md` sections 4.8 and 5, NLHD-8. -- Implementation: - - [x] Record arc residual history for accepted Riks/arc increments. - - [x] Add predictor direction consistency and load-factor reversal indicators. - - [x] Add a simple turning-point indicator where current path data supports - it. - - [x] Add path/report fields that distinguish load-control Riks from direct - displacement control. -- Tests: - - [x] Extend `solver_implicit` to verify Riks/arc diagnostic fields. - - [x] Extend `implicit_inp` only if an existing deterministic input path can - consume the fields cheaply. -- Acceptance: - - [x] Riks/arc diagnostics expose residual and predictor/path direction state - without implementing mixed-control continuation. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(solver_implicit|implicit_inp)$" --output-on-failure -``` - -### [x] TODO 0.6.1-9: Add restart-after-each-accepted audit - -- Source: - - `docs/v6.1_development_plan.md` sections 4.9 and 5, NLHD-9. -- Implementation: - - [x] Add a compact multi-increment restart audit flow. - - [x] After each accepted increment, write restart, read into a fresh model - and compare lifecycle diagnostics. - - [x] Compare supported contact/material/path diagnostic summaries before and - after restart. - - [x] Continue one increment after restart to prove the restored state is - usable. -- Tests: - - [x] Extend `restart` or add a compact restart-lifecycle test. - - [x] Keep the model small and deterministic. -- Acceptance: - - [x] Restart audit covers more than one accepted increment without relying - on a large benchmark. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^restart$" --output-on-failure -``` - -### [x] TODO 0.6.1-10: Couple solver diagnostics to nonlinear rows - -- Source: - - `docs/v6.1_development_plan.md` sections 4.10 and 5, NLHD-10. -- Implementation: - - [x] Link matrix class, solver method, preconditioner, iteration count and - solver status into lifecycle or nonlinear report rows. - - [x] Include initial/final/relative residual where current solver diagnostics - already provide them. - - [x] Add a fallback marker for dense pivoting or method fallback paths if - available. - - [x] Keep solver selection behavior unchanged. -- Tests: - - [x] Extend `linear_solver_cg` for field availability and naming where - needed. - - [x] Extend `solver_implicit` to verify nonlinear rows include solver - diagnostics. -- Acceptance: - - [x] A nonlinear failure can be distinguished from a linear solver failure - through report/API fields. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(solver_implicit|linear_solver_cg)$" --output-on-failure -``` - -### [x] TODO 0.6.1-11: Synchronize documentation and benchmark matrix - -- Source: - - `docs/v6.1_development_plan.md` sections 4.11 and 5, DOC-1. -- Implementation: - - [x] Update `docs/v6_benchmark_matrix.md` with 0.6.1 diagnostic tests and - evidence placeholders. - - [x] Update interface docs with new lifecycle, cutback, contact and solver - diagnostic fields. - - [x] Update user/developer manuals with the 0.6.1 boundary and deferred - algorithm rewrites. - - [x] Add or update a 0.6.1 acceptance report section. -- Tests: - - [x] Run wording `rg` checks so docs do not claim 0.6.1 delivers complete - AL/mortar tangent, mixed-control continuation or cohesive mainline. -- Acceptance: - - [x] Documentation states that 0.6.1 delivers diagnostic hardening, while - larger solver rewrites remain follow-up work. - -Verified: - -```powershell -rg -n "0\.6\.1.*(complete|完整|industrial|生产一致切线|mixed-control continuation|AL/mortar consistent tangent).*交付|0\.6\.1.*delivers complete|0\.6\.1.*完整 AL|0\.6\.1.*mixed-control" docs -rg -n "0\.6\.1|nonlinear_lifecycle.csv|arc_mode|fem_tangent_audit_report|closed-stick|linear_fail_class" docs/v6_benchmark_matrix.md docs/v6_acceptance_report.md docs/07_user_manual.md docs/08_developer_manual.md -``` - -### [x] TODO 0.6.1-12: Update version, report and release evidence - -- Source: - - `docs/v6.1_development_plan.md` section 6, REL-1. -- Implementation: - - [x] Update benchmark/acceptance matrix with final 0.6.1 test evidence. - - [x] Update acceptance report with 0.6.1 scope, commands and limitations. - - [x] Raise project version only when 0.6.1 implementation is ready to close. - - [x] Keep deferred boundaries explicit in release documentation. -- Tests: - - [x] Run the planned 0.6.1 targeted regression command. - - [x] Run `ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure`. - - [x] Run `git diff --check`. -- Acceptance: - - [x] 0.6.1 closes with green targeted tests, green acceptance subset and - documented deferred boundaries. - -Verified: - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(smoke|perf_contact_pair_p1)$" --output-on-failure -ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure -ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure -git diff --check -``` - -## Suggested 0.6.1 Regression Commands - -```powershell -cmake --build build-codex-gcc --parallel -ctest --test-dir build-codex-gcc -R "^(nonlinear_lifecycle|solver_implicit|implicit_inp|restart|contact|contact_mortar_report|contact_multiplier_report|cohesive_contact|particle_acceptance|linear_solver_cg)$" --output-on-failure ctest --test-dir build-codex-gcc -L v5_acceptance --output-on-failure git diff --check ``` diff --git a/tools/testing/check_cli_output_dir.py b/tools/testing/check_cli_output_dir.py new file mode 100644 index 0000000..dbe33eb --- /dev/null +++ b/tools/testing/check_cli_output_dir.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""Check femlite CLI output-directory success and failure boundaries.""" + +from __future__ import annotations + +import os +import shutil +import subprocess +import sys +from pathlib import Path + + +def require(condition: bool, message: str) -> None: + if not condition: + raise AssertionError(message) + + +def run_command(command: list[str], cwd: Path) -> subprocess.CompletedProcess[str]: + return subprocess.run( + command, + cwd=cwd, + text=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + check=False, + ) + + +def main(argv: list[str]) -> int: + if len(argv) != 4: + print( + "usage: check_cli_output_dir.py ", + file=sys.stderr, + ) + return 2 + + repo_root = Path(argv[1]).resolve() + femlite_exe = Path(argv[2]).resolve() + build_dir = Path(argv[3]).resolve() + input_file = repo_root / "tests" / "data" / "c3d4_static_pull.inp" + + out_dir = build_dir / "cli_output_dir_boundary" / "nested" / "static" + if out_dir.parent.parent.exists(): + shutil.rmtree(out_dir.parent.parent) + + ok = run_command( + [ + str(femlite_exe), + str(input_file), + "--static-linear", + "--output-dir", + str(out_dir), + "--output-interval", + "1", + ], + repo_root, + ) + require(ok.returncode == 0, f"successful output-dir run failed:\n{ok.stdout}") + require(out_dir.is_dir(), "CLI did not create nested output directory") + require((out_dir / "history.csv").is_file(), "history.csv was not written") + require( + (out_dir / "result_00000001.vtk").is_file(), + "VTK output was not written in the requested directory", + ) + + bad_char = '"' if os.name == "nt" else "'" + bad_dir = build_dir / f"cli_output_dir_bad{bad_char}path" + bad = run_command( + [str(femlite_exe), str(input_file), "--output-dir", str(bad_dir)], + repo_root, + ) + require(bad.returncode != 0, "invalid output-dir unexpectedly succeeded") + require( + "output directory path must not contain" in bad.stdout + or "failed to create output directory" in bad.stdout, + f"invalid output-dir did not report a stable error:\n{bad.stdout}", + ) + + return 0 + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) diff --git a/tools/testing/check_perf_contact_pair_omp.py b/tools/testing/check_perf_contact_pair_omp.py index 872c6c1..d004f83 100644 --- a/tools/testing/check_perf_contact_pair_omp.py +++ b/tools/testing/check_perf_contact_pair_omp.py @@ -40,10 +40,12 @@ FLOAT_METRICS = ( "path_tan_f_sum", "path_gap_sum", "path_slip_sum", + "path_fric_work", "force_sum", "tan_force_sum", "gap_sum", "slip_sum", + "fric_work", ) @@ -113,6 +115,8 @@ def parse_metrics(output: str, threads: int) -> dict[str, float]: raise SystemExit(f"missing tangent checksum for OMP_NUM_THREADS={threads}") if values["path_gap_sum"] <= 0.0 or values["gap_sum"] <= 0.0: raise SystemExit(f"missing gap checksum for OMP_NUM_THREADS={threads}") + if values["path_fric_work"] < 0.0 or values["fric_work"] < 0.0: + raise SystemExit(f"negative friction work for OMP_NUM_THREADS={threads}") if values["state_maintained"] <= 0: raise SystemExit(f"missing maintained state for OMP_NUM_THREADS={threads}") if values["activation_count"] <= 0: @@ -125,6 +129,21 @@ def close_enough(left: float, right: float) -> bool: return abs(left - right) <= 1.0e-9 * scale +def compare_cases( + label: str, + reference: dict[str, float], + actual: dict[str, float], +) -> list[tuple[str, str]]: + mismatches: list[tuple[str, str]] = [] + for metric in INT_METRICS: + if reference[metric] != actual[metric]: + mismatches.append((label, metric)) + for metric in FLOAT_METRICS: + if not close_enough(reference[metric], actual[metric]): + mismatches.append((label, metric)) + return mismatches + + def main(argv: list[str]) -> int: if len(argv) != 3: print( @@ -135,38 +154,32 @@ def main(argv: list[str]) -> int: source_root = Path(argv[1]).resolve() executable = Path(argv[2]).resolve() - cases = { - threads: run_case(source_root, executable, threads) + runs = { + threads: [ + run_case(source_root, executable, threads), + run_case(source_root, executable, threads), + ] for threads in (1, 2, 4) } + repeat_mismatches = [ + mismatch + for threads, values in runs.items() + for mismatch in compare_cases(f"OMP={threads} repeat", values[0], values[1]) + ] + cases = {threads: values[0] for threads, values in runs.items()} serial = cases[1] - - mismatches = [ - (threads, metric) + cross_mismatches = [ + mismatch for threads, values in cases.items() if threads != 1 - for metric in INT_METRICS - if serial[metric] != values[metric] + for mismatch in compare_cases(f"OMP={threads}", serial, values) ] - float_mismatches = [ - (threads, metric) - for threads, values in cases.items() - if threads != 1 - for metric in FLOAT_METRICS - if not close_enough(serial[metric], values[metric]) - ] - if mismatches or float_mismatches: + if repeat_mismatches or cross_mismatches: print("OpenMP contact performance statistics differ:") - for threads, metric in mismatches: - print( - f" {metric}: OMP=1 {serial[metric]}, " - f"OMP={threads} {cases[threads][metric]}" - ) - for threads, metric in float_mismatches: - print( - f" {metric}: OMP=1 {serial[metric]:.12e}, " - f"OMP={threads} {cases[threads][metric]:.12e}" - ) + for label, metric in repeat_mismatches: + print(f" {label}: repeat mismatch in {metric}") + for label, metric in cross_mismatches: + print(f" {label}: mismatch versus OMP=1 in {metric}") return 1 print("perf_contact_pair path OpenMP consistency: PASS")