|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +import numpy as np |
5 | 6 | import pandas as pd |
6 | 7 |
|
7 | 8 | from modelitool.simulate import OMModel, library_contents, load_library |
@@ -133,30 +134,37 @@ def test_get_parameters(self, simul): |
133 | 134 | assert param == expected_param |
134 | 135 |
|
135 | 136 | 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 | | - |
141 | 137 | 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"), |
145 | 141 | "tolerance": 1e-06, |
146 | 142 | "solver": "dassl", |
147 | | - "boundary": boundaries_seconds, |
| 143 | + "outputFormat": "csv", |
148 | 144 | } |
149 | 145 |
|
| 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 | + |
150 | 151 | simu = OMModel( |
151 | 152 | model_path="TestLib.boundary_test", |
152 | 153 | package_path=PACKAGE_DIR / "package.mo", |
153 | 154 | lmodel=["Modelica"], |
154 | 155 | boundary_table_name="Boundaries", |
155 | 156 | ) |
156 | 157 |
|
157 | | - res = simu.simulate(simulation_options=simulation_options) |
| 158 | + simulation_options_with_boundary = simulation_options.copy() |
| 159 | + simulation_options_with_boundary["boundary"] = x_options |
158 | 160 |
|
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, |
162 | 168 | ) |
| 169 | + |
| 170 | + assert all(x_options.index == res1.index) |
0 commit comments