Skip to content

Commit

Permalink
Use ExpandableArray for BackendDAE.EquationArray
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 14, 2017
1 parent 8429f94 commit 3eb1be0
Show file tree
Hide file tree
Showing 23 changed files with 388 additions and 633 deletions.
11 changes: 4 additions & 7 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -38,6 +38,7 @@ encapsulated package BackendDAE
import Absyn;
import DAE;
import DoubleEndedList;
import ExpandableArray;
import FCore;
import HashTable3;
import HashTableCG;
Expand Down Expand Up @@ -211,13 +212,7 @@ uniontype VariableArray "array of Equations are expandable, to amortize the cost
end VariableArray;

public
uniontype EquationArray
record EQUATION_ARRAY
Integer size "size of the Equations in scalar form";
Integer numberOfElement "no. elements";
array<Option<Equation>> equOptArr;
end EQUATION_ARRAY;
end EquationArray;
type EquationArray = ExpandableArray<Equation>;

public
uniontype Var "variables"
Expand Down Expand Up @@ -381,6 +376,8 @@ uniontype Equation
EquationAttributes attr;
end FOR_EQUATION;

record DUMMY_EQUATION
end DUMMY_EQUATION;
end Equation;

public
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -169,7 +169,7 @@ algorithm
));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
varSize := BackendVariable.varsSize(vars_1);
eqnSize := BackendDAEUtil.equationSize(eqnarr);
eqnSize := BackendEquation.equationArraySize(eqnarr);
neqStr := intString(eqnSize);
nvarStr := intString(varSize);

Expand Down
15 changes: 6 additions & 9 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -67,6 +67,7 @@ import DAEDump;
import Debug;
import Differentiate;
import ElementSource;
import ExpandableArray;
import Expression;
import ExpressionDump;
import ExpressionSolve;
Expand Down Expand Up @@ -4113,7 +4114,6 @@ protected
Integer ne,nv;
array<Integer> w_vars, w_eqns;
DAE.FunctionTree functionTree;
array<Option<BackendDAE.Equation>> equOptArr;
list<tuple<Integer,Integer>> tplIndexWeight;
list<Integer> indexs;
list<BackendDAE.Var> var_lst;
Expand All @@ -4136,7 +4136,7 @@ algorithm
end if;

BackendDAE.VARIABLES(varArr = BackendDAE.VARIABLE_ARRAY(numberOfElements = nv)) := vars;
BackendDAE.EQUATION_ARRAY(equOptArr = equOptArr, numberOfElement = ne) := eqns;
ne := ExpandableArray.getNumberOfElements(eqns);
//init weights
w_vars := arrayCreate(nv, -1);
w_eqns := arrayCreate(ne, -1);
Expand Down Expand Up @@ -4254,7 +4254,7 @@ algorithm

for syst in inDAE.eqs loop
BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns) := syst;
BackendDAE.EQUATION_ARRAY(numberOfElement = n) := eqns;
n := ExpandableArray.getNumberOfElements(eqns);
update := false;
indRemove := {};

Expand Down Expand Up @@ -4634,7 +4634,6 @@ protected
Inline.Functiontuple fns = (SOME(functionTree),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE(), DAE.DEFAULT_INLINE()});
Boolean inlined;
BackendDAE.Equation eq, eqNew;
Option<BackendDAE.Equation> eqn;
BackendDAE.EqSystem tmpEqs, tmpEqs1;
list<Integer> idEqns;
Boolean inlined1;
Expand All @@ -4644,7 +4643,6 @@ algorithm
inlined1 := false;
tmpEqs1 := BackendDAEUtil.createEqSystem( BackendVariable.listVar({}), BackendEquation.listEquation({}));
BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,matching=matching as BackendDAE.MATCHING(comps=comps),stateSets=stateSets,partitionKind=partitionKind) := syst;
//BackendDAE.EQUATION_ARRAY(equOptArr=equOptArr) := eqns;
for comp in comps
loop
if BackendEquation.isEquationsSystem(comp) or BackendEquation.isTornSystem(comp) or
Expand All @@ -4659,8 +4657,7 @@ algorithm
eq := BackendEquation.equationNth1(eqns, id);
//eqn := BackendInline.inlineEqOpt(SOME(eq), fns);
//eqns := BackendEquation.setAtIndexFirst(id, eq, eqns);
(eqn, tmpEqs, inlined, shared) := BackendInline.inlineEqOptAppend(SOME(eq), fns, shared);
SOME(eqNew) := eqn;
(eqNew, tmpEqs, inlined, shared) := BackendInline.inlineEqAppend_debug(eq, fns, shared);
if inlined or not BackendEquation.equationEqual(eq, eqNew)
then
tmpEqs1 := BackendDAEUtil.mergeEqSystems(tmpEqs, tmpEqs1);
Expand Down Expand Up @@ -4737,7 +4734,7 @@ algorithm
compOrders := {};
ii := 1;
BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,matching=matching as BackendDAE.MATCHING(comps=comps),stateSets=stateSets,partitionKind=partitionKind) := syst;
BackendDAE.EQUATION_ARRAY(numberOfElement=ne) := eqns;
ne := ExpandableArray.getNumberOfElements(eqns);
BackendDAE.VARIABLES(numberOfVars= nv) := vars;

for comp in comps loop
Expand Down Expand Up @@ -5131,7 +5128,7 @@ algorithm
outIndx := outIndx + 1;
outUpdate := update;
if not para then
BackendDAE.EQUATION_ARRAY(numberOfElement=ne) := inEqns;
ne := ExpandableArray.getNumberOfElements(inEqns);
BackendDAE.VARIABLES(numberOfVars= nv) := inVars;
ass1 := ne :: ass1;
ass2 := nv :: ass2;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -94,7 +94,7 @@ algorithm
case syst as BackendDAE.EQSYSTEM(mT=SOME(mt), matching=BackendDAE.MATCHING(ass1=ass1, ass2=ass2)) algorithm
comps_m := Sorting.TarjanTransposed(mt, ass2);

markarray := arrayCreate(BackendDAEUtil.equationArraySize(inSystem.orderedEqs), -1);
markarray := arrayCreate(BackendEquation.getNumberOfEquations(inSystem.orderedEqs), -1);
comps := analyseStrongComponentsScalar(comps_m, inSystem, inShared, ass1, ass2, mapEqnIncRow, mapIncRowEqn, 1, markarray);
GC.free(markarray);
ass1 := varAssignmentNonScalar(ass1, mapIncRowEqn);
Expand Down

0 comments on commit 3eb1be0

Please sign in to comment.