Skip to content

Commit

Permalink
Use the index from the correct set
Browse files Browse the repository at this point in the history
Earlier, we did go through all variables in all equation systems in
order to find the indexes of initialization variables in the current
equation system. Now we check which variables in the current equation
system are initialization variables (and return the current index).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Dec 10, 2015
1 parent 87f3733 commit 7e7a75b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -2939,6 +2939,42 @@ algorithm
end try;
end traversingVarIndexFinder;

public function getVarIndexFromVariablesIndexInFirstSet
input BackendDAE.Variables inVariables;
input BackendDAE.Variables inVariables2;
output list<Integer> v_lst;
protected
array<list<Integer>> a;
algorithm
(a,_) := traverseBackendDAEVars(inVariables,
function traversingVarIndexInFirstSetFinder(inVars = inVariables2), (arrayCreate(1,{}),arrayCreate(1,1)));
v_lst := listReverse(a[1]);
end getVarIndexFromVariablesIndexInFirstSet;

protected function traversingVarIndexInFirstSetFinder
"author: Frenkel TUD 2010-11"
input BackendDAE.Var inVar;
input BackendDAE.Variables inVars;
input tuple<array<list<Integer>>,array<Integer>> inIndices;
output BackendDAE.Var outVar = inVar;
output tuple<array<list<Integer>>,array<Integer>> outIndices;
protected
DAE.ComponentRef cr;
list<Integer> indices1,indices2;
array<list<Integer>> l;
array<Integer> i;
algorithm
(l,i) := inIndices;
outIndices := inIndices;
try
cr := varCref(inVar);
getVar(cr, inVars);
l[1] := i[1]::l[1];
else
end try;
i[1] := i[1]+1;
end traversingVarIndexInFirstSetFinder;

public function mergeVariables
"Merges two sets of Variables, where the variables of the first set takes
precedence over the second set."
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -1220,11 +1220,11 @@ algorithm
(m_, _, _, mapIncRowEqn) := BackendDAEUtil.incidenceMatrixScalar(syst, BackendDAE.SOLVABLE(), SOME(funcs));
//BackendDump.dumpEqSystem(syst, "fixInitialSystem");
//BackendDump.dumpVariables(initVars, "selected initialization variables");
//BackendDump.dumpVariables(inEqSystem.orderedVars, "vars in the system");
//BackendDump.dumpIncidenceMatrix(m_);

// get state-index list
stateIndices := BackendVariable.getVarIndexFromVariables(inEqSystem.orderedVars, initVars);
//print("{" + stringDelimitList(List.map(stateIndices, intString), ",") + "}\n");
stateIndices := BackendVariable.getVarIndexFromVariablesIndexInFirstSet(inEqSystem.orderedVars, initVars);

// get initial equation-index list
//(initEqs, _) := List.extractOnTrue(BackendEquation.equationList(inEqSystem.orderedEqs), BackendEquation.isInitialEquation);
Expand Down

0 comments on commit 7e7a75b

Please sign in to comment.