Skip to content

Commit

Permalink
export stepSize to <DefaultExperiment> in modeldescription.xml (#12017)
Browse files Browse the repository at this point in the history
* expected output
* do not export stepSize to FMI-1.0
  • Loading branch information
arun3688 committed Feb 21, 2024
1 parent 6a64373 commit 4f26c77
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Template/CodegenCppInit.tpl
Expand Up @@ -19,7 +19,7 @@ template modelInitXMLFile(SimCode simCode, String numRealVars, String numIntVars
let descriptionTag = if generateFMUModelDescription then "fmiModelDescription" else "ModelDescription"
let fmiDescriptionAttributes = if generateFMUModelDescription then fmiDescriptionAttributes(simCode, FMUVersion, FMUType, FMUGuid) else 'modelName="<%dotPath(modelInfo.name)%>"'
let fmiTypeDefinitions = if generateFMUModelDescription then CodegenFMUCommon.fmiTypeDefinitions(simCode, FMUVersion)
let fmiDefaultExperiment = if generateFMUModelDescription then CodegenFMUCommon.DefaultExperiment(simulationSettingsOpt)
let fmiDefaultExperiment = if generateFMUModelDescription then CodegenFMUCommon.DefaultExperiment(simulationSettingsOpt, FMUVersion)
<<
<?xml version="1.0" encoding="UTF-8"?>
<!--Generated with the modifications: <%generatorComments%> -->
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Template/CodegenFMU1.tpl
Expand Up @@ -64,7 +64,7 @@ case SIMCODE(__) then
<fmiModelDescription
<%fmiModelDescriptionAttributes(simCode,guid)%>>
<%fmiTypeDefinitions(simCode, "1.0")%>
<%DefaultExperiment(simulationSettingsOpt)%>
<%DefaultExperiment(simulationSettingsOpt, "1.0")%>
<%fmiModelVariables(simCode, "1.0")%>
<%if isFMICSType(FMUType) then Implementation()%>
</fmiModelDescription>
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Template/CodegenFMU2.tpl
Expand Up @@ -98,7 +98,7 @@ case SIMCODE(__) then
<Category name="logFmi2Call" />
</LogCategories>
>> %>
<%DefaultExperiment(simulationSettingsOpt)%>
<%DefaultExperiment(simulationSettingsOpt, "2.0")%>
<%fmiModelVariables(simCode, "2.0")%>
<%ModelStructure(modelStructure)%>
</fmiModelDescription>
Expand Down
11 changes: 8 additions & 3 deletions OMCompiler/Compiler/Template/CodegenFMUCommon.tpl
Expand Up @@ -793,21 +793,26 @@ match type_
>>
end TypeDefinitionType;

template DefaultExperiment(Option<SimulationSettings> simulationSettingsOpt)
template DefaultExperiment(Option<SimulationSettings> simulationSettingsOpt, String FMUVersion)
"Generates code for DefaultExperiment file for FMU target."
::=
match simulationSettingsOpt
case SOME(v) then
<<
<DefaultExperiment <%DefaultExperimentAttribute(v)%>/>
<DefaultExperiment <%DefaultExperimentAttribute(v, FMUVersion)%>/>
>>
end DefaultExperiment;

template DefaultExperimentAttribute(SimulationSettings simulationSettings)
template DefaultExperimentAttribute(SimulationSettings simulationSettings, String FMUVersion)
"Generates code for DefaultExperiment Attribute file for FMU target."
::=
match simulationSettings
case SIMULATION_SETTINGS(__) then
if isFMIVersion20(FMUVersion) then
<<
startTime="<%startTime%>" stopTime="<%stopTime%>" tolerance="<%tolerance%>" stepSize="<%stepSize%>"
>>
else
<<
startTime="<%startTime%>" stopTime="<%stopTime%>" tolerance="<%tolerance%>"
>>
Expand Down
Expand Up @@ -14,12 +14,12 @@ readFile("Pendulum_systemCall.log");
// "Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.fmu"
// ""
// 0
// "info: maximum step size for 'model.root': 0.010000
// "info: maximum step size for 'model.root': 0.002000
// info: Result file: model_res.mat (bufferSize=10)
// info: Parameter model.root.fmu.world.label1 will not be stored in the result file, because the signal type is not supported
// info: Parameter model.root.fmu.world.label2 will not be stored in the result file, because the signal type is not supported
// info: Final Statistics for 'model.root':
// NumSteps = 523 NumRhsEvals = 533 NumLinSolvSetups = 36
// NumNonlinSolvIters = 532 NumNonlinSolvConvFails = 0 NumErrTestFails = 1
// NumSteps = 2511 NumRhsEvals = 2517 NumLinSolvSetups = 134
// NumNonlinSolvIters = 2516 NumNonlinSolvConvFails = 0 NumErrTestFails = 1
// "
// endResult
Expand Up @@ -120,7 +120,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -101,7 +101,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -128,7 +128,7 @@ getErrorString();
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -107,7 +107,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -179,7 +179,7 @@ val(evaporator_qm_S, 100);
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -73,7 +73,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/fmi/ModelExchange/2.0/Makefile
Expand Up @@ -21,6 +21,7 @@ fmi_attributes_17.mos \
fmi_attributes_18.mos \
fmi_attributes_19.mos \
fmi_attributes_20.mos \
fmi_attributes_21.mos \
FMUResourceTest.mos \
testBug2764.mos \
testBug2765.mos \
Expand Down
Expand Up @@ -135,7 +135,7 @@ readFile("fmi_attributes_15_tmp.xml")
// <Category name=\"logAll\" description=\"logAll\" />
// <Category name=\"logFmi2Call\" description=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
39 changes: 39 additions & 0 deletions testsuite/openmodelica/fmi/ModelExchange/2.0/fmi_attributes_21.mos
@@ -0,0 +1,39 @@
// name: fmi_attributes_21.mos
// keywords: FMI 2.0 export
// status: correct
// teardown_command: rm -rf fmi_attributes_21.fmu fmi_attributes_21.log fmi_attributes_21.xml fmi_attributes_21_tmp.xml fmi_attributes_21_info.json

loadString("
model fmi_attributes_21
Real x = time;
parameter Real x0(fixed = false);
initial equation
x0 = x;
equation
annotation(
experiment(StartTime = 0.2, StopTime = 1, Tolerance = 1e-06, Interval = 0.01));
end fmi_attributes_21;
"); getErrorString();

buildModelFMU(fmi_attributes_21); getErrorString();

// unzip to console, quiet, extra quiet
system("unzip -cqq fmi_attributes_21.fmu modelDescription.xml > fmi_attributes_21_tmp.xml"); getErrorString();

system("sed -n \"/<DefaultExperiment/p\" fmi_attributes_21_tmp.xml > fmi_attributes_21.xml"); getErrorString();
readFile("fmi_attributes_21.xml"); getErrorString();


// Result:
// true
// ""
// "fmi_attributes_21.fmu"
// ""
// 0
// ""
// 0
// ""
// " <DefaultExperiment startTime=\"0.2\" stopTime=\"1.0\" tolerance=\"1e-6\" stepSize=\"0.01\"/>
// "
// ""
// endResult
Expand Up @@ -129,7 +129,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -125,7 +125,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -143,7 +143,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down
Expand Up @@ -139,7 +139,7 @@ readFile("modelDescription.tmp.xml");
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\" stepSize=\"0.002\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
Expand Down

0 comments on commit 4f26c77

Please sign in to comment.