HaomingLuo commited on
Commit
bbe9b3e
·
verified ·
1 Parent(s): 21b4e50

Add DENIM incomplete-physics closure dataset and evidence

Browse files

Adds the 128-trajectory three-memory-to-two-memory closure cohort, DENIM versus GRU/J2 metrics, time-step and structural deployment gates, figures, source and reproducibility documentation.

DENIM_REPRODUCE.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Reproduce DENIM closure v1
2
+
3
+ From the AgentFEM-Physics-Data project root with the configured `fenicsx-env`:
4
+
5
+ ```bash
6
+ python -m src.generate_t2_graybox_closure --count-per-family 16 --force
7
+ python -m src.train_t2_graybox_closure
8
+ python -m src.validate_t2_graybox_closure
9
+ python -m src.plot_t2_graybox_closure
10
+ python -m pytest -q tests/test_t2_graybox_discrete_energy.py tests/test_t2_graybox_closure.py
11
+ ```
12
+
13
+ The data were generated with AgentFEM commit
14
+ `e76f2a96f58cc12f47fd6fae996c22fdca300ed1`. Reproducing generation therefore
15
+ requires AgentFEM and its FEniCSx environment. Loading the published DENIM
16
+ weights only requires PyTorch and the included core implementation.
DENIM_START_HERE.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DENIM incomplete-physics closure
2
+
3
+ DENIM is the **Discrete-Energy Neural Internal-variable Model** developed in
4
+ the AgentFEM material-loading-memory study.
5
+
6
+ This increment contains 128 complete multiaxial trajectories, each with 241
7
+ ordered states. Training uses five path families (80 trajectories), validation
8
+ uses rotating-principal loading (16), and test fully withholds out-of-phase
9
+ Lissajous and random-direction-block loading (32).
10
+
11
+ The reference is intentionally richer than the learned model:
12
+
13
+ - reference: three kinematic memories plus tabulated isotropic hardening;
14
+ - DENIM: two tensor memories plus a learned monotone saturating hardening law;
15
+ - known to DENIM: isotropic elasticity, J2 geometry and initial yield stress;
16
+ - hidden: reference hardening table, recovery parameters and update equations.
17
+
18
+ Start with:
19
+
20
+ - `data/t2_graybox_closure_v1/manifest.json`
21
+ - `artifacts/t2_graybox_closure_v1/model_metrics.json`
22
+ - `artifacts/t2_graybox_closure_v1/deployment_validation.json`
23
+ - `docs/T2_GRAYBOX_CLOSURE_RESULTS.md`
24
+
25
+ The HDF5 groups store strain, stress, plastic strain, PEEQ, plastic increments,
26
+ the three reference memories and the two-channel closure state. SI units and
27
+ Voigt order `xx, yy, zz, xy, yz, xz` with tensor shear are used throughout.
28
+
29
+ Data are CC BY 4.0. Included code uses the repository code license.
README.md CHANGED
@@ -30,9 +30,40 @@ repository now contains two compatible releases.
30
  - **T2 multiaxial v2:** 1,024 independently generated J2 and Chaboche
31
  trajectories in the complete five-dimensional deviatoric strain space,
32
  with ID, path-OOD and parameter-OOD splits.
 
 
 
33
 
34
- Start with `T2_V2_START_HERE.md` for the research extension or `START_HERE.md`
35
- for the original v1 release.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  ## Multiaxial v2 at a glance
38
 
@@ -82,6 +113,8 @@ misspecified physical models.
82
  - Manuscript roadmap: `docs/T2_MULTIAXIAL_RESEARCH_MEMO.md`
83
  - Literature map: `docs/T2_MULTIAXIAL_LITERATURE.md`
84
  - Commands: `T2_V2_REPRODUCE.md`
 
 
85
 
86
  The data were generated with AgentFEM commit
87
  `058faecc05aeda143d014fd229401003a9258bbb` (`0.3.7.dev0`). All quantities use
 
30
  - **T2 multiaxial v2:** 1,024 independently generated J2 and Chaboche
31
  trajectories in the complete five-dimensional deviatoric strain space,
32
  with ID, path-OOD and parameter-OOD splits.
33
+ - **T2 DENIM closure v1:** 128 multiaxial trajectories from a deliberately
34
+ richer three-memory, tabulated-hardening reference material. The published
35
+ two-memory DENIM model must learn the missing internal-variable closure.
36
 
37
+ Start with `DENIM_START_HERE.md` for the incomplete-physics study,
38
+ `T2_V2_START_HERE.md` for the multiaxial benchmark, or `START_HERE.md` for the
39
+ original v1 release.
40
+
41
+ ## DENIM incomplete-physics closure
42
+
43
+ ![DENIM closure summary](artifacts/t2_graybox_closure_v1/closure_summary.png)
44
+
45
+ DENIM stands for **Discrete-Energy Neural Internal-variable Model**. The
46
+ reference material contains three kinematic memory channels and a non-
47
+ exponential tabulated isotropic-hardening curve. DENIM retains only two memory
48
+ channels and receives none of the reference hardening equations or parameters.
49
+
50
+ Held-out non-proportional path results:
51
+
52
+ | Model | Test RMSE | Test R2 |
53
+ |---|---:|---:|
54
+ | Incomplete J2, no learned hardening | 59.541 MPa | 0.730208 |
55
+ | GRU | 76.988 MPa | 0.548933 |
56
+ | **DENIM** | **1.136 MPa** | **0.999902** |
57
+
58
+ The 918-parameter DENIM also passed coarse/fine increment checks and three
59
+ notched-bar deployment gates. Cyclic and monotonic reaction relative-L2 errors
60
+ were 0.636% and 0.500%; the severe cyclic stress test required one global
61
+ trust-region fallback. This remains a fixed synthetic material study with
62
+ internal-state supervision, not an experimental calibration or a certified
63
+ production material.
64
+
65
+ The standalone weights and model card are published at
66
+ [HaomingLuo/AgentFEM-DENIM](https://huggingface.co/HaomingLuo/AgentFEM-DENIM).
67
 
68
  ## Multiaxial v2 at a glance
69
 
 
113
  - Manuscript roadmap: `docs/T2_MULTIAXIAL_RESEARCH_MEMO.md`
114
  - Literature map: `docs/T2_MULTIAXIAL_LITERATURE.md`
115
  - Commands: `T2_V2_REPRODUCE.md`
116
+ - DENIM data and evidence: `DENIM_START_HERE.md`
117
+ - DENIM reproduction: `DENIM_REPRODUCE.md`
118
 
119
  The data were generated with AgentFEM commit
120
  `058faecc05aeda143d014fd229401003a9258bbb` (`0.3.7.dev0`). All quantities use
SHA256SUMS CHANGED
@@ -1,120 +1,23 @@
1
- 4a8e89fe65965e0b5ab34a6a1b8faa412666e426ce92500dba6af0c8f3e0ca0b CODE_LICENSE
2
- cdd59472c82b98d55f37288e0dd5994059194134fba6568029052eeff64faee4 DATA_LICENSE.md
3
- 882fd0ac467a25c367798249f997bcc5460be8c5041b720f5e52809140ef8f60 KNOWN_LIMITATIONS.md
4
- a0cbfe8420f8e7b9f27a5ec84c3b661a181112db356a8f0c4b4cb5dac66e7df5 PAPER_ROADMAP.md
5
- 2ff89e3e5cf36e56bfd986ba3dcc3837a07bb06153944455cc2fd532aefb34d2 README.md
6
- 5884a4ae4cb5fd092b6dec45bd61107cf2365fa0500e4c1ff34a051583a16148 REPRODUCE.md
7
- e552710f9fea8e21877e2011a457f75c790968fd5dbfd1549f066aa567875ea4 START_HERE.md
8
- 9e62aabbc8bd24dd38539b03bf5f9c1e73507bb9a9d1b73c37c0d3ca6b2f7f14 T2_V2_REPRODUCE.md
9
- c1329e03b40e57f66370343bf3f8a078149fefc28fbfbab80ee00412124571f7 T2_V2_START_HERE.md
10
- b06a19ffe36df25bbeedf35ccb8df9a9afff6df28870a354bf5c0dfc245fd948 artifacts/t2_material_loading_memory_v1/QUALITY_REPORT.md
11
- d19cc739e61edff4182ed700e924af7b051f24d37f07fbfa6581eff5e589483a artifacts/t2_material_loading_memory_v1/baseline_metrics.json
12
- 0537f7cd76aae72abfa644761b8eec2f58903e66b8b2c040354f71650cfe0615 artifacts/t2_material_loading_memory_v1/baseline_models.pt
13
- 9fc457b15d4e838a7dffd1d98d92fc002ee7d4e44f919c5ce1cf37e1bad75e8b artifacts/t2_material_loading_memory_v1/baseline_predictions.png
14
- d671538e1fe482de5ee12496185a7c2f65363d1376af4174016a902b1d8cb24d artifacts/t2_material_loading_memory_v1/hysteresis_preview.png
15
- 4986bb10e002c1c2c1648b8ff3ee20676b2982215494e7f7eafaabdf7eeda298 artifacts/t2_material_loading_memory_v1/quality.json
16
- 722c22826844dd451b28d938f72c09f0ee17a13cb7f599a8c9691570167273ad artifacts/t2_multiaxial_ood_v2/QUALITY_REPORT.md
17
- 54b95a1e83f0836a460370420e0eaed8653818f56252b5e2745739c42137be42 artifacts/t2_multiaxial_ood_v2/model_metrics.json
18
- 934b3cb6c5092849141f18ae7914ad58463b4f99ce4accd3a8d8eb390fca9a95 artifacts/t2_multiaxial_ood_v2/model_protocol_comparison.png
19
- 19f8bfeb1b19ac5836bdb1e8b2f857ed05a25d6904427333fe156582d209ade9 artifacts/t2_multiaxial_ood_v2/multiaxial_hysteresis_preview.png
20
- 7aae708be60dbb7a41b3c16068fd4eebc8cf4c5cabfe8f09ec417843f252bb18 artifacts/t2_multiaxial_ood_v2/physics_integrator_summary.json
21
- f70ebec439c8972772649e621c18def3f94c9fe6b832d4e8e9cf8801ebffa0c0 artifacts/t2_multiaxial_ood_v2/quality.json
22
- 69b803b9a1449bda3e8208fe27bcc1e868e4408b8582c2fb9c56a128922e971c artifacts/t2_multiaxial_ood_v2/structural_validation/mild_id/notched_bar_comparison.png
23
- 8eb1650c1358f618f02bd51e668c23dfe57f12555a9f8c8fa97df25f3c9cd889 artifacts/t2_multiaxial_ood_v2/structural_validation/mild_id/notched_bar_results.npz
24
- 3f13f49c24a0fd69e82710001a99aed812faceca330c11dedce6e2e48d511aaa artifacts/t2_multiaxial_ood_v2/structural_validation/mild_id/structural_validation.json
25
- d7af84c60b140016d5abba35454a63d84bd58584911d0496760d35b9f276c01f artifacts/t2_multiaxial_ood_v2/structural_validation/moderate_ood/notched_bar_comparison.png
26
- ded38f99016820dacb06d1a325b7cf6fd13a1d7053020803ff6c45ec2c2ec268 artifacts/t2_multiaxial_ood_v2/structural_validation/moderate_ood/notched_bar_results.npz
27
- 9b2d02481d691954fa2622cbf9608a3bc68858ccec44732b69b5bfea0c347f5e artifacts/t2_multiaxial_ood_v2/structural_validation/moderate_ood/structural_validation.json
28
- 740e645838d4b3276169a72e304aee7cab054dab8a63edb60d5867a87d63af57 artifacts/t2_multiaxial_ood_v2/structural_validation/severe_ood/notched_bar_comparison.png
29
- 999ef1d758cedec3d918662f223448826ff037b86423821f99d7f3e8bb959d51 artifacts/t2_multiaxial_ood_v2/structural_validation/severe_ood/notched_bar_results.npz
30
- 21491c8fe4848c20149f2f25b4baad4bda35f5806fd002606bbbf2b0798a4c3f artifacts/t2_multiaxial_ood_v2/structural_validation/severe_ood/structural_validation.json
31
- 2929ddd73ad5e2bb1258aa5501c89a41c2c1ce3548c5a9a84aa133e12b4ab1c2 artifacts/t2_multiaxial_ood_v2/training_summary.json
32
- 5054d2c6e6d289c928e91c67b1c2535b7fc765d00ed7e05c39ec364c35981851 configs/t2_material_loading_memory_pilot.json
33
- 50eb2dee418aba303e20ba6c219fb7d201d0a5a2391b933da2f3651e767191f5 configs/t2_material_loading_memory_v1.json
34
- 622237a1fe57b695ccdfc5b9d2a28d82d4e6be051be5443cd89537a0a091cbf6 configs/t2_multiaxial_ood_v2.json
35
- d2523144f022f78b71c0f5b006c03a393123dc8bcad190e23375a994a248330d data/t2_material_loading_memory_v1/design.jsonl
36
- 86ce6e7fa60f668736906c7158dfe0d5e3a8d40ca8a7e8d4e93df1d6a9afadfd data/t2_material_loading_memory_v1/index.jsonl
37
- 0c863700bb310edbe6363ad3ca143015279226b7d1af9db25599ae79f7beb297 data/t2_material_loading_memory_v1/manifest.json
38
- bf77420e04584151af10ea6e503fe4ab09946aa8c52d097ac8d4c902362387d3 data/t2_material_loading_memory_v1/shards/part-00000.h5
39
- 7278e897caf225f3cb3a6e34e65881fc2c87f310f730245ab4bffb54ace475b3 data/t2_material_loading_memory_v1/shards/part-00001.h5
40
- 952b90eed1ce3ac288487cf31180384fc12f79aa03d95e4885bfd73b85c9a46d data/t2_material_loading_memory_v1/shards/part-00002.h5
41
- 5de72c7a4aba0594945cb381c33696c25c58c6f72c873098852ce68e0f447094 data/t2_material_loading_memory_v1/shards/part-00003.h5
42
- 37edc592132c17f9c0e0f186cf2f0fab60d7abf6135ed31834003ed3d6595801 data/t2_material_loading_memory_v1/shards/part-00004.h5
43
- 7039ab13425efac4e7bbdd415d31a5276acd3617a22163ad563c6817fca7360e data/t2_material_loading_memory_v1/shards/part-00005.h5
44
- 67739a62d001131729ce506bb575a48555dd7dbbf393ac5a30cacf5094636854 data/t2_material_loading_memory_v1/shards/part-00006.h5
45
- 37d8caa79a1cb672288f38e1625b4837671bfb9210416b10ce4a60ad5a912ef8 data/t2_material_loading_memory_v1/shards/part-00007.h5
46
- c0915b6d8bed2c3bd2d5ae156ff42e6c491b81eb6fc797614c6124f7485b1184 data/t2_multiaxial_ood_v2/README.md
47
- 6eee820f46b173f927de5b5033a18b2e9e76c03f019c43f8fc505248b875a312 data/t2_multiaxial_ood_v2/design.jsonl
48
- a13c1a19098d42d8729184b975e96bbf911c340367c5b46d9aa87887b22268ba data/t2_multiaxial_ood_v2/index.jsonl
49
- 99793bdd23bb2abebc8d84ab2e2b7875d6c48c1ca62287d4cd83bff38dec83b6 data/t2_multiaxial_ood_v2/manifest.json
50
- 16456ca1050a8afff4b687610d0af7b952dcd2b82149ad61a13e7f1296daa1d4 data/t2_multiaxial_ood_v2/shards/part-00000.h5
51
- 3d56b126367a7cc2e7c7adeca5ae7badaafc91ad4130d5cab444a18c81ec3b10 data/t2_multiaxial_ood_v2/shards/part-00001.h5
52
- 7742b2533ae3a7c2f5018e83abfa44c236caed8c11766d357f56dc92b136f84c data/t2_multiaxial_ood_v2/shards/part-00002.h5
53
- 189d2ef804c3639fb85a58bddacc982e2d7634add25f0ea214c2652f69193aa6 data/t2_multiaxial_ood_v2/shards/part-00003.h5
54
- 364cdd35f7d8280992267ceda7c4313a197811f8df408763c1f60a144a2a0c59 data/t2_multiaxial_ood_v2/shards/part-00004.h5
55
- bf3abef7c1a1c1686725014f5be2b49189bca023014d889d418c8950a7699e80 data/t2_multiaxial_ood_v2/shards/part-00005.h5
56
- 27fd47d03fff7ca8e394be61d4a4af2366de9d38ed695e47cbb2ae1fa8c90af7 data/t2_multiaxial_ood_v2/shards/part-00006.h5
57
- 9d1b9d2bc4770cd67516b2f56ba56ae951d6d072a0f0286efccd18c6e94a686e data/t2_multiaxial_ood_v2/shards/part-00007.h5
58
- 961e1520be9d9f6277423f5f2d422ccc9fde1a7c680d65a66724107edad43365 docs/T2_MULTIAXIAL_LITERATURE.md
59
- 46dd7c86bf01b1faffb6216b171452ead2fc5c449512e34683f21ed6c907fd01 docs/T2_MULTIAXIAL_RESEARCH_MEMO.md
60
- bcb156b8ecc18d5f222e9671dcf792a142fa7969b0eb9455591506a66ed21c36 environment-reproduce.yml
61
- f841ccfb11c917545824bb4aaae605f39ce16aa1441f2a6ca182b5c8951c193a environment-use.yml
62
- 2b0b7be156eae06668a54ab20ad40a7b16dc0d3ce27083096003f188a64054bd models/t2_multiaxial_ood_v2/README.md
63
- c078b5514c8fc2245be0dcb5a7051a9e229f4168dc4ace5753ef8bbc6dd775d4 models/t2_multiaxial_ood_v2/id_causal_tcn.pt
64
- a28b9731ef309c31d721086e5c4d44a4fcedebb3f2284d42dbfc4ca99bee1678 models/t2_multiaxial_ood_v2/id_causal_tcn_history.json
65
- b346b3f373d5bea97febc396cb0f4f4c8db59041c97dcea345e975624605d0fb models/t2_multiaxial_ood_v2/id_gru.pt
66
- 5dbe2d240055d660b1f2b65d6b795c14d6164674a907af066454d8730dc5927a models/t2_multiaxial_ood_v2/id_gru_history.json
67
- c058e02c5283f9367b97c68bcdcf66d9319462a2d60b23e7587162a09cd1da5b models/t2_multiaxial_ood_v2/id_lstm.pt
68
- f297cf91466d3fe8f8efb48ff38f55b74c3f95e80a3d32cc5b38dcd5e6ba373d models/t2_multiaxial_ood_v2/id_lstm_history.json
69
- 4c682f1bc1ec6c8d2db5f542367fbd6daa4922ef566387d2f35974fbd669027b models/t2_multiaxial_ood_v2/id_normalization.json
70
- e46c537a2963fbe6bea4c215f4118ca0b496ebfda8f5e2c0cf31a5ba455b0430 models/t2_multiaxial_ood_v2/id_physics_integrator_nn.pt
71
- b535a1dd4e4682a96a9d5d5b9e3405ef16b058956763f66125bc3f03d76010f6 models/t2_multiaxial_ood_v2/id_physics_integrator_nn_history.json
72
- 600e6e021e63990c005cab724397d42eaf49b3c0f06a3e6974bf44c6fe542498 models/t2_multiaxial_ood_v2/id_physics_state_gru.pt
73
- 56e443773f51c475d624041e169eb170a6552e357e905f56cfd84d727d881ebd models/t2_multiaxial_ood_v2/id_physics_state_gru_history.json
74
- e46bcadac4daaee66b2efdba5f790e9e28a330036172aa65ae1f4cc14df4d47a models/t2_multiaxial_ood_v2/id_pointwise_mlp.pt
75
- 0e14ef379256b97176cf73fd4c83754d8ef956de4ef51f3b3d096478096a8f7c models/t2_multiaxial_ood_v2/id_pointwise_mlp_history.json
76
- ced5a5222c7656c1347b8f8c7380f050ef9d2f758e8548e0ce28b69bdc65c6b5 models/t2_multiaxial_ood_v2/parameter_ood_causal_tcn.pt
77
- 55b6f565a9a5b0b61bbba3a7dcc0572c8572f19939b07a036e791b4e60a76153 models/t2_multiaxial_ood_v2/parameter_ood_causal_tcn_history.json
78
- da578b8b562530dbe6425caaa9cdbab2230957161258c11a7a2b9a204d1ab029 models/t2_multiaxial_ood_v2/parameter_ood_gru.pt
79
- f5c785caf4fa75943b3451aeb051a375ca5a1b00abaed603a3e4ee15c50ef254 models/t2_multiaxial_ood_v2/parameter_ood_gru_history.json
80
- c267359a397e0c27ee11a4f220c2ec8eef8390e70389e92bcb0f4d1507dbed52 models/t2_multiaxial_ood_v2/parameter_ood_lstm.pt
81
- 700b2a2035da1090f74a4355678c7970f63b98582674cc720cb80bb130b2ac56 models/t2_multiaxial_ood_v2/parameter_ood_lstm_history.json
82
- 1526e6ab0f9c5a9641bf50443445cb072ace38536610bc7c1762bb751e71873e models/t2_multiaxial_ood_v2/parameter_ood_normalization.json
83
- cf8f6a75d1356e08ccf2439f93f49c4dc629456974eeba1159572f198755313c models/t2_multiaxial_ood_v2/parameter_ood_physics_integrator_nn.pt
84
- 6137632878dd2ec15cf356ebe0dd486bb708453c8a241cee96d782579bc8e612 models/t2_multiaxial_ood_v2/parameter_ood_physics_integrator_nn_history.json
85
- 59db7abe20857c7dcbe157b9d702bc71958771692fe0ea9f391dde8efeca74ea models/t2_multiaxial_ood_v2/parameter_ood_physics_state_gru.pt
86
- 7fb343b9efdbaca64e9e06ecd52df7900c248c99c9782aed393537d49bbbee86 models/t2_multiaxial_ood_v2/parameter_ood_physics_state_gru_history.json
87
- bfd9dd42ffb36a38c6591ed5c68eaef47e19c580b83669ca68c5ac8bc1eaaf30 models/t2_multiaxial_ood_v2/parameter_ood_pointwise_mlp.pt
88
- 230bedd7aab23020f42f956b3ba550fbb43e0da8a4adfad04d9baa954a3b91bd models/t2_multiaxial_ood_v2/parameter_ood_pointwise_mlp_history.json
89
- 4f57c8c7cd668fec6224689574a744d5ed27f9ce3d6ba89388a2b869d12d85b4 models/t2_multiaxial_ood_v2/path_ood_causal_tcn.pt
90
- 522fc250a90575319caef23831bbef3a26fa5b2d3fc6f6c457a7c13bb1e44cf0 models/t2_multiaxial_ood_v2/path_ood_causal_tcn_history.json
91
- db6dd4f4f314cefc83a0cb2317bd22dc571ad49ce8945d968bcf6a9d4039618a models/t2_multiaxial_ood_v2/path_ood_gru.pt
92
- d41faf4dab2173f672dae3d899ce00f15c372f4ee32e2aa0303a496fe3b451a1 models/t2_multiaxial_ood_v2/path_ood_gru_history.json
93
- ee2a768fa9e4cbb291e2bd39f20366da297a3f18765d7f3b5b87c93dae5bb51b models/t2_multiaxial_ood_v2/path_ood_lstm.pt
94
- 255dfbf87c1a6cd1d87dba06d4ecdba36522a99831928ae9ac3d8ef91d9cf904 models/t2_multiaxial_ood_v2/path_ood_lstm_history.json
95
- 99754f29cc5cc085716ccc1549c897d833589d17bd343c4da732f375257a7082 models/t2_multiaxial_ood_v2/path_ood_normalization.json
96
- 8177fdd618367c478b1108ec0fad90be44a18df9ff1f9af3b719722ffa3a8e28 models/t2_multiaxial_ood_v2/path_ood_physics_integrator_nn.pt
97
- 7ba19d106d92a0c6308c3cfae0bb0ebc1cbeea0924e1c967ac82e8a85f768de3 models/t2_multiaxial_ood_v2/path_ood_physics_integrator_nn_history.json
98
- 14cb4597811838917c98e148fd1570881d4383771b897257e7bacc6ca0e724c8 models/t2_multiaxial_ood_v2/path_ood_physics_state_gru.pt
99
- d88b52443a7c0074516eddf5860c40cd40b488d872b905bac49c08f7980e2869 models/t2_multiaxial_ood_v2/path_ood_physics_state_gru_history.json
100
- e4bb90d495371ab8bc8bb5883cc5bcc6ececd3f62372b221ca6b4e98558d86fe models/t2_multiaxial_ood_v2/path_ood_pointwise_mlp.pt
101
- 5356d05b393fe7f8a09bd00c28466c965f7c2260b7b6ae05a11c59d75b0b54c9 models/t2_multiaxial_ood_v2/path_ood_pointwise_mlp_history.json
102
- 9098c128e0b540ab83b1f1323d1c3b437a8130a8a88309684fd931c09ca6d4fe reproduce_t2_v1.sh
103
- d36bef7aa852e850a524e22f4b9689325b40320ad3046004d2f31df4c7605e26 src/baseline_t2_material_loading_memory.py
104
- 21158e37d8742b20ef5817bb314fb0dfe926f9633b82087a063447d8e863f9fe src/load_t2_material_loading_memory.py
105
- 229915f1d28cceb7e63eb9795b0e9e640eae8c4ff38052c3374a5ef7d89ffd3b src/package_t2_material_loading_memory_v1.py
106
- 3521afa9ce4ebb5a9c2cdcf869612989057f9ba7e4b44101facda95d2764e09a src/package_t2_multiaxial_release.py
107
- f6d80c48d66c2d5e14fdccff65d9fecd8a632f5322f68eb5f9ec23679b8f67ed src/structural_validate_t2_models.py
108
- 79eddf3174eb343ef1e8dc4aef2df0a7be62819a03c594aaa22886fd49f57c2d src/t2_material_loading_memory.py
109
- 604bc6283e7a461073d03a3b69440873d46809baf9e2ca4c79dfbeaa0704a5d7 src/t2_material_loading_memory_v1.py
110
- ee8a54ed0243c0d834554c7cb728a496ab6df74308a20f9663c34a3e9b882eb0 src/t2_multiaxial_ood_v2.py
111
- 27653364825e5f6d64edb91c7669c40257ecfa839bdcc987f6150b7376706b9a src/train_t2_multiaxial_models.py
112
- 50b761b008c07ae8419db652a37270ebe15d5c9b7168d87cef1f836c9acc245f src/train_t2_physics_integrator.py
113
- 2efb9502d85dde486939d02613e13fe6d254e8c6e74e2d82f2eb3201c01d1ac7 src/verify_t2_download.py
114
- 79319ee3dc4c32abc5b9cf68ce5efd226c82d36c43cd74a26a7f49dddffe9154 src/verify_t2_multiaxial_download.py
115
- 05c9cc11d32f54c88d3769b394b15f14bc283dc1f10b33b187b9e59166c676d6 tests/test_t2_material_loading_memory.py
116
- de16ddbac7c1e9dd020d2fff57da76d56ffd4ba2ce3b1ef61b41f02295c89e5a tests/test_t2_material_loading_memory_v1.py
117
- f851886f02ce4e30c24881ef167ebb0462616a18d486ccf4d384afe61146dab2 tests/test_t2_multiaxial_models.py
118
- f135a64d401ca69f2774fca56d187b3570b733e339f272f13b6a06d3fc0d1d20 tests/test_t2_multiaxial_ood_v2.py
119
- b2753c68fb0b1819f281828cc84e741566453e70019243acedf51dd07ed997d3 tests/test_t2_physics_integrator.py
120
- 5e391f7cdcdf4ba800bb87d6d1c2db58131303f91376df1aad78bcc2eb47149c tests/test_t2_structural_validation.py
 
1
+ 4a8e89fe65965e0b5ab34a6a1b8faa412666e426ce92500dba6af0c8f3e0ca0b ./CODE_LICENSE
2
+ cdd59472c82b98d55f37288e0dd5994059194134fba6568029052eeff64faee4 ./DATA_LICENSE.md
3
+ e05c7afc635aa69f6e617b2ad756ab6a5b3db1fff38c537d389aa8dfcdcbc2b8 ./DENIM_REPRODUCE.md
4
+ f4ee1edcdc64d659819fc747eefa7a2982785c81b07dd2ee75b49d9a8584c4d8 ./DENIM_START_HERE.md
5
+ 1f5f037829b9ab33e7c9277e8c881eed5b68d488f5c462843d28bdd24009e382 ./README.md
6
+ 5d83466373c7eea5391f03cc2b391f9da78e752f9f9c8811debead910e9638b8 ./artifacts/t2_graybox_closure_v1/closure_summary.png
7
+ f04ca496825ec0c84c11cc284d640aa0e195a21c89cd262065ddaddb9fedd2dc ./artifacts/t2_graybox_closure_v1/deployment_validation.json
8
+ 7b5f00ce4b68f9caf3bd05842d2163317a1a8b4250a519ac3d26fecd3cc3616e ./artifacts/t2_graybox_closure_v1/model_metrics.json
9
+ 62c3839ce60377947ecc095ea9165d85a47a529a9d4817bfa97091c9a1ea4b72 ./artifacts/t2_graybox_closure_v1/structural_reaction_comparison.png
10
+ 1789c8070f012c57d02c106dfa4c9193d162d96d0124a02cb8ad48046632d86f ./data/t2_graybox_closure_v1/cohort.h5
11
+ 7cc21cbffa2a12740d16c37bc2250120c4bd68161bad20bf75fbfa8ae26c3c7e ./data/t2_graybox_closure_v1/manifest.json
12
+ 31157d577ae53f2f8a3eb4dc86cd7fd7d753edee4dcf26ffc12359ed2c98e531 ./docs/T2_GRAYBOX_CLOSURE_RESULTS.md
13
+ e5186581f3cda7806128858de98160e59198136bb2e6c171c91ee3fc7b0a6644 ./docs/T2_GRAYBOX_RESEARCH_DESIGN.md
14
+ fd22c6c892549d4ee651477d57f1ffdccc3232ee8e9bd068b43b716635e3c866 ./src/generate_t2_graybox_closure.py
15
+ d559606a3bbca6b9d1215a8d9a653fc1d2564f6338337dbc5623c8c3aca50d1c ./src/generate_t2_graybox_cohort.py
16
+ a4450ac5b1aad188b4a74d5b3b77988ef196efadcdcfa08d985fe99f9b8a4999 ./src/plot_t2_graybox_closure.py
17
+ 97c7683e8cd094299faf56bd6bfae208c9dbf279b237404b52c87877c242e815 ./src/t2_graybox_discrete_energy.py
18
+ 8a39134bad45d086e0966a93e7ed578fa1d6a8fd9c1eb4cfd3275c44b37b809a ./src/train_t2_graybox_closure.py
19
+ 45efa5e68e3cd554da9194214e31079d8ce539cd252f2222101c957661a421c2 ./src/train_t2_graybox_discrete_energy.py
20
+ 2ef6ae3dd51da5ce1343a8b6622f35220260a1554aa19ce89815ec462a8229e9 ./src/validate_t2_graybox.py
21
+ 6e2fbbb2a498b104d479ba3cd2c37797aaae2268c5e4781c705f1817e264637d ./src/validate_t2_graybox_closure.py
22
+ 32cbc95c13ee17a25eccd4f611a6fbf19a8fe17556bc7058dae3aca605aa8c00 ./tests/test_t2_graybox_closure.py
23
+ 81d3331a05ff897df65272927dab6214367567203f25b04869403ad5dd15ab33 ./tests/test_t2_graybox_discrete_energy.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
artifacts/t2_graybox_closure_v1/closure_summary.png ADDED

Git LFS Details

  • SHA256: 5d83466373c7eea5391f03cc2b391f9da78e752f9f9c8811debead910e9638b8
  • Pointer size: 131 Bytes
  • Size of remote file: 408 kB
artifacts/t2_graybox_closure_v1/deployment_validation.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "scope": "reference has three memories and tabulated hardening; deployed DENRM has two memories and no access to the reference equations",
3
+ "time_discretization": {
4
+ "121": {
5
+ "trajectory_count": 8,
6
+ "rmse_mpa": 0.9438070587644558,
7
+ "mae_mpa": 0.5064686423720376,
8
+ "maximum_yield_residual_pa": 0.23421859741210938
9
+ },
10
+ "481": {
11
+ "trajectory_count": 8,
12
+ "rmse_mpa": 0.9584221120986024,
13
+ "mae_mpa": 0.5178831071589605,
14
+ "maximum_yield_residual_pa": 0.062465548515319824
15
+ },
16
+ "terminal_121_to_481_relative_change": 0.010678476861357365
17
+ },
18
+ "structure": {
19
+ "mild_cyclic": {
20
+ "reaction_relative_l2": 0.0063571165780202015,
21
+ "maximum_absolute_reaction_error": 3322117.808588028,
22
+ "maximum_newton_iterations": 39,
23
+ "mean_newton_iterations": 3.1728395061728394,
24
+ "trust_region_fallback_count": 0,
25
+ "trust_region_fallback_steps": [],
26
+ "elapsed_seconds": 32.52564716688357
27
+ },
28
+ "severe_monotonic": {
29
+ "reaction_relative_l2": 0.004998587374687885,
30
+ "maximum_absolute_reaction_error": 2280042.1006396413,
31
+ "maximum_newton_iterations": 4,
32
+ "mean_newton_iterations": 2.918032786885246,
33
+ "trust_region_fallback_count": 0,
34
+ "trust_region_fallback_steps": [],
35
+ "elapsed_seconds": 22.391408500028774
36
+ },
37
+ "severe_cyclic_stress_test": {
38
+ "passed": true,
39
+ "maximum_newton_iterations": 68,
40
+ "trust_region_fallback_count": 1
41
+ }
42
+ }
43
+ }
artifacts/t2_graybox_closure_v1/model_metrics.json ADDED
@@ -0,0 +1,938 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "scope": "out-of-template fixed material: three-memory tabulated reference; two-memory DENRM closure; reference equations and parameters hidden",
3
+ "training": {
4
+ "denrm": {
5
+ "training_seconds": 5.88968341704458,
6
+ "best_validation_loss": 0.001059024827554822,
7
+ "steps": 1600,
8
+ "history": [
9
+ {
10
+ "step": 0,
11
+ "training_loss": 0.38579270243644714,
12
+ "validation_loss": 0.3402066230773926,
13
+ "moduli_pa": [
14
+ 36511551488.0,
15
+ 4961107456.0
16
+ ],
17
+ "recovery_mean": [
18
+ 53.978187561035156,
19
+ 53.607749938964844
20
+ ]
21
+ },
22
+ {
23
+ "step": 25,
24
+ "training_loss": 0.362447053194046,
25
+ "validation_loss": 0.3224169611930847,
26
+ "moduli_pa": [
27
+ 34367172608.0,
28
+ 5155069952.0
29
+ ],
30
+ "recovery_mean": [
31
+ 66.52778625488281,
32
+ 42.87104034423828
33
+ ]
34
+ },
35
+ {
36
+ "step": 50,
37
+ "training_loss": 0.34120920300483704,
38
+ "validation_loss": 0.30471307039260864,
39
+ "moduli_pa": [
40
+ 32751876096.0,
41
+ 5379547136.0
42
+ ],
43
+ "recovery_mean": [
44
+ 91.26919555664062,
45
+ 24.301742553710938
46
+ ]
47
+ },
48
+ {
49
+ "step": 75,
50
+ "training_loss": 0.3269484341144562,
51
+ "validation_loss": 0.28713279962539673,
52
+ "moduli_pa": [
53
+ 31651561472.0,
54
+ 5652205056.0
55
+ ],
56
+ "recovery_mean": [
57
+ 84.29915618896484,
58
+ 20.22152328491211
59
+ ]
60
+ },
61
+ {
62
+ "step": 100,
63
+ "training_loss": 0.3009229302406311,
64
+ "validation_loss": 0.2689945101737976,
65
+ "moduli_pa": [
66
+ 30809159680.0,
67
+ 5966798336.0
68
+ ],
69
+ "recovery_mean": [
70
+ 83.6806869506836,
71
+ 18.058650970458984
72
+ ]
73
+ },
74
+ {
75
+ "step": 125,
76
+ "training_loss": 0.2786237597465515,
77
+ "validation_loss": 0.2504095137119293,
78
+ "moduli_pa": [
79
+ 30237321216.0,
80
+ 6323388416.0
81
+ ],
82
+ "recovery_mean": [
83
+ 81.95033264160156,
84
+ 18.312686920166016
85
+ ]
86
+ },
87
+ {
88
+ "step": 150,
89
+ "training_loss": 0.25676900148391724,
90
+ "validation_loss": 0.23147740960121155,
91
+ "moduli_pa": [
92
+ 29915416576.0,
93
+ 6708836864.0
94
+ ],
95
+ "recovery_mean": [
96
+ 81.4782485961914,
97
+ 15.426806449890137
98
+ ]
99
+ },
100
+ {
101
+ "step": 175,
102
+ "training_loss": 0.23221440613269806,
103
+ "validation_loss": 0.21231752634048462,
104
+ "moduli_pa": [
105
+ 29674477568.0,
106
+ 7121011200.0
107
+ ],
108
+ "recovery_mean": [
109
+ 80.01480865478516,
110
+ 13.733681678771973
111
+ ]
112
+ },
113
+ {
114
+ "step": 200,
115
+ "training_loss": 0.20759211480617523,
116
+ "validation_loss": 0.19307036697864532,
117
+ "moduli_pa": [
118
+ 29439066112.0,
119
+ 7553696768.0
120
+ ],
121
+ "recovery_mean": [
122
+ 80.49824523925781,
123
+ 13.581315040588379
124
+ ]
125
+ },
126
+ {
127
+ "step": 225,
128
+ "training_loss": 0.19005323946475983,
129
+ "validation_loss": 0.17390401661396027,
130
+ "moduli_pa": [
131
+ 29217683456.0,
132
+ 7999151616.0
133
+ ],
134
+ "recovery_mean": [
135
+ 81.21581268310547,
136
+ 13.737420082092285
137
+ ]
138
+ },
139
+ {
140
+ "step": 250,
141
+ "training_loss": 0.16811104118824005,
142
+ "validation_loss": 0.1550476849079132,
143
+ "moduli_pa": [
144
+ 29005221888.0,
145
+ 8453497344.0
146
+ ],
147
+ "recovery_mean": [
148
+ 81.85221099853516,
149
+ 13.336631774902344
150
+ ]
151
+ },
152
+ {
153
+ "step": 275,
154
+ "training_loss": 0.14668172597885132,
155
+ "validation_loss": 0.13673055171966553,
156
+ "moduli_pa": [
157
+ 28820140032.0,
158
+ 8907949056.0
159
+ ],
160
+ "recovery_mean": [
161
+ 81.97718048095703,
162
+ 12.545027732849121
163
+ ]
164
+ },
165
+ {
166
+ "step": 300,
167
+ "training_loss": 0.12552151083946228,
168
+ "validation_loss": 0.11921704560518265,
169
+ "moduli_pa": [
170
+ 28673732608.0,
171
+ 9357985792.0
172
+ ],
173
+ "recovery_mean": [
174
+ 82.01515197753906,
175
+ 11.597881317138672
176
+ ]
177
+ },
178
+ {
179
+ "step": 325,
180
+ "training_loss": 0.10822976380586624,
181
+ "validation_loss": 0.10272443294525146,
182
+ "moduli_pa": [
183
+ 28560623616.0,
184
+ 9795586048.0
185
+ ],
186
+ "recovery_mean": [
187
+ 82.02208709716797,
188
+ 10.332350730895996
189
+ ]
190
+ },
191
+ {
192
+ "step": 350,
193
+ "training_loss": 0.09075888991355896,
194
+ "validation_loss": 0.08739122003316879,
195
+ "moduli_pa": [
196
+ 28471363584.0,
197
+ 10213148672.0
198
+ ],
199
+ "recovery_mean": [
200
+ 81.90467834472656,
201
+ 9.32406997680664
202
+ ]
203
+ },
204
+ {
205
+ "step": 375,
206
+ "training_loss": 0.07610809057950974,
207
+ "validation_loss": 0.07339120656251907,
208
+ "moduli_pa": [
209
+ 28399831040.0,
210
+ 10600233984.0
211
+ ],
212
+ "recovery_mean": [
213
+ 81.78054809570312,
214
+ 8.494053840637207
215
+ ]
216
+ },
217
+ {
218
+ "step": 400,
219
+ "training_loss": 0.06161889061331749,
220
+ "validation_loss": 0.060893524438142776,
221
+ "moduli_pa": [
222
+ 28341405696.0,
223
+ 10953349120.0
224
+ ],
225
+ "recovery_mean": [
226
+ 81.67314910888672,
227
+ 7.281245231628418
228
+ ]
229
+ },
230
+ {
231
+ "step": 425,
232
+ "training_loss": 0.049724966287612915,
233
+ "validation_loss": 0.04988915100693703,
234
+ "moduli_pa": [
235
+ 28292188160.0,
236
+ 11269372928.0
237
+ ],
238
+ "recovery_mean": [
239
+ 81.47404479980469,
240
+ 6.630867004394531
241
+ ]
242
+ },
243
+ {
244
+ "step": 450,
245
+ "training_loss": 0.03952129930257797,
246
+ "validation_loss": 0.04041518270969391,
247
+ "moduli_pa": [
248
+ 28249556992.0,
249
+ 11541736448.0
250
+ ],
251
+ "recovery_mean": [
252
+ 81.29922485351562,
253
+ 6.021451473236084
254
+ ]
255
+ },
256
+ {
257
+ "step": 475,
258
+ "training_loss": 0.03089054673910141,
259
+ "validation_loss": 0.032407063990831375,
260
+ "moduli_pa": [
261
+ 28213374976.0,
262
+ 11774376960.0
263
+ ],
264
+ "recovery_mean": [
265
+ 81.13003540039062,
266
+ 5.364430904388428
267
+ ]
268
+ },
269
+ {
270
+ "step": 500,
271
+ "training_loss": 0.02404674142599106,
272
+ "validation_loss": 0.025776276364922523,
273
+ "moduli_pa": [
274
+ 28182515712.0,
275
+ 11968174080.0
276
+ ],
277
+ "recovery_mean": [
278
+ 80.99635314941406,
279
+ 4.950754642486572
280
+ ]
281
+ },
282
+ {
283
+ "step": 525,
284
+ "training_loss": 0.018640588968992233,
285
+ "validation_loss": 0.020371830090880394,
286
+ "moduli_pa": [
287
+ 28155969536.0,
288
+ 12126825472.0
289
+ ],
290
+ "recovery_mean": [
291
+ 80.88662719726562,
292
+ 4.511253833770752
293
+ ]
294
+ },
295
+ {
296
+ "step": 550,
297
+ "training_loss": 0.01432683877646923,
298
+ "validation_loss": 0.016041528433561325,
299
+ "moduli_pa": [
300
+ 28133527552.0,
301
+ 12256707584.0
302
+ ],
303
+ "recovery_mean": [
304
+ 80.75028991699219,
305
+ 4.252326488494873
306
+ ]
307
+ },
308
+ {
309
+ "step": 575,
310
+ "training_loss": 0.01105501875281334,
311
+ "validation_loss": 0.012632152996957302,
312
+ "moduli_pa": [
313
+ 28114489344.0,
314
+ 12360554496.0
315
+ ],
316
+ "recovery_mean": [
317
+ 80.64956665039062,
318
+ 4.030571937561035
319
+ ]
320
+ },
321
+ {
322
+ "step": 600,
323
+ "training_loss": 0.00851615983992815,
324
+ "validation_loss": 0.009983028285205364,
325
+ "moduli_pa": [
326
+ 28099076096.0,
327
+ 12442387456.0
328
+ ],
329
+ "recovery_mean": [
330
+ 80.56149291992188,
331
+ 3.8380002975463867
332
+ ]
333
+ },
334
+ {
335
+ "step": 625,
336
+ "training_loss": 0.006600786931812763,
337
+ "validation_loss": 0.007946695201098919,
338
+ "moduli_pa": [
339
+ 28086566912.0,
340
+ 12507003904.0
341
+ ],
342
+ "recovery_mean": [
343
+ 80.49900817871094,
344
+ 3.6947028636932373
345
+ ]
346
+ },
347
+ {
348
+ "step": 650,
349
+ "training_loss": 0.0053570871241390705,
350
+ "validation_loss": 0.0063914707861840725,
351
+ "moduli_pa": [
352
+ 28075978752.0,
353
+ 12558013440.0
354
+ ],
355
+ "recovery_mean": [
356
+ 80.43580627441406,
357
+ 3.6173617839813232
358
+ ]
359
+ },
360
+ {
361
+ "step": 675,
362
+ "training_loss": 0.004254811909049749,
363
+ "validation_loss": 0.005211687181144953,
364
+ "moduli_pa": [
365
+ 28067526656.0,
366
+ 12596985856.0
367
+ ],
368
+ "recovery_mean": [
369
+ 80.38912963867188,
370
+ 3.533376693725586
371
+ ]
372
+ },
373
+ {
374
+ "step": 700,
375
+ "training_loss": 0.003568624146282673,
376
+ "validation_loss": 0.004317067097872496,
377
+ "moduli_pa": [
378
+ 28060622848.0,
379
+ 12627590144.0
380
+ ],
381
+ "recovery_mean": [
382
+ 80.34644317626953,
383
+ 3.5010931491851807
384
+ ]
385
+ },
386
+ {
387
+ "step": 725,
388
+ "training_loss": 0.0030797154176980257,
389
+ "validation_loss": 0.003639265662059188,
390
+ "moduli_pa": [
391
+ 28055009280.0,
392
+ 12652579840.0
393
+ ],
394
+ "recovery_mean": [
395
+ 80.31182098388672,
396
+ 3.509168863296509
397
+ ]
398
+ },
399
+ {
400
+ "step": 750,
401
+ "training_loss": 0.0026616451796144247,
402
+ "validation_loss": 0.003123655915260315,
403
+ "moduli_pa": [
404
+ 28050157568.0,
405
+ 12671583232.0
406
+ ],
407
+ "recovery_mean": [
408
+ 80.28031158447266,
409
+ 3.511824369430542
410
+ ]
411
+ },
412
+ {
413
+ "step": 775,
414
+ "training_loss": 0.0023994487710297108,
415
+ "validation_loss": 0.0027253602165728807,
416
+ "moduli_pa": [
417
+ 28046227456.0,
418
+ 12685670400.0
419
+ ],
420
+ "recovery_mean": [
421
+ 80.25259399414062,
422
+ 3.5231423377990723
423
+ ]
424
+ },
425
+ {
426
+ "step": 800,
427
+ "training_loss": 0.0022111996077001095,
428
+ "validation_loss": 0.0024182889610528946,
429
+ "moduli_pa": [
430
+ 28043079680.0,
431
+ 12696512512.0
432
+ ],
433
+ "recovery_mean": [
434
+ 80.24041748046875,
435
+ 3.5388340950012207
436
+ ]
437
+ },
438
+ {
439
+ "step": 825,
440
+ "training_loss": 0.0019987437408417463,
441
+ "validation_loss": 0.0021795332431793213,
442
+ "moduli_pa": [
443
+ 28040531968.0,
444
+ 12704957440.0
445
+ ],
446
+ "recovery_mean": [
447
+ 80.23200988769531,
448
+ 3.5715126991271973
449
+ ]
450
+ },
451
+ {
452
+ "step": 850,
453
+ "training_loss": 0.002004354726523161,
454
+ "validation_loss": 0.001990213990211487,
455
+ "moduli_pa": [
456
+ 28038168576.0,
457
+ 12712061952.0
458
+ ],
459
+ "recovery_mean": [
460
+ 80.20845794677734,
461
+ 3.63393497467041
462
+ ]
463
+ },
464
+ {
465
+ "step": 875,
466
+ "training_loss": 0.0018554218113422394,
467
+ "validation_loss": 0.0018389651086181402,
468
+ "moduli_pa": [
469
+ 28036198400.0,
470
+ 12717541376.0
471
+ ],
472
+ "recovery_mean": [
473
+ 80.20215606689453,
474
+ 3.687563896179199
475
+ ]
476
+ },
477
+ {
478
+ "step": 900,
479
+ "training_loss": 0.0017452541505917907,
480
+ "validation_loss": 0.0017167719779536128,
481
+ "moduli_pa": [
482
+ 28034633728.0,
483
+ 12721585152.0
484
+ ],
485
+ "recovery_mean": [
486
+ 80.1939926147461,
487
+ 3.743239641189575
488
+ ]
489
+ },
490
+ {
491
+ "step": 925,
492
+ "training_loss": 0.001715177553705871,
493
+ "validation_loss": 0.0016167458379641175,
494
+ "moduli_pa": [
495
+ 28033349632.0,
496
+ 12725056512.0
497
+ ],
498
+ "recovery_mean": [
499
+ 80.1828384399414,
500
+ 3.8185606002807617
501
+ ]
502
+ },
503
+ {
504
+ "step": 950,
505
+ "training_loss": 0.0016669955803081393,
506
+ "validation_loss": 0.001535505405627191,
507
+ "moduli_pa": [
508
+ 28032174080.0,
509
+ 12727435264.0
510
+ ],
511
+ "recovery_mean": [
512
+ 80.17253875732422,
513
+ 3.88539719581604
514
+ ]
515
+ },
516
+ {
517
+ "step": 975,
518
+ "training_loss": 0.0016166572459042072,
519
+ "validation_loss": 0.0014670428354293108,
520
+ "moduli_pa": [
521
+ 28031420416.0,
522
+ 12729533440.0
523
+ ],
524
+ "recovery_mean": [
525
+ 80.17072296142578,
526
+ 3.940000057220459
527
+ ]
528
+ },
529
+ {
530
+ "step": 1000,
531
+ "training_loss": 0.0015592570416629314,
532
+ "validation_loss": 0.0014085541479289532,
533
+ "moduli_pa": [
534
+ 28030697472.0,
535
+ 12731159552.0
536
+ ],
537
+ "recovery_mean": [
538
+ 80.168701171875,
539
+ 3.995509386062622
540
+ ]
541
+ },
542
+ {
543
+ "step": 1025,
544
+ "training_loss": 0.001497658435255289,
545
+ "validation_loss": 0.0013588758883997798,
546
+ "moduli_pa": [
547
+ 28029941760.0,
548
+ 12732693504.0
549
+ ],
550
+ "recovery_mean": [
551
+ 80.16358947753906,
552
+ 4.0645270347595215
553
+ ]
554
+ },
555
+ {
556
+ "step": 1050,
557
+ "training_loss": 0.0014918273082002997,
558
+ "validation_loss": 0.0013167214347049594,
559
+ "moduli_pa": [
560
+ 28029257728.0,
561
+ 12734109696.0
562
+ ],
563
+ "recovery_mean": [
564
+ 80.15717315673828,
565
+ 4.141843318939209
566
+ ]
567
+ },
568
+ {
569
+ "step": 1075,
570
+ "training_loss": 0.0014394468162208796,
571
+ "validation_loss": 0.0012805506121367216,
572
+ "moduli_pa": [
573
+ 28028692480.0,
574
+ 12735278080.0
575
+ ],
576
+ "recovery_mean": [
577
+ 80.15647888183594,
578
+ 4.207617282867432
579
+ ]
580
+ },
581
+ {
582
+ "step": 1100,
583
+ "training_loss": 0.0014387787086889148,
584
+ "validation_loss": 0.00124912871979177,
585
+ "moduli_pa": [
586
+ 28028207104.0,
587
+ 12736008192.0
588
+ ],
589
+ "recovery_mean": [
590
+ 80.15387725830078,
591
+ 4.281273365020752
592
+ ]
593
+ },
594
+ {
595
+ "step": 1125,
596
+ "training_loss": 0.0014404304092749953,
597
+ "validation_loss": 0.0012217233888804913,
598
+ "moduli_pa": [
599
+ 28027781120.0,
600
+ 12736673792.0
601
+ ],
602
+ "recovery_mean": [
603
+ 80.15155029296875,
604
+ 4.345944881439209
605
+ ]
606
+ },
607
+ {
608
+ "step": 1150,
609
+ "training_loss": 0.001406863215379417,
610
+ "validation_loss": 0.0011979984119534492,
611
+ "moduli_pa": [
612
+ 28027357184.0,
613
+ 12737250304.0
614
+ ],
615
+ "recovery_mean": [
616
+ 80.1491928100586,
617
+ 4.400686740875244
618
+ ]
619
+ },
620
+ {
621
+ "step": 1175,
622
+ "training_loss": 0.0013912664726376534,
623
+ "validation_loss": 0.0011767047690227628,
624
+ "moduli_pa": [
625
+ 28027031552.0,
626
+ 12737569792.0
627
+ ],
628
+ "recovery_mean": [
629
+ 80.15200805664062,
630
+ 4.452568054199219
631
+ ]
632
+ },
633
+ {
634
+ "step": 1200,
635
+ "training_loss": 0.0013114067260175943,
636
+ "validation_loss": 0.0011584279127418995,
637
+ "moduli_pa": [
638
+ 28026796032.0,
639
+ 12738101248.0
640
+ ],
641
+ "recovery_mean": [
642
+ 80.1464614868164,
643
+ 4.505070686340332
644
+ ]
645
+ },
646
+ {
647
+ "step": 1225,
648
+ "training_loss": 0.0013662618584930897,
649
+ "validation_loss": 0.0011425709817558527,
650
+ "moduli_pa": [
651
+ 28026439680.0,
652
+ 12738462720.0
653
+ ],
654
+ "recovery_mean": [
655
+ 80.1444320678711,
656
+ 4.5508131980896
657
+ ]
658
+ },
659
+ {
660
+ "step": 1250,
661
+ "training_loss": 0.001352808903902769,
662
+ "validation_loss": 0.0011285572545602918,
663
+ "moduli_pa": [
664
+ 28026210304.0,
665
+ 12738686976.0
666
+ ],
667
+ "recovery_mean": [
668
+ 80.14773559570312,
669
+ 4.593008518218994
670
+ ]
671
+ },
672
+ {
673
+ "step": 1275,
674
+ "training_loss": 0.0013008920941501856,
675
+ "validation_loss": 0.0011164838215336204,
676
+ "moduli_pa": [
677
+ 28026007552.0,
678
+ 12738899968.0
679
+ ],
680
+ "recovery_mean": [
681
+ 80.14260864257812,
682
+ 4.6314473152160645
683
+ ]
684
+ },
685
+ {
686
+ "step": 1300,
687
+ "training_loss": 0.0013721792493015528,
688
+ "validation_loss": 0.001106198993511498,
689
+ "moduli_pa": [
690
+ 28025753600.0,
691
+ 12739145728.0
692
+ ],
693
+ "recovery_mean": [
694
+ 80.14543914794922,
695
+ 4.6689934730529785
696
+ ]
697
+ },
698
+ {
699
+ "step": 1325,
700
+ "training_loss": 0.0013383395271375775,
701
+ "validation_loss": 0.0010971891460940242,
702
+ "moduli_pa": [
703
+ 28025583616.0,
704
+ 12739411968.0
705
+ ],
706
+ "recovery_mean": [
707
+ 80.14244079589844,
708
+ 4.707152843475342
709
+ ]
710
+ },
711
+ {
712
+ "step": 1350,
713
+ "training_loss": 0.001375432126224041,
714
+ "validation_loss": 0.0010895031737163663,
715
+ "moduli_pa": [
716
+ 28025454592.0,
717
+ 12739528704.0
718
+ ],
719
+ "recovery_mean": [
720
+ 80.14447784423828,
721
+ 4.735220432281494
722
+ ]
723
+ },
724
+ {
725
+ "step": 1375,
726
+ "training_loss": 0.0013677821261808276,
727
+ "validation_loss": 0.0010831705294549465,
728
+ "moduli_pa": [
729
+ 28025354240.0,
730
+ 12739641344.0
731
+ ],
732
+ "recovery_mean": [
733
+ 80.14130401611328,
734
+ 4.761801719665527
735
+ ]
736
+ },
737
+ {
738
+ "step": 1400,
739
+ "training_loss": 0.001299329218454659,
740
+ "validation_loss": 0.0010778201976791024,
741
+ "moduli_pa": [
742
+ 28025284608.0,
743
+ 12739703808.0
744
+ ],
745
+ "recovery_mean": [
746
+ 80.14286804199219,
747
+ 4.782402515411377
748
+ ]
749
+ },
750
+ {
751
+ "step": 1425,
752
+ "training_loss": 0.0013210629113018513,
753
+ "validation_loss": 0.0010733811650425196,
754
+ "moduli_pa": [
755
+ 28025257984.0,
756
+ 12739722240.0
757
+ ],
758
+ "recovery_mean": [
759
+ 80.14280700683594,
760
+ 4.800633430480957
761
+ ]
762
+ },
763
+ {
764
+ "step": 1450,
765
+ "training_loss": 0.0013196938671171665,
766
+ "validation_loss": 0.001069833291694522,
767
+ "moduli_pa": [
768
+ 28025192448.0,
769
+ 12739804160.0
770
+ ],
771
+ "recovery_mean": [
772
+ 80.14232635498047,
773
+ 4.815746307373047
774
+ ]
775
+ },
776
+ {
777
+ "step": 1475,
778
+ "training_loss": 0.001338963396847248,
779
+ "validation_loss": 0.0010670004412531853,
780
+ "moduli_pa": [
781
+ 28025122816.0,
782
+ 12739866624.0
783
+ ],
784
+ "recovery_mean": [
785
+ 80.1413345336914,
786
+ 4.828505516052246
787
+ ]
788
+ },
789
+ {
790
+ "step": 1500,
791
+ "training_loss": 0.0012910541845485568,
792
+ "validation_loss": 0.0010647053131833673,
793
+ "moduli_pa": [
794
+ 28025067520.0,
795
+ 12739908608.0
796
+ ],
797
+ "recovery_mean": [
798
+ 80.14176177978516,
799
+ 4.839024543762207
800
+ ]
801
+ },
802
+ {
803
+ "step": 1525,
804
+ "training_loss": 0.0012954988051205873,
805
+ "validation_loss": 0.0010628391755744815,
806
+ "moduli_pa": [
807
+ 28025024512.0,
808
+ 12739956736.0
809
+ ],
810
+ "recovery_mean": [
811
+ 80.14260864257812,
812
+ 4.847418308258057
813
+ ]
814
+ },
815
+ {
816
+ "step": 1550,
817
+ "training_loss": 0.0013016999000683427,
818
+ "validation_loss": 0.001061332761310041,
819
+ "moduli_pa": [
820
+ 28024995840.0,
821
+ 12739997696.0
822
+ ],
823
+ "recovery_mean": [
824
+ 80.14128112792969,
825
+ 4.8541178703308105
826
+ ]
827
+ },
828
+ {
829
+ "step": 1575,
830
+ "training_loss": 0.0012788278982043266,
831
+ "validation_loss": 0.001060084905475378,
832
+ "moduli_pa": [
833
+ 28024963072.0,
834
+ 12740007936.0
835
+ ],
836
+ "recovery_mean": [
837
+ 80.14088439941406,
838
+ 4.859494686126709
839
+ ]
840
+ },
841
+ {
842
+ "step": 1599,
843
+ "training_loss": 0.0013084724778309464,
844
+ "validation_loss": 0.001059024827554822,
845
+ "moduli_pa": [
846
+ 28024963072.0,
847
+ 12740020224.0
848
+ ],
849
+ "recovery_mean": [
850
+ 80.14115142822266,
851
+ 4.864330768585205
852
+ ]
853
+ }
854
+ ]
855
+ },
856
+ "gru": {
857
+ "training_seconds": 12.37983391713351,
858
+ "best_validation_loss": 0.6981670260429382,
859
+ "epochs": 60
860
+ }
861
+ },
862
+ "models": {
863
+ "incomplete_j2": {
864
+ "train": {
865
+ "trajectory_count": 80,
866
+ "rmse_mpa": 51.314945220947266,
867
+ "mae_mpa": 27.921403884887695,
868
+ "r2": 0.7595025300979614
869
+ },
870
+ "validation": {
871
+ "trajectory_count": 16,
872
+ "rmse_mpa": 75.12889862060547,
873
+ "mae_mpa": 43.42414855957031,
874
+ "r2": 0.7140845060348511
875
+ },
876
+ "test": {
877
+ "trajectory_count": 32,
878
+ "rmse_mpa": 59.54129409790039,
879
+ "mae_mpa": 41.032962799072266,
880
+ "r2": 0.7302080392837524
881
+ },
882
+ "inference_seconds_all_trajectories": 2.0804422500077635
883
+ },
884
+ "gru": {
885
+ "train": {
886
+ "trajectory_count": 80,
887
+ "rmse_mpa": 23.556150436401367,
888
+ "mae_mpa": 14.713386535644531,
889
+ "r2": 0.9493206143379211
890
+ },
891
+ "validation": {
892
+ "trajectory_count": 16,
893
+ "rmse_mpa": 85.85247039794922,
894
+ "mae_mpa": 57.07228088378906,
895
+ "r2": 0.6266387701034546
896
+ },
897
+ "test": {
898
+ "trajectory_count": 32,
899
+ "rmse_mpa": 76.98819732666016,
900
+ "mae_mpa": 52.02629089355469,
901
+ "r2": 0.5489333271980286
902
+ },
903
+ "inference_seconds_all_trajectories": 0.06955916690640152
904
+ },
905
+ "denrm": {
906
+ "train": {
907
+ "trajectory_count": 80,
908
+ "rmse_mpa": 0.8718719482421875,
909
+ "mae_mpa": 0.4504835605621338,
910
+ "r2": 0.9999305605888367
911
+ },
912
+ "validation": {
913
+ "trajectory_count": 16,
914
+ "rmse_mpa": 1.9618406295776367,
915
+ "mae_mpa": 1.0055958032608032,
916
+ "r2": 0.9998050332069397
917
+ },
918
+ "test": {
919
+ "trajectory_count": 32,
920
+ "rmse_mpa": 1.135945200920105,
921
+ "mae_mpa": 0.6864870190620422,
922
+ "r2": 0.9999017715454102
923
+ },
924
+ "inference_seconds_all_trajectories": 10.250110333086923,
925
+ "maximum_yield_residual_pa": 96.0,
926
+ "maximum_plastic_trace": 6.51925802230835e-09,
927
+ "minimum_peeq_increment": 0.0,
928
+ "learned_moduli_pa": [
929
+ 28024965120.0,
930
+ 12740021248.0
931
+ ],
932
+ "minimum_reference_yield_dissipation": 0.0172310508787632,
933
+ "minimum_dynamic_recovery_dissipation": 4.376159267849289e-06,
934
+ "minimum_backward_euler_dissipation": -0.047634124755859375,
935
+ "maximum_energy_balance_relative_residual": 1.5819839518371737e-06
936
+ }
937
+ }
938
+ }
artifacts/t2_graybox_closure_v1/structural_reaction_comparison.png ADDED

Git LFS Details

  • SHA256: 62c3839ce60377947ecc095ea9165d85a47a529a9d4817bfa97091c9a1ea4b72
  • Pointer size: 131 Bytes
  • Size of remote file: 160 kB
data/t2_graybox_closure_v1/cohort.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1789c8070f012c57d02c106dfa4c9193d162d96d0124a02cb8ad48046632d86f
3
+ size 10093525
data/t2_graybox_closure_v1/manifest.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema": "agentfem.physics-data.incomplete-physics-closure",
3
+ "schema_version": "1.0.0",
4
+ "sample_count": 128,
5
+ "count_per_family": 16,
6
+ "points_per_trajectory": 241,
7
+ "path_families": [
8
+ "proportional_axial_cycle",
9
+ "proportional_shear_cycle",
10
+ "sequential_axial_shear",
11
+ "orthogonal_cross",
12
+ "nonproportional_square",
13
+ "rotating_principal_cycle",
14
+ "out_of_phase_lissajous",
15
+ "random_direction_blocks"
16
+ ],
17
+ "splits": {
18
+ "train": 80,
19
+ "validation": 16,
20
+ "test": 32
21
+ },
22
+ "known_to_model": [
23
+ "young_pa",
24
+ "poisson",
25
+ "yield_stress_pa",
26
+ "J2_geometry"
27
+ ],
28
+ "hidden_from_model": [
29
+ "three_reference_memory_channels",
30
+ "all_reference_recovery_parameters",
31
+ "piecewise_linear_isotropic_hardening_table",
32
+ "reference_hardening_update_equations"
33
+ ],
34
+ "intentional_model_mismatch": "reference has three memories; DENRM has two and must close the lumped medium/slow state",
35
+ "ground_truth": "AgentFEM three-memory Chaboche with tabulated isotropic hardening",
36
+ "scope": "Out-of-template synthetic closure cohort; fixed material.",
37
+ "elapsed_seconds": 21.372640792047605,
38
+ "bytes": 10093525
39
+ }
docs/T2_GRAYBOX_CLOSURE_RESULTS.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # T2真正不完备物理灰盒闭环:阶段结果
2
+
3
+ ## 结论
4
+
5
+ 本阶段已完成一条可复现的灰盒神经本构闭环,而不是增加一组黑箱网络对比。
6
+ 最终方法定名为 **DENIM(Discrete-Energy Neural Internal-variable Model,离散能量神经内变量模型)**。
7
+
8
+ 参考材料使用AgentFEM生成,包含三条运动硬化记忆通道和非指数、分段线性的各向同性
9
+ 硬化表;DENIM只保留两条记忆通道,且不知道参考硬化方程、表格和参数。第二、第三条
10
+ 参考记忆被合并为一个不完备状态,网络必须学习被删去自由度产生的有效闭合规律。
11
+
12
+ 在完整留出的两类非比例多轴路径上,DENIM应力RMSE为 **1.136 MPa**、
13
+ `R2=0.999902`;相同数据上的GRU为 **76.988 MPa**、`R2=0.548933`,
14
+ 不含硬化学习的J2骨架为 **59.541 MPa**、`R2=0.730208`。这说明结果不依赖
15
+ 提出模型与三通道参考模型同构。
16
+
17
+ ## 架构选择
18
+
19
+ 保留的物理:小应变各向同性弹性、J2屈服几何、关联流动、塑性不可压缩、非负塑性
20
+ 乘子、PEEQ单调、弹性预测—隐式塑性校正和状态提交/回滚。
21
+
22
+ 学习的未知物理:
23
+
24
+ - 零点锚定的各向同性硬化函数;采用正权重饱和指数混合和非负线性尾项,结构上保证
25
+ `R(0)=0`和`dR/dp>=0`,并能表达Voce型及表格型饱和硬化;
26
+ - 两条无迹张量记忆的正生产模量;
27
+ - 由客观张量不变量、流动方向投影、PEEQ和反向加载指标驱动的非负动态恢复率。
28
+
29
+ 网络只表示硬化闭合项,弹性、屈服几何、流动方向和局部隐式积分不交给网络猜测。
30
+ 最终DENIM仅 **918** 个可训练参数,GRU为 **49,254** 个参数。
31
+
32
+ ## 数据与划分
33
+
34
+ - 128条独立多轴轨迹,每条241个状态点;
35
+ - 训练80条:比例轴向、比例剪切、顺序轴剪、正交交叉和非比例方形路径;
36
+ - 验证16条:旋转主方向路径;
37
+ - 测试32条:完整留出的异相Lissajous和随机方向块;
38
+ - 模型只知道`E`、`nu`、初始屈服应力和J2骨架;
39
+ - 参考模型的三通道参数、表格硬化数据和更新方程全部隐藏。
40
+
41
+ 数据由AgentFEM提交`e76f2a96f58cc12f47fd6fae996c22fdca300ed1`生成。
42
+
43
+ ## 核心结果
44
+
45
+ | 模型 | 训练RMSE / MPa | 验证RMSE / MPa | 未见路径测试RMSE / MPa | 测试R2 |
46
+ |---|---:|---:|---:|---:|
47
+ | 不完备J2,无硬化学习 | 51.315 | 75.129 | 59.541 | 0.730208 |
48
+ | GRU | 23.556 | 85.852 | 76.988 | 0.548933 |
49
+ | DENIM | **0.872** | **1.962** | **1.136** | **0.999902** |
50
+
51
+ DENIM相比GRU将未见路径RMSE降低 **98.52%**,相比不完备J2降低 **98.09%**。
52
+ 训练用时5.89 s,GRU训练用时12.38 s。材料点推理方面,DENIM需要执行局部隐式
53
+ 返回映射,128条轨迹用时10.25 s;GRU直接前向推理为0.070 s。该结果体现了可信
54
+ 约束和速度之间的真实代价,后续应通过矢量化、隐式微分和编译优化缩小差距。
55
+
56
+ ## 物理与数值门槛
57
+
58
+ - 最大屈服一致性残差:96 Pa;
59
+ - 最大塑性应变迹:`6.52e-9`;
60
+ - 最小PEEQ增量:0;
61
+ - 最小动态恢复耗散:`4.38e-6 J/m3`;
62
+ - 离散能量余额最大相对残差:`1.58e-6`;
63
+ - 后向欧拉耗散最小值为`-4.76e-2 J/m3`,属于单精度分账舍入量,正式论文应以
64
+ 双精度重算并给出相对容差,不应直接宣称严格机器零负值。
65
+
66
+ 初版返回映射曾在粗时间步的近90度正交换向中数值爆炸。根因是直接对包含大剪切
67
+ 模量项的流动方向做固定点迭代,且根区间未闭合时仍接受状态。现已解析消去该大项,
68
+ 使用单调的标量一致性方程并扩大根区间。修正后:
69
+
70
+ - 121点粗时间步RMSE:0.944 MPa;
71
+ - 481点细时间步RMSE:0.958 MPa;
72
+ - 两种离散下精度基本一致;最大屈服残差均小于0.25 Pa;
73
+ - 121点与481点终态相对变化约1.07%,其中包含参考积分自身的离散差异。
74
+
75
+ ## 结构有限元部署
76
+
77
+ DENIM作为材料更新嵌入12单元变截面杆的全局平衡迭代,并与AgentFEM原生三通道
78
+ 表格硬化材料对照:
79
+
80
+ | 结构门槛 | 反力相对L2误差 | 最大Newton迭代 | 回退 |
81
+ |---|---:|---:|---:|
82
+ | 轻缺口循环加载 | **0.636%** | 39 | 0 |
83
+ | 强缺口单调加载 | **0.500%** | 4 | 0 |
84
+ | 强缺口循环压力测试 | 通过 | 68 | 1次信赖域回退 |
85
+
86
+ 强缺口循环工况通过,但一次回退说明当前有限差分方向切线在完全换向附近仍不够理想。
87
+ 论文升级应实现由局部隐式残量Jacobian得到的一致算法切线,并与固定旧状态有限差分
88
+ 逐点核验。
89
+
90
+ ## 科研价值与文章定位
91
+
92
+ 当前工作已经形成一篇论文的核心方法和主要数值证据:
93
+
94
+ 1. 不是轨迹到应力的黑箱映射,而是只学习未知硬化闭合项;
95
+ 2. 参考模型三条记忆、学习模型两条记忆,验证了不完备状态下的有效闭合;
96
+ 3. 物理约束由架构保证,不依赖损失惩罚;
97
+ 4. 粗细时间步、离散能量和结构Newton共同验证;
98
+ 5. 过程中暴露并修正了非比例大转向下返回映射失稳,形成可讨论的数值贡献。
99
+
100
+ 仅凭当前合成固定材料结果,适合形成高质量计算力学/工程AI论文初稿,尚不足以稳妥
101
+ 宣称CMAME/IJNME级完成稿。提升到更高水平至少还需要:
102
+
103
+ - 一组公开实验多轴循环数据,或自有实验数据;
104
+ - 从当前内部状态监督推进到应力—应变主监督,内部状态仅用于诊断或教师蒸馏;
105
+ - 自动/隐式一致切线和二维或三维积分点部署;
106
+ - 多随机种子、噪声与数据稀缺性统计,不需要海选更多网络;
107
+ - 与经标定经典模型比较,而不只比较无硬化J2和GRU。
108
+
109
+ 建议论文题目:
110
+
111
+ > **From trajectory fitting to deployable constitutive closure: a discrete-energy neural return map for path-dependent plasticity**
112
+
113
+ ## 与文献的关系
114
+
115
+ - [Masi et al., TANN, JMPS 2021](https://doi.org/10.1016/j.jmps.2020.104277):
116
+ 将热力学结构嵌入神经本构;
117
+ - [Vlassis and Sun, CMAME 2021](https://doi.org/10.1016/j.cma.2021.113695):
118
+ Sobolev/level-set方法学习可解释塑性硬化,并比较GRU等黑箱模型;
119
+ - [Meyer and Ekre, JMPS 2023](https://doi.org/10.1016/j.jmps.2023.105416):
120
+ 神经网络只表示未知演化律,并从实验中发现可解释方程;
121
+ - [Bleyer, CMAME 2025](https://doi.org/10.1016/j.cma.2025.118145):
122
+ 将塑性更新写成隐式优化层并使用隐式微分;
123
+ - [Masi, CMAME 2026](https://doi.org/10.1016/j.cma.2026.119260):
124
+ 以凸自由能和半正定传输算子实施硬热力学约束。
125
+
126
+ DENIM不把“物理神经本构”本身视为新概念。可主张的组合创新是:面向不完备硬化
127
+ 状态的紧凑闭合、可审计离散能量分账、非比例粗时间步稳定返回映射,以及从材料点到
128
+ 结构Newton的统一部署证据。
129
+
130
+ ## 可复现资产
131
+
132
+ - 数据:`data/t2_graybox_closure_v1/cohort.h5`
133
+ - 数据清单:`data/t2_graybox_closure_v1/manifest.json`
134
+ - DENIM权重:`models/t2_graybox_closure_v1/denrm.pt`(发布时文件名为`denim.pt`)
135
+ - GRU权重:`models/t2_graybox_closure_v1/gru.pt`
136
+ - 模型指标:`artifacts/t2_graybox_closure_v1/model_metrics.json`
137
+ - 部署指标:`artifacts/t2_graybox_closure_v1/deployment_validation.json`
138
+ - 总结图:`artifacts/t2_graybox_closure_v1/closure_summary.png`
139
+ - 结构反力图:`artifacts/t2_graybox_closure_v1/structural_reaction_comparison.png`
140
+ - 核心实现:`src/t2_graybox_discrete_energy.py`
141
+ - 数据生成:`src/generate_t2_graybox_closure.py`
142
+ - 训练:`src/train_t2_graybox_closure.py`
143
+ - 部署验证:`src/validate_t2_graybox_closure.py`
144
+ - 回归测试:`tests/test_t2_graybox_closure.py`及`tests/test_t2_graybox_discrete_energy.py`
145
+
146
+ 复现顺序:生成数据、训练、部署验证、绘图。所有产物均写入本项目目录,未修改
147
+ AgentFEM核心代码。
docs/T2_GRAYBOX_RESEARCH_DESIGN.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # T2灰盒神经本构主线:离散能量约束的神经硬化返回映射
2
+
3
+ ## 研究问题
4
+
5
+ 材料点随机留出精度不能回答未知加载路径、时间步变化和结构有限元收敛问题。
6
+ 现有白盒物理积分网络直接使用J2/Chaboche硬化公式,适合作为算法积分上限,
7
+ 不能证明神经网络能够学习未知本构演化。下一阶段只保留可靠的力学骨架,让
8
+ 网络学习未知硬化记忆,并检验该模型能否从材料点进入结构Newton求解。
9
+
10
+ 核心问题为:
11
+
12
+ > 在不提供Chaboche硬化演化公式的条件下,能否从有限的多轴应力—应变历程中
13
+ > 学得紧凑、客观、耗散可接受的硬化记忆,并在未见路径、改变时间步和非均匀
14
+ > 结构中保持精度与求解稳定性?
15
+
16
+ ## 文献判断
17
+
18
+ 现有重要路线包括:
19
+
20
+ 1. TANN从自由能和耗散出发,将热力学关系嵌入网络;
21
+ 2. Sobolev/level-set方法学习屈服面与硬化并控制函数导数;
22
+ 3. Meyer—Ekre方法将神经网络嵌入标准耗散材料结构,学习并进一步识别未知演化律;
23
+ 4. 隐式层方法把塑性更新写成可微凸优化层;
24
+ 5. 2026年的hard-thermodynamic与thermodynamic-hierarchy工作进一步比较自由能、
25
+ 耗散势、传输算子和神经ODE等框架。
26
+
27
+ 因此,本项目不把“热力学神经网络”“神经返回映射”或“学习演化律”本身作为
28
+ 新的概念。可形成差异的部分是:以一个明确不完备的J2骨架为起点,把未知硬化
29
+ 学习、后向欧拉离散能量分账、时间步OOD、一致算法切线及结构Newton门统一在
30
+ 同一条可复现的AgentFEM工作流中。
31
+
32
+ ## 唯一主架构
33
+
34
+ 定名为 **DENIM(Discrete-Energy Neural Internal-variable Model,离散能量神经内变量模型)**。
35
+ 名称指向“离散能量+可学习内变量”的方法范式;当前实例限定为小应变J2循环塑性,不把名称扩张为所有材料模型的通用解。
36
+
37
+ ### 保留的已知物理
38
+
39
+ - 小应变各向同性线弹性;
40
+ - J2屈服几何;
41
+ - 关联流动方向;
42
+ - 塑性不可压缩;
43
+ - 非负塑性乘子与PEEQ单调;
44
+ - 弹性预测—隐式塑性校正;
45
+ - 接受状态的commit/rollback语义。
46
+
47
+ ### 故意移除的物理
48
+
49
+ - Voce指数型各向同性硬化公式;
50
+ - 固定Armstrong—Frederick动态恢复公式;
51
+ - 数据生成器中的Chaboche参数及其更新方程。
52
+
53
+ ### 神经硬化状态
54
+
55
+ 状态为塑性应变、PEEQ、标量各向同性硬化量和两个无迹二阶记忆张量。两个张量
56
+ 表示快、慢两类方向记忆,但不向网络提供Chaboche的解析更新。
57
+
58
+ 各向同性硬化使用零点锚定的单调神经函数
59
+
60
+ `R_theta(p) >= 0, dR_theta/dp >= 0, R_theta(0)=0`。
61
+
62
+ 张量记忆采用客观的后向欧拉更新。网络只读取张量不变量、与当前流动方向的
63
+ 投影、PEEQ和反向加载指标,输出非负动态恢复率;生产模量保持为正的可学习
64
+ 材料常数。经典双背应力Chaboche是该模型的一个特例,但网络也可表达随状态和
65
+ 方向历史变化的恢复规律。
66
+
67
+ ### 离散能量
68
+
69
+ 每个接受增量显式记录:
70
+
71
+ - 塑性功;
72
+ - 各向同性硬化储能变化;
73
+ - 运动硬化储能变化;
74
+ - 初始屈服耗散;
75
+ - 动态恢复耗散;
76
+ - 后向欧拉数值耗散;
77
+ - 离散能量余额。
78
+
79
+ 正参数化和单调硬化保证关键耗散通道非负;训练、验证和结构部署均使用同一
80
+ 分账定义。连续热力学正确但离散积分失真的模型不能通过时间步门。
81
+
82
+ ### 一致切线
83
+
84
+ 局部塑性校正写成隐式残量。训练阶段可使用可微固定点/隐式微分,部署阶段由
85
+ 局部残量的Jacobian得到算法切线,并以固定旧状态的有限差分独立核验。结构门
86
+ 同时报告反力误差、Newton迭代、cutback和回退,不以材料点RMSE替代稳定性。
87
+
88
+ ## 数据设计
89
+
90
+ 不重新海选网络,只增加一组面向演化发现的固定材料队列:
91
+
92
+ 1. 已知`E, nu, sigma_y`,隐藏所有硬化公式与硬化参数;
93
+ 2. 训练路径使用比例、剪切、顺序轴剪、正交和方形非比例加载;
94
+ 3. 验证留出旋转主方向;
95
+ 4. 测试完整留出Lissajous和随机五维方向块;
96
+ 5. 对同一连续路径随机改变离散步长,形成时间步OOD;
97
+ 6. 第一真值为AgentFEM组合硬化,用于验证能否恢复已知规律;
98
+ 7. 第二真值使用非指数表格硬化和多时间尺度记忆,避免提出模型与生成器同构;
99
+ 8. 最后增加公开OFHC铜/316钢路径或实验数据,不把合成结果冒充实验发现。
100
+
101
+ ## 最小对照组
102
+
103
+ 只保留三个必要对照,不重新训练一排相似网络:
104
+
105
+ 1. 现有GRU:代表黑箱历史模型;
106
+ 2. 不含硬化的J2骨架:代表物理不完备但没有学习;
107
+ 3. DENIM:本文方法。
108
+
109
+ 现有白盒物理积分网络只作为不可超越的“知道真公式”参考上限,不参与公平的
110
+ 未知物理排名。
111
+
112
+ ## 成功门槛
113
+
114
+ DENIM必须同时满足:
115
+
116
+ - 路径OOD应力RMSE显著低于GRU;
117
+ - PEEQ、塑性不可压缩和客观性零违例;
118
+ - 离散能量余额达到数值积分容差,耗散通道无负值;
119
+ - 241、121及非均匀时间步下终态和历程保持自洽;
120
+ - 算法切线与固定旧状态有限差分一致;
121
+ - 二维或三维非均匀结构中达到可接受反力误差,并稳定完成全局Newton;
122
+ - 公开路径/实验对照不劣于经标定的经典基线。
123
+
124
+ 若DENIM不能超过GRU,应保留失败结果并检查信息不足、状态维数、离散更新和
125
+ 训练路径覆盖,不通过增删测试集制造胜出。
126
+
127
+ ## 论文主线
128
+
129
+ 建议题目方向:
130
+
131
+ **From trajectory fitting to deployable constitutive discovery: a discrete-energy neural return map for path-dependent plasticity**
132
+
133
+ 文章的核心贡献不是新网络名称,而是证明:未知硬化可以在保留少量可靠物理的
134
+ 条件下学习;连续层面的物理约束仍不够,离散能量、时间步一致性、算法切线和
135
+ 结构平衡必须共同构成神经本构的可信验证链。
136
+
137
+ ## 主要文献入口
138
+
139
+ - Masi et al., Thermodynamics-based Artificial Neural Networks, JMPS 2021,
140
+ https://doi.org/10.1016/j.jmps.2020.104277
141
+ - Vlassis and Sun, Sobolev training of thermodynamic-informed neural networks,
142
+ CMAME 2021, https://doi.org/10.1016/j.cma.2021.113695
143
+ - Meyer and Ekre, Thermodynamically consistent neural network plasticity
144
+ modeling and discovery of evolution laws, JMPS 2023,
145
+ https://doi.org/10.1016/j.jmps.2023.105416
146
+ - Bleyer, Learning elastoplasticity with implicit layers, CMAME 2025,
147
+ https://doi.org/10.1016/j.cma.2025.118145
148
+ - Masi, Learning inelastic constitutive models from stress-strain data under
149
+ hard thermodynamic constraints, CMAME 2026,
150
+ https://doi.org/10.1016/j.cma.2026.119260
151
+ - Jones and Fuhg, A hierarchy of thermodynamics learning frameworks for
152
+ inelastic constitutive modeling, arXiv:2603.02645
src/generate_t2_graybox_closure.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Generate the out-of-template cohort for incomplete-physics closure.
2
+
3
+ The reference material has three kinematic time scales and a piecewise-linear
4
+ isotropic hardening curve. DENRM is deliberately restricted to two memory
5
+ channels and is not given either reference evolution law.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import time
13
+ from pathlib import Path
14
+
15
+ import h5py
16
+ import numpy as np
17
+
18
+ from agentfem import constitutive
19
+
20
+ from src.generate_t2_graybox_cohort import design, split_for_family
21
+ from src.t2_multiaxial_ood_v2 import PATH_FAMILIES, strain_history, tensor_to_voigt
22
+
23
+
24
+ ROOT = Path(__file__).resolve().parents[1]
25
+ DATA_DIR = ROOT / "data" / "t2_graybox_closure_v1"
26
+ DATA_PATH = DATA_DIR / "cohort.h5"
27
+ MANIFEST_PATH = DATA_DIR / "manifest.json"
28
+
29
+ MATERIAL = {
30
+ "young_pa": 190.0e9,
31
+ "poisson": 0.30,
32
+ "yield_stress_pa": 280.0e6,
33
+ "backstress_c1_pa": 28.0e9,
34
+ "backstress_gamma1": 80.0,
35
+ "backstress_c2_pa": 10.0e9,
36
+ "backstress_gamma2": 12.0,
37
+ "backstress_c3_pa": 3.0e9,
38
+ "backstress_gamma3": 1.5,
39
+ "hardening_peeq": (0.0, 0.002, 0.006, 0.015, 0.030, 0.060, 0.100),
40
+ "hardening_stress_pa": (
41
+ 280.0e6,
42
+ 301.0e6,
43
+ 324.0e6,
44
+ 345.0e6,
45
+ 358.0e6,
46
+ 370.0e6,
47
+ 378.0e6,
48
+ ),
49
+ }
50
+
51
+
52
+ def closure_design(count_per_family: int = 16) -> list[dict[str, object]]:
53
+ rows = design(count_per_family)
54
+ for row in rows:
55
+ row.update(MATERIAL)
56
+ row["material_model"] = "hidden_three_memory_tabulated_hardening"
57
+ return rows
58
+
59
+
60
+ def material() -> constitutive.ChabocheCombinedHardening:
61
+ hardening = constitutive.TabulatedIsotropicHardening(
62
+ equivalent_plastic_strain=tuple(MATERIAL["hardening_peeq"]),
63
+ yield_stress=tuple(MATERIAL["hardening_stress_pa"]),
64
+ extrapolation="constant",
65
+ )
66
+ return constitutive.chaboche(
67
+ young=float(MATERIAL["young_pa"]),
68
+ poisson=float(MATERIAL["poisson"]),
69
+ yield_stress=float(MATERIAL["yield_stress_pa"]),
70
+ backstresses=(
71
+ (float(MATERIAL["backstress_c1_pa"]), float(MATERIAL["backstress_gamma1"])),
72
+ (float(MATERIAL["backstress_c2_pa"]), float(MATERIAL["backstress_gamma2"])),
73
+ (float(MATERIAL["backstress_c3_pa"]), float(MATERIAL["backstress_gamma3"])),
74
+ ),
75
+ isotropic_hardening=hardening,
76
+ name="hidden three-memory tabulated reference",
77
+ )
78
+
79
+
80
+ def solve(parameters: dict[str, object], *, points: int | None = None) -> dict[str, np.ndarray]:
81
+ law = material()
82
+ coordinates, strains = strain_history(parameters, points=points)
83
+ count = len(strains)
84
+ stress = np.empty_like(strains)
85
+ plastic = np.empty_like(strains)
86
+ peeq = np.empty(count)
87
+ increment = np.empty(count)
88
+ truth_memories = np.empty((count, 3, 3, 3))
89
+ latent_memories = np.empty((count, 2, 3, 3))
90
+ radius = np.empty(count)
91
+ state = None
92
+ for index, strain in enumerate(strains):
93
+ update = law.update(strain, state, linearization="none")
94
+ state = update.state
95
+ stress[index] = update.stress
96
+ plastic[index] = state.plastic_strain
97
+ peeq[index] = state.equivalent_plastic_strain
98
+ increment[index] = update.plastic_multiplier_increment
99
+ truth_memories[index] = state.backstresses
100
+ # The two-channel closure sees one fast state and one deliberately
101
+ # unresolved aggregate of the medium and slow reference mechanisms.
102
+ latent_memories[index, 0] = state.backstresses[0]
103
+ latent_memories[index, 1] = state.backstresses[1] + state.backstresses[2]
104
+ radius[index] = law.current_yield_stress(peeq[index]) - law.yield_stress
105
+ return {
106
+ "strain": tensor_to_voigt(strains),
107
+ "stress_pa": tensor_to_voigt(stress),
108
+ "plastic_strain": tensor_to_voigt(plastic),
109
+ "peeq": peeq,
110
+ "plastic_increment": increment,
111
+ "memories_pa": tensor_to_voigt(latent_memories),
112
+ "truth_memories_pa": tensor_to_voigt(truth_memories),
113
+ "isotropic_radius_pa": radius,
114
+ "path_coordinates": coordinates,
115
+ }
116
+
117
+
118
+ def generate(count_per_family: int = 16, *, force: bool = False) -> dict[str, object]:
119
+ rows = closure_design(count_per_family)
120
+ DATA_DIR.mkdir(parents=True, exist_ok=True)
121
+ if DATA_PATH.exists() and not force:
122
+ raise FileExistsError(f"{DATA_PATH} already exists; pass --force to replace it.")
123
+ temporary = DATA_PATH.with_suffix(".h5.tmp")
124
+ started = time.perf_counter()
125
+ with h5py.File(temporary, "w") as h5:
126
+ h5.attrs["schema"] = "agentfem.physics-data.incomplete-physics-closure"
127
+ h5.attrs["schema_version"] = "1.0.0"
128
+ h5.attrs["material_json"] = json.dumps(MATERIAL, sort_keys=True)
129
+ for index, row in enumerate(rows):
130
+ group = h5.create_group(f"{index:05d}")
131
+ group.attrs["path_family"] = str(row["path_family"])
132
+ group.attrs["split"] = split_for_family(str(row["path_family"]))
133
+ group.attrs["parameters_json"] = json.dumps(row, sort_keys=True)
134
+ for name, value in solve(row).items():
135
+ group.create_dataset(name, data=value, compression="gzip", shuffle=True)
136
+ temporary.replace(DATA_PATH)
137
+ manifest = {
138
+ "schema": "agentfem.physics-data.incomplete-physics-closure",
139
+ "schema_version": "1.0.0",
140
+ "sample_count": len(rows),
141
+ "count_per_family": count_per_family,
142
+ "points_per_trajectory": 241,
143
+ "path_families": list(PATH_FAMILIES),
144
+ "splits": {
145
+ "train": 5 * count_per_family,
146
+ "validation": count_per_family,
147
+ "test": 2 * count_per_family,
148
+ },
149
+ "known_to_model": ["young_pa", "poisson", "yield_stress_pa", "J2_geometry"],
150
+ "hidden_from_model": [
151
+ "three_reference_memory_channels",
152
+ "all_reference_recovery_parameters",
153
+ "piecewise_linear_isotropic_hardening_table",
154
+ "reference_hardening_update_equations",
155
+ ],
156
+ "intentional_model_mismatch": (
157
+ "reference has three memories; DENRM has two and must close the lumped medium/slow state"
158
+ ),
159
+ "ground_truth": "AgentFEM three-memory Chaboche with tabulated isotropic hardening",
160
+ "scope": "Out-of-template synthetic closure cohort; fixed material.",
161
+ "elapsed_seconds": time.perf_counter() - started,
162
+ "bytes": DATA_PATH.stat().st_size,
163
+ }
164
+ MANIFEST_PATH.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
165
+ print(json.dumps(manifest, indent=2))
166
+ return manifest
167
+
168
+
169
+ def main() -> None:
170
+ parser = argparse.ArgumentParser()
171
+ parser.add_argument("--count-per-family", type=int, default=16)
172
+ parser.add_argument("--force", action="store_true")
173
+ args = parser.parse_args()
174
+ generate(args.count_per_family, force=args.force)
175
+
176
+
177
+ if __name__ == "__main__":
178
+ main()
src/generate_t2_graybox_cohort.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Generate the fixed-material cohort for T2 gray-box hardening discovery."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import time
8
+ from pathlib import Path
9
+
10
+ import h5py
11
+ import numpy as np
12
+
13
+ from agentfem import constitutive
14
+
15
+ from src.t2_multiaxial_ood_v2 import (
16
+ PATH_FAMILIES,
17
+ design_parameters,
18
+ strain_history,
19
+ tensor_to_voigt,
20
+ )
21
+
22
+
23
+ ROOT = Path(__file__).resolve().parents[1]
24
+ DATA_DIR = ROOT / "data" / "t2_graybox_hardening_v1"
25
+ DATA_PATH = DATA_DIR / "cohort.h5"
26
+ MANIFEST_PATH = DATA_DIR / "manifest.json"
27
+
28
+ MATERIAL = {
29
+ "young_pa": 190.0e9,
30
+ "poisson": 0.30,
31
+ "yield_stress_pa": 280.0e6,
32
+ "backstress_c1_pa": 35.0e9,
33
+ "backstress_gamma1": 60.0,
34
+ "backstress_c2_pa": 8.0e9,
35
+ "backstress_gamma2": 8.0,
36
+ "isotropic_saturation_pa": 70.0e6,
37
+ "isotropic_rate": 8.0,
38
+ }
39
+
40
+
41
+ def design(count_per_family: int = 32) -> list[dict[str, object]]:
42
+ if count_per_family < 4 or count_per_family > 64:
43
+ raise ValueError("count_per_family must be between 4 and 64.")
44
+ source = design_parameters()
45
+ rows: list[dict[str, object]] = []
46
+ for family_index, family in enumerate(PATH_FAMILIES):
47
+ start = 512 + family_index * 64
48
+ for replicate in range(count_per_family):
49
+ row = dict(source[start + replicate])
50
+ row.update(MATERIAL)
51
+ row["material_model"] = "hidden_combined_hardening"
52
+ row["path_family"] = family
53
+ row["replicate"] = replicate
54
+ row["hardening_modulus_pa"] = 0.0
55
+ rows.append(row)
56
+ return rows
57
+
58
+
59
+ def split_for_family(family: str) -> str:
60
+ if family in {
61
+ "proportional_axial_cycle",
62
+ "proportional_shear_cycle",
63
+ "sequential_axial_shear",
64
+ "orthogonal_cross",
65
+ "nonproportional_square",
66
+ }:
67
+ return "train"
68
+ if family == "rotating_principal_cycle":
69
+ return "validation"
70
+ return "test"
71
+
72
+
73
+ def solve(
74
+ parameters: dict[str, object], *, points: int | None = None
75
+ ) -> dict[str, np.ndarray]:
76
+ law = constitutive.chaboche(
77
+ young=float(parameters["young_pa"]),
78
+ poisson=float(parameters["poisson"]),
79
+ yield_stress=float(parameters["yield_stress_pa"]),
80
+ backstresses=(
81
+ (
82
+ float(parameters["backstress_c1_pa"]),
83
+ float(parameters["backstress_gamma1"]),
84
+ ),
85
+ (
86
+ float(parameters["backstress_c2_pa"]),
87
+ float(parameters["backstress_gamma2"]),
88
+ ),
89
+ ),
90
+ isotropic_saturation=float(parameters["isotropic_saturation_pa"]),
91
+ isotropic_rate=float(parameters["isotropic_rate"]),
92
+ )
93
+ coordinates, strains = strain_history(parameters, points=points)
94
+ count = len(strains)
95
+ stress = np.empty_like(strains)
96
+ plastic = np.empty_like(strains)
97
+ peeq = np.empty(count)
98
+ increment = np.empty(count)
99
+ memories = np.empty((count, 2, 3, 3))
100
+ radius = np.empty(count)
101
+ state = None
102
+ for index, strain in enumerate(strains):
103
+ update = law.update(strain, state, linearization="none")
104
+ state = update.state
105
+ stress[index] = update.stress
106
+ plastic[index] = state.plastic_strain
107
+ peeq[index] = state.equivalent_plastic_strain
108
+ increment[index] = update.plastic_multiplier_increment
109
+ memories[index] = state.backstresses
110
+ radius[index] = law.current_yield_stress(peeq[index]) - law.yield_stress
111
+ return {
112
+ "strain": tensor_to_voigt(strains),
113
+ "stress_pa": tensor_to_voigt(stress),
114
+ "plastic_strain": tensor_to_voigt(plastic),
115
+ "peeq": peeq,
116
+ "plastic_increment": increment,
117
+ "memories_pa": tensor_to_voigt(memories),
118
+ "isotropic_radius_pa": radius,
119
+ "path_coordinates": coordinates,
120
+ }
121
+
122
+
123
+ def generate(count_per_family: int = 32, *, force: bool = False) -> dict[str, object]:
124
+ rows = design(count_per_family)
125
+ DATA_DIR.mkdir(parents=True, exist_ok=True)
126
+ if DATA_PATH.exists() and not force:
127
+ raise FileExistsError(f"{DATA_PATH} already exists; pass --force to replace it.")
128
+ temporary = DATA_PATH.with_suffix(".h5.tmp")
129
+ started = time.perf_counter()
130
+ with h5py.File(temporary, "w") as h5:
131
+ h5.attrs["schema"] = "agentfem.physics-data.graybox-hardening"
132
+ h5.attrs["schema_version"] = "1.0.0-pilot"
133
+ h5.attrs["material_json"] = json.dumps(MATERIAL, sort_keys=True)
134
+ for index, row in enumerate(rows):
135
+ group = h5.create_group(f"{index:05d}")
136
+ group.attrs["path_family"] = str(row["path_family"])
137
+ group.attrs["split"] = split_for_family(str(row["path_family"]))
138
+ group.attrs["parameters_json"] = json.dumps(row, sort_keys=True)
139
+ for name, value in solve(row).items():
140
+ group.create_dataset(name, data=value, compression="gzip", shuffle=True)
141
+ temporary.replace(DATA_PATH)
142
+ manifest = {
143
+ "schema": "agentfem.physics-data.graybox-hardening",
144
+ "schema_version": "1.0.0-pilot",
145
+ "sample_count": len(rows),
146
+ "count_per_family": count_per_family,
147
+ "points_per_trajectory": 241,
148
+ "path_families": list(PATH_FAMILIES),
149
+ "splits": {
150
+ "train": 5 * count_per_family,
151
+ "validation": count_per_family,
152
+ "test": 2 * count_per_family,
153
+ },
154
+ "known_to_model": ["young_pa", "poisson", "yield_stress_pa"],
155
+ "hidden_from_model": [
156
+ "backstress_c1_pa",
157
+ "backstress_gamma1",
158
+ "backstress_c2_pa",
159
+ "backstress_gamma2",
160
+ "isotropic_saturation_pa",
161
+ "isotropic_rate",
162
+ "hardening_update_equations",
163
+ ],
164
+ "ground_truth": "AgentFEM Chaboche combined hardening",
165
+ "scope": "Fixed synthetic material; controlled recovery-of-known-law cohort.",
166
+ "elapsed_seconds": time.perf_counter() - started,
167
+ "bytes": DATA_PATH.stat().st_size,
168
+ }
169
+ MANIFEST_PATH.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
170
+ print(json.dumps(manifest, indent=2))
171
+ return manifest
172
+
173
+
174
+ def main() -> None:
175
+ parser = argparse.ArgumentParser()
176
+ parser.add_argument("--count-per-family", type=int, default=32)
177
+ parser.add_argument("--force", action="store_true")
178
+ args = parser.parse_args()
179
+ generate(args.count_per_family, force=args.force)
180
+
181
+
182
+ if __name__ == "__main__":
183
+ main()
src/plot_t2_graybox_closure.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Create compact paper-ready figures for the incomplete-physics closure."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import matplotlib
9
+
10
+ matplotlib.use("Agg")
11
+ import matplotlib.pyplot as plt
12
+ import numpy as np
13
+ import torch
14
+
15
+ from src import t2_graybox_discrete_energy as graybox
16
+ from src.generate_t2_graybox_closure import MATERIAL
17
+ from src.train_t2_graybox_discrete_energy import load_cohort
18
+ from src.train_t2_multiaxial_models import RecurrentStress
19
+
20
+
21
+ ROOT = Path(__file__).resolve().parents[1]
22
+ DATA = ROOT / "data" / "t2_graybox_closure_v1" / "cohort.h5"
23
+ MODELS = ROOT / "models" / "t2_graybox_closure_v1"
24
+ ARTIFACTS = ROOT / "artifacts" / "t2_graybox_closure_v1"
25
+
26
+
27
+ def main() -> None:
28
+ cohort = load_cohort(DATA)
29
+ denrm_checkpoint = torch.load(MODELS / "denrm.pt", map_location="cpu", weights_only=False)
30
+ denrm = graybox.NeuralHardeningLaw(channels=2)
31
+ denrm.load_state_dict(denrm_checkpoint["state_dict"])
32
+ denrm.eval()
33
+ gru_checkpoint = torch.load(MODELS / "gru.pt", map_location="cpu", weights_only=False)
34
+ gru = RecurrentStress(6, cell="gru", hidden=72)
35
+ gru.load_state_dict(gru_checkpoint["state_dict"])
36
+ gru.eval()
37
+ norm = gru_checkpoint["normalization"]
38
+ with torch.no_grad():
39
+ denrm_stress = graybox.rollout(
40
+ cohort.strain,
41
+ torch.full((len(cohort.strain),), float(MATERIAL["young_pa"])),
42
+ torch.full((len(cohort.strain),), float(MATERIAL["poisson"])),
43
+ torch.full((len(cohort.strain),), float(MATERIAL["yield_stress_pa"])),
44
+ denrm,
45
+ bisection_iterations=24,
46
+ )["stress"]
47
+ gru_stress = (
48
+ gru((cohort.strain - norm["strain_mean"]) / norm["strain_std"])
49
+ * norm["stress_std"]
50
+ + norm["stress_mean"]
51
+ )
52
+
53
+ metrics = json.loads((ARTIFACTS / "model_metrics.json").read_text())
54
+ figure, axes = plt.subplots(2, 2, figsize=(11.0, 7.8), constrained_layout=True)
55
+ colors = {"truth": "#1f2937", "denrm": "#e11d48", "gru": "#2563eb"}
56
+ component_labels = ("xx", "yy", "zz", "xy", "yz", "xz")
57
+ for axis, family in zip(
58
+ axes[0], ("out_of_phase_lissajous", "random_direction_blocks"), strict=True
59
+ ):
60
+ index = next(i for i, value in enumerate(cohort.families) if value == family)
61
+ strain = cohort.strain[index].numpy()
62
+ component = int(np.argmax(np.ptp(strain, axis=0)))
63
+ x = 100.0 * strain[:, component]
64
+ axis.plot(
65
+ x,
66
+ cohort.stress[index, :, component].numpy() / 1.0e6,
67
+ color=colors["truth"],
68
+ linewidth=2.1,
69
+ label="AgentFEM reference",
70
+ )
71
+ axis.plot(
72
+ x,
73
+ denrm_stress[index, :, component].numpy() / 1.0e6,
74
+ "--",
75
+ color=colors["denrm"],
76
+ linewidth=1.8,
77
+ label="DENIM (2-state closure)",
78
+ )
79
+ axis.plot(
80
+ x,
81
+ gru_stress[index, :, component].numpy() / 1.0e6,
82
+ color=colors["gru"],
83
+ linewidth=1.1,
84
+ alpha=0.85,
85
+ label="GRU",
86
+ )
87
+ axis.set_title(family.replace("_", " "))
88
+ axis.set_xlabel(f"strain {component_labels[component]} (%)")
89
+ axis.set_ylabel(f"stress {component_labels[component]} (MPa)")
90
+ axis.grid(alpha=0.22)
91
+ axes[0, 0].legend(frameon=False, fontsize=8)
92
+
93
+ names = ("Incomplete J2", "GRU", "DENIM")
94
+ keys = ("incomplete_j2", "gru", "denrm")
95
+ rmse = [metrics["models"][key]["test"]["rmse_mpa"] for key in keys]
96
+ bars = axes[1, 0].bar(
97
+ names, rmse, color=("#9ca3af", colors["gru"], colors["denrm"])
98
+ )
99
+ axes[1, 0].bar_label(bars, fmt="%.2f")
100
+ axes[1, 0].set_ylabel("held-out path RMSE (MPa)")
101
+ axes[1, 0].set_title("unseen loading-path accuracy")
102
+ axes[1, 0].grid(axis="y", alpha=0.22)
103
+
104
+ peeq = np.linspace(0.0, 0.10, 250)
105
+ with torch.no_grad():
106
+ learned = denrm.isotropic(
107
+ torch.tensor(peeq, dtype=torch.float32),
108
+ torch.full((len(peeq),), float(MATERIAL["yield_stress_pa"])),
109
+ ).numpy()
110
+ reference = np.interp(
111
+ peeq,
112
+ np.asarray(MATERIAL["hardening_peeq"]),
113
+ np.asarray(MATERIAL["hardening_stress_pa"]),
114
+ ) - float(MATERIAL["yield_stress_pa"])
115
+ axes[1, 1].plot(peeq, reference / 1.0e6, color=colors["truth"], linewidth=2.1, label="hidden table")
116
+ axes[1, 1].plot(peeq, learned / 1.0e6, "--", color=colors["denrm"], linewidth=1.8, label="learned monotone law")
117
+ axes[1, 1].set_xlabel("equivalent plastic strain")
118
+ axes[1, 1].set_ylabel("isotropic hardening radius (MPa)")
119
+ axes[1, 1].set_title("unknown hardening-law recovery")
120
+ axes[1, 1].grid(alpha=0.22)
121
+ axes[1, 1].legend(frameon=False, fontsize=8)
122
+
123
+ figure.suptitle(
124
+ "Incomplete-physics closure: 3-state tabulated reference → 2-state DENIM",
125
+ fontsize=13,
126
+ )
127
+ ARTIFACTS.mkdir(parents=True, exist_ok=True)
128
+ figure.savefig(ARTIFACTS / "closure_summary.png", dpi=220)
129
+ plt.close(figure)
130
+
131
+
132
+ if __name__ == "__main__":
133
+ main()
src/t2_graybox_discrete_energy.py ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Core assets for a discrete-energy neural hardening return map.
2
+
3
+ This module deliberately keeps elasticity and J2 kinematics explicit while
4
+ leaving the isotropic hardening curve and state-dependent dynamic recovery to
5
+ small neural functions. It is the constitutive core of the T2 gray-box study,
6
+ not yet an AgentFEM material provider.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass
12
+
13
+ import torch
14
+ from torch import nn
15
+ from torch.nn import functional as F
16
+
17
+
18
+ VOIGT_WEIGHTS = torch.tensor((1.0, 1.0, 1.0, 2.0, 2.0, 2.0))
19
+
20
+
21
+ def double_contract(left: torch.Tensor, right: torch.Tensor) -> torch.Tensor:
22
+ weights = VOIGT_WEIGHTS.to(dtype=left.dtype, device=left.device)
23
+ return (left * right * weights).sum(dim=-1)
24
+
25
+
26
+ def deviatoric(value: torch.Tensor) -> torch.Tensor:
27
+ mean = value[..., :3].mean(dim=-1, keepdim=True)
28
+ return torch.cat((value[..., :3] - mean, value[..., 3:]), dim=-1)
29
+
30
+
31
+ def von_mises(value: torch.Tensor) -> torch.Tensor:
32
+ selected = deviatoric(value)
33
+ return torch.sqrt(torch.clamp(1.5 * double_contract(selected, selected), min=0.0))
34
+
35
+
36
+ def elastic_stress(
37
+ strain: torch.Tensor,
38
+ plastic_strain: torch.Tensor,
39
+ young: torch.Tensor,
40
+ poisson: torch.Tensor,
41
+ ) -> torch.Tensor:
42
+ elastic = strain - plastic_strain
43
+ shear = young / (2.0 * (1.0 + poisson))
44
+ bulk = young / (3.0 * (1.0 - 2.0 * poisson))
45
+ trace = elastic[..., :3].sum(dim=-1)
46
+ mean = trace / 3.0
47
+ normal = (
48
+ 2.0 * shear[..., None] * (elastic[..., :3] - mean[..., None])
49
+ + bulk[..., None] * trace[..., None]
50
+ )
51
+ return torch.cat((normal, 2.0 * shear[..., None] * elastic[..., 3:]), dim=-1)
52
+
53
+
54
+ class MonotoneIsotropicHardening(nn.Module):
55
+ """Zero-anchored monotone saturating hardening curve.
56
+
57
+ A positive mixture of exponential saturation modes represents Voce-like
58
+ and tabulated concave hardening while a nonnegative linear tail permits
59
+ continued hardening. Positivity makes monotonicity structural rather than
60
+ a soft training penalty.
61
+ """
62
+
63
+ def __init__(self, neurons: int = 12, plastic_scale: float = 0.01):
64
+ super().__init__()
65
+ self.plastic_scale = float(plastic_scale)
66
+ self.raw_weight = nn.Parameter(torch.full((neurons,), -5.0))
67
+ self.raw_slope = nn.Parameter(torch.linspace(-1.5, 1.5, neurons))
68
+ self.raw_linear = nn.Parameter(torch.tensor(-5.0))
69
+
70
+ def _positive_parameters(self) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
71
+ weight = F.softplus(self.raw_weight)
72
+ slope = F.softplus(self.raw_slope) + 1.0e-6
73
+ linear = F.softplus(self.raw_linear)
74
+ return weight, slope, linear
75
+
76
+ def forward(self, peeq: torch.Tensor, stress_scale: torch.Tensor) -> torch.Tensor:
77
+ weight, slope, linear = self._positive_parameters()
78
+ coordinate = peeq[..., None] / self.plastic_scale
79
+ saturation = -torch.expm1(-slope * coordinate)
80
+ dimensionless = linear * coordinate.squeeze(-1) + (
81
+ weight * saturation
82
+ ).sum(dim=-1)
83
+ return stress_scale * dimensionless
84
+
85
+ def derivative(self, peeq: torch.Tensor, stress_scale: torch.Tensor) -> torch.Tensor:
86
+ weight, slope, linear = self._positive_parameters()
87
+ coordinate = peeq[..., None] / self.plastic_scale
88
+ value = linear + (
89
+ weight * slope * torch.exp(-slope * coordinate)
90
+ ).sum(dim=-1)
91
+ return stress_scale * value / self.plastic_scale
92
+
93
+ def stored_energy(self, peeq: torch.Tensor, stress_scale: torch.Tensor) -> torch.Tensor:
94
+ coordinate = torch.linspace(
95
+ 0.0, 1.0, 65, dtype=peeq.dtype, device=peeq.device
96
+ )
97
+ points = peeq[..., None] * coordinate
98
+ values = self.forward(points, stress_scale[..., None])
99
+ return torch.trapezoid(values, points, dim=-1)
100
+
101
+
102
+ class ObjectiveRecoveryNetwork(nn.Module):
103
+ """Positive recovery rates from objective scalar state descriptors."""
104
+
105
+ def __init__(self, channels: int = 2, hidden: int = 24):
106
+ super().__init__()
107
+ self.channels = int(channels)
108
+ input_size = 3 + 3 * self.channels
109
+ self.network = nn.Sequential(
110
+ nn.Linear(input_size, hidden),
111
+ nn.SiLU(),
112
+ nn.Linear(hidden, hidden),
113
+ nn.SiLU(),
114
+ nn.Linear(hidden, self.channels),
115
+ )
116
+ nn.init.zeros_(self.network[-1].weight)
117
+ nn.init.constant_(self.network[-1].bias, -1.0)
118
+
119
+ def features(
120
+ self,
121
+ peeq: torch.Tensor,
122
+ isotropic_radius: torch.Tensor,
123
+ flow_direction: torch.Tensor,
124
+ memories: torch.Tensor,
125
+ stress_scale: torch.Tensor,
126
+ reversal: torch.Tensor,
127
+ ) -> torch.Tensor:
128
+ scale = stress_scale.clamp_min(1.0)
129
+ norms = torch.sqrt(
130
+ torch.clamp(double_contract(memories, memories), min=0.0)
131
+ ) / scale[..., None]
132
+ projections = double_contract(memories, flow_direction[..., None, :]) / scale[..., None]
133
+ cross = torch.zeros_like(norms)
134
+ if self.channels > 1:
135
+ for index in range(self.channels):
136
+ other = (index + 1) % self.channels
137
+ cross[..., index] = double_contract(
138
+ memories[..., index, :], memories[..., other, :]
139
+ ) / scale.square()
140
+ scalars = torch.stack(
141
+ (peeq / 0.02, isotropic_radius / scale, reversal), dim=-1
142
+ )
143
+ return torch.cat((scalars, norms, projections, cross), dim=-1)
144
+
145
+ def forward(
146
+ self,
147
+ peeq: torch.Tensor,
148
+ isotropic_radius: torch.Tensor,
149
+ flow_direction: torch.Tensor,
150
+ memories: torch.Tensor,
151
+ stress_scale: torch.Tensor,
152
+ reversal: torch.Tensor,
153
+ ) -> torch.Tensor:
154
+ values = self.features(
155
+ peeq,
156
+ isotropic_radius,
157
+ flow_direction,
158
+ memories,
159
+ stress_scale,
160
+ reversal,
161
+ )
162
+ return 200.0 * torch.sigmoid(self.network(values)) + 1.0e-6
163
+
164
+
165
+ @dataclass
166
+ class GrayboxState:
167
+ plastic_strain: torch.Tensor
168
+ peeq: torch.Tensor
169
+ memories: torch.Tensor
170
+ previous_flow: torch.Tensor
171
+
172
+ @property
173
+ def backstress(self) -> torch.Tensor:
174
+ return self.memories.sum(dim=-2)
175
+
176
+
177
+ def initial_state(
178
+ batch: int,
179
+ *,
180
+ channels: int = 2,
181
+ dtype: torch.dtype = torch.float32,
182
+ device: torch.device | str = "cpu",
183
+ ) -> GrayboxState:
184
+ tensor = torch.zeros((batch, 6), dtype=dtype, device=device)
185
+ memories = torch.zeros((batch, channels, 6), dtype=dtype, device=device)
186
+ return GrayboxState(
187
+ plastic_strain=tensor,
188
+ peeq=torch.zeros(batch, dtype=dtype, device=device),
189
+ memories=memories,
190
+ previous_flow=tensor.clone(),
191
+ )
192
+
193
+
194
+ class NeuralHardeningLaw(nn.Module):
195
+ """Unknown hardening law embedded in a known J2 state representation."""
196
+
197
+ def __init__(self, channels: int = 2):
198
+ super().__init__()
199
+ self.channels = int(channels)
200
+ self.raw_moduli = nn.Parameter(torch.linspace(2.0, 0.0, channels))
201
+ self.log_total_modulus_ratio = nn.Parameter(torch.tensor(5.0))
202
+ self.isotropic = MonotoneIsotropicHardening()
203
+ self.recovery = ObjectiveRecoveryNetwork(channels=channels)
204
+
205
+ def moduli(self, stress_scale: torch.Tensor) -> torch.Tensor:
206
+ fractions = torch.softmax(self.raw_moduli, dim=0)
207
+ total = torch.exp(self.log_total_modulus_ratio).clamp(max=500.0)
208
+ return total * stress_scale[..., None] * fractions
209
+
210
+ def update_memories(
211
+ self,
212
+ state: GrayboxState,
213
+ flow_direction: torch.Tensor,
214
+ increment: torch.Tensor,
215
+ stress_scale: torch.Tensor,
216
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
217
+ isotropic = self.isotropic(state.peeq, stress_scale)
218
+ old_norm = torch.sqrt(
219
+ torch.clamp(double_contract(state.previous_flow, state.previous_flow), min=0.0)
220
+ )
221
+ current_norm = torch.sqrt(
222
+ torch.clamp(double_contract(flow_direction, flow_direction), min=0.0)
223
+ )
224
+ reversal = double_contract(state.previous_flow, flow_direction) / (
225
+ old_norm * current_norm
226
+ ).clamp_min(1.0e-12)
227
+ recovery = self.recovery(
228
+ state.peeq,
229
+ isotropic,
230
+ flow_direction,
231
+ state.memories,
232
+ stress_scale,
233
+ reversal,
234
+ )
235
+ moduli = self.moduli(stress_scale)
236
+ numerator = state.memories + (
237
+ (2.0 / 3.0)
238
+ * moduli[..., :, None]
239
+ * increment[..., None, None]
240
+ * flow_direction[..., None, :]
241
+ )
242
+ denominator = 1.0 + recovery * increment[..., None]
243
+ updated = numerator / denominator[..., None]
244
+ return updated, recovery, moduli
245
+
246
+
247
+ def _candidate_update(
248
+ trial_deviatoric: torch.Tensor,
249
+ state: GrayboxState,
250
+ increment: torch.Tensor,
251
+ shear: torch.Tensor,
252
+ yield_stress: torch.Tensor,
253
+ law: NeuralHardeningLaw,
254
+ *,
255
+ direction_iterations: int = 6,
256
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
257
+ shifted_trial = trial_deviatoric - state.backstress
258
+ direction = 1.5 * shifted_trial / von_mises(shifted_trial).clamp_min(1.0)[..., None]
259
+ recovery = moduli = None
260
+ memories = state.memories
261
+ # For a fixed plastic increment the Armstrong--Frederick-type backward
262
+ # Euler update can be rearranged before finding the direction. Removing
263
+ # the large term proportional to G*increment avoids the oscillatory vector
264
+ # fixed point that occurs when a coarse increment rotates the loading path
265
+ # by nearly 90 degrees.
266
+ for _ in range(direction_iterations):
267
+ memories, recovery, moduli = law.update_memories(
268
+ state, direction, increment, yield_stress
269
+ )
270
+ denominator = 1.0 + recovery * increment[..., None]
271
+ effective_trial = trial_deviatoric - (
272
+ state.memories / denominator[..., None]
273
+ ).sum(dim=-2)
274
+ direction = (
275
+ 1.5
276
+ * effective_trial
277
+ / von_mises(effective_trial).clamp_min(1.0)[..., None]
278
+ )
279
+ memories, recovery, moduli = law.update_memories(
280
+ state, direction, increment, yield_stress
281
+ )
282
+ denominator = 1.0 + recovery * increment[..., None]
283
+ effective_trial = trial_deviatoric - (
284
+ state.memories / denominator[..., None]
285
+ ).sum(dim=-2)
286
+ radius = yield_stress + law.isotropic(state.peeq + increment, yield_stress)
287
+ effective_plastic_modulus = 3.0 * shear + (moduli / denominator).sum(dim=-1)
288
+ # Signed consistency equation. Unlike taking von Mises of an overshot
289
+ # trial state, this remains monotone after the root and therefore supplies
290
+ # a valid bracket for bisection.
291
+ residual = (
292
+ von_mises(effective_trial)
293
+ - effective_plastic_modulus * increment
294
+ - radius
295
+ )
296
+ return residual, direction, memories, recovery, moduli
297
+
298
+
299
+ def advance(
300
+ strain: torch.Tensor,
301
+ state: GrayboxState,
302
+ young: torch.Tensor,
303
+ poisson: torch.Tensor,
304
+ yield_stress: torch.Tensor,
305
+ law: NeuralHardeningLaw,
306
+ *,
307
+ bisection_iterations: int = 28,
308
+ direction_iterations: int = 6,
309
+ ) -> tuple[torch.Tensor, GrayboxState, dict[str, torch.Tensor]]:
310
+ """Accept one strain-driven increment using a bracketed neural return map."""
311
+
312
+ trial = elastic_stress(strain, state.plastic_strain, young, poisson)
313
+ trial_deviatoric = deviatoric(trial)
314
+ shifted_trial = trial_deviatoric - state.backstress
315
+ old_radius = yield_stress + law.isotropic(state.peeq, yield_stress)
316
+ trial_function = von_mises(shifted_trial) - old_radius
317
+ plastic = trial_function > yield_stress.clamp_min(1.0) * 1.0e-12
318
+ shear = young / (2.0 * (1.0 + poisson))
319
+ lower = torch.zeros_like(trial_function)
320
+ upper = 2.0 * F.relu(trial_function) / (3.0 * shear).clamp_min(1.0) + 1.0e-14
321
+ # Large non-proportional increments can rotate the flow direction almost
322
+ # orthogonally. A fixed four-doubling bracket silently failed in that
323
+ # regime and accepted a positive consistency residual. Expand until the
324
+ # monotone hardening return is safely bracketed over a much wider range.
325
+ for _ in range(16):
326
+ residual, *_ = _candidate_update(
327
+ trial_deviatoric,
328
+ state,
329
+ upper,
330
+ shear,
331
+ yield_stress,
332
+ law,
333
+ direction_iterations=direction_iterations,
334
+ )
335
+ upper = torch.where(plastic & (residual > 0.0), 2.0 * upper, upper)
336
+ for _ in range(bisection_iterations):
337
+ middle = 0.5 * (lower + upper)
338
+ residual, *_ = _candidate_update(
339
+ trial_deviatoric,
340
+ state,
341
+ middle,
342
+ shear,
343
+ yield_stress,
344
+ law,
345
+ direction_iterations=direction_iterations,
346
+ )
347
+ lower = torch.where(plastic & (residual > 0.0), middle, lower)
348
+ upper = torch.where(plastic & (residual <= 0.0), middle, upper)
349
+ increment = torch.where(plastic, 0.5 * (lower + upper), torch.zeros_like(lower))
350
+ residual, direction, memories, recovery, moduli = _candidate_update(
351
+ trial_deviatoric,
352
+ state,
353
+ increment,
354
+ shear,
355
+ yield_stress,
356
+ law,
357
+ direction_iterations=direction_iterations,
358
+ )
359
+ direction = torch.where(plastic[..., None], direction, torch.zeros_like(direction))
360
+ memories = torch.where(
361
+ plastic[..., None, None], memories, state.memories
362
+ )
363
+ updated = GrayboxState(
364
+ plastic_strain=state.plastic_strain + increment[..., None] * direction,
365
+ peeq=state.peeq + increment,
366
+ memories=memories,
367
+ previous_flow=torch.where(
368
+ plastic[..., None], direction, state.previous_flow
369
+ ),
370
+ )
371
+ stress = elastic_stress(strain, updated.plastic_strain, young, poisson)
372
+ return stress, updated, {
373
+ "plastic_increment": increment,
374
+ "yield_residual": torch.where(plastic, residual, torch.zeros_like(residual)),
375
+ "recovery": recovery,
376
+ "moduli": moduli,
377
+ "plastic": plastic,
378
+ }
379
+
380
+
381
+ def rollout(
382
+ strain: torch.Tensor,
383
+ young: torch.Tensor,
384
+ poisson: torch.Tensor,
385
+ yield_stress: torch.Tensor,
386
+ law: NeuralHardeningLaw,
387
+ *,
388
+ bisection_iterations: int = 28,
389
+ ) -> dict[str, torch.Tensor]:
390
+ """Integrate a batch of complete strain histories."""
391
+
392
+ batch, points, _ = strain.shape
393
+ state = initial_state(
394
+ batch,
395
+ channels=law.channels,
396
+ dtype=strain.dtype,
397
+ device=strain.device,
398
+ )
399
+ stresses = []
400
+ plastics = []
401
+ peeqs = []
402
+ memories = []
403
+ increments = []
404
+ residuals = []
405
+ recoveries = []
406
+ moduli_history = []
407
+ for point in range(points):
408
+ stress, state, diagnostics = advance(
409
+ strain[:, point],
410
+ state,
411
+ young,
412
+ poisson,
413
+ yield_stress,
414
+ law,
415
+ bisection_iterations=bisection_iterations,
416
+ )
417
+ stresses.append(stress)
418
+ plastics.append(state.plastic_strain)
419
+ peeqs.append(state.peeq)
420
+ memories.append(state.memories)
421
+ increments.append(diagnostics["plastic_increment"])
422
+ residuals.append(diagnostics["yield_residual"])
423
+ recoveries.append(diagnostics["recovery"])
424
+ moduli_history.append(diagnostics["moduli"])
425
+ return {
426
+ "stress": torch.stack(stresses, dim=1),
427
+ "plastic_strain": torch.stack(plastics, dim=1),
428
+ "peeq": torch.stack(peeqs, dim=1),
429
+ "memories": torch.stack(memories, dim=1),
430
+ "plastic_increment": torch.stack(increments, dim=1),
431
+ "yield_residual": torch.stack(residuals, dim=1),
432
+ "recovery": torch.stack(recoveries, dim=1),
433
+ "moduli": torch.stack(moduli_history, dim=1),
434
+ }
435
+
436
+
437
+ def discrete_energy_ledger(
438
+ result: dict[str, torch.Tensor],
439
+ yield_stress: torch.Tensor,
440
+ law: NeuralHardeningLaw,
441
+ ) -> dict[str, torch.Tensor]:
442
+ """Partition accepted plastic work using the implemented BE update."""
443
+
444
+ plastic = result["plastic_strain"]
445
+ memories = result["memories"]
446
+ peeq = result["peeq"]
447
+ increment = result["plastic_increment"]
448
+ stress = result["stress"]
449
+ old_plastic = torch.cat((torch.zeros_like(plastic[:, :1]), plastic[:, :-1]), dim=1)
450
+ old_memories = torch.cat((torch.zeros_like(memories[:, :1]), memories[:, :-1]), dim=1)
451
+ plastic_work = double_contract(stress, plastic - old_plastic)
452
+ stress_scale = yield_stress[:, None].expand_as(peeq)
453
+ isotropic_energy = law.isotropic.stored_energy(peeq, stress_scale)
454
+ old_isotropic = torch.cat(
455
+ (torch.zeros_like(isotropic_energy[:, :1]), isotropic_energy[:, :-1]), dim=1
456
+ )
457
+ isotropic_change = isotropic_energy - old_isotropic
458
+ moduli = result["moduli"]
459
+ kinematic_energy = (
460
+ 3.0 * double_contract(memories, memories) / (4.0 * moduli)
461
+ ).sum(dim=-1)
462
+ old_kinematic = torch.cat(
463
+ (torch.zeros_like(kinematic_energy[:, :1]), kinematic_energy[:, :-1]), dim=1
464
+ )
465
+ kinematic_change = kinematic_energy - old_kinematic
466
+ reference = yield_stress[:, None] * increment
467
+ dynamic_recovery = (
468
+ 3.0
469
+ * result["recovery"]
470
+ * double_contract(memories, memories)
471
+ * increment[..., None]
472
+ / (2.0 * moduli)
473
+ ).sum(dim=-1)
474
+ memory_increment = memories - old_memories
475
+ backward_euler = (
476
+ 3.0 * double_contract(memory_increment, memory_increment) / (4.0 * moduli)
477
+ ).sum(dim=-1)
478
+ isotropic_radius = law.isotropic(peeq, stress_scale)
479
+ backward_euler = backward_euler + isotropic_radius * increment - isotropic_change
480
+ balance = (
481
+ plastic_work
482
+ - isotropic_change
483
+ - kinematic_change
484
+ - reference
485
+ - dynamic_recovery
486
+ - backward_euler
487
+ )
488
+ active = increment > 0.0
489
+ zero = torch.zeros_like(balance)
490
+ channels = {
491
+ "plastic_work": plastic_work,
492
+ "isotropic_stored_energy_change": isotropic_change,
493
+ "kinematic_stored_energy_change": kinematic_change,
494
+ "reference_yield_dissipation": reference,
495
+ "dynamic_recovery_dissipation": dynamic_recovery,
496
+ "backward_euler_dissipation": backward_euler,
497
+ "balance_residual": balance,
498
+ }
499
+ return {
500
+ name: torch.where(active, value, zero) for name, value in channels.items()
501
+ }
502
+
503
+
504
+ def hard_constraint_diagnostics(state: GrayboxState) -> dict[str, torch.Tensor]:
505
+ return {
506
+ "maximum_plastic_trace": state.plastic_strain[..., :3].sum(dim=-1).abs(),
507
+ "minimum_peeq": state.peeq,
508
+ "maximum_memory_trace": state.memories[..., :3].sum(dim=-1).abs(),
509
+ }
510
+
511
+
512
+ __all__ = [
513
+ "GrayboxState",
514
+ "MonotoneIsotropicHardening",
515
+ "NeuralHardeningLaw",
516
+ "ObjectiveRecoveryNetwork",
517
+ "advance",
518
+ "deviatoric",
519
+ "double_contract",
520
+ "discrete_energy_ledger",
521
+ "elastic_stress",
522
+ "hard_constraint_diagnostics",
523
+ "initial_state",
524
+ "rollout",
525
+ "von_mises",
526
+ ]
527
+
528
+ # Public research name. Keep the descriptive class name for readable source
529
+ # and expose DENIM as the stable method alias used by the model card and demo.
530
+ DENIM = NeuralHardeningLaw
531
+ __all__.append("DENIM")
src/train_t2_graybox_closure.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Train DENRM on the intentionally mismatched incomplete-physics cohort."""
2
+
3
+ from pathlib import Path
4
+
5
+ from src.generate_t2_graybox_closure import DATA_PATH, MATERIAL
6
+ from src.train_t2_graybox_discrete_energy import run
7
+
8
+
9
+ ROOT = Path(__file__).resolve().parents[1]
10
+
11
+
12
+ if __name__ == "__main__":
13
+ run(
14
+ graybox_steps=1600,
15
+ gru_epochs=60,
16
+ data_path=DATA_PATH,
17
+ material=MATERIAL,
18
+ model_dir=ROOT / "models" / "t2_graybox_closure_v1",
19
+ artifact_dir=ROOT / "artifacts" / "t2_graybox_closure_v1",
20
+ scope=(
21
+ "out-of-template fixed material: three-memory tabulated reference; "
22
+ "two-memory DENRM closure; reference equations and parameters hidden"
23
+ ),
24
+ )
src/train_t2_graybox_discrete_energy.py ADDED
@@ -0,0 +1,428 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Train and evaluate the single T2 gray-box hardening architecture.
2
+
3
+ The neural hardening law is initialized from accepted internal-state
4
+ transitions produced by high-fidelity simulation. The formulas and parameters
5
+ of the generating hardening law are never passed to the model. A stress-only
6
+ variant is a later promotion gate; this first controlled study asks whether the
7
+ unknown evolution can be recovered and deployed through an independent return
8
+ map.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import argparse
14
+ import json
15
+ import random
16
+ import time
17
+ from dataclasses import dataclass
18
+ from pathlib import Path
19
+
20
+ import h5py
21
+ import numpy as np
22
+ import torch
23
+ from torch import nn
24
+
25
+ from agentfem import constitutive
26
+
27
+ from src import t2_graybox_discrete_energy as graybox
28
+ from src.generate_t2_graybox_cohort import DATA_PATH, MATERIAL
29
+ from src.train_t2_multiaxial_models import RecurrentStress
30
+
31
+
32
+ ROOT = Path(__file__).resolve().parents[1]
33
+ MODEL_DIR = ROOT / "models" / "t2_graybox_hardening_v1"
34
+ ARTIFACT_DIR = ROOT / "artifacts" / "t2_graybox_hardening_v1"
35
+ METRICS_PATH = ARTIFACT_DIR / "model_metrics.json"
36
+
37
+
38
+ @dataclass
39
+ class Cohort:
40
+ strain: torch.Tensor
41
+ stress: torch.Tensor
42
+ plastic: torch.Tensor
43
+ peeq: torch.Tensor
44
+ increment: torch.Tensor
45
+ memories: torch.Tensor
46
+ radius: torch.Tensor
47
+ splits: tuple[str, ...]
48
+ families: tuple[str, ...]
49
+
50
+
51
+ def load_cohort(data_path: Path = DATA_PATH) -> Cohort:
52
+ arrays: dict[str, list[np.ndarray]] = {
53
+ name: []
54
+ for name in (
55
+ "strain",
56
+ "stress_pa",
57
+ "plastic_strain",
58
+ "peeq",
59
+ "plastic_increment",
60
+ "memories_pa",
61
+ "isotropic_radius_pa",
62
+ )
63
+ }
64
+ splits: list[str] = []
65
+ families: list[str] = []
66
+ with h5py.File(data_path, "r") as h5:
67
+ for name in sorted(h5):
68
+ group = h5[name]
69
+ for field in arrays:
70
+ arrays[field].append(group[field][...])
71
+ splits.append(str(group.attrs["split"]))
72
+ families.append(str(group.attrs["path_family"]))
73
+ tensor = lambda name: torch.tensor(np.stack(arrays[name]), dtype=torch.float32)
74
+ return Cohort(
75
+ strain=tensor("strain"),
76
+ stress=tensor("stress_pa"),
77
+ plastic=tensor("plastic_strain"),
78
+ peeq=tensor("peeq"),
79
+ increment=tensor("plastic_increment"),
80
+ memories=tensor("memories_pa"),
81
+ radius=tensor("isotropic_radius_pa"),
82
+ splits=tuple(splits),
83
+ families=tuple(families),
84
+ )
85
+
86
+
87
+ def mask(cohort: Cohort, split: str) -> torch.Tensor:
88
+ return torch.tensor([value == split for value in cohort.splits], dtype=torch.bool)
89
+
90
+
91
+ def transition_data(cohort: Cohort, selected: torch.Tensor) -> dict[str, torch.Tensor]:
92
+ plastic_increment = cohort.increment[selected, 1:]
93
+ active = plastic_increment > 1.0e-11
94
+ old_plastic = cohort.plastic[selected, :-1]
95
+ new_plastic = cohort.plastic[selected, 1:]
96
+ flow = (new_plastic - old_plastic) / plastic_increment.clamp_min(1.0e-14)[..., None]
97
+ previous_increment = cohort.increment[selected, :-1]
98
+ previous_plastic = torch.cat(
99
+ (torch.zeros_like(old_plastic[:, :1]), old_plastic[:, :-1]), dim=1
100
+ )
101
+ previous_flow = (old_plastic - previous_plastic) / previous_increment.clamp_min(1.0e-14)[..., None]
102
+ previous_flow = torch.where(
103
+ (previous_increment > 1.0e-11)[..., None],
104
+ previous_flow,
105
+ torch.zeros_like(previous_flow),
106
+ )
107
+ result = {
108
+ "increment": plastic_increment[active],
109
+ "flow": flow[active],
110
+ "previous_flow": previous_flow[active],
111
+ "old_peeq": cohort.peeq[selected, :-1][active],
112
+ "new_peeq": cohort.peeq[selected, 1:][active],
113
+ "old_memories": cohort.memories[selected, :-1][active],
114
+ "new_memories": cohort.memories[selected, 1:][active],
115
+ "new_radius": cohort.radius[selected, 1:][active],
116
+ }
117
+ return result
118
+
119
+
120
+ def train_graybox(
121
+ cohort: Cohort,
122
+ *,
123
+ steps: int = 1200,
124
+ batch_size: int = 4096,
125
+ material: dict[str, float] = MATERIAL,
126
+ ) -> tuple[graybox.NeuralHardeningLaw, dict[str, object]]:
127
+ training = transition_data(cohort, mask(cohort, "train"))
128
+ validation = transition_data(cohort, mask(cohort, "validation"))
129
+ model = graybox.NeuralHardeningLaw(channels=2)
130
+ optimizer = torch.optim.Adam(model.parameters(), lr=2.0e-3)
131
+ scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, steps, eta_min=2.0e-5)
132
+ generator = torch.Generator().manual_seed(20260925)
133
+ yield_stress = float(material["yield_stress_pa"])
134
+
135
+ def objective(data: dict[str, torch.Tensor], indices: torch.Tensor | None = None):
136
+ selected = data if indices is None else {key: value[indices] for key, value in data.items()}
137
+ count = len(selected["increment"])
138
+ scale = torch.full((count,), yield_stress)
139
+ state = graybox.GrayboxState(
140
+ plastic_strain=torch.zeros((count, 6)),
141
+ peeq=selected["old_peeq"],
142
+ memories=selected["old_memories"],
143
+ previous_flow=selected["previous_flow"],
144
+ )
145
+ predicted, recovery, moduli = model.update_memories(
146
+ state, selected["flow"], selected["increment"], scale
147
+ )
148
+ predicted_radius = model.isotropic(selected["new_peeq"], scale)
149
+ memory_state = ((predicted - selected["new_memories"]) / yield_stress).square().mean()
150
+ memory_increment = (
151
+ (
152
+ (predicted - state.memories)
153
+ - (selected["new_memories"] - state.memories)
154
+ )
155
+ / 5.0e6
156
+ ).square().mean()
157
+ radius = ((predicted_radius - selected["new_radius"]) / 70.0e6).square().mean()
158
+ loss = memory_state + memory_increment + radius
159
+ return loss, {
160
+ "memory_state": memory_state,
161
+ "memory_increment": memory_increment,
162
+ "radius": radius,
163
+ "recovery_mean": recovery.mean(dim=0),
164
+ "moduli": moduli.mean(dim=0),
165
+ }
166
+
167
+ started = time.perf_counter()
168
+ best_loss = float("inf")
169
+ best_state = None
170
+ history = []
171
+ for step in range(steps):
172
+ indices = torch.randint(
173
+ len(training["increment"]),
174
+ (min(batch_size, len(training["increment"])),),
175
+ generator=generator,
176
+ )
177
+ optimizer.zero_grad()
178
+ loss, diagnostics = objective(training, indices)
179
+ loss.backward()
180
+ torch.nn.utils.clip_grad_norm_(model.parameters(), 10.0)
181
+ optimizer.step()
182
+ scheduler.step()
183
+ if step % 25 == 0 or step + 1 == steps:
184
+ with torch.no_grad():
185
+ validation_loss, validation_diagnostics = objective(validation)
186
+ value = float(validation_loss)
187
+ history.append(
188
+ {
189
+ "step": step,
190
+ "training_loss": float(loss.detach()),
191
+ "validation_loss": value,
192
+ "moduli_pa": validation_diagnostics["moduli"].tolist(),
193
+ "recovery_mean": validation_diagnostics["recovery_mean"].tolist(),
194
+ }
195
+ )
196
+ if value < best_loss:
197
+ best_loss = value
198
+ best_state = {key: value.detach().clone() for key, value in model.state_dict().items()}
199
+ if best_state is None:
200
+ raise RuntimeError("Gray-box training did not produce a checkpoint.")
201
+ model.load_state_dict(best_state)
202
+ model.eval()
203
+ return model, {
204
+ "training_seconds": time.perf_counter() - started,
205
+ "best_validation_loss": best_loss,
206
+ "steps": steps,
207
+ "history": history,
208
+ }
209
+
210
+
211
+ def train_gru(
212
+ cohort: Cohort,
213
+ *,
214
+ epochs: int = 60,
215
+ ) -> tuple[nn.Module, dict[str, object], dict[str, torch.Tensor]]:
216
+ train = mask(cohort, "train")
217
+ validation = mask(cohort, "validation")
218
+ strain_mean = cohort.strain[train].mean(dim=(0, 1), keepdim=True)
219
+ strain_std = cohort.strain[train].std(dim=(0, 1), keepdim=True).clamp_min(1.0e-6)
220
+ stress_mean = cohort.stress[train].mean(dim=(0, 1), keepdim=True)
221
+ stress_std = cohort.stress[train].std(dim=(0, 1), keepdim=True).clamp_min(1.0e6)
222
+ inputs = (cohort.strain - strain_mean) / strain_std
223
+ targets = (cohort.stress - stress_mean) / stress_std
224
+ model = RecurrentStress(6, cell="gru", hidden=72)
225
+ optimizer = torch.optim.AdamW(model.parameters(), lr=2.0e-3, weight_decay=1.0e-5)
226
+ generator = torch.Generator().manual_seed(20260925)
227
+ train_indices = torch.where(train)[0]
228
+ best_loss = float("inf")
229
+ best_state = None
230
+ started = time.perf_counter()
231
+ for _ in range(epochs):
232
+ shuffled = train_indices[torch.randperm(len(train_indices), generator=generator)]
233
+ model.train()
234
+ for start in range(0, len(shuffled), 16):
235
+ selected = shuffled[start : start + 16]
236
+ optimizer.zero_grad()
237
+ loss = (model(inputs[selected]) - targets[selected]).square().mean()
238
+ loss.backward()
239
+ optimizer.step()
240
+ model.eval()
241
+ with torch.no_grad():
242
+ value = float((model(inputs[validation]) - targets[validation]).square().mean())
243
+ if value < best_loss:
244
+ best_loss = value
245
+ best_state = {key: value.detach().clone() for key, value in model.state_dict().items()}
246
+ if best_state is None:
247
+ raise RuntimeError("GRU training did not produce a checkpoint.")
248
+ model.load_state_dict(best_state)
249
+ model.eval()
250
+ return model, {
251
+ "training_seconds": time.perf_counter() - started,
252
+ "best_validation_loss": best_loss,
253
+ "epochs": epochs,
254
+ }, {
255
+ "strain_mean": strain_mean,
256
+ "strain_std": strain_std,
257
+ "stress_mean": stress_mean,
258
+ "stress_std": stress_std,
259
+ }
260
+
261
+
262
+ def _voigt_to_tensor(value: np.ndarray) -> np.ndarray:
263
+ tensor = np.zeros((3, 3), dtype=float)
264
+ tensor[(0, 1, 2, 0, 1, 0), (0, 1, 2, 1, 2, 2)] = value
265
+ tensor[(1, 2, 2), (0, 1, 0)] = value[[3, 4, 5]]
266
+ return tensor
267
+
268
+
269
+ def no_hardening_response(
270
+ cohort: Cohort, material: dict[str, float] = MATERIAL
271
+ ) -> torch.Tensor:
272
+ law = constitutive.J2LinearIsotropicHardening(
273
+ young=float(material["young_pa"]),
274
+ poisson=float(material["poisson"]),
275
+ yield_stress=float(material["yield_stress_pa"]),
276
+ hardening_modulus=0.0,
277
+ )
278
+ result = np.empty_like(cohort.stress.numpy())
279
+ for case in range(len(cohort.strain)):
280
+ state = None
281
+ for point, strain in enumerate(cohort.strain[case].numpy()):
282
+ update = law.update(_voigt_to_tensor(strain), state, linearization="none")
283
+ state = update.state
284
+ tensor = update.stress
285
+ result[case, point] = tensor[(0, 1, 2, 0, 1, 0), (0, 1, 2, 1, 2, 2)]
286
+ return torch.tensor(result)
287
+
288
+
289
+ def stress_metrics(
290
+ prediction: torch.Tensor,
291
+ reference: torch.Tensor,
292
+ selected: torch.Tensor,
293
+ ) -> dict[str, float | int]:
294
+ error = prediction[selected] - reference[selected]
295
+ denominator = ((reference[selected] - reference[selected].mean()).square().sum()).clamp_min(1.0)
296
+ return {
297
+ "trajectory_count": int(selected.sum()),
298
+ "rmse_mpa": float(torch.sqrt(error.square().mean()) / 1.0e6),
299
+ "mae_mpa": float(error.abs().mean() / 1.0e6),
300
+ "r2": float(1.0 - error.square().sum() / denominator),
301
+ }
302
+
303
+
304
+ def run(
305
+ *,
306
+ graybox_steps: int = 1200,
307
+ gru_epochs: int = 60,
308
+ data_path: Path = DATA_PATH,
309
+ material: dict[str, float] = MATERIAL,
310
+ model_dir: Path = MODEL_DIR,
311
+ artifact_dir: Path = ARTIFACT_DIR,
312
+ scope: str = "fixed synthetic material; hardening parameters and formulas hidden from learned models",
313
+ ) -> dict[str, object]:
314
+ random.seed(20260925)
315
+ np.random.seed(20260925)
316
+ torch.manual_seed(20260925)
317
+ cohort = load_cohort(data_path)
318
+ graybox_model, graybox_training = train_graybox(
319
+ cohort, steps=graybox_steps, material=material
320
+ )
321
+ gru_model, gru_training, normalization = train_gru(cohort, epochs=gru_epochs)
322
+ with torch.no_grad():
323
+ started = time.perf_counter()
324
+ graybox_result = graybox.rollout(
325
+ cohort.strain,
326
+ torch.full((len(cohort.strain),), float(material["young_pa"])),
327
+ torch.full((len(cohort.strain),), float(material["poisson"])),
328
+ torch.full((len(cohort.strain),), float(material["yield_stress_pa"])),
329
+ graybox_model,
330
+ bisection_iterations=24,
331
+ )
332
+ graybox_inference = time.perf_counter() - started
333
+ started = time.perf_counter()
334
+ gru_prediction = (
335
+ gru_model(
336
+ (cohort.strain - normalization["strain_mean"])
337
+ / normalization["strain_std"]
338
+ )
339
+ * normalization["stress_std"]
340
+ + normalization["stress_mean"]
341
+ )
342
+ gru_inference = time.perf_counter() - started
343
+ started = time.perf_counter()
344
+ incomplete_prediction = no_hardening_response(cohort, material)
345
+ incomplete_inference = time.perf_counter() - started
346
+
347
+ metrics: dict[str, object] = {
348
+ "scope": scope,
349
+ "training": {
350
+ "denrm": graybox_training,
351
+ "gru": gru_training,
352
+ },
353
+ "models": {},
354
+ }
355
+ for name, prediction, seconds in (
356
+ ("incomplete_j2", incomplete_prediction, incomplete_inference),
357
+ ("gru", gru_prediction, gru_inference),
358
+ ("denrm", graybox_result["stress"], graybox_inference),
359
+ ):
360
+ metrics["models"][name] = {
361
+ split: stress_metrics(prediction, cohort.stress, mask(cohort, split))
362
+ for split in ("train", "validation", "test")
363
+ }
364
+ metrics["models"][name]["inference_seconds_all_trajectories"] = seconds
365
+ active = graybox_result["plastic_increment"] > 1.0e-11
366
+ ledger = graybox.discrete_energy_ledger(
367
+ graybox_result,
368
+ torch.full((len(cohort.strain),), float(material["yield_stress_pa"])),
369
+ graybox_model,
370
+ )
371
+ energy_scale = ledger["plastic_work"][active].abs().max().clamp_min(1.0)
372
+ metrics["models"]["denrm"].update(
373
+ maximum_yield_residual_pa=float(graybox_result["yield_residual"][active].abs().max()),
374
+ maximum_plastic_trace=float(
375
+ graybox_result["plastic_strain"][..., :3].sum(dim=-1).abs().max()
376
+ ),
377
+ minimum_peeq_increment=float(
378
+ torch.diff(graybox_result["peeq"], dim=1).min()
379
+ ),
380
+ learned_moduli_pa=(
381
+ graybox_model.moduli(torch.tensor(float(material["yield_stress_pa"])))
382
+ .detach()
383
+ .tolist()
384
+ ),
385
+ minimum_reference_yield_dissipation=float(
386
+ ledger["reference_yield_dissipation"][active].min()
387
+ ),
388
+ minimum_dynamic_recovery_dissipation=float(
389
+ ledger["dynamic_recovery_dissipation"][active].min()
390
+ ),
391
+ minimum_backward_euler_dissipation=float(
392
+ ledger["backward_euler_dissipation"][active].min().detach()
393
+ ),
394
+ maximum_energy_balance_relative_residual=float(
395
+ (
396
+ ledger["balance_residual"][active].abs().max() / energy_scale
397
+ ).detach()
398
+ ),
399
+ )
400
+ model_dir.mkdir(parents=True, exist_ok=True)
401
+ artifact_dir.mkdir(parents=True, exist_ok=True)
402
+ torch.save(
403
+ {"state_dict": graybox_model.state_dict(), "material_known": {
404
+ key: material[key] for key in ("young_pa", "poisson", "yield_stress_pa")
405
+ }},
406
+ model_dir / "denrm.pt",
407
+ )
408
+ torch.save(
409
+ {"state_dict": gru_model.state_dict(), "normalization": normalization},
410
+ model_dir / "gru.pt",
411
+ )
412
+ (artifact_dir / "model_metrics.json").write_text(
413
+ json.dumps(metrics, indent=2) + "\n", encoding="utf-8"
414
+ )
415
+ print(json.dumps({"models": metrics["models"]}, indent=2))
416
+ return metrics
417
+
418
+
419
+ def main() -> None:
420
+ parser = argparse.ArgumentParser()
421
+ parser.add_argument("--graybox-steps", type=int, default=1200)
422
+ parser.add_argument("--gru-epochs", type=int, default=60)
423
+ args = parser.parse_args()
424
+ run(graybox_steps=args.graybox_steps, gru_epochs=args.gru_epochs)
425
+
426
+
427
+ if __name__ == "__main__":
428
+ main()
src/validate_t2_graybox.py ADDED
@@ -0,0 +1,411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Time-discretization and structural deployment gates for T2 DENRM."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import time
7
+ from pathlib import Path
8
+
9
+ import matplotlib
10
+
11
+ matplotlib.use("Agg")
12
+ import matplotlib.pyplot as plt
13
+ import numpy as np
14
+ import torch
15
+ from scipy.optimize import least_squares
16
+
17
+ from src import structural_validate_t2_models as structure
18
+ from src import t2_graybox_discrete_energy as graybox
19
+ from src.generate_t2_graybox_cohort import MATERIAL, design, solve
20
+
21
+
22
+ ROOT = Path(__file__).resolve().parents[1]
23
+ MODEL_PATH = ROOT / "models" / "t2_graybox_hardening_v1" / "denrm.pt"
24
+ ARTIFACT_DIR = ROOT / "artifacts" / "t2_graybox_hardening_v1"
25
+ OUTPUT = ARTIFACT_DIR / "deployment_validation.json"
26
+ BASIS = torch.tensor((1.0, -0.5, -0.5, 0.0, 0.0, 0.0), dtype=torch.float64)
27
+
28
+
29
+ def load_model(model_path: Path = MODEL_PATH) -> graybox.NeuralHardeningLaw:
30
+ checkpoint = torch.load(model_path, map_location="cpu", weights_only=False)
31
+ model = graybox.NeuralHardeningLaw(channels=2).double()
32
+ model.load_state_dict(checkpoint["state_dict"])
33
+ model.eval()
34
+ return model
35
+
36
+
37
+ def _rollout(
38
+ model: graybox.NeuralHardeningLaw,
39
+ strain: np.ndarray,
40
+ material: dict[str, object] = MATERIAL,
41
+ ) -> dict[str, torch.Tensor]:
42
+ selected = torch.tensor(strain, dtype=torch.float64)
43
+ batch = len(selected)
44
+ with torch.no_grad():
45
+ return graybox.rollout(
46
+ selected,
47
+ torch.full((batch,), float(material["young_pa"]), dtype=torch.float64),
48
+ torch.full((batch,), float(material["poisson"]), dtype=torch.float64),
49
+ torch.full((batch,), float(material["yield_stress_pa"]), dtype=torch.float64),
50
+ model,
51
+ bisection_iterations=30,
52
+ )
53
+
54
+
55
+ def time_discretization_gate(
56
+ model: graybox.NeuralHardeningLaw,
57
+ *,
58
+ rows: list[dict[str, object]] | None = None,
59
+ solve_function=solve,
60
+ material: dict[str, object] = MATERIAL,
61
+ ) -> dict[str, object]:
62
+ rows = design(4) if rows is None else rows
63
+ selected = [rows[index] for index in range(0, len(rows), 4)]
64
+ result: dict[str, object] = {}
65
+ predictions: dict[int, dict[str, torch.Tensor]] = {}
66
+ references: dict[int, np.ndarray] = {}
67
+ for points in (121, 481):
68
+ solved = [solve_function(row, points=points) for row in selected]
69
+ strain = np.stack([case["strain"] for case in solved])
70
+ reference = np.stack([case["stress_pa"] for case in solved])
71
+ prediction = _rollout(model, strain, material)
72
+ error = prediction["stress"].numpy() - reference
73
+ active = prediction["plastic_increment"] > 1.0e-11
74
+ predictions[points] = prediction
75
+ references[points] = reference
76
+ result[str(points)] = {
77
+ "trajectory_count": len(selected),
78
+ "rmse_mpa": float(np.sqrt(np.mean(error**2)) / 1.0e6),
79
+ "mae_mpa": float(np.mean(np.abs(error)) / 1.0e6),
80
+ "maximum_yield_residual_pa": float(
81
+ prediction["yield_residual"][active].abs().max()
82
+ ),
83
+ }
84
+ coarse_terminal = predictions[121]["stress"][:, -1]
85
+ fine_terminal = predictions[481]["stress"][:, -1]
86
+ reference_scale = torch.tensor(references[481][:, -1]).norm().clamp_min(1.0)
87
+ result["terminal_121_to_481_relative_change"] = float(
88
+ (coarse_terminal - fine_terminal).norm() / reference_scale
89
+ )
90
+ return result
91
+
92
+
93
+ def _response(
94
+ model: graybox.NeuralHardeningLaw,
95
+ old_state: graybox.GrayboxState,
96
+ scalar_strain: float,
97
+ ) -> tuple[float, float, graybox.GrayboxState]:
98
+ def evaluate(value: float):
99
+ strain = (float(value) * BASIS).reshape(1, 6)
100
+ with torch.no_grad():
101
+ return graybox.advance(
102
+ strain,
103
+ old_state,
104
+ torch.tensor((float(MATERIAL["young_pa"]),), dtype=torch.float64),
105
+ torch.tensor((float(MATERIAL["poisson"]),), dtype=torch.float64),
106
+ torch.tensor((float(MATERIAL["yield_stress_pa"]),), dtype=torch.float64),
107
+ model,
108
+ bisection_iterations=30,
109
+ )
110
+
111
+ stress, state, _ = evaluate(scalar_strain)
112
+ generalized = float(graybox.double_contract(stress[0], BASIS))
113
+ step = 1.0e-7 * max(1.0, abs(scalar_strain) / 0.005)
114
+ upper, _, _ = evaluate(scalar_strain + step)
115
+ lower, _, _ = evaluate(scalar_strain - step)
116
+ tangent = float(
117
+ (graybox.double_contract(upper[0], BASIS) - graybox.double_contract(lower[0], BASIS))
118
+ / (2.0 * step)
119
+ )
120
+ return generalized, tangent, state
121
+
122
+
123
+ def _batch_response(
124
+ model: graybox.NeuralHardeningLaw,
125
+ old_state: graybox.GrayboxState,
126
+ scalar_strain: np.ndarray,
127
+ material: dict[str, object] = MATERIAL,
128
+ ) -> tuple[np.ndarray, np.ndarray, graybox.GrayboxState]:
129
+ """Evaluate every element in one batched constitutive call.
130
+
131
+ The global bar problem has independent quadrature-point states, which map
132
+ directly to DENRM's batch dimension. Batching preserves the local return
133
+ map while avoiding thousands of tiny Python/PyTorch calls.
134
+ """
135
+
136
+ values = torch.as_tensor(scalar_strain, dtype=torch.float64)
137
+ batch = len(values)
138
+ young = torch.full((batch,), float(material["young_pa"]), dtype=torch.float64)
139
+ poisson = torch.full((batch,), float(material["poisson"]), dtype=torch.float64)
140
+ yield_stress = torch.full(
141
+ (batch,), float(material["yield_stress_pa"]), dtype=torch.float64
142
+ )
143
+
144
+ def evaluate(selected: torch.Tensor):
145
+ strain = selected[:, None] * BASIS[None, :]
146
+ return graybox.advance(
147
+ strain,
148
+ old_state,
149
+ young,
150
+ poisson,
151
+ yield_stress,
152
+ model,
153
+ bisection_iterations=30,
154
+ )
155
+
156
+ with torch.no_grad():
157
+ stress, state, _ = evaluate(values)
158
+ generalized = graybox.double_contract(stress, BASIS)
159
+ step = 1.0e-7 * torch.maximum(
160
+ torch.ones_like(values), values.abs() / 0.005
161
+ )
162
+ upper, _, _ = evaluate(values + step)
163
+ lower, _, _ = evaluate(values - step)
164
+ tangent = (
165
+ graybox.double_contract(upper, BASIS)
166
+ - graybox.double_contract(lower, BASIS)
167
+ ) / (2.0 * step)
168
+ return generalized.numpy(), tangent.numpy(), state
169
+
170
+
171
+ def solve_structure(
172
+ model: graybox.NeuralHardeningLaw,
173
+ displacement: np.ndarray,
174
+ *,
175
+ elements: int = 12,
176
+ notch_depth: float,
177
+ material: dict[str, object] = MATERIAL,
178
+ ) -> dict[str, np.ndarray | float]:
179
+ nodes, area = structure.geometry(elements, notch_depth)
180
+ lengths = np.diff(nodes)
181
+ states = graybox.initial_state(elements, channels=2, dtype=torch.float64)
182
+ u = np.zeros(elements + 1)
183
+ reactions = []
184
+ iterations = []
185
+ trust_region_fallback_steps: list[int] = []
186
+ started = time.perf_counter()
187
+ for step_index, end_value in enumerate(displacement):
188
+ if step_index > 0:
189
+ u += np.linspace(0.0, end_value - u[-1], elements + 1)
190
+ u[0] = 0.0
191
+ u[-1] = end_value
192
+ accepted = None
193
+ for iteration in range(60):
194
+ internal = np.zeros(elements + 1)
195
+ stiffness = np.zeros((elements + 1, elements + 1))
196
+ strains = np.diff(u) / lengths
197
+ current_stress, current_tangent, trial_states = _batch_response(
198
+ model, states, strains, material
199
+ )
200
+ for element in range(elements):
201
+ stress = current_stress[element]
202
+ tangent = float(np.clip(current_tangent[element], 1.0e7, 4.0e11))
203
+ b = np.asarray((-1.0 / lengths[element], 1.0 / lengths[element]))
204
+ dofs = (element, element + 1)
205
+ internal[list(dofs)] += area[element] * stress * b * lengths[element]
206
+ stiffness[np.ix_(dofs, dofs)] += (
207
+ area[element] * tangent * np.outer(b, b) * lengths[element]
208
+ )
209
+ residual = internal[1:-1]
210
+ scale = max(float(np.linalg.norm(internal)), 1.0)
211
+ # The local law is solved tightly, but its scalar tangent is a
212
+ # finite-difference directional derivative across an active-set
213
+ # switch. Use an engineering equilibrium tolerance and a bounded
214
+ # Newton correction, matching the deployment gate used for the
215
+ # other learned constitutive models in this project.
216
+ if np.linalg.norm(residual) <= 2.0e-6 * scale + 1.0e2:
217
+ accepted = trial_states
218
+ break
219
+ increment = np.linalg.solve(stiffness[1:-1, 1:-1], residual)
220
+ maximum = 0.20 * max(abs(end_value), 1.0e-5)
221
+ norm_increment = np.max(np.abs(increment))
222
+ if norm_increment > maximum:
223
+ increment *= maximum / norm_increment
224
+ u[1:-1] -= increment
225
+ if accepted is None:
226
+ # Reversal points can place several integration points on different
227
+ # sides of the elastic/plastic active-set switch. Recover the same
228
+ # FE equilibrium with a bounded trust-region solve; the local
229
+ # constitutive law and its committed state remain unchanged.
230
+ end_fixed = float(end_value)
231
+
232
+ # In a one-dimensional bar, equilibrium is equivalently expressed
233
+ # by a single constant axial force. Solving for all element
234
+ # strains plus that force avoids poor conditioning in nodal
235
+ # coordinates at a displacement reversal.
236
+ def force_compatibility(unknown: np.ndarray) -> np.ndarray:
237
+ candidate_strain = unknown[:-1]
238
+ force_scaled = unknown[-1]
239
+ candidate_stress, _, _ = _batch_response(
240
+ model, states, candidate_strain, material
241
+ )
242
+ force_balance = area * candidate_stress / 1.0e8 - force_scaled
243
+ compatibility = (
244
+ np.dot(lengths, candidate_strain) - end_fixed
245
+ ) / 0.005
246
+ return np.concatenate((force_balance, (compatibility,)))
247
+
248
+ def force_compatibility_jacobian(unknown: np.ndarray) -> np.ndarray:
249
+ candidate_strain = unknown[:-1]
250
+ _, candidate_tangent, _ = _batch_response(
251
+ model, states, candidate_strain, material
252
+ )
253
+ candidate_tangent = np.clip(candidate_tangent, 1.0e7, 4.0e11)
254
+ jacobian = np.zeros((elements + 1, elements + 1))
255
+ jacobian[np.arange(elements), np.arange(elements)] = (
256
+ area * candidate_tangent / 1.0e8
257
+ )
258
+ jacobian[:elements, -1] = -1.0
259
+ jacobian[-1, :elements] = lengths / 0.005
260
+ return jacobian
261
+
262
+ initial_strain = np.diff(u) / lengths
263
+ initial_force = float(internal[-1]) / 1.0e8
264
+ recovered = least_squares(
265
+ force_compatibility,
266
+ np.concatenate((initial_strain, (initial_force,))),
267
+ method="trf",
268
+ jac=force_compatibility_jacobian,
269
+ x_scale=np.concatenate((np.full(elements, 0.005), (1.0,))),
270
+ max_nfev=120,
271
+ xtol=1.0e-12,
272
+ ftol=1.0e-12,
273
+ gtol=1.0e-12,
274
+ )
275
+ if recovered.success:
276
+ strains = recovered.x[:-1]
277
+ u = np.concatenate(((0.0,), np.cumsum(lengths * strains)))
278
+ current_stress, _, trial_states = _batch_response(
279
+ model, states, strains, material
280
+ )
281
+ internal = np.zeros(elements + 1)
282
+ for element in range(elements):
283
+ b = np.asarray((-1.0 / lengths[element], 1.0 / lengths[element]))
284
+ dofs = (element, element + 1)
285
+ internal[list(dofs)] += (
286
+ area[element]
287
+ * current_stress[element]
288
+ * b
289
+ * lengths[element]
290
+ )
291
+ residual = internal[1:-1]
292
+ scale = max(float(np.linalg.norm(internal)), 1.0)
293
+ if np.linalg.norm(residual) <= 2.0e-6 * scale + 1.0e2:
294
+ accepted = trial_states
295
+ iteration = 60 + int(recovered.nfev)
296
+ trust_region_fallback_steps.append(step_index)
297
+ if accepted is None:
298
+ raise RuntimeError(
299
+ f"DENRM structural solve failed at step {step_index}; "
300
+ f"max_abs_element_strain={float(np.max(np.abs(strains))):.6g}."
301
+ )
302
+ states = accepted
303
+ reactions.append(float(internal[-1]))
304
+ iterations.append(iteration + 1)
305
+ return {
306
+ "reaction": np.asarray(reactions),
307
+ "iterations": np.asarray(iterations),
308
+ "trust_region_fallback_steps": trust_region_fallback_steps,
309
+ "elapsed_seconds": time.perf_counter() - started,
310
+ }
311
+
312
+
313
+ def structural_gate(
314
+ model: graybox.NeuralHardeningLaw,
315
+ *,
316
+ material: dict[str, object] = MATERIAL,
317
+ native_law_factory=structure.material,
318
+ artifact_dir: Path = ARTIFACT_DIR,
319
+ ) -> dict[str, object]:
320
+ result: dict[str, object] = {}
321
+ figure, axes = plt.subplots(1, 2, figsize=(10.0, 4.2), constrained_layout=True)
322
+ cases = (
323
+ ("mild_cyclic", 0.12, structure.load_history(points=81)),
324
+ ("severe_monotonic", 0.42, np.linspace(0.0, 0.0065, 61)),
325
+ )
326
+ for axis, (name, depth, displacement) in zip(
327
+ axes,
328
+ cases,
329
+ strict=True,
330
+ ):
331
+ reference = structure.solve_native(
332
+ 12,
333
+ displacement,
334
+ notch_depth=depth,
335
+ law_factory=native_law_factory,
336
+ )
337
+ learned = solve_structure(
338
+ model, displacement, notch_depth=depth, material=material
339
+ )
340
+ difference = learned["reaction"] - reference["reaction"]
341
+ relative = float(
342
+ np.linalg.norm(difference) / max(np.linalg.norm(reference["reaction"]), 1.0)
343
+ )
344
+ result[name] = {
345
+ "reaction_relative_l2": relative,
346
+ "maximum_absolute_reaction_error": float(np.max(np.abs(difference))),
347
+ "maximum_newton_iterations": int(np.max(learned["iterations"])),
348
+ "mean_newton_iterations": float(np.mean(learned["iterations"])),
349
+ "trust_region_fallback_count": len(
350
+ learned["trust_region_fallback_steps"]
351
+ ),
352
+ "trust_region_fallback_steps": list(
353
+ learned["trust_region_fallback_steps"]
354
+ ),
355
+ "elapsed_seconds": float(learned["elapsed_seconds"]),
356
+ }
357
+ axis.plot(displacement, reference["reaction"], label="AgentFEM reference")
358
+ axis.plot(displacement, learned["reaction"], "--", label="DENRM")
359
+ axis.set_title(name.replace("_", " "))
360
+ axis.set_xlabel("prescribed end displacement")
361
+ axis.set_ylabel("reaction")
362
+ axis.grid(alpha=0.2)
363
+ axes[0].legend(frameon=False)
364
+ artifact_dir.mkdir(parents=True, exist_ok=True)
365
+ figure.savefig(artifact_dir / "structural_reaction_comparison.png", dpi=190)
366
+ plt.close(figure)
367
+
368
+ # Deliberately retain a stronger cyclic extrapolation as a falsification
369
+ # gate. It currently exceeds the training strain envelope during reversal;
370
+ # recording the failure is more informative than silently shrinking it.
371
+ try:
372
+ severe_cyclic = solve_structure(
373
+ model,
374
+ structure.load_history(points=81),
375
+ notch_depth=0.42,
376
+ material=material,
377
+ )
378
+ result["severe_cyclic_stress_test"] = {
379
+ "passed": True,
380
+ "maximum_newton_iterations": int(
381
+ np.max(severe_cyclic["iterations"])
382
+ ),
383
+ "trust_region_fallback_count": len(
384
+ severe_cyclic["trust_region_fallback_steps"]
385
+ ),
386
+ }
387
+ except RuntimeError as error:
388
+ result["severe_cyclic_stress_test"] = {
389
+ "passed": False,
390
+ "failure": str(error),
391
+ "interpretation": (
392
+ "strong cyclic localization leaves the present training envelope; "
393
+ "this is a declared promotion-gate failure, not a successful deployment"
394
+ ),
395
+ }
396
+ return result
397
+
398
+
399
+ def main() -> None:
400
+ model = load_model()
401
+ ARTIFACT_DIR.mkdir(parents=True, exist_ok=True)
402
+ result = {
403
+ "time_discretization": time_discretization_gate(model),
404
+ "structure": structural_gate(model),
405
+ }
406
+ OUTPUT.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
407
+ print(json.dumps(result, indent=2))
408
+
409
+
410
+ if __name__ == "__main__":
411
+ main()
src/validate_t2_graybox_closure.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Promotion gates for the out-of-template incomplete-physics closure."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from src.generate_t2_graybox_closure import MATERIAL, closure_design, material, solve
7
+ from src.validate_t2_graybox import (
8
+ load_model,
9
+ structural_gate,
10
+ time_discretization_gate,
11
+ )
12
+
13
+
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+ MODEL_PATH = ROOT / "models" / "t2_graybox_closure_v1" / "denrm.pt"
16
+ ARTIFACT_DIR = ROOT / "artifacts" / "t2_graybox_closure_v1"
17
+ OUTPUT = ARTIFACT_DIR / "deployment_validation.json"
18
+
19
+
20
+ def main() -> None:
21
+ model = load_model(MODEL_PATH)
22
+ ARTIFACT_DIR.mkdir(parents=True, exist_ok=True)
23
+ result = {
24
+ "scope": (
25
+ "reference has three memories and tabulated hardening; deployed DENRM "
26
+ "has two memories and no access to the reference equations"
27
+ ),
28
+ "time_discretization": time_discretization_gate(
29
+ model,
30
+ rows=closure_design(4),
31
+ solve_function=solve,
32
+ material=MATERIAL,
33
+ ),
34
+ "structure": structural_gate(
35
+ model,
36
+ material=MATERIAL,
37
+ native_law_factory=material,
38
+ artifact_dir=ARTIFACT_DIR,
39
+ ),
40
+ }
41
+ OUTPUT.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
42
+ print(json.dumps(result, indent=2))
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()
tests/test_t2_graybox_closure.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from src.generate_t2_graybox_closure import closure_design, material, solve
4
+
5
+
6
+ def test_reference_is_intentionally_richer_than_closure_state():
7
+ law = material()
8
+ assert law.backstress_count == 3
9
+ assert law.isotropic_hardening is not None
10
+ assert len(law.isotropic_hardening.equivalent_plastic_strain) == 7
11
+
12
+
13
+ def test_closure_cohort_preserves_total_reference_backstress():
14
+ row = closure_design(4)[0]
15
+ nine_points = 9
16
+ result = solve(row, points=nine_points)
17
+ assert result["strain"].shape == (nine_points, 6)
18
+ assert result["truth_memories_pa"].shape == (nine_points, 3, 6)
19
+ assert result["memories_pa"].shape == (nine_points, 2, 6)
20
+ np.testing.assert_allclose(
21
+ result["memories_pa"].sum(axis=1),
22
+ result["truth_memories_pa"].sum(axis=1),
23
+ rtol=1.0e-12,
24
+ atol=1.0e-5,
25
+ )
tests/test_t2_graybox_discrete_energy.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import torch
4
+
5
+ from src import t2_graybox_discrete_energy as subject
6
+
7
+
8
+ def test_monotone_hardening_is_zero_anchored_and_nondecreasing() -> None:
9
+ model = subject.MonotoneIsotropicHardening().double()
10
+ peeq = torch.linspace(0.0, 0.03, 101, dtype=torch.float64)
11
+ scale = torch.full_like(peeq, 300.0e6)
12
+ radius = model(peeq, scale)
13
+ assert abs(float(radius[0].detach())) < 1.0e-8
14
+ assert torch.all(radius[1:] >= radius[:-1])
15
+ assert torch.all(model.derivative(peeq, scale) > 0.0)
16
+
17
+
18
+ def test_recovery_is_positive_and_objective_under_basis_rotation() -> None:
19
+ torch.manual_seed(7)
20
+ model = subject.ObjectiveRecoveryNetwork(channels=2).double()
21
+ memories = subject.deviatoric(torch.randn(4, 2, 6, dtype=torch.float64))
22
+ flow = subject.deviatoric(torch.randn(4, 6, dtype=torch.float64))
23
+ peeq = torch.linspace(0.0, 0.02, 4, dtype=torch.float64)
24
+ radius = torch.linspace(0.0, 80.0e6, 4, dtype=torch.float64)
25
+ scale = torch.full((4,), 280.0e6, dtype=torch.float64)
26
+ reversal = torch.linspace(-1.0, 1.0, 4, dtype=torch.float64)
27
+ result = model(peeq, radius, flow, memories, scale, reversal)
28
+ assert torch.all(result > 0.0)
29
+
30
+ def as_matrix(value: torch.Tensor) -> torch.Tensor:
31
+ tensor = torch.zeros((*value.shape[:-1], 3, 3), dtype=value.dtype)
32
+ tensor[..., 0, 0] = value[..., 0]
33
+ tensor[..., 1, 1] = value[..., 1]
34
+ tensor[..., 2, 2] = value[..., 2]
35
+ tensor[..., 0, 1] = tensor[..., 1, 0] = value[..., 3]
36
+ tensor[..., 1, 2] = tensor[..., 2, 1] = value[..., 4]
37
+ tensor[..., 0, 2] = tensor[..., 2, 0] = value[..., 5]
38
+ return tensor
39
+
40
+ def as_voigt(value: torch.Tensor) -> torch.Tensor:
41
+ return value[..., (0, 1, 2, 0, 1, 0), (0, 1, 2, 1, 2, 2)]
42
+
43
+ rotation, _ = torch.linalg.qr(torch.randn(3, 3, dtype=torch.float64))
44
+ rotated_flow = as_voigt(
45
+ torch.einsum("ij,bjk,lk->bil", rotation, as_matrix(flow), rotation)
46
+ )
47
+ rotated_memories = as_voigt(
48
+ torch.einsum("ij,bcjk,lk->bcil", rotation, as_matrix(memories), rotation)
49
+ )
50
+ rotated = model(
51
+ peeq, radius, rotated_flow, rotated_memories, scale, reversal
52
+ )
53
+ torch.testing.assert_close(rotated, result, rtol=1.0e-12, atol=1.0e-12)
54
+
55
+
56
+ def test_memory_update_preserves_deviatoric_state_and_nonnegative_rates() -> None:
57
+ law = subject.NeuralHardeningLaw(channels=2).double()
58
+ state = subject.initial_state(3, channels=2, dtype=torch.float64)
59
+ flow = subject.deviatoric(torch.randn(3, 6, dtype=torch.float64))
60
+ increment = torch.tensor((0.0, 1.0e-4, 5.0e-4), dtype=torch.float64)
61
+ scale = torch.full((3,), 280.0e6, dtype=torch.float64)
62
+ memories, recovery, moduli = law.update_memories(
63
+ state, flow, increment, scale
64
+ )
65
+ assert torch.all(recovery > 0.0)
66
+ assert torch.all(moduli > 0.0)
67
+ assert torch.max(torch.abs(memories[..., :3].sum(dim=-1))) < 1.0e-8
68
+ assert torch.count_nonzero(memories[0]) == 0
69
+
70
+
71
+ def test_elastic_stress_recovers_zero_for_zero_elastic_strain() -> None:
72
+ strain = torch.randn(5, 6, dtype=torch.float64)
73
+ stress = subject.elastic_stress(
74
+ strain,
75
+ strain,
76
+ torch.full((5,), 200.0e9, dtype=torch.float64),
77
+ torch.full((5,), 0.3, dtype=torch.float64),
78
+ )
79
+ assert torch.count_nonzero(stress) == 0
80
+
81
+
82
+ def test_neural_return_map_closes_yield_surface_and_state_constraints() -> None:
83
+ law = subject.NeuralHardeningLaw(channels=2).double()
84
+ strain = torch.zeros((2, 25, 6), dtype=torch.float64)
85
+ axial = torch.linspace(0.0, 0.009, 25, dtype=torch.float64)
86
+ strain[:, :, 0] = axial
87
+ strain[:, :, 1] = -0.5 * axial
88
+ strain[:, :, 2] = -0.5 * axial
89
+ result = subject.rollout(
90
+ strain,
91
+ torch.full((2,), 190.0e9, dtype=torch.float64),
92
+ torch.full((2,), 0.3, dtype=torch.float64),
93
+ torch.full((2,), 280.0e6, dtype=torch.float64),
94
+ law,
95
+ )
96
+ assert torch.isfinite(result["stress"]).all()
97
+ assert torch.all(result["peeq"][:, 1:] >= result["peeq"][:, :-1])
98
+ assert torch.max(torch.abs(result["plastic_strain"][..., :3].sum(-1))) < 1.0e-10
99
+ active = result["plastic_increment"] > 1.0e-12
100
+ assert torch.max(torch.abs(result["yield_residual"][active])) < 20.0
101
+ ledger = subject.discrete_energy_ledger(
102
+ result,
103
+ torch.full((2,), 280.0e6, dtype=torch.float64),
104
+ law,
105
+ )
106
+ scale = ledger["plastic_work"][active].abs().max()
107
+ assert ledger["reference_yield_dissipation"][active].min() >= 0.0
108
+ assert ledger["dynamic_recovery_dissipation"][active].min() >= 0.0
109
+ assert ledger["backward_euler_dissipation"][active].min() >= -1.0e-8 * scale
110
+ assert ledger["balance_residual"][active].abs().max() < 1.0e-8 * scale