Skip to content

Commit

Permalink
Add Reference FMUs (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Nov 21, 2024
1 parent ece2b64 commit 74b2cae
Show file tree
Hide file tree
Showing 103 changed files with 14,779 additions and 16 deletions.
6 changes: 5 additions & 1 deletion testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

all: difftool resources test

test: api.log AircraftVehicleDemonstrator.log import.log export.log simulation.log assc.log
test: api.log AircraftVehicleDemonstrator.log import.log export.log simulation.log assc.log reference-fmus.log

partest: difftool resources
cd partest && time ./runtests.pl -nocolour -with-xml
Expand Down Expand Up @@ -36,3 +36,7 @@ simulation.log: difftool
assc.log: difftool
@$(MAKE) -C assc -f Makefile test > $@
@grep == assc.log

reference-fmus.log: difftool
@$(MAKE) -C reference-fmus -f Makefile test > $@
@grep == reference-fmus.log
78 changes: 78 additions & 0 deletions testsuite/reference-fmus/BouncingBall.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- status: correct
-- teardown_command: rm -rf BouncingBall-lua/
-- linux: yes
-- ucrt64: yes
-- win: yes
-- mac: yes
-- asan: yes

oms_setCommandLineOption("--suppressPath=true")
oms_setTempDirectory("./BouncingBall-lua/")
oms_setWorkingDirectory("./BouncingBall-lua/")

oms_newModel("model")
oms_addSystem("model.root", oms_system_wc)

oms_addSubModel("model.root.BouncingBall", "../../resources/BouncingBall.fmu")

oms_setResultFile("model", "BouncingBall-cs.mat")
oms_setStopTime("model", 3.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

if 1 == oms_compareSimulationResults("../../references/BouncingBall-cs.mat", "BouncingBall-cs.mat", "model.root.BouncingBall.h", 1e-4, 1e-4) then
print("signal h is equal")
else
print("signal h is not equal")
end

if 1 == oms_compareSimulationResults("../../references/BouncingBall-cs.mat", "BouncingBall-cs.mat", "model.root.BouncingBall.v", 1e-4, 1e-4) then
print("signal v is equal")
else
print("signal v is not equal")
end

oms_newModel("model")
oms_addSystem("model.root", oms_system_sc)

oms_addSubModel("model.root.BouncingBall", "../../resources/BouncingBall.fmu")

oms_setResultFile("model", "BouncingBall-me.mat")
oms_setStopTime("model", 3.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

if 1 == oms_compareSimulationResults("../../references/BouncingBall-me.mat", "BouncingBall-me.mat", "model.root.BouncingBall.h", 1e-4, 1e-4) then
print("signal h is equal")
else
print("signal h is not equal")
end

if 1 == oms_compareSimulationResults("../../references/BouncingBall-me.mat", "BouncingBall-me.mat", "model.root.BouncingBall.v", 1e-4, 1e-4) then
print("signal v is equal")
else
print("signal v is not equal")
end

-- Result:
-- info: Result file: BouncingBall-cs.mat (bufferSize=1)
-- signal h is equal
-- signal v is equal
-- info: maximum step size for 'model.root': 0.001000
-- info: Result file: BouncingBall-me.mat (bufferSize=1)
-- info: Final Statistics for 'model.root':
-- NumSteps = 502 NumRhsEvals = 503 NumLinSolvSetups = 27
-- NumNonlinSolvIters = 502 NumNonlinSolvConvFails = 0 NumErrTestFails = 0
-- signal h is equal
-- signal v is equal
-- endResult
64 changes: 64 additions & 0 deletions testsuite/reference-fmus/Dahlquist.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- status: correct
-- teardown_command: rm -rf Dahlquist-lua/
-- linux: yes
-- ucrt64: yes
-- win: yes
-- mac: yes
-- asan: yes

oms_setCommandLineOption("--suppressPath=true")
oms_setTempDirectory("./Dahlquist-lua/")
oms_setWorkingDirectory("./Dahlquist-lua/")

oms_newModel("model")
oms_addSystem("model.root", oms_system_wc)

oms_addSubModel("model.root.Dahlquist", "../../resources/Dahlquist.fmu")

oms_setResultFile("model", "Dahlquist-cs.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

if 1 == oms_compareSimulationResults("../../references/Dahlquist-cs.mat", "Dahlquist-cs.mat", "model.root.Dahlquist.x", 1e-4, 1e-4) then
print("signal x is equal")
else
print("signal x is not equal")
end

oms_newModel("model")
oms_addSystem("model.root", oms_system_sc)

oms_addSubModel("model.root.Dahlquist", "../../resources/Dahlquist.fmu")

oms_setResultFile("model", "Dahlquist-me.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

if 1 == oms_compareSimulationResults("../../references/Dahlquist-me.mat", "Dahlquist-me.mat", "model.root.Dahlquist.x", 1e-4, 1e-4) then
print("signal x is equal")
else
print("signal x is not equal")
end

-- Result:
-- info: Result file: Dahlquist-cs.mat (bufferSize=1)
-- signal x is equal
-- info: maximum step size for 'model.root': 0.001000
-- info: Result file: Dahlquist-me.mat (bufferSize=1)
-- info: Final Statistics for 'model.root':
-- NumSteps = 10001 NumRhsEvals = 10002 NumLinSolvSetups = 501
-- NumNonlinSolvIters = 10001 NumNonlinSolvConvFails = 0 NumErrTestFails = 0
-- signal x is equal
-- endResult
83 changes: 83 additions & 0 deletions testsuite/reference-fmus/Feedthrough.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
-- status: correct
-- teardown_command: rm -rf Feedthrough-lua/
-- linux: yes
-- ucrt64: yes
-- win: yes
-- mac: yes
-- asan: yes

oms_setCommandLineOption("--suppressPath=true")
oms_setTempDirectory("./Feedthrough-lua/")
oms_setWorkingDirectory("./Feedthrough-lua/")

oms_newModel("model")
oms_addSystem("model.root", oms_system_wc)

oms_addSubModel("model.root.Feedthrough", "../../resources/Feedthrough.fmu")

oms_setResultFile("model", "Feedthrough-cs.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_setBoolean("model.root.Feedthrough.Boolean_input", true)
oms_setInteger("model.root.Feedthrough.Enumeration_input", 2)
oms_setReal("model.root.Feedthrough.Float64_continuous_input", 3.1)
oms_setReal("model.root.Feedthrough.Float64_discrete_input", 4.2)
oms_setInteger("model.root.Feedthrough.Int32_input", 5)

oms_initialize("model")
oms_simulate("model")
print("info: Feedthrough.Boolean_output: " .. oms_getBoolean("model.root.Feedthrough.Boolean_output"))
print("info: Feedthrough.Enumeration_output: " .. oms_getInteger("model.root.Feedthrough.Enumeration_output"))
print("info: Feedthrough.Float64_continuous_output: " .. oms_getReal("model.root.Feedthrough.Float64_continuous_output"))
print("info: Feedthrough.Float64_discrete_output: " .. oms_getReal("model.root.Feedthrough.Float64_discrete_output"))
print("info: Feedthrough.Int32_output: " .. oms_getInteger("model.root.Feedthrough.Int32_output"))

oms_terminate("model")
oms_delete("model")

oms_newModel("model")
oms_addSystem("model.root", oms_system_sc)

oms_addSubModel("model.root.Feedthrough", "../../resources/Feedthrough.fmu")

oms_setResultFile("model", "Feedthrough-me.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)

oms_instantiate("model")
oms_setBoolean("model.root.Feedthrough.Boolean_input", true)
oms_setInteger("model.root.Feedthrough.Enumeration_input", 2)
oms_setReal("model.root.Feedthrough.Float64_continuous_input", 3.1)
oms_setReal("model.root.Feedthrough.Float64_discrete_input", 4.2)
oms_setInteger("model.root.Feedthrough.Int32_input", 5)

oms_initialize("model")
oms_simulate("model")
print("info: Feedthrough.Boolean_output: " .. oms_getBoolean("model.root.Feedthrough.Boolean_output"))
print("info: Feedthrough.Enumeration_output: " .. oms_getInteger("model.root.Feedthrough.Enumeration_output"))
print("info: Feedthrough.Float64_continuous_output: " .. oms_getReal("model.root.Feedthrough.Float64_continuous_output"))
print("info: Feedthrough.Float64_discrete_output: " .. oms_getReal("model.root.Feedthrough.Float64_discrete_output"))
print("info: Feedthrough.Int32_output: " .. oms_getInteger("model.root.Feedthrough.Int32_output"))

oms_terminate("model")
oms_delete("model")

-- Result:
-- info: Result file: Feedthrough-cs.mat (bufferSize=1)
-- info: Parameter model.root.Feedthrough.String_parameter will not be stored in the result file, because the signal type is not supported
-- info: Feedthrough.Boolean_output: 1
-- info: Feedthrough.Enumeration_output: 2
-- info: Feedthrough.Float64_continuous_output: 3.1
-- info: Feedthrough.Float64_discrete_output: 4.2
-- info: Feedthrough.Int32_output: 5
-- info: model doesn't contain any continuous state
-- info: Result file: Feedthrough-me.mat (bufferSize=1)
-- info: Parameter model.root.Feedthrough.String_parameter will not be stored in the result file, because the signal type is not supported
-- info: Feedthrough.Boolean_output: 1
-- info: Feedthrough.Enumeration_output: 2
-- info: Feedthrough.Float64_continuous_output: 3.1
-- info: Feedthrough.Float64_discrete_output: 4.2
-- info: Feedthrough.Int32_output: 5
-- endResult
56 changes: 56 additions & 0 deletions testsuite/reference-fmus/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
TEST = ../rtest -v

TESTFILES = \
BouncingBall.lua \
Dahlquist.lua \
Feedthrough.lua \
Resource.lua \
Stair.lua \
VanDerPol.lua \

# Run make failingtest
FAILINGTESTFILES = \

# Dependency files that are not .lua or Makefile
# Add them here or they will be cleaned.
DEPENDENCIES = \
*.lua \
*.py \
Makefile \

CLEAN = `ls | grep -w -v -f deps.tmp`

.PHONY : test clean getdeps failingtest

test:
@echo
@echo Running tests...
@$(TEST) $(TESTFILES)

baseline:
@echo
@echo Updating badelines...
@$(TEST) -b $(TESTFILES)

# Cleans all files that are not listed as dependencies
clean:
@echo $(DEPENDENCIES) | sed 's/ /\\\|/g' > deps.tmp
@rm -rf $(CLEAN)

# Run this if you want to list out the files (dependencies).
# do it after cleaning and updating the folder
# then you can get a list of file names (which must be dependencies
# since you got them from repository + your own new files)
# then add them to the DEPENDENCIES. You can find the
# list in deps.txt
getdeps:
@echo $(DEPENDENCIES) | sed 's/ /\\\|/g' > deps.tmp
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
@echo Dependency list saved in deps.txt.
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES

failingtest:
@echo
@echo Running failing tests...
@echo
@$(TEST) $(FAILINGTESTFILES)
45 changes: 45 additions & 0 deletions testsuite/reference-fmus/Resource.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- status: correct
-- teardown_command: rm -rf Resource-lua/
-- linux: yes
-- ucrt64: yes
-- win: yes
-- mac: yes
-- asan: yes

oms_setCommandLineOption("--suppressPath=true")
oms_setTempDirectory("./Resource-lua/")
oms_setWorkingDirectory("./Resource-lua/")

oms_newModel("model")
oms_addSystem("model.root", oms_system_wc)
oms_addSubModel("model.root.Resource", "../../resources/Resource.fmu")
oms_setResultFile("model", "Resource-cs.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)
oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
print("info: Resource.y: " .. oms_getInteger("model.root.Resource.y"))
oms_terminate("model")
oms_delete("model")

oms_newModel("model")
oms_addSystem("model.root", oms_system_sc)
oms_addSubModel("model.root.Resource", "../../resources/Resource.fmu")
oms_setResultFile("model", "Resource-me.mat")
oms_setStopTime("model", 10.0)
oms_setTolerance("model.root", 1e-5, 1e-5)
oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
print("info: Resource.y: " .. oms_getInteger("model.root.Resource.y"))
oms_terminate("model")
oms_delete("model")

-- Result:
-- info: Result file: Resource-cs.mat (bufferSize=1)
-- info: Resource.y: 97
-- info: model doesn't contain any continuous state
-- info: Result file: Resource-me.mat (bufferSize=1)
-- info: Resource.y: 97
-- endResult
Loading

0 comments on commit 74b2cae

Please sign in to comment.