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

Commit 91ff2aa

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

File tree

2 files changed

+50
-41
lines changed

2 files changed

+50
-41
lines changed

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: 33 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,14 @@ 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;
15071500
outAllEquations := inEq::inAllEquations;
1508-
outEquationsforZeroCrossings := if bzceqns then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
1501+
1502+
outOdeEquations := if bdynamic and not skipDiscrete then inEq::inOdeEquations else inOdeEquations;
1503+
// FIXME: actually discrete equtaions should be also skipable in the algebraic equations
1504+
// but currently the event handling with sample operator fail if they are skipped
1505+
outAlgebraicEquations := if not bdynamic then inEq::inAlgebraicEquations else inAlgebraicEquations;
1506+
outEquationsforZeroCrossings := if bzceqns and not skipDiscrete then inEq::inEquationsforZeroCrossings else inEquationsforZeroCrossings;
15091507
end addEquationsToLists;
15101508

15111509
protected function createEquationsForSystem1
@@ -1526,26 +1524,32 @@ protected
15261524
list<Integer> eqsIdx,varIdx;
15271525
list<BackendDAE.Var> varlst;
15281526
list<BackendDAE.Equation> eqnlst;
1529-
Boolean createAlgebraicEquations, bdynamic, skip;
1527+
Boolean createAlgebraicEquations, bdynamic, bzceqns, skip;
15301528
Boolean debug = false;
15311529
algorithm
15321530
(stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations) := inArg;
15331531
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15341532
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex) := inFold;
15351533
(varlst,varIdx,eqnlst,eqsIdx) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, syst.orderedVars, syst.orderedEqs);
1536-
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
15371534

15381535
skip := false;
15391536

1537+
// skip is when equations
1538+
skip := List.mapBoolAnd(eqnlst, BackendEquation.isWhenEquation);
1539+
// skip is discrete
1540+
skip := skip or List.mapBoolAnd(varlst, BackendVariable.isVarDiscrete);
1541+
1542+
// Do we need this equation in the ode block?
1543+
bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
1544+
// Do we need this equation to detect zerocrossings?
1545+
bzceqns := BackendDAEUtil.blockIsDynamic(eqsIdx, zceqnsmark);
1546+
15401547
if debug then
15411548
print("Proceed component: " + BackendDump.strongComponentString(comp) + "\n");
15421549
BackendDump.dumpEquationList(eqnlst,"Equations:");
15431550
BackendDump.dumpVarList(varlst,"Variables:");
1551+
print("Discrete equation: "+boolString(skip)+" \n");
15441552
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);
15491553

15501554
outFold := match comp
15511555
local
@@ -1558,6 +1562,7 @@ algorithm
15581562
list<SimCode.SimEqSystem> equations1, noDiscEquations1;
15591563
String message;
15601564

1565+
// case used for then inline solver, if "not createAlgebraicEquations = true"
15611566
case _ guard not (createAlgebraicEquations or bdynamic) or skip and not createAlgebraicEquations
15621567
then (uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15631568
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex);
@@ -1572,13 +1577,9 @@ algorithm
15721577
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
15731578
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1), {index}, backendMapping);
15741579
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;
1580+
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1581+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
1582+
algebraicEquations, allEquations, equationsforZeroCrossings);
15821583
then (uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
15831584
tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex + 1);
15841585

@@ -1594,7 +1595,7 @@ algorithm
15941595
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);
15951596

15961597
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1597-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1598+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
15981599
algebraicEquations, allEquations, equationsforZeroCrossings);
15991600
then
16001601
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1611,7 +1612,7 @@ algorithm
16111612
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);
16121613

16131614
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1614-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1615+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16151616
algebraicEquations, allEquations, equationsforZeroCrossings);
16161617
then
16171618
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1629,7 +1630,7 @@ algorithm
16291630
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping);
16301631

16311632
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1632-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1633+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16331634
algebraicEquations, allEquations, equationsforZeroCrossings);
16341635
then
16351636
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1664,7 +1665,7 @@ algorithm
16641665
eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
16651666

16661667
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1667-
addEquationsToLists(equations1, stateeqnsmark, zceqnsmark, {e}, odeEquations,
1668+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
16681669
algebraicEquations, allEquations, equationsforZeroCrossings);
16691670
then
16701671
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
@@ -1681,13 +1682,9 @@ algorithm
16811682
eqBackendSimCodeMapping = appendSccIdxRange(firstEqIndex, uniqueEqIndex1 - 1, index, eqBackendSimCodeMapping);
16821683
backendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex1 - 1),{index}, backendMapping);
16831684
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;
1685+
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1686+
addEquationsToLists(equations1, bdynamic, bzceqns, skip, odeEquations,
1687+
algebraicEquations, allEquations, equationsforZeroCrossings);
16911688
then
16921689
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,
16931690
eqSccMapping, eqBackendSimCodeMapping,backendMapping, sccIndex + 1);
@@ -1703,7 +1700,7 @@ algorithm
17031700
//eqSccMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, sccIndex, eqSccMapping);
17041701

17051702
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings) =
1706-
addEquationsToLists(noDiscEquations1, stateeqnsmark, zceqnsmark, eqnslst, odeEquations,
1703+
addEquationsToLists(noDiscEquations1, bdynamic, bzceqns, skip, odeEquations,
17071704
algebraicEquations, allEquations, equationsforZeroCrossings);
17081705
then
17091706
(uniqueEqIndex1, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, tempvars,

0 commit comments

Comments
 (0)