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

Commit fd5058e

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
fixing ticket:4237: Support of clockPartitions in jacobians
- rewrite the SimCode jacobian tuple to records - added partitionIndex to jacobians
1 parent 576ecd3 commit fd5058e

File tree

11 files changed

+306
-263
lines changed

11 files changed

+306
-263
lines changed

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,18 +3543,18 @@ protected function TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate "author: Wau
35433543
algorithm
35443544
(jacOut,tplOut) := matchcontinue(jacIn,tplIn)
35453545
local
3546-
Integer maxCol,jacIdx;
3546+
Integer maxCol,jacIdx,partIdx;
35473547
list<SimCode.JacobianColumn> jacCols;
35483548
list<SimCodeVar.SimVar> vars;
35493549
String name;
3550-
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>> sparsePatt;
3550+
SimCode.SparsityPattern sparsity,sparsityT;
35513551
list<list<Integer>> colCols;
35523552
array<Integer> ass;
35533553
Integer newIdx;
3554-
case(SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),(newIdx,ass))
3554+
case(SOME(SimCode.JAC_MATRIX(jacCols,vars,name,sparsity,sparsityT,colCols,maxCol,jacIdx,partIdx)),(newIdx,ass))
35553555
equation
35563556
(jacCols,(newIdx,ass)) = List.mapFold(jacCols,TDS_replaceSimEqSysIdxInJacobianColumnWithUpdate,(newIdx,ass));
3557-
then (SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),(newIdx,ass));
3557+
then (SOME(SimCode.JAC_MATRIX(jacCols,vars,name,sparsity,sparsityT,colCols,maxCol,jacIdx,partIdx)),(newIdx,ass));
35583558
else (jacIn,tplIn);
35593559
end matchcontinue;
35603560
end TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate;
@@ -3570,13 +3570,13 @@ algorithm
35703570
local
35713571
list<SimCode.SimEqSystem> simEqs;
35723572
list<SimCodeVar.SimVar> simVars;
3573-
String colLen;
3573+
Integer rowLen;
35743574
array<Integer> ass;
35753575
Integer newIdx;
3576-
case((simEqs,simVars,colLen),(newIdx,ass))
3576+
case (SimCode.JAC_COLUMN(simEqs,simVars,rowLen),(newIdx,ass))
35773577
equation
35783578
(simEqs,(newIdx,ass)) = List.mapFold(simEqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass));
3579-
then((simEqs,simVars,colLen),(newIdx,ass));
3579+
then (SimCode.JAC_COLUMN(simEqs,simVars,rowLen),(newIdx,ass));
35803580
else (jacIn,tplIn);
35813581
end matchcontinue;
35823582
end TDS_replaceSimEqSysIdxInJacobianColumnWithUpdate;
@@ -3585,22 +3585,15 @@ protected function TDS_replaceSimEqSysIdxInJacobianMatrix "author: Waurich TUD 2
35853585
Replaces the index with the assigned one in a jacobian matrix."
35863586
input Option<SimCode.JacobianMatrix> jacIn;
35873587
input array<Integer> assIn;
3588-
output Option<SimCode.JacobianMatrix> jacOut;
3588+
output Option<SimCode.JacobianMatrix> jacOut = jacIn;
35893589
algorithm
3590-
jacOut := matchcontinue(jacIn,assIn)
3590+
jacOut := matchcontinue(jacIn)
35913591
local
3592-
Integer maxCol,jacIdx;
3593-
list<SimCode.JacobianColumn> jacCols;
3594-
list<SimCodeVar.SimVar> vars;
3595-
String name;
3596-
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>> sparsePatt;
3597-
list<list<Integer>> colCols;
3598-
array<Integer> ass;
3599-
Integer newIdx;
3600-
case(SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),_)
3592+
SimCode.JacobianMatrix jacMatrix;
3593+
case SOME(jacMatrix as SimCode.JAC_MATRIX())
36013594
equation
3602-
jacCols = List.map1(jacCols,TDS_replaceSimEqSysIdxInJacobianColumn,assIn);
3603-
then SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx));
3595+
jacMatrix.columns = List.map1(jacMatrix.columns, TDS_replaceSimEqSysIdxInJacobianColumn, assIn);
3596+
then SOME(jacMatrix);
36043597
else jacIn;
36053598
end matchcontinue;
36063599
end TDS_replaceSimEqSysIdxInJacobianMatrix;
@@ -3609,21 +3602,9 @@ protected function TDS_replaceSimEqSysIdxInJacobianColumn "author: Waurich TUD 2
36093602
Replaces the index with the assigned one in a jacobian column."
36103603
input SimCode.JacobianColumn jacIn;
36113604
input array<Integer> assIn;
3612-
output SimCode.JacobianColumn jacOut;
3605+
output SimCode.JacobianColumn jacOut = jacIn;
36133606
algorithm
3614-
jacOut := matchcontinue(jacIn,assIn)
3615-
local
3616-
list<SimCode.SimEqSystem> simEqs;
3617-
list<SimCodeVar.SimVar> simVars;
3618-
String colLen;
3619-
array<Integer> ass;
3620-
Integer newIdx;
3621-
case((simEqs,simVars,colLen),_)
3622-
equation
3623-
simEqs = List.map1(simEqs,TDS_replaceSimEqSysIndex,assIn);
3624-
then ((simEqs,simVars,colLen));
3625-
else jacIn;
3626-
end matchcontinue;
3607+
jacOut.columnEqns := List.map1(jacOut.columnEqns, TDS_replaceSimEqSysIndex, assIn);
36273608
end TDS_replaceSimEqSysIdxInJacobianColumn;
36283609

36293610
protected function TDS_updateModelInfo "

Compiler/SimCode/SerializeModelInfo.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ algorithm
526526
j = listLength(lSystem.simJac);
527527

528528
jeqs = match lSystem.jacobianMatrix
529-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
529+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
530530
else {};
531531
end match;
532532
eqs = SimCodeUtil.sortEqSystems(listAppend(lSystem.residual,jeqs));
@@ -568,7 +568,7 @@ algorithm
568568
j = listLength(lSystem.simJac);
569569

570570
jeqs = match lSystem.jacobianMatrix
571-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
571+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
572572
else {};
573573
end match;
574574
eqs = SimCodeUtil.sortEqSystems(listAppend(lSystem.residual,jeqs));
@@ -607,7 +607,7 @@ algorithm
607607
j = listLength(atL.simJac);
608608

609609
jeqs = match atL.jacobianMatrix
610-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
610+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
611611
else {};
612612
end match;
613613
eqs = SimCodeUtil.sortEqSystems(listAppend(atL.residual,jeqs));
@@ -700,7 +700,7 @@ algorithm
700700
serializeEquation(file,listHead(eqs),section,withOperations,parent=nlSystem.index,first=true);
701701
min(serializeEquation(file,e,section,withOperations,parent=nlSystem.index) for e in List.rest(eqs));
702702
jeqs = match nlSystem.jacobianMatrix
703-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
703+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
704704
else {};
705705
end match;
706706
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
@@ -730,7 +730,7 @@ algorithm
730730
serializeEquation(file,listHead(eqs),section,withOperations,parent=nlSystem.index,first=true);
731731
min(serializeEquation(file,e,section,withOperations,parent=nlSystem.index) for e in List.rest(eqs));
732732
jeqs = match nlSystem.jacobianMatrix
733-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
733+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
734734
else {};
735735
end match;
736736
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
@@ -757,7 +757,7 @@ algorithm
757757
serializeEquation(file,listHead(eqs),section,withOperations,parent=atNL.index,first=true);
758758
min(serializeEquation(file,e,section,withOperations,parent=atNL.index) for e in List.rest(eqs));
759759
jeqs = match atNL.jacobianMatrix
760-
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
760+
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
761761
else {};
762762
end match;
763763
min(serializeEquation(file,e,section,withOperations) for e in jeqs);

Compiler/SimCode/SimCode.mo

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,32 @@ import SimCodeVar;
6565
type ExtConstructor = tuple<DAE.ComponentRef, String, list<DAE.Exp>>;
6666
type ExtDestructor = tuple<String, DAE.ComponentRef>;
6767
type ExtAlias = tuple<DAE.ComponentRef, DAE.ComponentRef>;
68-
type JacobianColumn = tuple<list<SimEqSystem>, list<SimCodeVar.SimVar>, String>; // column equations, column vars, column length
69-
type JacobianMatrix = tuple<list<JacobianColumn>, // column
70-
list<SimCodeVar.SimVar>, // seed vars
71-
String, // matrix name
72-
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>>, // sparse pattern
73-
list<list<Integer>>, // colored cols
74-
Integer, // max color used
75-
Integer>; // jacobian index
7668

69+
type SparsityPattern = list< tuple<Integer, list<Integer>> >;
70+
71+
uniontype JacobianColumn
72+
record JAC_COLUMN
73+
list<SimEqSystem> columnEqns; // column equations equals in size to column vars
74+
list<SimCodeVar.SimVar> columnVars; // all column vars, none results vars index -1, the other corresponding to rows index
75+
Integer numberOfResultVars; // corresponds to the number of rows
76+
end JAC_COLUMN;
77+
end JacobianColumn;
78+
79+
uniontype JacobianMatrix
80+
record JAC_MATRIX
81+
list<JacobianColumn> columns; // columns equations and variables
82+
list<SimCodeVar.SimVar> seedVars; // corresponds to the number of columns
83+
String matrixName; // unique matrix name
84+
SparsityPattern sparsity;
85+
SparsityPattern sparsityT;
86+
list<list<Integer>> coloredCols;
87+
Integer maxColorCols;
88+
Integer jacobianIndex;
89+
Integer partitionIndex;
90+
end JAC_MATRIX;
91+
end JacobianMatrix;
92+
93+
constant JacobianMatrix emptyJacobian = JAC_MATRIX({}, {}, "", {}, {}, {}, 0, -1, -1);
7794

7895
constant PartitionData emptyPartitionData = PARTITIONDATA(-1,{},{},{});
7996

0 commit comments

Comments
 (0)