File size: 1,527 Bytes
f1564a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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