Skip to content

Commit 2e33f33

Browse files
committed
[test_ModelicaSystemDoE] update test
1 parent 69c0f6d commit 2e33f33

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

tests/test_ModelicaSystemDoE.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import OMPython
23
import pandas as pd
34
import pathlib
@@ -37,7 +38,6 @@ def param_doe() -> dict[str, list]:
3738

3839

3940
def test_ModelicaSystemDoE(tmp_path, model_doe, param_doe):
40-
4141
tmpdir = tmp_path / 'DoE'
4242
tmpdir.mkdir(exist_ok=True)
4343

@@ -46,13 +46,32 @@ def test_ModelicaSystemDoE(tmp_path, model_doe, param_doe):
4646
modelName="M",
4747
parameters=param_doe,
4848
resultpath=tmpdir,
49+
simargs={"override": {'stopTime': 1.0}},
4950
)
5051
mod_doe.prepare()
5152
df_doe = mod_doe.get_doe()
5253
assert isinstance(df_doe, pd.DataFrame)
5354
assert df_doe.shape[0] == 16
54-
assert df_doe['results available'].sum() == 16
55+
assert df_doe['results available'].sum() == 0
5556

5657
mod_doe.simulate()
57-
sol = mod_doe.get_solutions(var_list=['x[1]', 'y[1]'])
58-
assert len(sol) == 16
58+
assert df_doe['results available'].sum() == 16
59+
60+
for row in df_doe.to_dict('records'):
61+
resultfilename = row[mod_doe.DF_COLUMNS_RESULTFILENAME]
62+
resultfile = mod_doe._resultpath / resultfilename
63+
64+
var_dict = {
65+
# simple / non-structural parameters
66+
'a': float(row['a']),
67+
'b': float(row['b']),
68+
# structural parameters
69+
'p': float(row['p']),
70+
'q': float(row['q']),
71+
# variables using the structural parameters
72+
f"x[{row['p']}]": float(row['a']),
73+
f"y[{row['p']}]": float(row['b']),
74+
}
75+
sol = mod_doe._mod.getSolutions(resultfile=resultfile.as_posix(), varList=list(var_dict.keys()))
76+
77+
assert np.isclose(sol[:, -1], np.array(list(var_dict.values()))).all()

0 commit comments

Comments
 (0)