/
Connect.mo
1850 lines (1705 loc) · 59.3 KB
/
Connect.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-2008, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF 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öpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* 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.
*
*/
package Connect
" file: Connect.mo
package: Connect
description: Connection set management
RCS: $Id$
Connections generate connection sets (datatype SET is described below)
which are constructed during instantiation. When a connection
set is generated, it is used to create a number of equations.
The kind of equations created depends on the type of the set.
Connect.mo is called from Inst.mo and is responsible for
creation of all connect-equations later passed to the DAE module
in DAE.mo."
public import Exp;
public import Static;
public import DAE;
public import Env;
public import Prefix;
public import Absyn;
public
uniontype Face "This type indicates whether a connector is an inside or an outside
connector. Note: this is not the same as inner and outer references. A connector is inside if it connects from the outside into a component
and it is outside if it connects out from the component. This is important when generating equations for flow variables,
where outside connectors are multiplied with -1 (since flow is always into a component)."
record INNER end INNER;
record OUTER end OUTER;
end Face;
public
uniontype Set "A connection set is represented using the `Set\' type."
record EQU
list<Exp.ComponentRef> expComponentRefLst;
end EQU;
record FLOW
list<tuple<Exp.ComponentRef, Face>> tplExpComponentRefFaceLst;
end FLOW;
end Set;
public
uniontype Sets "The connection \'Sets\' contains
- the connection set
- a list of component references occuring in connect statemens
- a list of deleted components
- connect statements to propagate upwards in instance hierachy (inner/outer connectors)
The list of componentReferences are
used only when evaluating the cardinality operator. It is passed -into-
classes to be instantiated, while the \'Set list\' is returned -from-
instantiated classes.
The list of deleted components is required to be able to remove connections to them.
"
record SETS
list<Set> setLst;
list<Exp.ComponentRef> connection "connection_set connect_refs - list of
crefs in connect statements. This is used to be able to evaluate cardinality. It is registered in env
by Inst.addConnnectionSetToEnv. " ;
list<Exp.ComponentRef> deletedComponents "list of components with conditional declaration = false";
list<OuterConnect> outerConnects "connects to propagate upwards";
end SETS;
end Sets;
uniontype OuterConnect
record OUTERCONNECT
Prefix.Prefix scope "the scope that this connect was created";
Exp.ComponentRef cr1;
Absyn.InnerOuter io1 "inner/outer attribute for cr1 component";
Face f1;
Exp.ComponentRef cr2;
Absyn.InnerOuter io2 "inner/outer attribute for cr2 component";
Face f2;
end OUTERCONNECT;
end OuterConnect;
public constant Sets emptySet=SETS({},{},{},{});
public function addDeletedComponent "Adds a deleted component, i.e. conditional component
with condition = false, to Sets, if condition b is false"
input Boolean b;
input Exp.ComponentRef component;
input Sets sets;
output Sets outSets;
algorithm
outSets := matchcontinue(b,component,sets)
local
list<Set> setLst;
list<Exp.ComponentRef> crs,deletedComps;
list<OuterConnect> outerConn;
case(true,component,sets) then sets;
case(false,component,SETS(setLst,crs,deletedComps,outerConn))
then SETS(setLst,crs,component::deletedComps,outerConn);
end matchcontinue;
end addDeletedComponent;
public function addOuterConnection " Adds a connection with a reference to an outer connector
These are added to a special list, such that they can be moved up in the instance hierachy to a place
where both instances are defined.
"
input Prefix.Prefix scope;
input Sets sets;
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Absyn.InnerOuter io1;
input Absyn.InnerOuter io2;
input Face f1;
input Face f2;
output Sets outSets;
algorithm
outSets := matchcontinue(scope,sets,cr1,cr2,io1,io2,f1,f2)
local list<Set> ss;
list<Exp.ComponentRef> crs,dc;
list<OuterConnect> oc;
/* First check if already added */
case(scope,sets as SETS(ss,crs,dc,oc),cr1,cr2,io1,io2,f1,f2) equation
_::_ = Util.listSelect2(oc,cr1,cr2,outerConnectionMatches);
then sets;
case(scope,SETS(ss,crs,dc,oc),cr1,cr2,io1,io2,f1,f2) then SETS(ss,crs,dc,OUTERCONNECT(scope,cr1,io1,f1,cr2,io2,f2)::oc);
end matchcontinue;
end addOuterConnection;
protected function outerConnectionMatches "Returns true if OuterConnect matches the two component refernces passed as argument"
input OuterConnect oc;
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
output Boolean matches;
algorithm
matches := matchcontinue(oc,cr1,cr2)
local Exp.ComponentRef cr11,cr22;
case(OUTERCONNECT(cr1=cr11,cr2=cr22),cr1,cr2) equation
matches = Exp.crefEqual(cr11,cr1) and Exp.crefEqual(cr22,cr2) or
Exp.crefEqual(cr11,cr2) and Exp.crefEqual(cr22,cr1);
then matches;
end matchcontinue;
end outerConnectionMatches;
public function addOuterConnectToSets "adds an outerconnection to all sets where a corresponding inner definition is present
For instance,
if a connection set contains {world.v, topPin.v}
and we have an outer connection connect(world,a2.aPin),
the connection should be added to the set, resulting in
{world.v,topPin.v,a2.aPin.v}
"
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Absyn.InnerOuter io1;
input Absyn.InnerOuter io2;
input Face f1;
input Face f2;
input list<Set> setLst;
input list<Exp.ComponentRef> inCrs;
output list<Set> outSetLst;
output list<Exp.ComponentRef> outCrs;
output Boolean added "true if addition was made";
algorithm
(outSetLst,outCrs,added) := matchcontinue(cr1,cr2,io1,io2,f1,f2,setLst,inCrs)
local list<Exp.ComponentRef> crs; Set set;
list<tuple<Exp.ComponentRef,Face>> fcrs;
Boolean added2;
case(cr1,cr2,io1,io2,f1,f2,{},inCrs) then ({},inCrs,false);
case(cr1,cr2,io1,io2,f1,f2,EQU(crs)::setLst,inCrs) equation
(crs,inCrs,added) = addOuterConnectToSets2(cr1,cr2,io1,io2,crs,inCrs);
(setLst,inCrs,added2) = addOuterConnectToSets(cr1,cr2,io1,io2,f1,f2,setLst,inCrs);
then (EQU(crs)::setLst,inCrs,added or added2);
case(cr1,cr2,io1,io2,f1,f2,FLOW(fcrs)::setLst,inCrs) equation
(fcrs,inCrs,added) = addOuterConnectToSets3(cr1,cr2,f1,f2,io1,io2,fcrs,inCrs);
(setLst,inCrs,added2) = addOuterConnectToSets(cr1,cr2,io1,io2,f1,f2,setLst,inCrs);
then (FLOW(fcrs)::setLst,inCrs,added or added2);
case(cr1,cr2,io1,io2,f1,f2,set::setLst,inCrs) equation
(setLst,inCrs,added) = addOuterConnectToSets(cr1,cr2,io1,io2,f1,f2,setLst,inCrs);
then (set::setLst,inCrs,added);
end matchcontinue;
end addOuterConnectToSets;
protected function addOuterConnectToSets2 "help function to addOuterconnectToSets"
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Absyn.InnerOuter io1;
input Absyn.InnerOuter io2;
input list<Exp.ComponentRef> crs;
input list<Exp.ComponentRef> inCrs "from connection crefs (outer scopes)";
output list<Exp.ComponentRef> outCrs;
output list<Exp.ComponentRef> outCrs2 "from connection crefs (outer scopes)";
output Boolean added;
protected
Boolean isOuter1,isOuter2;
algorithm
(_,isOuter1) := Inst.innerOuterBooleans(io1);
(_,isOuter2) := Inst.innerOuterBooleans(io2);
(outCrs,outCrs2,added) := addOuterConnectToSets22(cr1,cr2,isOuter1,isOuter2,crs,inCrs);
end addOuterConnectToSets2;
protected function addOuterConnectToSets22 "help function to addOuterconnectToSets2"
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Boolean isOuter1;
input Boolean isOuter2;
input list<Exp.ComponentRef> crs;
input list<Exp.ComponentRef> inCrs "from connection crefs (outer scopes)";
output list<Exp.ComponentRef> outCrs;
output list<Exp.ComponentRef> outCrs2 "from connection crefs (outer scopes)";
output Boolean added;
algorithm
(outCrs,outCrs2,added) := matchcontinue(cr1,cr2,isOuter1,isOuter2,crs,inCrs)
local Exp.ComponentRef outerCr,outerCr,connectorCr,newCr;
case(cr1,cr2,true,true,crs,inCrs) equation
Error.addMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE,{"Connections where both connectors are outer references","No suggestion"});
then (crs,inCrs,false);
case(cr1,cr2,true,false,crs,inCrs) equation
outerCr::_ = Util.listSelect1R(crs,cr1,Exp.crefPrefixOf);
connectorCr = Exp.crefStripPrefix(outerCr,cr1);
newCr = Exp.joinCrefs(cr2,connectorCr);
then (newCr::crs,inCrs,true);
case(cr1,cr2,false,true,crs,inCrs) equation
outerCr::_ = Util.listSelect1R(crs,cr2,Exp.crefPrefixOf);
connectorCr = Exp.crefStripPrefix(outerCr,cr2);
newCr = Exp.joinCrefs(cr1,connectorCr);
then (newCr::crs,inCrs,true);
case(cr1,cr2,_,_,crs,inCrs) then (crs,inCrs,false);
end matchcontinue;
end addOuterConnectToSets22;
protected function addOuterConnectToSets3 "help function to addOuterconnectToSets"
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Face f1;
input Face f2;
input Absyn.InnerOuter io1;
input Absyn.InnerOuter io2;
input list<tuple<Exp.ComponentRef,Face>> crs;
input list<Exp.ComponentRef> inCrs;
output list<tuple<Exp.ComponentRef,Face>> outCrs;
output list<Exp.ComponentRef> outCrs2;
output Boolean added;
protected
Boolean isOuter1,isOuter2;
algorithm
(_,isOuter1) := Inst.innerOuterBooleans(io1);
(_,isOuter2) := Inst.innerOuterBooleans(io2);
(outCrs,outCrs2,added) := addOuterConnectToSets33(cr1,cr2,isOuter1,isOuter2,f1,f2,crs,inCrs);
end addOuterConnectToSets3;
protected function addOuterConnectToSets33 "help function to addOuterconnectToSets3"
input Exp.ComponentRef cr1;
input Exp.ComponentRef cr2;
input Boolean isOuter1;
input Boolean isOuter2;
input Face f1;
input Face f2;
input list<tuple<Exp.ComponentRef,Face>> crs;
input list<Exp.ComponentRef> inCrs;
output list<tuple<Exp.ComponentRef,Face>> outCrs;
output list<Exp.ComponentRef> outCrs2;
output Boolean added;
algorithm
(outCrs,outCrs2,added) := matchcontinue(cr1,cr2,isOuter1,isOuter2,f1,f2,crs,inCrs)
local Exp.ComponentRef outerCr,outerCr,connectorCr,newCr;
case(cr1,cr2,true,true,f1,f2,crs,inCrs) equation
Error.addMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE,{"Connections where both connectors are outer references","No suggestion"});
then (crs,inCrs,false);
case(cr1,cr2,true,false,f1,f2,crs,inCrs) equation
outerCr::_ = Util.listSelect1R(Util.listMap(crs,Util.tuple21),cr1,Exp.crefPrefixOf);
connectorCr = Exp.crefStripPrefix(outerCr,cr1);
newCr = Exp.joinCrefs(cr2,connectorCr);
then ((newCr,f2)::crs,inCrs,true);
case(cr1,cr2,false,true,f1,f2,crs,inCrs) equation
outerCr::_ = Util.listSelect1R(Util.listMap(crs,Util.tuple21),cr2,Exp.crefPrefixOf);
connectorCr = Exp.crefStripPrefix(outerCr,cr2);
newCr = Exp.joinCrefs(cr1,connectorCr);
then ((newCr,f1)::crs,inCrs,true);
case(cr1,cr2,_,_,_,_,crs,inCrs) then (crs,inCrs,false);
end matchcontinue;
end addOuterConnectToSets33;
public function addEqu "function: addEqu
Adds an equal equation, see explaining text above.
- Adding
The two functions `add_eq\' and `add_flow\' addes a variable to a
connection set. The first function is used to add a non-flow
variable, and the second is used to add a flow variable. When
two component are to be added to a collection of connection sets,
the connections sets containg the components have to be located.
If no such set exists, a new set containing only the new component
is created.
If the connection sets containing the two components are not the
same, they are merged.
"
input Sets ss;
input Exp.ComponentRef r1;
input Exp.ComponentRef r2;
output Sets ss_1;
Set s1,s2;
Sets ss_1;
algorithm
s1 := findEquSet(ss, r1);
s2 := findEquSet(ss, r2);
ss_1 := merge(ss, s1, s2);
end addEqu;
public function addFlow "function: addFlow
Adds an flow equation, see add_equ above.
"
input Sets ss;
input Exp.ComponentRef r1;
input Face d1;
input Exp.ComponentRef r2;
input Face d2;
output Sets ss_1;
Set s1,s2;
Sets ss_1;
algorithm
s1 := findFlowSet(ss, r1, d1);
s2 := findFlowSet(ss, r2, d2);
ss_1 := merge(ss, s1, s2);
end addFlow;
public function addArrayFlow "function: addArrayFlow
For connecting two arrays, a flow equation for each index should be generated, see addFlow.
"
input Sets ss;
input Exp.ComponentRef r1;
input Face d1;
input Exp.ComponentRef r2;
input Face d2;
input Integer dsize;
output Sets ss_1;
Set s1,s2;
Sets ss_1;
algorithm
outSets:=
matchcontinue (ss,r1,d1,r2,d2,dsize)
local
Sets s,ss_1,ss_2,ss;
Exp.ComponentRef r1_1,r2_1,r1,r2;
Integer i_1,i;
Set s1,s2;
case (s,_,_,_,_,0) then s;
case (ss,r1,d1,r2,d2,i)
equation
r1_1 = Exp.subscriptCref(r1, {Exp.INDEX(Exp.ICONST(i))});
r2_1 = Exp.subscriptCref(r2, {Exp.INDEX(Exp.ICONST(i))});
i_1 = i - 1;
s1 = findFlowSet(ss, r1_1,d1);
s2 = findFlowSet(ss, r2_1,d2);
ss_1 = merge(ss, s1, s2);
ss_2 = addArrayFlow(ss_1, r1,d1, r2,d2, i_1);
then
ss_2;
end matchcontinue;
end addArrayFlow;
public function addMultiArrayEqu "function: addMultiArrayEqu
Author: BZ 2008-07
For connecting two arrays, an equal equation for each index should
be generated. generic dimensionality
"
input Sets inSets1;
input Exp.ComponentRef inComponentRef2;
input Exp.ComponentRef inComponentRef3;
input list<Integer> dimensions;
output Sets outSets;
algorithm
outSets:=
matchcontinue (inSets1,inComponentRef2,inComponentRef3,dimensions)
local
Integer i_1,i;
list<Integer> rest;
list<list<Integer>> intSubs;
list<list<Exp.Subscript>> subSubs;
Integer dimension;
case (inSets1,_,_,{}) then inSets1;
case (inSets1,inComponentRef2,inComponentRef3,dimensions)
equation
intSubs = generateSubscriptList(dimensions);
intSubs = listReverse(intSubs);
subSubs = Util.listMap(intSubs,Exp.intSubscripts);
outSets = addMultiArrayEqu2(inSets1,inComponentRef2,inComponentRef3,subSubs);
then
outSets;
end matchcontinue;
end addMultiArrayEqu;
protected function addMultiArrayEqu2 "
Author: BZ, 2008-07
Generates Subscripts, from the input list<list, for the componentreferences given.
"
input Sets inSets1;
input Exp.ComponentRef inComponentRef2;
input Exp.ComponentRef inComponentRef3;
input list<list<Exp.Subscript>> dimensions;
output Sets outSets;
algorithm outSets := matchcontinue(inSets1,inComponentRef2,inComponentRef3,dimensions)
local
Sets s,ss_1,ss_2,ss;
Exp.ComponentRef r1_1,r2_1,r1,r2;
Set s1,s2;
list<list<Exp.Subscript>> restDims;
list<Exp.Subscript> dims;
Integer dimension;
case (s,_,_,{}) then s;
case (ss,r1,r2,dims::restDims)
equation
r1_1 = Exp.replaceCrefSliceSub(r1,dims);
r2_1 = Exp.replaceCrefSliceSub(r2,dims);
s1 = findEquSet(ss, r1_1);
s2 = findEquSet(ss, r2_1);
ss_1 = merge(ss, s1, s2);
ss_2 = addMultiArrayEqu2(ss_1, r1, r2, restDims);
then
ss_2;
end matchcontinue;
end addMultiArrayEqu2;
protected function generateSubscriptList "
Author BZ 2008-07
Generates all subscripts for the dimension/(s)
"
input list<Integer> dims;
output list<list<Integer>> subs;
algorithm subs := matchcontinue(dims)
local
Integer dim;
list<Integer> rest;
list<list<Integer>> nextLevel,result,currLevel;
case(dim::{})
equation
currLevel = generateSubscriptList2(dim);
currLevel = listReverse(currLevel);
then currLevel;
case(dim::rest)
equation
currLevel = generateSubscriptList2(dim);
currLevel = listReverse(currLevel);
nextLevel = generateSubscriptList(rest);
result = mergeCurrentWithRestIndexies(nextLevel,currLevel);
then result;
end matchcontinue;
end generateSubscriptList;
protected function generateSubscriptList2 "
helper function for generateSubscriptList
"
input Integer i;
output list<list<Integer>> oil;
algorithm oil := matchcontinue(i)
local
case(0) then {};
case(i)
equation
oil = generateSubscriptList2(i-1);
then
{i}::oil;
end matchcontinue;
end generateSubscriptList2;
protected function mergeCurrentWithRestIndexies "
Helper function for generateSubscriptList, merges recursive dimensions with current.
"
input list<list<Integer>> curr;
input list<list<Integer>> Indexies;
output list<list<Integer>> oIndexies;
algorithm oIndexies := matchcontinue(curr,Indexies)
local
list<Integer> il;
list<list<Integer>> ill,merged;
case(_,{}) then {};
case(curr,(il as (_ :: (_ :: _)))::ill)
equation
ill = mergeCurrentWithRestIndexies(curr,ill);
merged = Util.listMap1(curr,Util.listAppendr,il);
merged = listAppend(merged,ill);
then
merged;
case(curr,(il as {_})::ill)
equation
ill = mergeCurrentWithRestIndexies(curr,ill);
merged = Util.listMap1(curr,Util.listAppendr,il);
merged = listAppend(merged,ill);
then
merged;
end matchcontinue;
end mergeCurrentWithRestIndexies;
public function equations "
- Equation generation
From a number of connection sets, this function generates a list
of equations.
"
input Sets sets;
input Prefix.Prefix pre "prefix required for checking deleted components";
output list<DAE.Element> eqns;
algorithm
eqns := matchcontinue(sets,pre)
local list<Set> s;
list<Exp.ComponentRef> crs,deletedComps;
Exp.ComponentRef cr,deletedComp;
list<OuterConnect> outerConn;
case(sets as SETS(s,crs,{},outerConn),pre) equation
then equations2(sets);
case(SETS(s,crs,deletedComp::deletedComps,outerConn),pre) equation
cr= deletedComp;
s = removeComponentInSets(cr,s);
then equations(SETS(s,crs,deletedComps,outerConn),pre);
case(_,_) equation
Debug.fprint("failtrace","Connect.equations failed\n");
then fail();
end matchcontinue;
end equations;
protected function removeComponentInSets "Removes all connections to component from the set"
input Exp.ComponentRef compName;
input list<Set> s;
output list<Set> outS;
algorithm
outS := matchcontinue(compName,s)
local list<Exp.ComponentRef> crs;
list<tuple<Exp.ComponentRef, Face>> fcrs;
case(compName,{}) then {};
case(compName, EQU(crs)::s) equation
crs = Util.listSelect1R(crs,compName,Exp.crefNotPrefixOf);
s = removeComponentInSets(compName,s);
then EQU(crs)::s;
case(compName, FLOW(fcrs)::s) equation
fcrs = Util.listSelect1(fcrs,compName,flowTupleNotPrefixOf);
s = removeComponentInSets(compName,s);
then FLOW(fcrs)::s;
case(_,_) equation
Debug.fprint("failtrace","-removeComponentInSets failed\n");
then fail();
end matchcontinue;
end removeComponentInSets;
protected function flowTupleNotPrefixOf "Help function to removeComponentInSets.
Determines if connection cref is to the component "
input tuple<Exp.ComponentRef, Face> tpl;
input Exp.ComponentRef compName;
output Boolean b;
algorithm
b:= matchcontinue(tpl,compName)
local Exp.ComponentRef cr1;
case((cr1,_),compName)
then Exp.crefNotPrefixOf(compName,cr1);
end matchcontinue;
end flowTupleNotPrefixOf;
protected function equations2 "
Helper function to equations. Once deleted components has been removed from connection sets,
this function generates the equations.
"
input Sets inSets;
output list<DAE.Element> outDAEElementLst;
algorithm
outDAEElementLst:=
matchcontinue (inSets)
local
list<DAE.Element> dae1,dae2,dae;
list<Exp.ComponentRef> cs,crs,dc;
list<Set> ss;
Sets sets;
list<OuterConnect> outerConn;
case (SETS(setLst = {})) then {};
/* Empty equ set, can come from deleting components */
case (SETS((EQU(expComponentRefLst = {}) :: ss),crs,dc,outerConn))
equation
dae = equations2(SETS(ss,crs,dc,outerConn));
then
dae;
/* Empty flow set, can come from deleting components */
case (SETS((FLOW(tplExpComponentRefFaceLst = {}) :: ss),crs,dc,outerConn))
equation
dae = equations2(SETS(ss,crs,dc,outerConn));
then
dae;
case (SETS((EQU(expComponentRefLst = cs) :: ss),crs,dc,outerConn))
equation
dae1 = equEquations(cs);
dae2 = equations2(SETS(ss,crs,dc,outerConn));
dae = listAppend(dae1, dae2);
then
dae;
case (SETS((FLOW(tplExpComponentRefFaceLst = cs) :: ss),crs,dc,outerConn))
local list<tuple<Exp.ComponentRef, Face>> cs;
equation
dae1 = flowEquations(cs);
dae2 = equations2(SETS(ss,crs,dc,outerConn));
dae = listAppend(dae1, dae2);
then
dae;
case (sets)
equation
Debug.fprint("failtrace","-equations2 failed\n");
then
fail();
end matchcontinue;
end equations2;
protected function equEquations "function: equEquations
A non-flow connection set contains a number of components.
Generating the equation from this set means equating all the
components. For n components, this will give n-1 equations.
For example, if the set contains the components `x\', `y.a\' and
`z.b\', the equations generated will me `x = y.a\' and `y.a = z.b\'.
"
input list<Exp.ComponentRef> inExpComponentRefLst;
output list<DAE.Element> outDAEElementLst;
algorithm
outDAEElementLst:=
matchcontinue (inExpComponentRefLst)
local
list<DAE.Element> eq;
Exp.ComponentRef x,y;
list<Exp.ComponentRef> cs;
case {_} then {};
case (x :: (y :: cs))
equation
eq = equEquations((y :: cs));
then
(DAE.EQUEQUATION(x,y) :: eq);
case(_) equation print(" FAILURE IN CONNECT \n"); then fail();
end matchcontinue;
end equEquations;
protected function flowEquations "function: flowEquations
Generating equations from a flow connection set is a little
trickier that from a non-flow set. Only one equation is
generated, but it has to consider whether the comoponents were
inner or outer connectors.
This function uses `flow_sum\' to create the sum of all components
(some of which will be negated), and the returns the equation
where this sum is equal to 0.0.
"
input list<tuple<Exp.ComponentRef, Face>> cs;
output list<DAE.Element> outDAEElementLst;
Exp.Exp sum;
algorithm
sum := flowSum(cs);
outDAEElementLst := {DAE.EQUATION(sum,Exp.RCONST(0.0))};
end flowEquations;
protected function flowSum "function: flowSum
This function creates an exression expressing the sum of all
components in the given list. Before adding the component to the
sum, it is passed to `sign_flow\' which will negate all outer
connectors.
"
input list<tuple<Exp.ComponentRef, Face>> inTplExpComponentRefFaceLst;
output Exp.Exp outExp;
algorithm
outExp:=
matchcontinue (inTplExpComponentRefFaceLst)
local
Exp.Exp exp,exp1,exp2;
Exp.ComponentRef c;
Face f;
list<tuple<Exp.ComponentRef, Face>> cs;
case {(c,f)}
equation
exp = signFlow(c, f);
then
exp;
case (((c,f) :: cs))
equation
exp1 = signFlow(c, f);
exp2 = flowSum(cs);
then
Exp.BINARY(exp1,Exp.ADD(Exp.REAL()),exp2);
end matchcontinue;
end flowSum;
protected function signFlow "function: signFlow
This function takes a name of a component and a `Face\', returns an
expression. If the face is `INNER\' the expression simply contains
the component reference, but if it is `OUTER\', the expression is
negated.
"
input Exp.ComponentRef inComponentRef;
input Face inFace;
output Exp.Exp outExp;
algorithm
outExp:=
matchcontinue (inComponentRef,inFace)
local Exp.ComponentRef c;
case (c,INNER()) then Exp.CREF(c,Exp.OTHER());
case (c,OUTER()) then Exp.UNARY(Exp.UMINUS(Exp.REAL()),Exp.CREF(c,Exp.OTHER()));
end matchcontinue;
end signFlow;
protected function findEquSet "
- Lookup
These functions are used to find and create connection sets.
function: findEquSet
This function finds a non-flow connection set that contains the
component named by the second argument. If no such set is found,
a new set is created.
"
input Sets inSets;
input Exp.ComponentRef inComponentRef;
output Set outSet;
algorithm
outSet:=
matchcontinue (inSets,inComponentRef)
local
Set s;
Exp.ComponentRef c;
list<Set> ss;
list<Exp.ComponentRef> crs,dc;
list<OuterConnect> outerConn;
case (SETS(setLst = {}),c)
equation
s = newEquSet(c);
then
s;
case (SETS(setLst = (s :: _)),c)
equation
findInSet(s, c);
then
s;
case (SETS((_ :: ss),crs,dc,outerConn),c)
equation
s = findEquSet(SETS(ss,crs,dc,outerConn), c);
then
s;
end matchcontinue;
end findEquSet;
protected function findFlowSet "function: findFlowSet
This function finds a flow connection set that contains the
component named by the second argument. If no such set is found,
a new set is created.
"
input Sets inSets;
input Exp.ComponentRef inComponentRef;
input Face inFace;
output Set outSet;
algorithm
outSet:=
matchcontinue (inSets,inComponentRef,inFace)
local
Set s;
Exp.ComponentRef c;
Face d;
list<Set> ss;
list<Exp.ComponentRef> crs,dc;
list<OuterConnect> outerConn;
case (SETS(setLst = {}),c,d)
equation
s = newFlowSet(c, d);
then
s;
case (SETS(setLst = (s :: _)),c,d)
equation
findInSet(s, c);
then
s;
case (SETS((_ :: ss),crs,dc,outerConn),c,d)
equation
s = findFlowSet(SETS(ss,crs,dc,outerConn), c, d);
then
s;
end matchcontinue;
end findFlowSet;
protected function findInSet "function: findInSet
This function checks if a componet already appears in a given
connection set.
"
input Set inSet;
input Exp.ComponentRef inComponentRef;
algorithm
_:=
matchcontinue (inSet,inComponentRef)
local
list<Exp.ComponentRef> cs;
Exp.ComponentRef c;
case (EQU(expComponentRefLst = cs),c)
equation
findInSetEqu(cs, c);
then
();
case (FLOW(tplExpComponentRefFaceLst = cs),c)
local list<tuple<Exp.ComponentRef, Face>> cs;
equation
findInSetFlow(cs, c);
then
();
end matchcontinue;
end findInSet;
protected function findInSetEqu "function: findInSetEqu
This is a version of `find_in_set\' which is specialized on
non-flow connection sets
"
input list<Exp.ComponentRef> inExpComponentRefLst;
input Exp.ComponentRef inComponentRef;
algorithm
_:=
matchcontinue (inExpComponentRefLst,inComponentRef)
local
Exp.ComponentRef c1,c2;
list<Exp.ComponentRef> cs;
case ((c1 :: _),c2)
equation
Static.eqCref(c1, c2);
then
();
case ((_ :: cs),c2)
equation
findInSetEqu(cs, c2);
then
();
end matchcontinue;
end findInSetEqu;
protected function findInSetFlow "function: findInSetFlow
This is a version of `find_in_set\' which is specialized on
flow connection sets
"
input list<tuple<Exp.ComponentRef, Face>> inTplExpComponentRefFaceLst;
input Exp.ComponentRef inComponentRef;
algorithm
_:=
matchcontinue (inTplExpComponentRefFaceLst,inComponentRef)
local
Exp.ComponentRef c1,c2;
list<tuple<Exp.ComponentRef, Face>> cs;
case (((c1,_) :: _),c2)
equation
Static.eqCref(c1, c2);
then
();
case ((_ :: cs),c2)
equation
findInSetFlow(cs, c2);
then
();
end matchcontinue;
end findInSetFlow;
protected function newEquSet "function: newEquSet
This function creates a new non-flow connection set containing
only the given component.
"
input Exp.ComponentRef inComponentRef;
output Set outSet;
algorithm
outSet:=
matchcontinue (inComponentRef)
local Exp.ComponentRef c;
case c then EQU({c});
end matchcontinue;
end newEquSet;
protected function newFlowSet "function: newFlowSet
This function creates a new-flow connection set containing only
the given component.
"
input Exp.ComponentRef inComponentRef;
input Face inFace;
output Set outSet;
algorithm
outSet:=
matchcontinue (inComponentRef,inFace)
local
Exp.ComponentRef c;
Face d;
case (c,d) then FLOW({(c,d)});
end matchcontinue;
end newFlowSet;
protected function merge "
- Merging
The result of merging two connection sets is the intersection of
the two sets.
"
input Sets inSets1;
input Set inSet2;
input Set inSet3;
output Sets outSets;
algorithm
outSets:=
matchcontinue (inSets1,inSet2,inSet3)
local
list<Set> ss,ss_1;
list<Exp.ComponentRef> crs,cs,cs1,cs2,dc;
Set s1,s2;
list<OuterConnect> outerConn;
case (SETS(ss,crs,dc,outerConn),s1,s2)
equation
equality(s1 = s2);
then
SETS(ss,crs,dc,outerConn);
case (SETS(ss,crs,dc,outerConn),(s1 as EQU(expComponentRefLst = cs1)),(s2 as EQU(expComponentRefLst = cs2)))
equation
cs = listAppend(cs1, cs2);
SETS(ss_1,_,_,_) = removeSet2(SETS(ss,crs,dc,outerConn), s1, s2);
then
SETS((EQU(cs) :: ss_1),crs,dc,outerConn);
case (SETS(ss,crs,dc,outerConn),(s1 as FLOW(tplExpComponentRefFaceLst = cs1)),(s2 as FLOW(tplExpComponentRefFaceLst = cs2)))
local list<tuple<Exp.ComponentRef, Face>> cs,cs1,cs2;
equation
cs = listAppend(cs1, cs2);
SETS(ss_1,_,_,_) = removeSet2(SETS(ss,crs,dc,outerConn), s1, s2);
then
SETS((FLOW(cs) :: ss_1),crs,dc,outerConn);
end matchcontinue;
end merge;
protected function removeSet2 "function: removeSet2
This function removes the two sets given in the second and third
argument from the collection of sets given in the first argument.
"
input Sets inSets1;
input Set inSet2;
input Set inSet3;
output Sets outSets;
algorithm
outSets:=
matchcontinue (inSets1,inSet2,inSet3)
local
list<Exp.ComponentRef> crs,dc;
Sets ss_1;
Set s,s1,s2;
list<Set> ss;
list<OuterConnect> outerConn;
case (SETS({},crs,dc,outerConn),_,_) then SETS({},crs,dc,outerConn);
case (SETS((s :: ss),crs,dc,outerConn),s1,s2)