Skip to content

Commit ac4f8bb

Browse files
authored
add CompositeModels tests (#1511)
1 parent 630e70f commit ac4f8bb

4 files changed

Lines changed: 181 additions & 1 deletion

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## status: correct
2+
## teardown_command:
3+
## linux: yes
4+
## ucrt64: yes
5+
## win: yes
6+
## mac: yes
7+
8+
9+
from poplib import CR
10+
from OMSimulator import SSP, CRef, Settings
11+
12+
Settings.suppressPath = True
13+
14+
# this example creates a composite model with FMI3 FMU and connects them together.
15+
# It then simulates the model and prints the results.
16+
17+
model = SSP()
18+
model.addResource("../resources/Feedthrough3.fmu", new_name="resources/Feedthrough3.fmu")
19+
model.addComponent(CRef("default", "Feedthrough1"), "resources/Feedthrough3.fmu")
20+
model.addComponent(CRef("default", "Feedthrough2"), "resources/Feedthrough3.fmu")
21+
22+
23+
## connections
24+
model.addConnection(CRef("default", "Feedthrough1", "Float64_continuous_output"), CRef("default", "Feedthrough2", "Float64_continuous_input"))
25+
model.addConnection(CRef("default", "Feedthrough1", "Int64_output"), CRef("default", "Feedthrough2", "Int64_input"))
26+
27+
instantiated_model = model.instantiate() ## internally generate the json file and also set the model state like virgin,
28+
instantiated_model.setResultFile("")
29+
instantiated_model.setStopTime(10.0)
30+
instantiated_model.setTolerance(1e-5)
31+
32+
instantiated_model.setValue(CRef("default", "Feedthrough1", "Float64_continuous_input"), 3.5)
33+
instantiated_model.setValue(CRef("default", "Feedthrough1", "Int64_input"), 7)
34+
35+
instantiated_model.initialize()
36+
instantiated_model.simulate()
37+
print(f"info: Feedthrough1.Float64_continuous_input : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_input'))}")
38+
print(f"info: Feedthrough1.Float64_continuous_output : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_output'))}")
39+
print(f"info: Feedthrough2.Float64_continuous_input : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Float64_continuous_input'))}")
40+
print(f"info: Feedthrough2.Float64_continuous_output : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Float64_continuous_output'))}")
41+
print(f"info: Feedthrough1.Int64_input : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Int64_input'))}")
42+
print(f"info: Feedthrough1.Int64_output : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Int64_output'))}")
43+
print(f"info: Feedthrough2.Int64_input : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Int64_input'))}")
44+
print(f"info: Feedthrough2.Int64_output : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Int64_output'))}")
45+
46+
instantiated_model.terminate()
47+
instantiated_model.delete()
48+
49+
## Result:
50+
## warning: Unknown FMI3 base type for var : Binary_input
51+
## warning: Unknown FMI3 base type for var : Binary_output
52+
## warning: Unknown FMI3 base type for var : Binary_input
53+
## warning: Unknown FMI3 base type for var : Binary_output
54+
## Loading FMI version 3...
55+
## Loading FMI version 3...
56+
## info: No result file will be created
57+
## info: Feedthrough1.Float64_continuous_input : 3.5
58+
## info: Feedthrough1.Float64_continuous_output : 3.5
59+
## info: Feedthrough2.Float64_continuous_input : 3.5
60+
## info: Feedthrough2.Float64_continuous_output : 3.5
61+
## info: Feedthrough1.Int64_input : 7
62+
## info: Feedthrough1.Int64_output : 7
63+
## info: Feedthrough2.Int64_input : 7
64+
## info: Feedthrough2.Int64_output : 7
65+
## info: 4 warnings
66+
## info: 0 errors
67+
## endResult

testsuite/CompositeModels/Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
TEST = ../../rtest -v
2+
3+
TESTFILES = \
4+
connectFmi2AndFmi3.py \
5+
FeedthroughConnections.py \
6+
7+
# Run make failingtest
8+
FAILINGTESTFILES = \
9+
10+
# Dependency files that are not .lua or Makefile
11+
# Add them here or they will be cleaned.
12+
DEPENDENCIES = \
13+
*.py \
14+
Makefile \
15+
16+
CLEAN = `ls | grep -w -v -f deps.tmp`
17+
18+
.PHONY : test clean getdeps failingtest
19+
20+
test:
21+
@echo
22+
@echo Running tests...
23+
@$(TEST) $(TESTFILES)
24+
25+
baseline:
26+
@echo
27+
@echo Updating baselines...
28+
@$(TEST) -b $(TESTFILES)
29+
30+
# Cleans all files that are not listed as dependencies
31+
clean:
32+
@echo $(DEPENDENCIES) | sed 's/ /\\\|/g' > deps.tmp
33+
@rm -rf $(CLEAN)
34+
35+
# Run this if you want to list out the files (dependencies).
36+
# do it after cleaning and updating the folder
37+
# then you can get a list of file names (which must be dependencies
38+
# since you got them from repository + your own new files)
39+
# then add them to the DEPENDENCIES. You can find the
40+
# list in deps.txt
41+
getdeps:
42+
@echo $(DEPENDENCIES) | sed 's/ /\\\|/g' > deps.tmp
43+
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
44+
@echo Dependency list saved in deps.txt.
45+
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES
46+
47+
failingtest:
48+
@echo
49+
@echo Running failing tests...
50+
@echo
51+
@$(TEST) $(FAILINGTESTFILES)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## status: correct
2+
## teardown_command:
3+
## linux: yes
4+
## ucrt64: yes
5+
## win: yes
6+
## mac: yes
7+
8+
9+
from OMSimulator import SSP, CRef, Settings
10+
11+
Settings.suppressPath = True
12+
13+
# this example creates a composite model with an FMI2 and an FMI3 FMU and connects them together.
14+
# It then simulates the model and prints the results.
15+
16+
model = SSP()
17+
18+
## FMI2.0
19+
model.addResource("../resources/Modelica.Blocks.Math.Gain.fmu", new_name="resources/Gain.fmu")
20+
model.addComponent(CRef("default", "Gain1"), "resources/Gain.fmu")
21+
22+
## FMI3.0
23+
model.addResource("../resources/Feedthrough3.fmu", new_name="resources/Feedthrough3.fmu")
24+
model.addComponent(CRef("default", "Feedthrough1"), "resources/Feedthrough3.fmu")
25+
26+
## connections (Gain.y (FMI2) --> Feedthrough.Float64_continuous_input (FMI3))
27+
model.addConnection(CRef("default", "Gain1", "y"), CRef("default", "Feedthrough1", "Float64_continuous_input"))
28+
29+
instantiated_model = model.instantiate() ## internally generate the json file and also set the model state like virgin,
30+
instantiated_model.setResultFile("")
31+
instantiated_model.setStopTime(10.0)
32+
instantiated_model.setTolerance(1e-5)
33+
34+
instantiated_model.setValue(CRef("default", "Gain1", "u"), 15)
35+
instantiated_model.initialize()
36+
instantiated_model.simulate()
37+
38+
print(f"info: default.Gain1.u : {instantiated_model.getValue(CRef('default', 'Gain1', 'u'))}")
39+
print(f"info: default.Gain1.y : {instantiated_model.getValue(CRef('default', 'Gain1', 'y'))}")
40+
print(f"info: default.Feedthrough1.Float64_continuous_input : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_input'))}")
41+
print(f"info: default.Feedthrough1.Float64_continuous_output : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_output'))}")
42+
43+
instantiated_model.terminate()
44+
instantiated_model.delete()
45+
46+
47+
## Result:
48+
## warning: Unknown FMI3 base type for var : Binary_input
49+
## warning: Unknown FMI3 base type for var : Binary_output
50+
## Loading FMI version 3...
51+
## info: No result file will be created
52+
## info: default.Gain1.u : 15.0
53+
## info: default.Gain1.y : 15.0
54+
## info: default.Feedthrough1.Float64_continuous_input : 15.0
55+
## info: default.Feedthrough1.Float64_continuous_output : 15.0
56+
## info: 2 warnings
57+
## info: 0 errors
58+
## endResult

testsuite/Makefile

Lines changed: 5 additions & 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 AircraftVehicleDemonstrator.log dcmotor.log simulation.log reference-fmus.log reference-fmus3.log
5+
test: api.log parker.log AircraftVehicleDemonstrator.log CompositeModels.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
@@ -21,6 +21,10 @@ AircraftVehicleDemonstrator.log: difftool
2121
@$(MAKE) -C AircraftVehicleDemonstrator -f Makefile test > $@
2222
@grep == AircraftVehicleDemonstrator.log
2323

24+
CompositeModels.log: difftool
25+
@$(MAKE) -C CompositeModels -f Makefile test > $@
26+
@grep == CompositeModels.log
27+
2428
parker.log: difftool
2529
@$(MAKE) -C parker -f Makefile test > $@
2630
@grep == parker.log

0 commit comments

Comments
 (0)