Skip to content

Commit d0c69bb

Browse files
author
Matthias Arzt
committed
Add FMU interface for c++ simulation target.
"SimulationRuntime/cpp/Core/System/..." Add a static library libOMCppSystem_static for linking with c++ fmu simulation traget. "SimulationRuntime/cpp/Include/FMU/..." Add FMU interface for c++ simulation target. "Compiler/Template/CodegenCpp.tpl" c++ simulation target, add member funktions for accessing values of algebraic variables and parameters. "Compiler/Template/CodegenFMUCpp.tpl" changed to generate new FMU interface for c++ simulation target. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15688 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 6dac3ad commit d0c69bb

File tree

13 files changed

+806
-1263
lines changed

13 files changed

+806
-1263
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
302302
<%resethelpvar(whenClauses,simCode)%>
303303
<%LabeledDAE(modelInfo.labels,simCode)%>
304304
<%functionAnalyticJacobians(jacobianMatrixes,simCode)%>
305+
<%giveVariables(modelInfo)%>
305306
>>
306307
end simulationCppFile;
307308
/* <%saveConditions(simCode)%>*/
@@ -2363,6 +2364,13 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
23632364
virtual void setVariables(const ublas::vector<double>& variables, const ublas::vector<double>& variables2);
23642365
23652366
>>%>
2367+
bool getReal(int handle, double& value);
2368+
bool getInteger(int handle, int& value);
2369+
bool getBoolean(int handle, bool& value);
2370+
2371+
bool setReal(int handle, double& value);
2372+
bool setInteger(int handle, int& value);
2373+
bool setBoolean(int handle, bool& value);
23662374
>>
23672375
end generateMethodDeclarationCode;
23682376
@@ -7323,13 +7331,149 @@ end algStmtAssignArr;
73237331
template indexSpecFromCref(ComponentRef cr, Context context, Text &preExp /*BUFP*/,
73247332
Text &varDecls /*BUFP*/,SimCode simCode)
73257333
"Helper to algStmtAssignArr.
7326-
Currently works only for CREF_IDENT."
7327-
::=
7334+
Currently works only for CREF_IDENT." ::=
73287335
match cr
73297336
case CREF_IDENT(subscriptLst=subs as (_ :: _)) then
73307337
daeExpCrefRhsIndexSpec(subs, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
73317338
end indexSpecFromCref;
73327339

7340+
// generate Member Function get Real
7341+
7342+
template giveVariables(ModelInfo modelInfo)
7343+
"Define Memeber Function getReal off Cpp Target"
7344+
::=
7345+
match modelInfo
7346+
case MODELINFO(vars=SIMVARS(__)) then
7347+
<<
7348+
bool <%lastIdentOfPath(name)%>::getReal(int handle, double& value)
7349+
{
7350+
switch(handle)
7351+
{
7352+
<%System.tmpTickReset(0)%>
7353+
<%vars.stateVars |> var hasindex i0 fromindex 0 => giveVariablesState(var, System.tmpTick(), "__z", i0) ;separator="\n"%>
7354+
<%vars.derivativeVars |> var hasindex i0 fromindex 0 => giveVariablesState(var, System.tmpTick(), "__zDot", i0) ;separator="\n"%>
7355+
<%vars.algVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7356+
<%vars.paramVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7357+
default:
7358+
return false;
7359+
}
7360+
}
7361+
7362+
bool <%lastIdentOfPath(name)%>::getInteger(int handle, int& value)
7363+
{
7364+
switch(handle)
7365+
{
7366+
<%listAppend( listAppend( vars.intAlgVars, vars.intParamVars ), vars.intAliasVars ) |>
7367+
var hasindex i0 fromindex 0 => giveVariablesDefault(var, i0)
7368+
;separator="\n"%>
7369+
default:
7370+
return false;
7371+
}
7372+
}
7373+
7374+
bool <%lastIdentOfPath(name)%>::getBoolean(int handle, bool& value)
7375+
{
7376+
switch(handle)
7377+
{
7378+
<%listAppend( listAppend( vars.boolAlgVars, vars.boolParamVars ), vars.boolAliasVars ) |>
7379+
var hasindex i0 fromindex 0 => giveVariablesDefault(var, i0)
7380+
;separator="\n"%>
7381+
default:
7382+
return false;
7383+
}
7384+
}
7385+
/*
7386+
<%System.tmpTickReset(0)%>
7387+
<%vars.stringAlgVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7388+
<%vars.stringParamVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7389+
<%vars.stringAliasVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7390+
*/
7391+
bool <%lastIdentOfPath(name)%>::setReal(int handle, double& value)
7392+
{
7393+
switch(handle)
7394+
{
7395+
<%listAppend(vars.algVars, vars.paramVars) |>
7396+
var hasindex i0
7397+
fromindex intAdd(listLength(vars.stateVars), listLength(vars.derivativeVars))
7398+
=> setVariablesDefault(var, i0) ;separator="\n"%>
7399+
default:
7400+
return false;
7401+
}
7402+
}
7403+
7404+
bool <%lastIdentOfPath(name)%>::setInteger(int handle, int& value)
7405+
{
7406+
switch(handle)
7407+
{
7408+
<%listAppend( listAppend( vars.intAlgVars, vars.intParamVars ), vars.intAliasVars ) |>
7409+
var hasindex i0 fromindex 0 => setVariablesDefault(var, i0)
7410+
;separator="\n"%>
7411+
default:
7412+
return false;
7413+
}
7414+
}
7415+
7416+
bool <%lastIdentOfPath(name)%>::setBoolean(int handle, bool& value)
7417+
{
7418+
switch(handle)
7419+
{
7420+
<%listAppend( listAppend( vars.boolAlgVars, vars.boolParamVars ), vars.boolAliasVars ) |>
7421+
var hasindex i0 fromindex 0 => setVariablesDefault(var, i0)
7422+
;separator="\n"%>
7423+
default:
7424+
return false;
7425+
}
7426+
}
7427+
/*
7428+
<%System.tmpTickReset(0)%>
7429+
<%vars.stringAlgVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7430+
<%vars.stringParamVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7431+
<%vars.stringAliasVars |> var => giveVariablesDefault(var, System.tmpTick()) ;separator="\n"%>
7432+
*/
7433+
>>
7434+
end giveVariables;
7435+
7436+
template giveVariablesState(SimVar simVar, Integer valueReference, String arrayName, Integer index)
7437+
"Generates code for getting variables in cpp target for use in FMU. "
7438+
::=
7439+
match simVar
7440+
case SIMVAR(__) then
7441+
let description = if comment then '// "<%comment%>"'
7442+
<<
7443+
case <%valueReference%> : value = <%arrayName%>[<%index%>]; return true; <%description%>
7444+
>>
7445+
end giveVariablesState;
7446+
7447+
template giveVariablesDefault(SimVar simVar, Integer valueReference)
7448+
"Generates code for getting variables in cpp target for use in FMU. "
7449+
::=
7450+
match simVar
7451+
case SIMVAR(__) then
7452+
let description = if comment then '// "<%comment%>"'
7453+
<<
7454+
case <%valueReference%> : value = <%cref(name)%>; return true; <%description%>
7455+
>>
7456+
end giveVariablesDefault;
7457+
7458+
template setVariablesDefault(SimVar simVar, Integer valueReference)
7459+
"Generates code for getting variables in cpp target for use in FMU. "
7460+
::=
7461+
match simVar
7462+
case SIMVAR(__) then
7463+
let description = if comment then '// "<%comment%>"'
7464+
let variablename = cref(name)
7465+
match causality
7466+
case INPUT() then
7467+
<<
7468+
case <%valueReference%> : <%variablename%> = value; return true; <%description%>
7469+
>>
7470+
else
7471+
<<
7472+
//case <%valueReference%> : <%variablename%> = value; return true; // not an input
7473+
>>
7474+
end match
7475+
end setVariablesDefault;
73337476

73347477

73357478
end CodegenCpp;
7479+

0 commit comments

Comments
 (0)