Skip to content

Commit 85ffb50

Browse files
committed
FMUF2P: Add test
1 parent a480598 commit 85ffb50

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/test_f2p.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python
2+
3+
import openturns as ot
4+
import openturns.testing as ott
5+
import otfmi
6+
import otfmi.example.utility
7+
import pytest
8+
9+
10+
@pytest.fixture
11+
def path_fmu():
12+
"""Load FMU and setup pure python reference."""
13+
return otfmi.example.utility.get_path_fmu("epid")
14+
15+
16+
@pytest.fixture
17+
def mesh():
18+
return ot.RegularGrid(2.0, 0.5, 50)
19+
20+
21+
def test_default_mesh(path_fmu):
22+
f = otfmi.FMUFieldToPointFunction(path_fmu,
23+
inputs_fmu=["infection_rate", "healing_rate"],
24+
outputs_fmu=["infected"])
25+
mesh = f.getInputMesh()
26+
start_time = mesh.getVertices().getMin()[0]
27+
end_time = mesh.getVertices().getMax()[0]
28+
ott.assert_almost_equal(start_time, 0.0)
29+
ott.assert_almost_equal(end_time, 200.0)
30+
31+
32+
def test_start_time_coherence(path_fmu, mesh):
33+
"""Check if incoherent start time raises an error"""
34+
with pytest.raises(ValueError):
35+
_ = otfmi.FMUFieldToPointFunction(path_fmu, mesh,
36+
inputs_fmu=["infection_rate", "healing_rate"],
37+
outputs_fmu=["infected"],
38+
start_time=10)
39+
40+
41+
def test_start_time(path_fmu, mesh):
42+
"""Check if start times are taken into account."""
43+
model_fmu_1 = otfmi.FMUFieldToPointFunction(
44+
path_fmu,
45+
mesh,
46+
inputs_fmu=["infection_rate", "healing_rate"],
47+
outputs_fmu=["infected"],
48+
start_time=0,
49+
)
50+
model_fmu_2 = otfmi.FMUFieldToPointFunction(
51+
path_fmu,
52+
mesh,
53+
inputs_fmu=["infection_rate", "healing_rate"],
54+
outputs_fmu=["infected"],
55+
start_time=1,
56+
)
57+
n = mesh.getVerticesNumber()
58+
input_value = [[0.007, 0.02]] * n
59+
y1 = model_fmu_1(input_value)
60+
y2 = model_fmu_2(input_value)
61+
assert y2[0] - y1[0] != 0.0
62+
63+
64+
def test_final_time_coherence(path_fmu, mesh):
65+
"""Check if incoherent final time raises an error."""
66+
with pytest.raises(ValueError):
67+
_ = otfmi.FMUFieldToPointFunction(path_fmu, mesh,
68+
inputs_fmu=["infection_rate", "healing_rate"],
69+
outputs_fmu=["infected"],
70+
final_time=10)

0 commit comments

Comments
 (0)