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

fix solver oms_mav and oms_mav2 in dostep #1163

Merged
merged 5 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
56 changes: 47 additions & 9 deletions src/OMSimulatorLib/SystemWC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,23 @@ oms_status_enu_t oms::SystemWC::exportToSSD_SimulationInformation(pugi::xml_node
{
/* ssd:SimulationInformation should be added as vendor specific annotations from Version 1.0 */
pugi::xml_node node_simulation_information = node.append_child(oms::ssp::Version1_0::simulation_information);
pugi::xml_node node_solver;

if (solverMethod == oms_solver_wc_mav || solverMethod == oms_solver_wc_mav2)
{
node_solver = node_simulation_information.append_child(oms::ssp::Version1_0::VariableStepSolver);
node_solver.append_attribute("description") = getSolverName().c_str();
node_solver.append_attribute("initialStepSize") = std::to_string(initialStepSize).c_str();
node_solver.append_attribute("minimumStepSize") = std::to_string(minimumStepSize).c_str();
node_solver.append_attribute("maximumStepSize") = std::to_string(maximumStepSize).c_str();
}
else if (solverMethod == oms_solver_wc_ma)
{
node_solver = node_simulation_information.append_child(oms::ssp::Version1_0::FixedStepMaster);
node_solver.append_attribute("description") = getSolverName().c_str();
node_solver.append_attribute("stepSize") = std::to_string(maximumStepSize).c_str();
}

pugi::xml_node node_solver = node_simulation_information.append_child(oms::ssp::Version1_0::FixedStepMaster);
node_solver.append_attribute("description") = getSolverName().c_str();
node_solver.append_attribute("stepSize") = std::to_string(maximumStepSize).c_str();
node_solver.append_attribute("absoluteTolerance") = std::to_string(absoluteTolerance).c_str();
node_solver.append_attribute("relativeTolerance") = std::to_string(relativeTolerance).c_str();

Expand All @@ -120,22 +133,45 @@ oms_status_enu_t oms::SystemWC::importFromSSD_SimulationInformation(const pugi::
{
std::string solverName = "";
const char* FixedStepMaster = "";
const char* VariableStepSolver = "";

pugi::xml_node fixedStepMaster = node.child(oms::ssp::Version1_0::FixedStepMaster);
if (fixedStepMaster)
{
solverName = fixedStepMaster.attribute("description").as_string();
FixedStepMaster = oms::ssp::Version1_0::FixedStepMaster;
if (sspVersion == "1.0")
{
solverName = fixedStepMaster.attribute("description").as_string();
FixedStepMaster = oms::ssp::Version1_0::FixedStepMaster;
}
else
{
solverName = node.child("FixedStepMaster").attribute("description").as_string();
FixedStepMaster = "FixedStepMaster";
}
initialStepSize = minimumStepSize = maximumStepSize = node.child(FixedStepMaster).attribute("stepSize").as_double();
}
else

pugi::xml_node variableStepSolver = node.child(oms::ssp::Version1_0::VariableStepSolver);
if (variableStepSolver)
{
solverName = node.child("FixedStepMaster").attribute("description").as_string();
FixedStepMaster = "FixedStepMaster";
if (sspVersion == "1.0")
{
solverName = variableStepSolver.attribute("description").as_string();
VariableStepSolver = oms::ssp::Version1_0::VariableStepSolver;
}
else
{
solverName = node.child("VariableStepSolver").attribute("description").as_string();
VariableStepSolver = "VariableStepSolver";
}
minimumStepSize = node.child(VariableStepSolver).attribute("minimumStepSize").as_double();
maximumStepSize = node.child(VariableStepSolver).attribute("maximumStepSize").as_double();
initialStepSize = node.child(VariableStepSolver).attribute("initialStepSize").as_double();
}

if (oms_status_ok != setSolverMethod(solverName))
return oms_status_error;
initialStepSize = minimumStepSize = maximumStepSize = node.child(FixedStepMaster).attribute("stepSize").as_double();

absoluteTolerance = node.child(FixedStepMaster).attribute("absoluteTolerance").as_double();
relativeTolerance = node.child(FixedStepMaster).attribute("relativeTolerance").as_double();
return oms_status_ok;
Expand Down Expand Up @@ -499,6 +535,8 @@ oms_status_enu_t oms::SystemWC::doStep()

for (const auto& component : mav_canGetAndSetStateFMUcomponents)
component.second->freeState();

return oms_status_ok;
}
else if (solverMethod == oms_solver_wc_ma)
{
Expand Down
1 change: 1 addition & 0 deletions testsuite/resources/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Enum1 \
equationPair.equation1 \
equationPair.equation2 \
fmidertest \
fmi_attributes_19 \
HelloWorld \
HelloWorldWithInput \
Int1 \
Expand Down
Binary file not shown.
Binary file not shown.
191 changes: 191 additions & 0 deletions testsuite/resources/fmi_attributes_19/modelDescription.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
fmiVersion="2.0"
modelName="fmi_attributes_19"
guid="{390234b1-e001-4b5c-aebe-7c3337586558}"
description=""
generationTool="OpenModelica Compiler OpenModelica v1.20.0-dev-59-g0e39c77344 (64-bit)"
generationDateAndTime="2022-05-20T09:13:14Z"
variableNamingConvention="structured"
numberOfEventIndicators="0">
<CoSimulation
modelIdentifier="fmi_attributes_19"
needsExecutionTool="false"
canHandleVariableCommunicationStepSize="true"
canInterpolateInputs="true"
maxOutputDerivativeOrder="1"
canRunAsynchronuously = "false"
canBeInstantiatedOnlyOncePerProcess="false"
canNotUseMemoryManagementFunctions="false"
canGetAndSetFMUstate="true"
canSerializeFMUstate="false"
providesDirectionalDerivative="true">
<SourceFiles>
<File name="fmi_attributes_19.c" />
<File name="fmi_attributes_19_functions.c" />
<File name="fmi_attributes_19_records.c" />
<File name="fmi_attributes_19_01exo.c" />
<File name="fmi_attributes_19_02nls.c" />
<File name="fmi_attributes_19_03lsy.c" />
<File name="fmi_attributes_19_04set.c" />
<File name="fmi_attributes_19_05evt.c" />
<File name="fmi_attributes_19_06inz.c" />
<File name="fmi_attributes_19_07dly.c" />
<File name="fmi_attributes_19_08bnd.c" />
<File name="fmi_attributes_19_09alg.c" />
<File name="fmi_attributes_19_10asr.c" />
<File name="fmi_attributes_19_11mix.c" />
<File name="fmi_attributes_19_12jac.c" />
<File name="fmi_attributes_19_13opt.c" />
<File name="fmi_attributes_19_14lnz.c" />
<File name="fmi_attributes_19_15syn.c" />
<File name="fmi_attributes_19_16dae.c" />
<File name="fmi_attributes_19_17inl.c" />
<File name="fmi_attributes_19_18spd.c" />
<File name="fmi_attributes_19_init_fmu.c" />
<File name="fmi_attributes_19_FMU.c" />
<File name="gc/memory_pool.c" />
<File name="gc/omc_gc.c" />
<File name="./util/base_array.c" />
<File name="./util/boolean_array.c" />
<File name="./util/division.c" />
<File name="./util/doubleEndedList.c" />
<File name="./util/generic_array.c" />
<File name="./util/index_spec.c" />
<File name="./util/integer_array.c" />
<File name="./util/jacobian_util.c" />
<File name="./util/list.c" />
<File name="./util/modelica_string_lit.c" />
<File name="./util/modelica_string.c" />
<File name="./util/ModelicaUtilities.c" />
<File name="./util/omc_error.c" />
<File name="./util/omc_file.c" />
<File name="./util/omc_init.c" />
<File name="./util/omc_mmap.c" />
<File name="./util/omc_msvc.c" />
<File name="./util/omc_numbers.c" />
<File name="./util/parallel_helper.c" />
<File name="./util/rational.c" />
<File name="./util/real_array.c" />
<File name="./util/ringbuffer.c" />
<File name="./util/simulation_options.c" />
<File name="./util/string_array.c" />
<File name="./util/utility.c" />
<File name="./util/varinfo.c" />
<File name="./math-support/pivot.c" />
<File name="./simulation/omc_simulation_util.c" />
<File name="./simulation/options.c" />
<File name="./simulation/simulation_info_json.c" />
<File name="./simulation/simulation_omc_assert.c" />
<File name="./simulation/solver/delay.c" />
<File name="./simulation/solver/fmi_events.c" />
<File name="./simulation/solver/model_help.c" />
<File name="./simulation/solver/omc_math.c" />
<File name="./simulation/solver/spatialDistribution.c" />
<File name="./simulation/solver/stateset.c" />
<File name="./simulation/solver/synchronous.c" />
<File name="./simulation/solver/initialization/initialization.c" />
<File name="./meta/meta_modelica_catch.c" />
<File name="./simulation/solver/nonlinearSolverHomotopy.c" />
<File name="./simulation/solver/nonlinearSolverHybrd.c" />
<File name="./simulation/solver/nonlinearValuesList.c" />
<File name="./simulation/solver/nonlinearSystem.c" />
</SourceFiles>
</CoSimulation>
<LogCategories>
<Category name="logEvents" description="logEvents" />
<Category name="logSingularLinearSystems" description="logSingularLinearSystems" />
<Category name="logNonlinearSystems" description="logNonlinearSystems" />
<Category name="logDynamicStateSelection" description="logDynamicStateSelection" />
<Category name="logStatusWarning" description="logStatusWarning" />
<Category name="logStatusDiscard" description="logStatusDiscard" />
<Category name="logStatusError" description="logStatusError" />
<Category name="logStatusFatal" description="logStatusFatal" />
<Category name="logStatusPending" description="logStatusPending" />
<Category name="logAll" description="logAll" />
<Category name="logFmi2Call" description="logFmi2Call" />
</LogCategories>
<DefaultExperiment startTime="0.0" stopTime="1.0" tolerance="1e-06"/>
<ModelVariables>
<!-- Index of variable = "1" -->
<ScalarVariable
name="x"
valueReference="0"
variability="continuous"
causality="local"
initial="exact">
<Real start="-1.0"/>
</ScalarVariable>
<!-- Index of variable = "2" -->
<ScalarVariable
name="der(x)"
valueReference="1"
variability="continuous"
causality="local"
initial="approx">
<Real start="0.0" derivative="1" nominal="500.0"/>
</ScalarVariable>
<!-- Index of variable = "3" -->
<ScalarVariable
name="x1"
valueReference="2"
variability="continuous"
causality="local"
initial="exact">
<Real start="0.0"/>
</ScalarVariable>
<!-- Index of variable = "4" -->
<ScalarVariable
name="rp1"
valueReference="3"
variability="fixed"
causality="parameter"
initial="exact">
<Real start="6.0"/>
</ScalarVariable>
<!-- Index of variable = "5" -->
<ScalarVariable
name="x2"
valueReference="0"
variability="discrete"
causality="local"
initial="exact">
<Integer start="0"/>
</ScalarVariable>
<!-- Index of variable = "6" -->
<ScalarVariable
name="rp2"
valueReference="1"
variability="fixed"
causality="parameter"
initial="exact">
<Integer start="7"/>
</ScalarVariable>
<!-- Index of variable = "7" -->
<ScalarVariable
name="x3"
valueReference="0"
variability="discrete"
causality="local"
initial="exact">
<Boolean start="false"/>
</ScalarVariable>
<!-- Index of variable = "8" -->
<ScalarVariable
name="rp3"
valueReference="1"
variability="fixed"
causality="parameter"
initial="exact">
<Boolean start="true"/>
</ScalarVariable>
</ModelVariables>
<ModelStructure>
<Derivatives>
<Unknown index="2" dependencies="1" dependenciesKind="dependent" />
</Derivatives>
<InitialUnknowns>
<Unknown index="2" dependencies="1" dependenciesKind="dependent" />
</InitialUnknowns>
</ModelStructure>
</fmiModelDescription>
Loading