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

Commit

Permalink
[Backend] Skip all discrete equations in the ODE block
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun committed Sep 10, 2018
1 parent baf7ba4 commit 88fda20
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
22 changes: 17 additions & 5 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,15 @@ protected
BackendDAE.StrongComponents comps;
BackendDAE.Matching matching;
BackendDAE.EquationArray orderedEqs;
BackendDAE.Variables systVars;
list<Integer> eventEqs;
list<Integer> eventEqsIn;
Integer offset;
algorithm
BackendDAE.EQSYSTEM(orderedEqs=orderedEqs,matching=matching) := systIn;
BackendDAE.EQSYSTEM(orderedEqs=orderedEqs,orderedVars=systVars,matching=matching) := systIn;
comps := BackendDAEUtil.getCompsOfMatching(matching);
(eventEqsIn,offset) := eventInfoIn;
eventEqs := getEventNodeEqs1(comps,offset,{});
eventEqs := getEventNodeEqs1(comps,orderedEqs,systVars,offset,{});
offset := offset+ExpandableArray.getNumberOfElements(orderedEqs);
eventEqs := listAppend(eventEqs,eventEqsIn);
eventInfoOut := (eventEqs,offset);
Expand All @@ -818,6 +819,8 @@ end getEventNodeEqs;
protected function getEventNodeEqs1 "author: Waurich TUD 2013-06
Fold-function for getEventNodeEqs to compute the when equation in an eqSystem."
input BackendDAE.StrongComponents comps;
input BackendDAE.EquationArray orderedEqs;
input BackendDAE.Variables systVars;
input Integer offset;
input list<Integer> eventEqsIn;
output list<Integer> eventEqsOut;
Expand All @@ -827,21 +830,30 @@ algorithm
Integer eqn;
Integer sysCount;
list<Integer> eventEqs;
list<Integer> condVars;
list<BackendDAE.Var> eqnVars;
BackendDAE.StrongComponents rest;
BackendDAE.StrongComponent head;
case((head::rest),_,_)
equation
true = isWhenEquation(head);
BackendDAE.SINGLEWHENEQUATION(eqn = eqn) = head;
eqn = eqn+offset;
eventEqs = getEventNodeEqs1(rest,offset,eqn::eventEqsIn);
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eqn::eventEqsIn);
then
eventEqs;
// discrete variables
case((head::rest),_,_)
equation
(eqnVars,_,_,eventEqs) = BackendDAEUtil.getStrongComponentVarsAndEquations(head, systVars, orderedEqs);
true = List.mapBoolAnd(eqnVars, BackendVariable.isVarDiscrete);
eventEqs = list(i+offset for i in eventEqs);
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,listAppend(eventEqs,eventEqsIn));
then
eventEqs;
case((head::rest),_,_)
equation
false = isWhenEquation(head);
eventEqs = getEventNodeEqs1(rest,offset,eventEqsIn);
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eventEqsIn);
then
eventEqs;
case({},_,_)
Expand Down
66 changes: 30 additions & 36 deletions Compiler/SimCode/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1485,9 +1485,9 @@ end createEquationsForSystem;

protected function addEquationsToLists
input list<SimCode.SimEqSystem> inEq;
input array<Integer> stateeqnsmark;
input array<Integer> zceqnsmark;
input list<Integer> eqsIdx;
input Boolean bdynamic;
input Boolean bzceqns;
input Boolean skipDiscrete;
input list<list<SimCode.SimEqSystem>> inOdeEquations;
input list<list<SimCode.SimEqSystem>> inAlgebraicEquations;
input list<list<SimCode.SimEqSystem>> inAllEquations;
Expand All @@ -1496,16 +1496,11 @@ protected function addEquationsToLists
output list<list<SimCode.SimEqSystem>> outAlgebraicEquations;
output list<list<SimCode.SimEqSystem>> outAllEquations;
output list<list<SimCode.SimEqSystem>> outEquationsforZeroCrossings;
protected
Boolean bdynamic "block is dynamic, belongs to dynamic section";
Boolean bzceqns "block needs to evaluate zeroCrossings";
algorithm
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
bzceqns := BackendDAEUtil.blockIsDynamic(eqsIdx, zceqnsmark);
outOdeEquations := if bdynamic then inEq::inOdeEquations else inOdeEquations;
outAlgebraicEquations := if not bdynamic then inEq::inAlgebraicEquations else inAlgebraicEquations;
outOdeEquations := if bdynamic and not skipDiscrete then inEq::inOdeEquations else inOdeEquations;
outAlgebraicEquations := if not bdynamic and not skipDiscrete then inEq::inAlgebraicEquations else inAlgebraicEquations;
outAllEquations := inEq::inAllEquations;
outEquationsforZeroCrossings := if bzceqns then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
outEquationsforZeroCrossings := if bzceqns and not skipDiscrete then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
end addEquationsToLists;

protected function createEquationsForSystem1
Expand All @@ -1526,26 +1521,32 @@ protected
list<Integer> eqsIdx,varIdx;
list<BackendDAE.Var> varlst;
list<BackendDAE.Equation> eqnlst;
Boolean createAlgebraicEquations, bdynamic, skip;
Boolean createAlgebraicEquations, bdynamic, bzceqns, skip;
Boolean debug = false;
algorithm
(stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations) := inArg;
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex) := inFold;
(varlst,varIdx,eqnlst,eqsIdx) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, syst.orderedVars, syst.orderedEqs);
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);

skip := false;

// skip is when equations
skip := List.mapBoolAnd(eqnlst, BackendEquation.isWhenEquation);
// skip is discrete
skip := skip or List.mapBoolAnd(varlst, BackendVariable.isVarDiscrete);

// Do we need this equation in the ode block?
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
// Do we need this equation to detect zerocrossings?
bzceqns := BackendDAEUtil.blockIsDynamic(eqsIdx, zceqnsmark);

if debug then
print("Proceed component: " + BackendDump.strongComponentString(comp) + "\n");
BackendDump.dumpEquationList(eqnlst,"Equations:");
BackendDump.dumpVarList(varlst,"Variables:");
print("Discrete equation: "+boolString(skip)+" \n");
end if;
// skip is when equations
skip := List.mapBoolAnd(eqnlst, BackendEquation.isWhenEquation);
// skip is discrete
skip := skip or List.mapBoolAnd(varlst, BackendVariable.isVarDiscrete);

outFold := match comp
local
Expand All @@ -1558,6 +1559,7 @@ algorithm
list<SimCode.SimEqSystem> equations1, noDiscEquations1;
String message;

// case used for then inline solver, if "not createAlgebraicEquations = true"
case _ guard not (createAlgebraicEquations or bdynamic) or skip and not createAlgebraicEquations
then (uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex);
Expand All @@ -1572,13 +1574,9 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1), {index}, backendMapping);
end if;
if BackendEquation.isWhenEquation(BackendEquation.get(syst.orderedEqs, index)) then
allEquations = equations1::allEquations;
else
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {index}, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
end if;
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then (uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex + 1);

Expand All @@ -1594,7 +1592,7 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);

(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
Expand All @@ -1611,7 +1609,7 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);

(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
Expand All @@ -1629,7 +1627,7 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);

(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
Expand Down Expand Up @@ -1664,7 +1662,7 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);

(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
Expand All @@ -1681,13 +1679,9 @@ algorithm
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1),{index}, backendMapping);
end if;
if BackendEquation.isWhenEquation(BackendEquation.get(syst.orderedEqs, index)) then
allEquations = equations1::allEquations;
else
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {index}, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
end if;
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,
eqSccMapping, eqBackendSimCodeMapping,backendMapping, sccIndex + 1);
Expand All @@ -1703,7 +1697,7 @@ algorithm
//eqSccMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, sccIndex, eqSccMapping);

(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
addEquationsToLists(noDiscEquations1, stateeqnsmark, zceqnsmark, eqnslst, odeEquations,
addEquationsToLists(noDiscEquations1, bdynamic, bzceqns, skip, odeEquations,
algebraicEquations, allEquations, equationsforZeroCrossings);
then
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,
Expand Down

0 comments on commit 88fda20

Please sign in to comment.