-
Notifications
You must be signed in to change notification settings - Fork 297
/
RemoveSimpleEquations.mo
5430 lines (5011 loc) · 223 KB
/
RemoveSimpleEquations.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package RemoveSimpleEquations "
file: RemoveSimpleEquations.mo
package: RemoveSimpleEquations
description: RemoveSimpleEquations contains functions to remove simple equations.
Simple equations are either alias equations or time independent equations.
Alias equations can be simplified to 'a = b', 'a = -b' or 'a = not b'.
The package contains three main functions.
fastAcausal: to remove with a linear scaling with respect to the
number of equations in an acausal system as much as
possible simple equations.
allAcausal: to remove all simple equations in an acausal system
the function may needs a lots of time.
causal: to remove with a linear scaling with respect to the
number of equations in an causal system all
simple equations"
public import Absyn;
public import BackendDAE;
public import DAE;
public import FCore;
protected
import AvlSetInt;
import BackendDAEUtil;
import BackendDump;
import BackendEquation;
import BackendVariable;
import BackendVarTransform;
import BaseHashSet;
import BaseHashTable;
import Ceval;
import ComponentReference;
import Debug;
import ElementSource;
import Error;
import EvaluateFunctions;
import Expression;
import ExpressionDump;
import ExpressionSimplify;
import ExpressionSolve;
import Flags;
import GC;
import HashSet;
import HashTableCrToCrEqLst;
import HashTableCrToExp;
import HashTableExpToIndex;
import List;
import SimCodeUtil;
import Types;
import Util;
protected type EquationSourceAndAttributes = tuple<DAE.ElementSource, BackendDAE.EquationAttributes> "eqnAttributes(source,EquationAttributes)";
protected
uniontype SimpleContainer
record ALIAS
DAE.ComponentRef cr1;
Boolean negatedCr1;
Integer i1;
DAE.ComponentRef cr2;
Boolean negatedCr2;
Integer i2;
EquationSourceAndAttributes eqnAttributes;
Integer visited;
end ALIAS;
record PARAMETERALIAS
DAE.ComponentRef unknowncr;
Boolean negatedCr1;
Integer i1;
DAE.ComponentRef paramcr;
Boolean negatedCr2;
Integer i2;
EquationSourceAndAttributes eqnAttributes;
Integer visited;
end PARAMETERALIAS;
record TIMEALIAS
DAE.ComponentRef cr1;
Boolean negatedCr1;
Integer i1;
DAE.ComponentRef cr2;
Boolean negatedCr2;
Integer i2;
EquationSourceAndAttributes eqnAttributes;
Integer visited;
end TIMEALIAS;
record TIMEINDEPENTVAR
DAE.ComponentRef cr;
Integer i;
DAE.Exp exp;
EquationSourceAndAttributes eqnAttributes;
Integer visited;
end TIMEINDEPENTVAR;
end SimpleContainer;
protected type AccTuple = tuple<BackendDAE.Variables, BackendDAE.Shared, list<BackendDAE.Equation>, list<SimpleContainer>, Integer, array<list<Integer>>, Boolean>;
protected type VarSetAttributes =
tuple<
Boolean,
tuple<Integer, list<tuple<Option<DAE.Exp>, DAE.ComponentRef>>>,
list<tuple<DAE.Exp, DAE.ComponentRef>>,
tuple<Option<DAE.Exp>,
Option<DAE.Exp>>
> "fixed, list<startvalue, origin, cr>, nominal, (min, max)";
protected constant VarSetAttributes EMPTYVARSETATTRIBUTES = (false, (-1, {}), {}, (NONE(), NONE()));
// =============================================================================
// Starting point for preOpt and postOpt removeSimpleEquations module
//
// =============================================================================
public function removeSimpleEquations "
This is the main function of 'remove simple equations' for both acausal and
causal systems."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
if BackendDAEUtil.hasDAEMatching(inDAE) then
// This case performs "remove simple equations" on a causal system.
// Note: It is fine to do some substitutions in order to minimize SCCs, but
// alias/known variable vectors may not be touched.
outDAE := match(Flags.getConfigString(Flags.REMOVE_SIMPLE_EQUATIONS))
case "default" then causal(inDAE);
case "causal" then causal(inDAE);
case "new" then performAliasEliminationBB(inDAE, findAliases=true);
else inDAE;
end match;
outDAE := fixAliasVars(outDAE) "workaround for #3323";
outDAE := fixAliasAndKnownVarsCausal(inDAE, outDAE);
else
// This case performs "remove simple equations" on an acausal system.
outDAE := match(Flags.getConfigString(Flags.REMOVE_SIMPLE_EQUATIONS))
case "default" then fastAcausal(inDAE);
case "fastAcausal" then fastAcausal(inDAE);
case "allAcausal" then allAcausal(inDAE);
case "new" then performAliasEliminationBB(inDAE, true);
else inDAE;
end match;
outDAE := fixAliasVars(outDAE) "workaround for #3323";
outDAE := fixKnownVars(outDAE);
end if;
end removeSimpleEquations;
public function removeVerySimpleEquations "This is a very simple removeSimpleEquations, finding a few variables and removing them to speed up the rest of the backend"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
if BackendDAEUtil.hasDAEMatching(inDAE) then
Error.addInternalError("Cannot run removeVerySimpleEquations on a matched system (continuing anyway)", sourceInfo());
outDAE := inDAE;
else
outDAE := performAliasEliminationBB(inDAE, findAliases=true);
end if;
end removeVerySimpleEquations;
protected function fixAliasVars "author: lochel
This is a workaround for #3323
TODO: Remove this once removeSimpleEquations is implemented properly.
This module traverses all alias variables and double-checks if they are alias or known variables."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.Variables aliasVars;
list<BackendDAE.Var> aliasVarList = {};
list<BackendDAE.Var> knownVarList;
DAE.Exp binding;
algorithm
aliasVars := BackendDAEUtil.getAliasVars(inDAE);
knownVarList := BackendVariable.varList(BackendDAEUtil.getGlobalKnownVarsFromDAE(inDAE));
for var in BackendVariable.varList(aliasVars) loop
binding := BackendVariable.varBindExp(var);
if Expression.isConst(binding) then
knownVarList := var::knownVarList;
else
aliasVarList := var::aliasVarList;
end if;
end for;
outDAE := BackendDAEUtil.setAliasVars(inDAE, BackendVariable.listVar(aliasVarList));
outDAE := BackendDAEUtil.setDAEGlobalKnownVars(outDAE, BackendVariable.listVar(knownVarList));
end fixAliasVars;
protected function fixKnownVars "author: lochel
This is a workaround.
TODO: Remove this once removeSimpleEquations is implemented properly.
This module traverses all known variables and double-checks if they are known or not."
input output BackendDAE.BackendDAE dae;
protected
BackendDAE.EqSystem eqs;
BackendDAE.Variables globalKnownVars;
DAE.Exp binding;
list<BackendDAE.Equation> eqnList = {};
list<BackendDAE.Var> varList = {};
list<BackendDAE.Var> knownVarList = {};
list<DAE.ComponentRef> crlst;
algorithm
globalKnownVars := dae.shared.globalKnownVars;
for var in BackendVariable.varList(globalKnownVars) loop
if BackendVariable.varHasBindExp(var) then
binding := BackendVariable.varBindExp(var);
(_, crlst) := Expression.traverseExpTopDown(binding, Expression.traversingComponentRefFinderNoPreDer, {});
if BackendDAEUtil.containAnyVar(crlst, dae.shared.localKnownVars) then
varList := BackendVariable.setBindExp(var, NONE())::varList;
eqnList := BackendDAE.EQUATION(BackendVariable.varExp(var), binding, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_BINDING)::eqnList;
else
knownVarList := var::knownVarList;
end if;
else
knownVarList := var::knownVarList;
end if;
end for;
if not listEmpty(varList) then
eqs := BackendDAEUtil.createEqSystem(BackendVariable.listVar(varList), BackendEquation.listEquation(eqnList), {}, BackendDAE.UNSPECIFIED_PARTITION());
dae.eqs := eqs::dae.eqs;
end if;
dae := BackendDAEUtil.setDAEGlobalKnownVars(dae, BackendVariable.listVar(knownVarList));
end fixKnownVars;
protected function fixAliasAndKnownVarsCausal "author: lochel
TODO: Remove this once removeSimpleEquations is implemented properly.
This module moves back all newly introduced alias variables to the correct partition."
input BackendDAE.BackendDAE inDAE1 "original dae";
input BackendDAE.BackendDAE inDAE2 "transformed dae";
output BackendDAE.BackendDAE outDAE = inDAE2;
protected
BackendDAE.Variables aliasVars1, knownVars1;
BackendDAE.Variables aliasVars2, knownVars2;
list<BackendDAE.Var> aliasVarList = {};
list<BackendDAE.Var> knownVarList = {};
DAE.ComponentRef cref;
algorithm
aliasVars1 := BackendDAEUtil.getAliasVars(inDAE1);
aliasVars2 := BackendDAEUtil.getAliasVars(inDAE2);
knownVars1 := BackendDAEUtil.getGlobalKnownVarsFromDAE(inDAE1);
knownVars2 := BackendDAEUtil.getGlobalKnownVarsFromDAE(inDAE2);
for var in BackendVariable.varList(aliasVars2) loop
cref := BackendVariable.varCref(var);
if not BackendVariable.existsVar(cref, aliasVars1, false) then
// put var back to the correct partition
outDAE := fixAliasVarsCausal2(var, outDAE);
else
aliasVarList := var::aliasVarList;
end if;
end for;
outDAE := BackendDAEUtil.setAliasVars(outDAE, BackendVariable.listVar(aliasVarList));
//BackendDump.dumpVarList(knownVarList, "knownVarList in");
for var in BackendVariable.varList(knownVars2) loop
cref := BackendVariable.varCref(var);
if not BackendVariable.existsVar(cref, knownVars1, false) and
not (BackendVariable.isInput(var) or BackendVariable.isAlgebraicOldState(var)) then
// put var back to the correct partition
outDAE := fixKnownVarsCausal2(var, outDAE);
else
knownVarList := var::knownVarList;
end if;
end for;
//BackendDump.dumpVarList(knownVarList, "knownVarList out");
outDAE := BackendDAEUtil.setDAEGlobalKnownVars(outDAE, BackendVariable.listVar(knownVarList));
end fixAliasAndKnownVarsCausal;
protected function fixAliasVarsCausal2
input BackendDAE.Var inVar;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
DAE.Exp binding;
list<DAE.ComponentRef> rightCrefs;
BackendDAE.EqSystems eqs, eqs1 = {};
BackendDAE.Shared shared;
Boolean done=false;
BackendDAE.Var var;
BackendDAE.Equation eqn;
BackendDAE.Variables orderedVars "ordered Variables, only states and alg. vars";
BackendDAE.EquationArray orderedEqs "ordered Equations";
algorithm
try
binding := BackendVariable.varBindExp(inVar);
rightCrefs := Expression.getAllCrefs(binding);
BackendDAE.DAE(eqs, shared) := inDAE;
var := BackendVariable.setBindExp(inVar, NONE());
var := BackendVariable.setVarFixed(var, false) "??? should we do this ???";
eqn := BackendDAE.EQUATION(BackendVariable.varExp(var), binding, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_BINDING);
for eq in eqs loop
BackendDAE.EQSYSTEM(orderedVars=orderedVars, orderedEqs=orderedEqs) := eq;
if BackendVariable.existsAnyVar(rightCrefs, orderedVars, false) then
orderedVars := BackendVariable.addVar(var, orderedVars);
orderedEqs := BackendEquation.add(eqn, orderedEqs);
eqs1 := BackendDAEUtil.setEqSystEqs(BackendDAEUtil.setEqSystVars(eq, orderedVars), orderedEqs)::eqs1;
false := done;
done := true;
else
eqs1 := eq::eqs1;
end if;
end for;
// if no partition was selected, create a new one
if not done then
eqs1 := BackendDAEUtil.createEqSystem( BackendVariable.listVar({var}), BackendEquation.listEquation({eqn}),
{}, BackendDAE.UNSPECIFIED_PARTITION() )::eqs1;
end if;
outDAE := BackendDAE.DAE(listReverse(eqs1), shared);
//BackendDump.dumpVarList({inVar}, "fixAliasVarsCausal2 done for ...");
else
BackendDump.dumpVarList({inVar}, "fixAliasVarsCausal2 failed for ...");
Error.addCompilerError("fixAliasVarsCausal2 failed");
fail();
end try;
end fixAliasVarsCausal2;
protected function fixKnownVarsCausal2
input BackendDAE.Var inVar;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
DAE.Exp binding;
list<DAE.ComponentRef> rightCrefs;
BackendDAE.EqSystems eqs1 = {};
Boolean done=false;
BackendDAE.Var var;
BackendDAE.Equation eqn;
BackendDAE.Variables orderedVars "ordered Variables, only states and alg. vars";
BackendDAE.EquationArray orderedEqs "ordered Equations";
algorithm
try
binding := BackendVariable.varBindExp(inVar);
rightCrefs := Expression.getAllCrefs(binding);
var := BackendVariable.setBindExp(inVar, NONE());
eqn := BackendDAE.EQUATION(BackendVariable.varExp(var), binding, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_BINDING);
for eq in inDAE.eqs loop
BackendDAE.EQSYSTEM(orderedVars=orderedVars, orderedEqs=orderedEqs) := eq;
if BackendVariable.existsAnyVar(rightCrefs, orderedVars, false) then
orderedVars := BackendVariable.addVar(var, orderedVars);
orderedEqs := BackendEquation.add(eqn, orderedEqs);
eqs1 := BackendDAEUtil.setEqSystEqs(BackendDAEUtil.setEqSystVars(eq, orderedVars), orderedEqs)::eqs1;
false := done;
done := true;
else
eqs1 := eq::eqs1;
end if;
end for;
// if no partition was selected, create a new one
if not done then
eqs1 := BackendDAEUtil.createEqSystem( BackendVariable.listVar({var}), BackendEquation.listEquation({eqn}),
{}, BackendDAE.UNSPECIFIED_PARTITION() )::eqs1;
end if;
outDAE := BackendDAE.DAE(listReverse(eqs1), inDAE.shared);
else
BackendDump.dumpVarList({inVar}, "fixKnownVarsCausal2 failed for ...");
Error.addCompilerError("fixKnownVarsCausal2 failed");
fail();
end try;
end fixKnownVarsCausal2;
// =============================================================================
// section for fastAcausal
//
// =============================================================================
public function fastAcausal "author: Frenkel TUD 2012-12
This Function remove with a linear scaling with respect to the number of
equations in an acausal system as much as possible simple equations."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendVarTransform.VariableReplacements repl;
Boolean b, warnAliasConflicts;
Integer size;
HashSet.HashSet unReplaceable;
algorithm
// get the size of the system to set up the replacement hashmap
size := BackendDAEUtil.daeSize(inDAE);
size := intMax(BaseHashTable.defaultBucketSize, realInt(realMul(intReal(size), 0.7)));
repl := BackendVarTransform.emptyReplacementsSized(size);
// check for unReplaceable crefs
unReplaceable := HashSet.emptyHashSet();
unReplaceable := BackendDAEUtil.foldEqSystem(inDAE, addUnreplaceable, unReplaceable);
((_,unReplaceable)) := BackendDAEUtil.traverseBackendDAEExps(inDAE, Expression.traverseSubexpressionsHelper, (traverserExpUnreplaceable, unReplaceable));
unReplaceable := addUnreplaceableFromWhens(inDAE, unReplaceable);
if Flags.isSet(Flags.DUMP_REPL) then
BackendDump.dumpHashSet(unReplaceable, "Unreplaceable Crefs:");
end if;
// traverse all systems and remove simple equations
(outDAE, (repl, b, _, _, warnAliasConflicts)) := BackendDAEUtil.mapEqSystemAndFold(inDAE, fastAcausal1, (repl, false, unReplaceable, Flags.getConfigInt(Flags.MAXTRAVERSALS), false));
if warnAliasConflicts and BackendDAEUtil.isSimulationDAE(inDAE.shared) then
Error.addMessage(Error.CONFLICTING_ALIAS_SET, {});
end if;
// traverse the shared parts
outDAE := removeSimpleEquationsShared(b, outDAE, repl);
end fastAcausal;
protected function addUnreplaceable
input BackendDAE.EqSystem syst;
input BackendDAE.Shared shared;
input HashSet.HashSet inUnreplaceable;
output HashSet.HashSet outUnreplaceable = inUnreplaceable;
protected
BackendDAE.Variables orderedVars;
algorithm
BackendDAE.EQSYSTEM(orderedVars=orderedVars) := syst;
for var in BackendVariable.varList(orderedVars) loop
if BackendVariable.varUnreplaceable(var) then
outUnreplaceable := BaseHashSet.add(BackendVariable.varCref(var), outUnreplaceable);
end if;
end for;
end addUnreplaceable;
protected function fastAcausal1 "author: Frenkel TUD 2012-12
traverse an Equations system to remove simple equations"
input BackendDAE.EqSystem inSystem;
input BackendDAE.Shared inShared;
input tuple<BackendVarTransform.VariableReplacements, Boolean, HashSet.HashSet, Integer, Boolean> inTpl;
output BackendDAE.EqSystem outSystem = BackendDAEUtil.copyEqSystem(inSystem);
output BackendDAE.Shared outShared;
output tuple<BackendVarTransform.VariableReplacements, Boolean, HashSet.HashSet, Integer, Boolean> outTpl;
protected
BackendVarTransform.VariableReplacements repl;
HashSet.HashSet unReplaceable;
list<BackendDAE.Equation> eqnslst;
list<SimpleContainer> simpleeqnslst;
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
array<list<Integer>> mT; //[varIdx] = simpleContainer
Boolean foundSimple, globalFoundSimple, warnAliasConflicts;
Integer maxTraversals;
algorithm
// Don't apply removeSimpleEquations to clocked partitions
if BackendDAEUtil.isClockedSyst(inSystem) then
outSystem := inSystem;
outShared := inShared;
outTpl := inTpl;
return;
end if;
try
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns) := outSystem;
((repl, globalFoundSimple, unReplaceable, maxTraversals, warnAliasConflicts)) := inTpl;
// transform to list, this is later not neccesary because the acausal system should save the equations as list
eqnslst := BackendEquation.equationList(eqns);
mT := arrayCreate(BackendVariable.varsSize(vars), {});
// check equations
((_, _, eqnslst, simpleeqnslst, _, _, foundSimple)) := List.fold( eqnslst, simpleEquationsFinder,
(vars, inShared, {}, {}, 1, mT, false) );
//print("Found "+intString(listLength(simpleeqnslst))+" SimpleEquationsContainers\n");
//print(stringDelimitList(List.map(simpleeqnslst, dumpSimpleContainer),"\n")+"\n");
(vars, outShared, repl, unReplaceable, eqnslst, globalFoundSimple, warnAliasConflicts) := causalFinder(foundSimple, simpleeqnslst, eqnslst, 1, maxTraversals, vars, inShared, repl, unReplaceable, mT, {}, globalFoundSimple, warnAliasConflicts);
outSystem := updateSystem(globalFoundSimple, eqnslst, vars, repl, outSystem);
outTpl := ((repl, globalFoundSimple, unReplaceable, maxTraversals, warnAliasConflicts));
GC.free(mT);
else
//Error.addCompilerWarning("The module removeSimpleEquations failed for a subsystem. The relevant subsystem get skipped and the transformation is proceeded.");
outSystem := inSystem;
outShared := inShared;
outTpl := inTpl;
end try;
end fastAcausal1;
protected function causalFinder "author: Frenkel TUD 2012-12"
input Boolean foundSimple;
input list<SimpleContainer> simpleContainerIn;
input list<BackendDAE.Equation> iEqnslst;
input Integer traversalIdx;
input Integer maxTraversals;
input BackendDAE.Variables iVars;
input BackendDAE.Shared ishared;
input BackendVarTransform.VariableReplacements iRepl;
input HashSet.HashSet iUnreplaceable;
input array<list<Integer>> iMT;
input list<BackendDAE.Equation> iGlobalEqnslst;
input Boolean inGlobalFoundSimple;
output BackendDAE.Variables outVars = iVars;
output BackendDAE.Shared outShared = ishared;
output BackendVarTransform.VariableReplacements outRepl = iRepl;
output HashSet.HashSet outUnReplaceable = iUnreplaceable;
output list<BackendDAE.Equation> outEqnslst;
output Boolean outGlobalFoundSimple = inGlobalFoundSimple;
input output Boolean warnAliasConflicts;
protected
BackendDAE.Variables vars;
BackendVarTransform.VariableReplacements repl;
Boolean b, b1;
array<SimpleContainer> simpleContainer;
list<BackendDAE.Equation> eqnslst;
BackendDAE.Shared shared;
algorithm
if foundSimple then
// transform simpleeqns to array
simpleContainer := List.listArrayReverse(simpleContainerIn);
// collect and handle sets
(vars, eqnslst, shared, repl, b) := handleSets(arrayLength(simpleContainer), 1, simpleContainer, iMT, iUnreplaceable, iVars, iEqnslst, ishared, iRepl);
warnAliasConflicts := warnAliasConflicts or b;
// perform replacements and try again
(eqnslst, b1) := BackendVarTransform.replaceEquations(eqnslst, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst, warnAliasConflicts) := causalFinder1(intGt(traversalIdx, maxTraversals), b1, eqnslst, traversalIdx+1, maxTraversals, vars, shared, repl, iUnreplaceable, iMT, iGlobalEqnslst, inGlobalFoundSimple, warnAliasConflicts);
outGlobalFoundSimple := true;
else
outEqnslst := listAppend(iEqnslst, iGlobalEqnslst);
end if;
end causalFinder;
protected function causalFinder1 "author: Frenkel TUD 2012-12"
input Boolean finished "index > traversal";
input Boolean b;
input list<BackendDAE.Equation> iEqnslst;
input Integer index;
input Integer maxTraversals;
input BackendDAE.Variables iVars;
input BackendDAE.Shared ishared;
input BackendVarTransform.VariableReplacements iRepl;
input HashSet.HashSet iUnreplaceable;
input array<list<Integer>> iMT;
input list<BackendDAE.Equation> iGlobalEqnslst;
input Boolean inGlobalFoundSimple;
output BackendDAE.Variables outVars = iVars;
output BackendDAE.Shared outShared = ishared;
output BackendVarTransform.VariableReplacements outRepl = iRepl;
output HashSet.HashSet outUnReplaceable = iUnreplaceable;
output list<BackendDAE.Equation> outEqnslst = listAppend(iEqnslst, iGlobalEqnslst);
input output Boolean warnAliasConflicts;
algorithm
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst) :=
match (finished, b, iEqnslst, index, iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst)
local
Boolean b1;
list<BackendDAE.Equation> eqnslst;
list<SimpleContainer> simpleeqnslst;
BackendDAE.Variables vars;
BackendDAE.Shared shared;
case(true, _, _, _, _, _, _, _, _) then (iVars, ishared, iRepl, iUnreplaceable, listAppend(iEqnslst, iGlobalEqnslst));
case(_, false, {}, _, _, _, _, _, _) then (iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst);
case(_, false, _, _, _, _, _, _, _) then (iVars, ishared, iRepl, iUnreplaceable, listAppend(iEqnslst, iGlobalEqnslst));
case(_, true, _, _, _, _, _, _, _)
equation
((vars, shared, eqnslst, simpleeqnslst, _, _, b1)) = List.fold(iEqnslst, simpleEquationsFinder, (iVars, ishared, {}, {}, 1, iMT, false));
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst, _, warnAliasConflicts) = causalFinder(b1, simpleeqnslst, eqnslst, index, maxTraversals, vars, shared, iRepl, iUnreplaceable, iMT, iGlobalEqnslst, inGlobalFoundSimple, warnAliasConflicts);
then
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst);
end match;
end causalFinder1;
// =============================================================================
// section for allAcausal
//
// =============================================================================
public function allAcausal "author: Frenkel TUD 2012-12"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendVarTransform.VariableReplacements repl;
Boolean b, warnAliasConflicts;
Integer size;
HashSet.HashSet unReplaceable;
algorithm
// get the size of the system to set up the replacement hashmap
size := BackendDAEUtil.daeSize(inDAE);
size := intMax(BaseHashTable.defaultBucketSize, realInt(realMul(intReal(size), 0.7)));
repl := BackendVarTransform.emptyReplacementsSized(size);
// check for unReplaceable crefs
unReplaceable := HashSet.emptyHashSet();
unReplaceable := BackendDAEUtil.foldEqSystem(inDAE, addUnreplaceable, unReplaceable);
((_,unReplaceable)) := BackendDAEUtil.traverseBackendDAEExps(inDAE, Expression.traverseSubexpressionsHelper, (traverserExpUnreplaceable, unReplaceable));
unReplaceable := addUnreplaceableFromWhens(inDAE, unReplaceable);
if Flags.isSet(Flags.DUMP_REPL) then
BackendDump.dumpHashSet(unReplaceable, "Unreplaceable Crefs:");
end if;
(outDAE, (repl, _, b, warnAliasConflicts)) := BackendDAEUtil.mapEqSystemAndFold(inDAE, allAcausal1, (repl, unReplaceable, false, false));
if warnAliasConflicts and BackendDAEUtil.isSimulationDAE(inDAE.shared) then
Error.addMessage(Error.CONFLICTING_ALIAS_SET, {});
end if;
outDAE := removeSimpleEquationsShared(b, outDAE, repl);
// until remove simple equations does not update assignments and comps remove them
end allAcausal;
protected function allAcausal1 "author: Frenkel TUD 2012-12
This function moves simple equations on the form a=b and a=const and
a=f(not time) in BackendDAE.BackendDAE to get speed up"
input BackendDAE.EqSystem inSystem;
input BackendDAE.Shared inShared;
input tuple<BackendVarTransform.VariableReplacements, HashSet.HashSet, Boolean, Boolean> inTpl;
output BackendDAE.EqSystem outSystem;
output BackendDAE.Shared outShared;
output tuple<BackendVarTransform.VariableReplacements, HashSet.HashSet, Boolean, Boolean> outTpl;
protected
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
BackendVarTransform.VariableReplacements repl;
HashSet.HashSet unReplaceable;
Boolean b, b1, warnAliasConflicts;
array<list<Integer>> mT;
list<BackendDAE.Equation> eqnslst;
BackendDAE.EqSystem syst;
algorithm
// Don't apply removeSimpleEquations to clocked partitions
if BackendDAEUtil.isClockedSyst(inSystem) then
outSystem := inSystem;
outShared := inShared;
outTpl := inTpl;
return;
end if;
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns) := inSystem;
((repl, unReplaceable, b1, warnAliasConflicts)) := inTpl;
// transform to list, this is later not neccesary because the acausal system should save the equations as list
eqnslst := BackendEquation.equationList(eqns);
mT := arrayCreate(BackendVariable.varsSize(vars), {});
// check equations
((vars, outShared, repl, unReplaceable, _, eqnslst, b, warnAliasConflicts)) := allCausalFinder(eqnslst, (vars, inShared, repl, unReplaceable, mT, {}, false, warnAliasConflicts));
outSystem := updateSystem(b, eqnslst, vars, repl, inSystem);
outTpl := ((repl, unReplaceable, b or b1, warnAliasConflicts));
end allAcausal1;
// =============================================================================
// section for causal
//
// =============================================================================
public function causal "author: Frenkel TUD 2012-12"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendVarTransform.VariableReplacements repl;
Boolean b, warnAliasConflicts;
Integer size;
HashSet.HashSet unReplaceable;
algorithm
// get the size of the system to set up the replacement hashmap
size := BackendDAEUtil.daeSize(inDAE);
size := intMax(BaseHashTable.defaultBucketSize, realInt(realMul(intReal(size), 0.7)));
repl := BackendVarTransform.emptyReplacementsSized(size);
// check for unReplaceable crefs
unReplaceable := HashSet.emptyHashSet();
unReplaceable := BackendDAEUtil.foldEqSystem(inDAE, addUnreplaceable, unReplaceable);
((_,unReplaceable)) := BackendDAEUtil.traverseBackendDAEExps(inDAE, Expression.traverseSubexpressionsHelper, (traverserExpUnreplaceable, unReplaceable));
unReplaceable := addUnreplaceableFromWhens(inDAE, unReplaceable);
// do not replace state sets
unReplaceable := addUnreplaceableFromStateSets(inDAE, unReplaceable);
if Flags.isSet(Flags.DUMP_REPL) then
BackendDump.dumpHashSet(unReplaceable, "Unreplaceable Crefs:");
end if;
(outDAE, (repl, _, b, warnAliasConflicts)) := BackendDAEUtil.mapEqSystemAndFold(inDAE, causal1, (repl, unReplaceable, false, false));
if warnAliasConflicts and BackendDAEUtil.isSimulationDAE(inDAE.shared) then
Error.addMessage(Error.CONFLICTING_ALIAS_SET, {});
end if;
outDAE := removeSimpleEquationsShared(b, outDAE, repl);
// until remove simple equations does not update assignments and comps remove them
end causal;
protected function causal1 "author: Frenkel TUD 2012-12
This function moves simple equations on the form a=b and a=const and
a=f(not time) in BackendDAE.BackendDAE to get speed up"
input BackendDAE.EqSystem inSystem;
input BackendDAE.Shared inShared;
input tuple<BackendVarTransform.VariableReplacements, HashSet.HashSet, Boolean, Boolean> inTpl;
output BackendDAE.EqSystem outSystem;
output BackendDAE.Shared outShared;
output tuple<BackendVarTransform.VariableReplacements, HashSet.HashSet, Boolean, Boolean> outTpl;
protected
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
BackendDAE.StrongComponents comps;
BackendVarTransform.VariableReplacements repl;
HashSet.HashSet unReplaceable;
Boolean b, b1, warnAliasConflicts;
array<list<Integer>> mT;
list<BackendDAE.Equation> eqnslst;
BackendDAE.EqSystem syst;
algorithm
// Don't apply removeSimpleEquations to clocked partitions
if BackendDAEUtil.isClockedSyst(inSystem) then
outSystem := inSystem;
outShared := inShared;
outTpl := inTpl;
return;
end if;
BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns, matching=BackendDAE.MATCHING(comps=comps)) := inSystem;
((repl, unReplaceable, b1, warnAliasConflicts)) := inTpl;
mT := arrayCreate(BackendVariable.varsSize(vars), {});
// check equations
((vars, outShared, repl, unReplaceable, _, eqnslst, b, warnAliasConflicts)) := traverseComponents(comps, eqns, allCausalFinder, (vars, inShared, repl, unReplaceable, mT, {}, false, warnAliasConflicts));
outSystem := updateSystem(b, eqnslst, vars, repl, inSystem);
outTpl := ((repl, unReplaceable, b or b1, warnAliasConflicts));
end causal1;
protected function traverseComponents "author: Frenkel TUD 2010-12"
replaceable type Type_a subtypeof Any;
input BackendDAE.StrongComponents inComps;
input BackendDAE.EquationArray iEqns;
input FuncType inFunc;
input Type_a inTypeA;
output Type_a outTypeA;
partial function FuncType
input list<BackendDAE.Equation> iEqns;
input Type_a inTypeA;
output Type_a outTypeA;
end FuncType;
algorithm
outTypeA :=
match(inComps, iEqns, inFunc, inTypeA)
local
Integer e;
list<Integer> elst;
BackendDAE.StrongComponent comp;
BackendDAE.StrongComponents rest;
BackendDAE.Equation eqn;
list<BackendDAE.Equation> eqnlst, eqnlst1;
BackendDAE.InnerEquations innerEquations;
BackendDAE.InnerEquation innerEquation;
Type_a arg;
case ({}, _, _, _) then inTypeA;
case (BackendDAE.SINGLEEQUATION(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.EQUATIONSYSTEM(eqns=elst)::rest, _, _, _)
equation
eqnlst = BackendEquation.getList(elst, iEqns);
arg = inFunc(eqnlst, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.SINGLEARRAY(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.SINGLEIFEQUATION(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.SINGLEALGORITHM(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.SINGLECOMPLEXEQUATION(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.SINGLEWHENEQUATION(eqn=e)::rest, _, _, _)
equation
eqn = BackendEquation.get(iEqns, e);
arg = inFunc({eqn}, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=elst, innerEquations=innerEquations))::rest, _, _, _)
equation
// collect all equations
eqnlst = BackendEquation.getList(elst, iEqns);
(elst,_,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
eqnlst1 = BackendEquation.getList(elst, iEqns);
eqnlst = listAppend(eqnlst, eqnlst1);
arg = inFunc(eqnlst, inTypeA);
then
traverseComponents(rest, iEqns, inFunc, arg);
end match;
end traverseComponents;
protected function allCausalFinder "author: Frenkel TUD 2012-12"
input list<BackendDAE.Equation> eqns;
input tuple<BackendDAE.Variables, BackendDAE.Shared, BackendVarTransform.VariableReplacements, HashSet.HashSet, array<list<Integer>>, list<BackendDAE.Equation>, Boolean, Boolean> inTpl;
output tuple<BackendDAE.Variables, BackendDAE.Shared, BackendVarTransform.VariableReplacements, HashSet.HashSet, array<list<Integer>>, list<BackendDAE.Equation>, Boolean, Boolean> outTpl;
protected
BackendDAE.Variables vars;
BackendDAE.Shared shared;
BackendVarTransform.VariableReplacements repl;
HashSet.HashSet unReplaceable;
array<list<Integer>> mt;
Boolean b, b1, b2, b3, globalFoundSimple, warnAliasConflicts;
list<BackendDAE.Equation> globaleqnslst, eqnslst;
list<SimpleContainer> simpleeqnslst;
algorithm
(vars, shared, repl, unReplaceable, mt, globaleqnslst, b, warnAliasConflicts) := inTpl;
(eqnslst, b2) := BackendVarTransform.replaceEquations(eqns, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
((_, _, eqnslst, simpleeqnslst, _, _, b1)) := List.fold(eqnslst, simpleEquationsFinder, (vars, shared, {}, {}, 1, mt, false));
(vars, shared, repl, unReplaceable, eqnslst, globalFoundSimple, b3) := allCausalFinder1(b1, b2, simpleeqnslst, eqnslst, vars, shared, repl, unReplaceable, mt, globaleqnslst, b, warnAliasConflicts);
warnAliasConflicts := warnAliasConflicts or b3;
outTpl := (vars, shared, repl, unReplaceable, mt, eqnslst, globalFoundSimple, warnAliasConflicts);
end allCausalFinder;
protected function allCausalFinder1 "author: Frenkel TUD 2012-12"
input Boolean foundSimple;
input Boolean didReplacement;
input list<SimpleContainer> iSimpleeqnslst;
input list<BackendDAE.Equation> iEqnslst;
input BackendDAE.Variables iVars;
input BackendDAE.Shared ishared;
input BackendVarTransform.VariableReplacements iRepl;
input HashSet.HashSet iUnreplaceable;
input array<list<Integer>> iMT;
input list<BackendDAE.Equation> iGlobalEqnslst;
input Boolean globalFoundSimple;
output BackendDAE.Variables outVars;
output BackendDAE.Shared outShared;
output BackendVarTransform.VariableReplacements outRepl;
output HashSet.HashSet outUnReplaceable;
output list<BackendDAE.Equation> outEqnslst;
output Boolean outGlobalFoundSimple;
input output Boolean warnAliasConflicts;
algorithm
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst, outGlobalFoundSimple, warnAliasConflicts) :=
match (foundSimple, didReplacement, iSimpleeqnslst, iEqnslst, iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst, globalFoundSimple)
local
BackendDAE.Variables vars;
BackendVarTransform.VariableReplacements repl;
Boolean b, b1;
array<SimpleContainer> simpleeqns;
list<BackendDAE.Equation> eqnslst;
BackendDAE.Shared shared;
case (false, _, _, {}, _, _, _, _, _, _)
then (iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst, didReplacement or globalFoundSimple, warnAliasConflicts);
case (false, _, _, _, _, _, _, _, _, _)
then (iVars, ishared, iRepl, iUnreplaceable, listAppend(iEqnslst, iGlobalEqnslst), didReplacement or globalFoundSimple, warnAliasConflicts);
case (true, _, _, _, _, _, _, _, _, _)
equation
// transform simpleeqns to array
simpleeqns = List.listArrayReverse(iSimpleeqnslst);
// collect and handle sets
(vars, eqnslst, shared, repl, b) = handleSets(arrayLength(simpleeqns), 1, simpleeqns, iMT, iUnreplaceable, iVars, iEqnslst, ishared, iRepl);
warnAliasConflicts = warnAliasConflicts or b;
// perform replacements and try again
(eqnslst, b1) = BackendVarTransform.replaceEquations(eqnslst, repl, SOME(BackendVarTransform.skipPreChangeEdgeOperator));
then
allCausalFinder2(b1, eqnslst, vars, shared, repl, iUnreplaceable, iMT, iGlobalEqnslst, true, warnAliasConflicts);
end match;
end allCausalFinder1;
protected function allCausalFinder2 "author: Frenkel TUD 2012-12"
input Boolean b;
input list<BackendDAE.Equation> iEqnslst;
input BackendDAE.Variables iVars;
input BackendDAE.Shared ishared;
input BackendVarTransform.VariableReplacements iRepl;
input HashSet.HashSet iUnreplaceable;
input array<list<Integer>> iMT;
input list<BackendDAE.Equation> iGlobalEqnslst;
input Boolean globalFoundSimple;
output BackendDAE.Variables outVars;
output BackendDAE.Shared outShared;
output BackendVarTransform.VariableReplacements outRepl;
output HashSet.HashSet outUnReplaceable;
output list<BackendDAE.Equation> outEqnslst;
output Boolean outGlobalFoundSimple;
input output Boolean warnAliasConflicts;
algorithm
(outVars, outShared, outRepl, outUnReplaceable, outEqnslst, outGlobalFoundSimple, warnAliasConflicts) :=
match (b, iEqnslst, iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst, globalFoundSimple)
local
Boolean b1;
list<BackendDAE.Equation> eqnslst;
list<SimpleContainer> simpleeqnslst;
BackendDAE.Variables vars;
BackendDAE.Shared shared;
case(false, {}, _, _, _, _, _, _) then (iVars, ishared, iRepl, iUnreplaceable, iGlobalEqnslst, globalFoundSimple, warnAliasConflicts);
case(false, _, _, _, _, _, _, _) then (iVars, ishared, iRepl, iUnreplaceable, listAppend(iEqnslst, iGlobalEqnslst), globalFoundSimple, warnAliasConflicts);
case(true, _, _, _, _, _, _, _)
equation
((vars, shared, eqnslst, simpleeqnslst, _, _, b1)) = List.fold(iEqnslst, simpleEquationsFinder, (iVars, ishared, {}, {}, 1, iMT, false));
then
allCausalFinder1(b1, false, simpleeqnslst, eqnslst, vars, shared, iRepl, iUnreplaceable, iMT, iGlobalEqnslst, globalFoundSimple, warnAliasConflicts);
end match;
end allCausalFinder2;
// =============================================================================
// functions to find simple equations
//
// =============================================================================
protected function simpleEquationsFinder "author: Frenkel TUD 2012-12
map from equation to lhs and rhs"
input BackendDAE.Equation eqn;
input AccTuple inTpl;
output AccTuple outTpl;
algorithm
outTpl:=
matchcontinue (eqn, inTpl)
local
DAE.ComponentRef cr;
DAE.Exp e1, e2;
DAE.ElementSource source;
BackendDAE.Variables v;
BackendDAE.Shared s;
list<BackendDAE.Equation> eqns;
list<SimpleContainer> seqns;
Integer index;
array<list<Integer>> mT;
Boolean b;
BackendDAE.EquationAttributes eqAttr;
case (BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, attr=eqAttr), _)
equation
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrExpStrExpStr("Found Equation ", e1, " = ", e2, " to handle.\n");
end if;
then
simpleEquationAcausal(e1, e2, (source, eqAttr), false, inTpl);
case (BackendDAE.ARRAY_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _)
equation
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrExpStrExpStr("Found Array Equation ", e1, " = ", e2, " to handle.\n");
end if;
then
simpleArrayEquationAcausal(e1, e2, Expression.typeof(e1), (source, eqAttr), inTpl);
case (BackendDAE.SOLVED_EQUATION(componentRef=cr, exp=e2, source=source, attr=eqAttr), _)
equation
e1 = Expression.crefExp(cr);
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrExpStrExpStr("Found Solved Equation ", e1, " = ", e2, " to handle.\n");
end if;
then
simpleEquationAcausal(e1, e2, (source, eqAttr), false, inTpl);
case (BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, attr=eqAttr), _)
equation
if Flags.isSet(Flags.DEBUG_ALIAS) then
BackendDump.debugStrExpStr("Found Residual Equation ", e1, " to handle.\n");
end if;
then
simpleExpressionAcausal(e1, (source, eqAttr), false, inTpl);
case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2, source=source, attr=eqAttr), _)
equation
if Flags.isSet(Flags.DEBUG_ALIAS) then