-
Notifications
You must be signed in to change notification settings - Fork 298
/
BackendDump.mo
4779 lines (4429 loc) · 172 KB
/
BackendDump.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package BackendDump
" file: BackendDump.mo
package: BackendDump
description: Unparsing the BackendDAE structure
These file is subdivided into several section:
- section for all print* functions
- section for all dump* functions
- section for all *String functions
- section for all debug* functions
- unsorted section
Please follow the introduced naming style (above) and sort all new functions
into the corresponding section (except unsorted section).
"
import BackendDAE;
import DAE;
import HashSet;
import Tpl;
protected
import Absyn;
import AbsynUtil;
import Array;
import BackendDAEUtil;
import BackendEquation;
import BackendVariable;
import BaseHashSet;
import CodegenModelica;
import ComponentReference;
import DAEDump;
import DAEUtil;
import Debug;
import DoubleEnded;
import DumpHTML;
import ElementSource;
import Error;
import Expression;
import ExpressionDump;
import Flags;
import GraphvizDump;
import GraphML;
import HpcOmTaskGraph;
import Initialization;
import IOStream;
import List;
import Matching;
import System;
import Util;
import ZeroCrossings;
// =============================================================================
// section for all print* functions
//
// These are functions, that print directly to the standard-stream.
// - printBackendDAE
// - printEqSystem
// - printEquation
// - printEquationArray
// - printEquationList
// - printEquations
// - printClassAttributes
// - printShared
// - printStateSets
// - printVar
// - printVariables
// - printVarList
// =============================================================================
public function printBackendDAE "This function dumps the BackendDAE.BackendDAE representation to stdout."
input BackendDAE.BackendDAE inBackendDAE;
protected
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
algorithm
BackendDAE.DAE(eqs, shared) := inBackendDAE;
List.map_0(eqs, printEqSystem);
print("\n");
printShared(shared);
end printBackendDAE;
public function printEqSystem "This function prints the BackendDAE.EqSystem representation to stdout."
input BackendDAE.EqSystem inSyst;
protected
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs;
Option<BackendDAE.AdjacencyMatrix> m;
Option<BackendDAE.AdjacencyMatrix> mT;
BackendDAE.Matching matching;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
algorithm
print("\n" + partitionKindString(inSyst.partitionKind) + "\n" + UNDERLINE + "\n");
dumpVariables(inSyst.orderedVars, "Variables");
dumpEquationArray(inSyst.orderedEqs, "Equations");
dumpEquationArray(inSyst.removedEqs, "Simple Equations");
dumpStateSets(inSyst.stateSets, "State Sets");
dumpOption(inSyst.m, dumpAdjacencyMatrix);
dumpOption(inSyst.mT, dumpAdjacencyMatrixT);
print("\n");
dumpFullMatching(inSyst.matching,SOME(inSyst));
print("\n");
end printEqSystem;
public function printEquation "author: PA
Helper function to print_equations"
input BackendDAE.Equation inEquation;
algorithm
print(equationString(inEquation) + "\n");
end printEquation;
public function printEquationArray "Helper function to dump."
input BackendDAE.EquationArray eqns;
algorithm
_ := List.fold(BackendEquation.equationList(eqns), printEquationList2, (1, 1));
end printEquationArray;
public function printEquationList "Helper function to dump."
input list<BackendDAE.Equation> eqns;
algorithm
_ := List.fold(eqns, printEquationList2, (1, 1));
end printEquationList;
protected function printEquationList2 "Helper function for printEquationArray and printEquationList"
input BackendDAE.Equation inEquation;
input tuple<Integer,Integer> inInteger;
output tuple<Integer,Integer> oInteger;
protected
Integer iscalar,i,size;
BackendDAE.EquationAttributes attr;
algorithm
(i,iscalar) := inInteger;
size := BackendEquation.equationSize(inEquation);
attr := BackendEquation.getEquationAttributes(inEquation);
print(intString(i) + "/" + intString(iscalar) + " (" + intString(size) + "): " + equationString(inEquation) + " " + equationAttrString(attr) + "\n");
oInteger := (i + 1,iscalar + size);
end printEquationList2;
public function equationListString
input list<BackendDAE.Equation> inEqns;
input String heading;
output String outString;
algorithm
outString := match(inEqns, heading)
local
String buffer;
case (_, "") equation
((_, _, buffer)) = List.fold(inEqns, equationList2String, (1, 1, ""));
then buffer;
else equation
((_, _, buffer)) = List.fold(inEqns, equationList2String, (1, 1, ""));
buffer = heading + "\n" + UNDERLINE + "\n" + buffer;
then buffer;
end match;
end equationListString;
protected function equationList2String
input BackendDAE.Equation inEquation;
input tuple<Integer, Integer, String /*buffer*/> inTuple;
output tuple<Integer, Integer, String /*buffer*/> outTuple;
protected
Integer iscalar, i, size;
String buffer;
algorithm
(i, iscalar, buffer) := inTuple;
size := BackendEquation.equationSize(inEquation);
buffer := buffer + intString(i) + "/" + intString(iscalar) + " (" + intString(size) + "): " + equationString(inEquation) + "\n";
outTuple := (i + 1, iscalar + size, buffer);
end equationList2String;
public function printEquations ""
input list<Integer> inIntegerLst;
input BackendDAE.EqSystem syst;
algorithm
_:= match(inIntegerLst, syst)
local
Integer n;
list<Integer> rest;
case ({}, _) then ();
case ((n :: rest), _) equation
printEquations(rest, syst);
printEquationNo(n, syst);
then ();
end match;
end printEquations;
protected function printEquationNo "author: PA
Helper function to printEquations"
input Integer inInteger;
input BackendDAE.EqSystem syst;
algorithm
_:=
match (inInteger,syst)
local
Integer eqno;
BackendDAE.Equation eq;
BackendDAE.EquationArray eqns;
case (eqno,BackendDAE.EQSYSTEM(orderedEqs = eqns))
equation
eq = BackendEquation.get(eqns, eqno);
printEquation(eq);
then
();
end match;
end printEquationNo;
public function printClassAttributes "This unction print the Optimica ClassAttributes: objetiveE, objetiveE"
input DAE.ClassAttributes optimicaFun;
protected
Option<DAE.Exp> e1,e2;
algorithm
DAE.OPTIMIZATION_ATTRS(objetiveE = e1, objectiveIntegrandE = e2) := optimicaFun;
print("Mayer" + "\n" + UNDERLINE + "\n\n");
print(ExpressionDump.printOptExpStr(e1));
print("Lagrange" + "\n" + UNDERLINE + "\n\n");
print(ExpressionDump.printOptExpStr(e2));
print("\n");
end printClassAttributes;
public function printShared "This function dumps the BackendDAE.Shared representation to stdout."
input BackendDAE.Shared inShared;
protected
BackendDAE.EqSystems eqS;
BackendDAE.InlineData inlineData;
algorithm
print("\nBackendDAEType: ");
printBackendDAEType(inShared.backendDAEType);
print("\n\n");
dumpVariables(inShared.globalKnownVars, "Known variables only depending on parameters and constants - globalKnownVars");
dumpVariables(inShared.localKnownVars, "Known variables only depending on states and inputs - localKnownVars");
dumpVariables(inShared.externalObjects, "External Objects");
dumpExternalObjectClasses(inShared.extObjClasses, "Classes of External Objects");
dumpVariables(inShared.aliasVars, "Alias Variables");
dumpEquationArray(inShared.removedEqs, "Simple Shared Equations");
dumpEquationArray(inShared.initialEqs, "Initial Equations");
dumpZeroCrossingList(ZeroCrossings.toList(inShared.eventInfo.zeroCrossings), "Zero Crossings");
dumpZeroCrossingList(DoubleEnded.toListNoCopyNoClear(inShared.eventInfo.relations), "Relations");
if stringEqual(Config.simCodeTarget(), "Cpp") then
dumpZeroCrossingList(ZeroCrossings.toList(inShared.eventInfo.samples), "Samples");
else
dumpTimeEvents(inShared.eventInfo.timeEvents, "Time Events");
end if;
dumpConstraintList(inShared.constraints, "Constraints");
dumpBasePartitions(inShared.partitionsInfo.basePartitions, "Base partitions");
dumpSubPartitions(inShared.partitionsInfo.subPartitions, "Sub partitions");
if Flags.isSet(Flags.DUMP_FUNCTIONS) then
DAEDump.dumpFunctionTree(inShared.functionTree, "Functions");
end if;
end printShared;
public function printBasePartitions
input array<BackendDAE.BasePartition> basePartitions;
protected
String clkExpStr, nSubClocksStr;
algorithm
for i in 1:arrayLength(basePartitions) loop
clkExpStr := Tpl.tplString2( ExpressionDumpTpl.dumpClockKind,
basePartitions[i].clock, "");
nSubClocksStr := intString(basePartitions[i].nSubClocks);
print(intString(i) + ": " + clkExpStr + "[" + nSubClocksStr + "]" + "\n");
end for;
end printBasePartitions;
public function printSubPartitions
input array<BackendDAE.SubPartition> subPartitions;
protected
String subClockStr, eventStr;
algorithm
for i in 1:arrayLength(subPartitions) loop
subClockStr := subClockString(subPartitions[i].clock);
eventStr := "event(" + boolString(subPartitions[i].holdEvents) + ")";
print(intString(i) + ": " + subClockStr + " " + eventStr + "\n");
end for;
end printSubPartitions;
public function subClockString
input BackendDAE.SubClock subClock;
output String subClockString;
algorithm
subClockString := match(subClock)
local
String factorStr, shiftStr, solverStr;
case(BackendDAE.INFERED_SUBCLOCK())
then "INFERED_SUBCLOCK";
case(BackendDAE.SUBCLOCK(_))
algorithm
factorStr := "factor(" + MMath.rationalString(subClock.factor) + ")";
shiftStr := "shift(" + MMath.rationalString(subClock.shift) + ")";
solverStr := "solver(" + optionString(subClock.solver) + ")";
if stringLength(solverStr) > 8 then
subClockString := factorStr + " " + shiftStr + " " + solverStr;
else
subClockString := factorStr + " " + shiftStr + " ";
end if;
then subClockString;
end match;
end subClockString;
public function optionString
input Option<String> option;
output String optionString;
algorithm
optionString := match option
local
String s;
case SOME(s) then s;
else "";
end match;
end optionString;
public function printBackendDAEType "This is a helper for printShared."
input BackendDAE.BackendDAEType btp;
algorithm
print(printBackendDAEType2String(btp));
end printBackendDAEType;
public function printBackendDAEType2String "This is a helper for printShared."
input BackendDAE.BackendDAEType btp;
output String str;
algorithm
str := match(btp)
case (BackendDAE.SIMULATION()) then "simulation";
case (BackendDAE.JACOBIAN()) then "jacobian";
case (BackendDAE.ALGEQSYSTEM()) then "algebraic loop";
case (BackendDAE.ARRAYSYSTEM()) then "multidim equation arrays";
case (BackendDAE.PARAMETERSYSTEM()) then "parameter system";
case (BackendDAE.INITIALSYSTEM()) then "initialization";
case (BackendDAE.INLINESYSTEM()) then "inline system";
end match;
end printBackendDAEType2String;
public function printStateSets "author: Frenkel TUD"
input BackendDAE.StateSets stateSets;
algorithm
List.map_0(stateSets, printStateSet);
end printStateSets;
protected function printStateSet "author: lochel"
input BackendDAE.StateSet inStateSet;
algorithm
print("StateSet \"" + ComponentReference.printComponentRefStr(ComponentReference.crefFirstCref(inStateSet.crA)) + "\" (rang " + intString(inStateSet.rang) + ")\n");
dumpVarList(inStateSet.statescandidates, "state candidates");
dumpEquationList(inStateSet.eqns, "eqns");
dumpVarList(inStateSet.ovars, "ovars");
dumpEquationList(inStateSet.oeqns, "oeqns");
dumpVarList(inStateSet.varA, "varA");
dumpVarList(inStateSet.varJ, "varJ");
//print(jacobianString(inStateSet.jacobian));
end printStateSet;
public function printVar
input BackendDAE.Var inVar;
algorithm
print(varString(inVar) + "\n");
end printVar;
public function printVariables "Helper function to dump."
input BackendDAE.Variables vars;
algorithm
_ := List.fold(BackendVariable.varList(vars), printVars1, 1);
end printVariables;
public function printVarList "Helper function to dump."
input list<BackendDAE.Var> vars;
algorithm
_ := List.fold(vars, printVars1, 1);
end printVarList;
protected function printVars1 "This is a helper function for printVariables and printVarList"
input BackendDAE.Var inVar;
input Integer inVarNo;
output Integer outVarNo;
algorithm
print(intString(inVarNo));
print(": ");
printVar(inVar);
outVarNo := inVarNo + 1;
end printVars1;
public function varListString
input list<BackendDAE.Var> inVars;
input String heading;
output String outString;
algorithm
outString := match(inVars, heading)
local
String buffer;
case (_, "") equation
((_, buffer)) = List.fold(inVars, var1String, (1, ""));
then buffer;
else equation
((_, buffer)) = List.fold(inVars, var1String, (1, ""));
buffer = heading + "\n" + UNDERLINE + "\n" + buffer;
then buffer;
end match;
end varListString;
protected function var1String
input BackendDAE.Var inVar;
input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
protected
Integer varNo;
String buffer;
algorithm
(varNo, buffer) := inTpl;
buffer := buffer + intString(varNo) + ": ";
buffer := buffer + varString(inVar) + "\n";
outTpl := (varNo + 1, buffer);
end var1String;
public function varListStringShort
input list<BackendDAE.Var> inVars;
input String heading;
output String outString;
algorithm
outString := match(inVars, heading)
local
String buffer;
case (_, "") equation
((_, buffer)) = List.fold(inVars, varNameString, (1, ""));
then buffer;
else equation
((_, buffer)) = List.fold(inVars, varNameString, (1, ""));
buffer = heading + "\n" + UNDERLINE + "\n" + buffer;
then buffer;
end match;
end varListStringShort;
protected function varNameString
input BackendDAE.Var inVar;
input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
protected
Integer varNo;
String buffer;
algorithm
(varNo, buffer) := inTpl;
buffer := buffer + intString(varNo) + ": ";
buffer := buffer + ComponentReference.printComponentRefStr(inVar.varName) + "\n";
outTpl := (varNo + 1, buffer);
end varNameString;
public function varListStringIndented
input list<BackendDAE.Var> inVars;
input String heading;
output String outString;
algorithm
outString := match(inVars, heading)
local
String buffer;
case (_, "") equation
((_, buffer)) = List.fold(inVars, var1StringIndented, (1, ""));
then buffer;
else equation
((_, buffer)) = List.fold(inVars, var1StringIndented, (1, ""));
buffer = heading + "\n" + buffer;
then buffer;
end match;
end varListStringIndented;
protected function var1StringIndented
input BackendDAE.Var inVar;
input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
protected
Integer varNo;
String buffer;
algorithm
(varNo, buffer) := inTpl;
buffer := buffer + " " + intString(varNo) + ": ";
buffer := buffer + varString(inVar) + "\n";
outTpl := (varNo + 1, buffer);
end var1StringIndented;
protected function printExternalObjectClasses "dump classes of external objects"
input BackendDAE.ExternalObjectClasses cls;
algorithm
_ := match(cls)
local
BackendDAE.ExternalObjectClasses xs;
Absyn.Path path;
list<Absyn.Path> paths;
list<String> paths_lst;
DAE.ElementSource source "the element source";
String path_str;
case {} then ();
case BackendDAE.EXTOBJCLASS(path,source)::_ equation
print("class ");
print(AbsynUtil.pathString(path));
print("\n extends ExternalObject;");
print("\n origin: ");
paths = ElementSource.getElementSourceTypes(source);
paths_lst = list(AbsynUtil.pathString(p) for p in paths);
path_str = stringDelimitList(paths_lst, ", ");
print(path_str + "\n");
print("end ");print(AbsynUtil.pathString(path));
then ();
end match;
end printExternalObjectClasses;
public function printSparsityPatternCrefs
input BackendDAE.SparsePatternCrefs inPattern;
algorithm
for e in inPattern loop
print(ComponentReference.printComponentRefStr(Util.tuple21(e)) +
" affects the following (" + intString(listLength(Util.tuple22(e))) +
") outputs\n ");
ComponentReference.printComponentRefList(Util.tuple22(e));
end for;
end printSparsityPatternCrefs;
// =============================================================================
// section for all graphviz* functions
//
// =============================================================================
public function graphvizBackendDAE
input BackendDAE.BackendDAE inBackendDAE;
input String inFileNameSuffix;
protected
BackendDAE.BackendDAE dae;
BackendDAE.EqSystems eqSystems;
String fileNamePrefix;
String buffer;
algorithm
dae := setAdjacencyMatrix(inBackendDAE);
Tpl.tplNoret2(GraphvizDump.dumpBackendDAE, dae, inFileNameSuffix);
end graphvizBackendDAE;
public function graphvizAdjacencyMatrix
input BackendDAE.BackendDAE inBackendDAE;
input String inFileNameSuffix;
protected
BackendDAE.BackendDAE dae;
BackendDAE.EqSystems eqSystems;
String fileNamePrefix;
String buffer;
algorithm
dae := setAdjacencyMatrix(inBackendDAE);
Tpl.tplNoret2(GraphvizDump.dumpAdjacencyMatrix, dae, inFileNameSuffix);
end graphvizAdjacencyMatrix;
protected function setAdjacencyMatrix
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
protected
BackendDAE.EqSystems eqSystems;
BackendDAE.Shared shared;
algorithm
BackendDAE.DAE(eqSystems, shared) := inBackendDAE;
eqSystems := List.map1(eqSystems, setAdjacencyMatrix1, BackendDAEUtil.isInitializationDAE(shared));
outBackendDAE := BackendDAE.DAE(eqSystems, shared);
end setAdjacencyMatrix;
protected function setAdjacencyMatrix1
input BackendDAE.EqSystem inEqSystem;
input Boolean isInitial;
output BackendDAE.EqSystem outEqSystem;
algorithm
(outEqSystem, _, _) := BackendDAEUtil.getAdjacencyMatrix(inEqSystem, BackendDAE.NORMAL(), NONE(), isInitial);
end setAdjacencyMatrix1;
// =============================================================================
// section for all dump* functions
//
// These are functions, that print directly to the standard-stream and separates
// there output (e.g. with some kind of headings).
// - dumpBackendDAE
// - dumpBackendDAEToModelica
// - dumpBackendDAEEqnList
// - dumpBackendDAEVarList
// - dumpComponent
// - dumpComponents
// - dumpComponentsAdvanced
// - dumpEqnsSolved
// - dumpEqSystem
// - dumpEqSystems
// - dumpEquationArray
// - dumpEquationList
// - dumpHashSet
// - dumpSparsityPattern
// - dumpTearing
// - dumpVariables
// - dumpVarList
// =============================================================================
public constant String BORDER = "########################################";
public constant String UNDERLINE = "========================================";
public function dumpDAE "dumps the DAE representation of the current transformation state"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
algorithm
dumpBackendDAE(inDAE, "dumpDAE");
end dumpDAE;
public function dumpBackendDAE "This function dumps the BackendDAE.BackendDAE representation to stdout."
input BackendDAE.BackendDAE inBackendDAE;
input String heading;
algorithm
print("\n" + BORDER + "\n" + heading + "\n" + BORDER + "\n\n");
printBackendDAE(inBackendDAE);
print("\n");
end dumpBackendDAE;
public function dumpBackendDAEToModelica "This function dumps the BackendDAE.BackendDAE representation to a Modelica file."
input BackendDAE.BackendDAE inBackendDAE;
input String suffix;
protected
String str;
algorithm
str := Tpl.tplString(CodegenModelica.dumpBackendDAE, inBackendDAE);
Error.addMessage(Error.BACKEND_DAE_TO_MODELICA, {suffix, str});
end dumpBackendDAEToModelica;
public function dumpEqSystem
input BackendDAE.EqSystem inEqSystem;
input String heading;
algorithm
print("\n" + heading + "\n" + UNDERLINE + "\n");
printEqSystem(inEqSystem);
print("\n");
end dumpEqSystem;
public function dumpEqSystemShort
input BackendDAE.EqSystem inEqSystem;
input String heading;
algorithm
print("\n" + heading + " (" + partitionKindString(inEqSystem.partitionKind) + ")\n" + UNDERLINE + "\n");
dumpVariables(inEqSystem.orderedVars, "Variables");
dumpEquationArray(inEqSystem.orderedEqs, "Equations");
print("\n");
end dumpEqSystemShort;
public function dumpEqSystems
input BackendDAE.EqSystems inEqSystems;
input String heading;
algorithm
print("\n" + BORDER + "\n" + heading + " (" + intString(listLength(inEqSystems)) + " partitions)\n" + BORDER + "\n\n");
List.map_0(inEqSystems, printEqSystem);
print("\n");
end dumpEqSystems;
public function dumpBasePartitions
input array<BackendDAE.BasePartition> basePartitions;
input String heading;
algorithm
if arrayLength(basePartitions) > 0 then
print("\n" + heading + " (" + intString(arrayLength(basePartitions)) + ")\n" + UNDERLINE + "\n");
printBasePartitions(basePartitions);
print("\n");
end if;
end dumpBasePartitions;
public function dumpSubPartitions
input array<BackendDAE.SubPartition> subPartitions;
input String heading;
algorithm
if arrayLength(subPartitions) > 0 then
print("\n" + heading + " (" + intString(arrayLength(subPartitions)) + ")\n" + UNDERLINE + "\n");
printSubPartitions(subPartitions);
print("\n");
end if;
end dumpSubPartitions;
public function dumpVariables "function dumpVariables"
input BackendDAE.Variables inVars;
input String heading;
algorithm
if BackendVariable.varsSize(inVars) > 0 then
print("\n" + heading + " (" + intString(BackendVariable.varsSize(inVars)) + ")\n" + UNDERLINE + "\n");
printVariables(inVars);
print("\n");
end if;
end dumpVariables;
public function dumpVarList "function dumpVarList"
input list<BackendDAE.Var> inVars;
input String heading;
algorithm
print("\n" + heading + " (" + intString(listLength(inVars)) + ")\n" + UNDERLINE + "\n");
printVarList(inVars);
print("\n");
end dumpVarList;
public function dumpEquationArray "function dumpEquationArray"
input BackendDAE.EquationArray inEqns;
input String heading;
algorithm
if BackendEquation.getNumberOfEquations(inEqns) + BackendEquation.equationArraySize(inEqns) > 0 then
print("\n" + heading + " (" + intString(BackendEquation.getNumberOfEquations(inEqns)) + ", " + intString(BackendEquation.equationArraySize(inEqns)) + ")\n" + UNDERLINE + "\n");
printEquationArray(inEqns);
print("\n");
end if;
end dumpEquationArray;
public function dumpEquationList "function dumpEquationList"
input list<BackendDAE.Equation> inEqns;
input String heading;
algorithm
if not listEmpty(inEqns) then
print("\n" + heading + " (" + intString(listLength(inEqns)) + ")\n" + UNDERLINE + "\n");
printEquationList(inEqns);
print("\n");
end if;
end dumpEquationList;
protected function dumpExternalObjectClasses "dump classes of external objects"
input BackendDAE.ExternalObjectClasses inEOC;
input String heading;
algorithm
if not listEmpty(inEOC) then
print("\n" + heading + " (" + intString(listLength(inEOC)) + ")\n" + UNDERLINE + "\n");
printExternalObjectClasses(inEOC);
print("\n");
end if;
end dumpExternalObjectClasses;
public function dumpStateSets
input BackendDAE.StateSets stateSets;
input String heading;
algorithm
if not listEmpty(stateSets) then
print("\n" + heading + "\n" + UNDERLINE + "\n");
printStateSets(stateSets);
print("\n");
end if;
end dumpStateSets;
public function dumpZeroCrossingList
input list<BackendDAE.ZeroCrossing> inZeroCrossingList;
input String heading;
protected
BackendDAE.ZeroCrossing zeroCrossing;
algorithm
if not listEmpty(inZeroCrossingList) then
print("\n" + heading + " (" + intString(listLength(inZeroCrossingList)) + ")\n" + UNDERLINE + "\n");
for zeroCrossing in inZeroCrossingList loop
print(zeroCrossingString(zeroCrossing) + "\n");
end for;
print("\n");
end if;
end dumpZeroCrossingList;
public function dumpTimeEvents
input list<BackendDAE.TimeEvent> inTimeEvents;
input String heading;
protected
BackendDAE.TimeEvent timeEvent;
algorithm
if not listEmpty(inTimeEvents) then
print("\n" + heading + " (" + intString(listLength(inTimeEvents)) + ")\n" + UNDERLINE + "\n");
for timeEvent in inTimeEvents loop
print(timeEventString(timeEvent) + "\n");
end for;
print("\n");
end if;
end dumpTimeEvents;
protected function dumpConstraintList
input list<DAE.Constraint> inConstraintArray;
input String heading;
algorithm
if not listEmpty(inConstraintArray) then
print("\n" + heading + " (" + intString(listLength(inConstraintArray)) + ")\n" + UNDERLINE + "\n");
dumpConstraints(inConstraintArray, 0);
print("\n");
end if;
end dumpConstraintList;
public function dumpHashSet "author lochel"
input HashSet.HashSet hashSet;
input String heading;
protected
Integer size;
algorithm
size := BaseHashSet.currentSize(hashSet);
print("\n" + heading + " (" + intString(size) + ")\n" + UNDERLINE + "\n");
BaseHashSet.printHashSet(hashSet);
print("\n");
end dumpHashSet;
public function dumpSparsityPattern
input BackendDAE.SparsePattern inPattern;
input String heading;
protected
BackendDAE.SparsePatternCrefs pattern,patternT;
list< .DAE.ComponentRef> diffVars, diffedVars;
Integer nnz;
algorithm
(pattern, patternT, (diffVars, diffedVars), nnz) := inPattern;
print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of non zero elements: " + intString(nnz) + "\n");
print("Independents [or inputs] (" + intString(listLength(diffVars)) + ")\n");
ComponentReference.printComponentRefList(diffVars);
print("Dependents [or outputs] (" + intString(listLength(diffedVars)) + ")\n");
ComponentReference.printComponentRefList(diffedVars);
printSparsityPatternCrefs(pattern);
print("\n" + "Transposed pattern" + "\n");
printSparsityPatternCrefs(patternT);
end dumpSparsityPattern;
public function dumpSparseColoring
input BackendDAE.SparseColoring inColoring;
input String heading;
protected
Integer i=0;
algorithm
print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of colors: " + intString(listLength(inColoring)) + "\n");
for crList in inColoring loop
print("The following (" + intString(listLength(crList)) + ") independents belong to one color\n"+intString(i)+": ");
ComponentReference.printComponentRefList(crList);
i := i+1;
end for;
end dumpSparseColoring;
public function dumpTearing "
author: Frenkel TUD
Dump tearing vars and residual equations."
input list<list<Integer>> inResEqn;
input list<list<Integer>> inTearVar;
algorithm
_:=
match (inResEqn,inTearVar)
local
list<Integer> tearingvars,residualeqns;
list<list<Integer>> r,t;
list<String> str_r,str_t;
String str_r_f,str_r_1,str_t_f,str_t_1,str,sr,st;
case (residualeqns::r,tearingvars::t)
equation
str_r = List.map(residualeqns, intString);
str_r_f = stringDelimitList(str_r, ", ");
str_r_1 = stringAppend(str_r_f, "\n");
sr = stringAppend("ResidualEqns: ",str_r_1);
str_t = List.map(tearingvars, intString);
str_t_f = stringDelimitList(str_t, ", ");
str_t_1 = stringAppend(str_t_f, "\n");
st = stringAppend("TearingVars: ",str_t_1);
str = stringAppend(sr, st);
print(str);
print("\n");
dumpTearing(r,t);
then
();
end match;
end dumpTearing;
public function dumpBackendDAEEqnList
input list<BackendDAE.Equation> inBackendDAEEqnList;
input String header;
input Boolean printExpTree;
algorithm
print(header + "\n");
dumpBackendDAEEqnList2(inBackendDAEEqnList,printExpTree);
print("===================\n");
end dumpBackendDAEEqnList;
protected function dumpBackendDAEEqnList2
input list<BackendDAE.Equation> inBackendDAEEqnList;
input Boolean printExpTree;
algorithm
_ := matchcontinue (inBackendDAEEqnList,printExpTree)
local
DAE.Exp e1_1,e2_1,e1,e2,e_1,e;
String str;
list<String> strList;
list<BackendDAE.Equation> res;
list<DAE.Exp> expList,expList2;
Integer i;
DAE.ElementSource source;
DAE.Algorithm alg;
Boolean diffed;
DAE.ComponentRef cr;
BackendDAE.EquationKind eqKind;
BackendDAE.WhenEquation weqn;
case ({}, _) then ();
case (BackendDAE.EQUATION(exp=e1, scalar=e2, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res, _) equation /*done*/
str = "EQUATION: ";
str = str + ExpressionDump.printExpStr(e1);
str = str + " = ";
str = str + ExpressionDump.printExpStr(e2);
str = str + " (" + equationKindString(eqKind) + ")\n";
print(str);
str = "LHS:\n";
str = str + ExpressionDump.dumpExpStr(e1, 0);
str = str + "RHS:\n";
str = str + ExpressionDump.dumpExpStr(e2, 0);
str = str + "\n";
str = if printExpTree then str else "";
print(str);
dumpBackendDAEEqnList2(res, printExpTree);
then ();
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res, _) equation /*done*/
str = "COMPLEX_EQUATION: ";
str = str + ExpressionDump.printExpStr(e1);
str = str + " = ";
str = str + ExpressionDump.printExpStr(e2);
str = str + " (" + equationKindString(eqKind) + ")\n";
print(str);
str = "LHS:\n";
str = str + ExpressionDump.dumpExpStr(e1, 0);
str = str + "RHS:\n";
str = str + ExpressionDump.dumpExpStr(e2, 0);
str = str + "\n";
str = if printExpTree then str else "";
print(str);
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.SOLVED_EQUATION(exp=e, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res,_) equation
print("SOLVED_EQUATION: ");
str = ExpressionDump.printExpStr(e);
print(str);
print(" (" + equationKindString(eqKind) + ")\n");
str = ExpressionDump.dumpExpStr(e,0);
str = if printExpTree then str else "";
print(str);
print("\n");
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.RESIDUAL_EQUATION(exp=e, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res, _) equation /*done*/
str = "RESIDUAL_EQUATION: ";
str = str + ExpressionDump.printExpStr(e);
str = str + " (" + equationKindString(eqKind) + ")\n";
print(str);
str = ExpressionDump.dumpExpStr(e, 0);
str = str + "\n";
str = if printExpTree then str else "";
print(str);
dumpBackendDAEEqnList2(res, printExpTree);
then ();