Skip to content

Commit

Permalink
janitor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm authored and adrpo committed Jan 23, 2020
1 parent 932130d commit 315a2d2
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 131 deletions.
26 changes: 13 additions & 13 deletions OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1819,18 +1819,18 @@ only to get the functionsTree.
output BackendDAE.EqSystem oSyst;

protected
array<Integer> ass1, ass2;
BackendDAE.Variables v;
BackendDAE.EqSystem syst;
BackendDAE.Variables iVars = BackendVariable.listVar(iVarlst);
BackendDAE.EquationArray ordererdEqs, arrEqs;
list<Integer> indx_lst_v, indx_lst_e, ind_mark, statevarindx_lst;
array<Integer> indx_arr;
list<BackendDAE.Equation> el;
list<BackendDAE.Var> vl;

DAE.FunctionTree funcs;
BackendDAE.IncidenceMatrix m;
array<Integer> ass1, ass2;
BackendDAE.Variables v;
BackendDAE.EqSystem syst;
BackendDAE.Variables iVars = BackendVariable.listVar(iVarlst);
BackendDAE.EquationArray ordererdEqs, arrEqs;
list<Integer> indx_lst_v, indx_lst_e, ind_mark, statevarindx_lst;
array<Integer> indx_arr;
list<BackendDAE.Equation> el;
list<BackendDAE.Var> vl;

DAE.FunctionTree funcs;
BackendDAE.IncidenceMatrix m;
algorithm
oSyst := match iSyst
case syst as BackendDAE.EQSYSTEM( orderedEqs=ordererdEqs, orderedVars=v,
Expand Down Expand Up @@ -1861,7 +1861,7 @@ algorithm
syst.orderedVars := BackendVariable.listVar1(vl);
syst.orderedEqs := arrEqs;
syst.stateSets := {};
then BackendDAEUtil.clearEqSyst(syst);
then clearEqSyst(syst);
end match;
end reduceEqSystem;

Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -451,8 +451,8 @@ algorithm
case DAE.CREF(componentRef = cr)
algorithm
try
(_, ilst) := BackendVariable.getVar(cr, vars);
tree := AvlSetInt.addList(tree, ilst);
(_, ilst) := BackendVariable.getVar(cr, vars);
tree := AvlSetInt.addList(tree, ilst);
else
end try;
then (true, tree);
Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -2467,24 +2467,24 @@ algorithm
BackendDAE.VARIABLES(varArr=BackendDAE.VARIABLE_ARRAY(numberOfElements=outNumVariables)) := inVariables;
end varsSize;

/*
public function varDim
"Returns the dimension of variables in the Variables structure.
NOTE: function fail if dimension is not constant
"
input BackendDAE.Var inVar;
output Integer outDimVariables = 1;
protected
protected
DAE.Dimensions dims;
Integer n;
algorithm

BackendDAE.VAR(arryDim=dims) := inVar;
for dim in dims loop
DAE.DIM_INTEGER(n) := dim;
outDimVariables := n * outDimVariables;
outDimVariables := n * outDimVariables;
end for;

end varDim;
*/

protected function varsLoadFactor
input BackendDAE.Variables inVariables;
Expand Down
9 changes: 4 additions & 5 deletions OMCompiler/Compiler/BackEnd/Differentiate.mo
Expand Up @@ -1368,7 +1368,6 @@ algorithm
DAE.FunctionTree funcs;

Integer i;
Boolean b;

list<Boolean> blst;
list<DAE.ComponentRef> crefs;
Expand Down Expand Up @@ -1416,11 +1415,11 @@ algorithm
cr = ComponentReference.createDifferentiatedCrefName(cr, inDiffwrtCref, matrixName);
res = Expression.makeCrefExp(cr, tp);

b = ComponentReference.crefEqual(DAE.CREF_IDENT("$",DAE.T_REAL_DEFAULT,{}), inDiffwrtCref);
(zero,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
res = if b then zero else res;
if ComponentReference.crefEqual(DAE.CREF_IDENT("$",DAE.T_REAL_DEFAULT,{}), inDiffwrtCref) then
(res,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
end if;
then
(res, inFunctionTree);
(res, inFunctionTree);

/* Differentiate with respect to DAE.CREF_IDENT(ident="$") demands zero expressions */
case (DAE.CALL(path=Absyn.IDENT(name = "der"),expLst = {e}), DAE.CREF_IDENT(ident="$"), _, _, _)
Expand Down
43 changes: 20 additions & 23 deletions OMCompiler/Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1910,17 +1910,14 @@ public function crefLastSubs "Return the last subscripts of a ComponentRef"
input DAE.ComponentRef inComponentRef;
output list<DAE.Subscript> outSubscriptLst;
algorithm
outSubscriptLst := match (inComponentRef)
outSubscriptLst := match inComponentRef
local
DAE.Ident id;
list<DAE.Subscript> subs;
DAE.ComponentRef cr;

case (DAE.CREF_IDENT(subscriptLst=subs))
then subs;

case (DAE.CREF_QUAL(componentRef=cr)) equation
then crefLastSubs(cr);
case DAE.CREF_IDENT(subscriptLst = subs)
then subs;
case DAE.CREF_QUAL(componentRef = cr)
then crefLastSubs(cr);
end match;
end crefLastSubs;

Expand Down Expand Up @@ -4006,29 +4003,29 @@ public function createDifferentiatedCrefName
input String inMatrixName;
output DAE.ComponentRef outCref;
protected
list<DAE.Subscript> subs;
constant Boolean debug = false;
list<DAE.Subscript> subs;
constant Boolean debug = false;
algorithm
if debug then print("inCref: " + ComponentReference.printComponentRefStr(inCref) +"\n"); end if;
if debug then print("inCref: " + printComponentRefStr(inCref) + "\n"); end if;

// move subs and and type to lastCref, to move type replace by last type
// and move last cref type to the last cref.
subs := ComponentReference.crefLastSubs(inCref);
outCref := ComponentReference.crefStripLastSubs(inCref);
outCref := ComponentReference.replaceSubsWithString(outCref);
if debug then print("after full type " + Types.printTypeStr(ComponentReference.crefTypeConsiderSubs(inCref)) + "\n"); end if;
outCref := ComponentReference.crefSetLastType(outCref, DAE.T_UNKNOWN_DEFAULT);
if debug then print("after strip: " + ComponentReference.printComponentRefListStr(ComponentReference.expandCref(outCref, true)) + "\n"); end if;
subs := crefLastSubs(inCref);
outCref := crefStripLastSubs(inCref);
outCref := replaceSubsWithString(outCref);
if debug then print("after full type: " + Types.printTypeStr(crefTypeFull(crefStripIterSub(outCref))) + "\n"); end if;
outCref := crefSetLastType(outCref, DAE.T_UNKNOWN_DEFAULT);
if debug then print("after strip: " + printComponentRefListStr(expandCref(outCref, true)) + "\n"); end if;

// join crefs
outCref := ComponentReference.joinCrefs(outCref, ComponentReference.makeCrefIdent(DAE.partialDerivativeNamePrefix + inMatrixName, DAE.T_UNKNOWN_DEFAULT, {}));
outCref := ComponentReference.joinCrefs(outCref, inX);
if debug then print("after join: " + ComponentReference.printComponentRefListStr(ComponentReference.expandCref(outCref, true)) + "\n"); end if;
outCref := joinCrefs(outCref, makeCrefIdent(DAE.partialDerivativeNamePrefix + inMatrixName, DAE.T_UNKNOWN_DEFAULT, {}));
outCref := joinCrefs(outCref, inX);
if debug then print("after join: " + printComponentRefListStr(expandCref(outCref, true)) + "\n"); end if;

// fix subs and type of the last cref
outCref := ComponentReference.crefSetLastSubs(outCref, subs);
outCref := ComponentReference.crefSetLastType(outCref, ComponentReference.crefLastType(inCref));
if debug then print("outCref: " + ComponentReference.printComponentRefStr(outCref) +"\n"); end if;
outCref := crefSetLastSubs(outCref, subs);
outCref := crefSetLastType(outCref, crefLastType(inCref));
if debug then print("outCref: " + printComponentRefStr(outCref) + "\n"); end if;
end createDifferentiatedCrefName;

annotation(__OpenModelica_Interface="frontend");
Expand Down
25 changes: 11 additions & 14 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -363,9 +363,7 @@ algorithm
FlagsUtil.setConfigEnum(Flags.SYM_SOLVER, 0);
end if;

if not (Config.simCodeTarget() == "omsic" or
Config.simCodeTarget() == "omsicpp")
then
if not (Config.simCodeTarget() == "omsic" or Config.simCodeTarget() == "omsicpp") then
(uniqueEqIndex, odeEquations, algebraicEquations, localKnownVars, allEquations, equationsForZeroCrossings, tempvars,
equationSccMapping, eqBackendSimCodeMapping, backendMapping, sccOffset) :=
createEquationsForSystems(contSysts, shared, uniqueEqIndex, zeroCrossings, tempvars, 1, backendMapping, true);
Expand Down Expand Up @@ -642,7 +640,7 @@ algorithm
execStat("simCode: some other stuff during SimCode phase");


if ((Config.simCodeTarget() <> "Cpp") and (Config.simCodeTarget()<>"omsicpp"))then
if (Config.simCodeTarget() <> "Cpp") and (Config.simCodeTarget() <> "omsicpp") then
reasonableSize := Util.nextPrime(10+integer(1.4*(BackendDAEUtil.equationArraySizeBDAE(inBackendDAE)+BackendDAEUtil.equationArraySizeBDAE(inInitDAE)+listLength(parameterEquations))));
eqCache := HashTableSimCodeEqCache.emptyHashTableSized(reasonableSize);

Expand Down Expand Up @@ -4684,22 +4682,22 @@ algorithm
SimCode.JacobianMatrix tmpJac;
list<String> matrixnames;
case (_, _, _)
equation
// b = FlagsUtil.disableDebug(Flags.EXEC_STAT);
crefSimVarHT = createCrefToSimVarHT(inModelInfo);
algorithm
// b := FlagsUtil.disableDebug(Flags.EXEC_STAT);
crefSimVarHT := createCrefToSimVarHT(inModelInfo);
// The jacobian code requires single systems;
// I did not rewrite it to take advantage of any parallelism in the code

// This is used to set the matrixnames for Linearization and DataReconciliation procedure
// For dataReconciliation F is set in earlier order which cause index problem for linearization matrix and hence identify if
// dataReconciliation is involved and pass the matrix names
if Util.isSome(shared.dataReconciliationData) then
matrixnames={"A", "B", "C", "D"};
matrixnames := {"A", "B", "C", "D"};
else
matrixnames={"A", "B", "C", "D", "F"};
matrixnames := {"A", "B", "C", "D", "F"};
end if;
(res, ouniqueEqIndex) = createSymbolicJacobianssSimCode(inSymjacs, crefSimVarHT, iuniqueEqIndex, matrixnames, {});
// _ = FlagsUtil.set(Flags.EXEC_STAT, b);
(res, ouniqueEqIndex) := createSymbolicJacobianssSimCode(inSymjacs, crefSimVarHT, iuniqueEqIndex, matrixnames, {});
// _ := FlagsUtil.set(Flags.EXEC_STAT, b);
then (res,ouniqueEqIndex);
end match;
end createJacobianLinearCode;
Expand All @@ -4712,7 +4710,6 @@ algorithm
case (NONE())
then true;
case (SOME((_,_,{},{},{},_)))
equation
then true;
else
false;
Expand Down Expand Up @@ -14190,7 +14187,7 @@ protected
DAE.ComponentRef badcref;
algorithm
try
SimCode.SIMCODE(crefToSimVarHT = crefToSimVarHT) := simCode;
SimCode.SIMCODE(crefToSimVarHT = crefToSimVarHT) := simCode;
outSimVar := simVarFromHT(inCref, crefToSimVarHT);
else
//print("cref2simvar: " + ComponentReference.printComponentRefStr(inCref) + " not found!\n");
Expand All @@ -14208,7 +14205,6 @@ protected
DAE.ComponentRef cref, badcref;
SimCodeVar.SimVar sv;
list<DAE.Subscript> subs;
Integer index;
algorithm
try
if BaseHashTable.hasKey(inCref, crefToSimVarHT) then
Expand All @@ -14226,6 +14222,7 @@ algorithm
end if;

sv.variable_index := match sv.variable_index
local Integer index;
case SOME(index)
then SOME(index + getScalarElementIndex(subs, List.map(sv.numArrayElement, stringInt)) - 1);
end match;
Expand Down

0 comments on commit 315a2d2

Please sign in to comment.