Download code/test_t4_structural_dynamics.py from HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing: direct link, hf CLI and curl.
- Browser
- Download file 3.24 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/resolve/main/code/test_t4_structural_dynamics.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/code/test_t4_structural_dynamics.py
-
curl -L -o test_t4_structural_dynamics.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/resolve/main/code/test_t4_structural_dynamics.py
3.24 kB
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| from src.t4_structural_dynamics import analytical_first_frequency, load_config | |
| from src.load_t4_structural_dynamics import load_trajectory, trajectory_ids | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA = ROOT / "data" / "t4_structural_dynamics_pilot" | |
| def test_t4_analytical_frequency_is_reproducible(): | |
| config = load_config() | |
| assert np.isclose(analytical_first_frequency(config), 41.126088262057024) | |
| assert config["software"]["agentfem_commit"].startswith("882de08") | |
| def test_t4_quality_gates_pass(): | |
| quality = json.loads((DATA / "quality.json").read_text(encoding="utf-8")) | |
| assert quality["passed"] is True | |
| assert all(quality["gates"].values()) | |
| assert quality["trajectory_count"] == 4 | |
| assert quality["finest_first_frequency_relative_error"] < 0.01 | |
| assert quality["last_modal_mesh_relative_change"] < 0.002 | |
| assert quality["time_refinement_tip_history_relative_l2"] < 0.03 | |
| assert quality["maximum_energy_balance_relative_residual"] < 0.02 | |
| def test_t4_pilot_schema_fields_and_sensor_histories_are_finite(): | |
| with h5py.File(DATA / "pilot.h5", "r") as h5: | |
| assert h5.attrs["schema"] == "agentfem.physics-data.structural-dynamics-pilot" | |
| assert h5.attrs["schema_version"] == "0.1.0" | |
| assert int(h5.attrs["trajectory_count"]) == 4 | |
| assert h5["common/reference_geometry_m"].shape == (245, 3) | |
| assert h5["common/topology"].shape == (48, 9) | |
| assert h5["common/sensor_coordinates_m"].shape == (5, 2) | |
| assert set(h5["trajectories"]) == { | |
| "half_sine_pulse", | |
| "sub_resonant_sine", | |
| "near_resonant_sine", | |
| "chirp", | |
| } | |
| for group in h5["trajectories"].values(): | |
| assert group["time_s"].shape == (2001,) | |
| assert group["sensor_displacement_m"].shape == (2001, 5) | |
| assert group["fields/time_s"].shape == (201,) | |
| assert group["fields/displacement_m"].shape == (201, 245, 3) | |
| assert group["fields/velocity_m_per_s"].shape == (201, 245, 3) | |
| assert group["fields/acceleration_m_per_s2"].shape == (201, 245, 3) | |
| assert float(group.attrs["energy_balance_reference_j_per_m"]) > 0.0 | |
| for dataset in ( | |
| "force_scale", | |
| "sensor_displacement_m", | |
| "strain_energy_j_per_m", | |
| "kinetic_energy_j_per_m", | |
| "external_work_j_per_m", | |
| "damping_dissipation_j_per_m", | |
| "energy_balance_relative_residual", | |
| "fields/displacement_m", | |
| "fields/velocity_m_per_s", | |
| "fields/acceleration_m_per_s2", | |
| ): | |
| assert np.all(np.isfinite(group[dataset][...])) | |
| def test_t4_lightweight_reader_loads_one_complete_trajectory(): | |
| ids = trajectory_ids() | |
| assert ids == ( | |
| "chirp", | |
| "half_sine_pulse", | |
| "near_resonant_sine", | |
| "sub_resonant_sine", | |
| ) | |
| sample = load_trajectory("chirp") | |
| assert sample["arrays"]["sensor_displacement_m"].shape == (2001, 5) | |
| assert sample["arrays"]["displacement_m"].shape == (201, 245, 3) | |