AgentFEM-Material-Loading-Memory / tests /test_t2_physics_integrator.py
HaomingLuo's picture
Add multiaxial OOD v2 data, six neural models, and FE validation
f1564a0 verified
Raw History Blame Contribute Delete
1.53 kB
from __future__ import annotations
import torch
from src import train_t2_physics_integrator as subject
def parameters() -> torch.Tensor:
return torch.tensor(
[[190.0e9, 0.3, 280.0e6, 0.0, 35.0e9, 60.0, 8.0e9, 8.0, 70.0e6, 8.0]],
dtype=torch.float32,
)
def test_physics_integrator_preserves_hard_state_constraints() -> None:
strain = torch.zeros((1, 31, 6), dtype=torch.float32)
strain[0, :, 0] = torch.linspace(0.0, 0.007, 31)
strain[0, :, 1] = -0.5 * strain[0, :, 0]
strain[0, :, 2] = -0.5 * strain[0, :, 0]
model = subject.PlasticIncrementNet()
mean = torch.zeros(10)
std = torch.ones(10)
result = subject.rollout(strain, parameters(), model, mean, std)
assert torch.all(result["peeq"][:, 1:] >= result["peeq"][:, :-1])
assert float(result["plastic_strain"][..., :3].sum(dim=-1).abs().max().detach()) < 1.0e-6
assert torch.isfinite(result["stress"]).all()
def test_elastic_path_remains_elastic() -> None:
strain = torch.zeros((1, 11, 6), dtype=torch.float32)
strain[0, :, 0] = torch.linspace(0.0, 1.0e-5, 11)
model = subject.PlasticIncrementNet()
result = subject.rollout(strain, parameters(), model, torch.zeros(10), torch.ones(10))
assert torch.count_nonzero(result["plastic_increment"]) == 0
assert torch.count_nonzero(result["peeq"]) == 0
def test_neural_correction_is_bounded() -> None:
model = subject.PlasticIncrementNet()
values = model(torch.randn(50, 17))
assert float(values.abs().max()) <= 0.750001