Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toplevelparameter #1308

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/OMSimulatorLib/ComponentFMUCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions src/OMSimulatorLib/ComponentFMUME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions testsuite/resources/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ invalidSSV \
invalidSSM \
replaceSubmodel4 \
replaceSubmodel5 \
toplevelparameter1 \
toplevelparameter2 \

MOSs = \
ASSCExample.mos \
Expand Down
102 changes: 102 additions & 0 deletions testsuite/resources/toplevelparameter1/SystemStructure.ssd
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0"?>
<ssd:SystemStructureDescription
xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon"
xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues"
xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping"
xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary"
xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd"
name="model"
version="1.0">
<ssd:System
name="root">
<ssd:Connectors>
<ssd:Connector
name="Input_cref"
kind="input">
<ssc:Real />
</ssd:Connector>
</ssd:Connectors>
<ssd:ParameterBindings>
<ssd:ParameterBinding
source="resources/root.ssv" />
</ssd:ParameterBindings>
<ssd:Elements>
<ssd:Component
name="addP"
type="application/x-fmu-sharedlibrary"
source="resources/0001_addP.fmu">
<ssd:Connectors>
<ssd:Connector
name="u1"
kind="input">
<ssc:Real />
<ssd:ConnectorGeometry
x="0.000000"
y="0.333333" />
</ssd:Connector>
<ssd:Connector
name="u2"
kind="input">
<ssc:Real />
<ssd:ConnectorGeometry
x="0.000000"
y="0.666667" />
</ssd:Connector>
<ssd:Connector
name="y"
kind="output">
<ssc:Real />
<ssd:ConnectorGeometry
x="1.000000"
y="0.500000" />
</ssd:Connector>
<ssd:Connector
name="k1"
kind="parameter">
<ssc:Real />
</ssd:Connector>
<ssd:Connector
name="k2"
kind="parameter">
<ssc:Real />
</ssd:Connector>
</ssd:Connectors>
<ssd:ParameterBindings>
<ssd:ParameterBinding
source="resources/addp.ssv" />
</ssd:ParameterBindings>
</ssd:Component>
</ssd:Elements>
<ssd:Annotations>
<ssc:Annotation
type="org.openmodelica">
<oms:Annotations>
<oms:SimulationInformation>
<oms:FixedStepMaster
description="oms-ma"
stepSize="0.001000"
absoluteTolerance="0.000100"
relativeTolerance="0.000100" />
</oms:SimulationInformation>
</oms:Annotations>
</ssc:Annotation>
</ssd:Annotations>
</ssd:System>
<ssd:DefaultExperiment
startTime="0.000000"
stopTime="1.000000">
<ssd:Annotations>
<ssc:Annotation
type="org.openmodelica">
<oms:Annotations>
<oms:SimulationInformation
resultFile="model_res.mat"
loggingInterval="0.000000"
bufferSize="10"
signalFilter="resources/signalFilter.xml" />
</oms:Annotations>
</ssc:Annotation>
</ssd:Annotations>
</ssd:DefaultExperiment>
</ssd:SystemStructureDescription>
Binary file not shown.
19 changes: 19 additions & 0 deletions testsuite/resources/toplevelparameter1/resources/addp.ssv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ssv:ParameterSet
xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues"
version="1.0"
name="parameters">
<ssv:Parameters>
<ssv:Parameter
name="k1">
<ssv:Real
value="10" />
</ssv:Parameter>
<ssv:Parameter
name="k2">
<ssv:Real
value="20" />
</ssv:Parameter>
</ssv:Parameters>
</ssv:ParameterSet>
24 changes: 24 additions & 0 deletions testsuite/resources/toplevelparameter1/resources/root.ssv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ssv:ParameterSet
xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues"
version="1.0"
name="parameters">
<ssv:Parameters>
<ssv:Parameter
name="addP.k1">
<ssv:Real
value="-200" />
</ssv:Parameter>
<ssv:Parameter
name="addP.k2">
<ssv:Real
value="-300" />
</ssv:Parameter>
<ssv:Parameter
name="Input_cref">
<ssv:Real
value="-20" />
</ssv:Parameter>
</ssv:Parameters>
</ssv:ParameterSet>
28 changes: 28 additions & 0 deletions testsuite/resources/toplevelparameter1/resources/signalFilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<oms:SignalFilter
version="1.0">
<oms:Variable
name="model.root.Input_cref"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.u1"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.u2"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.y"
type="Real"
kind="output" />
<oms:Variable
name="model.root.addP.k1"
type="Real"
kind="parameter" />
<oms:Variable
name="model.root.addP.k2"
type="Real"
kind="parameter" />
</oms:SignalFilter>
143 changes: 143 additions & 0 deletions testsuite/resources/toplevelparameter2/SystemStructure.ssd
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?xml version="1.0"?>
<ssd:SystemStructureDescription
xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon"
xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription"
xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues"
xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping"
xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary"
xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd"
name="model"
version="1.0">
<ssd:System
name="root">
<ssd:Connectors>
<ssd:Connector
name="Input_cref"
kind="input">
<ssc:Real />
</ssd:Connector>
</ssd:Connectors>
<ssd:ParameterBindings>
<ssd:ParameterBinding>
<ssd:ParameterValues>
<ssv:ParameterSet
version="1.0"
name="parameters">
<ssv:Parameters>
<ssv:Parameter
name="Input_cref">
<ssv:Real
value="-20" />
</ssv:Parameter>
<ssv:Parameter
name="addP.k1">
<ssv:Real
value="-200" />
</ssv:Parameter>
<ssv:Parameter
name="addP.k2">
<ssv:Real
value="-400" />
</ssv:Parameter>
</ssv:Parameters>
</ssv:ParameterSet>
</ssd:ParameterValues>
</ssd:ParameterBinding>
</ssd:ParameterBindings>
<ssd:Elements>
<ssd:Component
name="addP"
type="application/x-fmu-sharedlibrary"
source="resources/0001_addP.fmu">
<ssd:Connectors>
<ssd:Connector
name="u1"
kind="input">
<ssc:Real />
<ssd:ConnectorGeometry
x="0.000000"
y="0.333333" />
</ssd:Connector>
<ssd:Connector
name="u2"
kind="input">
<ssc:Real />
<ssd:ConnectorGeometry
x="0.000000"
y="0.666667" />
</ssd:Connector>
<ssd:Connector
name="y"
kind="output">
<ssc:Real />
<ssd:ConnectorGeometry
x="1.000000"
y="0.500000" />
</ssd:Connector>
<ssd:Connector
name="k1"
kind="parameter">
<ssc:Real />
</ssd:Connector>
<ssd:Connector
name="k2"
kind="parameter">
<ssc:Real />
</ssd:Connector>
</ssd:Connectors>
<ssd:ParameterBindings>
<ssd:ParameterBinding>
<ssd:ParameterValues>
<ssv:ParameterSet
version="1.0"
name="parameters">
<ssv:Parameters>
<ssv:Parameter
name="k2">
<ssv:Real
value="20" />
</ssv:Parameter>
<ssv:Parameter
name="k1">
<ssv:Real
value="10" />
</ssv:Parameter>
</ssv:Parameters>
</ssv:ParameterSet>
</ssd:ParameterValues>
</ssd:ParameterBinding>
</ssd:ParameterBindings>
</ssd:Component>
</ssd:Elements>
<ssd:Annotations>
<ssc:Annotation
type="org.openmodelica">
<oms:Annotations>
<oms:SimulationInformation>
<oms:FixedStepMaster
description="oms-ma"
stepSize="0.001000"
absoluteTolerance="0.000100"
relativeTolerance="0.000100" />
</oms:SimulationInformation>
</oms:Annotations>
</ssc:Annotation>
</ssd:Annotations>
</ssd:System>
<ssd:DefaultExperiment
startTime="0.000000"
stopTime="1.000000">
<ssd:Annotations>
<ssc:Annotation
type="org.openmodelica">
<oms:Annotations>
<oms:SimulationInformation
resultFile="model_res.mat"
loggingInterval="0.000000"
bufferSize="10"
signalFilter="resources/signalFilter.xml" />
</oms:Annotations>
</ssc:Annotation>
</ssd:Annotations>
</ssd:DefaultExperiment>
</ssd:SystemStructureDescription>
Binary file not shown.
28 changes: 28 additions & 0 deletions testsuite/resources/toplevelparameter2/resources/signalFilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<oms:SignalFilter
version="1.0">
<oms:Variable
name="model.root.Input_cref"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.u1"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.u2"
type="Real"
kind="input" />
<oms:Variable
name="model.root.addP.y"
type="Real"
kind="output" />
<oms:Variable
name="model.root.addP.k1"
type="Real"
kind="parameter" />
<oms:Variable
name="model.root.addP.k2"
type="Real"
kind="parameter" />
</oms:SignalFilter>
Loading