Skip to content

Commit

Permalink
fixing ticket:4237: Support of clockPartitions in jacobians
Browse files Browse the repository at this point in the history
- rewrite the SimCode jacobian tuple to records
- added partitionIndex to jacobians
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Jan 30, 2017
1 parent 576ecd3 commit fd5058e
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 263 deletions.
49 changes: 15 additions & 34 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -3543,18 +3543,18 @@ protected function TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate "author: Wau
algorithm
(jacOut,tplOut) := matchcontinue(jacIn,tplIn)
local
Integer maxCol,jacIdx;
Integer maxCol,jacIdx,partIdx;
list<SimCode.JacobianColumn> jacCols;
list<SimCodeVar.SimVar> vars;
String name;
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>> sparsePatt;
SimCode.SparsityPattern sparsity,sparsityT;
list<list<Integer>> colCols;
array<Integer> ass;
Integer newIdx;
case(SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),(newIdx,ass))
case(SOME(SimCode.JAC_MATRIX(jacCols,vars,name,sparsity,sparsityT,colCols,maxCol,jacIdx,partIdx)),(newIdx,ass))
equation
(jacCols,(newIdx,ass)) = List.mapFold(jacCols,TDS_replaceSimEqSysIdxInJacobianColumnWithUpdate,(newIdx,ass));
then (SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),(newIdx,ass));
then (SOME(SimCode.JAC_MATRIX(jacCols,vars,name,sparsity,sparsityT,colCols,maxCol,jacIdx,partIdx)),(newIdx,ass));
else (jacIn,tplIn);
end matchcontinue;
end TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate;
Expand All @@ -3570,13 +3570,13 @@ algorithm
local
list<SimCode.SimEqSystem> simEqs;
list<SimCodeVar.SimVar> simVars;
String colLen;
Integer rowLen;
array<Integer> ass;
Integer newIdx;
case((simEqs,simVars,colLen),(newIdx,ass))
case (SimCode.JAC_COLUMN(simEqs,simVars,rowLen),(newIdx,ass))
equation
(simEqs,(newIdx,ass)) = List.mapFold(simEqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass));
then((simEqs,simVars,colLen),(newIdx,ass));
then (SimCode.JAC_COLUMN(simEqs,simVars,rowLen),(newIdx,ass));
else (jacIn,tplIn);
end matchcontinue;
end TDS_replaceSimEqSysIdxInJacobianColumnWithUpdate;
Expand All @@ -3585,22 +3585,15 @@ protected function TDS_replaceSimEqSysIdxInJacobianMatrix "author: Waurich TUD 2
Replaces the index with the assigned one in a jacobian matrix."
input Option<SimCode.JacobianMatrix> jacIn;
input array<Integer> assIn;
output Option<SimCode.JacobianMatrix> jacOut;
output Option<SimCode.JacobianMatrix> jacOut = jacIn;
algorithm
jacOut := matchcontinue(jacIn,assIn)
jacOut := matchcontinue(jacIn)
local
Integer maxCol,jacIdx;
list<SimCode.JacobianColumn> jacCols;
list<SimCodeVar.SimVar> vars;
String name;
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>> sparsePatt;
list<list<Integer>> colCols;
array<Integer> ass;
Integer newIdx;
case(SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx)),_)
SimCode.JacobianMatrix jacMatrix;
case SOME(jacMatrix as SimCode.JAC_MATRIX())
equation
jacCols = List.map1(jacCols,TDS_replaceSimEqSysIdxInJacobianColumn,assIn);
then SOME((jacCols,vars,name,sparsePatt,colCols,maxCol,jacIdx));
jacMatrix.columns = List.map1(jacMatrix.columns, TDS_replaceSimEqSysIdxInJacobianColumn, assIn);
then SOME(jacMatrix);
else jacIn;
end matchcontinue;
end TDS_replaceSimEqSysIdxInJacobianMatrix;
Expand All @@ -3609,21 +3602,9 @@ protected function TDS_replaceSimEqSysIdxInJacobianColumn "author: Waurich TUD 2
Replaces the index with the assigned one in a jacobian column."
input SimCode.JacobianColumn jacIn;
input array<Integer> assIn;
output SimCode.JacobianColumn jacOut;
output SimCode.JacobianColumn jacOut = jacIn;
algorithm
jacOut := matchcontinue(jacIn,assIn)
local
list<SimCode.SimEqSystem> simEqs;
list<SimCodeVar.SimVar> simVars;
String colLen;
array<Integer> ass;
Integer newIdx;
case((simEqs,simVars,colLen),_)
equation
simEqs = List.map1(simEqs,TDS_replaceSimEqSysIndex,assIn);
then ((simEqs,simVars,colLen));
else jacIn;
end matchcontinue;
jacOut.columnEqns := List.map1(jacOut.columnEqns, TDS_replaceSimEqSysIndex, assIn);
end TDS_replaceSimEqSysIdxInJacobianColumn;

protected function TDS_updateModelInfo "
Expand Down
12 changes: 6 additions & 6 deletions Compiler/SimCode/SerializeModelInfo.mo
Expand Up @@ -526,7 +526,7 @@ algorithm
j = listLength(lSystem.simJac);

jeqs = match lSystem.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
else {};
end match;
eqs = SimCodeUtil.sortEqSystems(listAppend(lSystem.residual,jeqs));
Expand Down Expand Up @@ -568,7 +568,7 @@ algorithm
j = listLength(lSystem.simJac);

jeqs = match lSystem.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
else {};
end match;
eqs = SimCodeUtil.sortEqSystems(listAppend(lSystem.residual,jeqs));
Expand Down Expand Up @@ -607,7 +607,7 @@ algorithm
j = listLength(atL.simJac);

jeqs = match atL.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then jeqs;
else {};
end match;
eqs = SimCodeUtil.sortEqSystems(listAppend(atL.residual,jeqs));
Expand Down Expand Up @@ -700,7 +700,7 @@ algorithm
serializeEquation(file,listHead(eqs),section,withOperations,parent=nlSystem.index,first=true);
min(serializeEquation(file,e,section,withOperations,parent=nlSystem.index) for e in List.rest(eqs));
jeqs = match nlSystem.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
else {};
end match;
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
Expand Down Expand Up @@ -730,7 +730,7 @@ algorithm
serializeEquation(file,listHead(eqs),section,withOperations,parent=nlSystem.index,first=true);
min(serializeEquation(file,e,section,withOperations,parent=nlSystem.index) for e in List.rest(eqs));
jeqs = match nlSystem.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
else {};
end match;
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
Expand All @@ -757,7 +757,7 @@ algorithm
serializeEquation(file,listHead(eqs),section,withOperations,parent=atNL.index,first=true);
min(serializeEquation(file,e,section,withOperations,parent=atNL.index) for e in List.rest(eqs));
jeqs = match atNL.jacobianMatrix
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
case SOME(SimCode.JAC_MATRIX(columns={SimCode.JAC_COLUMN(columnEqns=jeqs)})) then SimCodeUtil.sortEqSystems(jeqs);
else {};
end match;
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
Expand Down
33 changes: 25 additions & 8 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -65,15 +65,32 @@ import SimCodeVar;
type ExtConstructor = tuple<DAE.ComponentRef, String, list<DAE.Exp>>;
type ExtDestructor = tuple<String, DAE.ComponentRef>;
type ExtAlias = tuple<DAE.ComponentRef, DAE.ComponentRef>;
type JacobianColumn = tuple<list<SimEqSystem>, list<SimCodeVar.SimVar>, String>; // column equations, column vars, column length
type JacobianMatrix = tuple<list<JacobianColumn>, // column
list<SimCodeVar.SimVar>, // seed vars
String, // matrix name
tuple<list< tuple<Integer, list<Integer>>>,list< tuple<Integer, list<Integer>>>>, // sparse pattern
list<list<Integer>>, // colored cols
Integer, // max color used
Integer>; // jacobian index

type SparsityPattern = list< tuple<Integer, list<Integer>> >;

uniontype JacobianColumn
record JAC_COLUMN
list<SimEqSystem> columnEqns; // column equations equals in size to column vars
list<SimCodeVar.SimVar> columnVars; // all column vars, none results vars index -1, the other corresponding to rows index
Integer numberOfResultVars; // corresponds to the number of rows
end JAC_COLUMN;
end JacobianColumn;

uniontype JacobianMatrix
record JAC_MATRIX
list<JacobianColumn> columns; // columns equations and variables
list<SimCodeVar.SimVar> seedVars; // corresponds to the number of columns
String matrixName; // unique matrix name
SparsityPattern sparsity;
SparsityPattern sparsityT;
list<list<Integer>> coloredCols;
Integer maxColorCols;
Integer jacobianIndex;
Integer partitionIndex;
end JAC_MATRIX;
end JacobianMatrix;

constant JacobianMatrix emptyJacobian = JAC_MATRIX({}, {}, "", {}, {}, {}, 0, -1, -1);

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

Expand Down

0 comments on commit fd5058e

Please sign in to comment.