Skip to content

Commit

Permalink
FMI2 Cpp: separate initializeMemory from initializeFreeVariables to a…
Browse files Browse the repository at this point in the history
…void memory leak in fmi2Reset and to speed it up

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25459 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
rfranke committed Apr 9, 2015
1 parent e296a44 commit a9009b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
22 changes: 14 additions & 8 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -119,6 +119,7 @@ let initeqs = generateEquationMemberFuncDecls(initialEquations,"initEquation")
virtual bool initial();
virtual void setInitial(bool);
virtual void initialize();
virtual void initializeMemory();
virtual void initializeFreeVariables();
virtual void initializeBoundVariables();
virtual void initEquations();
Expand Down Expand Up @@ -5078,23 +5079,27 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
<<
void <%lastIdentOfPath(modelInfo.name)%>Initialize::initialize()
{
initializeMemory();
initializeFreeVariables();
initializeBoundVariables();
saveAll();
}

void <%lastIdentOfPath(modelInfo.name)%>Initialize::initializeFreeVariables()
void <%lastIdentOfPath(modelInfo.name)%>Initialize::initializeMemory()
{
_discrete_events = _event_handling->initialize(this);
//create and initialize Algloopsolvers
<%generateAlgloopsolvers( listAppend(allEquations,initialEquations),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>

//initialize Algloop variables
initializeAlgloopSolverVariables();
//init alg loop vars
<%initAlgloopvars%>
}

void <%lastIdentOfPath(modelInfo.name)%>Initialize::initializeFreeVariables()
{
_simTime = 0.0;
/*variable decls*/
<%varDecls%>

/*initialize parameter*/
initializeParameterVars();
Expand All @@ -5114,11 +5119,6 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
/*external vars decls*/
initializeExternalVar();

//init event handling
<%initEventHandling%>
//init alg loop vars
<%initAlgloopvars%>

#if defined(__TRICORE__) || defined(__vxworks)
//init inputs
stepStarted(0.0);
Expand All @@ -5127,9 +5127,15 @@ case SIMCODE(modelInfo = MODELINFO(__)) then

void <%lastIdentOfPath(modelInfo.name)%>Initialize::initializeBoundVariables()
{
//variable decls
<%varDecls%>

//bound start values
<%initFunctions%>

//init event handling
<%initEventHandling%>

//init equations
initEquations();

Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -247,6 +247,7 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
// initialization
void <%modelIdentifier%>FMU::initialize() {
<%modelIdentifier%>WriteOutput::initialize();
<%modelIdentifier%>Initialize::initializeMemory();
<%modelIdentifier%>Initialize::initializeFreeVariables();
<%modelIdentifier%>Jacobian::initialize();
<%modelIdentifier%>Jacobian::initializeColoredJacobianA();
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Include/FMU2/FMU2Wrapper.cpp
Expand Up @@ -154,7 +154,7 @@ fmi2Status FMU2Wrapper::terminate()

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

Expand Down

0 comments on commit a9009b7

Please sign in to comment.