Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Use sorted variable references in Cpp fmi2GetDirectionalDerivative
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Mar 17, 2018
1 parent ced7f13 commit 399b730
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions Compiler/Template/CodegenFMUCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ template fmuModelCppFile(SimCode simCode,Text& extraFuncs,Text& extraFuncsDecl,T
"Generates code for FMU target."
::=
match simCode
case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVars, outputVars=outputVars)), modelStructure=modelStructure) then
case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVars)), modelStructure=modelStructure) then
let modelName = dotPath(modelInfo.name)
let modelShortName = lastIdentOfPath(modelInfo.name)
let modelLongName = System.stringReplace(modelName, ".", "_")
Expand Down Expand Up @@ -288,7 +288,10 @@ case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVa
match var case SIMVAR(name=name, type_=T_REAL()) then
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
// value references of real discrete states and outputs
unsigned int <%modelShortName%>FMU::_outputRefs[] = {<%DiscreteStateOutputRefs(modelStructure)%>};
unsigned int <%modelShortName%>FMU::_outputRefs[] = {<%algVars |> var =>
match var case SIMVAR(name=name, type_=T_REAL(), varKind=CLOCKED_STATE())
case SIMVAR(name=name, type_=T_REAL(), causality=OUTPUT()) then
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};

// constructor
<%modelShortName%>FMU::<%modelShortName%>FMU(IGlobalSettings* globalSettings, shared_ptr<ISimObjects> simObjects)
Expand Down Expand Up @@ -319,22 +322,6 @@ case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVa
// <%setExternalFunction(modelInfo)%>
end fmuModelCppFile;

template DiscreteStateOutputRefs(Option<FmiModelStructure> fmiModelStructure)
"Generates list of value references of discrete states and outputs"
::=
match fmiModelStructure
case SOME(modelStructure as FMIMODELSTRUCTURE(__)) then
let discreteStateRefs = match modelStructure.fmiDiscreteStates
case FMIDISCRETESTATES(fmiUnknownsList=fmiUnknownsList) then
'<%fmiUnknownsList |> fmiUnknown => match fmiUnknown
case FMIUNKNOWN(index=index) then intSub(index, 1) ;separator=", "%>'
let outputRefs = match modelStructure.fmiOutputs
case FMIOUTPUTS(fmiUnknownsList=fmiUnknownsList) then
'<%fmiUnknownsList |> fmiUnknown => match fmiUnknown
case FMIUNKNOWN(index=index) then intSub(index, 1) ;separator=", "%>'
'<%discreteStateRefs%><%if intGt(stringLength(discreteStateRefs), 0) then ", "%><%outputRefs%>'
end DiscreteStateOutputRefs;

template ModelDefineData(ModelInfo modelInfo)
"Generates global data in simulation file."
::=
Expand Down

0 comments on commit 399b730

Please sign in to comment.