Skip to content

Commit

Permalink
FMI2 Cpp: implement fmi2Reset function
Browse files Browse the repository at this point in the history
- CodegenFMUCpp.tpl: need an own initialize() method that does all but evaluation of initial equations
- FMU2Wrapper.cpp: implement reset() method and adapt initialization
- FMUWrapper.cpp: adapt initialization (enabling override of free variables prior to initialization of bound variables)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25397 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
rfranke committed Apr 4, 2015
1 parent 2fd6859 commit 07ccc17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -179,6 +179,9 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
boost::shared_ptr<IAlgLoopSolverFactory> nonLinSolverFactory,
boost::shared_ptr<ISimData> simData);
// initialization
virtual void initialize();
// getters for given value references
virtual void getReal(const unsigned int vr[], int nvr, double value[]);
virtual void getInteger(const unsigned int vr[], int nvr, int value[]);
Expand Down Expand Up @@ -241,6 +244,14 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
<%modelIdentifier%>Extension(globalSettings, nonLinSolverFactory, simData) {
}

// initialization
void <%modelIdentifier%>FMU::initialize() {
<%modelIdentifier%>WriteOutput::initialize();
<%modelIdentifier%>Initialize::initializeFreeVariables();
<%modelIdentifier%>Jacobian::initialize();
<%modelIdentifier%>Jacobian::initializeColoredJacobianA();
}

// getters
<%accessFunctions(simCode, "get", modelIdentifier, modelInfo)%>
// setters
Expand Down
5 changes: 2 additions & 3 deletions SimulationRuntime/cpp/Include/FMU/FMUWrapper.cpp
Expand Up @@ -21,7 +21,7 @@ FMUWrapper::FMUWrapper(fmiString instanceName, fmiString GUID,
solver_factory(new AlgLoopSolverFactory(&_global_settings,PATH(""),PATH("")));
_model = boost::shared_ptr<MODEL_CLASS>
(new MODEL_CLASS(&_global_settings, solver_factory, boost::shared_ptr<ISimData>(new SimData())));
_model->setInitial(true);
_model->initialize();
_tmp_real_buffer.resize(_model->getDimReal());
_tmp_int_buffer.resize(_model->getDimInteger());
_tmp_bool_buffer.resize(_model->getDimBoolean());
Expand Down Expand Up @@ -128,9 +128,8 @@ fmiStatus FMUWrapper::setString(const fmiValueReference vr[], size_t nvr,
/* of the model equations */
fmiStatus FMUWrapper::initialize(fmiBoolean toleranceControlled, fmiReal relativeTolerance, fmiEventInfo& eventInfo)
{
// TODO: here is some code duplication to SimulationRuntime/cpp/Core/Solver/Initailization.cpp
_model->initialize();
_model->setInitial(true);
_model->initializeBoundVariables();

bool restart=true;
int iter=0;
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Include/FMU2/FMU2Wrapper.cpp
Expand Up @@ -76,8 +76,7 @@ FMU2Wrapper::FMU2Wrapper(fmi2String instanceName, fmi2String GUID,
_model = boost::shared_ptr<MODEL_CLASS>
(new MODEL_CLASS(&_global_settings, solver_factory,
boost::shared_ptr<ISimData>(new SimData())));
_model->setInitial(true);
_model->initializeFreeVariables();
_model->initialize();
_string_buffer.resize(_model->getDimString());
}

Expand Down Expand Up @@ -155,6 +154,7 @@ fmi2Status FMU2Wrapper::terminate()

fmi2Status FMU2Wrapper::reset()
{
_model->initialize();
return fmi2OK;
}

Expand Down

0 comments on commit 07ccc17

Please sign in to comment.