Skip to content

Commit

Permalink
- Moved functionODE_residual to the runtime instead of templates (com…
Browse files Browse the repository at this point in the history
…pile once, link many times)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10149 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 19, 2011
1 parent d2ad9d9 commit 7cd5f1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
34 changes: 0 additions & 34 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -146,8 +146,6 @@ case simCode as SIMCODE(__) then
<%functionODE(odeEquations,(match simulationSettingsOpt case SOME(settings as SIMULATION_SETTINGS(__)) then settings.method else ""))%>
<%functionODE_residual()%>
<%functionAlgebraic(algebraicEquations)%>
<%functionAliasEquation(removedEquations)%>
Expand Down Expand Up @@ -1135,38 +1133,6 @@ template functionAliasEquation(list<SimEqSystem> removedEquations)
end functionAliasEquation;


template functionODE_residual()
"Generates residual function for dassl in simulation file."
::=
<<
int functionODE_residual(double *t, double *x, double *xd, double *delta,
fortran_integer *ires, double *rpar, fortran_integer *ipar)
{
double timeBackup;
double* statesBackup;
int i;
timeBackup = localData->timeValue;
statesBackup = localData->states;
localData->timeValue = *t;
localData->states = x;
functionODE();
/* get the difference between the temp_xd(=localData->statesDerivatives)
and xd(=statesDerivativesBackup) */
for (i=0; i < localData->nStates; i++) {
delta[i] = localData->statesDerivatives[i] - xd[i];
}

localData->states = statesBackup;
localData->timeValue = timeBackup;

return 0;
}
>>
end functionODE_residual;

template functionDAE( list<SimEqSystem> allEquationsPlusWhen,
list<SimWhenClause> whenClauses,
list<HelpVarInfo> helpVarInfo)
Expand Down
2 changes: 0 additions & 2 deletions Compiler/susan_codegen/SimCode/SimCodeQSS.tpl
Expand Up @@ -102,8 +102,6 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(varInfo=varInfo as VARINFO(__)))

<%SimCodeC.externalFunctionIncludes(externalFunctionIncludes)%>

<%SimCodeC.functionODE_residual()%>

#ifdef _OMC_MEASURE_TIME
int measure_time_flag = 1;
#else
Expand Down
26 changes: 26 additions & 0 deletions c_runtime/solver_main.cpp
Expand Up @@ -1331,3 +1331,29 @@ interpolation_control(const int &dideventstep, double &interpolationStep,
}
return 0;
}

int functionODE_residual(double *t, double *x, double *xd, double *delta,
fortran_integer *ires, double *rpar, fortran_integer *ipar)
{
double timeBackup;
double* statesBackup;
int i;

timeBackup = globalData->timeValue;
statesBackup = globalData->states;

globalData->timeValue = *t;
globalData->states = x;
functionODE();

/* get the difference between the temp_xd(=localData->statesDerivatives)
and xd(=statesDerivativesBackup) */
for (i=0; i < globalData->nStates; i++) {
delta[i] = globalData->statesDerivatives[i] - xd[i];
}

globalData->states = statesBackup;
globalData->timeValue = timeBackup;

return 0;
}

0 comments on commit 7cd5f1b

Please sign in to comment.