Skip to content

Commit

Permalink
Merge branch 'main' into eis
Browse files Browse the repository at this point in the history
  • Loading branch information
eisDNV authored Nov 12, 2024
2 parents 6c3d710 + 7539966 commit 203bea0
Showing 1 changed file with 44 additions and 38 deletions.
82 changes: 44 additions & 38 deletions tests/test_oscillator_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -243,45 +243,51 @@ 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,
}

# 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)

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

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 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)


Expand Down

0 comments on commit 203bea0

Please sign in to comment.