Skip to content

Commit fd590d5

Browse files
committed
🐛✅real test for boundary conditions
1 parent 24ca0b5 commit fd590d5

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

tests/test_simulate.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import numpy as np
56
import pandas as pd
67

78
from modelitool.simulate import OMModel, library_contents, load_library
@@ -133,30 +134,37 @@ def test_get_parameters(self, simul):
133134
assert param == expected_param
134135

135136
def test_set_boundaries_df(self):
136-
boundaries_seconds = pd.DataFrame(
137-
{"x1": [10, 20, 30], "x2": [3, 4, 5]},
138-
index=[16675200, 16678800, 16682400],
139-
)
140-
141137
simulation_options = {
142-
"startTime": 16675200,
143-
"stopTime": 16682400,
144-
"stepSize": 3600,
138+
"startTime": pd.Timestamp("2009-07-13 00:00:00"),
139+
"stopTime": pd.Timestamp("2009-07-13 02:00:00"),
140+
"stepSize": pd.Timedelta("1h"),
145141
"tolerance": 1e-06,
146142
"solver": "dassl",
147-
"boundary": boundaries_seconds,
143+
"outputFormat": "csv",
148144
}
149145

146+
x_options = pd.DataFrame(
147+
{"Boundaries.y[1]": [10, 20, 30], "Boundaries.y[2]": [3, 4, 5]},
148+
index=pd.date_range("2009-07-13 00:00:00", periods=3, freq="h"),
149+
)
150+
150151
simu = OMModel(
151152
model_path="TestLib.boundary_test",
152153
package_path=PACKAGE_DIR / "package.mo",
153154
lmodel=["Modelica"],
154155
boundary_table_name="Boundaries",
155156
)
156157

157-
res = simu.simulate(simulation_options=simulation_options)
158+
simulation_options_with_boundary = simulation_options.copy()
159+
simulation_options_with_boundary["boundary"] = x_options
158160

159-
x_direct = pd.DataFrame(
160-
{"Boundaries.y[1]": [100, 200, 300], "Boundaries.y[2]": [30, 40, 50]},
161-
index=pd.date_range("2009-07-13 00:00:00", periods=3, freq="h"),
161+
res1 = simu.simulate(simulation_options=simulation_options_with_boundary)
162+
res1 = res1.loc[:, ["Boundaries.y[1]", "Boundaries.y[2]"]]
163+
164+
np.testing.assert_allclose(
165+
x_options.to_numpy(),
166+
res1.to_numpy(),
167+
rtol=1e-3,
162168
)
169+
170+
assert all(x_options.index == res1.index)

0 commit comments

Comments
 (0)