Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 40.5% 534 / 0 / 1318
Functions: -% 0 / 1 / 1
Branches: 37.9% 122 / 0 / 322

OMCompiler/Compiler/BackEnd/BackendDump.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package BackendDump
37 " file: BackendDump.mo
38 package: BackendDump
39 description: Unparsing the BackendDAE structure
40
41
42 These file is subdivided into several section:
43 - section for all print* functions
44 - section for all dump* functions
45 - section for all *String functions
46 - section for all debug* functions
47 - unsorted section
48
49 Please follow the introduced naming style (above) and sort all new functions
50 into the corresponding section (except unsorted section).
51 "
52
53 import BackendDAE;
54 import DAE;
55 import HashSet;
56 import Tpl;
57
58 protected
59 import Absyn;
60 import AbsynUtil;
61 import Array;
62 import BackendDAEUtil;
63 import BackendEquation;
64 import BackendVariable;
65 import BaseHashSet;
66 import ComponentReference;
67 protected import ComponentReferenceBasics;
68 import DAEDump;
69 import DAEDumpTypes;
70 import DAEUtil;
71 import Debug;
72 import DumpHTML;
73 import ElementSource;
74 import Error;
75 import Expression;
76 protected import ExpressionBasics;
77 import ExpressionDump;
78 import Flags;
79 import GraphvizDump;
80 import GraphML;
81 import HpcOmTaskGraph;
82 import Initialization;
83 import IOStream;
84 import List;
85 import Matching;
86 import MMath;
87 import System;
88 import Util;
89 import ZeroCrossings;
90
91 // =============================================================================
92 // section for all print* functions
93 //
94 // These are functions, that print directly to the standard-stream.
95 // - printBackendDAE
96 // - printEqSystem
97 // - printEquation
98 // - printEquationArray
99 // - printEquationList
100 // - printEquations
101 // - printClassAttributes
102 // - printShared
103 // - printStateSets
104 // - printVar
105 // - printVariables
106 // - printVarList
107 // =============================================================================
108
109 public function printBackendDAE "This function dumps the BackendDAE.BackendDAE representation to stdout."
110 input BackendDAE.BackendDAE inBackendDAE;
111 protected
112 BackendDAE.EqSystems eqs;
113 BackendDAE.Shared shared;
114 algorithm
115 79 BackendDAE.DAE(eqs, shared) := inBackendDAE;
116 79 List.map_0(eqs, printEqSystem);
117 79 print("\n");
118 79 printShared(shared);
119 end printBackendDAE;
120
121 public function printEqSystem "This function prints the BackendDAE.EqSystem representation to stdout."
122 input BackendDAE.EqSystem inSyst;
123 algorithm
124 127 print("\n" + partitionKindString(inSyst.partitionKind) + "\n" + UNDERLINE + "\n");
125 127 dumpVariables(inSyst.orderedVars, "Variables");
126 127 dumpEquationArray(inSyst.orderedEqs, "Equations");
127 127 dumpEquationArray(inSyst.removedEqs, "Simple Equations");
128 127 dumpStateSets(inSyst.stateSets, "State Sets");
129 127 dumpOption(inSyst.m, dumpAdjacencyMatrix);
130 127 dumpOption(inSyst.mT, dumpAdjacencyMatrixT);
131
132 127 print("\n");
133 127 dumpFullMatching(inSyst.matching,SOME(inSyst));
134 127 print("\n");
135 end printEqSystem;
136
137 public function printEquation "author: PA
138 Helper function to print_equations"
139 input BackendDAE.Equation inEquation;
140 algorithm
141 ✗ print(equationString(inEquation) + "\n");
142 end printEquation;
143
144 public function printEquationArray "Helper function to dump."
145 input BackendDAE.EquationArray eqns;
146 algorithm
147 271 List.fold(BackendEquation.equationList(eqns), printEquationList2, (1, 1));
148 end printEquationArray;
149
150 public function printEquationList "Helper function to dump."
151 input list<BackendDAE.Equation> eqns;
152 algorithm
153 15 List.fold(eqns, printEquationList2, (1, 1));
154 end printEquationList;
155
156 protected function printEquationList2 "Helper function for printEquationArray and printEquationList"
157 input BackendDAE.Equation inEquation;
158 input tuple<Integer,Integer> inInteger;
159 output tuple<Integer,Integer> oInteger;
160 protected
161 Integer iscalar,i,size;
162 BackendDAE.EquationAttributes attr;
163 algorithm
164 7253 (i,iscalar) := inInteger;
165 7253 size := BackendEquation.equationSize(inEquation);
166 7253 attr := BackendEquation.getEquationAttributes(inEquation);
167 7253 print(intString(i) + "/" + intString(iscalar) + " (" + intString(size) + "): " + equationString(inEquation) + " " + equationAttrString(attr) + "\n");
168 7253 oInteger := (i + 1,iscalar + size);
169 end printEquationList2;
170
171 public function equationListString
172 input list<BackendDAE.Equation> inEqns;
173 input String heading;
174 output String outString;
175 algorithm
176 outString := match heading
177 local
178 String buffer;
179
180 case "" algorithm
181 ✗ (_, _, buffer) := List.fold(inEqns, equationList2String, (1, 1, ""));
182 then buffer;
183
184 else algorithm
185 ✗ (_, _, buffer) := List.fold(inEqns, equationList2String, (1, 1, ""));
186 ✗ buffer := heading + "\n" + UNDERLINE + "\n" + buffer;
187 then buffer;
188 end match;
189 end equationListString;
190
191 protected function equationList2String
192 input BackendDAE.Equation inEquation;
193 input tuple<Integer, Integer, String /*buffer*/> inTuple;
194 output tuple<Integer, Integer, String /*buffer*/> outTuple;
195 protected
196 Integer iscalar, i, size;
197 String buffer;
198 algorithm
199 ✗ (i, iscalar, buffer) := inTuple;
200 ✗ size := BackendEquation.equationSize(inEquation);
201 ✗ buffer := buffer + intString(i) + "/" + intString(iscalar) + " (" + intString(size) + "): " + equationString(inEquation) + "\n";
202 ✗ outTuple := (i + 1, iscalar + size, buffer);
203 end equationList2String;
204
205 public function printEquations ""
206 input list<Integer> inIntegerLst;
207 input BackendDAE.EqSystem syst;
208 algorithm
209 ():= match inIntegerLst
210 local
211 Integer n;
212 list<Integer> rest;
213 case {} then ();
214 case n :: rest algorithm
215 ✗ printEquations(rest, syst);
216 ✗ printEquationNo(n, syst);
217 then ();
218 end match;
219 end printEquations;
220
221 protected function printEquationNo "author: PA
222 Helper function to printEquations"
223 input Integer inInteger;
224 input BackendDAE.EqSystem syst;
225 algorithm
226 ():=
227 match (inInteger,syst)
228 local
229 Integer eqno;
230 BackendDAE.Equation eq;
231 BackendDAE.EquationArray eqns;
232 case (eqno,BackendDAE.EQSYSTEM(orderedEqs = eqns))
233 algorithm
234 ✗ eq := BackendEquation.get(eqns, eqno);
235 ✗ printEquation(eq);
236 then
237 ();
238 end match;
239 end printEquationNo;
240
241 public function printClassAttributes "This unction print the Optimica ClassAttributes: objetiveE, objetiveE"
242 input DAE.ClassAttributes optimicaFun;
243 protected
244 Option<DAE.Exp> e1,e2;
245 algorithm
246 ✗ DAE.OPTIMIZATION_ATTRS(objetiveE = e1, objectiveIntegrandE = e2) := optimicaFun;
247 ✗ print("Mayer" + "\n" + UNDERLINE + "\n\n");
248 ✗ print(ExpressionDump.printOptExpStr(e1));
249 ✗ print("Lagrange" + "\n" + UNDERLINE + "\n\n");
250 ✗ print(ExpressionDump.printOptExpStr(e2));
251 ✗ print("\n");
252 end printClassAttributes;
253
254 public function printShared "This function dumps the BackendDAE.Shared representation to stdout."
255 input BackendDAE.Shared inShared;
256 protected
257 algorithm
258 79 print("\nBackendDAEType: ");
259 79 printBackendDAEType(inShared.backendDAEType);
260 79 print("\n\n");
261
262 79 dumpVariables(inShared.globalKnownVars, "Known variables only depending on parameters and constants - globalKnownVars");
263 79 dumpVariables(inShared.localKnownVars, "Known variables only depending on states and inputs - localKnownVars");
264 79 dumpVariables(inShared.externalObjects, "External Objects");
265 79 dumpExternalObjectClasses(inShared.extObjClasses, "Classes of External Objects");
266 79 dumpVariables(inShared.aliasVars, "Alias Variables");
267 79 dumpEquationArray(inShared.removedEqs, "Simple Shared Equations");
268 79 dumpEquationArray(inShared.initialEqs, "Initial Equations");
269 79 dumpZeroCrossingList(ZeroCrossings.toList(inShared.eventInfo.zeroCrossings), "Zero Crossings");
270 79 dumpZeroCrossingList(ZeroCrossings.toList(inShared.eventInfo.relations), "Relations");
271
3/4
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 77 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
79 if stringEqual(Config.simCodeTarget(), "Cpp") then
272 2 dumpZeroCrossingList(ZeroCrossings.toList(inShared.eventInfo.samples), "Samples");
273 else
274 77 dumpTimeEvents(inShared.eventInfo.timeEvents, "Time Events");
275 end if;
276 79 dumpConstraintList(inShared.constraints, "Constraints");
277 79 dumpBasePartitions(inShared.partitionsInfo.basePartitions, "Base partitions");
278 79 dumpSubPartitions(inShared.partitionsInfo.subPartitions, "Sub partitions");
279
280
1/2
✓ Branch 1 taken 79 times.
✗ Branch 2 not taken.
79 if Flags.isSet(Flags.DUMP_FUNCTIONS) then
281 ✗ DAEDump.dumpFunctionTree(inShared.functionTree, "Functions");
282 end if;
283
284 end printShared;
285
286 public function printBasePartitions
287 input array<BackendDAE.BasePartition> basePartitions;
288 protected
289 String clkExpStr, nSubClocksStr;
290 algorithm
291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
14 for i in 1:arrayLength(basePartitions) loop
292 8 clkExpStr := Tpl.tplString2( ExpressionDumpTpl.dumpClockKind,
293 basePartitions[i].clock, "");
294 8 nSubClocksStr := intString(basePartitions[i].nSubClocks);
295 8 print(intString(i) + ": " + clkExpStr + "[" + nSubClocksStr + "]" + "\n");
296 end for;
297 end printBasePartitions;
298
299 public function printSubPartitions
300 input array<BackendDAE.SubPartition> subPartitions;
301 protected
302 String subClockStr, eventStr;
303 algorithm
304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
18 for i in 1:arrayLength(subPartitions) loop
305 12 subClockStr := subClockString(subPartitions[i].clock);
306
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
22 eventStr := "event(" + boolString(subPartitions[i].holdEvents) + ")";
307 12 print(intString(i) + ": " + subClockStr + " " + eventStr + "\n");
308 end for;
309 end printSubPartitions;
310
311 public function subClockString
312 input BackendDAE.SubClock subClock;
313 output String subClockString;
314 algorithm
315 subClockString := match subClock
316 local
317 String factorStr, shiftStr, solverStr;
318 case BackendDAE.INFERED_SUBCLOCK()
319 then "INFERED_SUBCLOCK";
320 case BackendDAE.SUBCLOCK(_)
321 algorithm
322 12 factorStr := "factor(" + MMath.rationalString(subClock.factor) + ")";
323 12 shiftStr := "shift(" + MMath.rationalString(subClock.shift) + ")";
324 12 solverStr := "solver(" + optionString(subClock.solver) + ")";
325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if stringLength(solverStr) > 8 then
326 ✗ subClockString := factorStr + " " + shiftStr + " " + solverStr;
327 else
328 12 subClockString := factorStr + " " + shiftStr + " ";
329 end if;
330 then subClockString;
331 end match;
332 end subClockString;
333
334 public function optionString
335 input Option<String> option;
336 output String optionString;
337 algorithm
338 optionString := match option
339 local
340 String s;
341 case SOME(s) then s;
342 else "";
343 end match;
344 end optionString;
345
346 public function printBackendDAEType "This is a helper for printShared."
347 input BackendDAE.BackendDAEType btp;
348 algorithm
349 79 print(printBackendDAEType2String(btp));
350 end printBackendDAEType;
351
352 public function printBackendDAEType2String "This is a helper for printShared."
353 input BackendDAE.BackendDAEType btp;
354 output String str;
355 algorithm
356 str := match btp
357 case BackendDAE.SIMULATION() then "simulation";
358 case BackendDAE.JACOBIAN() then "jacobian";
359 case BackendDAE.ALGEQSYSTEM() then "algebraic loop";
360 case BackendDAE.ARRAYSYSTEM() then "multidim equation arrays";
361 case BackendDAE.PARAMETERSYSTEM() then "parameter system";
362 case BackendDAE.INITIALSYSTEM() then "initialization";
363 case BackendDAE.INLINESYSTEM() then "inline system";
364 end match;
365 end printBackendDAEType2String;
366
367 public function printStateSets "author: Frenkel TUD"
368 input BackendDAE.StateSets stateSets;
369 algorithm
370 ✗ List.map_0(stateSets, printStateSet);
371 end printStateSets;
372
373 protected function printStateSet "author: lochel"
374 input BackendDAE.StateSet inStateSet;
375 algorithm
376 ✗ print("StateSet \"" + ComponentReferenceBasics.printComponentRefStr(ComponentReferenceBasics.crefFirstCref(inStateSet.crA)) + "\" (rang " + intString(inStateSet.rang) + ")\n");
377
378 ✗ dumpVarList(inStateSet.statescandidates, "state candidates");
379 ✗ dumpEquationList(inStateSet.eqns, "eqns");
380
381 ✗ dumpVarList(inStateSet.ovars, "ovars");
382 ✗ dumpEquationList(inStateSet.oeqns, "oeqns");
383
384 ✗ dumpVarList(inStateSet.varA, "varA");
385 ✗ dumpVarList(inStateSet.varJ, "varJ");
386
387 //print(jacobianString(inStateSet.jacobian));
388 end printStateSet;
389
390 public function printVar
391 input BackendDAE.Var inVar;
392 algorithm
393 10259 print(varString(inVar) + "\n");
394 end printVar;
395
396 public function printVariables "Helper function to dump."
397 input BackendDAE.Variables vars;
398 algorithm
399 285 List.fold(BackendVariable.varList(vars), printVars1, 1);
400 end printVariables;
401
402 public function printVarList "Helper function to dump."
403 input list<BackendDAE.Var> vars;
404 algorithm
405 262 List.fold(vars, printVars1, 1);
406 end printVarList;
407
408 protected function printVars1 "This is a helper function for printVariables and printVarList"
409 input BackendDAE.Var inVar;
410 input Integer inVarNo;
411 output Integer outVarNo;
412 algorithm
413 10259 print(intString(inVarNo));
414 10259 print(": ");
415 10259 printVar(inVar);
416 10259 outVarNo := inVarNo + 1;
417 end printVars1;
418
419 public function varListString
420 input list<BackendDAE.Var> inVars;
421 input String heading;
422 output String outString;
423 algorithm
424 outString := match heading
425 local
426 String buffer;
427
428 case "" algorithm
429 ✗ (_, buffer) := List.fold(inVars, var1String, (1, ""));
430 then buffer;
431
432 else algorithm
433 ✗ (_, buffer) := List.fold(inVars, var1String, (1, ""));
434 ✗ buffer := heading + "\n" + UNDERLINE + "\n" + buffer;
435 then buffer;
436 end match;
437 end varListString;
438
439 protected function var1String
440 input BackendDAE.Var inVar;
441 input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
442 output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
443 protected
444 Integer varNo;
445 String buffer;
446 algorithm
447 ✗ (varNo, buffer) := inTpl;
448 ✗ buffer := buffer + intString(varNo) + ": ";
449 ✗ buffer := buffer + varString(inVar) + "\n";
450 ✗ outTpl := (varNo + 1, buffer);
451 end var1String;
452
453 public function varListStringShort
454 input list<BackendDAE.Var> inVars;
455 input String heading;
456 output String outString;
457 algorithm
458 outString := match heading
459 local
460 String buffer;
461
462 case "" algorithm
463 ✗ (_, buffer) := List.fold(inVars, varNameString, (1, ""));
464 then buffer;
465
466 else algorithm
467 3 (_, buffer) := List.fold(inVars, varNameString, (1, ""));
468 3 buffer := heading + "\n" + UNDERLINE + "\n" + buffer;
469 then buffer;
470 end match;
471 end varListStringShort;
472
473 protected function varNameString
474 input BackendDAE.Var inVar;
475 input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
476 output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
477 protected
478 Integer varNo;
479 String buffer;
480 algorithm
481 17 (varNo, buffer) := inTpl;
482 17 buffer := buffer + intString(varNo) + ": ";
483 17 buffer := buffer + ComponentReferenceBasics.printComponentRefStr(inVar.varName) + "\n";
484 17 outTpl := (varNo + 1, buffer);
485 end varNameString;
486
487 public function varListStringIndented
488 input list<BackendDAE.Var> inVars;
489 input String heading;
490 output String outString;
491 algorithm
492 outString := match heading
493 local
494 String buffer;
495
496 case "" algorithm
497 ✗ (_, buffer) := List.fold(inVars, var1StringIndented, (1, ""));
498 then buffer;
499
500 else algorithm
501 ✗ (_, buffer) := List.fold(inVars, var1StringIndented, (1, ""));
502 ✗ buffer := heading + "\n" + buffer;
503 then buffer;
504 end match;
505 end varListStringIndented;
506
507 protected function var1StringIndented
508 input BackendDAE.Var inVar;
509 input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
510 output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
511 protected
512 Integer varNo;
513 String buffer;
514 algorithm
515 ✗ (varNo, buffer) := inTpl;
516 ✗ buffer := buffer + " " + intString(varNo) + ": ";
517 ✗ buffer := buffer + varString(inVar) + "\n";
518 ✗ outTpl := (varNo + 1, buffer);
519 end var1StringIndented;
520
521 protected function printExternalObjectClasses "dump classes of external objects"
522 input BackendDAE.ExternalObjectClasses cls;
523 algorithm
524 () := match cls
525 local
526 Absyn.Path path;
527 list<Absyn.Path> paths;
528 list<String> paths_lst;
529 DAE.ElementSource source "the element source";
530 String path_str;
531
532 case {} then ();
533
534 case BackendDAE.EXTOBJCLASS(path,source)::_ algorithm
535 ✗ print("class ");
536 ✗ print(AbsynUtil.pathString(path));
537 ✗ print("\n extends ExternalObject;");
538 ✗ print("\n origin: ");
539 ✗ paths := ElementSource.getElementSourceTypes(source);
540 ✗ paths_lst := list(AbsynUtil.pathString(p) for p in paths);
541 ✗ path_str := stringDelimitList(paths_lst, ", ");
542 ✗ print(path_str + "\n");
543 ✗ print("end ");print(AbsynUtil.pathString(path));
544 then ();
545 end match;
546 end printExternalObjectClasses;
547
548 public function printSparsityPatternCrefs
549 input BackendDAE.SparsePatternCrefs inPattern;
550 algorithm
551 ✗ for e in inPattern loop
552 ✗ print(ComponentReferenceBasics.printComponentRefStr(Util.tuple21(e)) +
553 " affects the following (" + intString(listLength(Util.tuple22(e))) +
554 ") outputs\n ");
555 ✗ ComponentReference.printComponentRefList(Util.tuple22(e));
556 end for;
557 end printSparsityPatternCrefs;
558
559
560 // =============================================================================
561 // section for all graphviz* functions
562 //
563 // =============================================================================
564
565 public function graphvizBackendDAE
566 input BackendDAE.BackendDAE inBackendDAE;
567 input String inFileNameSuffix;
568 protected
569 BackendDAE.BackendDAE dae;
570 algorithm
571 ✗ dae := setAdjacencyMatrix(inBackendDAE);
572 ✗ Tpl.tplNoret2(GraphvizDump.dumpBackendDAE, dae, inFileNameSuffix);
573 end graphvizBackendDAE;
574
575 public function graphvizAdjacencyMatrix
576 input BackendDAE.BackendDAE inBackendDAE;
577 input String inFileNameSuffix;
578 protected
579 BackendDAE.BackendDAE dae;
580 algorithm
581 ✗ dae := setAdjacencyMatrix(inBackendDAE);
582 ✗ Tpl.tplNoret2(GraphvizDump.dumpAdjacencyMatrix, dae, inFileNameSuffix);
583 end graphvizAdjacencyMatrix;
584
585 protected function setAdjacencyMatrix
586 input BackendDAE.BackendDAE inBackendDAE;
587 output BackendDAE.BackendDAE outBackendDAE;
588 protected
589 BackendDAE.EqSystems eqSystems;
590 BackendDAE.Shared shared;
591 algorithm
592 ✗ BackendDAE.DAE(eqSystems, shared) := inBackendDAE;
593 ✗ eqSystems := List.map1(eqSystems, setAdjacencyMatrix1, BackendDAEUtil.isInitializationDAE(shared));
594 ✗ outBackendDAE := BackendDAE.DAE(eqSystems, shared);
595 end setAdjacencyMatrix;
596
597 protected function setAdjacencyMatrix1
598 input BackendDAE.EqSystem inEqSystem;
599 input Boolean isInitial;
600 output BackendDAE.EqSystem outEqSystem;
601 algorithm
602 ✗ (outEqSystem, _, _) := BackendDAEUtil.getAdjacencyMatrix(inEqSystem, BackendDAE.NORMAL(), NONE(), isInitial);
603 end setAdjacencyMatrix1;
604
605 // =============================================================================
606 // section for all dump* functions
607 //
608 // These are functions, that print directly to the standard-stream and separates
609 // there output (e.g. with some kind of headings).
610 // - dumpBackendDAE
611 // - dumpBackendDAEEqnList
612 // - dumpBackendDAEVarList
613 // - dumpComponent
614 // - dumpComponents
615 // - dumpComponentsAdvanced
616 // - dumpEqnsSolved
617 // - dumpEqSystem
618 // - dumpEqSystems
619 // - dumpEquationArray
620 // - dumpEquationList
621 // - dumpHashSet
622 // - dumpSparsityPattern
623 // - dumpTearing
624 // - dumpVariables
625 // - dumpVarList
626 // =============================================================================
627
628 public constant String BORDER = "########################################";
629 public constant String UNDERLINE = "========================================";
630
631 public function dumpDAE "dumps the DAE representation of the current transformation state"
632 input BackendDAE.BackendDAE inDAE;
633 output BackendDAE.BackendDAE outDAE = inDAE;
634 algorithm
635 2 dumpBackendDAE(inDAE, "dumpDAE");
636 end dumpDAE;
637
638 public function dumpBackendDAE "This function dumps the BackendDAE.BackendDAE representation to stdout."
639 input BackendDAE.BackendDAE inBackendDAE;
640 input String heading;
641 algorithm
642 79 print("\n" + BORDER + "\n" + heading + "\n" + BORDER + "\n\n");
643 79 printBackendDAE(inBackendDAE);
644 79 print("\n");
645 end dumpBackendDAE;
646
647 public function dumpEqSystem
648 input BackendDAE.EqSystem inEqSystem;
649 input String heading;
650 algorithm
651 ✗ print("\n" + heading + "\n" + UNDERLINE + "\n");
652 ✗ printEqSystem(inEqSystem);
653 ✗ print("\n");
654 end dumpEqSystem;
655
656 public function dumpEqSystemShort
657 input BackendDAE.EqSystem inEqSystem;
658 input String heading;
659 algorithm
660 ✗ print("\n" + heading + " (" + partitionKindString(inEqSystem.partitionKind) + ")\n" + UNDERLINE + "\n");
661 ✗ dumpVariables(inEqSystem.orderedVars, "Variables");
662 ✗ dumpEquationArray(inEqSystem.orderedEqs, "Equations");
663 ✗ print("\n");
664 end dumpEqSystemShort;
665
666 public function dumpEqSystems
667 input BackendDAE.EqSystems inEqSystems;
668 input String heading;
669 algorithm
670 6 print("\n" + BORDER + "\n" + heading + " (" + intString(listLength(inEqSystems)) + " partitions)\n" + BORDER + "\n\n");
671 6 List.map_0(inEqSystems, printEqSystem);
672 6 print("\n");
673 end dumpEqSystems;
674
675 public function dumpBasePartitions
676 input array<BackendDAE.BasePartition> basePartitions;
677 input String heading;
678 algorithm
679
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 6 times.
85 if arrayLength(basePartitions) > 0 then
680 12 print("\n" + heading + " (" + intString(arrayLength(basePartitions)) + ")\n" + UNDERLINE + "\n");
681 6 printBasePartitions(basePartitions);
682 6 print("\n");
683 end if;
684 end dumpBasePartitions;
685
686 public function dumpSubPartitions
687 input array<BackendDAE.SubPartition> subPartitions;
688 input String heading;
689 algorithm
690
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 6 times.
85 if arrayLength(subPartitions) > 0 then
691 12 print("\n" + heading + " (" + intString(arrayLength(subPartitions)) + ")\n" + UNDERLINE + "\n");
692 6 printSubPartitions(subPartitions);
693 6 print("\n");
694 end if;
695 end dumpSubPartitions;
696
697
698 public function dumpVariables "function dumpVariables"
699 input BackendDAE.Variables inVars;
700 input String heading;
701 algorithm
702
2/2
✓ Branch 1 taken 322 times.
✓ Branch 2 taken 285 times.
607 if BackendVariable.varsSize(inVars) > 0 then
703 285 print("\n" + heading + " (" + intString(BackendVariable.varsSize(inVars)) + ")\n" + UNDERLINE + "\n");
704 285 printVariables(inVars);
705 285 print("\n");
706 end if;
707 end dumpVariables;
708
709 public function dumpVarList "function dumpVarList"
710 input list<BackendDAE.Var> inVars;
711 input String heading;
712 algorithm
713 250 print("\n" + heading + " (" + intString(listLength(inVars)) + ")\n" + UNDERLINE + "\n");
714 250 printVarList(inVars);
715 250 print("\n");
716 end dumpVarList;
717
718 public function dumpEquationArray "function dumpEquationArray"
719 input BackendDAE.EquationArray inEqns;
720 input String heading;
721 algorithm
722
2/2
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 271 times.
565 if BackendEquation.getNumberOfEquations(inEqns) + BackendEquation.equationArraySize(inEqns) > 0 then
723 271 print("\n" + heading + " (" + intString(BackendEquation.getNumberOfEquations(inEqns)) + ", " + intString(BackendEquation.equationArraySize(inEqns)) + ")\n" + UNDERLINE + "\n");
724 271 printEquationArray(inEqns);
725 271 print("\n");
726 end if;
727 end dumpEquationArray;
728
729 public function dumpEquationList "function dumpEquationList"
730 input list<BackendDAE.Equation> inEqns;
731 input String heading;
732 algorithm
733
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 3 times.
115 if not listEmpty(inEqns) then
734 3 print("\n" + heading + " (" + intString(listLength(inEqns)) + ")\n" + UNDERLINE + "\n");
735 3 printEquationList(inEqns);
736 3 print("\n");
737 end if;
738 end dumpEquationList;
739
740 protected function dumpExternalObjectClasses "dump classes of external objects"
741 input BackendDAE.ExternalObjectClasses inEOC;
742 input String heading;
743 algorithm
744
1/2
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
79 if not listEmpty(inEOC) then
745 ✗ print("\n" + heading + " (" + intString(listLength(inEOC)) + ")\n" + UNDERLINE + "\n");
746 ✗ printExternalObjectClasses(inEOC);
747 ✗ print("\n");
748 end if;
749 end dumpExternalObjectClasses;
750
751 public function dumpStateSets
752 input BackendDAE.StateSets stateSets;
753 input String heading;
754 algorithm
755
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if not listEmpty(stateSets) then
756 ✗ print("\n" + heading + "\n" + UNDERLINE + "\n");
757 ✗ printStateSets(stateSets);
758 ✗ print("\n");
759 end if;
760 end dumpStateSets;
761
762 public function dumpZeroCrossingList
763 input list<BackendDAE.ZeroCrossing> inZeroCrossingList;
764 input String heading;
765 protected
766 BackendDAE.ZeroCrossing zeroCrossing;
767 algorithm
768
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 2 times.
160 if not listEmpty(inZeroCrossingList) then
769 2 print("\n" + heading + " (" + intString(listLength(inZeroCrossingList)) + ")\n" + UNDERLINE + "\n");
770
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for zeroCrossing in inZeroCrossingList loop
771 6 print(zeroCrossingString(zeroCrossing) + "\n");
772 end for;
773 2 print("\n");
774 end if;
775 end dumpZeroCrossingList;
776
777 public function dumpTimeEvents
778 input list<BackendDAE.TimeEvent> inTimeEvents;
779 input String heading;
780 protected
781 BackendDAE.TimeEvent timeEvent;
782 algorithm
783
1/2
✓ Branch 0 taken 77 times.
✗ Branch 1 not taken.
77 if not listEmpty(inTimeEvents) then
784 ✗ print("\n" + heading + " (" + intString(listLength(inTimeEvents)) + ")\n" + UNDERLINE + "\n");
785 ✗ for timeEvent in inTimeEvents loop
786 ✗ print(timeEventString(timeEvent) + "\n");
787 end for;
788 ✗ print("\n");
789 end if;
790 end dumpTimeEvents;
791
792 protected function dumpConstraintList
793 input list<DAE.Constraint> inConstraintArray;
794 input String heading;
795 algorithm
796
1/2
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
79 if not listEmpty(inConstraintArray) then
797 ✗ print("\n" + heading + " (" + intString(listLength(inConstraintArray)) + ")\n" + UNDERLINE + "\n");
798 ✗ dumpConstraints(inConstraintArray, 0);
799 ✗ print("\n");
800 end if;
801 end dumpConstraintList;
802
803 public function dumpHashSet "author lochel"
804 input HashSet.HashSet hashSet;
805 input String heading;
806 protected
807 Integer size;
808 algorithm
809 ✗ size := BaseHashSet.currentSize(hashSet);
810 ✗ print("\n" + heading + " (" + intString(size) + ")\n" + UNDERLINE + "\n");
811 ✗ BaseHashSet.printHashSet(hashSet);
812 ✗ print("\n");
813 end dumpHashSet;
814
815 public function dumpSparsityPattern
816 input BackendDAE.SparsePattern inPattern;
817 input String heading;
818 protected
819 BackendDAE.SparsePatternCrefs pattern,patternT;
820 list< .DAE.ComponentRef> diffVars, diffedVars;
821 Integer nnz;
822 algorithm
823 ✗ (pattern, patternT, (diffVars, diffedVars), nnz) := inPattern;
824
825 ✗ print("\n" + heading + "\n" + UNDERLINE + "\n");
826 ✗ print("Number of non zero elements: " + intString(nnz) + "\n");
827 ✗ print("Independents [or inputs] (" + intString(listLength(diffVars)) + ")\n");
828 ✗ ComponentReference.printComponentRefList(diffVars);
829
830 ✗ print("Dependents [or outputs] (" + intString(listLength(diffedVars)) + ")\n");
831 ✗ ComponentReference.printComponentRefList(diffedVars);
832
833 ✗ printSparsityPatternCrefs(pattern);
834 ✗ print("\n" + "Transposed pattern" + "\n");
835 ✗ printSparsityPatternCrefs(patternT);
836 end dumpSparsityPattern;
837
838 public function dumpSparseColoring
839 input BackendDAE.SparseColoring inColoring;
840 input String heading;
841 protected
842 Integer i=0;
843 algorithm
844 ✗ print("\n" + heading + "\n" + UNDERLINE + "\n");
845 ✗ print("Number of colors: " + intString(listLength(inColoring)) + "\n");
846 ✗ for crList in inColoring loop
847 ✗ print("The following (" + intString(listLength(crList)) + ") independents belong to one color\n"+intString(i)+": ");
848 ✗ ComponentReference.printComponentRefList(crList);
849 ✗ i := i+1;
850 end for;
851 end dumpSparseColoring;
852
853 public function dumpTearing "
854 author: Frenkel TUD
855 Dump tearing vars and residual equations."
856 input list<list<Integer>> inResEqn;
857 input list<list<Integer>> inTearVar;
858 algorithm
859 ():=
860 match (inResEqn,inTearVar)
861 local
862 list<Integer> tearingvars,residualeqns;
863 list<list<Integer>> r,t;
864 list<String> str_r,str_t;
865 String str_r_f,str_r_1,str_t_f,str_t_1,str,sr,st;
866 case (residualeqns::r,tearingvars::t)
867 algorithm
868 ✗ str_r := List.map(residualeqns, intString);
869 ✗ str_r_f := stringDelimitList(str_r, ", ");
870 ✗ str_r_1 := stringAppend(str_r_f, "\n");
871 ✗ sr := stringAppend("ResidualEqns: ",str_r_1);
872 ✗ str_t := List.map(tearingvars, intString);
873 ✗ str_t_f := stringDelimitList(str_t, ", ");
874 ✗ str_t_1 := stringAppend(str_t_f, "\n");
875 ✗ st := stringAppend("TearingVars: ",str_t_1);
876 ✗ str := stringAppend(sr, st);
877 ✗ print(str);
878 ✗ print("\n");
879 ✗ dumpTearing(r,t);
880 then
881 ();
882 end match;
883 end dumpTearing;
884
885 public function dumpBackendDAEEqnList
886 input list<BackendDAE.Equation> inBackendDAEEqnList;
887 input String header;
888 input Boolean printExpTree;
889 algorithm
890 ✗ print(header + "\n");
891 ✗ dumpBackendDAEEqnList2(inBackendDAEEqnList,printExpTree);
892 ✗ print("===================\n");
893 end dumpBackendDAEEqnList;
894
895 protected function dumpBackendDAEEqnList2
896 input list<BackendDAE.Equation> inBackendDAEEqnList;
897 input Boolean printExpTree;
898 algorithm
899 () := matchcontinue inBackendDAEEqnList
900 local
901 DAE.Exp e1,e2,e;
902 String str;
903 list<BackendDAE.Equation> res;
904 DAE.Algorithm alg;
905 BackendDAE.EquationKind eqKind;
906 BackendDAE.WhenEquation weqn;
907
908 case {} then ();
909
910 case BackendDAE.EQUATION(exp=e1, scalar=e2, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm /*done*/
911 str := "EQUATION: ";
912 ✗ str := str + ExpressionBasics.printExpStr(e1);
913 ✗ str := str + " = ";
914 ✗ str := str + ExpressionBasics.printExpStr(e2);
915 ✗ str := str + " (" + equationKindString(eqKind) + ")\n";
916 ✗ print(str);
917
918 str := "LHS:\n";
919 ✗ str := str + ExpressionDump.dumpExpStr(e1, 0);
920 ✗ str := str + "RHS:\n";
921 ✗ str := str + ExpressionDump.dumpExpStr(e2, 0);
922 ✗ str := str + "\n";
923 ✗ str := if printExpTree then str else "";
924 ✗ print(str);
925
926 ✗ dumpBackendDAEEqnList2(res, printExpTree);
927 then ();
928
929 case BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm /*done*/
930 str := "COMPLEX_EQUATION: ";
931 ✗ str := str + ExpressionBasics.printExpStr(e1);
932 ✗ str := str + " = ";
933 ✗ str := str + ExpressionBasics.printExpStr(e2);
934 ✗ str := str + " (" + equationKindString(eqKind) + ")\n";
935 ✗ print(str);
936
937 str := "LHS:\n";
938 ✗ str := str + ExpressionDump.dumpExpStr(e1, 0);
939 ✗ str := str + "RHS:\n";
940 ✗ str := str + ExpressionDump.dumpExpStr(e2, 0);
941 ✗ str := str + "\n";
942 ✗ str := if printExpTree then str else "";
943 ✗ print(str);
944
945 ✗ dumpBackendDAEEqnList2(res,printExpTree);
946 then ();
947
948 case BackendDAE.SOLVED_EQUATION(exp=e, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm
949 ✗ print("SOLVED_EQUATION: ");
950 ✗ str := ExpressionBasics.printExpStr(e);
951 ✗ print(str);
952 ✗ print(" (" + equationKindString(eqKind) + ")\n");
953 ✗ str := ExpressionDump.dumpExpStr(e,0);
954 ✗ str := if printExpTree then str else "";
955 ✗ print(str);
956 ✗ print("\n");
957 ✗ dumpBackendDAEEqnList2(res,printExpTree);
958 then ();
959
960 case BackendDAE.RESIDUAL_EQUATION(exp=e, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm /*done*/
961 str := "RESIDUAL_EQUATION: ";
962 ✗ str := str + ExpressionBasics.printExpStr(e);
963 ✗ str := str + " (" + equationKindString(eqKind) + ")\n";
964 ✗ print(str);
965
966 ✗ str := ExpressionDump.dumpExpStr(e, 0);
967 ✗ str := str + "\n";
968 ✗ str := if printExpTree then str else "";
969 ✗ print(str);
970
971 ✗ dumpBackendDAEEqnList2(res, printExpTree);
972 then ();
973
974 case BackendDAE.ARRAY_EQUATION(left=e1, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm
975 ✗ print("ARRAY_EQUATION: ");
976 ✗ str := ExpressionBasics.printExpStr(e1);
977 ✗ print(str);
978 ✗ str := str + " (" + equationKindString(eqKind) + ")\n";
979 ✗ str := ExpressionDump.dumpExpStr(e1,0);
980 ✗ str := if printExpTree then str else "";
981 ✗ print(str);
982 ✗ print("\n");
983 ✗ dumpBackendDAEEqnList2(res,printExpTree);
984 then ();
985
986 case BackendDAE.ALGORITHM(alg=alg, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::res algorithm
987 ✗ print("ALGORITHM: ");
988 ✗ dumpAlgorithms({alg},0);
989 ✗ print(" (" + equationKindString(eqKind) + ")\n");
990 ✗ dumpBackendDAEEqnList2(res,printExpTree);
991 then ();
992
993 case BackendDAE.WHEN_EQUATION(whenEquation=weqn, attr=BackendDAE.EQUATION_ATTRIBUTES(kind=eqKind))::_ algorithm
994 ✗ print("WHEN_EQUATION: ");
995 ✗ str := whenEquationString(weqn, true);
996 ✗ print(str);
997 ✗ str := str + " (" + equationKindString(eqKind) + ")\n";
998 ✗ e := weqn.condition;
999 ✗ str := ExpressionDump.dumpExpStr(e,0);
1000 ✗ str := if printExpTree then str else "";
1001 ✗ print(str);
1002 ✗ print("\n");
1003 then ();
1004
1005 case _::res algorithm
1006 ✗ print("SKIPED EQUATION\n");
1007 ✗ dumpBackendDAEEqnList2(res, printExpTree);
1008 then ();
1009 end matchcontinue;
1010 end dumpBackendDAEEqnList2;
1011
1012 public function dumpBackendDAEVarList
1013 input list<BackendDAE.Var> inBackendDAEVarList;
1014 input String header;
1015 algorithm
1016 ✗ print(header + "\n");
1017 ✗ printVarList(inBackendDAEVarList);
1018 ✗ print("===================\n");
1019 end dumpBackendDAEVarList;
1020
1021 public function dumpEqnsSolved "This function dumps the equations in the order they have to be calculate."
1022 input BackendDAE.BackendDAE inBackendDAE;
1023 input String heading;
1024 protected
1025 BackendDAE.EqSystems eqs;
1026 algorithm
1027 1 print("\n" + heading + "\n" + UNDERLINE + "\n");
1028 1 BackendDAE.DAE(eqs=eqs) := inBackendDAE;
1029 1 List.map_0(eqs, dumpEqnsSolved1);
1030 1 print("\n");
1031 end dumpEqnsSolved;
1032
1033 protected function dumpEqnsSolved1 "This is a helper for dumpEqnsSolved."
1034 input BackendDAE.EqSystem inEqSystem;
1035 algorithm
1036 ():= match inEqSystem
1037 local
1038 BackendDAE.EquationArray eqns;
1039 BackendDAE.Variables vars;
1040 BackendDAE.StrongComponents comps;
1041 case BackendDAE.EQSYSTEM(orderedVars=vars,
1042 orderedEqs=eqns,
1043 matching=BackendDAE.MATCHING(comps=comps)) algorithm
1044 1 dumpEqnsSolved2(comps, eqns, vars);
1045 then ();
1046
1047 else algorithm
1048 ✗ print("No Matching\n");
1049 then ();
1050 end match;
1051 end dumpEqnsSolved1;
1052
1053 protected function dumpEqnsSolved2 "author: Frenkel TUD 2012-03"
1054 input BackendDAE.StrongComponents inComps;
1055 input BackendDAE.EquationArray eqns;
1056 input BackendDAE.Variables vars;
1057 algorithm
1058 () :=
1059 matchcontinue inComps
1060 local
1061 Integer e,v;
1062 list<Integer> elst,vlst,vlst1,elst1,vlst2,elst2;
1063 list<list<Integer>> vlst1Lst;
1064 BackendDAE.StrongComponents rest;
1065 BackendDAE.Var var;
1066 BackendDAE.Equation eqn;
1067 list<BackendDAE.Var> varlst;
1068 list<BackendDAE.Equation> eqnlst;
1069 BackendDAE.JacobianType jacType;
1070 BackendDAE.InnerEquations innerEquations,innerEquations2;
1071 Boolean b;
1072 String s;
1073 Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> jac;
1074 case {} then ();
1075 case BackendDAE.SINGLEEQUATION(eqn=e,var=v)::rest
1076 algorithm
1077 3 print("SingleEquation: " + intString(e) + "\n");
1078 3 var := BackendVariable.getVarAt(vars,v);
1079 3 printVarList({var});
1080 3 eqn := BackendEquation.get(eqns,e);
1081 3 printEquationList({eqn});
1082 3 print("\n");
1083 3 dumpEqnsSolved2(rest,eqns,vars);
1084 then
1085 ();
1086 case BackendDAE.EQUATIONSYSTEM(eqns=elst,vars=vlst,jac=BackendDAE.FULL_JACOBIAN(jac),jacType=jacType)::rest
1087 algorithm
1088 ✗ print("Equationsystem " + jacobianTypeStr(jacType) + ":\n");
1089 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1090 ✗ printVarList(varlst);
1091 ✗ eqnlst := BackendEquation.getList(elst,eqns);
1092 ✗ printEquationList(eqnlst);
1093 ✗ print("\n");
1094 ✗ print("Jac:\n" + dumpJacobianStr(jac) + "\n");
1095 ✗ print("\n");
1096 ✗ dumpEqnsSolved2(rest,eqns,vars);
1097 then
1098 ();
1099 case BackendDAE.SINGLEARRAY(eqn=e,vars=vlst)::rest
1100 algorithm
1101 ✗ print("ArrayEquation:\n");
1102 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1103 ✗ printVarList(varlst);
1104 ✗ eqn := BackendEquation.get(eqns,e);
1105 ✗ printEquationList({eqn});
1106 ✗ print("\n");
1107 ✗ dumpEqnsSolved2(rest,eqns,vars);
1108 then
1109 ();
1110 case BackendDAE.SINGLEIFEQUATION(eqn=e,vars=vlst)::rest
1111 algorithm
1112 ✗ print("IfEquation:\n");
1113 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1114 ✗ printVarList(varlst);
1115 ✗ eqn := BackendEquation.get(eqns,e);
1116 ✗ printEquationList({eqn});
1117 ✗ print("\n");
1118 ✗ dumpEqnsSolved2(rest,eqns,vars);
1119 then
1120 ();
1121 case BackendDAE.SINGLEALGORITHM(eqn=e,vars=vlst)::rest
1122 algorithm
1123 ✗ print("Algorithm:\n");
1124 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1125 ✗ printVarList(varlst);
1126 ✗ eqn := BackendEquation.get(eqns,e);
1127 ✗ printEquationList({eqn});
1128 ✗ print("\n");
1129 ✗ dumpEqnsSolved2(rest,eqns,vars);
1130 then
1131 ();
1132 case BackendDAE.SINGLECOMPLEXEQUATION(eqn=e,vars=vlst)::rest
1133 algorithm
1134 1 print("ComplexEquation:\n");
1135 1 varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1136 1 printVarList(varlst);
1137 1 eqn := BackendEquation.get(eqns,e);
1138 1 printEquationList({eqn});
1139 1 print("\n");
1140 1 dumpEqnsSolved2(rest,eqns,vars);
1141 then
1142 ();
1143 case BackendDAE.SINGLEWHENEQUATION(eqn=e,vars=vlst)::rest
1144 algorithm
1145 ✗ print("WhenEquation:\n");
1146 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1147 ✗ printVarList(varlst);
1148 ✗ eqn := BackendEquation.get(eqns,e);
1149 ✗ printEquationList({eqn});
1150 ✗ print("\n");
1151 ✗ dumpEqnsSolved2(rest,eqns,vars);
1152 then
1153 ();
1154 // no dynamic tearing
1155 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=vlst,residualequations=elst,innerEquations=innerEquations),casualTearingSet=NONE(),linear=b)::rest
1156 algorithm
1157
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 s := if b then "linear" else "nonlinear";
1158 4 print("torn " + s + " Equationsystem:\n");
1159 4 (elst1,vlst1Lst,_) := List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
1160 4 vlst1 := List.flatten(vlst1Lst);
1161 4 varlst := List.map1r(vlst1, BackendVariable.getVarAt, vars);
1162 4 print("\ninternal vars (" + intString(listLength(varlst)) + ")\n");
1163 4 printVarList(varlst);
1164 4 varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1165 4 print("\nresidual vars (" + intString(listLength(varlst)) + ")\n");
1166 4 printVarList(varlst);
1167 4 eqnlst := BackendEquation.getList(elst1,eqns);
1168 4 print("\ninternal equations (" + intString(listLength(eqnlst)) + ")\n");
1169 4 printEquationList(eqnlst);
1170 4 eqnlst := BackendEquation.getList(elst,eqns);
1171 4 print("\nresidual equations (" + intString(listLength(eqnlst)) + ")\n");
1172 4 printEquationList(eqnlst);
1173 4 print("\n");
1174 4 dumpEqnsSolved2(rest,eqns,vars);
1175 then
1176 ();
1177 // dynamic tearing
1178 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=vlst,residualequations=elst,innerEquations=innerEquations),casualTearingSet=SOME(BackendDAE.TEARINGSET(tearingvars=vlst2,residualequations=elst2,innerEquations=innerEquations2)),linear=b)::rest
1179 algorithm
1180 ✗ s := if b then "linear" else "nonlinear";
1181 ✗ print("Strict torn " + s + " Equationsystem:\n");
1182 ✗ (elst1,vlst1Lst,_) := List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
1183 ✗ vlst1 := List.flatten(vlst1Lst);
1184 ✗ varlst := List.map1r(vlst1, BackendVariable.getVarAt, vars);
1185 ✗ printVarList(varlst);
1186 ✗ varlst := List.map1r(vlst, BackendVariable.getVarAt, vars);
1187 ✗ printVarList(varlst);
1188 ✗ print("\n");
1189 ✗ eqnlst := BackendEquation.getList(elst1,eqns);
1190 ✗ printEquationList(eqnlst);
1191 ✗ print("\n");
1192 ✗ eqnlst := BackendEquation.getList(elst,eqns);
1193 ✗ printEquationList(eqnlst);
1194 ✗ print("\n");
1195 ✗ dumpEqnsSolved2(rest,eqns,vars);
1196 ✗ print("Casual torn " + s + " Equationsystem:\n");
1197 ✗ (elst1,vlst1Lst,_) := List.map_3(innerEquations2, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
1198 ✗ vlst1 := List.flatten(vlst1Lst);
1199 ✗ varlst := List.map1r(vlst1, BackendVariable.getVarAt, vars);
1200 ✗ printVarList(varlst);
1201 ✗ varlst := List.map1r(vlst2, BackendVariable.getVarAt, vars);
1202 ✗ printVarList(varlst);
1203 ✗ print("\n");
1204 ✗ eqnlst := BackendEquation.getList(elst1,eqns);
1205 ✗ printEquationList(eqnlst);
1206 ✗ print("\n");
1207 ✗ eqnlst := BackendEquation.getList(elst2,eqns);
1208 ✗ printEquationList(eqnlst);
1209 ✗ print("\n");
1210 ✗ dumpEqnsSolved2(rest,eqns,vars);
1211 then
1212 ();
1213 case _::rest
1214 algorithm
1215 ✗ true := Flags.isSet(Flags.FAILTRACE);
1216 ✗ Debug.traceln("BackendDump.dumpEqnsSolved2 failed!");
1217 ✗ dumpEqnsSolved2(rest,eqns,vars);
1218 then
1219 ();
1220 case _::rest
1221 algorithm
1222 ✗ dumpEqnsSolved2(rest,eqns,vars);
1223 then
1224 ();
1225 end matchcontinue;
1226 end dumpEqnsSolved2;
1227
1228 public function dumpLoops "author: vitalij"
1229 input BackendDAE.BackendDAE inDAE;
1230 output BackendDAE.BackendDAE outDAE = inDAE;
1231 protected
1232 BackendDAE.StrongComponents comps;
1233 BackendDAE.EquationArray eqns;
1234 BackendDAE.Variables vars;
1235 Integer isyst = 1;
1236 Boolean firstComp = true; // used to print header only if there is actually an algebraic loop
1237 algorithm
1238
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for syst in inDAE.eqs loop
1239 firstComp := true;
1240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns, matching=BackendDAE.MATCHING(comps=comps)) := syst;
1241
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 for comp in comps loop
1242
3/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
8 if BackendEquation.isEquationsSystem(comp) or BackendEquation.isTornSystem(comp) then
1243
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if firstComp then
1244 firstComp := false;
1245 4 print("\nsystem " + intString(isyst) + "\n" + UNDERLINE + "\n");
1246 end if;
1247 4 print("\n" + BORDER + BORDER + "\n dumpLoops: SORTED COMPONENT \n" + BORDER + BORDER + "\n\n");
1248 4 dumpEqnsSolved2({comp}, eqns, vars);
1249
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if Flags.isSet(Flags.DUMP_LOOPS_VERBOSE) then
1250 ✗ printComponentAdjacencyMatrixEnhanced(comp, eqns, vars, outDAE.shared);
1251 end if;
1252 end if;
1253 end for;
1254 4 isyst := isyst + 1;
1255 end for;
1256 end dumpLoops;
1257
1258 public function printComponentAdjacencyMatrixEnhanced
1259 input BackendDAE.StrongComponent comp;
1260 input BackendDAE.EquationArray eqns;
1261 input BackendDAE.Variables vars;
1262 input BackendDAE.Shared shared;
1263 protected
1264 list<BackendDAE.Equation> compEqnLst;
1265 list<BackendDAE.Var> compVarLst;
1266 BackendDAE.EquationArray compEqns;
1267 BackendDAE.Variables compVars;
1268 BackendDAE.EqSystem syst;
1269 BackendDAE.AdjacencyMatrixEnhanced m, mT;
1270 algorithm
1271 ✗ (compVarLst, _, compEqnLst, _) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, vars, eqns);
1272 ✗ compEqns := BackendEquation.listEquation(compEqnLst);
1273 ✗ compVars := BackendVariable.listVar(compVarLst);
1274 ✗ syst := BackendDAEUtil.createEqSystem(compVars, compEqns);
1275 ✗ (m, mT, _, _) := BackendDAEUtil.getAdjacencyMatrixEnhancedScalar(syst, shared, false);
1276 ✗ print("\n" + BORDER + BORDER + "\n dumpLoopsVerbose: UNSORTED COMPONENT WITH ENHANCED ADJACENCY MATRIX \n" + BORDER + BORDER + "\n\n");
1277 ✗ dumpVariables(compVars, "component variables");
1278 ✗ dumpEquationArray(compEqns, "component equations");
1279 ✗ dumpAdjacencyMatrixEnhanced(m);
1280 ✗ print("\n\n");
1281 ✗ dumpAdjacencyMatrixTEnhanced(mT);
1282 end printComponentAdjacencyMatrixEnhanced;
1283
1284 public function dumpComponentsAdvanced "author: Frenkel TUD
1285 Prints the blocks of the BLT sorting on stdout."
1286 input list<list<Integer>> l;
1287 input array<Integer> v2;
1288 input BackendDAE.EqSystem syst;
1289 protected
1290 BackendDAE.Variables vars;
1291 algorithm
1292 ✗ print("Blocks\n");
1293 ✗ print("=======\n");
1294 ✗ vars := BackendVariable.daeVars(syst);
1295 ✗ dumpComponentsAdvanced2(l, 1,v2,vars);
1296 end dumpComponentsAdvanced;
1297
1298 protected function dumpComponentsAdvanced2 "author: PA
1299 Helper function to dump_components."
1300 input list<list<Integer>> inIntegerLstLst;
1301 input Integer inInteger;
1302 input array<Integer> v2;
1303 input BackendDAE.Variables vars;
1304 algorithm
1305 ():=
1306 match (inIntegerLstLst, inInteger)
1307 local
1308 Integer i_1,i;
1309 list<String> ls;
1310 String s;
1311 list<Integer> l;
1312 list<list<Integer>> lst;
1313 case ({}, _) then ();
1314 case ((l :: lst), i)
1315 algorithm
1316 ✗ print("{");
1317 ✗ ls := List.map(l, intString);
1318 ✗ s := stringDelimitList(ls, ", ");
1319 ✗ print(s);
1320 ✗ print("} ");
1321 ✗ dumpComponentsAdvanced3(l,v2,vars);
1322 ✗ print("\n");
1323 i_1 := i + 1;
1324 ✗ dumpComponentsAdvanced2(lst, i_1,v2,vars);
1325 then ();
1326 end match;
1327 end dumpComponentsAdvanced2;
1328
1329 protected function dumpComponentsAdvanced3 "author: PA
1330 Helper function to dump_components."
1331 input list<Integer> inIntegerLst;
1332 input array<Integer> v2;
1333 input BackendDAE.Variables vars;
1334 algorithm
1335 ():=
1336 match inIntegerLst
1337 local
1338 Integer i,v;
1339 String s;
1340 list<Integer> l;
1341 DAE.ComponentRef c;
1342 BackendDAE.Var var;
1343 Boolean b;
1344 case {} then ();
1345 case i::{}
1346 algorithm
1347 ✗ v := v2[i];
1348 ✗ var := BackendVariable.getVarAt(vars,v);
1349 ✗ c := BackendVariable.varCref(var);
1350 ✗ b := BackendVariable.isStateVar(var);
1351 ✗ s := if b then "der(" else "";
1352 ✗ print(s);
1353 ✗ s := ComponentReferenceBasics.printComponentRefStr(c);
1354 ✗ print(s);
1355 ✗ s := if b then ") " else " ";
1356 ✗ print(s);
1357 then ();
1358 case i::l
1359 algorithm
1360 ✗ v := v2[i];
1361 ✗ var := BackendVariable.getVarAt(vars,v);
1362 ✗ c := BackendVariable.varCref(var);
1363 ✗ b := BackendVariable.isStateVar(var);
1364 ✗ s := if b then "der(" else "";
1365 ✗ print(s);
1366 ✗ s := ComponentReferenceBasics.printComponentRefStr(c);
1367 ✗ print(s);
1368 ✗ s := if b then ") " else " ";
1369 ✗ print(s);
1370 ✗ dumpComponentsAdvanced3(l,v2,vars);
1371 then ();
1372 end match;
1373 end dumpComponentsAdvanced3;
1374
1375 public function dumpComponents
1376 input BackendDAE.StrongComponents inComps;
1377 input Option<BackendDAE.EqSystem> inSyst = NONE();
1378 algorithm
1379 63 print("StrongComponents\n");
1380 63 print(UNDERLINE + "\n");
1381 63 List.map1(inComps,dumpComponent,inSyst);
1382 end dumpComponents;
1383
1384 public function dumpComponent
1385 input BackendDAE.StrongComponent inComp;
1386 input Option<BackendDAE.EqSystem> inSyst = NONE();
1387
1388 algorithm
1389 215 print(printComponent(inComp,inSyst));
1390
1391 end dumpComponent;
1392
1393 public function printComponent
1394 input BackendDAE.StrongComponent inComp;
1395 input Option<BackendDAE.EqSystem> inSyst = NONE();
1396 output String oString;
1397
1398 protected
1399 String tmpStr,tmpStr2;
1400
1401 algorithm
1402 oString := match inComp
1403 local
1404 Integer i,v;
1405 list<Integer> ilst,vlst,ilst2,vlst2,innerEqLst;
1406 list<list<Integer>> innerVarLst;
1407 list<String> ls;
1408 String s,s2,s3,s4;
1409 BackendDAE.JacobianType jacType;
1410 BackendDAE.InnerEquations innerEquations,innerEquations2;
1411 BackendDAE.EqSystem eSys;
1412 Boolean b;
1413 case BackendDAE.SINGLEEQUATION(eqn=i,var=v)
1414 algorithm
1415 134733 tmpStr := "{" + intString(i) + ":" + intString(v) + "}\n";
1416 then tmpStr;
1417 case BackendDAE.EQUATIONSYSTEM(eqns=ilst,vars=vlst,jacType=jacType)
1418 algorithm
1419 1475 ls := List.map(ilst, intString);
1420 1475 s := stringDelimitList(ls, ", ");
1421 1475 ls := List.map(vlst, intString);
1422 1475 s2 := stringDelimitList(ls, ", ");
1423
1424 1475 tmpStr := "{" + s + ":" + s2 + "} Size: " + intString(listLength(vlst)) + " " + jacobianTypeStr(jacType) + "\n";
1425 then tmpStr;
1426 case BackendDAE.SINGLEARRAY(eqn=i,vars=vlst)
1427 algorithm
1428 7 ls := List.map(vlst, intString);
1429 7 s := stringDelimitList(ls, ", ");
1430 7 tmpStr := "Array " + " {{" + intString(i) + ":" + s + "}}\n";
1431 then tmpStr;
1432 case BackendDAE.SINGLEIFEQUATION(eqn=i,vars=vlst)
1433 algorithm
1434 ✗ ls := List.map(vlst, intString);
1435 ✗ s := stringDelimitList(ls, ", ");
1436 ✗ tmpStr := "IfEquation " + " {{" + intString(i) + ":" + s + "}}\n";
1437 then tmpStr;
1438 case BackendDAE.SINGLEALGORITHM(eqn=i,vars=vlst)
1439 algorithm
1440 29 ls := List.map(vlst, intString);
1441 29 s := stringDelimitList(ls, ", ");
1442 29 tmpStr := "Algorithm " + " {{" + intString(i) + ":" + s + "}}\n";
1443 then tmpStr;
1444 case BackendDAE.SINGLECOMPLEXEQUATION(eqn=i,vars=vlst)
1445 algorithm
1446 ✗ ls := List.map(vlst, intString);
1447 ✗ s := stringDelimitList(ls, ", ");
1448 ✗ tmpStr := "ComplexEquation " + " {" + intString(i) + ":" + s + "}\n";
1449 then tmpStr;
1450 case BackendDAE.SINGLEWHENEQUATION(eqn=i,vars=vlst)
1451 algorithm
1452 1119 ls := List.map(vlst, intString);
1453 1119 s := stringDelimitList(ls, ", ");
1454 1119 tmpStr := "WhenEquation " + " {" + intString(i) + ":" + s + "}\n";
1455 then tmpStr;
1456 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(residualequations=ilst,tearingvars=vlst,innerEquations=innerEquations),casualTearingSet=NONE(),linear=b)
1457 algorithm
1458 3612 ls := List.map(innerEquations, innerEquationString);
1459 3612 s := stringDelimitList(ls, ", ");
1460 3612 ls := List.map(ilst, intString);
1461 3612 s2 := stringDelimitList(ls, ", ");
1462 3612 ls := List.map(vlst, intString);
1463 3612 s3 := stringDelimitList(ls, ", ");
1464
2/2
✓ Branch 0 taken 1868 times.
✓ Branch 1 taken 1744 times.
3612 s4 := if b then "linear" else "nonlinear";
1465 3612 tmpStr := "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst)) + " " + s4 + "\n";
1466
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3612 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3610 times.
3612 if isSome(inSyst) then
1467
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
1468 ✗ SOME(eSys) := inSyst;
1469 ✗ (innerEqLst,innerVarLst,_) := BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations);
1470 ✗ tmpStr := tmpStr
1471 + "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst) + "\n"
1472 + "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst) + "\n"
1473 + "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
1474 + "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
1475 else
1476 2 tmpStr := tmpStr + "For more information please use \"-d=tearingdump\".\n";
1477 end if;
1478 end if;
1479 then tmpStr;
1480 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(residualequations=ilst,tearingvars=vlst,innerEquations=innerEquations),casualTearingSet=SOME(BackendDAE.TEARINGSET(residualequations=ilst2,tearingvars=vlst2,innerEquations=innerEquations2)),linear=b)
1481 algorithm
1482 ✗ ls := List.map(innerEquations, innerEquationString);
1483 ✗ s := stringDelimitList(ls, ", ");
1484 ✗ ls := List.map(ilst, intString);
1485 ✗ s2 := stringDelimitList(ls, ", ");
1486 ✗ ls := List.map(vlst, intString);
1487 ✗ s3 := stringDelimitList(ls, ", ");
1488 ✗ s4 := if b then "linear" else "nonlinear";
1489 ✗ tmpStr := "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst)) + " " + s4 + " (strict tearing set)\n";
1490 ✗ if isSome(inSyst) then
1491 ✗ if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
1492 ✗ SOME(eSys) := inSyst;
1493 ✗ (innerEqLst,innerVarLst,_) := BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations);
1494 ✗ tmpStr := tmpStr
1495 + "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst) + "\n"
1496 + "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst)
1497 + "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
1498 + "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
1499 else
1500 ✗ tmpStr := tmpStr + "For more information please use \"-d=tearingdump\".\n";
1501 end if;
1502 end if;
1503
1504 ✗ ls := List.map(innerEquations2, innerEquationString);
1505 ✗ s := stringDelimitList(ls, ", ");
1506 ✗ ls := List.map(ilst2, intString);
1507 ✗ s2 := stringDelimitList(ls, ", ");
1508 ✗ ls := List.map(vlst2, intString);
1509 ✗ s3 := stringDelimitList(ls, ", ");
1510 s4 := if b then "linear" else "nonlinear";
1511 ✗ tmpStr2 := "{{" + s + "}\n,{" + s2 + ":" + s3 + "}} Size: " + intString(listLength(vlst2)) + " " + s4 + " (casual tearing set)\n";
1512 ✗ if isSome(inSyst) then
1513 ✗ if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
1514 ✗ SOME(eSys) := inSyst;
1515 ✗ (innerEqLst,innerVarLst,_) := BackendDAEUtil.getEqnAndVarsFromInnerEquationLst(innerEquations2);
1516 ✗ tmpStr2 := tmpStr2
1517 + "\nTearing Variables:\n-------------------------------------\n" + dumpMarkedVars(eSys,vlst2) + "\n"
1518 + "Residual Equations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,ilst2)
1519 + "Inner Variables:\n-------------------------------------\n" + dumpMarkedVarsLsts(eSys,innerVarLst) + "\n"
1520 + "InnerEquations:\n-------------------------------------\n" + dumpMarkedEqns(eSys,innerEqLst);
1521 else
1522 ✗ tmpStr2 := tmpStr2 + "For more information please use \"-d=tearingdump\".\n";
1523 end if;
1524 end if;
1525 ✗ then tmpStr + tmpStr2;
1526 end match;
1527 end printComponent;
1528
1529
1530 public function dumpListList
1531 input list<list<Integer>> lstLst;
1532 input String heading;
1533 algorithm
1534 1 print("\n" + heading + ":\n" + UNDERLINE + "\n" + stringDelimitList(List.map(lstLst,intListStr),"\n") + "\n\n");
1535 end dumpListList;
1536
1537
1538 // =============================================================================
1539 // section for all *String functions
1540 //
1541 // These are functions, that return their output with a String.
1542 // - equationString
1543 // - strongComponentString
1544 // =============================================================================
1545
1546 public function strongComponentString
1547 input BackendDAE.StrongComponent inComp;
1548 output String outS;
1549 algorithm
1550 outS := match inComp
1551 local
1552 Integer i,v;
1553 list<Integer> ilst,vlst;
1554 list<String> ls,ls1;
1555 String s,s1,s2,sl,sj;
1556 BackendDAE.JacobianType jacType;
1557 BackendDAE.InnerEquations innerEquations;
1558 Boolean b;
1559 case BackendDAE.SINGLEEQUATION(eqn=i,var=v)
1560 algorithm
1561 1627 s := intString(i);
1562 1627 s1 := intString(v);
1563 1627 s := stringAppendList({"{",s,":",s1,"}"});
1564 then s;
1565 case BackendDAE.EQUATIONSYSTEM(eqns=ilst,vars=vlst,jacType=jacType)
1566 algorithm
1567 25 ls := List.map(ilst, intString);
1568 25 s := stringDelimitList(ls, ", ");
1569 25 ls1 := List.map(vlst, intString);
1570 25 s1 := stringDelimitList(ls1, ", ");
1571 25 sl := intString(listLength(ilst));
1572 25 sj := jacobianTypeStr(jacType);
1573 25 s2 := stringAppendList({"{",s,":",s1,"} Size: ",sl," ",sj});
1574 then
1575 s2;
1576 case BackendDAE.SINGLEARRAY(eqn=i,vars=vlst)
1577 algorithm
1578 3 ls := List.map(vlst, intString);
1579 3 s := stringDelimitList(ls, ", ");
1580 3 sl := intString(i);
1581 3 s2 := stringAppendList({"Array ",sl," {",s,"}"});
1582 then
1583 s2;
1584 case BackendDAE.SINGLEIFEQUATION(eqn=i,vars=vlst)
1585 algorithm
1586 ✗ ls := List.map(vlst, intString);
1587 ✗ s := stringDelimitList(ls, ", ");
1588 ✗ sl := intString(i);
1589 ✗ s2 := stringAppendList({"Array ",sl," {",s,"}"});
1590 then
1591 s2;
1592 case BackendDAE.SINGLEALGORITHM(eqn=i,vars=vlst)
1593 algorithm
1594 1 ls := List.map(vlst, intString);
1595 1 s := stringDelimitList(ls, ", ");
1596 1 sl := intString(i);
1597 1 s2 := stringAppendList({"Algorithm ",sl," {",s,"}"});
1598 then
1599 s2;
1600 case BackendDAE.SINGLECOMPLEXEQUATION(eqn=i,vars=vlst)
1601 algorithm
1602 ✗ ls := List.map(vlst, intString);
1603 ✗ s := stringDelimitList(ls, ", ");
1604 ✗ sl := intString(i);
1605 ✗ s2 := stringAppendList({"ComplexEquation ",sl," {",s,"}"});
1606 then
1607 s2;
1608 case BackendDAE.SINGLEWHENEQUATION(eqn=i,vars=vlst)
1609 algorithm
1610 27 ls := List.map(vlst, intString);
1611 27 s := stringDelimitList(ls, ", ");
1612 27 sl := intString(i);
1613 27 s2 := stringAppendList({"WhenEquation ",sl," {",s,"}"});
1614 then
1615 s2;
1616 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(residualequations=ilst,tearingvars=vlst,innerEquations=innerEquations),linear=b)
1617 algorithm
1618 53 ls := List.map(innerEquations, innerEquationString);
1619 53 s := stringDelimitList(ls, ", ");
1620 53 ls := List.map(ilst, intString);
1621 53 s1 := stringDelimitList(ls, ", ");
1622 53 ls := List.map(vlst, intString);
1623 53 s2 := stringDelimitList(ls, ", ");
1624 53 sj := intString(listLength(vlst));
1625
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 30 times.
53 sl := if b then "linear" else "nonlinear";
1626 53 s2 := stringAppendList({"torn ",sl," Equationsystem","{{",s,"},\n{",s1,":",s2,"} Size: ",sj});
1627 then
1628 s2;
1629 end match;
1630 end strongComponentString;
1631
1632 public function whenEquationString
1633 input BackendDAE.WhenEquation inWhenEqn;
1634 input Boolean inStart;
1635 output String outString;
1636 protected
1637 String conditionStr, whenStmtStr, elseWhenStr;
1638 DAE.Exp cond;
1639 BackendDAE.WhenEquation weqn;
1640 Option<BackendDAE.WhenEquation> oweqn;
1641 list<BackendDAE.WhenOperator> whenStmtLst;
1642 algorithm
1643 29 BackendDAE.WHEN_STMTS(condition=cond, whenStmtLst=whenStmtLst, elsewhenPart=oweqn) := inWhenEqn;
1644 29 conditionStr := ExpressionBasics.printExpStr(cond);
1645 29 whenStmtStr := stringDelimitList(List.map(whenStmtLst, dumpWhenOperatorStr), ";\n ") + ";\n";
1646
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
29 if isSome(oweqn) then
1647 ✗ SOME(weqn) := oweqn;
1648 ✗ elseWhenStr := whenEquationString(weqn, false);
1649 else
1650 elseWhenStr := "";
1651 end if;
1652
1653
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if inStart then
1654 29 outString := "when " + conditionStr + " then\n " + whenStmtStr + elseWhenStr + "end when;";
1655 else
1656 ✗ outString := "elsewhen " + conditionStr + " then\n " + whenStmtStr + elseWhenStr;
1657 end if;
1658 end whenEquationString;
1659
1660 public function equationString "Helper function to e.g. dump."
1661 input BackendDAE.Equation inEquation;
1662 output String outString;
1663 algorithm
1664 outString := match inEquation
1665 local
1666 String s1,s2,s3,res;
1667 DAE.Exp e1,e2,e,start, stop, iter;
1668 list<DAE.Exp> expl;
1669 DAE.ComponentRef cr;
1670 BackendDAE.Equation eqn;
1671 BackendDAE.WhenEquation weqn;
1672 DAE.Algorithm alg;
1673 DAE.ElementSource source;
1674 list<list<BackendDAE.Equation>> eqnstrue;
1675 list<BackendDAE.Equation> eqnsfalse,eqns;
1676 case BackendDAE.EQUATION(exp = e1,scalar = e2)
1677 algorithm
1678 19839 s1 := ExpressionBasics.printExpStr(e1);
1679 19839 s2 := ExpressionBasics.printExpStr(e2);
1680 19839 res := stringAppendList({s1," = ",s2});
1681 then
1682 res;
1683 case BackendDAE.COMPLEX_EQUATION(left = e1,right = e2)
1684 algorithm
1685 3590 s1 := ExpressionBasics.printExpStr(e1);
1686 3590 s2 := ExpressionBasics.printExpStr(e2);
1687 3590 res := stringAppendList({s1," = ",s2});
1688 then
1689 res;
1690 case BackendDAE.ARRAY_EQUATION(left = e1,right = e2)
1691 algorithm
1692 27 s1 := ExpressionBasics.printExpStr(e1);
1693 27 s2 := ExpressionBasics.printExpStr(e2);
1694 27 res := stringAppendList({s1," = ",s2});
1695 then
1696 res;
1697 case BackendDAE.SOLVED_EQUATION(componentRef = cr,exp = e2)
1698 algorithm
1699 6 s1 := ComponentReferenceBasics.printComponentRefStr(cr);
1700 6 s2 := ExpressionBasics.printExpStr(e2);
1701 6 res := stringAppendList({s1," := ",s2});
1702 then
1703 res;
1704 case BackendDAE.WHEN_EQUATION(whenEquation = weqn)
1705 algorithm
1706 29 res := whenEquationString(weqn, true);
1707 then
1708 res;
1709 case BackendDAE.RESIDUAL_EQUATION(exp = e)
1710 algorithm
1711 ✗ s1 := ExpressionBasics.printExpStr(e);
1712 ✗ res := stringAppendList({s1,"= 0"});
1713 then
1714 res;
1715 case BackendDAE.ALGORITHM(alg = alg,source = source)
1716 algorithm
1717 38 res := DAEDump.dumpAlgorithmsStr({DAE.ALGORITHM(alg,source)});
1718 then
1719 res;
1720 case BackendDAE.IF_EQUATION(conditions=e1::expl, eqnstrue=eqns::eqnstrue, eqnsfalse=eqnsfalse)
1721 algorithm
1722 3 s1 := ExpressionBasics.printExpStr(e1);
1723 3 s2 := stringDelimitList(List.map(eqns,equationString),"\n ");
1724 3 s3 := stringAppendList({"if ",s1," then\n ",s2});
1725 3 res := ifequationString(expl,eqnstrue,eqnsfalse,s3);
1726 then
1727 res;
1728 case BackendDAE.FOR_EQUATION(iter = iter, start = start, stop = stop, body = eqn)
1729 algorithm
1730 14 s1 := ExpressionBasics.printExpStr(iter) + " in " + ExpressionBasics.printExpStr(start) + " : " + ExpressionBasics.printExpStr(stop);
1731 14 s2 := equationString(eqn);
1732 14 res := stringAppendList({"for ", s1, " loop\n ", s2, "; end for; "});
1733 then
1734 res;
1735 end match;
1736 end equationString;
1737
1738 protected function zeroCrossingString "Dumps a zerocrossing into a string, for debugging purposes."
1739 input BackendDAE.ZeroCrossing inZeroCrossing;
1740 output String outString;
1741 algorithm
1742 outString:= match inZeroCrossing
1743 local
1744 list<String> eq_s_list;
1745 String eq_s,str,str2,str_index;
1746 DAE.Exp e;
1747 Integer index_;
1748 list<Integer> eq;
1749
1750 case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.RELATION(index=index_),occurEquLst = eq) algorithm
1751 6 eq_s_list := List.map(eq, intString);
1752 6 eq_s := stringDelimitList(eq_s_list, ",");
1753 6 str := ExpressionBasics.printExpStr(e);
1754 6 str_index:=intString(index_);
1755 6 str2 := stringAppendList({str," with index = ",str_index," in equations [",eq_s,"]"});
1756 then str2;
1757
1758 case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.LBINARY(),occurEquLst = eq) algorithm
1759 ✗ eq_s_list := List.map(eq, intString);
1760 ✗ eq_s := stringDelimitList(eq_s_list, ",");
1761 ✗ str := ExpressionBasics.printExpStr(e);
1762 ✗ str2 := stringAppendList({str," in equations [",eq_s,"]"});
1763 then str2;
1764
1765 case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.LUNARY(),occurEquLst = eq) algorithm
1766 ✗ eq_s_list := List.map(eq, intString);
1767 ✗ eq_s := stringDelimitList(eq_s_list, ",");
1768 ✗ str := ExpressionBasics.printExpStr(e);
1769 ✗ str2 := stringAppendList({str," in equations [",eq_s,"]"});
1770 then str2;
1771
1772 case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.CALL(path = Absyn.IDENT()),occurEquLst = eq) algorithm
1773 ✗ eq_s_list := List.map(eq, intString);
1774 ✗ eq_s := stringDelimitList(eq_s_list, ",");
1775 ✗ str := ExpressionBasics.printExpStr(e);
1776 ✗ str2 := stringAppendList({str," in equations [",eq_s,"]"});
1777 then str2;
1778
1779 else "";
1780 end match;
1781 end zeroCrossingString;
1782
1783 protected function timeEventString
1784 input BackendDAE.TimeEvent inTimeEvent;
1785 output String outString;
1786 algorithm
1787 outString := match inTimeEvent
1788 case BackendDAE.SIMPLE_TIME_EVENT()
1789 then "SIMPLE_TIME_EVENT";
1790
1791 case BackendDAE.SAMPLE_TIME_EVENT()
1792 ✗ then intString(inTimeEvent.index) + ": sample(" + ExpressionBasics.printExpStr(inTimeEvent.startExp) + ", " + ExpressionBasics.printExpStr(inTimeEvent.intervalExp) + ")";
1793
1794 else "unknown time event";
1795 end match;
1796 end timeEventString;
1797
1798 // =============================================================================
1799 // section for all debug* functions
1800 //
1801 // description: ???
1802 // =============================================================================
1803
1804 public function debugStrCrefLstStr
1805 input String a;
1806 input list<DAE.ComponentRef> b;
1807 input String c;
1808 input String d;
1809 algorithm
1810 ✗ print(a);
1811 ✗ debuglst(b,ComponentReferenceBasics.printComponentRefStr,c,d);
1812 end debugStrCrefLstStr;
1813
1814 public function debugCrefStr
1815 input DAE.ComponentRef a;
1816 input String b;
1817 algorithm
1818 ✗ print(ComponentReferenceBasics.printComponentRefStr(a) + b);
1819 end debugCrefStr;
1820
1821 public function debugStrIntStr
1822 input String a;
1823 input Integer b;
1824 input String c;
1825 algorithm
1826 ✗ print(a + intString(b) + c);
1827 end debugStrIntStr;
1828
1829 public function debugStrIntStrIntStr
1830 input String a;
1831 input Integer b;
1832 input String c;
1833 input Integer d;
1834 input String e;
1835 algorithm
1836 ✗ print(a + intString(b) + c + intString(d) + e);
1837 end debugStrIntStrIntStr;
1838
1839 public function debugCrefStrIntStr
1840 input DAE.ComponentRef a;
1841 input String b;
1842 input Integer c;
1843 input String d;
1844 algorithm
1845 ✗ print(ComponentReferenceBasics.printComponentRefStr(a) + b + intString(c) + d);
1846 end debugCrefStrIntStr;
1847
1848 public function debugStrCrefStr
1849 input String a;
1850 input DAE.ComponentRef b;
1851 input String c;
1852 algorithm
1853 ✗ print(a +ComponentReferenceBasics.printComponentRefStr(b) + c);
1854 end debugStrCrefStr;
1855
1856 public function debugStrCrefStrIntStr
1857 input String a;
1858 input DAE.ComponentRef b;
1859 input String c;
1860 input Integer d;
1861 input String e;
1862 algorithm
1863 ✗ print(a + ComponentReferenceBasics.printComponentRefStr(b) + c + intString(d) + e);
1864 end debugStrCrefStrIntStr;
1865
1866 public function debugStrCrefStrRealStrRealStrRealStr
1867 input String a;
1868 input DAE.ComponentRef b;
1869 input String c;
1870 input Real d;
1871 input String e;
1872 input Real f;
1873 input String g;
1874 input Real h;
1875 input String i;
1876 algorithm
1877 ✗ print(a + ComponentReferenceBasics.printComponentRefStr(b) + c + realString(d) + e + realString(f) + g + realString(h) + i);
1878 end debugStrCrefStrRealStrRealStrRealStr;
1879
1880 public function debugStrRealStrRealStrRealStrRealStr
1881 input String a;
1882 input Real b;
1883 input String c;
1884 input Real d;
1885 input String e;
1886 input Real f;
1887 input String g;
1888 input Real h;
1889 input String i;
1890 algorithm
1891 ✗ print(a + realString(b) + c + realString(d) + e + realString(f) + g + realString(h) + i);
1892 end debugStrRealStrRealStrRealStrRealStr;
1893
1894 public function debugStrCrefStrExpStr
1895 input String a;
1896 input DAE.ComponentRef b;
1897 input String c;
1898 input DAE.Exp d;
1899 input String e;
1900 algorithm
1901 ✗ print(a + ComponentReferenceBasics.printComponentRefStr(b) + c + ExpressionBasics.printExpStr(d) + e);
1902 end debugStrCrefStrExpStr;
1903
1904 public function debugStrCrefStrCrefStr
1905 input String a;
1906 input DAE.ComponentRef b;
1907 input String c;
1908 input DAE.ComponentRef d;
1909 input String e;
1910 algorithm
1911 ✗ print(a + ComponentReferenceBasics.printComponentRefStr(b) + c + ComponentReferenceBasics.printComponentRefStr(d) + e);
1912 end debugStrCrefStrCrefStr;
1913
1914 public function debugExpStr
1915 input DAE.Exp a;
1916 input String b;
1917 algorithm
1918 ✗ print(ExpressionBasics.printExpStr(a) + b);
1919 end debugExpStr;
1920
1921 public function debugStrExpStr
1922 input String a;
1923 input DAE.Exp b;
1924 input String c;
1925 algorithm
1926 ✗ print(a + ExpressionBasics.printExpStr(b) + c);
1927 end debugStrExpStr;
1928
1929 public function debugStrExpLstStr
1930 input String a;
1931 input list<DAE.Exp> b;
1932 input String c, d;
1933 algorithm
1934 ✗ print(a);
1935 ✗ debuglst(b,ExpressionBasics.printExpStr,c,d);
1936 end debugStrExpLstStr;
1937
1938 public function debugStrExpStrCrefStr
1939 input String a;
1940 input DAE.Exp b;
1941 input String c;
1942 input DAE.ComponentRef d;
1943 input String e;
1944 algorithm
1945 ✗ print(a + ExpressionBasics.printExpStr(b) + c + ComponentReferenceBasics.printComponentRefStr(d) + e);
1946 end debugStrExpStrCrefStr;
1947
1948 public function debugStrExpStrExpStr
1949 input String a;
1950 input DAE.Exp b;
1951 input String c;
1952 input DAE.Exp d;
1953 input String e;
1954 algorithm
1955 ✗ print(a + ExpressionBasics.printExpStr(b) + c + ExpressionBasics.printExpStr(d) + e);
1956 end debugStrExpStrExpStr;
1957
1958 public function debugExpStrExpStrExpStr
1959 input DAE.Exp a;
1960 input String b;
1961 input DAE.Exp c;
1962 input String d;
1963 input DAE.Exp e;
1964 input String f;
1965 algorithm
1966 ✗ print(ExpressionBasics.printExpStr(a) + b + ExpressionBasics.printExpStr(c) + d + ExpressionBasics.printExpStr(e) + f);
1967 end debugExpStrExpStrExpStr;
1968
1969 public function debugStrExpStrExpStrExpStr
1970 input String a;
1971 input DAE.Exp b;
1972 input String c;
1973 input DAE.Exp d;
1974 input String e;
1975 input DAE.Exp f;
1976 input String g;
1977 algorithm
1978 ✗ print(a + ExpressionBasics.printExpStr(b) + c + ExpressionBasics.printExpStr(d) + e + ExpressionBasics.printExpStr(f) + g);
1979 end debugStrExpStrExpStrExpStr;
1980
1981 public function debugStrEqnStr
1982 input String a;
1983 input BackendDAE.Equation b;
1984 input String c;
1985 algorithm
1986 ✗ print(a + equationString(b) + c);
1987 end debugStrEqnStr;
1988
1989 public function debugStrEqnStrEqnStr
1990 input String a;
1991 input BackendDAE.Equation b;
1992 input String c;
1993 input BackendDAE.Equation d;
1994 input String e;
1995 algorithm
1996 ✗ print(a + equationString(b) + c + equationString(d) + e);
1997 end debugStrEqnStrEqnStr;
1998
1999 public function debuglst
2000 input list<Type_a> lst;
2001 input FuncTypeType_aToStr f;
2002 input String c;
2003 input String se;
2004 partial function FuncTypeType_aToStr
2005 input Type_a inTypeA;
2006 output String outTypeA;
2007 end FuncTypeType_aToStr;
2008 replaceable type Type_a subtypeof Any;
2009 algorithm
2010 () := match lst
2011 local
2012 Type_a a;
2013 list<Type_a> rest;
2014 case {}
2015 algorithm
2016 ✗ print(se);
2017 then ();
2018 case a::{}
2019 algorithm
2020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 print(f(a));
2021 2 print(se);
2022 then ();
2023 case a::rest
2024 algorithm
2025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 print(f(a));
2026 3 print(c);
2027 3 debuglst(rest,f,c,se);
2028 then ();
2029 end match;
2030 end debuglst;
2031
2032 // =============================================================================
2033 // unsorted section
2034 //
2035 // These section should be empty. Feel free to sort these functions into one of
2036 // the upper sections.
2037 // =============================================================================
2038
2039 public function printCallFunction2StrDIVISION
2040 "Print the exp of typ DAE.CALL."
2041 input DAE.Exp inExp;
2042 input String stringDelimiter;
2043 input Option<tuple<strongComponentStringRefStrFunc,Type_a>> opcreffunc "tuple of function that print component references and a extra parameter passet throug the function";
2044 output String outString;
2045 replaceable type Type_a subtypeof Any;
2046 partial function strongComponentStringRefStrFunc
2047 input DAE.ComponentRef inComponentRef;
2048 input Type_a Param;
2049 output String outString;
2050 end strongComponentStringRefStrFunc;
2051 algorithm
2052 outString := match inExp
2053 local
2054 String s,s_1,s_2,fs,argstr;
2055 Absyn.Path fcn;
2056 list<DAE.Exp> args;
2057 DAE.Exp e1,e2;
2058 DAE.Type ty;
2059 case DAE.CALL(path = Absyn.IDENT("DIVISION"), expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty = ty))
2060 algorithm
2061 ✗ s := ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
2062 then
2063 s;
2064 case DAE.CALL(path = Absyn.IDENT("DIVISION_ARRAY_SCALAR"),expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty =ty))
2065 algorithm
2066 ✗ s := ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV_ARRAY_SCALAR(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
2067 then
2068 s;
2069 case DAE.CALL(path = Absyn.IDENT("DIVISION_SCALAR_ARRAY"),expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty =ty))
2070 algorithm
2071 ✗ s := ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV_SCALAR_ARRAY(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
2072 then
2073 s;
2074 case DAE.CALL(path = fcn,expLst = args)
2075 algorithm
2076 ✗ fs := AbsynUtil.pathString(fcn);
2077 ✗ argstr := stringDelimitList(
2078 List.map3(args, ExpressionDump.printExp2Str, stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION)), ",");
2079 ✗ s := stringAppend(fs, "(");
2080 ✗ s_1 := stringAppend(s, argstr);
2081 ✗ s_2 := stringAppend(s_1, ")");
2082 then
2083 s_2;
2084 end match;
2085 end printCallFunction2StrDIVISION;
2086
2087 // protected function printVarsStatistics "author: PA
2088 //
2089 // Prints statistics on variables, etc.
2090 // "
2091 // input BackendDAE.Variables inVariables1;
2092 // input BackendDAE.Variables inVariables2;
2093 // algorithm
2094 // _:=
2095 // matchcontinue (inVariables1,inVariables2)
2096 // local
2097 // String lenstr,bstr;
2098 // BackendDAE.VariableArray v1,v2;
2099 // Integer bsize1,n1,bsize2,n2;
2100 // case (BackendDAE.VARIABLES(varArr = v1,bucketSize = bsize1,numberOfVars = n1),BackendDAE.VARIABLES(varArr = v2,bucketSize = bsize2,numberOfVars = n2))
2101 // equation
2102 // print("Variable Statistics\n");
2103 // print("===================\n");
2104 // print("Number of variables: ");
2105 // lenstr = intString(n1);
2106 // print(lenstr);
2107 // print("\n");
2108 // print("Bucket size for variables: ");
2109 // bstr = intString(bsize1);
2110 // print(bstr);
2111 // print("\n");
2112 // print("Number of known variables: ");
2113 // lenstr = intString(n2);
2114 // print(lenstr);
2115 // print("\n");
2116 // print("Bucket size for known variables: ");
2117 // bstr = intString(bsize1);
2118 // print(bstr);
2119 // print("\n");
2120 // then
2121 // ();
2122 // end matchcontinue;
2123 // end printVarsStatistics;
2124
2125 public function dumpWhenOperatorStr
2126 "Dumps a WhenOperator into a string, for debugging purposes."
2127 input BackendDAE.WhenOperator inWhenOperator;
2128 output String outString;
2129 algorithm
2130 outString:=
2131 match inWhenOperator
2132 local
2133 String scr,se,se1,str;
2134 DAE.ComponentRef cr;
2135 DAE.Exp e,e1;
2136 case BackendDAE.ASSIGN(left=e1, right=e)
2137 algorithm
2138 29 scr := ExpressionBasics.printExpStr(e1);
2139 29 se := ExpressionBasics.printExpStr(e);
2140 29 str := stringAppendList({scr," := ",se});
2141 then
2142 str;
2143 case BackendDAE.REINIT(stateVar=cr,value=e)
2144 algorithm
2145 ✗ scr := ComponentReferenceBasics.printComponentRefStr(cr);
2146 ✗ se := ExpressionBasics.printExpStr(e);
2147 ✗ str := stringAppendList({"reinit(",scr,",",se,")"});
2148 then
2149 str;
2150 case BackendDAE.ASSERT(condition=e,message=e1)
2151 algorithm
2152 ✗ se := ExpressionBasics.printExpStr(e);
2153 ✗ se1 := ExpressionBasics.printExpStr(e1);
2154 ✗ str := stringAppendList({"assert(",se,",",se1,")"});
2155 then
2156 str;
2157 case BackendDAE.TERMINATE(message=e)
2158 algorithm
2159 ✗ se := ExpressionBasics.printExpStr(e);
2160 ✗ str := stringAppendList({"terminate(",se,")"});
2161 then
2162 str;
2163 case BackendDAE.NORETCALL(exp=e)
2164 ✗ then
2165 ExpressionBasics.printExpStr(e);
2166 end match;
2167 end dumpWhenOperatorStr;
2168
2169 public function dumpOption
2170 replaceable type Type_A subtypeof Any;
2171 input Option<Type_A> inType;
2172 input printType_A infunc;
2173 partial function printType_A
2174 input Type_A inType;
2175 end printType_A;
2176 algorithm
2177 () :=
2178 match inType
2179 local
2180 Type_A a;
2181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 case SOME(a) algorithm infunc(a); then();
2182 else ();
2183 end match;
2184 end dumpOption;
2185
2186 public function dumpAlgorithms "Help function to dump, prints algorithms to stdout"
2187 input list<DAE.Algorithm> ialgs;
2188 input Integer indx;
2189 algorithm
2190 () := match ialgs
2191 local
2192 list<DAE.Statement> stmts;
2193 IOStream.IOStream myStream;
2194 String is;
2195 list<DAE.Algorithm> algs;
2196
2197 case {} then ();
2198 case DAE.ALGORITHM_STMTS(stmts)::algs
2199 algorithm
2200 ✗ is := intString(indx);
2201 ✗ myStream := IOStream.create("", IOStream.LIST());
2202 ✗ myStream := IOStream.append(myStream,stringAppend(is,". "));
2203 ✗ myStream := DAEDump.dumpAlgorithmStream(DAE.ALGORITHM(DAE.ALGORITHM_STMTS(stmts),DAE.emptyElementSource), myStream);
2204 ✗ IOStream.print(myStream, IOStream.stdOutput);
2205 ✗ dumpAlgorithms(algs,indx+1);
2206 then ();
2207 end match;
2208 end dumpAlgorithms;
2209
2210 public function dumpConstraints "Help function to dump, prints constraints to stdout"
2211 input list<DAE.Constraint> ionstrs;
2212 input Integer indx;
2213 algorithm
2214 () := match ionstrs
2215 local
2216 list<DAE.Exp> exps;
2217 IOStream.IOStream myStream;
2218 String is;
2219 list<DAE.Constraint> constrs;
2220
2221 case {} then ();
2222 case DAE.CONSTRAINT_EXPS(exps)::constrs
2223 algorithm
2224 ✗ is := intString(indx);
2225 ✗ myStream := IOStream.create("", IOStream.LIST());
2226 ✗ myStream := IOStream.append(myStream,stringAppend(is,". "));
2227 ✗ myStream := DAEDump.dumpConstraintStream({DAE.CONSTRAINT(DAE.CONSTRAINT_EXPS(exps),DAE.emptyElementSource)}, myStream);
2228 ✗ IOStream.print(myStream, IOStream.stdOutput);
2229 ✗ dumpConstraints(constrs,indx+1);
2230 then ();
2231 end match;
2232 end dumpConstraints;
2233
2234 public function dumpSparsePatternArray
2235 "function: dumpSparsePattern
2236 author: wbraun
2237 description: function dumps sparse pattern of a Jacobain System."
2238 input array<list<Integer>> inSparsePatter;
2239 algorithm
2240 ✗ print("Print sparse pattern: " + intString(arrayLength(inSparsePatter)) + "\n");
2241 ✗ dumpSparsePattern2(arrayList(inSparsePatter), 1);
2242 ✗ print("\n");
2243 end dumpSparsePatternArray;
2244
2245 public function dumpSparsePattern
2246 "function: dumpSparsePattern
2247 author: wbraun
2248 description: function dumps sparse pattern of a Jacobain System."
2249 input list<list<Integer>> inSparsePatter;
2250 algorithm
2251 ✗ print("Print sparse pattern: " + intString(listLength(inSparsePatter)) + "\n");
2252 ✗ dumpSparsePattern2(inSparsePatter, 1);
2253 ✗ print("\n");
2254 end dumpSparsePattern;
2255
2256 public function dumpSparsePattern2
2257 "function: dumpSparsePattern
2258 author: wbraun
2259 description: help function to dumpSparsePattern."
2260 input list<list<Integer>> inSparsePatter;
2261 input Integer inInteger;
2262 algorithm
2263 () := match inSparsePatter
2264 local
2265 list<list<Integer>> rest;
2266 list<Integer> elem;
2267 String sparsepatternStr;
2268 case {} then ();
2269 case elem::rest
2270 algorithm
2271 ✗ sparsepatternStr := List.toStringCustom(elem, intString,"Row[" + intString(inInteger) + "] = ","{",";","}",true);
2272 ✗ print(sparsepatternStr + "\n");
2273 ✗ dumpSparsePattern2(rest,inInteger+1);
2274 then ();
2275 end match;
2276 end dumpSparsePattern2;
2277
2278 public function dumpJacobianStr
2279 "Dumps the sparse jacobian.
2280 Uses the variables to determine size of Jacobian matrix."
2281 input Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> inTplIntegerIntegerEquationLstOption;
2282 output String outString;
2283 algorithm
2284 outString:=
2285 match inTplIntegerIntegerEquationLstOption
2286 local
2287 list<String> res;
2288 String res_1;
2289 list<tuple<Integer, Integer, BackendDAE.Equation>> eqns;
2290 case SOME(eqns)
2291 algorithm
2292 ✗ res := dumpJacobianStr2(eqns);
2293 ✗ res_1 := stringDelimitList(res, ",\n");
2294 then
2295 res_1;
2296 case NONE() then "No analytic jacobian available\n";
2297 end match;
2298 end dumpJacobianStr;
2299
2300 protected function dumpJacobianStr2
2301 "Helper function to dumpJacobianStr"
2302 input list<tuple<Integer, Integer, BackendDAE.Equation>> inTplIntegerIntegerEquationLst;
2303 output list<String> outStringLst;
2304 algorithm
2305 outStringLst:=
2306 match inTplIntegerIntegerEquationLst
2307 local
2308 String estr,rowstr,colstr,str;
2309 list<String> strs;
2310 Integer row,col;
2311 DAE.Exp e;
2312 list<tuple<Integer, Integer, BackendDAE.Equation>> eqns;
2313 case {} then {};
2314 case (row,col,BackendDAE.RESIDUAL_EQUATION(exp = e)) :: eqns
2315 algorithm
2316 ✗ estr := ExpressionBasics.printExpStr(e);
2317 ✗ rowstr := intString(row);
2318 ✗ colstr := intString(col);
2319 ✗ str := stringAppendList({"{",rowstr,",",colstr,"}:",estr});
2320 ✗ strs := dumpJacobianStr2(eqns);
2321 then
2322 (str :: strs);
2323 end match;
2324 end dumpJacobianStr2;
2325
2326 public function jacobianTypeStr "author: PA
2327 Returns the jacobian type as a string, used for debugging."
2328 input BackendDAE.JacobianType inJacobianType;
2329 output String outString;
2330 algorithm
2331 outString := match inJacobianType
2332 case BackendDAE.JAC_CONSTANT() then "Jacobian Constant";
2333 case BackendDAE.JAC_LINEAR() then "Jacobian Linear";
2334 case BackendDAE.JAC_NONLINEAR() then "Jacobian Nonlinear";
2335 case BackendDAE.JAC_GENERIC() then "Generic Jacobian via directional derivatives";
2336 case BackendDAE.JAC_NO_ANALYTIC() then "No analytic jacobian";
2337 end match;
2338 end jacobianTypeStr;
2339
2340 public function dumpJacobianString
2341 "dumps a string representation of a jacobian.
2342 author: Waurich TUD 2014-10"
2343 input BackendDAE.Jacobian jacIn;
2344 algorithm
2345 _ := match jacIn
2346 local
2347 BackendDAE.BackendDAE dae;
2348 BackendDAE.FullJacobian fJac;
2349 BackendDAE.SymbolicJacobian sJac;
2350 BackendDAE.SparsePattern sparsePattern;
2351 String s;
2352 case BackendDAE.FULL_JACOBIAN(jacobian=fJac)
2353 algorithm
2354 ✗ s := "###############\n" +
2355 " FULL_JACOBIAN \n" +
2356 "###############\n\n" +
2357 dumpJacobianStr(fJac);
2358 ✗ print(s);
2359 then "";
2360 case BackendDAE.GENERIC_JACOBIAN(jacobian=SOME(sJac),sparsePattern=sparsePattern)
2361 algorithm
2362 ✗ (dae,_,_,_,_, _) := sJac;
2363 ✗ print("##################\n" +
2364 " GENERIC_JACOBIAN \n" +
2365 "##################\n\n");
2366 ✗ dumpBackendDAE(dae,"Directional Derivatives System");
2367 ✗ dumpSparsityPattern(sparsePattern,"Sparse Pattern");
2368 then "";
2369 case BackendDAE.GENERIC_JACOBIAN(jacobian=NONE(),sparsePattern=sparsePattern)
2370 algorithm
2371 ✗ print("##################\n" +
2372 " GENERIC_JACOBIAN \n" +
2373 "##################\n\n");
2374 ✗ dumpSparsityPattern(sparsePattern,"Sparse Pattern");
2375 then "";
2376
2377 case BackendDAE.EMPTY_JACOBIAN()
2378 algorithm
2379 ✗ print("################\n" +
2380 " EMPTY_JACOBIAN \n" +
2381 "################\n\n");
2382 then "";
2383 end match;
2384 end dumpJacobianString;
2385
2386 public function symJacString "dumps a string representation of a jacobian."
2387 input tuple<Option<BackendDAE.SymbolicJacobian>, BackendDAE.SparsePattern, BackendDAE.SparseColoring> jacIn;
2388 output String sOut;
2389 algorithm
2390 sOut := match jacIn
2391 local
2392 BackendDAE.BackendDAE dae;
2393 BackendDAE.SymbolicJacobian sJac;
2394 BackendDAE.SparsePattern sparsePattern;
2395 String s;
2396 case (SOME(sJac), sparsePattern, _)
2397 algorithm
2398 ✗ (dae,_,_,_,_, _) := sJac;
2399 s := "GENERIC JACOBIAN:\n";
2400 ✗ dumpBackendDAE(dae,"Directional Derivatives System");
2401 ✗ dumpSparsityPattern(sparsePattern,"Sparse Pattern");
2402 then s;
2403 case (NONE(), sparsePattern, _)
2404 algorithm
2405 s := "GENERIC JACOBIAN:\n";
2406 ✗ dumpSparsityPattern(sparsePattern,"Sparse Pattern");
2407 then s;
2408
2409 end match;
2410 end symJacString;
2411
2412 public function dumpEqnsStr
2413 "Helper function to dump."
2414 input list<BackendDAE.Equation> eqns;
2415 output String str;
2416 algorithm
2417 1 str := stringDelimitList(dumpEqnsStr2(eqns, 1, {}),"\n");
2418 end dumpEqnsStr;
2419
2420 protected function dumpEqnsStr2
2421 "Helper function to dump_eqns"
2422 input list<BackendDAE.Equation> inEquationLst;
2423 input Integer inInteger;
2424 input list<String> inAcc;
2425 output list<String> strs;
2426 algorithm
2427 strs := match (inEquationLst,inInteger,inAcc)
2428 local
2429 String es,is,str;
2430 Integer index_1,index;
2431 BackendDAE.Equation eqn;
2432 list<BackendDAE.Equation> eqns;
2433 list<String> acc;
2434
2435 1 case ({},_,acc) then listReverse(acc);
2436 case ((eqn :: eqns),index,acc)
2437 algorithm
2438 1 es := equationString(eqn);
2439 1 is := intString(index);
2440 1 str := (is + " : ") + es;
2441 1 index_1 := index + 1;
2442 acc := str::acc;
2443 1 then dumpEqnsStr2(eqns, index_1, acc);
2444 end match;
2445 end dumpEqnsStr2;
2446
2447 public function ifequationString
2448 input list<DAE.Exp> conditions;
2449 input list<list<BackendDAE.Equation>> eqnstrue;
2450 input list<BackendDAE.Equation> eqnsfalse;
2451 input String iString;
2452 output String outString;
2453 algorithm
2454 outString := match(conditions, eqnstrue, eqnsfalse)
2455 local
2456 list<list<BackendDAE.Equation>> eqnslst;
2457 list<BackendDAE.Equation> eqns;
2458 String seqns,s,se;
2459 DAE.Exp e;
2460 list<DAE.Exp> elst;
2461 case ({}, _, {})
2462 algorithm
2463 2 s := stringAppendList({iString,"\nend if"});
2464 then
2465 s;
2466 case ({}, _, _)
2467 algorithm
2468 1 seqns := stringDelimitList(List.map(eqnsfalse,equationString),"\n ");
2469 1 s := stringAppendList({iString,"\nelse\n ",seqns,"\nend if"});
2470 then
2471 s;
2472 case(e::elst, eqns::eqnslst, _)
2473 algorithm
2474 3 se := ExpressionBasics.printExpStr(e);
2475 3 seqns := stringDelimitList(List.map(eqns,equationString),"\n ");
2476 3 s := stringAppendList({iString,"\nelseif ",se," then\n ",seqns});
2477 3 then
2478 ifequationString(elst,eqnslst,eqnsfalse,s);
2479 end match;
2480 end ifequationString;
2481
2482 public function varString "Helper function to printVarList."
2483 input BackendDAE.Var inVar;
2484 output String outStr;
2485 protected
2486 list<Absyn.Path> paths;
2487 list<String> paths_lst;
2488 String unreplaceableStr;
2489 String dimensions;
2490 algorithm
2491 20315 paths := ElementSource.getElementSourceTypes(inVar.source);
2492
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 20315 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 20315 times.
20321 paths_lst := list(AbsynUtil.pathString(p) for p in paths);
2493
2/2
✓ Branch 0 taken 19783 times.
✓ Branch 1 taken 532 times.
20315 unreplaceableStr := if inVar.unreplaceable then " unreplaceable" else "";
2494 20315 dimensions := ExpressionBasics.dimensionsString(inVar.arryDim);
2495
3/4
✓ Branch 0 taken 16478 times.
✓ Branch 1 taken 3837 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16478 times.
20315 dimensions := if dimensions <> "" then " [" + dimensions + "]" else "";
2496
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 20315 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 20310 times.
20315 outStr := DAEDump.dumpDirectionStr(inVar.varDirection) + ComponentReferenceBasics.printComponentRefStr(inVar.varName)
2497 + (if isSome(inVar.tplExp) then " in " + ExpressionBasics.printExpStr(Util.getOption(inVar.tplExp)) else "") + ":"
2498 + kindString(inVar.varKind) + "(" + connectorTypeString(inVar.connectorType) + attributesString(inVar.values)
2499 + ") " + optExpressionString(inVar.bindExp, "") + DAEDumpTypes.dumpCommentAnnotationStr(inVar.comment)
2500 + stringDelimitList(paths_lst, ", ") + " type: " + DAEDump.daeTypeStr(inVar.varType) + dimensions + unreplaceableStr;
2501 end varString;
2502
2503 public function varStringShort "prints the cref name of the var only"
2504 input BackendDAE.Var inVar;
2505 output String outStr;
2506 algorithm
2507 ✗ outStr := ComponentReferenceBasics.printComponentRefStr(inVar.varName);
2508 end varStringShort;
2509
2510 public function dumpKind
2511 "Helper function to dump."
2512 input BackendDAE.VarKind inVarKind;
2513 algorithm
2514 ✗ print(kindString(inVarKind));
2515 end dumpKind;
2516
2517 public function kindString
2518 "Helper function to dump."
2519 input BackendDAE.VarKind inVarKind;
2520 output String kindStr;
2521 algorithm
2522 kindStr:=
2523 match inVarKind
2524 local
2525 Absyn.Path path;
2526 Integer i;
2527 DAE.ComponentRef dcr;
2528 case BackendDAE.VARIABLE() then "VARIABLE";
2529 449 case BackendDAE.STATE(index=i,derName=NONE()) then "STATE(" + intString(i) + ")";
2530 21 case BackendDAE.STATE(index=i,derName=SOME(dcr)) then "STATE(" + intString(i) + "," + ComponentReferenceBasics.printComponentRefStr(dcr) + ")";
2531 case BackendDAE.STATE_DER() then "STATE_DER";
2532 case BackendDAE.DUMMY_DER() then "DUMMY_DER";
2533 case BackendDAE.DUMMY_STATE() then "DUMMY_STATE";
2534 case BackendDAE.CLOCKED_STATE() then "CLOCKED_STATE";
2535 case BackendDAE.DISCRETE() then "DISCRETE";
2536 case BackendDAE.PARAM() then "PARAM";
2537 case BackendDAE.CONST() then "CONST";
2538 ✗ case BackendDAE.EXTOBJ(path) then "EXTOBJ: " + AbsynUtil.pathString(path);
2539 case BackendDAE.JAC_VAR() then "JACOBIAN_VAR";
2540 case BackendDAE.JAC_TMP_VAR() then "JACOBIAN_TMP_VAR";
2541 case BackendDAE.OPT_CONSTR() then "OPT_CONSTR";
2542 case BackendDAE.OPT_FCONSTR() then "OPT_FCONSTR";
2543 case BackendDAE.OPT_INPUT_WITH_DER() then "OPT_INPUT_WITH_DER";
2544 case BackendDAE.OPT_INPUT_DER() then "OPT_INPUT_DER";
2545 case BackendDAE.OPT_TGRID() then "OPT_TGRID";
2546 case BackendDAE.OPT_LOOP_INPUT() then "OPT_LOOP_INPUT";
2547 case BackendDAE.ALG_STATE() then "ALG_STATE";
2548 case BackendDAE.ALG_STATE_OLD() then "ALG_STATE_OLD";
2549 case BackendDAE.DAE_RESIDUAL_VAR() then "DAE_RESIDUAL_VAR";
2550 case BackendDAE.DAE_AUX_VAR() then "DAE_AUX_VAR";
2551 case BackendDAE.LOOP_ITERATION() then "LOOP_ITERATION";
2552 case BackendDAE.LOOP_SOLVED() then "LOOP_SOLVED";
2553 else "ERROR: BackendDump.kindString varKind not implemented";
2554 end match;
2555 end kindString;
2556
2557 public function dumpConnectorType
2558 input DAE.ConnectorType inConnectorType;
2559 algorithm
2560 ✗ print(connectorTypeString(inConnectorType));
2561 end dumpConnectorType;
2562
2563 public function connectorTypeString
2564 input DAE.ConnectorType inConnectorType;
2565 output String connectorTypeStr;
2566 algorithm
2567 connectorTypeStr := match inConnectorType
2568 case DAE.FLOW() then "flow=true ";
2569 case DAE.POTENTIAL() then "flow=false ";
2570 else "";
2571 end match;
2572 end connectorTypeString;
2573
2574 public function dumpAttributes
2575 "Helper function to dump."
2576 input Option<DAE.VariableAttributes> inAttr;
2577 algorithm
2578 ():=
2579 match inAttr
2580 local
2581 Option<DAE.Exp> min,max,start,fixed,nominal;
2582 Option<Boolean> isProtected,finalPrefix;
2583 Option<DAE.Distribution> dist;
2584 Option<DAE.StateSelect> stateSelectOption;
2585 case NONE() then ();
2586 case SOME(DAE.VAR_ATTR_REAL(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),nominal=NONE(),stateSelectOption=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE()))
2587 then ();
2588 case SOME(DAE.VAR_ATTR_REAL(min=min,max=max,start=start,fixed=fixed,nominal=nominal,stateSelectOption=stateSelectOption,isProtected=isProtected,finalPrefix=finalPrefix,distributionOption=dist))
2589 algorithm
2590 ✗ dumpOptExpression(min,"min");
2591 ✗ dumpOptExpression(max,"max");
2592 ✗ dumpOptExpression(start,"start");
2593 ✗ dumpOptExpression(fixed,"fixed");
2594 ✗ dumpOptExpression(nominal,"nominal");
2595 ✗ dumpOptStateSelection(stateSelectOption);
2596 ✗ dumpOptBoolean(isProtected,"protected");
2597 ✗ dumpOptBoolean(finalPrefix,"final");
2598 ✗ dumpOptDistribution(dist);
2599 then ();
2600 case SOME(DAE.VAR_ATTR_INT(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE()))
2601 then ();
2602 case SOME(DAE.VAR_ATTR_INT(min=min,max=max,start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix,distributionOption=dist))
2603 algorithm
2604 ✗ dumpOptExpression(min,"min");
2605 ✗ dumpOptExpression(max,"max");
2606 ✗ dumpOptExpression(start,"start");
2607 ✗ dumpOptExpression(fixed,"fixed");
2608 ✗ dumpOptBoolean(isProtected,"protected");
2609 ✗ dumpOptBoolean(finalPrefix,"final");
2610 ✗ dumpOptDistribution(dist);
2611 then ();
2612 case SOME(DAE.VAR_ATTR_BOOL(start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2613 then ();
2614 case SOME(DAE.VAR_ATTR_BOOL(start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix))
2615 algorithm
2616 ✗ dumpOptExpression(start,"start");
2617 ✗ dumpOptExpression(fixed,"fixed");
2618 ✗ dumpOptBoolean(isProtected,"protected");
2619 ✗ dumpOptBoolean(finalPrefix,"final");
2620 then ();
2621 case SOME(DAE.VAR_ATTR_STRING(start=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2622 then ();
2623 case SOME(DAE.VAR_ATTR_STRING(start=start,isProtected=isProtected,finalPrefix=finalPrefix))
2624 algorithm
2625 ✗ dumpOptExpression(start,"start");
2626 ✗ dumpOptBoolean(isProtected,"protected");
2627 ✗ dumpOptBoolean(finalPrefix,"final");
2628 then ();
2629 case SOME(DAE.VAR_ATTR_ENUMERATION(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2630 then ();
2631 case SOME(DAE.VAR_ATTR_ENUMERATION(min=min,max=max,start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix))
2632 algorithm
2633 ✗ dumpOptExpression(min,"min");
2634 ✗ dumpOptExpression(max,"max");
2635 ✗ dumpOptExpression(start,"start");
2636 ✗ dumpOptExpression(fixed,"fixed");
2637 ✗ dumpOptBoolean(isProtected,"protected");
2638 ✗ dumpOptBoolean(finalPrefix,"final");
2639 then ();
2640 else ();
2641 end match;
2642 end dumpAttributes;
2643
2644 protected function dumpOptDistribution "
2645
2646 "
2647 input Option<DAE.Distribution> dist;
2648 algorithm
2649 () := match dist
2650 local
2651 DAE.Exp e1,e2,e3;
2652
2653 case NONE() then ();
2654 case SOME(DAE.DISTRIBUTION(e1,e2,e3)) algorithm
2655 ✗ print("distribution = Distribution("+ExpressionBasics.printExpStr(e1)+", "
2656 +ExpressionBasics.printExpStr(e2)+", "
2657 +ExpressionBasics.printExpStr(e3)+")");
2658 then ();
2659 end match;
2660 end dumpOptDistribution;
2661
2662
2663 protected function dumpOptStateSelection "
2664
2665 "
2666 input Option<DAE.StateSelect> ss;
2667 algorithm
2668 () := match ss
2669 local
2670 ✗ case SOME(DAE.NEVER()) algorithm print("stateSelect=StateSelect.never "); then ();
2671 ✗ case SOME(DAE.AVOID()) algorithm print("stateSelect=StateSelect.avoid "); then ();
2672 case SOME(DAE.DEFAULT()) then ();
2673 ✗ case SOME(DAE.PREFER()) algorithm print("stateSelect=StateSelect.prefer "); then ();
2674 ✗ case SOME(DAE.ALWAYS()) algorithm print("stateSelect=StateSelect.alwas "); then ();
2675 else ();
2676 end match;
2677 end dumpOptStateSelection;
2678
2679 protected function dumpOptExpression
2680 "Helper function to dump."
2681 input Option<DAE.Exp> inExp;
2682 input String inString;
2683 algorithm
2684 ():=
2685 match (inExp,inString)
2686 local
2687 DAE.Exp e;
2688 String s,se,str;
2689 case (SOME(e),s)
2690 algorithm
2691 ✗ se := ExpressionBasics.printExpStr(e);
2692 ✗ str := stringAppendList({s," = ",se," "});
2693 ✗ print(str);
2694 then ();
2695 else ();
2696 end match;
2697 end dumpOptExpression;
2698
2699 protected function dumpOptBoolean
2700 "Helper function to dump."
2701 input Option<Boolean> inExp;
2702 input String inString;
2703 algorithm
2704 ():=
2705 match (inExp,inString)
2706 local
2707 String s,str;
2708 case (SOME(true),s)
2709 algorithm
2710 ✗ str := stringAppendList({s," = true "});
2711 ✗ print(str);
2712 then ();
2713 else ();
2714 end match;
2715 end dumpOptBoolean;
2716
2717 public function attributesString
2718 "Helper function to dump."
2719 input Option<DAE.VariableAttributes> inAttr;
2720 output String outString;
2721 algorithm
2722 outString :=
2723 match inAttr
2724 local
2725 Option<DAE.Exp> min,max,start,fixed,nominal,unit;
2726 Option<Boolean> isProtected,finalPrefix;
2727 Option<DAE.Distribution> dist;
2728 Option<DAE.StateSelect> stateSelectOption;
2729 Option<DAE.Uncertainty> uncertainopt;
2730 String str;
2731 case NONE() then "";
2732 case SOME(DAE.VAR_ATTR_REAL(min=NONE(),max=NONE(),start=NONE(),unit=NONE(),fixed=NONE(),nominal=NONE(),stateSelectOption=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE(),uncertainOption=NONE()))
2733 then "";
2734 case SOME(DAE.VAR_ATTR_REAL(min=min,max=max,start=start,unit=unit,fixed=fixed,nominal=nominal,stateSelectOption=stateSelectOption,isProtected=isProtected,finalPrefix=finalPrefix,distributionOption=dist,uncertainOption=uncertainopt))
2735 algorithm
2736 19014 str := optExpressionString(min,"min") + optExpressionString(max,"max") + optExpressionString(start,"start") + optExpressionString(unit,"unit") + optExpressionString(fixed,"fixed")
2737 + optExpressionString(nominal,"nominal") + optStateSelectionString(stateSelectOption) + optBooleanString(isProtected,"protected")
2738 + optBooleanString(finalPrefix,"final") + optDistributionString(dist) + optUncertainty(uncertainopt);
2739 then str;
2740 case SOME(DAE.VAR_ATTR_INT(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE(),distributionOption=NONE(),uncertainOption=NONE()))
2741 then "";
2742 case SOME(DAE.VAR_ATTR_INT(min=min,max=max,start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix,uncertainOption=uncertainopt))
2743 algorithm
2744 270 str := optExpressionString(min,"min") + optExpressionString(max,"max") + optExpressionString(start,"start") + optExpressionString(fixed,"fixed")
2745 + optBooleanString(isProtected,"protected") + optBooleanString(finalPrefix,"final") + optUncertainty(uncertainopt);
2746 then str;
2747 case SOME(DAE.VAR_ATTR_BOOL(start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2748 then "";
2749 case SOME(DAE.VAR_ATTR_BOOL(start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix))
2750 algorithm
2751 981 str := optExpressionString(start,"start") + optExpressionString(fixed,"fixed") + optBooleanString(isProtected,"protected") + optBooleanString(finalPrefix,"final");
2752 then str;
2753 case SOME(DAE.VAR_ATTR_STRING(start=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2754 then "";
2755 case SOME(DAE.VAR_ATTR_STRING(start=start,isProtected=isProtected,finalPrefix=finalPrefix))
2756 algorithm
2757 1 str := optExpressionString(start,"start") + optBooleanString(isProtected,"protected") + optBooleanString(finalPrefix,"final");
2758 then str;
2759 case SOME(DAE.VAR_ATTR_ENUMERATION(min=NONE(),max=NONE(),start=NONE(),fixed=NONE(),isProtected=NONE(),finalPrefix=NONE()))
2760 then "";
2761 case SOME(DAE.VAR_ATTR_ENUMERATION(min=min,max=max,start=start,fixed=fixed,isProtected=isProtected,finalPrefix=finalPrefix))
2762 algorithm
2763 8 str := optExpressionString(min,"min") + optExpressionString(max,"max") + optExpressionString(start,"start") + optExpressionString(fixed,"fixed")
2764 + optBooleanString(isProtected,"protected") + optBooleanString(finalPrefix,"final");
2765 then str;
2766 else "";
2767 end match;
2768 end attributesString;
2769
2770 protected function optDistributionString
2771 "funcion optDistributionString"
2772 input Option<DAE.Distribution> dist;
2773 output String outString;
2774 algorithm
2775 outString := match dist
2776 local
2777 DAE.Exp e1,e2,e3;
2778 String str;
2779 case NONE() then "";
2780 case SOME(DAE.DISTRIBUTION(e1,e2,e3))
2781 algorithm
2782 ✗ str := "distribution = Distribution(" + ExpressionBasics.printExpStr(e1) + ", "
2783 + ExpressionBasics.printExpStr(e2) + ", "
2784 + ExpressionBasics.printExpStr(e3) + ")";
2785 then str;
2786 end match;
2787 end optDistributionString;
2788
2789 protected function optUncertainty
2790 input Option<DAE.Uncertainty> uncertainty;
2791 output String outString;
2792 algorithm
2793 outString := match uncertainty
2794 case NONE() then "";
2795 case SOME(DAE.GIVEN()) then "uncertain=Uncertainty.given";
2796 case SOME(DAE.SOUGHT()) then "uncertain=Uncertainty.sought";
2797 case SOME(DAE.REFINE()) then "uncertain=Uncertainty.refine";
2798 case SOME(DAE.PROPAGATE()) then "uncertain=Uncertainty.propagate";
2799 end match;
2800 end optUncertainty;
2801
2802 protected function optStateSelectionString
2803 input Option<DAE.StateSelect> ss;
2804 output String outString;
2805 algorithm
2806 outString:= match ss
2807 case SOME(DAE.NEVER()) then "stateSelect=StateSelect.never ";
2808 case SOME(DAE.AVOID()) then "stateSelect=StateSelect.avoid ";
2809 case SOME(DAE.DEFAULT()) then "";
2810 case SOME(DAE.PREFER()) then "stateSelect=StateSelect.prefer ";
2811 case SOME(DAE.ALWAYS()) then "stateSelect=StateSelect.always ";
2812 else "";
2813 end match;
2814 end optStateSelectionString;
2815
2816 public function partitionKindString
2817 input BackendDAE.BaseClockPartitionKind inPartitionKind;
2818 output String outString;
2819 algorithm
2820 outString := match inPartitionKind
2821 local
2822 Integer idx;
2823 12 case BackendDAE.CLOCKED_PARTITION(idx) then "clocked partition(" + intString(idx) + ")";
2824 case BackendDAE.CONTINUOUS_TIME_PARTITION() then "continuous time partition";
2825 case BackendDAE.UNSPECIFIED_PARTITION() then "unspecified partition";
2826 case BackendDAE.UNKNOWN_PARTITION() then "unknown partition";
2827 else algorithm
2828 ✗ Error.addInternalError("function partitionKindString failed", sourceInfo());
2829 ✗ then fail();
2830 end match;
2831 end partitionKindString;
2832
2833 protected function equationAttrString
2834 input BackendDAE.EquationAttributes inEqAttr;
2835 output String outString;
2836 protected
2837 BackendDAE.EquationKind kind;
2838 BackendDAE.EvaluationStages evalStages;
2839 algorithm
2840 7253 BackendDAE.EQUATION_ATTRIBUTES(kind=kind,evalStages=evalStages) := inEqAttr;
2841 7253 outString := "[" + equationKindString(kind) + " " + equationEvaluationStageString(evalStages) + "]";
2842 end equationAttrString;
2843
2844 protected function equationKindString
2845 input BackendDAE.EquationKind inEqKind;
2846 output String outString;
2847 algorithm
2848 outString := match inEqKind
2849 local
2850 Integer i;
2851 DAE.ComponentRef cr;
2852 case BackendDAE.BINDING_EQUATION() then "binding";
2853 case BackendDAE.DYNAMIC_EQUATION() then "dynamic";
2854 case BackendDAE.INITIAL_EQUATION() then "initial";
2855 case BackendDAE.AUX_EQUATION() then "auxiliary";
2856 case BackendDAE.DISCRETE_EQUATION() then "discrete";
2857 case BackendDAE.UNKNOWN_EQUATION_KIND() then "unknown";
2858 case BackendDAE.CLOCKED_EQUATION(i)
2859 algorithm
2860 ✗ cr := DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(i), DAE.T_CLOCK_DEFAULT, {});
2861 ✗ then "clocked(" + ComponentReferenceBasics.printComponentRefStr(cr) + ")";
2862 else
2863 algorithm
2864 ✗ Error.addInternalError("function equationKindString failed", sourceInfo());
2865 ✗ then fail();
2866 end match;
2867 end equationKindString;
2868
2869 protected function equationEvaluationStageString
2870 input BackendDAE.EvaluationStages inEqEvalStage;
2871 output String outString = "|";
2872 algorithm
2873
1/2
✓ Branch 0 taken 7253 times.
✗ Branch 1 not taken.
14506 outString := outString + (if inEqEvalStage.dynamicEval then "1|" else "0|");
2874
1/2
✓ Branch 0 taken 7253 times.
✗ Branch 1 not taken.
14506 outString := outString + (if inEqEvalStage.algebraicEval then "1|" else "0|");
2875
1/2
✓ Branch 0 taken 7253 times.
✗ Branch 1 not taken.
14506 outString := outString + (if inEqEvalStage.zerocrossEval then "1|" else "0|");
2876
1/2
✓ Branch 0 taken 7253 times.
✗ Branch 1 not taken.
14506 outString := outString + (if inEqEvalStage.discreteEval then "1|" else "0|");
2877 end equationEvaluationStageString;
2878
2879 protected function optExpressionString
2880 "Helper function to dump."
2881 input Option<DAE.Exp> inExp;
2882 input String inString;
2883 output String outString;
2884 algorithm
2885 outString:=
2886 match inExp
2887 local
2888 DAE.Exp e;
2889 String se,str;
2890 case SOME(e)
2891 algorithm
2892 36118 se := ExpressionBasics.printExpStr(e);
2893 36118 str := inString + " = " + se + " ";
2894 then str;
2895 else "";
2896 end match;
2897 end optExpressionString;
2898
2899 protected function optBooleanString
2900 "Helper function to dump."
2901 input Option<Boolean> inExp;
2902 input String inString;
2903 output String outString;
2904 algorithm
2905 outString :=
2906 match inExp
2907 local
2908 String str;
2909 case SOME(true)
2910 algorithm
2911 2916 str := inString + " = true ";
2912 then str;
2913 else "";
2914 end match;
2915 end optBooleanString;
2916
2917 public function dumpAdjacencyMatrix "Prints adjacency matrix on stdout."
2918 input BackendDAE.AdjacencyMatrix m;
2919 protected
2920 Integer rowIndex=0;
2921 algorithm
2922 14 print("\nAdjacency Matrix (row: equation)\n" + UNDERLINE + "\n");
2923 14 print("number of rows: " + intString(arrayLength(m)));
2924
2925
2/2
✓ Branch 1 taken 81 times.
✓ Branch 2 taken 14 times.
95 for row in m loop
2926 81 rowIndex := rowIndex+1;
2927 81 print("\n" + intString(rowIndex) + ":");
2928
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 81 times.
153 for i in row loop
2929 72 print(" " + intString(i));
2930 end for;
2931 end for;
2932 14 print("\n");
2933 end dumpAdjacencyMatrix;
2934
2935 public function dumpAdjacencyMatrixT "Prints the transposed adjacency matrix on stdout."
2936 input BackendDAE.AdjacencyMatrixT mT;
2937 protected
2938 Integer rowIndex=0;
2939 algorithm
2940 14 print("\nTransposed Adjacency Matrix (row: variable)\n" + UNDERLINE + "\n");
2941 14 print("number of rows: " + intString(arrayLength(mT)));
2942
2943
2/2
✓ Branch 1 taken 81 times.
✓ Branch 2 taken 14 times.
95 for row in mT loop
2944 81 rowIndex := rowIndex+1;
2945 81 print("\n" + intString(rowIndex) + ":");
2946
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 81 times.
217 for i in row loop
2947 136 print(" " + intString(i));
2948 end for;
2949 end for;
2950 14 print("\n");
2951 end dumpAdjacencyMatrixT;
2952
2953 public function dumpAdjacencyRow
2954 "author: PA
2955 Helper function to dumpAdjacencyMatrix2."
2956 input list<Integer> inIntegerLst;
2957 algorithm
2958 () := match inIntegerLst
2959 local
2960 String s;
2961 Integer x;
2962 list<Integer> xs;
2963 case {}
2964 algorithm
2965 ✗ print("\n");
2966 then
2967 ();
2968 case x :: xs
2969 algorithm
2970 ✗ s := intString(x);
2971 ✗ print(s);
2972 ✗ print(" ");
2973 ✗ dumpAdjacencyRow(xs);
2974 then
2975 ();
2976 end match;
2977 end dumpAdjacencyRow;
2978
2979 public function dumpAdjacencyMatrixEnhanced
2980 "author: Frenkel TUD 2012-05
2981 Prints the adjacency matrix on stdout."
2982 input BackendDAE.AdjacencyMatrixEnhanced m;
2983 protected
2984 Integer mlen;
2985 String mlen_str;
2986 list<BackendDAE.AdjacencyMatrixElementEnhanced> m_1;
2987 algorithm
2988 4 print("Adjacency Matrix Enhanced (row == equation)\n");
2989 4 print("====================================\n");
2990 mlen := arrayLength(m);
2991 4 mlen_str := intString(mlen);
2992 4 print("number of rows: ");
2993 4 print(mlen_str);
2994 4 print("\n");
2995 4 m_1 := arrayList(m);
2996 4 dumpAdjacencyMatrixEnhanced2(m_1,1);
2997 end dumpAdjacencyMatrixEnhanced;
2998
2999 public function dumpAdjacencyMatrixTEnhanced
3000 "author: Frenkel TUD 2012-05
3001 Prints the transposed adjacency matrix on stdout."
3002 input BackendDAE.AdjacencyMatrixTEnhanced m;
3003 protected
3004 Integer mlen;
3005 String mlen_str;
3006 list<BackendDAE.AdjacencyMatrixElementEnhanced> m_1;
3007 algorithm
3008 4 print("Transpose Adjacency Matrix Enhanced (row == var)\n");
3009 4 print("=====================================\n");
3010 mlen := arrayLength(m);
3011 4 mlen_str := intString(mlen);
3012 4 print("number of rows: ");
3013 4 print(mlen_str);
3014 4 print("\n");
3015 4 m_1 := arrayList(m);
3016 4 dumpAdjacencyMatrixEnhanced2(m_1,1);
3017 end dumpAdjacencyMatrixTEnhanced;
3018
3019 protected function dumpAdjacencyMatrixEnhanced2
3020 "author: Frenkel TUD 2012-05
3021 Helper function to dumpAdjacencyMatrixEnhanced (+T)."
3022 input list<BackendDAE.AdjacencyMatrixElementEnhanced> inRows;
3023 input Integer rowIndex;
3024 algorithm
3025 () := match inRows
3026 local
3027 BackendDAE.AdjacencyMatrixElementEnhanced row;
3028 list<BackendDAE.AdjacencyMatrixElementEnhanced> rows;
3029 case {} then ();
3030 case row :: rows
3031 algorithm
3032 29 print(intString(rowIndex));print(":");
3033 29 dumpAdjacencyRowEnhanced(row);
3034 29 dumpAdjacencyMatrixEnhanced2(rows,rowIndex+1);
3035 then
3036 ();
3037 end match;
3038 end dumpAdjacencyMatrixEnhanced2;
3039
3040 public function dumpAdjacencyRowEnhanced
3041 "author: Frenkel TUD 2012-05
3042 Helper function to dumpAdjacencyMatrixEnhanced2."
3043 input BackendDAE.AdjacencyMatrixElementEnhanced inRow;
3044 algorithm
3045 () := match inRow
3046 local
3047 String s,s1,s2;
3048 Integer x;
3049 BackendDAE.Solvability solva;
3050 BackendDAE.AdjacencyMatrixElementEnhanced xs;
3051 BackendDAE.Constraints cons;
3052 case {}
3053 algorithm
3054 29 print("\n");
3055 then
3056 ();
3057 case (x,solva,{}) :: xs
3058 algorithm
3059 66 s := intString(x);
3060 66 s1 := dumpSolvability(solva);
3061 66 print("(" + s + "," + s1 + ")");
3062 66 print(" ");
3063 66 dumpAdjacencyRowEnhanced(xs);
3064 then
3065 ();
3066 case (x,solva,cons) :: xs
3067 algorithm
3068 14 s := intString(x);
3069 14 s1 := dumpSolvability(solva);
3070 14 s2 := ExpressionDump.constraintDTlistToString(cons,",");
3071 14 print("(" + s + "," + s1 + s2 +")");
3072 14 print(" ");
3073 14 dumpAdjacencyRowEnhanced(xs);
3074 then
3075 ();
3076 end match;
3077 end dumpAdjacencyRowEnhanced;
3078
3079 public function dumpSolvability
3080 "author: Frenkel TUD 2012-05,
3081 returns a string for the Solvability"
3082 input BackendDAE.Solvability solva;
3083 output String s;
3084 algorithm
3085 s := match solva
3086 local Boolean b;
3087 case BackendDAE.SOLVABILITY_SOLVED() then "solved";
3088 case BackendDAE.SOLVABILITY_CONSTONE() then "constone";
3089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 case BackendDAE.SOLVABILITY_CONST(b=b) then "const(" + boolString(b) + ")";
3090
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
16 case BackendDAE.SOLVABILITY_PARAMETER(b=b) then "param(" + boolString(b) + ")";
3091
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
32 case BackendDAE.SOLVABILITY_LINEAR(b=b) then "variable(" + boolString(b) + ")";
3092 case BackendDAE.SOLVABILITY_NONLINEAR() then "nonlinear";
3093 case BackendDAE.SOLVABILITY_UNSOLVABLE() then "unsolvable";
3094 case BackendDAE.SOLVABILITY_SOLVABLE() then "solvable";
3095 end match;
3096 end dumpSolvability;
3097
3098 public function dumpFullMatching
3099 input BackendDAE.Matching inMatch;
3100 input Option<BackendDAE.EqSystem> inSyst = NONE();
3101 algorithm
3102 ():= match inMatch
3103 local
3104 array<Integer> ass1;
3105 BackendDAE.StrongComponents comps;
3106
3107 case BackendDAE.NO_MATCHING() algorithm
3108 64 print("no matching\n");
3109 then ();
3110
3111 case BackendDAE.MATCHING(ass1, _, comps) algorithm
3112 63 dumpMatching(ass1);
3113 63 print("\n\n");
3114 63 dumpComponents(comps,inSyst);
3115 then ();
3116 end match;
3117 end dumpFullMatching;
3118
3119 public function dumpMatching "author: PA
3120 prints the matching information on stdout."
3121 input array<Integer> v;
3122 protected
3123 Integer len;
3124 String len_str;
3125 algorithm
3126 123 print("Matching\n");
3127 123 print(UNDERLINE + "\n");
3128 len := arrayLength(v);
3129 123 len_str := intString(len);
3130 123 print(len_str);
3131 123 print(" variables and equations\n");
3132 123 dumpMatching2(v, 1, len);
3133 end dumpMatching;
3134
3135 protected function dumpMatching2 "author: PA
3136 Helper function to dumpMatching. Uses a loop rather than recursion to avoid a stack overflow on
3137 large models (the matching array has one entry per scalar variable)."
3138 input array<Integer> v;
3139 input Integer i;
3140 input Integer len;
3141 algorithm
3142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 123 times.
7780 for j in i:len loop
3143 7657 print("var " + intString(j) + " is solved in eqn " + intString(v[j]) + "\n");
3144 end for;
3145 end dumpMatching2;
3146
3147 public function dumpMatchingVars "Prints matching information on stdout."
3148 input array<Integer> ass1 "eqn := ass1[var]";
3149 protected
3150 Integer varIndex=0;
3151 algorithm
3152 1 print("\nMatching\n" + UNDERLINE + "\n");
3153 1 print(intString(arrayLength(ass1)) + " variables\n");
3154
3155
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
4 for i in ass1 loop
3156 3 varIndex := varIndex+1;
3157 3 print("var " + intString(varIndex) + " is solved in eqn " + intString(i) + "\n");
3158 end for;
3159 end dumpMatchingVars;
3160
3161 public function dumpMatchingEqns "Prints matching information on stdout."
3162 input array<Integer> ass2 "var := ass2[eqn]";
3163 protected
3164 Integer eqnIndex=0;
3165 algorithm
3166 1 print("\nMatching\n" + UNDERLINE + "\n");
3167 1 print(intString(arrayLength(ass2)) + " equations\n");
3168
3169
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 time.
3 for i in ass2 loop
3170 2 eqnIndex := eqnIndex+1;
3171 2 print("eqn " + intString(eqnIndex) + " is solved for var " + intString(i) + "\n");
3172 end for;
3173 end dumpMatchingEqns;
3174
3175 public function dumpMarkedEqns
3176 "Dumps only the equations given as list of indexes to a string."
3177 input BackendDAE.EqSystem syst;
3178 input list<Integer> inIntegerLst;
3179 output String outString;
3180 protected
3181 BackendDAE.EquationArray eqns;
3182 list<String> slst;
3183 algorithm
3184 ✗ BackendDAE.EQSYSTEM(orderedEqs=eqns) := syst;
3185 ✗ slst := List.map1(inIntegerLst, dumpMarkedEqns1, eqns);
3186 ✗ outString := stringDelimitList(slst, "\n");
3187 end dumpMarkedEqns;
3188
3189 protected function dumpMarkedEqns1
3190 input Integer index;
3191 input BackendDAE.EquationArray eqns;
3192 output String outS;
3193 protected
3194 BackendDAE.Equation eqn;
3195 algorithm
3196 ✗ eqn := BackendEquation.get(eqns, index);
3197 ✗ outS := " " + intString(index) + ": " + equationString(eqn);
3198 end dumpMarkedEqns1;
3199
3200 public function dumpMarkedVarsLsts
3201 input BackendDAE.EqSystem syst;
3202 input list<list<Integer>> inIntegerLstLst;
3203 output String outString = "";
3204 algorithm
3205 ✗ for inIntegerLst in inIntegerLstLst loop
3206 ✗ outString := outString + dumpMarkedVars(syst,inIntegerLst) + ",";
3207 end for;
3208 end dumpMarkedVarsLsts;
3209
3210 public function dumpMarkedVars
3211 "Dumps only the variable names given as list of indexes to a string."
3212 input BackendDAE.EqSystem syst;
3213 input list<Integer> inIntegerLst;
3214 output String outString;
3215 protected
3216 BackendDAE.Variables vars;
3217 list<String> slst;
3218 algorithm
3219 ✗ BackendDAE.EQSYSTEM(orderedVars=vars) := syst;
3220 ✗ slst := List.map1(inIntegerLst, dumpMarkedVars1, vars);
3221 ✗ outString := stringDelimitList(slst, "\n");
3222 end dumpMarkedVars;
3223
3224 protected function dumpMarkedVars1
3225 input Integer index;
3226 input BackendDAE.Variables vars;
3227 output String outS;
3228 protected
3229 BackendDAE.Var var;
3230 algorithm
3231 ✗ var := BackendVariable.getVarAt(vars, index);
3232 ✗ outS := " " + intString(index) + ": " + varString(var);
3233 end dumpMarkedVars1;
3234
3235 public function dumpMarkedVarList
3236 "Dumps the variables given as list of indexes to a string."
3237 input list<BackendDAE.Var> varList;
3238 input list<Integer> selList;
3239 output String outString = "";
3240 protected
3241 BackendDAE.Var var;
3242 algorithm
3243
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 for sel in selList loop
3244 try
3245 5 var := listGet(varList, sel);
3246 else
3247 ✗ Error.addInternalError("function dumpMarkedVarList failed", sourceInfo());
3248 ✗ Error.addCompilerNotification("Could not get variable " + intString(sel) + " from varList \n" + varListString(varList,""));
3249 ✗ fail();
3250 end try;
3251 5 outString := outString + " " + varString(var) + "\n";
3252 end for;
3253 end dumpMarkedVarList;
3254
3255 public function dumpComponentsGraphStr
3256 "Dumps the assignment graph used to determine strong
3257 components to format suitable for Mathematica"
3258 input BackendDAE.BackendDAE inDAE;
3259 output BackendDAE.BackendDAE outDAE;
3260 protected
3261 Integer n;
3262 list<String> lst;
3263 String s;
3264 BackendDAE.EqSystem syst;
3265 BackendDAE.AdjacencyMatrix m;
3266 BackendDAE.AdjacencyMatrix mT;
3267 array<Integer> ass1,ass2;
3268 algorithm
3269 ✗ BackendDAE.DAE(eqs={syst as BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mT),matching=BackendDAE.MATCHING(ass1=ass1,ass2=ass2))}) := inDAE;
3270 ✗ n := BackendDAEUtil.systemSize(syst);
3271 ✗ lst := dumpComponentsGraphStr2(1,n,m,mT,ass1,ass2);
3272 ✗ s := stringDelimitList(lst,",");
3273 ✗ s := stringAppendList({"{",s,"}"});
3274 ✗ print(s);
3275 outDAE := inDAE;
3276 end dumpComponentsGraphStr;
3277
3278 protected function dumpComponentsGraphStr2 "help function"
3279 input Integer i;
3280 input Integer n;
3281 input BackendDAE.AdjacencyMatrix m;
3282 input BackendDAE.AdjacencyMatrixT mT;
3283 input array<Integer> ass1;
3284 input array<Integer> ass2;
3285 output list<String> lst = {};
3286 protected
3287 list<list<Integer>> llst;
3288 list<Integer> eqns;
3289 list<String> strLst,slst;
3290 String str;
3291 algorithm
3292 ✗ if i <= n then
3293 ✗ eqns := Matching.reachableEquations(i, mT, ass2);
3294 ✗ llst := List.map(eqns, List.create);
3295 ✗ llst := List.map1(llst, List.consr, i);
3296 ✗ slst := List.map(llst, intListStr);
3297 ✗ str := stringDelimitList(slst, ",");
3298 ✗ str := stringAppendList({"{", str, "}"});
3299 ✗ strLst := dumpComponentsGraphStr2(i+1, n, m, mT, ass1, ass2);
3300 lst := str::strLst;
3301 end if;
3302 end dumpComponentsGraphStr2;
3303
3304 public function dumpList "author: PA
3305
3306 Helper function to dump.
3307 "
3308 input list<Integer> l;
3309 input String str;
3310 protected
3311 list<String> s;
3312 String sl;
3313 algorithm
3314 ✗ s := List.map(l, intString);
3315 ✗ sl := stringDelimitList(s, ", ");
3316 ✗ print(str);
3317 ✗ print(sl);
3318 ✗ print("\n");
3319 end dumpList;
3320
3321 public function dumpComponentsOLD "author: PA
3322
3323 Prints the blocks of the BLT sorting on stdout.
3324 "
3325 input list<list<Integer>> l;
3326 algorithm
3327 ✗ print("Blocks\n");
3328 ✗ print("=======\n");
3329 ✗ dumpComponents2(l, 1);
3330 end dumpComponentsOLD;
3331
3332 protected function dumpComponents2 "author: PA
3333
3334 Helper function to dump_components.
3335 "
3336 input list<list<Integer>> inIntegerLstLst;
3337 input Integer inInteger;
3338 algorithm
3339 ():=
3340 match (inIntegerLstLst,inInteger)
3341 local
3342 Integer i_1,i;
3343 list<String> ls;
3344 String s;
3345 list<Integer> l;
3346 list<list<Integer>> lst;
3347 case ({},_) then ();
3348 case ((l :: lst),i)
3349 algorithm
3350 ✗ print("{");
3351 ✗ ls := List.map(List.sort(l,intGt), intString);
3352 ✗ s := stringDelimitList(ls, ", ");
3353 ✗ print(s);
3354 ✗ print("}\n");
3355 i_1 := i + 1;
3356 ✗ dumpComponents2(lst, i_1);
3357 then
3358 ();
3359 end match;
3360 end dumpComponents2;
3361
3362 protected function intListStr "Takes a list of Integers and produces a string on form: \"{1,2,3}\" "
3363 input list<Integer> lst;
3364 output String res;
3365 algorithm
3366 15 res := stringDelimitList(List.map(lst,intString),",");
3367 15 res := stringAppendList({"{",res,"}"});
3368 end intListStr;
3369
3370 // protected function dumpAliasVariable
3371 // "author: Frenkel TUD 2010-11"
3372 // input tuple<BackendDAE.Var,list<Integer>> inTpl;
3373 // output tuple<BackendDAE.Var,list<Integer>> outTpl;
3374 // algorithm
3375 // outTpl:=
3376 // matchcontinue (inTpl)
3377 // local
3378 // BackendDAE.Var v;
3379 // DAE.ComponentRef cr;
3380 // DAE.Exp e;
3381 // String s,scr,se;
3382 // case ((v,_))
3383 // equation
3384 // cr = BackendVariable.varCref(v);
3385 // e = BackendVariable.varBindExp(v);
3386 // //print("### dump var : " + ComponentReferenceBasics.printComponentRefStr(cr) + "\n");
3387 // scr = ComponentReferenceBasics.printComponentRefStr(cr);
3388 // se = ExpressionBasics.printExpStr(e);
3389 // s = stringAppendList({scr," = ",se,"\n"});
3390 // print(s);
3391 // then ((v,{}));
3392 // else inTpl;
3393 // end matchcontinue;
3394 // end dumpAliasVariable;
3395
3396 public function dumpStateVariables "author: Frenkel TUD 2010-12
3397
3398 dump State Variables.
3399 "
3400 input BackendDAE.Variables inVars;
3401 algorithm
3402 ✗ print("States Variables\n");
3403 ✗ print("=================\n");
3404 ✗ BackendVariable.traverseBackendDAEVars(inVars,dumpStateVariable,1);
3405 ✗ print("\n");
3406 end dumpStateVariables;
3407
3408 protected function dumpStateVariable
3409 input BackendDAE.Var inVar;
3410 input Integer inPos;
3411 output BackendDAE.Var v;
3412 output Integer pos;
3413 algorithm
3414 (v,pos) := matchcontinue (inVar,inPos)
3415 local
3416 DAE.ComponentRef cr;
3417 String scr;
3418 case (v,pos)
3419 algorithm
3420 ✗ true := BackendVariable.isStateVar(v);
3421 ✗ cr := BackendVariable.varCref(v);
3422 ✗ scr := ComponentReferenceBasics.printComponentRefStr(cr);
3423 ✗ print(intString(pos)); print(": ");
3424 ✗ print(scr); print("\n");
3425 ✗ then (v,pos+1);
3426 else (inVar,inPos);
3427 end matchcontinue;
3428 end dumpStateVariable;
3429
3430 public function bltdump "author: Frenkel TUD 2011-03"
3431 input String headerline;
3432 input BackendDAE.BackendDAE inDAE;
3433 algorithm
3434 () := matchcontinue inDAE
3435 local
3436 BackendDAE.EqSystems eqs;
3437 BackendDAE.Shared shared;
3438 String str, strlow;
3439
3440 case _ algorithm
3441 ✗ Flags.STRING_FLAG(data=str) := Flags.getConfigValue(Flags.DUMP_TARGET);
3442 ✗ strlow := System.tolower(str);
3443 ✗ true := intGt(System.stringFind(strlow, ".html"), 0);
3444 ✗ DumpHTML.dumpDAE(inDAE, headerline, str);
3445 then ();
3446
3447 case BackendDAE.DAE(eqs, shared) algorithm
3448 ✗ print(headerline + ":\n");
3449 ✗ List.map_0(eqs, printEqSystem);
3450 ✗ print("\n");
3451 ✗ printShared(shared);
3452 then ();
3453 end matchcontinue;
3454 end bltdump;
3455
3456 public function innerEquationString
3457 input BackendDAE.InnerEquation innerEquation;
3458 output String s;
3459 protected
3460 Integer e;
3461 list<Integer> v;
3462 algorithm
3463 23576 (e,v) := BackendDAEUtil.getEqnAndVarsFromInnerEquation(innerEquation);
3464 23576 s := stringDelimitList(List.map(v,intString), ",");
3465 23576 s := "{"+intString(e)+":"+s+"}";
3466 end innerEquationString;
3467
3468 protected type DumpCompShortSystemsTpl = tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>;
3469 protected type DumpCompShortMixedTpl = tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>;
3470 protected type DumpCompShortTornTpl = tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>;
3471
3472 public function dumpCompShort
3473 input BackendDAE.BackendDAE inDAE;
3474 protected
3475 Integer sys,inp,st,dvar,dst,seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2,strcomps;
3476 list<Integer> e_jc,e_jn,e_nj;
3477 list<tuple<Integer,Integer,Integer>> te_l,te_l2;
3478 list<tuple<Integer,Integer>> te_nl,te_nl2;
3479 list<Integer> m_se,m_salg,m_sarr,m_sec;
3480 list<tuple<Integer,Integer>> me_jc,e_jt,me_jt,me_jn,me_nj,me_lt,me_nt;
3481 list<DAE.ComponentRef> states,discvars,discstates,clockedstates={};
3482 HashSet.HashSet HS;
3483 BackendDAE.EqSystems systs;
3484 BackendDAE.EquationArray removedEqs;
3485 String sysStr, stStr, dvarStr, dstStr, clckStr, statesStr, discvarsStr, discstatesStr, clockedstatesStr, inpStr, strcompsStr, seqStr, sarrStr, salgStr, sceStr, sweStr, sieStr, eqsysStr, teqsysStr, meqsysStr, daeType;
3486
3487 list<String> msgs;
3488 DumpCompShortSystemsTpl systemsTpl;
3489 DumpCompShortMixedTpl mixedTpl;
3490 DumpCompShortTornTpl tornTpl,tornTpl2;
3491 BackendDAE.BackendDAEType backendDAEType;
3492 algorithm
3493 118 BackendDAE.DAE(systs, BackendDAE.SHARED(backendDAEType=backendDAEType)) := inDAE;
3494 118 removedEqs := BackendDAEUtil.collapseRemovedEqs(inDAE);
3495 118 daeType := printBackendDAEType2String(backendDAEType);
3496
3497 118 HS := HashSet.emptyHashSet();
3498 118 HS := List.fold(systs, Initialization.collectPreVariablesEqSystem, HS);
3499 118 (_,HS) := BackendDAEUtil.traverseBackendDAEExpsEqns(removedEqs, Expression.traverseSubexpressionsHelper, (Initialization.collectPreVariablesTraverseExp, HS));
3500 118 discstates := BaseHashSet.hashSetList(HS);
3501 118 dst := listLength(discstates);
3502
3503 // collect and print clocked states #6132
3504
2/2
✓ Branch 0 taken 6509 times.
✓ Branch 1 taken 118 times.
6627 for syst in systs loop
3505 6509 clockedstates := BackendVariable.filterCrefs(syst.orderedVars, BackendVariable.isVarClockedState, clockedstates);
3506 end for;
3507
3508 118 (sys,inp,st,states,dvar,discvars,seq,salg,sarr,sce,swe,sie,systemsTpl,mixedTpl,tornTpl,tornTpl2) := BackendDAEUtil.foldEqSystem(inDAE,dumpCompShort1,(0,0,0,{},0,{},0,0,0,0,0,0,({},{},{},{}),({},{},{},{},{},{},{},{},{},{}),({},{}),({},{})));
3509 118 (e_jc,e_jt,e_jn,e_nj) := systemsTpl;
3510 118 (m_se,m_salg,m_sarr,m_sec,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt) := mixedTpl;
3511 118 (te_l,te_nl) := tornTpl;
3512 118 (te_l2,te_nl2) := tornTpl2;
3513
3514 118 eqsys := listLength(e_jc)+listLength(e_jt)+listLength(e_jn)+listLength(e_nj);
3515 118 meqsys := listLength(m_se)+listLength(m_sarr)+listLength(m_salg)+listLength(m_sec)+listLength(me_jc)+listLength(me_jt)+listLength(me_jn)+listLength(me_nj)+listLength(me_lt)+listLength(me_nt);
3516 118 teqsys := listLength(te_l)+listLength(te_nl);
3517 118 teqsys2 := listLength(te_l2)+listLength(te_nl2);
3518 118 strcomps := seq+eqsys+meqsys+sarr+salg+sce+swe+sie+teqsys;
3519
3520 118 sysStr := intString(sys);
3521 118 stStr := intString(st);
3522 118 dvarStr := intString(dvar);
3523 118 dstStr := intString(dst);
3524 118 clckStr := intString(listLength(clockedstates));
3525
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 106 times.
118 statesStr := if Flags.isSet(Flags.DUMP_STATESELECTION_INFO)
3526 then " (" + stringDelimitList(List.map(states, ComponentReferenceBasics.printComponentRefStr),",") + ")"
3527 else " ('-d=stateselection' for list of states)";
3528
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118 times.
118 discvarsStr := if Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO)
3529 then " (" + stringDelimitList(List.map(discvars, ComponentReferenceBasics.printComponentRefStr),",") + ")"
3530 else " ('-d=discreteinfo' for list of discrete vars)";
3531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118 times.
118 discstatesStr := if Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO)
3532 then " (" + stringDelimitList(List.map(discstates, ComponentReferenceBasics.printComponentRefStr),",") + ")"
3533 else " ('-d=discreteinfo' for list of discrete states)";
3534
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 118 times.
118 clockedstatesStr := if Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO)
3535 then " (" + stringDelimitList(List.map(clockedstates, ComponentReferenceBasics.printComponentRefStr),",") + ")"
3536 else " ('-d=discreteinfo' for list of clocked states)";
3537 118 stStr := stStr+statesStr;
3538 118 dvarStr := dvarStr+discvarsStr;
3539 118 dstStr := dstStr+discstatesStr;
3540 118 clckStr := clckStr+clockedstatesStr;
3541 118 inpStr := intString(inp);
3542 msgs := {daeType,sysStr,stStr,dvarStr,dstStr,clckStr,inpStr};
3543 118 Error.addMessage(Error.BACKENDDAEINFO_STATISTICS, msgs);
3544
3545 118 strcompsStr := intString(strcomps);
3546 118 seqStr := intString(seq);
3547 118 sarrStr := intString(sarr);
3548 118 salgStr := intString(salg);
3549 118 sceStr := intString(sce);
3550 118 sweStr := intString(swe);
3551 118 sieStr := intString(sie);
3552 118 eqsysStr := intString(eqsys);
3553 118 teqsysStr := intString(teqsys);
3554 118 meqsysStr := intString(meqsys);
3555
3556 msgs := {daeType,strcompsStr,seqStr,sarrStr,salgStr,sceStr,sweStr,sieStr,eqsysStr,teqsysStr,meqsysStr};
3557 118 Error.addMessage(Error.BACKENDDAEINFO_STRONGCOMPONENT_STATISTICS, msgs);
3558
3559
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 108 times.
118 if intGt(eqsys,0) then
3560 10 dumpCompSystems(systemsTpl);
3561 end if;
3562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 if intGt(meqsys,0) then
3563 ✗ dumpCompMixed(mixedTpl);
3564 end if;
3565
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 2 times.
118 if intGt(teqsys,0) then
3566 116 dumpCompTorn(tornTpl,"strict");
3567 end if;
3568
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 116 times.
✓ Branch 3 taken 116 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 116 times.
✗ Branch 8 not taken.
118 if intGt(teqsys2,0) and not stringEqual(Config.dynamicTearing(),"false") then
3569 ✗ dumpCompTorn(tornTpl2,"casual");
3570 end if;
3571 end dumpCompShort;
3572
3573 protected function dumpCompSystems
3574 input DumpCompShortSystemsTpl systemsTpl;
3575 protected
3576 list<Integer> e_jc,e_jn,e_nj;
3577 list<tuple<Integer,Integer>> e_jt;
3578 String s_jc,s_jn,s_nj,s_jt;
3579 algorithm
3580 10 (e_jc,e_jt,e_jn,e_nj) := systemsTpl;
3581 10 s_jc := equationSizesStr(e_jc,intString); // TODO add density, like for the linear case
3582 10 s_jt := equationSizesStr(e_jt,sizeNumNonZeroTplString);
3583 10 s_jn := equationSizesStr(e_jn,intString); // TODO add density, like for the linear case
3584 10 s_nj := equationSizesStr(e_nj,intString); // TODO add density, like for the linear case
3585 10 Error.addMessage(Error.BACKENDDAEINFO_SYSTEMS, {s_jc,s_jt,s_jn,s_nj});
3586 end dumpCompSystems;
3587
3588 protected function dumpCompTorn
3589 input DumpCompShortTornTpl systemsTpl;
3590 input String whichset;
3591 protected
3592 list<tuple<Integer,Integer,Integer>> te_l;
3593 list<tuple<Integer,Integer>> te_nl;
3594 String s_l,s_nl;
3595 algorithm
3596 116 (te_l,te_nl) := systemsTpl;
3597 116 s_l := equationSizesStr(te_l,sizeNumNonZeroTornTplString);
3598 116 s_nl := equationSizesStr(te_nl,intTplString); // TODO add density, like for the linear case
3599 116 Error.addMessage(Error.BACKENDDAEINFO_TORN, {whichset,s_l,s_nl});
3600 end dumpCompTorn;
3601
3602 protected function dumpCompMixed
3603 input DumpCompShortMixedTpl mixedTpl;
3604 protected
3605 list<Integer> m_se,m_salg,m_sarr,m_sec;
3606 list<tuple<Integer,Integer>> me_jc,me_jt,me_jn,me_nj,me_lt,me_nt;
3607 String s_se,s_salg,s_sarr,s_sec,s_jc,s_jt,s_jn,s_nj,s_lt,s_nt;
3608 algorithm
3609 ✗ (m_se,m_salg,m_sarr,m_sec,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt) := mixedTpl;
3610 ✗ s_se := equationSizesStr(m_se,intString);
3611 ✗ s_salg := equationSizesStr(m_salg,intString);
3612 ✗ s_sarr := equationSizesStr(m_sarr,intString);
3613 ✗ s_sec := equationSizesStr(m_sec,intString);
3614 ✗ s_jc := equationSizesStr(me_jc,intTplString);
3615 ✗ s_jt := equationSizesStr(me_jt,intTplString);
3616 ✗ s_jn := equationSizesStr(me_jn,intTplString);
3617 ✗ s_nj := equationSizesStr(me_nj,intTplString);
3618 ✗ s_lt := equationSizesStr(me_lt,intTplString);
3619 ✗ s_nt := equationSizesStr(me_nt,intTplString);
3620 ✗ Error.addMessage(Error.BACKENDDAEINFO_MIXED, {s_se,s_salg,s_sarr,s_sec,s_jc,s_jt,s_jn,s_nj,s_lt,s_nt});
3621 end dumpCompMixed;
3622
3623 protected function equationSizesStr
3624 input list<A> eqs;
3625 input AToStr fn;
3626 output String str;
3627 replaceable type A subtypeof Any;
3628 partial function AToStr
3629 input A a;
3630 output String str;
3631 end AToStr;
3632 protected
3633 Integer len;
3634 algorithm
3635 272 len := listLength(eqs);
3636
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 110 times.
272 str := if len == 1 then "1 system" else (intString(len) + " systems");
3637
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 144 times.
272 str := if len == 0 then str else (str + "\n {" + stringDelimitList(List.map(eqs,fn),", ") + "}");
3638 end equationSizesStr;
3639
3640 protected function sizeNumNonZeroTplString
3641 input tuple<Integer,Integer> inTpl;
3642 output String str;
3643 protected
3644 Integer sz,nnz;
3645 Real density;
3646 algorithm
3647 4 (sz,nnz) := inTpl;
3648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 density := realDiv(realMul(100.0,intReal(nnz)),realMul(intReal(sz),intReal(sz)));
3649 4 str := System.snprintff("%.1f",20,density);
3650 4 str := "(" + intString(sz) + "," + str + "%)";
3651 end sizeNumNonZeroTplString;
3652
3653 protected function sizeNumNonZeroTornTplString
3654 input tuple<Integer,Integer,Integer> inTpl;
3655 output String str;
3656 protected
3657 Integer sz,nnz,others;
3658 Real density;
3659 algorithm
3660 92 (sz,others,nnz) := inTpl;
3661
2/4
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
92 density := if nnz == 0 then 0.0 else realDiv(realMul(100.0,intReal(nnz)),realMul(intReal(sz),intReal(sz)));
3662 92 str := System.snprintff("%.1f",20,density);
3663 92 str := "(" + intString(sz) + "," + intString(others) + "," + str + "%)";
3664 end sizeNumNonZeroTornTplString;
3665
3666 protected function intTplString
3667 input tuple<Integer,Integer> inTpl;
3668 output String outStr;
3669 protected
3670 Integer e,d;
3671 algorithm
3672 // d = number of residual/iteration/tearing vars
3673 // e = number of internal/inner/torn vars
3674 46 (d,e) := inTpl;
3675 46 outStr := "(" + intString(d) + "," + intString(e) + ")";
3676 end intTplString;
3677
3678 protected function dumpCompShort1
3679 input BackendDAE.EqSystem inSyst;
3680 input BackendDAE.Shared inShared;
3681 input tuple<Integer,Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>,Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
3682 output tuple<
3683 Integer,
3684 Integer,
3685 Integer,
3686 list<DAE.ComponentRef>,
3687 Integer,
3688 list<DAE.ComponentRef>,
3689 Integer,
3690 Integer,
3691 Integer,
3692 Integer,
3693 Integer,
3694 Integer,
3695 DumpCompShortSystemsTpl,
3696 DumpCompShortMixedTpl,
3697 DumpCompShortTornTpl,
3698 DumpCompShortTornTpl> outTpl;
3699 protected
3700 BackendDAE.Variables vars;
3701 BackendDAE.StrongComponents comps;
3702 Integer sys,inp,st,dvar,seq,salg,sarr,sce,swe,sie,inp1,st1,dvar1,seq1,salg1,sarr1,sce1,swe1,sie1;
3703 tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys,eqsys1;
3704 tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys,meqsys1;
3705 tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys1,teqsys_2,teqsys1_2;
3706 list<DAE.ComponentRef> states,states1,discvars,discvars1;
3707 algorithm
3708 6509 BackendDAE.EQSYSTEM(orderedVars=vars) := inSyst;
3709 6509 (sys, inp, st, states, dvar, discvars, seq, salg, sarr, sce, swe, sie, eqsys, meqsys, teqsys, teqsys_2) := inTpl;
3710
3711 6509 (inp1,st1,states1,dvar1,discvars1) := BackendVariable.traverseBackendDAEVars(vars,traversingisStateTopInputVarFinder,(inp,st,states,dvar,discvars));
3712 6509 comps := BackendDAEUtil.getStrongComponents(inSyst);
3713 6509 (seq1,salg1,sarr1,sce1,swe1,sie1,eqsys1,meqsys1,teqsys1,teqsys1_2) := List.fold(comps,dumpCompShort2,(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys_2));
3714
3715 6509 outTpl := (sys+1, inp1, st1, states1, dvar1, discvars1, seq1, salg1, sarr1, sce1, swe1, sie1, eqsys1, meqsys1, teqsys1, teqsys1_2);
3716 end dumpCompShort1;
3717
3718 protected function traversingisStateTopInputVarFinder
3719 input BackendDAE.Var inVar;
3720 input tuple<Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>> inTpl;
3721 output BackendDAE.Var outVar;
3722 output tuple<Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>> outTpl;
3723 algorithm
3724 (outVar,outTpl) := match (inVar,inTpl)
3725 local
3726 BackendDAE.Var v;
3727 Integer inp,st,dvar;
3728 DAE.ComponentRef cr;
3729 list<DAE.ComponentRef> states,discvars;
3730
3731 case (v,(inp,st,states,dvar,discvars)) guard BackendVariable.isStateVar(v) algorithm
3732 148 cr := BackendVariable.varCref(v);
3733 148 then (v,(inp,st+1,cr::states,dvar,discvars));
3734
3735 case (v,(inp,st,states,dvar,discvars)) guard BackendVariable.isVarDiscrete(v) algorithm
3736 956 cr := BackendVariable.varCref(v);
3737 956 then (v,(inp,st,states,dvar+1,cr::discvars));
3738
3739 case (v,(inp,st,states,dvar,discvars)) guard BackendVariable.isVarOnTopLevelAndInput(v)
3740 ✗ then (v,(inp+1,st,states,dvar,discvars));
3741
3742 else (inVar,inTpl);
3743 end match;
3744 end traversingisStateTopInputVarFinder;
3745
3746 protected function dumpCompShort2
3747 input BackendDAE.StrongComponent inComp;
3748 input tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
3749 output tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> outTpl;
3750 algorithm
3751 outTpl := match (inComp,inTpl)
3752 local
3753 Integer e,d,e2,d2,nnz,nnz2;
3754 list<Integer> ilst,ilst2;
3755 Integer seq,salg,sarr,sce,swe,sie;
3756 list<Integer> e_jc,e_jn,e_nj;
3757 list<tuple<Integer,Integer,Integer>> te_l,te_l2;
3758 list<tuple<Integer,Integer>> e_jt,te_nl,te_nl2;
3759 tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys;
3760 list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
3761 tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys;
3762 tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys2;
3763 BackendDAE.InnerEquations innerEquations,innerEquations2;
3764
3765 case (BackendDAE.SINGLEEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3766 17173 then ((seq+1,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2));
3767
3768 case (BackendDAE.SINGLEARRAY(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3769 48 then ((seq,salg,sarr+1,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2));
3770
3771 case (BackendDAE.SINGLEIFEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3772 ✗ then ((seq,salg,sarr,sce,swe,sie+1,eqsys,meqsys,teqsys,teqsys2));
3773
3774 case (BackendDAE.SINGLEALGORITHM(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3775 ✗ then ((seq,salg+1,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2));
3776
3777 case (BackendDAE.SINGLECOMPLEXEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3778 ✗ then((seq,salg,sarr,sce+1,swe,sie,eqsys,meqsys,teqsys,teqsys2));
3779
3780 case (BackendDAE.SINGLEWHENEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,teqsys2))
3781 ✗ then ((seq,salg,sarr,sce,swe+1,sie,eqsys,meqsys,teqsys,teqsys2));
3782
3783 case (BackendDAE.EQUATIONSYSTEM(eqns=ilst,jacType=BackendDAE.JAC_CONSTANT()),(seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2)) algorithm
3784 ✗ e := listLength(ilst);
3785 ✗ then ((seq,salg,sarr,sce,swe,sie,(e::e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2));
3786
3787 case (BackendDAE.EQUATIONSYSTEM(eqns=ilst,jac=BackendDAE.FULL_JACOBIAN(SOME(jac)),jacType=BackendDAE.JAC_LINEAR()),(seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2))
3788 algorithm
3789 4 e := listLength(ilst);
3790 4 nnz := listLength(jac);
3791 8 then ((seq,salg,sarr,sce,swe,sie,(e_jc,(e,nnz)::e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2));
3792
3793 case (BackendDAE.EQUATIONSYSTEM(eqns=ilst,jacType=BackendDAE.JAC_NONLINEAR()),(seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2)) algorithm
3794 ✗ e := listLength(ilst);
3795 ✗ then ((seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e::e_jn,e_nj),meqsys,teqsys,teqsys2));
3796
3797 case (BackendDAE.EQUATIONSYSTEM(eqns=ilst,jacType=BackendDAE.JAC_GENERIC()),(seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2)) algorithm
3798 8 e := listLength(ilst);
3799 8 then ((seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e::e_jn,e_nj),meqsys,teqsys,teqsys2));
3800
3801 case (BackendDAE.EQUATIONSYSTEM(eqns=ilst,jacType=BackendDAE.JAC_NO_ANALYTIC()),(seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e_nj),meqsys,teqsys,teqsys2)) algorithm
3802 ✗ e := listLength(ilst);
3803 ✗ then ((seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e::e_nj),meqsys,teqsys,teqsys2));
3804
3805 // no dynamic tearing
3806 case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=ilst,innerEquations=innerEquations,jac=BackendDAE.GENERIC_JACOBIAN(_,(_,_,_,nnz),_)),casualTearingSet=NONE(),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl),(te_l2,te_nl2))) algorithm
3807 92 d := listLength(ilst);
3808 92 e := listLength(innerEquations);
3809 276 then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e,nnz)::te_l,te_nl),((0,0,0)::te_l2,te_nl2)));
3810
3811 case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=ilst,innerEquations=innerEquations),casualTearingSet=NONE(),linear=false),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl),(te_l2,te_nl2))) algorithm
3812 46 d := listLength(ilst);
3813 46 e := listLength(innerEquations);
3814 138 then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,(d,e)::te_nl),(te_l2,(0,0)::te_nl2)));
3815
3816 case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=ilst,innerEquations=innerEquations,jac=BackendDAE.EMPTY_JACOBIAN()),casualTearingSet=NONE(),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl),(te_l2,te_nl2))) algorithm
3817 ✗ d := listLength(ilst);
3818 ✗ e := listLength(innerEquations);
3819 ✗ then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e,0)::te_l,te_nl),((0,0,0)::te_l2,te_nl2)));
3820
3821 // dynamic tearing
3822 case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=ilst,innerEquations=innerEquations,jac=BackendDAE.GENERIC_JACOBIAN(_,(_,_,_,nnz),_)),casualTearingSet=SOME(BackendDAE.TEARINGSET(tearingvars=ilst2,innerEquations=innerEquations2,jac=BackendDAE.GENERIC_JACOBIAN(_,(_,_,_,nnz2),_))),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl),(te_l2,te_nl2))) algorithm
3823 ✗ d := listLength(ilst);
3824 ✗ e := listLength(innerEquations);
3825 ✗ d2 := listLength(ilst2);
3826 ✗ e2 := listLength(innerEquations2);
3827 ✗ then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e,nnz)::te_l,te_nl),((d2,e2,nnz2)::te_l2,te_nl2)));
3828
3829 case (BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=ilst,innerEquations=innerEquations),casualTearingSet=SOME(BackendDAE.TEARINGSET(tearingvars=ilst2,innerEquations=innerEquations2)),linear=false),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl),(te_l2,te_nl2))) algorithm
3830 ✗ d := listLength(ilst);
3831 ✗ e := listLength(innerEquations);
3832 ✗ d2 := listLength(ilst2);
3833 ✗ e2 := listLength(innerEquations2);
3834 ✗ then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,(d,e)::te_nl),(te_l2,(d2,e2)::te_nl2)));
3835
3836 else algorithm
3837 ✗ print("dumpCompShort2 failed with:\n");
3838 ✗ dumpComponent(inComp);
3839 ✗ then fail();
3840 end match;
3841 end dumpCompShort2;
3842
3843 public function dumpNrOfEquations
3844 "author Frenkel TUD 2012-11
3845 prints the number of scalar equations in the dae system"
3846 input BackendDAE.BackendDAE inDAE;
3847 input String preStr;
3848 protected
3849 list<Integer> nlst;
3850 Integer n;
3851 BackendDAE.EqSystems systs;
3852 algorithm
3853 ✗ BackendDAE.DAE(eqs=systs) := inDAE;
3854 ✗ nlst := List.map(systs,BackendDAEUtil.systemSize);
3855 ✗ n := List.fold(nlst,intAdd,0);
3856 ✗ print(preStr + " NrOfEquations: " + intString(n) + "\n");
3857 end dumpNrOfEquations;
3858
3859 public function dumpCompInfo"dumps the information about the operations in the component.
3860 author Waurich TUD 2014-04"
3861 input BackendDAE.CompInfo compInfo;
3862 algorithm
3863 ✗ print(printCompInfo(compInfo));
3864 end dumpCompInfo;
3865
3866 protected function printCompInfo""
3867 input BackendDAE.CompInfo compInfo;
3868 output String sOut;
3869 algorithm
3870 sOut := matchcontinue compInfo
3871 local
3872 Integer numAdds,numMul,numDiv,numOth,numTrig,numRel,numLog,numFuncs, size;
3873 Real dens;
3874 String s;
3875 BackendDAE.CompInfo allOps, tornEqs ,otherEqs;
3876 BackendDAE.StrongComponent comp;
3877 case BackendDAE.COUNTER(comp=comp,numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs)
3878 algorithm
3879 s := "";
3880 ✗ if BackendDAEUtil.isSingleEquationComp(comp) then s:= "SE "+printComponent(comp);
3881 ✗ elseif BackendDAEUtil.isWhenComp(comp) then s:= "WE "+printComponent(comp);
3882 ✗ elseif BackendDAEUtil.isArrayComp(comp) then s:= "AE "+printComponent(comp);
3883 end if;
3884 ✗ s := s+"\tadd|"+intString(numAdds)+"\tmul|"+intString(numMul)+"\tdiv|"+intString(numDiv)+"\ttrig|"+intString(numTrig)+"\trel|"+intString(numRel)+"\tlog|"+intString(numLog)+"\toth|"+intString(numOth)+"\tfuncs|"+intString(numFuncs)+"\n";
3885 then s;
3886 case BackendDAE.SYSTEM(allOperations=allOps,comp=comp,size=size,density=dens)
3887 algorithm
3888 s := "";
3889 ✗ if BackendDAEUtil.isLinearEqSystemComp(comp) then s:= "LSYS";
3890 else s := "NLSYS";
3891 end if;
3892 ✗ s := s+printComponent(comp)+"\tsize|"+intString(size)+"\tdens|"+intString(realInt(dens*100.0))+ printCompInfo(allOps);
3893 then s;
3894 case BackendDAE.TORN_ANALYSE(tornEqs=tornEqs, otherEqs=otherEqs,comp=comp,tornSize=size)
3895 algorithm
3896 //if BackendDAEUtil.isLinearTornSystem(comp) then s = "linear"; else s = "nonlinear"; end if;
3897 ✗ s := "TS "+printComponent(comp)+"\tsize|"+intString(size)+"\n";
3898 ✗ s := s + "\tthe torn eqs:\t"+ printCompInfo(tornEqs);
3899 ✗ s := s + "\tthe other eqs:\t" + printCompInfo(otherEqs);
3900 then s;
3901 case BackendDAE.NO_COMP(numAdds=numAdds,numMul=numMul,numDiv=numDiv,numTrig=numTrig,numRelations=numRel,numLog=numLog,numOth=numOth,funcCalls=numFuncs)
3902 algorithm
3903 s := "NC";
3904 ✗ s := s+"\tadd|"+intString(numAdds)+"\tmul|"+intString(numMul)+"\tdiv|"+intString(numDiv)+"\ttrig|"+intString(numTrig)+"\trel|"+intString(numRel)+"\tlog|"+intString(numLog)+"\toth|"+intString(numOth)+"\tfuncs|"+intString(numFuncs)+"\n";
3905 then s;
3906 else
3907 then "Dont know this compInfo\n";
3908 end matchcontinue;
3909 end printCompInfo;
3910
3911
3912 // =============================================================================
3913 // section for all html-dumping functions
3914 //
3915 // =============================================================================
3916
3917 public function dumpEqSystemMatrixHTML"dumps the adjacency matrix for the eqsystem as html file.
3918 author: waurich TUD 2016-05"
3919 input BackendDAE.EqSystem sys;
3920 protected
3921 BackendDAE.AdjacencyMatrix m;
3922 algorithm
3923 ✗ if isSome(sys.m) then
3924 ✗ m := Util.getOption(sys.m);
3925 else
3926 ✗ (_,m,_) := BackendDAEUtil.getAdjacencyMatrix(sys,BackendDAE.NORMAL(),NONE(),false); //no shared available so dump regular system.
3927 end if;
3928 ✗ BackendDump.dumpEqSystem(sys,"SYS");
3929 ✗ BackendDump.dumpMatrixHTML(m,List.map(List.intRange(BackendDAEUtil.systemSize(sys)),intString),
3930 List.map(BackendVariable.varList(sys.orderedVars),BackendDump.varStringShort),
3931 "MATRIX_"+intString(BackendDAEUtil.systemSize(sys)));
3932 end dumpEqSystemMatrixHTML;
3933
3934 public function dumpEqSystemBLTmatrixHTML"dumps the adjacency matrix for the eqsystem as html file.
3935 author: waurich TUD 2016-05"
3936 input BackendDAE.EqSystem sys;
3937 algorithm
3938 () := matchcontinue sys
3939 local
3940 BackendDAE.StrongComponents comps;
3941 BackendDAE.AdjacencyMatrix m;
3942 BackendDAE.EquationArray eqs;
3943 BackendDAE.Variables vars;
3944 list<BackendDAE.Var> varLst;
3945 list<BackendDAE.Equation> eqLst;
3946 list<Integer> vIdxs, eIdxs;
3947 case BackendDAE.EQSYSTEM(vars,eqs,_,_,_,BackendDAE.MATCHING(comps=comps),_,_,_)
3948 algorithm
3949 ✗ (varLst,vIdxs,eqLst,eIdxs) := BackendDAEUtil.getStrongComponentsVarsAndEquations(comps, vars, eqs);
3950 ✗ eqs := BackendEquation.listEquation(eqLst);
3951 ✗ vars := BackendVariable.listVar1(varLst);
3952 ✗ (m, _) := BackendDAEUtil.adjacencyMatrixDispatch(vars, eqs, BackendDAE.NORMAL(), NONE(), false); //no shared available so dump regular system.
3953 ✗ BackendDump.dumpMatrixHTML(m,List.map(eIdxs,intString),
3954 List.map(vIdxs,intString),
3955 "BLT_MATRIX_"+intString(BackendDAEUtil.systemSize(sys)));
3956 then ();
3957 else
3958 algorithm
3959 ✗ print("dumpEqSystemBLTmatrixHTML does not output anything since there is no BLT sorting.");
3960 then ();
3961 end matchcontinue;
3962 end dumpEqSystemBLTmatrixHTML;
3963
3964
3965 public function dumpMatrixHTML
3966 input BackendDAE.AdjacencyMatrix m;
3967 input list<String> rowNames;
3968 input list<String> columNames;
3969 input String fileName;
3970 protected
3971 Integer size;
3972 algorithm
3973 size := arrayLength(m);
3974 ✗ if listLength(rowNames)==size and listLength(columNames)==size then
3975 ✗ DumpHTML.dumpMatrixHTML(m,rowNames,columNames,fileName);
3976 else
3977 ✗ DumpHTML.dumpMatrixHTML(m,List.fill("?",size),List.fill("?",size),fileName);
3978 end if;
3979 end dumpMatrixHTML;
3980
3981 // =============================================================================
3982 // section for all graphML dumping functions
3983 //
3984 // =============================================================================
3985
3986 public function dumpBipartiteGraphDAE" Dumps a *.graphml of the complete BackendDAE.BackendDAE as a bipartite graph. Can be opened with yEd.
3987 author: Waurich"
3988 input BackendDAE.BackendDAE dae;
3989 input String fileName;
3990 protected
3991 BackendDAE.Variables vars;
3992 BackendDAE.EquationArray eqs;
3993 BackendDAE.EqSystems eqSysts;
3994 BackendDAE.AdjacencyMatrix m;
3995 BackendDAE.Shared shared;
3996 list<BackendDAE.Equation> eqLst;
3997 list<BackendDAE.Var> varLst;
3998 list<tuple<Boolean,String>> varAtts,eqAtts;
3999 algorithm
4000 ✗ BackendDAE.DAE(eqs=eqSysts, shared=shared) := dae;
4001 ✗ eqLst := List.flatten(List.mapMap(eqSysts,BackendEquation.getEqnsFromEqSystem,BackendEquation.equationList));
4002 ✗ varLst := List.flatten(List.mapMap(eqSysts,BackendVariable.daeVars,BackendVariable.varList));
4003 ✗ vars := BackendVariable.listVar1(varLst);
4004 ✗ eqs := BackendEquation.listEquation(eqLst);
4005 // build the adjacency matrix for the whole System
4006 ✗ (_,m,_,_,_) := BackendDAEUtil.getAdjacencyMatrixScalar(BackendDAE.EQSYSTEM(vars,eqs,NONE(),NONE(),NONE(),BackendDAE.NO_MATCHING(), {},BackendDAE.UNKNOWN_PARTITION(), BackendEquation.emptyEqns()),BackendDAE.SOLVABLE(), SOME(BackendDAEUtil.getFunctions(shared)), BackendDAEUtil.isInitializationDAE(shared));
4007 ✗ varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple);
4008 ✗ eqAtts := List.threadMap(List.fill(false,listLength(eqLst)),List.fill("",listLength(eqLst)),Util.makeTuple);
4009 ✗ dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph_"+fileName);
4010 end dumpBipartiteGraphDAE;
4011
4012 public function dumpBipartiteGraphEqSystem" Dumps a *.graphml of an BackendDAE.EqSystem as a bipartite graph. Can be opened with yEd.
4013 author: Waurich"
4014 input BackendDAE.EqSystem syst;
4015 input BackendDAE.Shared shared;
4016 input String fileName;
4017 protected
4018 BackendDAE.Variables vars;
4019 BackendDAE.EquationArray eqs;
4020 BackendDAE.AdjacencyMatrix m;
4021 Option<BackendDAE.AdjacencyMatrix> mO;
4022 list<BackendDAE.Var> varLst;
4023 list<tuple<Boolean,String>> varAtts,eqAtts;
4024 algorithm
4025 ✗ BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs, m=mO) := syst;
4026 ✗ varLst := BackendVariable.varList(vars);
4027 ✗ varAtts := List.threadMap(List.fill(false,listLength(varLst)),List.fill("",listLength(varLst)),Util.makeTuple);
4028 ✗ eqAtts := List.threadMap(List.fill(false,BackendEquation.equationArraySize(eqs)),List.fill("",BackendEquation.equationArraySize(eqs)),Util.makeTuple);
4029
4030 ✗ if isSome(mO) then
4031 ✗ dumpBipartiteGraphStrongComponent2(vars,eqs,Util.getOption(mO),varAtts,eqAtts,"BipartiteGraph_"+fileName);
4032 else
4033 // build the adjacency matrix
4034 ✗ (_,m,_,_,_) := BackendDAEUtil.getAdjacencyMatrixScalar(syst, BackendDAE.SOLVABLE(), SOME(BackendDAEUtil.getFunctions(shared)), BackendDAEUtil.isInitializationDAE(shared));
4035 ✗ dumpBipartiteGraphStrongComponent2(vars,eqs,m,varAtts,eqAtts,"BipartiteGraph2_"+fileName);
4036 end if;
4037 end dumpBipartiteGraphEqSystem;
4038
4039 public function dumpBipartiteGraphStrongComponent"dumps a bipartite graph of an equation system or a torn system as graphml.Can be opened with yEd.
4040 waurich: TUD 2014-09"
4041 input BackendDAE.StrongComponent inComp;
4042 input BackendDAE.EqSystem eqSys;
4043 input Option<AvlTreePathFunction.Tree> funcs;
4044 input String name;
4045 protected
4046 BackendDAE.EquationArray eqs;
4047 BackendDAE.Variables vars;
4048 list<BackendDAE.Var> varLst;
4049 list<BackendDAE.Equation> eqLst;
4050 algorithm
4051 ✗ BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs) := eqSys;
4052 ✗ varLst := BackendVariable.varList(vars);
4053 ✗ eqLst := BackendEquation.equationList(eqs);
4054 ✗ dumpBipartiteGraphStrongComponent1(inComp,eqLst,varLst,funcs,name);
4055 end dumpBipartiteGraphStrongComponent;
4056
4057 public function dumpBipartiteGraphStrongComponent1"helper function for dumpBipartiteGraphStrongComponent which handles either an equationsystem or a torn system"
4058 input BackendDAE.StrongComponent inComp;
4059 input list<BackendDAE.Equation> eqsIn;
4060 input list<BackendDAE.Var> varsIn;
4061 input Option<AvlTreePathFunction.Tree> funcs;
4062 input String graphName;
4063 algorithm
4064 () := matchcontinue inComp
4065 local
4066 Integer numEqs, numVars;
4067 list<Boolean> tornInfo;
4068 list<String> addInfo;
4069 list<Integer> eqIdcs,varIdcs,tVarIdcs,rEqIdcs, tVarIdcsNew, rEqIdcsNew;
4070 list<list<Integer>> varIdcsLst;
4071 BackendDAE.InnerEquations innerEquations;
4072 list<tuple<Boolean,String>> varAtts,eqAtts;
4073 BackendDAE.EquationArray compEqs;
4074 BackendDAE.Variables compVars;
4075 BackendDAE.AdjacencyMatrix m;
4076 list<BackendDAE.Equation> compEqLst;
4077 list<BackendDAE.Var> compVarLst;
4078 case BackendDAE.EQUATIONSYSTEM(eqns=eqIdcs,vars=varIdcs)
4079 algorithm
4080 ✗ compEqLst := List.map1(eqIdcs,List.getIndexFirst,eqsIn);
4081 ✗ compVarLst := List.map1(varIdcs,List.getIndexFirst,varsIn);
4082 ✗ compVars := BackendVariable.listVar1(compVarLst);
4083 ✗ compEqs := BackendEquation.listEquation(compEqLst);
4084
4085 ✗ numEqs := listLength(compEqLst);
4086 ✗ numVars := listLength(compVarLst);
4087 ✗ (_,m,_,_,_) := BackendDAEUtil.getAdjacencyMatrixScalar(BackendDAE.EQSYSTEM(compVars,compEqs,NONE(),NONE(),NONE(),BackendDAE.NO_MATCHING(),{},BackendDAE.UNKNOWN_PARTITION(),BackendEquation.emptyEqns()), BackendDAE.SOLVABLE(), funcs, false); // no shared available so dump regular system not initial
4088
4089 ✗ varAtts := List.threadMap(List.fill(false,numVars),List.fill("",numVars),Util.makeTuple);
4090 ✗ eqAtts := List.threadMap(List.fill(false,numEqs),List.fill("",numEqs),Util.makeTuple);
4091 ✗ dumpBipartiteGraphStrongComponent2(compVars,compEqs,m,varAtts,eqAtts,"rL_eqSys_"+graphName);
4092 then ();
4093 case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=rEqIdcs,tearingvars=tVarIdcs,innerEquations=innerEquations))
4094 algorithm
4095 //gather equations ans variables
4096 ✗ (eqIdcs,varIdcsLst,_) := List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
4097 ✗ varIdcs := List.flatten(varIdcsLst);
4098 ✗ eqIdcs := listAppend(eqIdcs, rEqIdcs) annotation(__OpenModelica_DisableListAppendWarning=true);
4099 ✗ varIdcs := listAppend(varIdcs, tVarIdcs) annotation(__OpenModelica_DisableListAppendWarning=true);
4100 ✗ compEqLst := List.map1(eqIdcs,List.getIndexFirst,eqsIn);
4101 ✗ compVarLst := List.map1(varIdcs,List.getIndexFirst,varsIn);
4102 ✗ compVars := BackendVariable.listVar1(compVarLst);
4103 ✗ compEqs := BackendEquation.listEquation(compEqLst);
4104
4105 // get adjacency matrix
4106 ✗ numEqs := listLength(compEqLst);
4107 ✗ numVars := listLength(compVarLst);
4108 ✗ (_,m,_,_,_) := BackendDAEUtil.getAdjacencyMatrixScalar(BackendDAE.EQSYSTEM(compVars,compEqs,NONE(),NONE(),NONE(),BackendDAE.NO_MATCHING(),{},BackendDAE.UNKNOWN_PARTITION(),BackendEquation.emptyEqns()), BackendDAE.SOLVABLE(), funcs, false); // no shared available so dump regular system not initial
4109
4110 // add tearing info to graph object and dump graph
4111 ✗ addInfo := List.map(varIdcs,intString);// the DAE idcs for the vars
4112 ✗ tornInfo := List.fill(true,numVars);
4113 ✗ tVarIdcsNew := List.intRange(numVars-listLength(tVarIdcs));
4114 ✗ tornInfo := List.fold1(tVarIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a tearing var or not
4115 ✗ varAtts := List.threadMap(tornInfo,addInfo,Util.makeTuple);
4116 ✗ addInfo := List.map(eqIdcs,intString);// the DAE idcs for the eqs
4117 ✗ tornInfo := List.fill(true,numEqs);
4118 ✗ rEqIdcsNew := List.intRange(numEqs-listLength(rEqIdcs));
4119 ✗ tornInfo := List.fold1(rEqIdcsNew,List.replaceAtIndexFirst,false,tornInfo);//is it a residual eq or not
4120 ✗ eqAtts := List.threadMap(tornInfo,addInfo,Util.makeTuple);
4121 ✗ dumpBipartiteGraphStrongComponent2(compVars,compEqs,m,varAtts,eqAtts,graphName);
4122 then ();
4123 else
4124 algorithm
4125 ✗ print("dumpTornSystemBipartiteGraphML1 failed\n");
4126 then ();
4127 end matchcontinue;
4128 end dumpBipartiteGraphStrongComponent1;
4129
4130 public function dumpBipartiteGraphStrongComponent2"helper function for dumpBipartiteGraphStrongComponent1 which dumps the graphml"
4131 input BackendDAE.Variables varsIn;
4132 input BackendDAE.EquationArray eqsIn;
4133 input BackendDAE.AdjacencyMatrix mIn;
4134 input list<tuple<Boolean,String>> varAtts; //<isTornVar,daeIdx>
4135 input list<tuple<Boolean,String>> eqAtts; //<isResEq,daeIdx>
4136 input String name;
4137 protected
4138 Integer nameAttIdx,typeAttIdx,idxAttIdx, numVars,numEqs;
4139 list<Integer> varRange,eqRange;
4140 GraphML.GraphInfo graphInfo;
4141 Integer graphIdx;
4142 algorithm
4143 1 numEqs := BackendEquation.equationArraySize(eqsIn);
4144 1 numVars := BackendVariable.varsSize(varsIn);
4145 1 varRange := List.intRange(numVars);
4146 1 eqRange := List.intRange(numEqs);
4147 1 graphInfo := GraphML.createGraphInfo();
4148 1 (graphInfo,(_,graphIdx)) := GraphML.addGraph("EqSystemGraph", true, graphInfo);
4149 1 (graphInfo,(_,typeAttIdx)) := GraphML.addAttribute("", "type", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4150 1 (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4151 1 (graphInfo,(_,idxAttIdx)) := GraphML.addAttribute("", "systIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4152 1 (graphInfo,graphIdx) := addEqNodesToGraph(eqsIn,eqAtts,{nameAttIdx,typeAttIdx,idxAttIdx},(graphInfo,graphIdx));
4153 1 (graphInfo,graphIdx) := List.fold3(varRange,addVarNodeToGraph,varsIn,varAtts,{nameAttIdx,typeAttIdx,idxAttIdx}, (graphInfo,graphIdx));
4154 1 graphInfo := List.fold1(eqRange,addEdgeToGraph,mIn,graphInfo);
4155 1 GraphML.dumpGraph(graphInfo,name+".graphml");
4156 end dumpBipartiteGraphStrongComponent2;
4157
4158 protected function addEqNodesToGraph
4159 input BackendDAE.EquationArray eqs;
4160 input list<tuple<Boolean,String>> attsIn; // <isResEq,"daeIdx">
4161 input list<Integer> attributeIdcs;//<name,type>
4162 input tuple<GraphML.GraphInfo,Integer> graphInfoIn;
4163 output tuple<GraphML.GraphInfo,Integer> graphInfoOut;
4164 protected
4165 BackendDAE.Equation eq;
4166 Boolean isResEq;
4167 Integer nameAttrIdx,typeAttrIdx,idxAttrIdx, graphIdx, size, numEqs, e, eAbs, nextE;
4168 String eqString, eqNodeId, idxString, typeStr, daeIdxStr;
4169 GraphML.GraphInfo graphInfo;
4170 GraphML.NodeLabel nodeLabel;
4171 algorithm
4172 1 nameAttrIdx := listGet(attributeIdcs,1);
4173 1 typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not
4174 1 idxAttrIdx := listGet(attributeIdcs,3);
4175 1 (graphInfo,graphIdx) := graphInfoIn;
4176 1 numEqs := BackendEquation.getNumberOfEquations(eqs);
4177 e := 1;
4178 eAbs := 1;
4179 size := 1;
4180
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1 time.
36 while e <= numEqs loop
4181 //print("check e "+intString(e)+"\n");
4182 35 eq := BackendEquation.get(eqs,e);
4183 35 size := BackendEquation.equationSize(eq);
4184 //print("size e "+intString(size)+"\n");
4185 35 nextE := eAbs+size;
4186
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35 times.
70 while nextE>eAbs loop
4187 //print("add e "+intString(nextE-size)+"\n");
4188 35 nameAttrIdx := listGet(attributeIdcs,1);
4189 35 typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not
4190 35 idxAttrIdx := listGet(attributeIdcs,3);
4191 35 isResEq := Util.tuple21(listGet(attsIn,e));
4192 35 daeIdxStr := Util.tuple22(listGet(attsIn,e));
4193
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 typeStr := if isResEq then "residualEq" else "otherEq";
4194
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 35 times.
35 {eq} := BackendEquation.getList({e}, eqs);
4195 35 eqString := BackendDump.equationString(eq);
4196 35 eqNodeId := getEqNodeIdx(eAbs);
4197 35 idxString := intString(eAbs);
4198 35 nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN());
4199 70 (graphInfo,_) := GraphML.addNode(eqNodeId,GraphML.COLOR_GREEN2,GraphML.BORDERWIDTH_STANDARD,{nodeLabel},GraphML.RECTANGLE(),SOME(eqString),{(nameAttrIdx,eqString),(typeAttrIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo);
4200 35 eAbs := eAbs+1;
4201 size := size-1;
4202 end while;
4203 35 e := e+1;
4204 end while;
4205 1 graphInfoOut := (graphInfo,graphIdx);
4206 end addEqNodesToGraph;
4207
4208 public function dumpDAGStrongComponent"dumps a directed acyclic graph for the matched strongly connected component"
4209 input HpcOmTaskGraph.TaskGraph graphIn;
4210 input HpcOmTaskGraph.TaskGraphMeta metaIn;
4211 input String fileName;
4212 protected
4213 Integer graphIdx, nameAttIdx;
4214 GraphML.GraphInfo graphInfo;
4215 algorithm
4216 ✗ graphInfo := GraphML.createGraphInfo();
4217 ✗ (graphInfo, (_,graphIdx)) := GraphML.addGraph("TornSystemGraph", true, graphInfo);
4218 ✗ (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "Name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4219 ✗ graphInfo := buildGraphInfoDAG(graphIn,metaIn,graphInfo,graphIdx,{nameAttIdx});
4220 ✗ GraphML.dumpGraph(graphInfo, fileName+".graphml");
4221 end dumpDAGStrongComponent;
4222
4223 protected function buildGraphInfoDAG"helper function for dumpDAGStrongComponent"
4224 input HpcOmTaskGraph.TaskGraph graphIn;
4225 input HpcOmTaskGraph.TaskGraphMeta metaIn;
4226 input GraphML.GraphInfo graphInfoIn;
4227 input Integer graphIdx;
4228 input list<Integer> attIdcs;
4229 output GraphML.GraphInfo graphInfoOut;
4230 protected
4231 list<Integer> nodeIdcs;
4232 list<GraphML.Node> nodes;
4233 Integer nameAttIdx;
4234 algorithm
4235 ✗ nameAttIdx := listHead(attIdcs);
4236 ✗ nodeIdcs := List.intRange(arrayLength(graphIn));
4237 ✗ graphInfoOut := List.fold4(nodeIdcs,addNodeToDAG,graphIn,metaIn,graphIdx,{nameAttIdx},graphInfoIn);
4238 ✗ GraphML.GRAPHINFO(nodes=nodes) := graphInfoOut;
4239 end buildGraphInfoDAG;
4240
4241 protected function addNodeToDAG"add a node to a DAG.
4242 author:Waurich TUD 2014-07"
4243 input Integer nodeIdx;
4244 input HpcOmTaskGraph.TaskGraph graphIn;
4245 input HpcOmTaskGraph.TaskGraphMeta metaIn;
4246 input Integer graphIdx;
4247 input list<Integer> atts; //{nameAtt}
4248 input GraphML.GraphInfo graphInfoIn;
4249 output GraphML.GraphInfo graphInfoOut;
4250 protected
4251 GraphML.GraphInfo tmpGraph;
4252 Integer nameAttIdx;
4253 list<Integer> childNodes;
4254 array<String> compDescs;
4255 array<list<Integer>> inComps;
4256 GraphML.NodeLabel nodeLabel;
4257 String nodeString, nodeDesc, compName;
4258 algorithm
4259 ✗ HpcOmTaskGraph.TASKGRAPHMETA(inComps=inComps,compDescs=compDescs) := metaIn;
4260 ✗ nodeDesc := arrayGet(compDescs,nodeIdx);
4261 ✗ nodeString := intString(nodeIdx);
4262 ✗ compName := stringDelimitList(List.map(arrayGet(inComps,nodeIdx),intString),",");
4263 ✗ nameAttIdx := listGet(atts,1);
4264 ✗ nodeLabel := GraphML.NODELABEL_INTERNAL(nodeString,NONE(),GraphML.FONTPLAIN());
4265 ✗ (tmpGraph,_) := GraphML.addNode("Node"+intString(nodeIdx),
4266 GraphML.COLOR_ORANGE,
4267 GraphML.BORDERWIDTH_STANDARD,
4268 {nodeLabel},
4269 GraphML.RECTANGLE(),
4270 SOME(nodeDesc),
4271 {(nameAttIdx,compName)},
4272 graphIdx,
4273 graphInfoIn);
4274 ✗ childNodes := arrayGet(graphIn,nodeIdx);
4275 ✗ graphInfoOut := List.fold1(childNodes, addDirectedEdge, nodeIdx, tmpGraph);
4276 end addNodeToDAG;
4277
4278 protected function addDirectedEdge"add a directed edge from child to parent
4279 author: Waurich TUD 2014-07"
4280 input Integer child;
4281 input Integer parent;
4282 input GraphML.GraphInfo graphInfoIn;
4283 output GraphML.GraphInfo graphInfoOut;
4284 algorithm
4285 ✗ (graphInfoOut,_) := GraphML.addEdge( "Edge" + intString(parent)+intString(child),
4286 "Node" + intString(child),
4287 "Node" + intString(parent),
4288 GraphML.COLOR_BLACK,
4289 GraphML.LINE(),
4290 GraphML.LINEWIDTH_STANDARD,
4291 false,{},
4292 (GraphML.ARROWNONE(),GraphML.ARROWSTANDART()),
4293 {},
4294 graphInfoIn);
4295 end addDirectedEdge;
4296
4297 protected function addVarNodeToGraph "adds a node for a variable to the graph.
4298 author:Waurich TUD 2013-12"
4299 input Integer indx;
4300 input BackendDAE.Variables vars;
4301 input list<tuple<Boolean,String>> attsIn; //<isTearingVar,"index in the dae">
4302 input list<Integer> attributeIdcs;//<name,type,daeidx>
4303 input tuple<GraphML.GraphInfo,Integer> graphInfoIn;
4304 output tuple<GraphML.GraphInfo,Integer> graphInfoOut;
4305 protected
4306 BackendDAE.Var var;
4307 Boolean isTearVar;
4308 Integer nameAttrIdx,typeAttIdx,idxAttrIdx, graphIdx;
4309 String varString, varNodeId, idxString, typeStr, daeIdxStr;
4310 GraphML.GraphInfo graphInfo;
4311 GraphML.NodeLabel nodeLabel;
4312 algorithm
4313 35 (graphInfo,graphIdx) := graphInfoIn;
4314 35 nameAttrIdx := listGet(attributeIdcs,1);
4315 35 typeAttIdx := listGet(attributeIdcs,2); // if its a tearingvar or not
4316 35 idxAttrIdx:= listGet(attributeIdcs,3);
4317 35 isTearVar := Util.tuple21(listGet(attsIn,indx));
4318 35 daeIdxStr := Util.tuple22(listGet(attsIn,indx));
4319
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 typeStr := if isTearVar then "tearingVar" else "otherVar";
4320 35 var := BackendVariable.getVarAt(vars,indx);
4321 35 varString := BackendDump.varString(var);
4322 35 varNodeId := getVarNodeIdx(indx);
4323 35 idxString := intString(indx);
4324 35 nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN());
4325 70 (graphInfo,_) := GraphML.addNode(varNodeId, GraphML.COLOR_ORANGE2,GraphML.BORDERWIDTH_STANDARD, {nodeLabel},GraphML.ELLIPSE(),SOME(varString),{(nameAttrIdx,varString),(typeAttIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo);
4326 35 graphInfoOut := (graphInfo,graphIdx);
4327 end addVarNodeToGraph;
4328
4329 protected function addEqNodeToGraph "adds a node for an equation to the graph.
4330 author:Waurich TUD 2013-12"
4331 input Integer indx;
4332 input BackendDAE.EquationArray eqs;
4333 input list<tuple<Boolean,String>> attsIn; // <isResEq,"daeIdx">
4334 input list<Integer> attributeIdcs;//<name,type>
4335 input tuple<GraphML.GraphInfo,Integer> graphInfoIn;
4336 output tuple<GraphML.GraphInfo,Integer> graphInfoOut;
4337 protected
4338 BackendDAE.Equation eq;
4339 Boolean isResEq;
4340 Integer nameAttrIdx,typeAttrIdx,idxAttrIdx, graphIdx;
4341 String eqString, eqNodeId, idxString, typeStr, daeIdxStr;
4342 GraphML.GraphInfo graphInfo;
4343 GraphML.NodeLabel nodeLabel;
4344 algorithm
4345 ✗ (graphInfo,graphIdx) := graphInfoIn;
4346 ✗ nameAttrIdx := listGet(attributeIdcs,1);
4347 ✗ typeAttrIdx := listGet(attributeIdcs,2); // if its a residual or not
4348 ✗ idxAttrIdx := listGet(attributeIdcs,3);
4349 ✗ isResEq := Util.tuple21(listGet(attsIn,indx));
4350 ✗ daeIdxStr := Util.tuple22(listGet(attsIn,indx));
4351 ✗ typeStr := if isResEq then "residualEq" else "otherEq";
4352 ✗ {eq} := BackendEquation.getList({indx}, eqs);
4353 ✗ eqString := BackendDump.equationString(eq);
4354 ✗ eqNodeId := getEqNodeIdx(indx);
4355 ✗ idxString := intString(indx);
4356 ✗ nodeLabel := GraphML.NODELABEL_INTERNAL(idxString,NONE(),GraphML.FONTPLAIN());
4357 ✗ (graphInfo,_) := GraphML.addNode(eqNodeId,GraphML.COLOR_GREEN2,GraphML.BORDERWIDTH_STANDARD,{nodeLabel},GraphML.RECTANGLE(),SOME(eqString),{(nameAttrIdx,eqString),(typeAttrIdx,typeStr),(idxAttrIdx,daeIdxStr)},graphIdx,graphInfo);
4358 ✗ graphInfoOut := (graphInfo,graphIdx);
4359 end addEqNodeToGraph;
4360
4361 protected function addEdgeToGraph "adds an edge to the graph by traversing the adjacency matrix.
4362 author:Waurich TUD 2013-12"
4363 input Integer eqIdx;
4364 input BackendDAE.AdjacencyMatrix m;
4365 input GraphML.GraphInfo graphInfoIn;
4366 output GraphML.GraphInfo graphInfoOut;
4367 protected
4368 list<Integer> varLst;
4369 algorithm
4370 35 varLst := arrayGet(m,eqIdx);
4371 35 graphInfoOut := List.fold1(varLst,addEdgeToGraph2,eqIdx,graphInfoIn);
4372 end addEdgeToGraph;
4373
4374 protected function addEdgeToGraph2 "helper for addEdgeToGraph.
4375 author:Waurich TUD 2013-12"
4376 input Integer varIdxIn;
4377 input Integer eqIdx;
4378 input GraphML.GraphInfo graphInfoIn;
4379 output GraphML.GraphInfo graphInfoOut;
4380 protected
4381 Integer varIdx;
4382 String eqNodeId, varNodeId;
4383 GraphML.LineType lt;
4384 algorithm
4385
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if varIdxIn <= 0 then lt := GraphML.DASHED(); else lt := GraphML.LINE(); end if;
4386 111 varIdx := intAbs(varIdxIn);
4387 111 eqNodeId := getEqNodeIdx(eqIdx);
4388 111 varNodeId := getVarNodeIdx(varIdx);
4389 111 (graphInfoOut,_) := GraphML.addEdge("Edge_"+intString(varIdx)+"_"+intString(eqIdx),varNodeId,eqNodeId,GraphML.COLOR_BLACK,lt,GraphML.LINEWIDTH_STANDARD,false,{},(GraphML.ARROWNONE(),GraphML.ARROWNONE()),{}, graphInfoIn);
4390 end addEdgeToGraph2;
4391
4392 protected function getVarNodeIdx "outputs the identifier string for the given varIdx.
4393 author:Waurich TUD 2013-12"
4394 input Integer idx;
4395 output String varString;
4396 algorithm
4397 146 varString := "varNode"+intString(intAbs(idx));
4398 end getVarNodeIdx;
4399
4400 protected function getEqNodeIdx "outputs the identifier string for the given eqIdx.
4401 author:Waurich TUD 2013-12"
4402 input Integer idx;
4403 output String eqString;
4404 algorithm
4405 146 eqString := "eqNode"+intString(intAbs(idx));
4406 end getEqNodeIdx;
4407
4408 public function dumpBackendDAEBipartiteGraph
4409 input BackendDAE.BackendDAE dae;
4410 input String filename;
4411 protected
4412 Integer graphIdx, sysIdx, varIdx, eqIdx, order;
4413 Integer nameAttIdx,varAttIdx,eqAttIdx,sysAttIdx,tearAttIdx,compAttIdx,orderAttIdx;
4414 String tearInfo, nodeColor;
4415 GraphML.GraphInfo graphInfo;
4416 GraphML.ShapeType shapeType;
4417 GraphML.LineType lineType;
4418 Real lineWidth, borderWidth;
4419 BackendDAE.EqSystems systs;
4420 BackendDAE.Shared shared;
4421 list<BackendDAE.Equation> eqLst;
4422 list<BackendDAE.Var> varLst;
4423 list<Integer> eqIdxs, varIdxs;
4424 BackendDAE.Variables vars;
4425 BackendDAE.EquationArray eqs;
4426 BackendDAE.StrongComponents comps;
4427 BackendDAE.AdjacencyMatrix m,mT;
4428 array<Integer> ass2;
4429 algorithm
4430 //create graph
4431 ✗ graphInfo := GraphML.createGraphInfo();
4432 ✗ (graphInfo, (_,graphIdx)) := GraphML.addGraph("TaskGraph", true, graphInfo);
4433 ✗ (graphInfo,(_,nameAttIdx)) := GraphML.addAttribute("", "Name", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4434 ✗ (graphInfo,(_,varAttIdx)) := GraphML.addAttribute("", "VarIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4435 ✗ (graphInfo,(_,eqAttIdx)) := GraphML.addAttribute("", "EqIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4436 ✗ (graphInfo,(_,sysAttIdx)) := GraphML.addAttribute("", "SysIdx", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4437 ✗ (graphInfo,(_,tearAttIdx)) := GraphML.addAttribute("", "Tearing", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4438 ✗ (graphInfo,(_,compAttIdx)) := GraphML.addAttribute("", "SCC", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4439 ✗ (graphInfo,(_,orderAttIdx)) := GraphML.addAttribute("", "executionOrder", GraphML.TYPE_STRING(), GraphML.TARGET_NODE(), graphInfo);
4440
4441 //traverse dae
4442 ✗ BackendDAE.DAE(systs, shared) := dae;
4443 sysIdx := 1;
4444 ✗ for sys in systs loop
4445 ✗ BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs, matching = BackendDAE.MATCHING(comps=comps,ass2=ass2)) := sys;
4446 //dump the edges
4447 ✗ (m, mT) := BackendDAEUtil.adjacencyMatrix(sys, BackendDAE.NORMAL(), SOME(BackendDAEUtil.getFunctions(shared)), BackendDAEUtil.isInitializationDAE(shared));
4448
4449 //traverse comps
4450 order := 1;
4451 ✗ for comp in comps loop
4452 ✗ (varLst, varIdxs, eqLst, eqIdxs) := BackendDAEUtil.getStrongComponentsVarsAndEquations({comp},vars,eqs);
4453
4454 //dump variable nodes
4455 ✗ for varIdx in varIdxs loop
4456 ✗ nodeColor := if isAlgLoop(comp) then GraphML.COLOR_RED2 else GraphML.COLOR_GREEN2;
4457 ✗ borderWidth := if BackendVariable.isStateVar(BackendVariable.getVarAt(vars,varIdx)) then GraphML.BORDERWIDTH_BOLD else GraphML.BORDERWIDTH_STANDARD;
4458 ✗ if isTearingVar(varIdx,comp) then
4459 shapeType := GraphML.ELLIPSE();
4460 tearInfo := "TearingVar";
4461 nodeColor := GraphML.COLOR_RED;
4462 else
4463 shapeType := GraphML.ELLIPSE();
4464 tearInfo := "AlgebraicVar";
4465 end if;
4466 ✗ (graphInfo,_) := GraphML.addNode("V_"+intString(sysIdx)+"_"+intString(varIdx), nodeColor, borderWidth,
4467 {GraphML.NODELABEL_INTERNAL(intString(varIdx), NONE(), GraphML.FONTPLAIN())},
4468 shapeType, SOME(BackendDump.varString(BackendVariable.getVarAt(vars,varIdx))),
4469 {((nameAttIdx,"V_"+intString(sysIdx)+"_"+intString(varIdx))), ((varAttIdx, intString(varIdx))), ((eqAttIdx, "-")), ((compAttIdx, BackendDump.printComponent(comp))), ((sysAttIdx, intString(sysIdx))), ((tearAttIdx,tearInfo)), ((orderAttIdx,intString(order)))},
4470 graphIdx,graphInfo);
4471 end for;
4472
4473 //dump equation nodes
4474 ✗ for eqIdx in eqIdxs loop
4475 ✗ nodeColor := if isAlgLoop(comp) then GraphML.COLOR_RED2 else GraphML.COLOR_GREEN2;
4476 ✗ if isResidualEq(eqIdx,comp) then
4477 shapeType := GraphML.RECTANGLE();
4478 tearInfo := "ResidualEq";
4479 nodeColor := GraphML.COLOR_RED;
4480 else
4481 shapeType := GraphML.RECTANGLE();
4482 tearInfo := "AlgebraicEq";
4483 end if;
4484 ✗ (graphInfo,_) := GraphML.addNode("E_"+intString(sysIdx)+"_"+intString(eqIdx), nodeColor, GraphML.BORDERWIDTH_STANDARD,
4485 {GraphML.NODELABEL_INTERNAL(intString(eqIdx), NONE(), GraphML.FONTPLAIN())},
4486 shapeType, SOME(BackendDump.equationString(BackendEquation.get(eqs,eqIdx))),
4487 {((nameAttIdx,"E_"+intString(sysIdx)+"_"+intString(eqIdx))), ((varAttIdx, "-")), ((compAttIdx, BackendDump.printComponent(comp))), ((eqAttIdx, intString(eqIdx))), ((sysAttIdx, intString(sysIdx))), ((tearAttIdx,tearInfo)),((orderAttIdx,intString(order)))},
4488 graphIdx,graphInfo);
4489 end for;
4490 ✗ order := order+1;
4491 end for;//end comps
4492
4493 //dump edges
4494 ✗ for eqIdx in 1:arrayLength(m) loop
4495 ✗ for varIdx in arrayGet(m, eqIdx) loop
4496 ✗ if intLe(varIdx, 0) then
4497 lineType := GraphML.DASHED();
4498 else
4499 lineType := GraphML.LINE();
4500 end if;
4501 ✗ varIdx := intAbs(varIdx);
4502 ✗ lineWidth := if intEq(varIdx,ass2[eqIdx]) then GraphML.LINEWIDTH_BOLD else GraphML.LINEWIDTH_STANDARD;
4503 ✗ (graphInfo,_) := GraphML.addEdge("Edge_"+intString(sysIdx)+"_" + intString(eqIdx)+"_" + intString(varIdx),
4504 "V_"+intString(sysIdx)+"_"+intString(varIdx), "E_"+intString(sysIdx)+"_"+intString(eqIdx),
4505 GraphML.COLOR_BLACK,
4506 lineType,
4507 lineWidth,
4508 false,
4509 {},
4510 (GraphML.ARROWNONE(),GraphML.ARROWNONE()),
4511 {},
4512 graphInfo);
4513 end for;
4514 end for;//end edges
4515 ✗ sysIdx := sysIdx+1;
4516 end for;//end sys
4517
4518 //dump
4519 ✗ GraphML.dumpGraph(graphInfo, filename+".graphml");
4520 end dumpBackendDAEBipartiteGraph;
4521
4522 protected function isTearingVar
4523 input Integer varIdx;
4524 input BackendDAE.StrongComponent comp;
4525 output Boolean isTear;
4526 algorithm
4527 isTear := match comp
4528 local
4529 list<Integer> tVars;
4530 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(tearingvars=tVars))
4531 algorithm
4532 ✗ then List.exist1(tVars,intEq,varIdx);
4533 else
4534 then false;
4535 end match;
4536 end isTearingVar;
4537
4538 protected function isAlgLoop
4539 input BackendDAE.StrongComponent comp;
4540 output Boolean isLoop;
4541 algorithm
4542 isLoop := match comp
4543 case BackendDAE.EQUATIONSYSTEM(_)
4544 then true;
4545 case BackendDAE.TORNSYSTEM(_)
4546 then true;
4547 else
4548 then false;
4549 end match;
4550 end isAlgLoop;
4551
4552 protected function isResidualEq
4553 input Integer eqIdx;
4554 input BackendDAE.StrongComponent comp;
4555 output Boolean isRes;
4556 algorithm
4557 isRes := match comp
4558 local
4559 list<Integer> resEqs;
4560 case BackendDAE.TORNSYSTEM(strictTearingSet=BackendDAE.TEARINGSET(residualequations=resEqs))
4561 ✗ then List.exist1(resEqs,intEq,eqIdx);
4562 else
4563 then false;
4564 end match;
4565 end isResidualEq;
4566
4567 public function SSSHandlerArgString"
4568 author:Waurich"
4569 input Option<BackendDAE.StructurallySingularSystemHandlerArg> arg;
4570 protected
4571 BackendDAE.StateOrder stateorder;
4572 BackendDAE.ConstraintEquations constraints;
4573 array<list<Integer>> eqs2EqIdxs;
4574 array<Integer> eqIdx2Eq;
4575 Integer numEqs;
4576 algorithm
4577 ✗ if isSome(arg) then
4578 ✗ SOME((stateorder,constraints,eqs2EqIdxs,eqIdx2Eq,numEqs)) := arg;
4579 ✗ print(intString(numEqs)+"eqs before IR\n");
4580 ✗ dumpStateOrder(stateorder);
4581 ✗ print("Constraints:\n"+constraintEquationString(constraints)+"\n");
4582 else
4583 ✗ print("Empty StructurallySingularSystemHandlerArg\n");
4584 end if;
4585 end SSSHandlerArgString;
4586
4587 public function constraintEquationString"
4588 author:Waurich"
4589 input BackendDAE.ConstraintEquations constraints;
4590 output String s = "";
4591 protected
4592 Integer i;
4593 String s1;
4594 algorithm
4595 ✗ for i in 1:arrayLength(constraints) loop
4596 ✗ s1 := stringDelimitList(List.map(arrayGet(constraints,i),BackendDump.equationString),"\n")+"\n------------------\n";
4597 ✗ if listEmpty(arrayGet(constraints,i)) then
4598 s1 := "empty Constraints\n";
4599 end if;
4600 ✗ s := "eq "+intString(i) +": "+ s1 + s;
4601 end for;
4602 end constraintEquationString;
4603
4604 public function dumpStateOrder
4605 "author: Frenkel TUD 2011-05
4606 Prints the state order"
4607 input BackendDAE.StateOrder inStateOrder;
4608 algorithm
4609 ():=
4610 match inStateOrder
4611 local
4612 String str,len_str;
4613 Integer len;
4614 HashTableCG.HashTable ht;
4615 list<tuple<DAE.ComponentRef,DAE.ComponentRef>> tplLst;
4616 case BackendDAE.STATEORDER(ht,_)
4617 algorithm
4618 1 tplLst := BaseHashTable.hashTableList(ht);
4619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if not listEmpty(tplLst) then
4620 ✗ print("State Order: (");
4621 ✗ str := stringDelimitList(List.map(tplLst,printStateOrderStr),"\n");
4622 ✗ len := listLength(tplLst);
4623 ✗ len_str := intString(len);
4624 ✗ print(len_str);
4625 ✗ print(")\n");
4626 ✗ print("=============\n");
4627 ✗ print(str);
4628 ✗ print("\n\n");
4629 end if;
4630 then
4631 ();
4632 end match;
4633 end dumpStateOrder;
4634
4635 protected function printStateOrderStr "help function to dumpStateOrder"
4636 input tuple<DAE.ComponentRef,DAE.ComponentRef> tpl;
4637 output String str;
4638 algorithm
4639 ✗ str := ComponentReferenceBasics.printComponentRefStr(Util.tuple21(tpl)) + " ---d/dt---> " + ComponentReferenceBasics.printComponentRefStr(Util.tuple22(tpl));
4640 end printStateOrderStr;
4641
4642 public function dumpBackendDAEModeData
4643 input BackendDAE.BackendDAEModeData inDAEmodeData;
4644 protected
4645 BackendDAE.Variables modelVars;
4646 algorithm
4647 ✗ print("\n" + BORDER + "\nDAEMode\n" + UNDERLINE + "\n");
4648 ✗ if isSome(inDAEmodeData.modelVars) then
4649 ✗ SOME(modelVars) := inDAEmodeData.modelVars;
4650 ✗ dumpVariables(modelVars, "ModelVariables");
4651 else
4652 ✗ print("No ModelVariables\n");
4653 end if;
4654 ✗ print("DAEmode System:\n " + intString(inDAEmodeData.numResVars) + " residual variables\n " +
4655 intString(listLength(inDAEmodeData.stateVars)) + " state variables\n " +
4656 intString(listLength(inDAEmodeData.algStateVars)) + " algebraic state variables\n");
4657 ✗ dumpVarList(inDAEmodeData.stateVars, "State Variables");
4658 ✗ dumpVarList(inDAEmodeData.algStateVars, "Algebraic State Variables");
4659 end dumpBackendDAEModeData;
4660
4661 annotation(__OpenModelica_Interface="backend");
4662 end BackendDump;
4663