Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for ModelicaSystem.getContinuous()
It behaves differently before and after simulate()
  • Loading branch information
ondras12345 committed Apr 17, 2025
commit aab095787ae31c6dcdcd8936790f564c19f1f7d5
30 changes: 27 additions & 3 deletions tests/test_ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,41 @@ def test_getters(self):
},
]

assert mod.getInputs() == {}
assert mod.getOutputs() == {'y': '-0.4'}
assert mod.getOutputs("y") == ["-0.4"]

# getContinuous before simulate():
assert mod.getContinuous() == {
'x': '1.0',
'der(x)': None,
'y': '-0.4'
}
assert mod.getContinuous("y") == ['-0.4']
assert mod.getContinuous(["y", "x"]) == ['-0.4', '1.0']
assert mod.getContinuous("a") == ["NotExist"] # a is a parameter

stopTime=1.0
a = -0.5
b = 0.1
x0 = 1.0
mod.setSimulationOptions(f"stopTime={stopTime}")
mod.simulate()
# getContinuous after simulate() should return values at end of simulation:
with self.assertRaises(OMPython.ModelicaSystemError):
mod.getContinuous("a") # a is a parameter
with self.assertRaises(OMPython.ModelicaSystemError):
mod.getContinuous(["x", "a", "y"]) # a is a parameter
d = mod.getContinuous()
assert d.keys() == {"x", "der(x)", "y"}
x_analytical = -b/a + (x0 + b/a) * np.exp(a * stopTime)
dx_analytical = (x0 + b/a) * a * np.exp(a * stopTime)
assert np.isclose(d["x"], x_analytical, 1e-4)
assert np.isclose(d["der(x)"], dx_analytical, 1e-4)
assert np.isclose(d["y"], dx_analytical, 1e-4)
assert mod.getContinuous("x") == [d["x"]]
assert mod.getContinuous(["y", "x"]) == [d["y"], d["x"]]

assert mod.getInputs() == {}
assert mod.getOutputs() == {'y': '-0.4'}
assert mod.getOutputs("y") == ["-0.4"]

def test_simulate_inputs(self):
model_file = self.tmp / "M_input.mo"
Expand Down