Skip to content

Commit

Permalink
Align variables to avoid unexpected behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Aug 24, 2017
1 parent 3ade197 commit 52b0a09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -816,6 +816,9 @@ protected
HashSet.HashSet hs;
list<DAE.ComponentRef> crefs;
algorithm
// lochel: workaround to align all elements
globalKnownVars := BackendVariable.listVar(BackendVariable.varList(globalKnownVars));

outInitVars := selectInitializationVariables(dae.eqs);
outInitVars := BackendVariable.traverseBackendDAEVars(dae.shared.globalKnownVars, selectInitializationVariables2, outInitVars);
outInitVars := BackendVariable.traverseBackendDAEVars(dae.shared.aliasVars, selectInitializationVariables2, outInitVars);
Expand Down Expand Up @@ -846,6 +849,7 @@ algorithm
// flattern list and look for cyclic dependencies
flatComps := list(flattenParamComp(comp, globalKnownVars) for comp in comps);
//BackendDump.dumpIncidenceRow(flatComps);
//BackendDump.dumpVariables(globalKnownVars, "globalKnownVars");

// select secondary parameters
secondary := arrayCreate(nGlobalKnownVars, 0);
Expand All @@ -857,6 +861,7 @@ algorithm
v := BackendVariable.getVarAt(globalKnownVars, i);
bindExp := BackendVariable.varBindExpStartValueNoFail(v);
crefs := Expression.getAllCrefsExpanded(bindExp);
//BackendDump.dumpVarList({v}, intString(i));

_ := match(v)
// primary parameter
Expand Down
17 changes: 11 additions & 6 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -1345,12 +1345,17 @@ protected
CreateEquationsForSystemsFold foldArg;
CreateEquationsForSystemsArg arg;
algorithm
arg := (shared, inAllZeroCrossings, createAlgebraicEquations);
foldArg := (iuniqueEqIndex, {}, {}, {}, {}, itempvars, {}, {}, iBackendMapping, iSccOffset);
(ouniqueEqIndex, oodeEquations, oalgebraicEquations, oallEquations, oequationsForZeroCrossings, otempvars,
oeqSccMapping, oeqBackendSimCodeMapping, obackendMapping, oSccOffset) := List.fold1(inSysts, createEquationsForSystems1, arg, foldArg);
oequationsForZeroCrossings := Dangerous.listReverseInPlace(oequationsForZeroCrossings);
((ouniqueEqIndex, olocalKnownVars)) := BackendVariable.traverseBackendDAEVars(shared.localKnownVars, traverseKnVarsToSimEqSystem, (ouniqueEqIndex, {}));
try
arg := (shared, inAllZeroCrossings, createAlgebraicEquations);
foldArg := (iuniqueEqIndex, {}, {}, {}, {}, itempvars, {}, {}, iBackendMapping, iSccOffset);
(ouniqueEqIndex, oodeEquations, oalgebraicEquations, oallEquations, oequationsForZeroCrossings, otempvars,
oeqSccMapping, oeqBackendSimCodeMapping, obackendMapping, oSccOffset) := List.fold1(inSysts, createEquationsForSystems1, arg, foldArg);
oequationsForZeroCrossings := Dangerous.listReverseInPlace(oequationsForZeroCrossings);
((ouniqueEqIndex, olocalKnownVars)) := BackendVariable.traverseBackendDAEVars(shared.localKnownVars, traverseKnVarsToSimEqSystem, (ouniqueEqIndex, {}));
else
Error.addInternalError("createEquationsForSystems failed", sourceInfo());
fail();
end try;
end createEquationsForSystems;

protected function createEquationsForSystems1
Expand Down

0 comments on commit 52b0a09

Please sign in to comment.