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

Commit 399b730

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Use sorted variable references in Cpp fmi2GetDirectionalDerivative
Belonging to [master]: - #2287 - OpenModelica/OpenModelica-testsuite#879
1 parent ced7f13 commit 399b730

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

Compiler/Template/CodegenFMUCpp.tpl

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ template fmuModelCppFile(SimCode simCode,Text& extraFuncs,Text& extraFuncsDecl,T
207207
"Generates code for FMU target."
208208
::=
209209
match simCode
210-
case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVars, outputVars=outputVars)), modelStructure=modelStructure) then
210+
case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVars)), modelStructure=modelStructure) then
211211
let modelName = dotPath(modelInfo.name)
212212
let modelShortName = lastIdentOfPath(modelInfo.name)
213213
let modelLongName = System.stringReplace(modelName, ".", "_")
@@ -288,7 +288,10 @@ case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, algVars=algVa
288288
match var case SIMVAR(name=name, type_=T_REAL()) then
289289
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
290290
// value references of real discrete states and outputs
291-
unsigned int <%modelShortName%>FMU::_outputRefs[] = {<%DiscreteStateOutputRefs(modelStructure)%>};
291+
unsigned int <%modelShortName%>FMU::_outputRefs[] = {<%algVars |> var =>
292+
match var case SIMVAR(name=name, type_=T_REAL(), varKind=CLOCKED_STATE())
293+
case SIMVAR(name=name, type_=T_REAL(), causality=OUTPUT()) then
294+
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
292295

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

322-
template DiscreteStateOutputRefs(Option<FmiModelStructure> fmiModelStructure)
323-
"Generates list of value references of discrete states and outputs"
324-
::=
325-
match fmiModelStructure
326-
case SOME(modelStructure as FMIMODELSTRUCTURE(__)) then
327-
let discreteStateRefs = match modelStructure.fmiDiscreteStates
328-
case FMIDISCRETESTATES(fmiUnknownsList=fmiUnknownsList) then
329-
'<%fmiUnknownsList |> fmiUnknown => match fmiUnknown
330-
case FMIUNKNOWN(index=index) then intSub(index, 1) ;separator=", "%>'
331-
let outputRefs = match modelStructure.fmiOutputs
332-
case FMIOUTPUTS(fmiUnknownsList=fmiUnknownsList) then
333-
'<%fmiUnknownsList |> fmiUnknown => match fmiUnknown
334-
case FMIUNKNOWN(index=index) then intSub(index, 1) ;separator=", "%>'
335-
'<%discreteStateRefs%><%if intGt(stringLength(discreteStateRefs), 0) then ", "%><%outputRefs%>'
336-
end DiscreteStateOutputRefs;
337-
338325
template ModelDefineData(ModelInfo modelInfo)
339326
"Generates global data in simulation file."
340327
::=

0 commit comments

Comments
 (0)