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

Commit 88fda20

Browse files
author
Willi Braun
committed
[Backend] Skip all discrete equations in the ODE block
1 parent baf7ba4 commit 88fda20

2 files changed

Lines changed: 47 additions & 41 deletions

File tree

Compiler/BackEnd/HpcOmTaskGraph.mo

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,15 @@ protected
802802
BackendDAE.StrongComponents comps;
803803
BackendDAE.Matching matching;
804804
BackendDAE.EquationArray orderedEqs;
805+
BackendDAE.Variables systVars;
805806
list<Integer> eventEqs;
806807
list<Integer> eventEqsIn;
807808
Integer offset;
808809
algorithm
809-
BackendDAE.EQSYSTEM(orderedEqs=orderedEqs,matching=matching) := systIn;
810+
BackendDAE.EQSYSTEM(orderedEqs=orderedEqs,orderedVars=systVars,matching=matching) := systIn;
810811
comps := BackendDAEUtil.getCompsOfMatching(matching);
811812
(eventEqsIn,offset) := eventInfoIn;
812-
eventEqs := getEventNodeEqs1(comps,offset,{});
813+
eventEqs := getEventNodeEqs1(comps,orderedEqs,systVars,offset,{});
813814
offset := offset+ExpandableArray.getNumberOfElements(orderedEqs);
814815
eventEqs := listAppend(eventEqs,eventEqsIn);
815816
eventInfoOut := (eventEqs,offset);
@@ -818,6 +819,8 @@ end getEventNodeEqs;
818819
protected function getEventNodeEqs1 "author: Waurich TUD 2013-06
819820
Fold-function for getEventNodeEqs to compute the when equation in an eqSystem."
820821
input BackendDAE.StrongComponents comps;
822+
input BackendDAE.EquationArray orderedEqs;
823+
input BackendDAE.Variables systVars;
821824
input Integer offset;
822825
input list<Integer> eventEqsIn;
823826
output list<Integer> eventEqsOut;
@@ -827,21 +830,30 @@ algorithm
827830
Integer eqn;
828831
Integer sysCount;
829832
list<Integer> eventEqs;
830-
list<Integer> condVars;
833+
list<BackendDAE.Var> eqnVars;
831834
BackendDAE.StrongComponents rest;
832835
BackendDAE.StrongComponent head;
833836
case((head::rest),_,_)
834837
equation
835838
true = isWhenEquation(head);
836839
BackendDAE.SINGLEWHENEQUATION(eqn = eqn) = head;
837840
eqn = eqn+offset;
838-
eventEqs = getEventNodeEqs1(rest,offset,eqn::eventEqsIn);
841+
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eqn::eventEqsIn);
842+
then
843+
eventEqs;
844+
// discrete variables
845+
case((head::rest),_,_)
846+
equation
847+
(eqnVars,_,_,eventEqs) = BackendDAEUtil.getStrongComponentVarsAndEquations(head, systVars, orderedEqs);
848+
true = List.mapBoolAnd(eqnVars, BackendVariable.isVarDiscrete);
849+
eventEqs = list(i+offset for i in eventEqs);
850+
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,listAppend(eventEqs,eventEqsIn));
839851
then
840852
eventEqs;
841853
case((head::rest),_,_)
842854
equation
843855
false = isWhenEquation(head);
844-
eventEqs = getEventNodeEqs1(rest,offset,eventEqsIn);
856+
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eventEqsIn);
845857
then
846858
eventEqs;
847859
case({},_,_)

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,9 @@ end createEquationsForSystem;
14851485

14861486
protected function addEquationsToLists
14871487
input list<SimCode.SimEqSystem> inEq;
1488-
input array<Integer> stateeqnsmark;
1489-
input array<Integer> zceqnsmark;
1490-
input list<Integer> eqsIdx;
1488+
input Boolean bdynamic;
1489+
input Boolean bzceqns;
1490+
input Boolean skipDiscrete;
14911491
input list<list<SimCode.SimEqSystem>> inOdeEquations;
14921492
input list<list<SimCode.SimEqSystem>> inAlgebraicEquations;
14931493
input list<list<SimCode.SimEqSystem>> inAllEquations;
@@ -1496,16 +1496,11 @@ protected function addEquationsToLists
14961496
output list<list<SimCode.SimEqSystem>> outAlgebraicEquations;
14971497
output list<list<SimCode.SimEqSystem>> outAllEquations;
14981498
output list<list<SimCode.SimEqSystem>> outEquationsforZeroCrossings;
1499-
protected
1500-
Boolean bdynamic "block is dynamic, belongs to dynamic section";
1501-
Boolean bzceqns "block needs to evaluate zeroCrossings";
15021499
algorithm
1503-
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
1504-
bzceqns := BackendDAEUtil.blockIsDynamic(eqsIdx, zceqnsmark);
1505-
outOdeEquations := if bdynamic then inEq::inOdeEquations else inOdeEquations;
1506-
outAlgebraicEquations := if not bdynamic then inEq::inAlgebraicEquations else inAlgebraicEquations;
1500+
outOdeEquations := if bdynamic and not skipDiscrete then inEq::inOdeEquations else inOdeEquations;
1501+
outAlgebraicEquations := if not bdynamic and not skipDiscrete then inEq::inAlgebraicEquations else inAlgebraicEquations;
15071502
outAllEquations := inEq::inAllEquations;
1508-
outEquationsforZeroCrossings := if bzceqns then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
1503+
outEquationsforZeroCrossings := if bzceqns and not skipDiscrete then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
15091504
end addEquationsToLists;
15101505

15111506
protected function createEquationsForSystem1
@@ -1526,26 +1521,32 @@ protected
15261521
list<Integer> eqsIdx,varIdx;
15271522
list<BackendDAE.Var> varlst;
15281523
list<BackendDAE.Equation> eqnlst;
1529-
Boolean createAlgebraicEquations, bdynamic, skip;
1524+
Boolean createAlgebraicEquations, bdynamic, bzceqns, skip;
15301525
Boolean debug = false;
15311526
algorithm
15321527
(stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations) := inArg;
15331528
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15341529
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex) := inFold;
15351530
(varlst,varIdx,eqnlst,eqsIdx) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, syst.orderedVars, syst.orderedEqs);
1536-
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
15371531

15381532
skip := false;
15391533

1534+
// skip is when equations
1535+
skip := List.mapBoolAnd(eqnlst, BackendEquation.isWhenEquation);
1536+
// skip is discrete
1537+
skip := skip or List.mapBoolAnd(varlst, BackendVariable.isVarDiscrete);
1538+
1539+
// Do we need this equation in the ode block?
1540+
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
1541+
// Do we need this equation to detect zerocrossings?
1542+
bzceqns := BackendDAEUtil.blockIsDynamic(eqsIdx, zceqnsmark);
1543+
15401544
if debug then
15411545
print("Proceed component: " + BackendDump.strongComponentString(comp) + "\n");
15421546
BackendDump.dumpEquationList(eqnlst,"Equations:");
15431547
BackendDump.dumpVarList(varlst,"Variables:");
1548+
print("Discrete equation: "+boolString(skip)+" \n");
15441549
end if;
1545-
// skip is when equations
1546-
skip := List.mapBoolAnd(eqnlst, BackendEquation.isWhenEquation);
1547-
// skip is discrete
1548-
skip := skip or List.mapBoolAnd(varlst, BackendVariable.isVarDiscrete);
15491550

15501551
outFold := match comp
15511552
local
@@ -1558,6 +1559,7 @@ algorithm
15581559
list<SimCode.SimEqSystem> equations1, noDiscEquations1;
15591560
String message;
15601561

1562+
// case used for then inline solver, if "not createAlgebraicEquations = true"
15611563
case _ guard not (createAlgebraicEquations or bdynamic) or skip and not createAlgebraicEquations
15621564
then (uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15631565
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex);
@@ -1572,13 +1574,9 @@ algorithm
15721574
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
15731575
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1), {index}, backendMapping);
15741576
end if;
1575-
if BackendEquation.isWhenEquation(BackendEquation.get(syst.orderedEqs, index)) then
1576-
allEquations = equations1::allEquations;
1577-
else
1578-
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1579-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {index}, odeEquations,
1580-
algebraicEquations, allEquations, equationsforZeroCrossings);
1581-
end if;
1577+
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1578+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
1579+
algebraicEquations, allEquations, equationsforZeroCrossings);
15821580
then (uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15831581
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex + 1);
15841582

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

15961594
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1597-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1595+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
15981596
algebraicEquations, allEquations, equationsforZeroCrossings);
15991597
then
16001598
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1611,7 +1609,7 @@ algorithm
16111609
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);
16121610

16131611
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1614-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1612+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16151613
algebraicEquations, allEquations, equationsforZeroCrossings);
16161614
then
16171615
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1629,7 +1627,7 @@ algorithm
16291627
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);
16301628

16311629
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1632-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1630+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16331631
algebraicEquations, allEquations, equationsforZeroCrossings);
16341632
then
16351633
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1664,7 +1662,7 @@ algorithm
16641662
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
16651663

16661664
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1667-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1665+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16681666
algebraicEquations, allEquations, equationsforZeroCrossings);
16691667
then
16701668
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1681,13 +1679,9 @@ algorithm
16811679
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
16821680
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1),{index}, backendMapping);
16831681
end if;
1684-
if BackendEquation.isWhenEquation(BackendEquation.get(syst.orderedEqs, index)) then
1685-
allEquations = equations1::allEquations;
1686-
else
1687-
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1688-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {index}, odeEquations,
1689-
algebraicEquations, allEquations, equationsforZeroCrossings);
1690-
end if;
1682+
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1683+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
1684+
algebraicEquations, allEquations, equationsforZeroCrossings);
16911685
then
16921686
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,
16931687
eqSccMapping, eqBackendSimCodeMapping,backendMapping, sccIndex + 1);
@@ -1703,7 +1697,7 @@ algorithm
17031697
//eqSccMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, sccIndex, eqSccMapping);
17041698

17051699
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1706-
addEquationsToLists(noDiscEquations1, stateeqnsmark, zceqnsmark, eqnslst, odeEquations,
1700+
addEquationsToLists(noDiscEquations1, bdynamic, bzceqns, skip, odeEquations,
17071701
algebraicEquations, allEquations, equationsforZeroCrossings);
17081702
then
17091703
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,

0 commit comments

Comments
 (0)