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

Commit

Permalink
Generate FMI model structure without dependencies for array vars
Browse files Browse the repository at this point in the history
This corrects the lists of derivatives, outputs and discrete states.

Belonging to [master]:
  - #2679
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Oct 4, 2018
1 parent dd5a6fd commit 0641eaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
9 changes: 2 additions & 7 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -104,13 +104,8 @@ algorithm
then (syst, comps);

else algorithm
if Flags.isSet(Flags.NF_SCALARIZE) then
Error.addInternalError("function strongComponentsScalar failed (sorting strong components)", sourceInfo());
fail();
else
Error.addCompilerWarning("BackendDAETransform.strongComponentsScalar failed (sorting strong components)");
end if;
then (inSystem, {});
Error.addInternalError("function strongComponentsScalar failed (sorting strong components)", sourceInfo());
then fail();
end matchcontinue;
end strongComponentsScalar;

Expand Down
51 changes: 25 additions & 26 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -12047,15 +12047,18 @@ else
// create empty model structure
try
// create empty derivatives dependencies
derivatives := list(createFmiUnknownFromSimVar(v,1) for v in inModelInfo.vars.derivativeVars);
derivatives := list(SimCode.FMIUNKNOWN(getVariableIndex(v), {}, {})
for v in getScalarVars(inModelInfo.vars.derivativeVars));

// create empty output dependencies
varsA := List.filterOnTrue(inModelInfo.vars.algVars, isOutputSimVar);
outputs := list(createFmiUnknownFromSimVar(v,1) for v in varsA);
outputs := list(SimCode.FMIUNKNOWN(getVariableIndex(v), {}, {})
for v in getScalarVars(varsA));

// create empty clockedStates dependencies
clockedStates := List.filterOnTrue(inModelInfo.vars.algVars, isClockedStateSimVar);
discreteStates := list(createFmiUnknownFromSimVar(v,1) for v in clockedStates);
discreteStates := list(SimCode.FMIUNKNOWN(getVariableIndex(v), {}, {})
for v in getScalarVars(clockedStates));

contPartSimDer := NONE();

Expand Down Expand Up @@ -12109,15 +12112,6 @@ algorithm
end match;
end isFmiUnknown;

protected function createFmiUnknownFromSimVar
"create a basic FMIUNKNOWN without dependencies from a SimVar"
input SimCodeVar.SimVar var;
input Integer indexOffset;
output SimCode.FmiUnknown unknown;
algorithm
unknown := SimCode.FMIUNKNOWN(var.index + indexOffset, {}, {});
end createFmiUnknownFromSimVar;

protected function translateSparsePatterInts2FMIUnknown
"function translates simVar integers to fmi unknowns."
input list<tuple<Integer, list<Integer>>> inSparsePattern;
Expand Down Expand Up @@ -12235,7 +12229,7 @@ algorithm
numElems := numElems * stringInt(listGet(var.numArrayElement, i));
end for;
then numElems;
else then 1;
else 1;
end match;
end getNumElems;

Expand All @@ -12249,25 +12243,18 @@ function getScalarElements
protected
list<Integer> dims;
SimCodeVar.SimVar elt;
list<DAE.Subscript> subs;
Integer index = 0;
Integer index;
algorithm
// create list of elements
elts := match var
case SimCodeVar.SIMVAR(type_ = DAE.T_ARRAY()) algorithm
case SimCodeVar.SIMVAR(type_ = DAE.T_ARRAY(), variable_index = SOME(index)) algorithm
dims := List.map(List.lastN(var.numArrayElement, listLength(var.numArrayElement)), stringInt);
elt := var;
elt.type_ := Types.arrayElementType(var.type_);
subs := {};
elts := {};
then fillScalarElements(elt, dims, 1, subs, elts);
else then {var};
end match;
// set variable indices
(elts, index) := match var
case SimCodeVar.SIMVAR(variable_index = SOME(index))
then setVariableIndexHelper(elts, index);
else (elts, index);
elts := fillScalarElements(elt, dims, 1, {}, {});
elts := setVariableIndexHelper(elts, index);
then elts;
else {var};
end match;
end getScalarElements;

Expand Down Expand Up @@ -12308,6 +12295,18 @@ algorithm
end for;
end fillScalarElements;

protected
function getScalarVars
"Expand all arrays in a vector of SimVars. author: rfranke"
input list<SimCodeVar.SimVar> inVars;
output list<SimCodeVar.SimVar> outVars;
algorithm
outVars := {};
for var in inVars loop
outVars := listAppend(outVars, getScalarElements(var));
end for;
end getScalarVars;

public function getVariableIndex
input SimCodeVar.SimVar inVar;
output Integer outVariableIndex;
Expand Down

0 comments on commit 0641eaf

Please sign in to comment.