From 7dc62d6b26fc181eac39e940783b7a7f4596a886 Mon Sep 17 00:00:00 2001 From: Mendez Date: Mon, 11 Nov 2024 16:05:25 +0100 Subject: [PATCH 1/4] Fix connections unit test --- tests/test_oscillator_fmu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_oscillator_fmu.py b/tests/test_oscillator_fmu.py index 68cb8b6..a15eec5 100644 --- a/tests/test_oscillator_fmu.py +++ b/tests/test_oscillator_fmu.py @@ -97,7 +97,7 @@ def _system_structure(): "osc": {"source": "HarmonicOscillator.fmu", "stepSize": 0.01}, "drv": {"source": "DrivingForce.fmu", "stepSize": 0.01}, }, - connections=((("drv", "f[2]", "osc", "f[2]"),)), + connections=("drv", "f[2]", "osc", "f[2]"), version="0.1", start=0.0, base_step=0.01, From f61dd9fb58e26125039209d82d84dacd61b2a9a1 Mon Sep 17 00:00:00 2001 From: Mendez Date: Mon, 11 Nov 2024 16:11:08 +0100 Subject: [PATCH 2/4] Fix test to avoid checking for variable references --- tests/test_oscillator_fmu.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/test_oscillator_fmu.py b/tests/test_oscillator_fmu.py index a15eec5..a56e008 100644 --- a/tests/test_oscillator_fmu.py +++ b/tests/test_oscillator_fmu.py @@ -243,24 +243,17 @@ def test_run_osp_system_structure(system_structure, show): } } ) - assert variables["c"] == { - "reference": 1, - "type": 0, - "causality": 1, - "variability": 1, - } - assert variables["x[2]"] == { - "reference": 5, - "type": 0, - "causality": 2, - "variability": 4, - } - assert variables["v[2]"] == { - "reference": 8, - "type": 0, - "causality": 2, - "variability": 4, - } + assert variables["c"]["type"] == 0 + assert variables["c"]["causality"] == 1 + assert variables["c"]["variability"] == 1 + + assert variables["x[2]"]["type"] == 0 + assert variables["x[2]"]["causality"] == 2 + assert variables["x[2]"]["variability"] == 4 + + assert variables["v[2]"]["type"] == 0 + assert variables["v[2]"]["causality"] == 2 + assert variables["v[2]"]["variability"] == 4 # Instantiate a suitable manipulator for changing variables. manipulator = CosimManipulator.create_override() From ea1ebc26c70b93c602552e51a3cc7601dfb55fd7 Mon Sep 17 00:00:00 2001 From: Mendez Date: Mon, 11 Nov 2024 16:20:03 +0100 Subject: [PATCH 3/4] Check slave variables for both models in unit test --- tests/test_oscillator_fmu.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_oscillator_fmu.py b/tests/test_oscillator_fmu.py index a56e008..e4f8d44 100644 --- a/tests/test_oscillator_fmu.py +++ b/tests/test_oscillator_fmu.py @@ -243,6 +243,19 @@ def test_run_osp_system_structure(system_structure, show): } } ) + + for idx in range(simulator.num_slave_variables(1)): + struct = simulator.slave_variables(1)[idx] + variables.update( + { + struct.name.decode(): { + "reference": struct.reference, + "type": struct.type, + "causality": struct.causality, + "variability": struct.variability, + } + } + ) assert variables["c"]["type"] == 0 assert variables["c"]["causality"] == 1 assert variables["c"]["variability"] == 1 From dd3b3a8296e8d67cd0a2845da9010ffc57236aae Mon Sep 17 00:00:00 2001 From: Mendez Date: Mon, 11 Nov 2024 16:26:03 +0100 Subject: [PATCH 4/4] Remove harcoded slave indexes --- tests/test_oscillator_fmu.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_oscillator_fmu.py b/tests/test_oscillator_fmu.py index e4f8d44..f217dae 100644 --- a/tests/test_oscillator_fmu.py +++ b/tests/test_oscillator_fmu.py @@ -268,26 +268,26 @@ def test_run_osp_system_structure(system_structure, show): assert variables["v[2]"]["causality"] == 2 assert variables["v[2]"]["variability"] == 4 - # Instantiate a suitable manipulator for changing variables. - manipulator = CosimManipulator.create_override() - simulator.add_manipulator(manipulator=manipulator) - simulator.real_initial_value(0, 1, 0.5) - simulator.real_initial_value(0, 5, 1.0) # Instantiate a suitable observer for collecting results. - observer = CosimObserver.create_last_value() - simulator.add_observer(observer=observer) - times = [] - pos = [] - speed = [] - for step in range(1, 1000): - time = step * 0.01 - simulator.simulate_until(step * 1e8) - values = observer.last_real_values(0, [5, 8]) - # print(f"Time {simulator.status().current_time*1e-9}: {values}") - times.append(time) - pos.append(values[0]) - speed.append(values[1]) if show: + # Instantiate a suitable manipulator for changing variables. + manipulator = CosimManipulator.create_override() + simulator.add_manipulator(manipulator=manipulator) + simulator.real_initial_value(0, 1, 0.5) + simulator.real_initial_value(0, 5, 1.0) + observer = CosimObserver.create_last_value() + simulator.add_observer(observer=observer) + times = [] + pos = [] + speed = [] + for step in range(1, 1000): + time = step * 0.01 + simulator.simulate_until(step * 1e8) + values = observer.last_real_values(0, [5, 8]) + # print(f"Time {simulator.status().current_time*1e-9}: {values}") + times.append(time) + pos.append(values[0]) + speed.append(values[1]) do_show(times, pos, speed)