@@ -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 >>
306307end 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>>
23672375end generateMethodDeclarationCode;
23682376
@@ -7323,13 +7331,149 @@ end algStmtAssignArr;
73237331template 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." ::=
73287335match cr
73297336case CREF_IDENT(subscriptLst=subs as (_ :: _)) then
73307337 daeExpCrefRhsIndexSpec(subs, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
73317338end 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
73357478end CodegenCpp;
7479+
0 commit comments