-
Notifications
You must be signed in to change notification settings - Fork 297
/
testArrayEquations.mos
250 lines (244 loc) · 7.8 KB
/
testArrayEquations.mos
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
// name: testArrayEquations
// keywords: array equations, for loops
// status: correct
// teardown_command: rm -f *ArrayEquationsTest*
// cflags: -d=-newInst
setCommandLineOptions("--std=3.3"); getErrorString();
setCommandLineOptions("-d=newInst,-nfScalarize,dumpSimCode"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
loadString("
model ArrayEquationsTest
function myfor
input Real[:] u;
input Real[size(u, 1)] previous_x;
input Boolean isFirstTick;
output Real[size(u, 1)] x;
algorithm
for i in 1:size(u,1) loop
x[i] := if isFirstTick then previous_x[i] else previous_x[i] + u[i];
end for;
end myfor;
parameter Integer n = 10;
input Real[n] u(start = 1:n);
Real[n] x1(each start = 1);
Real[n] x2(each start = 2);
Real[n] x3(each start = 3);
Real[n] x4(each start = 4);
output Real y1, y2, y3, y4;
equation
when Clock(0.1) then
// for eqation
for i in 1:n loop
x1[i] = if firstTick(x1[i]) then previous(x1[i]) else previous(x1[i]) + u[i];
end for;
// function with for loop
x2 = myfor(u, previous(x2), firstTick());
// array equation
x3 = if firstTick(x3) then previous(x3) else previous(x3) + u;
end when;
// for equation requiring inline integration
for i in 1:n loop
der(x4[i]) = x3[i];
end for;
y1 = sum(x1);
y2 = sum(x2);
y3 = sum(x3);
y4 = sum(x4);
end ArrayEquationsTest;
"); getErrorString();
simulate(ArrayEquationsTest); getErrorString();
val(y1, 1.0);
val(y2, 1.0);
val(y3, 1.0);
val(y4, 1.0);
// Result:
// true
// ""
// true
// ""
// true
// ""
// true
// ""
//
//
// *********************
// * SimCode Equations *
// *********************
//
//
// allEquations:
// ========================================
//
// ========================================
//
//
//
// odeEquations (0 systems):
// ========================================
// ========================================
//
//
//
// algebraicEquations (0 systems):
// ========================================
// ========================================
//
//
// clockPartitions (1 systems):
//
// BaseClock:
// ========================================
// Clock(RCONST 0.1
// )========================================
//
// SubPartition Vars:
// ========================================
// index:-1: $DER.x4 (no alias) initial: no arrCref index:() [10]
// index:-1: x1 (no alias) initial: no arrCref index:() [10] (PREVIOUS)
// index:-1: x2 (no alias) initial: no arrCref index:() [10] (PREVIOUS)
// index:-1: x3 (no alias) initial: no arrCref index:() [10] (PREVIOUS)
// index:-1: x4 (no alias) initial: no arrCref index:() [10] (PREVIOUS)
// index:-1: y1 (no alias) initial: no arrCref index:() []
// index:-1: y2 (no alias) initial: no arrCref index:() []
// index:-1: y3 (no alias) initial: no arrCref index:() []
// index:-1: y4 (no alias) initial: no arrCref index:() []
// partition equations:
// ========================================
// 26: $CLKPRE.x1=x1 [Real[10]]
// 25: $CLKPRE.x2=x2 [Real[10]]
// 24: $CLKPRE.x3=x3 [Real[10]]
// 23: $CLKPRE.x4=x4 [Real[10]]
// 14 FOR-LOOP: for i in (1:10) loop
// x1[i]=if firstTick() then previous(x1[i]) else previous(x1[i]) + u[i][Real]
// end for;
// 15: y1=sum(x1) [Real]
// 16: x2=ArrayEquationsTest.myfor(u, {previous(x2[1]), previous(x2[2]), previous(x2[3]), previous(x2[4]), previous(x2[5]), previous(x2[6]), previous(x2[7]), previous(x2[8]), previous(x2[9]), previous(x2[10])}, firstTick()) [Real[10]]
// 17: y2=sum(x2) [Real]
// 18: x3=if firstTick() then {previous(x3[1]), previous(x3[2]), previous(x3[3]), previous(x3[4]), previous(x3[5]), previous(x3[6]), previous(x3[7]), previous(x3[8]), previous(x3[9]), previous(x3[10])} else {previous(x3[1]), previous(x3[2]), previous(x3[3]), previous(x3[4]), previous(x3[5]), previous(x3[6]), previous(x3[7]), previous(x3[8]), previous(x3[9]), previous(x3[10])} + u [Real[10]]
// 19 FOR-LOOP: for i in (1:10) loop
// $DER.x4[i]=x3[i][Real]
// end for;
// 20 FOR-LOOP: for i in (1:10) loop
// x4[i]=(if firstTick() then 0.0 else $DER.x4[i]) * interval() + previous(x4[i])[Real]
// end for;
// 21: y4=sum(x4) [Real]
// 22: y3=sum(x3) [Real]removedEquations equations:
// ========================================
// SubClock:
// factor(1/1) shift(0/1) Hold Events: false
//
// ========================================
//
//
//
// initialEquations: (13)
// ========================================
// 1: $DER.x4=0.0 [Real]
// 2: x1={1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} [Real[10]]
// 3: $CLKPRE.x1=x1 [Real[10]]
// 4: x2={2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0} [Real[10]]
// 5: $CLKPRE.x2=x2 [Real[10]]
// 6: x3={3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0} [Real[10]]
// 7: $CLKPRE.x3=x3 [Real[10]]
// 8: x4={4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0} [Real[10]]
// 9: $CLKPRE.x4=x4 [Real[10]]
// 10: y1=0.0 [Real]
// 11: y2=0.0 [Real]
// 12: y3=0.0 [Real]
// 13: y4=0.0 [Real]
// ========================================
//
//
//
// initialEquations_lambda0: (0)
// ========================================
//
// removedInitialEquations:
// ========================================
//
// startValueEquations:
// ========================================
//
// nominalValueEquations:
// ========================================
//
// minValueEquations:
// ========================================
//
// maxValueEquations:
// ========================================
//
// parameterEquations:
// ========================================
// 27: n=10 [Integer]
//
// removedEquations:
// ========================================
//
// algorithmAndEquationAsserts:
// ========================================
//
// equationsForZeroCrossings:
// ========================================
//
// generic calls:
// ========================================
//
// jacobianEquations:
// ========================================
//
// jacobianMatrices:
// ========================================
// Jacobian idx: 0
//
// Jacobian idx: 1
//
// Jacobian idx: 2
//
// Jacobian idx: 3
//
// Jacobian idx: 4
//
// Jacobian idx: 5
//
//
// modelInfo:
// ========================================
// algVars (104)
// ----------------------
// index:0: $CLKPRE.x1 (no alias) hideResult initial: x1 no arrCref index:(1) [10]
// index:1: $CLKPRE.x2 (no alias) hideResult initial: x2 no arrCref index:(11) [10]
// index:2: $CLKPRE.x3 (no alias) hideResult initial: x3 no arrCref index:(21) [10]
// index:3: $CLKPRE.x4 (no alias) hideResult initial: x4 no arrCref index:(31) [10]
// index:4: $DER.x4 (no alias) initial: no arrCref index:(41) [10]
// index:5: u (no alias) initial: 1.0:10.0 no arrCref index:(51) [10]
// index:6: x1 (no alias) initial: no arrCref index:(61) [10]
// index:7: x2 (no alias) initial: no arrCref index:(71) [10]
// index:8: x3 (no alias) initial: no arrCref index:(81) [10]
// index:9: x4 (no alias) initial: no arrCref index:(91) [10]
// index:10: y1 (no alias) initial: no arrCref index:(101) []
// index:11: y2 (no alias) initial: no arrCref index:(102) []
// index:12: y3 (no alias) initial: no arrCref index:(103) []
// index:13: y4 (no alias) initial: no arrCref index:(104) []
// intParamVars
// ----------------------
// index:0: n (no alias) initial: 10 no arrCref index:(105) []
// functions:
// -----------
//
// Function: ArrayEquationsTest.myfor
// outVars: x (Real, ) ,
// functionArguments: u (array(Real)[:], ) , previous_x (array(Real)[size(u, 1)], ) , isFirstTick (Boolean, ) ,
// variableDeclarations: x (Real, ) ,
// record SimulationResult
// resultFile = "ArrayEquationsTest_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-6, method = 'dassl', fileNamePrefix = 'ArrayEquationsTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// ""
// 560.0
// 570.0
// 580.0
// 372.5
// endResult