diff --git a/src/OMSimulatorLib/ComponentFMUCS.cpp b/src/OMSimulatorLib/ComponentFMUCS.cpp
index c79cd082f..af53d4de2 100644
--- a/src/OMSimulatorLib/ComponentFMUCS.cpp
+++ b/src/OMSimulatorLib/ComponentFMUCS.cpp
@@ -617,6 +617,14 @@ oms_status_enu_t oms::ComponentFMUCS::instantiate()
setResourcesHelper1(res.second);
}
}
+ /*
+ check for parameter entry at system level and override the start values if exist,
+ as system level parameter has highest priority, this is done after checking for
+ local resources because it is possible some parameters have local entry and other
+ parameters have top level system entry
+ */
+ if (getParentSystem() && getParentSystem()->getValues().hasResources())
+ setResourcesHelper2(getParentSystem()->getValues());
}
// set start values from root resources
else if (getParentSystem() && getParentSystem()->getValues().hasResources())
diff --git a/src/OMSimulatorLib/ComponentFMUME.cpp b/src/OMSimulatorLib/ComponentFMUME.cpp
index ea936a672..1e7d675ce 100644
--- a/src/OMSimulatorLib/ComponentFMUME.cpp
+++ b/src/OMSimulatorLib/ComponentFMUME.cpp
@@ -645,6 +645,14 @@ oms_status_enu_t oms::ComponentFMUME::instantiate()
setResourcesHelper1(res.second);
}
}
+ /*
+ check for parameter entry at system level and override the start values if exist,
+ as system level parameter has highest priority, this is done after checking for
+ local resources because it is possible some parameters have local entry and other
+ parameters have top level system entry
+ */
+ if (getParentSystem() && getParentSystem()->getValues().hasResources())
+ setResourcesHelper2(getParentSystem()->getValues());
}
// set start values from root resources
else if (getParentSystem() && getParentSystem()->getValues().hasResources())
diff --git a/testsuite/resources/Makefile b/testsuite/resources/Makefile
index f19895591..0c353d6a6 100644
--- a/testsuite/resources/Makefile
+++ b/testsuite/resources/Makefile
@@ -79,6 +79,8 @@ invalidSSV \
invalidSSM \
replaceSubmodel4 \
replaceSubmodel5 \
+toplevelparameter1 \
+toplevelparameter2 \
MOSs = \
ASSCExample.mos \
diff --git a/testsuite/resources/toplevelparameter1/SystemStructure.ssd b/testsuite/resources/toplevelparameter1/SystemStructure.ssd
new file mode 100644
index 000000000..481f60e98
--- /dev/null
+++ b/testsuite/resources/toplevelparameter1/SystemStructure.ssd
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/resources/toplevelparameter1/resources/0001_addP.fmu b/testsuite/resources/toplevelparameter1/resources/0001_addP.fmu
new file mode 100644
index 000000000..8e56c5a09
Binary files /dev/null and b/testsuite/resources/toplevelparameter1/resources/0001_addP.fmu differ
diff --git a/testsuite/resources/toplevelparameter1/resources/addp.ssv b/testsuite/resources/toplevelparameter1/resources/addp.ssv
new file mode 100644
index 000000000..d0e47c1c6
--- /dev/null
+++ b/testsuite/resources/toplevelparameter1/resources/addp.ssv
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/resources/toplevelparameter1/resources/root.ssv b/testsuite/resources/toplevelparameter1/resources/root.ssv
new file mode 100644
index 000000000..082ee45cf
--- /dev/null
+++ b/testsuite/resources/toplevelparameter1/resources/root.ssv
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/resources/toplevelparameter1/resources/signalFilter.xml b/testsuite/resources/toplevelparameter1/resources/signalFilter.xml
new file mode 100644
index 000000000..3e7670415
--- /dev/null
+++ b/testsuite/resources/toplevelparameter1/resources/signalFilter.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/resources/toplevelparameter2/SystemStructure.ssd b/testsuite/resources/toplevelparameter2/SystemStructure.ssd
new file mode 100644
index 000000000..3ae30e731
--- /dev/null
+++ b/testsuite/resources/toplevelparameter2/SystemStructure.ssd
@@ -0,0 +1,143 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/resources/toplevelparameter2/resources/0001_addP.fmu b/testsuite/resources/toplevelparameter2/resources/0001_addP.fmu
new file mode 100644
index 000000000..8e56c5a09
Binary files /dev/null and b/testsuite/resources/toplevelparameter2/resources/0001_addP.fmu differ
diff --git a/testsuite/resources/toplevelparameter2/resources/signalFilter.xml b/testsuite/resources/toplevelparameter2/resources/signalFilter.xml
new file mode 100644
index 000000000..3e7670415
--- /dev/null
+++ b/testsuite/resources/toplevelparameter2/resources/signalFilter.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/simulation/toplevelparameter1.lua b/testsuite/simulation/toplevelparameter1.lua
new file mode 100644
index 000000000..22e79ef59
--- /dev/null
+++ b/testsuite/simulation/toplevelparameter1.lua
@@ -0,0 +1,40 @@
+-- status: correct
+-- teardown_command: rm -rf toplevelparameters1/
+-- linux: no
+-- ucrt64: yes
+-- win: yes
+-- mac: no
+
+oms_setCommandLineOption("--suppressPath=true")
+oms_setTempDirectory("./toplevelparameters1/")
+oms_setWorkingDirectory("./toplevelparameters1/")
+
+
+oms_importFile("../../resources/toplevelparameter1.ssp")
+
+oms_setResultFile("model", "toplevelparameter1.mat")
+
+oms_instantiate("model")
+oms_initialize("model")
+oms_simulate("model")
+
+print("info: Parameter values")
+print("info: model.root.addP.k1 : " .. oms_getReal("model.root.addP.k1"))
+print("info: model.root.addP.k2 : " .. oms_getReal("model.root.addP.k2"))
+
+-- Top level cref's
+print("info: Top-System-Level-Vars")
+print("info: model.root.Input_cref : " .. oms_getReal("model.root.Input_cref"))
+
+
+oms_terminate("model")
+oms_delete("model")
+
+-- Result:
+-- info: Result file: toplevelparameter1.mat (bufferSize=1)
+-- info: Parameter values
+-- info: model.root.addP.k1 : -200.0
+-- info: model.root.addP.k2 : -300.0
+-- info: Top-System-Level-Vars
+-- info: model.root.Input_cref : -20.0
+-- endResult
diff --git a/testsuite/simulation/toplevelparameter2.lua b/testsuite/simulation/toplevelparameter2.lua
new file mode 100644
index 000000000..267aab62b
--- /dev/null
+++ b/testsuite/simulation/toplevelparameter2.lua
@@ -0,0 +1,40 @@
+-- status: correct
+-- teardown_command: rm -rf toplevelparameters1/
+-- linux: no
+-- ucrt64: yes
+-- win: yes
+-- mac: no
+
+oms_setCommandLineOption("--suppressPath=true")
+oms_setTempDirectory("./toplevelparameters2/")
+oms_setWorkingDirectory("./toplevelparameters2/")
+
+
+oms_importFile("../../resources/toplevelparameter2.ssp")
+
+oms_setResultFile("model", "toplevelparameter2.mat")
+
+oms_instantiate("model")
+oms_initialize("model")
+oms_simulate("model")
+
+print("info: Parameter values")
+print("info: model.root.addP.k1 : " .. oms_getReal("model.root.addP.k1"))
+print("info: model.root.addP.k2 : " .. oms_getReal("model.root.addP.k2"))
+
+-- Top level cref's
+print("info: Top-System-Level-Vars")
+print("info: model.root.Input_cref : " .. oms_getReal("model.root.Input_cref"))
+
+
+oms_terminate("model")
+oms_delete("model")
+
+-- Result:
+-- info: Result file: toplevelparameter2.mat (bufferSize=1)
+-- info: Parameter values
+-- info: model.root.addP.k1 : -200.0
+-- info: model.root.addP.k2 : -400.0
+-- info: Top-System-Level-Vars
+-- info: model.root.Input_cref : -20.0
+-- endResult