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

Commit 05ebd2e

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Only consider Real variables for fmi2GetDirectionalDerivative
Integer and Boolean variables don't work because they appear cluttered in SIMVARS.inputVars and their FMI valueReference re-starts from 0. Belonging to [master]: - #2039 - OpenModelica/OpenModelica-testsuite#788
1 parent d4ea7ac commit 05ebd2e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Compiler/Template/CodegenFMUCpp.tpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,13 @@ case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, outputVars=ou
283283
return new <%modelShortName%>FMU(globalSettings, simObjects);
284284
}
285285

286-
// static model properties
286+
// value references of real inputs and outputs
287287
unsigned int <%modelShortName%>FMU::_inputRefs[] = {<%inputVars |> var =>
288-
match var case SIMVAR(name=name) then intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
288+
match var case SIMVAR(name=name, type_=T_REAL()) then
289+
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
289290
unsigned int <%modelShortName%>FMU::_outputRefs[] = {<%outputVars |> var =>
290-
match var case SIMVAR(name=name) then intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
291+
match var case SIMVAR(name=name, type_=T_REAL()) then
292+
intSub(getVariableIndex(cref2simvar(name, simCode)), 1) ;separator=", "%>};
291293

292294
// constructor
293295
<%modelShortName%>FMU::<%modelShortName%>FMU(IGlobalSettings* globalSettings, shared_ptr<ISimObjects> simObjects)
@@ -602,7 +604,7 @@ template directionalDerivativeFunction(SimCode simCode)
602604
"Generates getDirectionalDerivative."
603605
::=
604606
match simCode
605-
case SIMCODE(modelInfo=MODELINFO(varInfo=VARINFO(numInVars=numInVars, numOutVars=numOutVars))) then
607+
case SIMCODE(modelInfo=MODELINFO()) then
606608
let modelShortName = lastIdentOfPath(modelInfo.name)
607609
<<
608610
void <%modelShortName%>FMU::getDirectionalDerivative(
@@ -622,7 +624,7 @@ case SIMCODE(modelInfo=MODELINFO(varInfo=VARINFO(numInVars=numInVars, numOutVars
622624
// find input reference
623625
if (ref_p == NULL || idx < ref_1)
624626
ref_p = _inputRefs; // reset ref_p if vrKnown decreases
625-
ref_p = std::find(ref_p, _inputRefs + <%numInVars%>, vrKnown[j]);
627+
ref_p = std::find(ref_p, _inputRefs + sizeof(_inputRefs)/sizeof(unsigned int), vrKnown[j]);
626628
ref_1 = idx;
627629
idx = _dimContinuousStates + (ref_p - _inputRefs);
628630
}
@@ -638,7 +640,7 @@ case SIMCODE(modelInfo=MODELINFO(varInfo=VARINFO(numInVars=numInVars, numOutVars
638640
// find output reference
639641
if (ref_p == NULL || idx < ref_1)
640642
ref_p = _outputRefs; // reset ref_p if vrUnknown decreases
641-
ref_p = std::find(ref_p, _outputRefs + <%numOutVars%>, vrUnknown[i]);
643+
ref_p = std::find(ref_p, _outputRefs + sizeof(_outputRefs)/sizeof(unsigned int), vrUnknown[i]);
642644
ref_1 = idx;
643645
idx = _dimContinuousStates + (ref_p - _outputRefs);
644646
}

0 commit comments

Comments
 (0)