Skip to content

Commit 630e70f

Browse files
authored
adapt fmi-3.0 tests to new oms3 (#1510)
1 parent 478478a commit 630e70f

19 files changed

Lines changed: 363 additions & 291 deletions

File tree

src/OMSimulatorLib/ComponentFMU3CS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ oms_status_enu_t oms::ComponentFMU3CS::instantiate()
661661
double relativeTolerance = 0.0;
662662
dynamic_cast<SystemWC*>(getParentSystem())->getTolerance(&relativeTolerance);
663663

664-
fmi3Status status_ = fmi3_enterInitializationMode(fmu, fmi3False, relativeTolerance, time, fmi3True, getModel().getStopTime());
664+
fmi3Status status_ = fmi3_enterInitializationMode(fmu, fmi3False, relativeTolerance, time, fmi3False, getModel().getStopTime());
665665

666666
if (fmi3OK != status_) return logError_FMUCall("fmi3_enterInitializationMode", this);
667667

src/OMSimulatorPython/fmu.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ def _load_model_description(self):
123123
# Parse UnitDefinitions
124124
self._parse_units(model_description)
125125

126-
# Parse variables
127-
self._parse_variables(model_description)
128-
126+
# Dispatch version-specific handling
127+
if self._fmiVersion == "2.0":
128+
self._parse_variables_fmi2(model_description)
129+
elif self._fmiVersion == "3.0":
130+
## TODO: implement FMI 3.0 variable parsing
131+
pass
129132
except ET.XMLSyntaxError as e:
130133
raise ValueError(f'Error parsing {model_desc_name}: {e}')
131134

@@ -144,7 +147,7 @@ def _get(attr, default):
144147
'stepSize': _get('stepSize', 1e-3),
145148
}
146149

147-
def _parse_variables(self, model_description):
150+
def _parse_variables_fmi2(self, model_description):
148151
'''Parses variables from the ModelVariables section of modelDescription.xml'''
149152
scalar_variables = model_description.xpath('//ModelVariables/ScalarVariable')
150153
for scalar_var in scalar_variables:

testsuite/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
all: difftool resources test
44

5-
test: api.log parker.log dcmotor.log simulation.log
5+
test: api.log parker.log AircraftVehicleDemonstrator.log dcmotor.log simulation.log reference-fmus.log reference-fmus3.log
66

77
partest: difftool resources
88
cd partest && time ./runtests.pl -nocolour -with-xml

testsuite/reference-fmus/3.0/BouncingBall.lua

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
3+
## status: correct
4+
## teardown_command: rm -rf BouncingBall-cs.mat BouncingBall-me.mat
5+
## linux: yes
6+
## ucrt64: yes
7+
## win: yes
8+
## asan: no
9+
10+
from OMSimulator import SSP, CRef, Settings, Capi
11+
Settings.suppressPath = True
12+
13+
model = SSP()
14+
model.addResource('../../resources/BouncingBall3.fmu', new_name='resources/BouncingBall3.fmu')
15+
model.addComponent(CRef('default', 'BouncingBall'), 'resources/BouncingBall3.fmu')
16+
17+
instantiated_model = model.instantiate()
18+
instantiated_model.setResultFile("BouncingBall-cs.mat")
19+
20+
instantiated_model.setStopTime(3.0)
21+
instantiated_model.setTolerance(1e-5)
22+
23+
instantiated_model.initialize()
24+
instantiated_model.simulate()
25+
26+
instantiated_model.terminate()
27+
instantiated_model.delete()
28+
29+
30+
if 1 == Capi.compareSimulationResults("../../references/BouncingBall-cs.mat", "BouncingBall-cs.mat", "model.root.BouncingBall.h", "default.BouncingBall.h", 1e-4, 1e-4):
31+
print("signal h is equal", flush=True)
32+
else:
33+
print("signal h is not equal", flush=True)
34+
35+
if 1 == Capi.compareSimulationResults("../../references/BouncingBall-cs.mat", "BouncingBall-cs.mat", "model.root.BouncingBall.v", "default.BouncingBall.v", 1e-4, 1e-4):
36+
print("signal v is equal", flush=True)
37+
else:
38+
print("signal v is not equal", flush=True)
39+
40+
41+
## Result:
42+
## Loading FMI version 3...
43+
## info: Result file: BouncingBall-cs.mat (bufferSize=1)
44+
## signal h is equal
45+
## signal v is equal
46+
## endResult

testsuite/reference-fmus/3.0/Dahlquist.lua

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## status: correct
2+
## teardown_command: rm -rf Dahlquist-cs.mat Dahlquist-me.mat
3+
## linux: yes
4+
## ucrt64: yes
5+
## win: yes
6+
## asan: no
7+
8+
from OMSimulator import SSP, CRef, Settings, Capi
9+
Settings.suppressPath = True
10+
11+
model = SSP()
12+
model.addResource('../../resources/Dahlquist3.fmu', new_name='resources/Dahlquist3.fmu')
13+
14+
model.addComponent(CRef('default', 'Dahlquist'), 'resources/Dahlquist3.fmu')
15+
16+
instantiated_model = model.instantiate()
17+
instantiated_model.setResultFile("Dahlquist-cs.mat")
18+
19+
instantiated_model.setStopTime(10.0)
20+
instantiated_model.setTolerance(1e-5)
21+
22+
instantiated_model.initialize()
23+
instantiated_model.simulate()
24+
25+
instantiated_model.terminate()
26+
instantiated_model.delete()
27+
28+
29+
if 1 == Capi.compareSimulationResults("../../references/Dahlquist-cs.mat", "Dahlquist-cs.mat", "model.root.Dahlquist.x", "default.Dahlquist.x", 1e-4, 1e-4):
30+
print("signal x is equal", flush=True)
31+
else:
32+
print("signal x is not equal", flush=True)
33+
34+
## Result:
35+
## Loading FMI version 3...
36+
## info: Result file: Dahlquist-cs.mat (bufferSize=1)
37+
## signal x is equal
38+
## endResult

testsuite/reference-fmus/3.0/Feedthrough.lua

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## status: correct
2+
## teardown_command:
3+
## linux: yes
4+
## ucrt64: yes
5+
## win: yes
6+
## asan: no
7+
8+
9+
from OMSimulator import SSP, CRef, Settings
10+
Settings.suppressPath = True
11+
12+
model = SSP()
13+
model.addResource('../../resources/Feedthrough3.fmu', new_name='resources/Feedthrough3.fmu')
14+
15+
model.addComponent(CRef('default', 'Feedthrough'), 'resources/Feedthrough3.fmu')
16+
17+
instantiated_model = model.instantiate()
18+
instantiated_model.setResultFile("")
19+
instantiated_model.setStopTime(10.0)
20+
instantiated_model.setTolerance(1e-5)
21+
22+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Float32_continuous_input'), 3.1)
23+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Float64_continuous_input'), 3.3)
24+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Int8_input'), 4)
25+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Int16_input'), 5)
26+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Int32_input'), 6)
27+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Int64_input'), 7)
28+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'UInt8_input'), 8)
29+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'UInt16_input'), 9)
30+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'UInt32_input'), 10)
31+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'UInt64_input'), 11)
32+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Boolean_input'), True)
33+
instantiated_model.setValue(CRef('default', 'Feedthrough', 'Enumeration_input'), 2)
34+
35+
## need to implement fmi3causality table in fmi4c library if inital attribute is not present
36+
## instantiated_model.setValue(CRef('default', 'Feedthrough', 'String_parameter'), "Set me!")
37+
38+
instantiated_model.initialize()
39+
instantiated_model.simulate()
40+
41+
# --- Print all outputs and values that were set ---
42+
print(f"info: Feedthrough.Float32_continuous_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Float32_continuous_input'))}", flush=True)
43+
print(f"info: Feedthrough.Float64_continuous_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Float64_continuous_input'))}", flush=True)
44+
print(f"info: Feedthrough.Int8_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Int8_input'))}", flush=True)
45+
print(f"info: Feedthrough.Int16_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Int16_input'))}", flush=True)
46+
print(f"info: Feedthrough.Int32_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Int32_input'))}", flush=True)
47+
print(f"info: Feedthrough.Int64_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Int64_input'))}", flush=True)
48+
print(f"info: Feedthrough.UInt8_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'UInt8_input'))}", flush=True)
49+
print(f"info: Feedthrough.UInt16_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'UInt16_input'))}", flush=True)
50+
print(f"info: Feedthrough.UInt32_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'UInt32_input'))}", flush=True)
51+
print(f"info: Feedthrough.UInt64_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'UInt64_input'))}", flush=True)
52+
print(f"info: Feedthrough.Boolean_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Boolean_input'))}", flush=True)
53+
print(f"info: Feedthrough.Enumeration_input: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'Enumeration_input'))}", flush=True)
54+
print(f"info: Feedthrough.String_parameter: {instantiated_model.getValue(CRef('default', 'Feedthrough', 'String_parameter'))}", flush=True)
55+
56+
instantiated_model.terminate()
57+
instantiated_model.delete()
58+
59+
60+
## Result:
61+
## warning: Unknown FMI3 base type for var : Binary_input
62+
## warning: Unknown FMI3 base type for var : Binary_output
63+
## Loading FMI version 3...
64+
## info: No result file will be created
65+
## info: Feedthrough.Float32_continuous_input: 3.0999999046325684
66+
## info: Feedthrough.Float64_continuous_input: 3.3
67+
## info: Feedthrough.Int8_input: 4
68+
## info: Feedthrough.Int16_input: 5
69+
## info: Feedthrough.Int32_input: 6
70+
## info: Feedthrough.Int64_input: 7
71+
## info: Feedthrough.UInt8_input: 8
72+
## info: Feedthrough.UInt16_input: 9
73+
## info: Feedthrough.UInt32_input: 10
74+
## info: Feedthrough.UInt64_input: 11
75+
## info: Feedthrough.Boolean_input: True
76+
## info: Feedthrough.Enumeration_input: 2
77+
## info: Feedthrough.String_parameter: Set me!
78+
## info: 2 warnings
79+
## info: 0 errors
80+
## endResult

0 commit comments

Comments
 (0)