-
Notifications
You must be signed in to change notification settings - Fork 299
/
BackendDump.mo
2981 lines (2827 loc) · 94.7 KB
/
BackendDump.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linköping University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package BackendDump
" file: BackendDump.mo
package: BackendDump
description: Unparsing the BackendDAE structure
RCS: $Id$
"
public import BackendDAE;
public import DAE;
protected import Absyn;
protected import Algorithm;
protected import BackendDAETransform;
protected import BackendDAEUtil;
protected import BackendVariable;
protected import BackendEquation;
protected import ComponentReference;
protected import DAEDump;
protected import DAEUtil;
protected import Debug;
protected import Expression;
protected import ExpressionDump;
protected import Flags;
protected import IOStream;
protected import List;
protected import SCode;
protected import Util;
protected import ClassInf;
public function printComponentRefStrDIVISION
input DAE.ComponentRef inCref;
input BackendDAE.Variables inVars;
output String outString;
algorithm
outString := matchcontinue(inCref,inVars)
local
DAE.ComponentRef c,co;
BackendDAE.Variables variables;
String sc;
case(c,variables)
equation
((BackendDAE.VAR(varName=co):: _),_) = BackendVariable.getVar(c,variables);
sc = ComponentReference.printComponentRefStr(co);
then
sc;
case(c,variables)
equation
sc = ComponentReference.printComponentRefStr(c);
then
sc;
end matchcontinue;
end printComponentRefStrDIVISION;
public function printCallFunction2StrDIVISION
"function: printCallFunction2Str
Print the exp of typ DAE.CALL."
input DAE.Exp inExp;
input String stringDelimiter;
input Option<tuple<printComponentRefStrFunc,Type_a>> opcreffunc "tuple of function that print component references and a extra parameter passet throug the function";
output String outString;
replaceable type Type_a subtypeof Any;
partial function printComponentRefStrFunc
input DAE.ComponentRef inComponentRef;
input Type_a Param;
output String outString;
end printComponentRefStrFunc;
algorithm
outString := matchcontinue (inExp,stringDelimiter,opcreffunc)
local
Expression.Ident s,s_1,s_2,fs,argstr;
Absyn.Path fcn;
list<DAE.Exp> args;
DAE.Exp e1,e2;
Expression.Type ty;
case( DAE.CALL(path = Absyn.IDENT("DIVISION"), expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty = ty)), _, _)
equation
s = ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
then
s;
case( DAE.CALL(path = Absyn.IDENT("DIVISION_ARRAY_SCALAR"),expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty =ty)), _, _)
equation
s = ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV_ARRAY_SCALAR(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
then
s;
case( DAE.CALL(path = Absyn.IDENT("DIVISION_SCALAR_ARRAY"),expLst = {e1,e2,DAE.SCONST(_)}, attr = DAE.CALL_ATTR(ty =ty)), _, _)
equation
s = ExpressionDump.printExp2Str(DAE.BINARY(e1,DAE.DIV_SCALAR_ARRAY(ty),e2),stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION));
then
s;
case (DAE.CALL(path = fcn,expLst = args), _,_)
equation
fs = Absyn.pathString(fcn);
argstr = stringDelimitList(
List.map3(args, ExpressionDump.printExp2Str, stringDelimiter,opcreffunc, SOME(printCallFunction2StrDIVISION)), ",");
s = stringAppend(fs, "(");
s_1 = stringAppend(s, argstr);
s_2 = stringAppend(s_1, ")");
then
s_2;
end matchcontinue;
end printCallFunction2StrDIVISION;
public function printEquations
input list<Integer> inIntegerLst;
input BackendDAE.EqSystem syst;
algorithm
_:=
match (inIntegerLst,syst)
local
BackendDAE.Value n;
list<BackendDAE.Value> rest;
case ({},_) then ();
case ((n :: rest),syst)
equation
printEquations(rest, syst);
printEquationNo(n, syst);
then
();
end match;
end printEquations;
protected function printEquationNo "function: printEquationNo
author: PA
Helper function to print_equations"
input Integer inInteger;
input BackendDAE.EqSystem syst;
algorithm
_:=
match (inInteger,syst)
local
BackendDAE.Value eqno_1,eqno;
BackendDAE.Equation eq;
BackendDAE.EquationArray eqns;
case (eqno,BackendDAE.EQSYSTEM(orderedEqs = eqns))
equation
eqno_1 = eqno - 1;
eq = BackendDAEUtil.equationNth(eqns, eqno_1);
printEquation(eq);
then
();
end match;
end printEquationNo;
public function printEquation "function: printEquation
author: PA
Helper function to print_equations
"
input BackendDAE.Equation inEquation;
algorithm
print(equationStr(inEquation) +& "\n");
end printEquation;
public function dumpEquation "function: dumpEquation
author: Frenkel TUD
"
input BackendDAE.Equation inEquation;
algorithm
_:=
match (inEquation)
local
String s1,s2,res;
DAE.Exp e1,e2;
DAE.ComponentRef cr;
BackendDAE.WhenEquation w;
case (BackendDAE.EQUATION(exp = e1,scalar = e2))
equation
ExpressionDump.dumpExp(e1);
print("=\n");
ExpressionDump.dumpExp(e2);
then
();
case (BackendDAE.RESIDUAL_EQUATION(exp = e1))
equation
ExpressionDump.dumpExp(e1);
print("\n");
then
();
case (_)
then
();
end match;
end dumpEquation;
protected function printVarsStatistics "function: printVarsStatistics
author: PA
Prints statistics on variables, currently depth of BinTree, etc.
"
input BackendDAE.Variables inVariables1;
input BackendDAE.Variables inVariables2;
algorithm
_:=
matchcontinue (inVariables1,inVariables2)
local
String lenstr,bstr;
BackendDAE.VariableArray v1,v2;
BackendDAE.Value bsize1,n1,bsize2,n2;
case (BackendDAE.VARIABLES(varArr = v1,bucketSize = bsize1,numberOfVars = n1),BackendDAE.VARIABLES(varArr = v2,bucketSize = bsize2,numberOfVars = n2))
equation
print("Variable Statistics\n");
print("===================\n");
print("Number of variables: ");
lenstr = intString(n1);
print(lenstr);
print("\n");
print("Bucket size for variables: ");
bstr = intString(bsize1);
print(bstr);
print("\n");
print("Number of known variables: ");
lenstr = intString(n2);
print(lenstr);
print("\n");
print("Bucket size for known variables: ");
bstr = intString(bsize1);
print(bstr);
print("\n");
then
();
end matchcontinue;
end printVarsStatistics;
public function dumpTypeStr
"Dump BackendDAE.Type to a string."
input BackendDAE.Type inType;
output String outString;
algorithm
outString:=
match (inType)
local
String s1,s2,str;
list<String> l;
case DAE.T_INTEGER(source = _) then "Integer ";
case DAE.T_REAL(source = _) then "Real ";
case DAE.T_BOOL(source = _) then "Boolean ";
case DAE.T_STRING(source = _) then "String ";
case DAE.T_ENUMERATION(names = l)
equation
s1 = stringDelimitList(l, ", ");
s2 = stringAppend("enumeration(", s1);
str = stringAppend(s2, ")");
then
str;
case DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(_)) then "ExternalObject ";
end match;
end dumpTypeStr;
public function dumpTearing
" function: dumpTearing
autor: Frenkel TUD
Dump tearing vars and residual equations."
input list<list<Integer>> inResEqn;
input list<list<Integer>> inTearVar;
algorithm
_:=
match (inResEqn,inTearVar)
local
list<Integer> tearingvars,residualeqns;
list<list<Integer>> r,t;
list<String> str_r,str_t;
String str_r_f,str_r_1,str_t_f,str_t_1,str,sr,st;
case (residualeqns::r,tearingvars::t)
equation
str_r = List.map(residualeqns, intString);
str_r_f = stringDelimitList(str_r, ", ");
str_r_1 = stringAppend(str_r_f, "\n");
sr = stringAppend("ResidualEqns: ",str_r_1);
str_t = List.map(tearingvars, intString);
str_t_f = stringDelimitList(str_t, ", ");
str_t_1 = stringAppend(str_t_f, "\n");
st = stringAppend("TearingVars: ",str_t_1);
str = stringAppend(sr, st);
print(str);
print("\n");
dumpTearing(r,t);
then
();
end match;
end dumpTearing;
public function dumpBackendDAEEqnList
input list<BackendDAE.Equation> inBackendDAEEqnList;
input String header;
input Boolean printExpTree;
algorithm
print(header +& "\n");
dumpBackendDAEEqnList2(inBackendDAEEqnList,printExpTree);
print("===================\n");
end dumpBackendDAEEqnList;
protected function dumpBackendDAEEqnList2
input list<BackendDAE.Equation> inBackendDAEEqnList;
input Boolean printExpTree;
algorithm
_ := matchcontinue (inBackendDAEEqnList,printExpTree)
local
DAE.Exp e1_1,e2_1,e1,e2,e_1,e;
String str;
list<String> strList;
list<BackendDAE.Equation> res;
list<DAE.Exp> expList,expList2;
Integer i;
DAE.ElementSource source;
DAE.Algorithm alg;
case ({}, _) then ();
case (BackendDAE.EQUATION(e1, e2, source)::res, printExpTree) equation /*done*/
str = "EQUATION: ";
str = str +& ExpressionDump.printExpStr(e1);
str = str +& " = ";
str = str +& ExpressionDump.printExpStr(e2);
str = str +& "\n";
print(str);
str = "LHS:\n";
str = str +& ExpressionDump.dumpExpStr(e1, 0);
str = str +& "RHS:\n";
str = str +& ExpressionDump.dumpExpStr(e2, 0);
str = str +& "\n";
str = Util.if_(printExpTree, str, "");
print(str);
dumpBackendDAEEqnList2(res, printExpTree);
then ();
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source)::res, printExpTree) equation /*done*/
str = "COMPLEX_EQUATION: ";
str = str +& ExpressionDump.printExpStr(e1);
str = str +& " = ";
str = str +& ExpressionDump.printExpStr(e2);
str = str +& "\n";
print(str);
str = "LHS:\n";
str = str +& ExpressionDump.dumpExpStr(e1, 0);
str = str +& "RHS:\n";
str = str +& ExpressionDump.dumpExpStr(e2, 0);
str = str +& "\n";
str = Util.if_(printExpTree, str, "");
print(str);
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.SOLVED_EQUATION(_, e, source)::res,printExpTree) equation
print("SOLVED_EQUATION: ");
str = ExpressionDump.printExpStr(e);
print(str);
print("\n");
str = ExpressionDump.dumpExpStr(e,0);
str = Util.if_(printExpTree,str,"");
print(str);
print("\n");
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.RESIDUAL_EQUATION(e, source)::res, printExpTree) equation /*done*/
str = "RESIDUAL_EQUATION: ";
str = str +& ExpressionDump.printExpStr(e);
str = str +& "\n";
print(str);
str = ExpressionDump.dumpExpStr(e, 0);
str = str +& "\n";
str = Util.if_(printExpTree, str, "");
print(str);
dumpBackendDAEEqnList2(res, printExpTree);
then ();
case (BackendDAE.ARRAY_EQUATION(left=e1,right=e2,source=source)::res,printExpTree) equation
print("ARRAY_EQUATION: ");
str = ExpressionDump.printExpStr(e1);
print(str);
print("\n");
str = ExpressionDump.dumpExpStr(e1,0);
str = Util.if_(printExpTree,str,"");
print(str);
print("\n");
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.ALGORITHM(alg=alg,source=source)::res,printExpTree) equation
print("ALGORITHM: ");
dumpAlgorithms({alg},0);
print("\n");
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (BackendDAE.WHEN_EQUATION(whenEquation=BackendDAE.WHEN_EQ(right=e/*TODO handle elsewhe also*/),source=source)::res, printExpTree) equation
print("WHEN_EQUATION: ");
str = ExpressionDump.printExpStr(e);
print(str);
print("\n");
str = ExpressionDump.dumpExpStr(e,0);
str = Util.if_(printExpTree,str,"");
print(str);
print("\n");
dumpBackendDAEEqnList2(res,printExpTree);
then ();
case (_::res, printExpTree) equation
print("SKIPED EQUATION\n");
dumpBackendDAEEqnList2(res, printExpTree);
then ();
end matchcontinue;
end dumpBackendDAEEqnList2;
public function dumpBackendDAEVarList
input list<BackendDAE.Var> inBackendDAEVarList;
input String header;
algorithm
print(header +& "\n");
dumpVars(inBackendDAEVarList);
print("===================\n");
end dumpBackendDAEVarList;
public function dumpZcStr1 ""
input list<BackendDAE.ZeroCrossing> zero_crossings;
output String outString;
algorithm outString := match(zero_crossings)
local
BackendDAE.ZeroCrossing vf;
String s1,s2,s3;
list<BackendDAE.ZeroCrossing> rest;
case({}) then "";
case( vf::rest )
equation
s1= dumpZcStr(vf);
s2= dumpZcStr1(rest);
s3 = stringAppendList({s1,"\n", s2 });
then
s3;
end match;
end dumpZcStr1;
public function dumpZcStr
"function: dumpZcStr
Dumps a zerocrossing into a string, for debugging purposes."
input BackendDAE.ZeroCrossing inZeroCrossing;
output String outString;
algorithm
outString:=
match (inZeroCrossing)
local
list<String> eq_s_list,wc_s_list;
String eq_s,wc_s,str,str2,str_index;
DAE.Exp e;
Integer index_;
list<BackendDAE.Value> eq,wc;
case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.RELATION(index=index_),occurEquLst = eq,occurWhenLst = wc)
equation
eq_s_list = List.map(eq, intString);
eq_s = stringDelimitList(eq_s_list, ",");
wc_s_list = List.map(wc, intString);
wc_s = stringDelimitList(wc_s_list, ",");
str = ExpressionDump.printExpStr(e);
str_index=intString(index_);
str2 = stringAppendList({str," with index = ",str_index," in equations [",eq_s,"] and when conditions [",wc_s,"]"});
then
str2;
else then "";
end match;
end dumpZcStr;
public function dumpWcStr
"function: dumpWcStr
Dumps a whenclause into a string, for debugging purposes."
input BackendDAE.WhenClause inWhenClause;
output String outString;
algorithm
outString:=
match (inWhenClause)
local
String sc,s1,si,str;
DAE.Exp c;
list<BackendDAE.WhenOperator> reinitStmtLst;
Integer i;
case BackendDAE.WHEN_CLAUSE(condition = c,reinitStmtLst = reinitStmtLst,elseClause = SOME(i))
equation
sc = ExpressionDump.printExpStr(c);
s1 = stringDelimitList(List.map(reinitStmtLst,dumpWhenOperatorStr)," ");
si = intString(i);
str = stringAppendList({" whenclause = ",sc," then ",s1," else whenclause",si});
then
str;
case BackendDAE.WHEN_CLAUSE(condition = c,reinitStmtLst = reinitStmtLst,elseClause = NONE())
equation
sc = ExpressionDump.printExpStr(c);
s1 = stringDelimitList(List.map(reinitStmtLst,dumpWhenOperatorStr)," ");
str = stringAppendList({" whenclause = ",sc," then ",s1});
then
str;
else
then "";
end match;
end dumpWcStr;
public function dumpWhenOperatorStr
"function: dumpWhenOperatorStr
Dumps a WhenOperator into a string, for debugging purposes."
input BackendDAE.WhenOperator inWhenOperator;
output String outString;
algorithm
outString:=
match (inWhenOperator)
local
String scr,se,se1,str;
DAE.ComponentRef cr;
DAE.Exp e,e1;
case BackendDAE.REINIT(stateVar=cr,value=e)
equation
scr = ComponentReference.printComponentRefStr(cr);
se = ExpressionDump.printExpStr(e);
str = stringAppendList({"reinit(",scr,",",se,")"});
then
str;
case BackendDAE.ASSERT(condition=e,message=e1)
equation
se = ExpressionDump.printExpStr(e);
se1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({"assert(",se,",",se1,")"});
then
str;
case BackendDAE.TERMINATE(message=e)
equation
se = ExpressionDump.printExpStr(e);
str = stringAppendList({"terminate(",se,")"});
then
str;
end match;
end dumpWhenOperatorStr;
public function dump
"function: dump
This function dumps the BackendDAE.BackendDAE representaton to stdout."
input BackendDAE.BackendDAE inBackendDAE;
algorithm
_:=
match (inBackendDAE)
local
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
case (BackendDAE.DAE(eqs,shared))
equation
List.map_0(eqs,dumpEqSystem);
print("\n");
dumpShared(shared);
then
();
end match;
end dump;
public function dumpOption
replaceable type Type_A subtypeof Any;
input Option<Type_A> inType;
input printType_A infunc;
partial function printType_A
input Type_A inType;
end printType_A;
algorithm
_ :=
match(inType,infunc)
local
Type_A a;
case(SOME(a),infunc) equation infunc(a); then ();
else
then ();
end match;
end dumpOption;
public function dumpEqSystem
"function: dumpEqSystem
This function dumps the BackendDAE.EqSystem representaton to stdout."
input BackendDAE.EqSystem inEqSystem;
algorithm
_:=
match (inEqSystem)
local
list<BackendDAE.Var> vars;
Integer varlen,eqnlen,eqnssize;
String varlen_str,eqnlen_str;
list<BackendDAE.Equation> eqnsl;
BackendDAE.Variables vars1;
BackendDAE.EquationArray eqns;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrix> mT;
BackendDAE.Matching matching;
case (BackendDAE.EQSYSTEM(orderedVars=vars1,orderedEqs=eqns,m=m,mT=mT,matching=matching))
equation
print("Variables (");
vars = BackendDAEUtil.varList(vars1);
varlen = listLength(vars);
varlen_str = intString(varlen);
print(varlen_str);
print(")\n");
print("=========\n");
dumpVars(vars);
print("\n");
print("\nEquations (");
eqnsl = BackendDAEUtil.equationList(eqns);
eqnlen = listLength(eqnsl);
eqnlen_str = intString(eqnlen);
print(eqnlen_str);
eqnssize = BackendDAEUtil.equationSize(eqns);
print(", ");
print(intString(eqnssize));
print(")\n");
print("=========\n");
dumpEqns(eqnsl);
print("\n");
dumpOption(m,dumpIncidenceMatrix);
dumpOption(mT,dumpIncidenceMatrixT);
dumpFullMatching(matching);
then
();
case (BackendDAE.EQSYSTEM(orderedVars=vars1,orderedEqs=eqns))
equation
print("Variables (");
vars = BackendDAEUtil.varList(vars1);
varlen = listLength(vars);
varlen_str = intString(varlen);
print(varlen_str);
print(")\n");
print("=========\n");
dumpVars(vars);
print("\n");
print("\nEquations (");
eqnsl = BackendDAEUtil.equationList(eqns);
eqnlen = listLength(eqnsl);
eqnlen_str = intString(eqnlen);
print(eqnlen_str);
print(")\n");
print("=========\n");
dumpEqns(eqnsl);
print("\n");
then
();
end match;
end dumpEqSystem;
public function dumpShared
"function: dumpShared
This function dumps the BackendDAE.Shared representaton to stdout."
input BackendDAE.Shared inShared;
algorithm
_:=
match (inShared)
local
list<BackendDAE.Var> knvars,extvars;
BackendDAE.Value varlen,eqnlen;
String varlen_str,eqnlen_str,s;
list<BackendDAE.Equation> reqnsl,ieqnsl;
list<String> ss;
BackendDAE.Variables vars2,vars3,av;
BackendDAE.EquationArray reqns,ieqns;
array<DAE.Constraint> constrs;
list<BackendDAE.ZeroCrossing> zc;
list<BackendDAE.WhenClause> wc;
BackendDAE.ExternalObjectClasses extObjCls;
BackendDAE.BackendDAEType btp;
BackendDAE.SymbolicJacobians symjacs;
DAE.FunctionTree funcs;
case (BackendDAE.SHARED(knownVars=vars2,externalObjects=vars3,aliasVars=av,initialEqs=ieqns,removedEqs=reqns,constraints=constrs,
functionTree=funcs,eventInfo=BackendDAE.EVENT_INFO(zeroCrossingLst = zc,whenClauseLst=wc),extObjClasses=extObjCls,backendDAEType=btp,symjacs=symjacs))
equation
print("BackendDAEType: ");
dumpBackendDAEType(btp);
print("\n\n");
print("Known Variables (constants) (");
knvars = BackendDAEUtil.varList(vars2);
varlen = listLength(knvars);
varlen_str = intString(varlen);
print(varlen_str);
print(")\n");
print("=============================\n");
dumpVars(knvars);
print("External Objects (");
extvars = BackendDAEUtil.varList(vars3);
varlen = listLength(extvars);
varlen_str = intString(varlen);
print(varlen_str);
print(")\n");
print("=============================\n");
dumpVars(extvars);
print("Classes of External Objects (");
varlen = listLength(extObjCls);
varlen_str = intString(varlen);
print(varlen_str);
print(")\n");
print("=============================\n");
dumpExtObjCls(extObjCls);
dumpAliasVariables(av);
print("Simple Equations (");
reqnsl = BackendDAEUtil.equationList(reqns);
eqnlen = listLength(reqnsl);
eqnlen_str = intString(eqnlen);
print(eqnlen_str);
print(")\n");
print("=========\n");
dumpEqns(reqnsl);
print("Initial Equations (");
ieqnsl = BackendDAEUtil.equationList(ieqns);
eqnlen = listLength(ieqnsl);
eqnlen_str = intString(eqnlen);
print(eqnlen_str);
print(")\n");
print("=========\n");
dumpEqns(ieqnsl);
print("Zero Crossings :\n");
print("===============\n");
s = dumpZcStr1(zc);
print(s);
print("\n");
print("When Clauses :\n");
print("===============\n");
ss = List.map(wc, dumpWcStr);
s = stringDelimitList(ss, ",\n");
print(s);
print("\n");
print("Constraints:\n");
print("===============\n");
dumpConstraints(arrayList(constrs),0);
then
();
end match;
end dumpShared;
public function dumpBackendDAEType
input BackendDAE.BackendDAEType btp;
algorithm
_ := match(btp)
case (BackendDAE.SIMULATION())equation print("simulation"); then ();
case (BackendDAE.JACOBIAN()) equation print("jacobian"); then ();
case (BackendDAE.ALGEQSYSTEM()) equation print("algebraic loop"); then ();
case (BackendDAE.ARRAYSYSTEM()) equation print("multidim equation arrays"); then ();
case (BackendDAE.PARAMETERSYSTEM()) equation print("parameter system"); then ();
end match;
end dumpBackendDAEType;
public function dumpAlgorithms "Help function to dump, prints algorithms to stdout"
input list<DAE.Algorithm> ialgs;
input Integer indx;
algorithm
_ := match(ialgs,indx)
local
list<Algorithm.Statement> stmts;
IOStream.IOStream myStream;
String is;
list<DAE.Algorithm> algs;
case({},_) then ();
case(DAE.ALGORITHM_STMTS(stmts)::algs,indx)
equation
is = intString(indx);
myStream = IOStream.create("", IOStream.LIST());
myStream = IOStream.append(myStream,stringAppend(is,". "));
myStream = DAEDump.dumpAlgorithmStream(DAE.ALGORITHM(DAE.ALGORITHM_STMTS(stmts),DAE.emptyElementSource), myStream);
IOStream.print(myStream, IOStream.stdOutput);
dumpAlgorithms(algs,indx+1);
then ();
end match;
end dumpAlgorithms;
public function dumpConstraints "Help function to dump, prints constraints to stdout"
input list<DAE.Constraint> ionstrs;
input Integer indx;
algorithm
_ := match(ionstrs,indx)
local
list<DAE.Exp> exps;
IOStream.IOStream myStream;
String is;
list<DAE.Constraint> constrs;
case({},_) then ();
case(DAE.CONSTRAINT_EXPS(exps)::constrs,indx)
equation
is = intString(indx);
myStream = IOStream.create("", IOStream.LIST());
myStream = IOStream.append(myStream,stringAppend(is,". "));
myStream = DAEDump.dumpConstraintStream({DAE.CONSTRAINT(DAE.CONSTRAINT_EXPS(exps),DAE.emptyElementSource)}, myStream);
IOStream.print(myStream, IOStream.stdOutput);
dumpConstraints(constrs,indx+1);
then ();
end match;
end dumpConstraints;
public function dumpSparsePattern
"function: dumpSparsePattern
author: wbraun
description: function dumps sparse pattern of a Jacobain System."
input list<list<Integer>> inSparsePatter;
algorithm
print("Print sparse pattern: " +& intString(listLength(inSparsePatter)) +& "\n");
dumpSparsePattern2(inSparsePatter, 1);
print("\n");
end dumpSparsePattern;
public function dumpSparsePattern2
"function: dumpSparsePattern
author: wbraun
description: help function to dumpSparsePattern."
input list<list<Integer>> inSparsePatter;
input Integer inInteger;
algorithm
_ := match(inSparsePatter, inInteger)
local
list<list<Integer>> rest;
list<Integer> elem;
String sparsepatternStr;
case({},inInteger) then ();
case(elem::rest,inInteger)
equation
sparsepatternStr = List.toString(elem, intString,"Row[" +& intString(inInteger) +& "] = ","{",";","}",true);
print(sparsepatternStr +& "\n");
dumpSparsePattern2(rest,inInteger+1);
then ();
end match;
end dumpSparsePattern2;
public function dumpJacobianStr
"function: dumpJacobianStr
Dumps the sparse jacobian.
Uses the variables to determine size of Jacobian matrix."
input Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> inTplIntegerIntegerEquationLstOption;
output String outString;
algorithm
outString:=
match (inTplIntegerIntegerEquationLstOption)
local
list<String> res;
String res_1;
list<tuple<BackendDAE.Value, BackendDAE.Value, BackendDAE.Equation>> eqns;
case (SOME(eqns))
equation
res = dumpJacobianStr2(eqns);
res_1 = stringDelimitList(res, ",\n");
then
res_1;
case (NONE()) then "No analytic jacobian available\n";
end match;
end dumpJacobianStr;
protected function dumpJacobianStr2
"function: dumpJacobianStr2
Helper function to dumpJacobianStr"
input list<tuple<Integer, Integer, BackendDAE.Equation>> inTplIntegerIntegerEquationLst;
output list<String> outStringLst;
algorithm
outStringLst:=
match (inTplIntegerIntegerEquationLst)
local
String estr,rowstr,colstr,str;
list<String> strs;
BackendDAE.Value row,col;
DAE.Exp e;
list<tuple<BackendDAE.Value, BackendDAE.Value, BackendDAE.Equation>> eqns;
case ({}) then {};
case (((row,col,BackendDAE.RESIDUAL_EQUATION(exp = e)) :: eqns))
equation
estr = ExpressionDump.printExpStr(e);
rowstr = intString(row);
colstr = intString(col);
str = stringAppendList({"{",rowstr,",",colstr,"}:",estr});
strs = dumpJacobianStr2(eqns);
then
(str :: strs);
end match;
end dumpJacobianStr2;
public function jacobianTypeStr "function: jacobianTypeStr
author: PA
Returns the jacobian type as a string, used for debugging."
input BackendDAE.JacobianType inJacobianType;
output String outString;
algorithm
outString := match (inJacobianType)
case BackendDAE.JAC_CONSTANT() then "Jacobian Constant";
case BackendDAE.JAC_TIME_VARYING() then "Jacobian Time varying";
case BackendDAE.JAC_NONLINEAR() then "Jacobian Nonlinear";
case BackendDAE.JAC_NO_ANALYTIC() then "No analytic jacobian";
end match;
end jacobianTypeStr;
public function dumpEqnsSolved
"function: dumpEqnsSolved
This function dumps the equations in the order they have to be calculate."
input BackendDAE.BackendDAE inBackendDAE;
algorithm
_:=
match (inBackendDAE)
local
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;
case (BackendDAE.DAE(eqs,shared))
equation
List.map1_0(eqs,dumpEqnsSolved1,shared);
then
();
end match;
end dumpEqnsSolved;
protected function dumpEqnsSolved1
"function: dumpEqnsSolved1."
input BackendDAE.EqSystem inEqSystem;
input BackendDAE.Shared inShared;
algorithm
_:=
match (inEqSystem,inShared)
local
BackendDAE.EquationArray eqns;
BackendDAE.Variables vars;
BackendDAE.StrongComponents comps;
case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,matching=BackendDAE.MATCHING(_,_,comps)),_)
equation
dumpEqnsSolved2(comps,eqns,vars);
then
();
else
equation
print("No Matching\n");
then
();
end match;
end dumpEqnsSolved1;
protected function dumpEqnsSolved2
" function: dumpEqnsSolved2
autor: Frenkel TUD 2012-03"
input BackendDAE.StrongComponents inComps;
input BackendDAE.EquationArray eqns;
input BackendDAE.Variables vars;
algorithm
_ :=
matchcontinue (inComps,eqns,vars)
local
Integer e,v;
list<Integer> elst,vlst,vlst1,elst1;
BackendDAE.StrongComponent comp;
BackendDAE.StrongComponents rest;
BackendDAE.Var var;
BackendDAE.Equation eqn;
list<BackendDAE.Var> varlst;
list<BackendDAE.Equation> eqnlst;
BackendDAE.JacobianType jacType;
list<tuple<Integer,list<Integer>>> eqnsvartpllst;
Boolean b;
String s;
case ({},_,_) then ();
case (BackendDAE.SINGLEEQUATION(eqn=e,var=v)::rest,_,_)
equation
print("SingleEquation: " +& intString(e) +& "\n");
var = BackendVariable.getVarAt(vars,v);
dumpVars({var});
eqn = BackendDAEUtil.equationNth(eqns,e-1);
dumpEqns({eqn});
dumpEqnsSolved2(rest,eqns,vars);
then
();
case (BackendDAE.MIXEDEQUATIONSYSTEM(condSystem=comp,disc_eqns=elst,disc_vars=vlst)::rest,_,_)
equation
print("Mixed EquationSystem:\n");
varlst = List.map1r(vlst, BackendVariable.getVarAt, vars);
dumpVars(varlst);