Download tests/test_t2_material_loading_memory.py from HaomingLuo/AgentFEM-Material-Loading-Memory: direct link, hf CLI and curl.
- Browser
- Download file 4.34 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/tests/test_t2_material_loading_memory.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/tests/test_t2_material_loading_memory.py
-
curl -L -o test_t2_material_loading_memory.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/tests/test_t2_material_loading_memory.py
4.34 kB
| import json | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| from src.t2_material_loading_memory import ( | |
| DATA_PATH, | |
| MATERIAL_MODELS, | |
| PATH_FAMILIES, | |
| _j2_monotonic_reference, | |
| case_identity, | |
| design_parameters, | |
| prescribed_history, | |
| solve_trajectory, | |
| split_assignments, | |
| ) | |
| def test_t2_design_is_unique_balanced_and_split_by_trajectory(): | |
| rows = design_parameters() | |
| split = split_assignments(rows) | |
| assert len(rows) == 96 | |
| assert len({case_identity(row) for row in rows}) == 96 | |
| assert sum(value == "train" for value in split.values()) == 72 | |
| assert sum(value == "validation" for value in split.values()) == 12 | |
| assert sum(value == "test" for value in split.values()) == 12 | |
| for model in MATERIAL_MODELS: | |
| assert sum(row["material_model"] == model for row in rows) == 48 | |
| for family in PATH_FAMILIES: | |
| indices = [ | |
| index | |
| for index, row in enumerate(rows) | |
| if row["material_model"] == model | |
| and row["path_family"] == family | |
| ] | |
| assert len(indices) == 8 | |
| assert sum(split[index] == "train" for index in indices) == 6 | |
| assert sum(split[index] == "validation" for index in indices) == 1 | |
| assert sum(split[index] == "test" for index in indices) == 1 | |
| def test_t2_prescribed_histories_have_fixed_size_and_required_reversals(): | |
| for row in design_parameters(): | |
| time, strain, anchors = prescribed_history(row) | |
| assert len(time) == len(strain) == 121 | |
| assert np.all(np.diff(time) > 0.0) | |
| assert strain[0] == 0.0 | |
| assert np.max(np.abs(strain)) <= 1.15 * row["maximum_equivalent_strain"] | |
| for anchor in anchors: | |
| assert np.any(np.isclose(strain, anchor, rtol=0.0, atol=1.0e-15)) | |
| if row["path_family"] not in ("monotonic_tension", "unload_reload"): | |
| assert np.min(anchors) < 0.0 < np.max(anchors) | |
| def test_t2_refined_paths_are_nested_at_every_coarse_state(): | |
| for row in design_parameters(): | |
| _, coarse, _ = prescribed_history(row, points=121) | |
| _, fine, _ = prescribed_history(row, points=241) | |
| np.testing.assert_allclose(coarse, fine[::2], rtol=0.0, atol=1.0e-15) | |
| def test_t2_agentfem_material_point_smoke_paths_are_physical(): | |
| rows = design_parameters() | |
| for model in MATERIAL_MODELS: | |
| for family in PATH_FAMILIES: | |
| row = next( | |
| item | |
| for item in rows | |
| if item["material_model"] == model | |
| and item["path_family"] == family | |
| ) | |
| arrays, metrics = solve_trajectory(row, points=41) | |
| assert metrics["all_finite"] | |
| assert metrics["plastic_step_count"] > 0 | |
| assert metrics["maximum_plastic_strain_trace"] < 1.0e-10 | |
| assert metrics["minimum_peeq_increment"] >= -1.0e-12 | |
| assert metrics["maximum_yield_surface_relative_residual"] < 1.0e-8 | |
| assert arrays["signed_equivalent_stress_pa"][0] == 0.0 | |
| if family == "symmetric_cyclic": | |
| assert metrics["zero_strain_stress_range_pa"] > 1.0e6 | |
| def test_t2_j2_monotonic_path_matches_closed_form(): | |
| row = next( | |
| item | |
| for item in design_parameters() | |
| if item["material_model"] == "j2_linear_isotropic" | |
| and item["path_family"] == "monotonic_tension" | |
| ) | |
| arrays, _ = solve_trajectory(row, points=41) | |
| stress, peeq = _j2_monotonic_reference(row) | |
| np.testing.assert_allclose( | |
| arrays["signed_equivalent_stress_pa"][-1], stress, rtol=1.0e-11 | |
| ) | |
| np.testing.assert_allclose( | |
| arrays["equivalent_plastic_strain"][-1], peeq, rtol=1.0e-11 | |
| ) | |
| def test_t2_packaged_pilot_is_readable_when_present(): | |
| if not DATA_PATH.exists(): | |
| return | |
| quality_path = DATA_PATH.parents[2] / "artifacts" / DATA_PATH.parent.name / "quality.json" | |
| quality = json.loads(quality_path.read_text(encoding="utf-8")) | |
| assert quality["status"] == "accepted" | |
| with h5py.File(DATA_PATH, "r") as h5: | |
| assert len(h5) == 96 | |
| for group in h5.values(): | |
| assert group["stress_pa"].shape == (121, 3, 3) | |
| assert np.isfinite(group["stress_pa"][:]).all() | |
| assert np.isfinite(group["equivalent_plastic_strain"][:]).all() | |