Skip to content

Commit 60c93f5

Browse files
committed
Merge pull request #4 from ptaeuber/tearing2
Prepare SimCode and Templates for dynamic tearing
2 parents 3f57560 + 7706696 commit 60c93f5

File tree

24 files changed

+16194
-15655
lines changed

24 files changed

+16194
-15655
lines changed

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,21 +3478,21 @@ algorithm
34783478
list<DAE.ElementSource> sources;
34793479
Boolean homotopySupport;
34803480
Boolean mixedSystem;
3481-
case(SimCode.SES_NONLINEAR(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport,mixedSystem=mixedSystem),_)
3481+
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport,mixedSystem=mixedSystem)),_)
34823482
equation
34833483
eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,assIn);
34843484
oldIdx = SimCodeUtil.eqIndex(simEqIn);
34853485
newIdx = arrayGet(assIn,oldIdx);
34863486
jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,assIn);
3487-
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport,mixedSystem);
3487+
simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport,mixedSystem), NONE());
34883488
then simEqSys;
3489-
case(SimCode.SES_LINEAR(partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem),ass)
3489+
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem)),ass)
34903490
equation
34913491
eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,ass);
34923492
oldIdx = SimCodeUtil.eqIndex(simEqIn);
34933493
newIdx = arrayGet(ass,oldIdx);
34943494
jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,ass);
3495-
simEqSys = SimCode.SES_LINEAR(newIdx,partOfMixed,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem);
3495+
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(newIdx,partOfMixed,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem), NONE());
34963496
then simEqSys;
34973497
case(_,ass)
34983498
equation
@@ -3525,19 +3525,19 @@ algorithm
35253525
list<DAE.ElementSource> sources;
35263526
Boolean homotopySupport;
35273527
Boolean mixedSystem;
3528-
case(SimCode.SES_NONLINEAR(index=oldIdx,eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport,mixedSystem=mixedSystem),(newIdx,ass))
3528+
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=oldIdx,eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport,mixedSystem=mixedSystem)),(newIdx,ass))
35293529
equation
35303530
(eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass));
35313531
(jacobianMatrix,(newIdx,ass)) = TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate(jacobianMatrix,(newIdx,ass));
35323532
ass = arrayUpdate(ass,oldIdx,newIdx);
3533-
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport,mixedSystem);
3533+
simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport,mixedSystem), NONE());
35343534
then (simEqSys,(newIdx+1,ass));
3535-
case(SimCode.SES_LINEAR(index=oldIdx,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem),(newIdx,ass))
3535+
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=oldIdx,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem)),(newIdx,ass))
35363536
equation
35373537
(eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass));
35383538
(jacobianMatrix,(newIdx,ass)) = TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate(jacobianMatrix,(newIdx,ass));
35393539
ass = arrayUpdate(ass,oldIdx,newIdx);
3540-
simEqSys = SimCode.SES_LINEAR(newIdx,partOfMixed,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem);
3540+
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(newIdx,partOfMixed,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem), NONE());
35413541
then (simEqSys,(newIdx+1,ass));
35423542
case(SimCode.SES_MIXED(index=oldIdx,cont=cont,discVars=discVars,discEqs=eqs,indexMixedSystem=indexMixedSystem),(newIdx,ass))
35433543
equation
@@ -4033,7 +4033,7 @@ algorithm
40334033
Integer indexLinearSystem;
40344034
case({},_,_,_)
40354035
then (listReverse(simEqsFold),simEqSysIdxIn);
4036-
case((simEqSys as SimCode.SES_LINEAR(index=index,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,jacobianMatrix=jacobianMatrix, residual=residual,sources=sources,indexLinearSystem=indexLinearSystem))::rest,_,_,_)
4036+
case((simEqSys as SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=index,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,jacobianMatrix=jacobianMatrix, residual=residual,sources=sources,indexLinearSystem=indexLinearSystem)))::rest,_,_,_)
40374037
equation
40384038
//print("the systemSimEqSys "+SimCodeUtil.dumpSimEqSystemLst(residual)+"\n");
40394039
numEqs = listLength(residual);
@@ -4042,7 +4042,7 @@ algorithm
40424042
(duplicated,_) = List.map1_2(residual,replaceExpsInSimEqSystem,repl);// replace the exps and crefs
40434043
duplicated = List.threadMap(duplicated,systSimEqSysIdcs2,SimCodeUtil.replaceSimEqSysIndex);
40444044
//print("the systemSimEqSysDupl "+SimCodeUtil.dumpSimEqSystemLst(duplicated)+"\n");
4045-
simEqSys = SimCode.SES_LINEAR(index,partOfMixed,vars,beqs,simJac,duplicated,jacobianMatrix,sources,indexLinearSystem);
4045+
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index,partOfMixed,vars,beqs,simJac,duplicated,jacobianMatrix,sources,indexLinearSystem), NONE());
40464046
simEqSysIdx = simEqSysIdxIn + numEqs;
40474047
(duplicated,simEqSysIdx) = TDS_duplicateSystemOfEquations(rest,simEqSysIdx,repl,simEqSys::simEqsFold);
40484048
then (duplicated,simEqSysIdx);
@@ -4115,15 +4115,15 @@ algorithm
41154115
Option<SimCode.JacobianMatrix> jac;
41164116
Boolean homotopySupport;
41174117
Boolean mixedSystem;
4118-
case(SimCode.SES_LINEAR(index=idx,partOfMixed=pom,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac),_)
4118+
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=idx,partOfMixed=pom,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac)),_)
41194119
equation
41204120
(lsIdx,nlsIdx,mIdx) = idcsIn;
4121-
simEqSys = SimCode.SES_LINEAR(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,lsIdx);
4121+
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,lsIdx), NONE());
41224122
then (simEqSys,(lsIdx+1,nlsIdx,mIdx));
4123-
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,jacobianMatrix=jac,linearTearing=lt,homotopySupport=homotopySupport,mixedSystem=mixedSystem),_)
4123+
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=idx,eqs=simEqSysLst,crefs=crefs,jacobianMatrix=jac,linearTearing=lt,homotopySupport=homotopySupport,mixedSystem=mixedSystem)),_)
41244124
equation
41254125
(lsIdx,nlsIdx,mIdx) = idcsIn;
4126-
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,nlsIdx,jac,lt,homotopySupport,mixedSystem);
4126+
simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(idx,simEqSysLst,crefs,nlsIdx,jac,lt,homotopySupport,mixedSystem), NONE());
41274127
then (simEqSys,(lsIdx,nlsIdx+1,mIdx));
41284128
case(SimCode.SES_MIXED(index=idx,cont=cont,discVars=simVars,discEqs=simEqSysLst),_)
41294129
equation
@@ -4209,23 +4209,23 @@ algorithm
42094209
(stmts,changed) = BackendVarTransform.replaceStatementLst(stmts,replIn,NONE(),{},false);
42104210
simEqSys = SimCode.SES_ALGORITHM(idx,stmts);
42114211
then (simEqSys,changed);
4212-
case(SimCode.SES_LINEAR(index=idx,partOfMixed=pom,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac,indexLinearSystem=idxLS),_)
4212+
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=idx,partOfMixed=pom,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac,indexLinearSystem=idxLS)),_)
42134213
equation
42144214
(simVars,bLst) = List.map1_2(simVars,replaceCrefInSimVar,replIn);
42154215
(expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE(),{},false);
42164216
changed = List.fold(bLst,boolOr,changed);
42174217
simJac = List.map1(simJac,replaceInSimJac,replIn);
4218-
simEqSys = SimCode.SES_LINEAR(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,idxLS);
4218+
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,idxLS), NONE());
42194219
then (simEqSys,changed);
4220-
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,linearTearing=lt,homotopySupport=homotopySupport,mixedSystem=mixedSystem),_)
4220+
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=idx,eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,linearTearing=lt,homotopySupport=homotopySupport,mixedSystem=mixedSystem)),_)
42214221
equation
42224222
expLst = List.map(crefs,Expression.crefExp);
42234223
(expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE(),{},false);
42244224
crefs = List.map(expLst,Expression.expCref);
42254225
(simEqSysLst,bLst) = List.map1_2(simEqSysLst,replaceExpsInSimEqSystem,replIn);
42264226
changed = changed or List.fold(bLst,boolOr,false);
42274227
print("implement Jacobian replacement for SES_NONLINEAR in HpcOmScheduler.replaceExpsInSimEqSystems!\n");
4228-
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,idxNLS,NONE(),lt,homotopySupport,mixedSystem);
4228+
simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(idx,simEqSysLst,crefs,idxNLS,NONE(),lt,homotopySupport,mixedSystem), NONE());
42294229
then (simEqSys,changed);
42304230
case(SimCode.SES_MIXED(index=idx,cont=simEqSys,discVars=simVars,discEqs=simEqSysLst,indexMixedSystem=idxMS),_)
42314231
equation

Compiler/SimCode/HpcOmSimCodeMain.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ algorithm
11811181
case(SimCode.SES_ARRAY_CALL_ASSIGN(index=index)) then index;
11821182
case(SimCode.SES_IFEQUATION(index=index)) then index;
11831183
case(SimCode.SES_ALGORITHM(index=index)) then index;
1184-
case(SimCode.SES_LINEAR(index=index)) then index;
1185-
case(SimCode.SES_NONLINEAR(index=index)) then index;
1184+
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=index))) then index;
1185+
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=index))) then index;
11861186
case(SimCode.SES_MIXED(index=index)) then index;
11871187
case(SimCode.SES_WHEN(index=index)) then index;
11881188
else fail();

Compiler/SimCode/SerializeModelInfo.mo

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ algorithm
426426
Integer i,j;
427427
DAE.Statement stmt;
428428
list<SimCode.SimEqSystem> eqs,jeqs;
429+
SimCode.LinearSystem lSystem;
430+
SimCode.NonlinearSystem nlSystem;
429431
case SimCode.SES_RESIDUAL()
430432
equation
431433
File.write(file, "\n{\"eqIndex\":");
@@ -484,24 +486,24 @@ algorithm
484486
serializeSource(file,eq.source,withOperations);
485487
File.write(file, "}");
486488
then true;
487-
case SimCode.SES_LINEAR()
489+
case SimCode.SES_LINEAR(lSystem = lSystem as SimCode.LINEARSYSTEM())
488490
equation
489-
i = listLength(eq.beqs);
490-
j = listLength(eq.simJac);
491+
i = listLength(lSystem.beqs);
492+
j = listLength(lSystem.simJac);
491493

492-
jeqs = match eq.jacobianMatrix
494+
jeqs = match lSystem.jacobianMatrix
493495
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then jeqs;
494496
else {};
495497
end match;
496-
eqs = SimCodeUtil.sortEqSystems(listAppend(eq.residual,jeqs));
498+
eqs = SimCodeUtil.sortEqSystems(listAppend(lSystem.residual,jeqs));
497499
if listEmpty(eqs) then
498500
File.write(file, "\n{\"eqIndex\":");
499501
else
500-
serializeEquation(file,listHead(eqs),section,withOperations,parent=eq.index,first=true);
501-
min(serializeEquation(file,e,section,withOperations,parent=eq.index) for e in listRest(eqs));
502+
serializeEquation(file,listHead(eqs),section,withOperations,parent=lSystem.index,first=true);
503+
min(serializeEquation(file,e,section,withOperations,parent=lSystem.index) for e in listRest(eqs));
502504
File.write(file, ",\n{\"eqIndex\":");
503505
end if;
504-
File.write(file, intString(eq.index));
506+
File.write(file, intString(lSystem.index));
505507
if parent <> 0 then
506508
File.write(file, ",\"parent\":");
507509
File.write(file, intString(parent));
@@ -511,17 +513,17 @@ algorithm
511513
// Ax=b
512514
File.write(file, "\",\"tag\":\"container\",\"display\":\"linear\",\"defines\":[");
513515
serializeUses(file,list(match v case SimCodeVar.SIMVAR() then v.name; end match
514-
for v in eq.vars));
516+
for v in lSystem.vars));
515517
File.write(file, "],\"equation\":[{\"size\":");
516518
File.write(file,intString(i));
517519
if i <> 0 then
518520
File.write(file,",\"density\":");
519521
File.write(file,realString(j / (i*i)));
520522
end if;
521523
File.write(file,",\"A\":[");
522-
serializeList1(file,eq.simJac,withOperations,serializeLinearCell);
524+
serializeList1(file,lSystem.simJac,withOperations,serializeLinearCell);
523525
File.write(file,"],\"b\":[");
524-
serializeList(file,eq.beqs,serializeExp);
526+
serializeList(file,lSystem.beqs,serializeExp);
525527
File.write(file,"]}]}");
526528
then true;
527529
case SimCode.SES_ALGORITHM(statements={stmt as DAE.STMT_ASSIGN()})
@@ -572,19 +574,19 @@ algorithm
572574
File.write(file, section);
573575
File.write(file, "\",\"tag\":\"algorithm\",\"equation\":[]}");
574576
then true;
575-
case SimCode.SES_NONLINEAR()
577+
case SimCode.SES_NONLINEAR(nlSystem = nlSystem as SimCode.NONLINEARSYSTEM())
576578
equation
577-
eqs = SimCodeUtil.sortEqSystems(eq.eqs);
578-
serializeEquation(file,listHead(eqs),section,withOperations,parent=eq.index,first=true);
579-
min(serializeEquation(file,e,section,withOperations,parent=eq.index) for e in List.rest(eqs));
580-
jeqs = match eq.jacobianMatrix
579+
eqs = SimCodeUtil.sortEqSystems(nlSystem.eqs);
580+
serializeEquation(file,listHead(eqs),section,withOperations,parent=nlSystem.index,first=true);
581+
min(serializeEquation(file,e,section,withOperations,parent=nlSystem.index) for e in List.rest(eqs));
582+
jeqs = match nlSystem.jacobianMatrix
581583
case SOME(({(jeqs,_,_)},_,_,_,_,_,_)) then SimCodeUtil.sortEqSystems(jeqs);
582584
else {};
583585
end match;
584586
min(serializeEquation(file,e,section,withOperations) for e in jeqs);
585587

586588
File.write(file, ",\n{\"eqIndex\":");
587-
File.write(file, intString(eq.index));
589+
File.write(file, intString(nlSystem.index));
588590
if parent <> 0 then
589591
File.write(file, ",\"parent\":");
590592
File.write(file, intString(parent));
@@ -593,7 +595,7 @@ algorithm
593595
File.write(file, section);
594596
File.write(file, "\",\"tag\":\"container\",\"display\":\"non-linear\"");
595597
File.write(file, ",\"defines\":[");
596-
serializeUses(file,eq.crefs);
598+
serializeUses(file,nlSystem.crefs);
597599
File.write(file, "],\"equation\":[[");
598600
serializeList(file,eqs,serializeEquationIndex);
599601
File.write(file, "],[");

Compiler/SimCode/SimCode.mo

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ encapsulated package SimCode
3434
package: SimCode
3535
description: Code generation using Susan templates
3636
37-
RCS: $Id$
37+
RCS: $Id: SimCode.mo 25853 2015-04-30 14:04:02Z vwaurich $
3838
3939
The entry points to this module are the translateModel function and the
4040
translateFunctions fuction.
@@ -389,27 +389,13 @@ uniontype SimEqSystem
389389
end SES_ALGORITHM;
390390

391391
record SES_LINEAR
392-
Integer index;
393-
Boolean partOfMixed;
394-
list<SimCodeVar.SimVar> vars;
395-
list<DAE.Exp> beqs;
396-
list<tuple<Integer, Integer, SimEqSystem>> simJac;
397-
/* solver linear tearing system */
398-
list<SimEqSystem> residual;
399-
Option<JacobianMatrix> jacobianMatrix;
400-
list<DAE.ElementSource> sources;
401-
Integer indexLinearSystem;
392+
LinearSystem lSystem;
393+
Option<LinearSystem> alternativeTearing;
402394
end SES_LINEAR;
403395

404396
record SES_NONLINEAR
405-
Integer index;
406-
list<SimEqSystem> eqs;
407-
list<DAE.ComponentRef> crefs;
408-
Integer indexNonLinearSystem;
409-
Option<JacobianMatrix> jacobianMatrix;
410-
Boolean linearTearing;
411-
Boolean homotopySupport;
412-
Boolean mixedSystem;
397+
NonlinearSystem nlSystem;
398+
Option<NonlinearSystem> alternativeTearing;
413399
end SES_NONLINEAR;
414400

415401
record SES_MIXED
@@ -442,6 +428,36 @@ uniontype SimEqSystem
442428

443429
end SimEqSystem;
444430

431+
public
432+
uniontype LinearSystem
433+
record LINEARSYSTEM
434+
Integer index;
435+
Boolean partOfMixed;
436+
list<SimCodeVar.SimVar> vars;
437+
list<DAE.Exp> beqs;
438+
list<tuple<Integer, Integer, SimEqSystem>> simJac;
439+
/* solver linear tearing system */
440+
list<SimEqSystem> residual;
441+
Option<JacobianMatrix> jacobianMatrix;
442+
list<DAE.ElementSource> sources;
443+
Integer indexLinearSystem;
444+
end LINEARSYSTEM;
445+
end LinearSystem;
446+
447+
public
448+
uniontype NonlinearSystem
449+
record NONLINEARSYSTEM
450+
Integer index;
451+
list<SimEqSystem> eqs;
452+
list<DAE.ComponentRef> crefs;
453+
Integer indexNonLinearSystem;
454+
Option<JacobianMatrix> jacobianMatrix;
455+
Boolean linearTearing;
456+
Boolean homotopySupport;
457+
Boolean mixedSystem;
458+
end NONLINEARSYSTEM;
459+
end NonlinearSystem;
460+
445461
uniontype StateSet
446462
record SES_STATESET
447463
Integer index;

0 commit comments

Comments
 (0)