This repository was archived by the owner on May 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathHpcOmTaskGraph.mo
More file actions
7018 lines (6633 loc) · 306 KB
/
HpcOmTaskGraph.mo
File metadata and controls
7018 lines (6633 loc) · 306 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package HpcOmTaskGraph
" file: HpcOmTaskGraph.mo
package: HpcOmTaskGraph
description: HpcOmTaskGraph contains the whole logic to create a TaskGraph on BLT-Level
"
public import BackendDAE;
public import DAE;
public import GraphML;
protected
import AdjacencyMatrix;
import Array;
import BackendDAEOptimize;
import BackendDAEUtil;
import BackendDump;
import BackendEquation;
import BackendVariable;
import ComponentReference;
import DAEDump;
import Error;
import ExpandableArray;
import Expression;
import Flags;
import HpcOmBenchmark;
import HpcOmScheduler;
import List;
import SCode;
import SimCodeUtil;
import SimCodeVar;
import System;
import Util;
//----------------------------
// Graph Structure
//----------------------------
public type TaskGraph = array<list<Integer>>;
public type Communications = list<Communication>;
public uniontype Communication
record COMMUNICATION
//Variables that have to be transmitted
Integer numberOfVars; //sum of {numOfIntegers,numOfFloats,numOfBoolean, numOfStrings}
list<Integer> integerVars;
list<Integer> floatVars;
list<Integer> booleanVars;
list<Integer> stringVars;
//Other values
Integer childNode;
Real requiredTime;
end COMMUNICATION;
end Communication;
public uniontype ComponentInfo
record COMPONENTINFO
Boolean isPartOfODESystem; // true if the component belongs to the ode system
Boolean isPartOfZeroFuncSystem; // true if the component belongs to the event system
Boolean isRemovedComponent; // true if the component was added via appendRemovedEquations (e.g. it is a assert)
end COMPONENTINFO;
end ComponentInfo;
// TODO: Store compParamMapping, compNames and compDescs in ComponentInfo
// TODO: Change nodeMark to compMarks
public uniontype TaskGraphMeta // stores all the metadata for the TaskGraph
record TASKGRAPHMETA
array<list<Integer>> inComps; // all StrongComponents from the BLT that belong to the Nodes [nodeId = arrayIdx]
array<tuple<Integer,Integer,Integer>> varCompMapping; // maps each variable to <compIdx, eqSystemIdx, offset>. The offset is the sum of the varNumber of all eqSystems with a minor index.
array<tuple<Integer,Integer,Integer>> eqCompMapping; // maps each equation to <compIdx, eqSystemIdx, offset>. The offset is the sum of the eqNumber of all eqSystems with a minor index.
array<list<Integer>> compParamMapping; // maps each scc to a list of parameters that are required for calculation. The indices are related to the known-parameter object of SHARED.
array<String> compNames; // the name of the components (e.g. '{18:7}')
array<String> compDescs; // a description of the components (e.g. 'R5.R * R5.i = C2.vinternal FOR R5.i')
array<tuple<Integer,Real>> exeCosts; // the execution cost for the components <numberOfOperations, requiredCycles>
array<Communications> commCosts; // the communication cost tuple(_,numberOfVars,requiredCycles) for an edge from array[parentSCC] to tuple(childSCC,_,_)
array<Integer> nodeMark; // used for level informations -> this is currently not a nodeMark, its a componentMark
array<ComponentInfo> compInformations; // used to store additional informations about the components
end TASKGRAPHMETA;
end TaskGraphMeta;
//----------------------------------------------------------
// Functions to build the task graph from the BLT structure
//----------------------------------------------------------
public function createTaskGraph "author: marcusw, waurich
Creates a task graph on scc-level."
input BackendDAE.BackendDAE iDAE;
input Boolean iAnalyzeParameters = false; //set this to true if the parameter information of task graph meta should be filled
output TaskGraph oGraph;
output TaskGraphMeta oGraphData;
protected
list<BackendDAE.EqSystem> systs;
BackendDAE.Shared shared;
TaskGraph graph;
TaskGraphMeta graphData;
algorithm
//Iterate over each system
BackendDAE.DAE(systs,shared) := iDAE;
(graph,graphData) := getEmptyTaskGraph(0,0,0);
((oGraph,oGraphData,_)) := List.fold(systs, function createTaskGraph0(iShared=shared, iAnalyzeParameters=iAnalyzeParameters), (graph,graphData,1));
end createTaskGraph;
public function createTaskGraph0 "author: marcusw, waurich
Creates a task graph out of the given system."
input BackendDAE.EqSystem iSyst; //The input system which should be analysed
input BackendDAE.Shared iShared;
input Boolean iAnalyzeParameters;
input tuple<TaskGraph,TaskGraphMeta,Integer> iGraphInfo; //<_,_,eqSysIdx>
output tuple<TaskGraph,TaskGraphMeta,Integer> oGrapInfo;
protected
BackendDAE.StrongComponents comps;
BackendDAE.Variables vars;
BackendDAE.EquationArray orderedEqs;
DAE.FunctionTree sharedFuncs;
TaskGraphMeta iGraphData;
TaskGraphMeta tmpGraphData;
TaskGraph iGraph;
TaskGraph tmpGraph;
array<Communications> commCosts;
array<list<Integer>> inComps;
array<list<Integer>> compParamMapping;
array<tuple<Integer,Real>> exeCosts;
array<Integer> nodeMark;
array<tuple<Integer,Integer,Integer>> varCompMapping, eqCompMapping; //Map each variable to the scc that solves her
array<String> compNames;
array<String> compDescs;
list<Integer> eventEqLst, eventVarLst, rootVars;
Integer numberOfVars;
array<ComponentInfo> compInformations;
Integer eqSysIdx;
tuple<TaskGraph,TaskGraphMeta,Integer> tplOut;
BackendDAE.EqSystem syst;
BackendDAE.Matching matching;
BackendDAE.IncidenceMatrix incidenceMatrix;
algorithm
BackendDAE.EQSYSTEM(matching=matching, orderedVars=vars, orderedEqs=orderedEqs) := iSyst;
comps := BackendDAEUtil.getCompsOfMatching(matching);
BackendDAE.SHARED(functionTree=sharedFuncs) := iShared;
(iGraph,iGraphData,eqSysIdx) := iGraphInfo;
(_,incidenceMatrix,_) := BackendDAEUtil.getIncidenceMatrix(iSyst, BackendDAE.NORMAL(), SOME(sharedFuncs));
numberOfVars := BackendVariable.varsSize(vars);
(tmpGraph,tmpGraphData) := getEmptyTaskGraph(listLength(comps), numberOfVars, ExpandableArray.getNumberOfElements(orderedEqs));
TASKGRAPHMETA(inComps=inComps, compNames=compNames, exeCosts=exeCosts, commCosts=commCosts, nodeMark=nodeMark, varCompMapping=varCompMapping, eqCompMapping=eqCompMapping, compParamMapping=compParamMapping, compInformations=compInformations) := tmpGraphData;
//print("createTaskGraph0 try to get varCompMapping\n");
(varCompMapping,eqCompMapping) := getVarEqCompMapping(comps, eqSysIdx, 0, 0, varCompMapping, eqCompMapping);
//print("createTaskGraph0 varCompMapping created\n");
compDescs := getEquationStrings(comps,iSyst); //gets the description i.e. the whole equation, for every component
((tmpGraph,inComps,compParamMapping,commCosts,compNames,nodeMark,_)) := List.fold(comps, function createTaskGraph1(iSystInfo=(incidenceMatrix,iSyst,iShared,listLength(comps)),iVarInfo=(varCompMapping,eqCompMapping,{}),iAnalyzeParameters=iAnalyzeParameters),(tmpGraph,inComps,compParamMapping,commCosts,compNames,nodeMark,1));
// gather the metadata
tmpGraphData := TASKGRAPHMETA(inComps, varCompMapping, eqCompMapping, compParamMapping, compNames, compDescs, exeCosts, commCosts, nodeMark, compInformations);
if(intGt(eqSysIdx,1)) then
(tmpGraph,tmpGraphData) := taskGraphAppend(iGraph,iGraphData,tmpGraph,tmpGraphData);
end if;
oGrapInfo := ((tmpGraph,tmpGraphData,eqSysIdx+1));
end createTaskGraph0;
public function getSystemComponents "author: marcusw
Returns all components of the given BackendDAE."
input BackendDAE.BackendDAE iDae;
output BackendDAE.StrongComponents oComps;
output array<tuple<BackendDAE.EqSystem, Integer>> oMapping; //Map each component to <eqSystem, eqSystemIdx>
protected
BackendDAE.EqSystems systs;
List<tuple<BackendDAE.EqSystem,Integer>> tmpSystems;
BackendDAE.StrongComponents tmpComps;
algorithm
(oComps,oMapping) := match(iDae)
case(BackendDAE.DAE(eqs=systs))
equation
((tmpComps, tmpSystems,_)) = List.fold(systs,getSystemComponents0,({},{},1));
then (tmpComps,listArray(tmpSystems));
else fail();
end match;
end getSystemComponents;
protected function getSystemComponents0 "author: marcusw
Adds the information for the given EqSystem to the system mapping structure."
input BackendDAE.EqSystem iSyst;
input tuple<BackendDAE.StrongComponents, list<tuple<BackendDAE.EqSystem,Integer>>, Integer> iSystMapping; //last Integer is idx of isyst
output tuple<BackendDAE.StrongComponents, list<tuple<BackendDAE.EqSystem,Integer>>, Integer> oSystMapping; //Map each component to <eqSystem, eqSystemIdx>
protected
BackendDAE.StrongComponents tmpComps, comps;
BackendDAE.Matching matching;
list<tuple<BackendDAE.EqSystem,Integer>> tmpSystMapping;
Integer currentIdx;
algorithm
oSystMapping := match(iSyst, iSystMapping)
case(BackendDAE.EQSYSTEM(matching=matching), (tmpComps,tmpSystMapping,currentIdx))
equation
comps = BackendDAEUtil.getCompsOfMatching(matching);
//print("--getSystemComponents0 begin\n");
tmpSystMapping = List.fold2(comps, getSystemComponents1, iSyst, currentIdx, tmpSystMapping);
//print(stringDelimitList(List.map(comps, BackendDump.printComponent),","));
tmpComps = listAppend(tmpComps,comps);
//print("--getSystemComponents0 end (found " + intString(listLength(comps)) + " components in system " + intString(currentIdx) + ")\n");
then ((tmpComps, tmpSystMapping, currentIdx+1));
else
equation
print("getSystemComponents0 failed\n");
then fail();
end match;
end getSystemComponents0;
protected function getSystemComponents1 "author: marcusw
Extends the mapping information for the given component and equation system."
input BackendDAE.StrongComponent icomp;
input BackendDAE.EqSystem isyst;
input Integer isystIdx;
input list<tuple<BackendDAE.EqSystem,Integer>> iMapping; //Map each component to the EqSystem
output list<tuple<BackendDAE.EqSystem,Integer>> oMapping; //Map each component to the EqSystem
algorithm
oMapping := listAppend(iMapping,{(isyst,isystIdx)});
end getSystemComponents1;
protected function getNumberOfSystemComponents "author: marcusw
Returns the number of components stored in the BackendDAE."
input BackendDAE.BackendDAE iDae;
output Integer oNumOfComps;
protected
BackendDAE.EqSystems eqs;
algorithm
BackendDAE.DAE(eqs=eqs) := iDae;
oNumOfComps := List.fold(eqs, getNumberOfEqSystemComponents, 0);
end getNumberOfSystemComponents;
protected function getNumberOfEqSystemComponents "author: marcusw
Adds the number of components in the given eqSystem to the iNumOfComps."
input BackendDAE.EqSystem iEqSystem;
input Integer iNumOfComps;
output Integer oNumOfComps;
protected
BackendDAE.StrongComponents comps;
BackendDAE.Matching matching;
algorithm
BackendDAE.EQSYSTEM(matching=matching) := iEqSystem;
comps := BackendDAEUtil.getCompsOfMatching(matching);
oNumOfComps := iNumOfComps + listLength(comps);
end getNumberOfEqSystemComponents;
public function getEmptyTaskGraph "author: Waurich TUD 2013-06
generates an empty TaskGraph and empty TaskGraphMeta for a graph with numComps nodes."
input Integer numComps;
input Integer numVars;
input Integer numEqs;
output TaskGraph graph;
output TaskGraphMeta graphData;
protected
array<list<Integer>> inComps;
array<tuple<Integer,Integer,Integer>> varCompMapping;
array<tuple<Integer,Integer,Integer>> eqCompMapping;
array<String> compNames;
array<String> compDescs;
array<tuple<Integer,Real>> exeCosts;
array<Communications> commCosts;
array<list<Integer>> compParamMapping;
array<Integer> nodeMark;
array<ComponentInfo> compInformations;
algorithm
graph := arrayCreate(numComps,{});
inComps := arrayCreate(numComps,{});
compParamMapping := arrayCreate(numComps,{});
varCompMapping := arrayCreate(numVars,(0,0,0));
eqCompMapping := arrayCreate(numEqs,(0,0,0));
compNames := arrayCreate(numComps,"");
compDescs := arrayCreate(numComps,"");
exeCosts := arrayCreate(numComps,(-1,-1.0));
commCosts := arrayCreate(numComps,{});
nodeMark := arrayCreate(numComps,0);
compInformations := arrayCreate(numComps, COMPONENTINFO(false,false,false));
graphData := TASKGRAPHMETA(inComps,varCompMapping,eqCompMapping,compParamMapping,compNames,compDescs,exeCosts,commCosts,nodeMark,compInformations);
end getEmptyTaskGraph;
public function copyTaskGraphMeta "author: Waurich TUD 2013-07
Copies the metadata to avoid overwriting the arrays."
input TaskGraphMeta graphDataIn;
output TaskGraphMeta graphDataOut;
protected
array<list<Integer>> inComps, inComps1;
array<tuple<Integer, Integer, Integer>> varCompMapping, varCompMapping1;
array<tuple<Integer,Integer,Integer>> eqCompMapping, eqCompMapping1;
array<list<Integer>> compParamMapping, compParamMapping1;
array<String> compNames, compNames1;
array<String> compDescs, compDescs1;
array<tuple<Integer,Real>> exeCosts, exeCosts1;
array<Communications> commCosts, commCosts1;
array<Integer>nodeMark, nodeMark1;
array<ComponentInfo> compInformations, compInformations1;
algorithm
TASKGRAPHMETA(inComps=inComps, varCompMapping=varCompMapping, eqCompMapping=eqCompMapping, compParamMapping=compParamMapping, compNames=compNames, compDescs=compDescs, exeCosts=exeCosts, commCosts=commCosts, nodeMark=nodeMark, compInformations=compInformations) := graphDataIn;
inComps1 := arrayCopy(inComps);
varCompMapping1 := arrayCopy(varCompMapping);
eqCompMapping1 := arrayCopy(eqCompMapping);
compParamMapping1 := arrayCopy(compParamMapping);
compNames1 := arrayCopy(compNames);
compDescs1 := arrayCopy(compDescs);
exeCosts1 := arrayCopy(exeCosts);
commCosts1 := arrayCopy(commCosts);
nodeMark1 := arrayCopy(nodeMark);
compInformations1 := arrayCopy(compInformations);
graphDataOut := TASKGRAPHMETA(inComps1,varCompMapping1,eqCompMapping1,compParamMapping1,compNames1,compDescs1,exeCosts1,commCosts1,nodeMark1,compInformations1);
end copyTaskGraphMeta;
protected function taskGraphAppend "author:Waurich TUD 2013-06
Appends a taskGraph system to an other taskGraph system.all indices will be numbered continuously."
input TaskGraph graph1In;
input TaskGraphMeta graphData1In;
input TaskGraph graph2In;
input TaskGraphMeta graphData2In;
output TaskGraph graphOut;
output TaskGraphMeta graphDataOut;
protected
Integer eqOffset;
Integer idxOffset;
Integer varOffset;
array<Communications> commCosts1, commCosts2;
array<list<Integer>> inComps1, inComps2;
array<tuple<Integer,Integer,Integer>> eqCompMapping1, eqCompMapping2;
array<tuple<Integer,Real>> exeCosts1, exeCosts2;
array<Integer> nodeMark1, nodeMark2;
array<list<Integer>> compParamMapping1, compParamMapping2;
array<tuple<Integer,Integer,Integer>> varCompMapping1, varCompMapping2; //Map each variable to the scc which solves her
array<String> compNames1, compNames2;
array<String> compDescs1, compDescs2;
array<ComponentInfo> compInformations1, compInformations2;
TaskGraph graph2;
algorithm
TASKGRAPHMETA(inComps = inComps1 ,varCompMapping=varCompMapping1, eqCompMapping=eqCompMapping1, compParamMapping=compParamMapping1, compNames=compNames1, compDescs=compDescs1, exeCosts=exeCosts1, commCosts=commCosts1, nodeMark=nodeMark1, compInformations=compInformations1) := graphData1In;
TASKGRAPHMETA(inComps = inComps2 ,varCompMapping=varCompMapping2, eqCompMapping=eqCompMapping2, compParamMapping=compParamMapping2, compNames=compNames2, compDescs=compDescs2, exeCosts=exeCosts2, commCosts=commCosts2, nodeMark=nodeMark2, compInformations=compInformations2) := graphData2In;
eqOffset := arrayLength(eqCompMapping1);
idxOffset := arrayLength(graph1In);
varOffset := arrayLength(varCompMapping1);
eqOffset := arrayLength(eqCompMapping1);
graph2 := Array.map1(graph2In,updateTaskGraphSystem,idxOffset);
graphOut := arrayAppend(graph1In,graph2);
inComps2 := Array.map1(inComps2,updateTaskGraphSystem,idxOffset);
inComps2 := arrayAppend(inComps1,inComps2);
//varCompMapping2 := Array.map1(varCompMapping2,modifyMapping,varOffset);
varCompMapping2 := Array.map1(varCompMapping2,modifyMapping,idxOffset);
varCompMapping2 := arrayAppend(varCompMapping1,varCompMapping2);
//eqCompMapping2 := Array.map1(eqCompMapping2,modifyMapping,eqOffset);
eqCompMapping2 := Array.map1(eqCompMapping2,modifyMapping,idxOffset);
eqCompMapping2 := arrayAppend(eqCompMapping1,eqCompMapping2);
compParamMapping2 := arrayAppend(compParamMapping1,compParamMapping2);
compNames2 := Array.map1(compNames2,stringAppend," subsys"); //TODO: change this
compNames2 := arrayAppend(compNames1,compNames2);
compDescs2 := arrayAppend(compDescs1,compDescs2);
exeCosts2 := arrayAppend(exeCosts1,exeCosts2);
commCosts2 := Array.map1(commCosts2,updateCommCosts,idxOffset);
commCosts2 := arrayAppend(commCosts1,commCosts2);
nodeMark2 := arrayAppend(nodeMark1,nodeMark2);
compInformations2 := arrayAppend(compInformations1, compInformations2);
graphDataOut := TASKGRAPHMETA(inComps2,varCompMapping2,eqCompMapping2,compParamMapping2,compNames2,compDescs2,exeCosts2,commCosts2,nodeMark2,compInformations2);
end taskGraphAppend;
protected function modifyMapping "author: marcusw, waurich
Adds the given offset to the first and last tuple-element."
input tuple<Integer,Integer,Integer> iMappingTuple;
input Integer iOffset;
output tuple<Integer,Integer,Integer> oMappingTuple;
protected
Integer i1,i2,i3; //i1 = offset
algorithm
(i1,i2,i3) := iMappingTuple;
oMappingTuple := (i1+iOffset,i2,iOffset);
end modifyMapping;
protected function updateCommCosts "author: Waurich TUD 2013-07
updates the CommCosts to the enumerated indeces."
input Communications commCostsIn;
input Integer idxOffset;
output Communications commCostsOut;
algorithm
commCostsOut := List.map1(commCostsIn,updateCommCosts1,idxOffset);
end updateCommCosts;
protected function updateCommCosts1 "author: Waurich TUD 2013-07
Adds the idxOffset to the child node index."
input Communication commCostsIn;
input Integer idxOffset;
output Communication commCostsOut;
protected
Integer numberOfVars, childNode;
list<Integer> integerVars,floatVars,booleanVars,stringVars;
Real requiredTime;
algorithm
COMMUNICATION(numberOfVars=numberOfVars,integerVars=integerVars,floatVars=floatVars,booleanVars=booleanVars,stringVars=stringVars,childNode=childNode,requiredTime=requiredTime) := commCostsIn;
childNode := childNode+idxOffset;
commCostsOut := COMMUNICATION(numberOfVars,integerVars,floatVars,booleanVars,stringVars,childNode,requiredTime);
end updateCommCosts1;
protected function updateTaskGraphSystem "author: Waurich TUD 2013-07
map function to add the indices in the taskGraph system to the number of nodes of the previous system."
input list<Integer> graphRowIn;
input Integer idxOffset;
output list<Integer> graphRowOut;
algorithm
graphRowOut := List.map1(graphRowIn,intAdd,idxOffset);
end updateTaskGraphSystem;
protected function createTaskGraph1 "author: marcusw, waurich
Appends the task-graph information for the given StrongComponent to the given graph."
input BackendDAE.StrongComponent iComponent;
input tuple<BackendDAE.IncidenceMatrix,BackendDAE.EqSystem,BackendDAE.Shared,Integer> iSystInfo; //<incidenceMatrix,isyst,iShared,numberOfComponents> in very compact form
input tuple<array<tuple<Integer,Integer,Integer>>,array<tuple<Integer,Integer,Integer>>,list<Integer>> iVarInfo; //<varCompMapping,eqCompMapping,eventVarLst
input Boolean iAnalyzeParameters;
input tuple<TaskGraph,array<list<Integer>>,array<list<Integer>>,array<Communications>,array<String>,array<Integer>,Integer> graphInfoIn;
//<taskGraph,inComps,compParamMapping,commCosts,compNames,nodeMark,componentIndex>
output tuple<TaskGraph,array<list<Integer>>,array<list<Integer>>,array<Communications>,array<String>,array<Integer>,Integer> graphInfoOut;
protected
BackendDAE.IncidenceMatrix incidenceMatrix;
BackendDAE.EqSystem isyst;
BackendDAE.Shared ishared;
BackendDAE.Variables orderedVars;
BackendDAE.Variables globalKnownVars, localKnownVars;
BackendDAE.EquationArray orderedEqs;
TaskGraph graphIn;
TaskGraph graphTmp;
array<list<Integer>> inComps;
array<tuple<Integer,Integer,Integer>> varCompMapping; //<sccIdx, eqSysIdx, offset>
array<tuple<Integer,Integer,Integer>> eqCompMapping; //<sccIdx, eqSysIdx, offset>
array<String> compNames;
array<String> compDescs;
array<Communications> commCosts;
Communications commCostsOfNode;
array<Integer> nodeMark;
tuple<list<Integer>, list<tuple<Integer, Integer>>, list<Integer>, list<Integer>> unsolvedVars; //<intVarIdc, <floatVarIdx, [0 if derived, 1 if not]>, boolVarIdc,stringVarIdc>
list<Integer> eventVarLst;
array<tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>>> requiredSccs; //required variables <int, float, bool, string>
Integer componentIndex, numberOfComps;
list<tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>>> requiredSccs_RefCount; //<sccIdx, refCountInt, refCountFloat, refCountBool, refCountString>
String compName;
list<Integer> paramVars;
array<list<Integer>> compParamMapping;
algorithm
(incidenceMatrix,isyst,ishared,numberOfComps) := iSystInfo;
BackendDAE.SHARED(globalKnownVars=globalKnownVars, localKnownVars=localKnownVars) := ishared;
BackendDAE.EQSYSTEM(orderedVars=orderedVars,orderedEqs=orderedEqs) := isyst;
(varCompMapping,eqCompMapping,eventVarLst) := iVarInfo;
(graphIn,inComps,compParamMapping,commCosts,compNames,nodeMark,componentIndex) := graphInfoIn;
inComps := arrayUpdate(inComps,componentIndex,{componentIndex});
compName := BackendDump.strongComponentString(iComponent);
compNames := arrayUpdate(compNames,componentIndex,compName);
_ := HpcOmBenchmark.benchSystem();
(unsolvedVars,paramVars) := getUnsolvedVarsBySCC(iComponent,incidenceMatrix,orderedVars,BackendVariable.addVariables(globalKnownVars,localKnownVars),orderedEqs,eventVarLst,iAnalyzeParameters);
compParamMapping := arrayUpdate(compParamMapping, componentIndex, paramVars);
requiredSccs := arrayCreate(numberOfComps,({},{},{},{})); //create a ref-counter for each component
requiredSccs := List.fold2(List.map1(Util.tuple41(unsolvedVars),Util.makeTuple,1),fillSccList,1,varCompMapping,requiredSccs);
requiredSccs := List.fold2(Util.tuple42(unsolvedVars),fillSccList,2,varCompMapping,requiredSccs);
requiredSccs := List.fold2(List.map1(Util.tuple43(unsolvedVars),Util.makeTuple,1),fillSccList,3,varCompMapping,requiredSccs);
requiredSccs := List.fold2(List.map1(Util.tuple44(unsolvedVars),Util.makeTuple,1),fillSccList,4,varCompMapping,requiredSccs);
((_,requiredSccs_RefCount)) := Array.fold(requiredSccs, convertRefArrayToList, (1,{}));
(commCosts,commCostsOfNode) := updateCommCostBySccRef(requiredSccs_RefCount, componentIndex, commCosts);
graphTmp := fillAdjacencyList(graphIn,componentIndex,commCostsOfNode,1);
graphTmp := Array.map1(graphTmp,List.sort,intGt);
graphInfoOut := (graphTmp,inComps,compParamMapping,commCosts,compNames,nodeMark,componentIndex+1);
end createTaskGraph1;
protected function updateCommCostBySccRef "author: marcusw
Updates the given commCosts-array with the values of the refCount-list."
input list<tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>>> requiredSccs_RefCount; //<sccIdx,refCountInt,refCountFloat,refCountBool,refCountString>
input Integer nodeIdx;
input array<Communications> iCommCosts;
output array<Communications> oCommCosts;
//the communications, created for the given node (nodeIdx) - the required time is set to -1.0, the childNode-idx is set the the parent-idx of the ref counter!
output Communications oNodeComms;
protected
Communications tmpComms;
algorithm
tmpComms := List.map1(requiredSccs_RefCount, createCommunicationObject, -1.0);
oCommCosts := List.fold1(tmpComms,updateCommCostBySccRef1,nodeIdx,iCommCosts);
oNodeComms := tmpComms;
end updateCommCostBySccRef;
protected function createCommunicationObject "author: marcusw
Helper function which converts a tuple<sccIdx,refCountInt,refCountFloat,refCountBool> to a Communictaion-object."
input tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>> iTuple;
input Real requiredTime;
output Communication oComm;
protected
list<Integer> integerVars,floatVars,booleanVars,stringVars;
Integer sccIdx,refCountSum;
algorithm
(sccIdx,integerVars,floatVars,booleanVars,stringVars) := iTuple;
refCountSum := listLength(integerVars) + listLength(floatVars) + listLength(booleanVars) + listLength(stringVars);
oComm := COMMUNICATION(refCountSum,integerVars,floatVars,booleanVars,stringVars,sccIdx,requiredTime);
end createCommunicationObject;
protected function updateCommCostBySccRef1 "author: marcusw
Helper function which appends an edge from source to target with the given parameters."
input Communication iEdgeSource;
input Integer iEdgeTarget; //sccIdx
input array<Communications> iCommCosts; //<sccIdx,numberOfVars,requiredCycles>
output array<Communications> oCommCosts;
protected
Communications oldComms;
Integer sourceSccIdx;
list<Integer> integerVars,floatVars,booleanVars,stringVars;
Integer numberOfVars;
Real requiredTime;
Communication tmpComm;
algorithm
COMMUNICATION(numberOfVars=numberOfVars,integerVars=integerVars,floatVars=floatVars,booleanVars=booleanVars,stringVars=stringVars,childNode=sourceSccIdx,requiredTime=requiredTime) := iEdgeSource;
oldComms := arrayGet(iCommCosts, sourceSccIdx);
//print("updateCommCostBySccRef1 added edge from " + intString(sourceSccIdx) + " to " + intString(iEdgeTarget) + "\n");
tmpComm := COMMUNICATION(numberOfVars,integerVars,floatVars,booleanVars,stringVars,iEdgeTarget,requiredTime);
oCommCosts := arrayUpdate(iCommCosts, sourceSccIdx, tmpComm::oldComms);
end updateCommCostBySccRef1;
protected function fillAdjacencyList "author: waurich TUD 2013-06
Append the child index to the rows indexed by the parent list."
input array<list<Integer>> adjLstIn;
input Integer childNode;
input Communications parentLst; //Communication-objects, with childNode = parentNodeIdx
input Integer Idx; //current parent, starting with 1
output array<list<Integer>> adjLstOut;
algorithm
adjLstOut := matchcontinue(adjLstIn,childNode,parentLst,Idx)
local
Communication parentNode;
list<Integer> parentRow;
array<list<Integer>> adjLst;
Integer parentNodeIdx;
case(_,_,_,_)
equation
true = listLength(parentLst) >= Idx;
parentNode = listGet(parentLst,Idx);
COMMUNICATION(childNode=parentNodeIdx) = parentNode;
parentRow = arrayGet(adjLstIn,parentNodeIdx);
parentRow = childNode::parentRow;
parentRow = List.removeOnTrue(parentNodeIdx,intEq,parentRow); // deletes the self-loops
adjLst = arrayUpdate(adjLstIn,parentNodeIdx,parentRow);
adjLst = fillAdjacencyList(adjLst,childNode,parentLst,Idx+1);
then
adjLst;
else adjLstIn;
end matchcontinue;
end fillAdjacencyList;
protected function getEquationStrings "author: Waurich TUD 2013-06
Gets the equation and the variable its solved for for every StrongComponent. index = component. entry = description"
input BackendDAE.StrongComponents iComps;
input BackendDAE.EqSystem iEqSystem;
output array<String> eqDescsOut;
protected
list<String> eqDescs;
algorithm
eqDescs := List.fold1(iComps,getEquationStrings2,iEqSystem,{});
eqDescs := listReverse(eqDescs);
eqDescsOut := listArray(eqDescs);
end getEquationStrings;
protected function getEquationStrings2 "author: Waurich TUD 2013-06
Implementation for getEquationStrings"
input BackendDAE.StrongComponent comp;
input BackendDAE.EqSystem iEqSystem;
input List<String> iEqDesc;
output List<String> oEqDesc;
algorithm
oEqDesc := matchcontinue(comp,iEqSystem,iEqDesc)
local
Integer i;
Integer v;
List<BackendDAE.Equation> eqnLst;
List<BackendDAE.Var> varLst;
array<Integer> ass2;
List<Integer> es;
List<Integer> vs;
List<String> descLst;
List<String> eqDescLst;
List<String> varDescLst;
String eqString;
String varString;
String desc;
Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> jac;
BackendDAE.JacobianType jacT;
BackendDAE.EquationArray orderedEqs;
BackendDAE.Variables orderedVars;
BackendDAE.Equation eqn;
BackendDAE.Var var;
case(BackendDAE.SINGLEEQUATION(eqn = i, var = v), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
var = listGet(varLst,v);
varString = getVarString(var);
desc = (eqString + " FOR " + varString);
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.EQUATIONSYSTEM(jac = BackendDAE.FULL_JACOBIAN(_)), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs),_)
equation
_ = BackendEquation.equationList(orderedEqs);
desc = ("Equation System");
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.SINGLEARRAY(eqn = i, vars = vs), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
//var = listGet(varLst,arrayGet(ass2,i));
//varString = getVarString(var);
//desc = ("ARRAY:"+eqString + " FOR " + varString);
desc = ("ARRAY:"+eqString + " FOR THE VARS: " + stringDelimitList(List.map1(vs,List.getIndexFirst,List.map(varLst,getVarString))," AND "));
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.SINGLEALGORITHM(eqn = i, vars = vs), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
//var = listGet(varLst,arrayGet(ass2,i));
//varString = getVarString(var);
//desc = ("ALGO:"+eqString + " FOR " + varString);
desc = ("ALGO: "+eqString + " FOR THE VARS: " + stringDelimitList(List.map1(vs,List.getIndexFirst,List.map(varLst,getVarString))," AND "));
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.SINGLECOMPLEXEQUATION(eqn = i, vars = vs), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
//var = listGet(varLst,arrayGet(ass2,i));
//varString = getVarString(var);
//desc = ("COMPLEX:"+eqString + " FOR " + varString);
desc = ("COMPLEX: "+eqString + " FOR THE VARS: " + stringDelimitList(List.map1(vs,List.getIndexFirst,List.map(varLst,getVarString))," AND "));
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.SINGLEWHENEQUATION(eqn = i, vars = vs), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
//var = listGet(varLst,arrayGet(ass2,i));
//varString = getVarString(var);
//desc = ("WHEN:"+eqString + " FOR " + varString);
desc = ("WHEN:"+eqString + " FOR THE VARS: " + stringDelimitList(List.map1(vs,List.getIndexFirst,List.map(varLst,getVarString))," AND "));
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.SINGLEIFEQUATION(eqn = i, vars = vs), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, orderedVars = orderedVars, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
eqnLst = BackendEquation.equationList(orderedEqs);
eqn = listGet(eqnLst,i);
eqString = BackendDump.equationString(eqn);
//get the variable string
varLst = BackendVariable.varList(orderedVars);
//var = listGet(varLst,arrayGet(ass2,i));
//varString = getVarString(var);
//desc = ("IFEQ:"+eqString + " FOR " + varString);
desc = ("IFEQ:"+eqString + " FOR THE VARS: " + stringDelimitList(List.map1(vs,List.getIndexFirst,List.map(varLst,getVarString))," AND "));
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.TORNSYSTEM(linear=true), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
_ = BackendEquation.equationList(orderedEqs);
desc = ("Torn linear System");
descLst = desc::iEqDesc;
then
descLst;
case(BackendDAE.TORNSYSTEM(linear=false), BackendDAE.EQSYSTEM(orderedEqs = orderedEqs, matching= BackendDAE.MATCHING()),_)
equation
//get the equation string
_ = BackendEquation.equationList(orderedEqs);
desc = ("Torn nonlinear System");
descLst = desc::iEqDesc;
then
descLst;
else
equation
desc = ("no singleEquation");
descLst = desc::iEqDesc;
then
descLst;
end matchcontinue;
end getEquationStrings2;
public function getVarString "author: waurich TUD 2013-06
Get the var string for a given variable. shortens the String. if necessary insert der operator."
input BackendDAE.Var inVar;
output String varString;
algorithm
varString := matchcontinue(inVar)
local
BackendDAE.VarKind kind;
list<String> varDescLst;
case(_)
equation
true = BackendVariable.isNonStateVar(inVar);
varString = BackendDump.varString(inVar);
varDescLst = stringListStringChar(varString);
varDescLst = shortenVarString(varDescLst);
varString = stringCharListString(varDescLst);
then
varString;
case(_)
equation
false = BackendVariable.isNonStateVar(inVar);
varString = BackendDump.varString(inVar);
varDescLst = stringListStringChar(varString);
varDescLst = shortenVarString(varDescLst);
varString = stringCharListString(varDescLst);
varString = (" der(" + varString + ")");
then
varString;
end matchcontinue;
end getVarString;
protected function shortenVarString "author: Waurich TUD 2013-06
Terminates var string at :"
input List<String> iString;
output List<String> oString;
protected
Integer pos;
algorithm
pos := List.position(":",iString)-1;
(oString,_) := List.split(iString,pos);
end shortenVarString;
protected function getEventNodes "author: Waurich TUD 2013-06
Gets the taskgraph nodes that are when-equations"
input BackendDAE.BackendDAE systIn;
input array<tuple<Integer,Integer,Integer>> eqCompMapping;
output list<Integer> eventNodes;
protected
list<Integer> eqLst;
list<tuple<Integer,Integer,Integer>> tplLst;
BackendDAE.EqSystems systemsIn;
algorithm
BackendDAE.DAE(eqs=systemsIn) := systIn;
((eqLst,_)) := List.fold(systemsIn, getEventNodeEqs,({},0));
eventNodes := getArrayTuple31(eqLst,eqCompMapping);
end getEventNodes;
protected function getEventNodeEqs "author: Waurich TUD 2013-06
Gets the equation for the When-nodes."
input BackendDAE.EqSystem systIn;
input tuple<list<Integer>,Integer> eventInfoIn;
output tuple<list<Integer>,Integer> eventInfoOut;
protected
BackendDAE.StrongComponents comps;
BackendDAE.Matching matching;
BackendDAE.EquationArray orderedEqs;
BackendDAE.Variables systVars;
list<Integer> eventEqs;
list<Integer> eventEqsIn;
Integer offset;
algorithm
BackendDAE.EQSYSTEM(orderedEqs=orderedEqs,orderedVars=systVars,matching=matching) := systIn;
comps := BackendDAEUtil.getCompsOfMatching(matching);
(eventEqsIn,offset) := eventInfoIn;
eventEqs := getEventNodeEqs1(comps,orderedEqs,systVars,offset,{});
offset := offset+ExpandableArray.getNumberOfElements(orderedEqs);
eventEqs := listAppend(eventEqs,eventEqsIn);
eventInfoOut := (eventEqs,offset);
end getEventNodeEqs;
protected function getEventNodeEqs1 "author: Waurich TUD 2013-06
Fold-function for getEventNodeEqs to compute the when equation in an eqSystem."
input BackendDAE.StrongComponents comps;
input BackendDAE.EquationArray orderedEqs;
input BackendDAE.Variables systVars;
input Integer offset;
input list<Integer> eventEqsIn;
output list<Integer> eventEqsOut;
algorithm
eventEqsOut := matchcontinue(comps,offset,eventEqsIn)
local
Integer eqn;
Integer sysCount;
list<Integer> eventEqs;
list<BackendDAE.Var> eqnVars;
BackendDAE.StrongComponents rest;
BackendDAE.StrongComponent head;
case((head::rest),_,_)
equation
true = isWhenEquation(head);
BackendDAE.SINGLEWHENEQUATION(eqn = eqn) = head;
eqn = eqn+offset;
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eqn::eventEqsIn);
then
eventEqs;
// discrete variables
case((head::rest),_,_)
equation
(eqnVars,_,_,eventEqs) = BackendDAEUtil.getStrongComponentVarsAndEquations(head, systVars, orderedEqs);
true = List.mapBoolAnd(eqnVars, BackendVariable.isVarDiscrete);
eventEqs = list(i+offset for i in eventEqs);
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,listAppend(eventEqs,eventEqsIn));
then
eventEqs;
case((head::rest),_,_)
equation
false = isWhenEquation(head);
eventEqs = getEventNodeEqs1(rest,orderedEqs,systVars,offset,eventEqsIn);
then
eventEqs;
case({},_,_)
then
eventEqsIn;
end matchcontinue;
end getEventNodeEqs1;
protected function getArrayTuple31 "author: Waurich TUD 2013-06
Matches entries of list1 with the assigned values of assign to obtain the values."
input list<Integer> list1;
input array<tuple<Integer,Integer,Integer>> assign;
output list<Integer> list2Out;
protected
list<tuple<Integer,Integer,Integer>> tplLst;
algorithm
tplLst := List.map1(list1,Array.getIndexFirst,assign);
list2Out := List.map(tplLst,Util.tuple31);
end getArrayTuple31;
protected function isWhenEquation "author: Waurich TUD 2013-06
checks if the comp is of type SINGLEWHENEQUATION."
input BackendDAE.StrongComponent inComp;
output Boolean isWhenEq;
algorithm
isWhenEq := matchcontinue(inComp)
local Integer eqn;
case(BackendDAE.SINGLEWHENEQUATION())
then
true;
else false;
end matchcontinue;
end isWhenEquation;
protected function fillSccList "author: marcusw
This function appends the scc, which solves the given variable, to the requiredsccs-list."
input tuple<Integer,Integer> iVariable; //<varIdx, [derived = 0, not derived = 1]>
input Integer iVarType; //<1 = int, 2 = float, 3 = bool, 4 = string>
input array<tuple<Integer,Integer,Integer>> iVarCompMapping; //<sccIdx, eqSysIdx, offset>
input array<tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>>> iRequiredSccs; //<int vars, float vars, bool vars>
output array<tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>>> oRequiredSccs;
algorithm
oRequiredSccs := match(iVariable,iVarType,iVarCompMapping,iRequiredSccs)
local
Integer varIdx, sccIdx;
list<Integer> integerVars,floatVars,booleanVars,stringVars;
array<tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>>> tmpRequiredSccs;
case ((varIdx,1),1,_,tmpRequiredSccs)
equation
((sccIdx,_,_)) = arrayGet(iVarCompMapping,varIdx);
((integerVars,floatVars,booleanVars,stringVars)) = arrayGet(iRequiredSccs, sccIdx);
integerVars = varIdx::integerVars;
tmpRequiredSccs = arrayUpdate(tmpRequiredSccs,sccIdx,(integerVars,floatVars,booleanVars,stringVars));
then tmpRequiredSccs;
case ((varIdx,1),2,_,tmpRequiredSccs)
equation
((sccIdx,_,_)) = arrayGet(iVarCompMapping,varIdx);
((integerVars,floatVars,booleanVars,stringVars)) = arrayGet(iRequiredSccs, sccIdx);
floatVars = varIdx::floatVars;
tmpRequiredSccs = arrayUpdate(tmpRequiredSccs,sccIdx,(integerVars,floatVars,booleanVars,stringVars));
then tmpRequiredSccs;
case ((varIdx,1),3,_,tmpRequiredSccs)
equation
((sccIdx,_,_)) = arrayGet(iVarCompMapping,varIdx);
((integerVars,floatVars,booleanVars,stringVars)) = arrayGet(iRequiredSccs, sccIdx);
booleanVars = varIdx::booleanVars;
tmpRequiredSccs = arrayUpdate(tmpRequiredSccs,sccIdx,(integerVars,floatVars,booleanVars,stringVars));
then tmpRequiredSccs;
case ((varIdx,1),4,_,tmpRequiredSccs)
equation
((sccIdx,_,_)) = arrayGet(iVarCompMapping,varIdx);
((integerVars,floatVars,booleanVars,stringVars)) = arrayGet(iRequiredSccs, sccIdx);
stringVars = varIdx::stringVars;
tmpRequiredSccs = arrayUpdate(tmpRequiredSccs,sccIdx,(integerVars,floatVars,booleanVars,stringVars));
then tmpRequiredSccs;
else iRequiredSccs;
end match;
end fillSccList;
protected function convertRefArrayToList "author: marcusw
Append the reference values for the given scc to the result list, if the reference counter is not zero."
input tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>> iRefCountValues; //<referenceInt, referenceFloat, referenceBool,referenceString>
input tuple<Integer,list<tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>>>> iList; //the current index and the current ref-list (<sccIdx, refCountInt, refCountFloat, refCountBool, refCountString>)
output tuple<Integer,list<tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>>>> oList;
protected
Integer curIdx;
list<Integer> integerVars,floatVars,booleanVars,stringVars;
tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>> tmpTuple;
list<tuple<Integer,list<Integer>,list<Integer>,list<Integer>,list<Integer>>> curList;
algorithm
oList := match(iRefCountValues,iList)
case(({},{},{},{}),(curIdx,curList))
then ((curIdx+1,curList));
case((integerVars,floatVars,booleanVars,stringVars),(curIdx,curList))
equation
tmpTuple = (curIdx,integerVars,floatVars,booleanVars,stringVars);
curList = tmpTuple::curList;
then ((curIdx+1,curList));
end match;
end convertRefArrayToList;
protected function getUnsolvedVarsBySCC "author: marcusw, waurich
Returns all required variables which are not solved inside the given component."
input BackendDAE.StrongComponent iComponent;
input BackendDAE.IncidenceMatrix iIncidenceMatrix;
input BackendDAE.Variables iOrderedVars;
input BackendDAE.Variables iKnownVars; //parameters and constants of SHARED-object
input BackendDAE.EquationArray iOrderedEquations;
input list<Integer> iEventVarLst;
input Boolean iAnalyzeParameters;
output tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> oUnsolvedVars; //<intVarIdc, <floatVarIdx, [0 if derived, 1 if not]>, boolVarIdc, stringVarIdc>
output list<Integer> oParamVars; //indices related to iKnownVars-object
algorithm
(oUnsolvedVars, oParamVars) := matchcontinue(iComponent, iIncidenceMatrix, iOrderedVars, iKnownVars, iOrderedEquations, iEventVarLst, iAnalyzeParameters)
local
Integer varIdx;
list<Integer> varIdc;
tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> tmpVars;
list<Integer> paramVars;
case(BackendDAE.SINGLEEQUATION(var=varIdx),_,_,_,_,_,_)
equation
(tmpVars, paramVars) = getUnsolvedVarsBySCC0(iComponent,iIncidenceMatrix,iOrderedVars,iKnownVars,iOrderedEquations,{varIdx},iEventVarLst, iAnalyzeParameters);
then
(tmpVars, paramVars);
case(BackendDAE.EQUATIONSYSTEM(vars=varIdc),_,_,_,_,_,_)
equation
(tmpVars, paramVars) = getUnsolvedVarsBySCC0(iComponent,iIncidenceMatrix,iOrderedVars,iKnownVars,iOrderedEquations,varIdc,iEventVarLst, iAnalyzeParameters);
then
(tmpVars, paramVars);
case(BackendDAE.SINGLEARRAY(vars=varIdc),_,_,_,_,_,_)
equation
(tmpVars, paramVars) = getUnsolvedVarsBySCC0(iComponent,iIncidenceMatrix,iOrderedVars,iKnownVars,iOrderedEquations,varIdc,iEventVarLst, iAnalyzeParameters);
then
(tmpVars, paramVars);
case(BackendDAE.SINGLEALGORITHM(vars=varIdc),_,_,_,_,_,_)
equation
(tmpVars, paramVars) = getUnsolvedVarsBySCC0(iComponent,iIncidenceMatrix,iOrderedVars,iKnownVars,iOrderedEquations,varIdc,iEventVarLst, iAnalyzeParameters);
then
(tmpVars, paramVars);
case(BackendDAE.SINGLECOMPLEXEQUATION(vars=varIdc),_,_,_,_,_,_)
equation
(tmpVars, paramVars) = getUnsolvedVarsBySCC0(iComponent,iIncidenceMatrix,iOrderedVars,iKnownVars,iOrderedEquations,varIdc,iEventVarLst, iAnalyzeParameters);
then (tmpVars, paramVars);
case(BackendDAE.SINGLEWHENEQUATION(vars=varIdc),_,_,_,_,_,_)