1 | package TestArray |
---|
2 | package PlainEquations |
---|
3 | model A "A simple model using basic types without arrays" |
---|
4 | input Real u; |
---|
5 | parameter Real p = 1; |
---|
6 | Real x; |
---|
7 | equation |
---|
8 | x = p*u; |
---|
9 | end A; |
---|
10 | |
---|
11 | model B "A simple model using arrays or basic types" |
---|
12 | parameter Integer N = 3; |
---|
13 | parameter Real p = 1; |
---|
14 | Real x[N]; |
---|
15 | input Real u; |
---|
16 | equation |
---|
17 | x[1] = u; |
---|
18 | for i in 2:N loop |
---|
19 | x[i] = x[i-1]+p; |
---|
20 | end for; |
---|
21 | end B; |
---|
22 | |
---|
23 | model C "A model using arrays of simple models without arrays" |
---|
24 | parameter Integer N = 3; |
---|
25 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
26 | A a[N](p = p); |
---|
27 | equation |
---|
28 | a[1].u = time; |
---|
29 | for i in 2:N loop |
---|
30 | a[i].u = a[i-1].x; |
---|
31 | end for; |
---|
32 | end C; |
---|
33 | |
---|
34 | model D "A model using arrays of models with arrays of basic types (same dimensions)" |
---|
35 | parameter Integer N = 3; |
---|
36 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
37 | B b[N](p = p, each N = 4); |
---|
38 | equation |
---|
39 | b[1].u = time; |
---|
40 | for i in 2:N loop |
---|
41 | b[i].u = b[i-1].x[end]; |
---|
42 | end for; |
---|
43 | end D; |
---|
44 | |
---|
45 | model E "A model using arrays of models with arrays of basic types (same dimensions)" |
---|
46 | parameter Integer N = 3; |
---|
47 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
48 | B b[N](p = p, N = {3, 4, 5}); |
---|
49 | equation |
---|
50 | b[1].u = time; |
---|
51 | for i in 2:N loop |
---|
52 | b[i].u = b[i-1].x[end]; |
---|
53 | end for; |
---|
54 | end E; |
---|
55 | end PlainEquations; |
---|
56 | |
---|
57 | package ConnectEquations |
---|
58 | connector CC |
---|
59 | Real e; |
---|
60 | flow Real f; |
---|
61 | end CC; |
---|
62 | |
---|
63 | model S "Source model" |
---|
64 | parameter Real p = 10; |
---|
65 | CC c; |
---|
66 | equation |
---|
67 | c.e = p; |
---|
68 | end S; |
---|
69 | |
---|
70 | model A "A simple model using basic types without arrays" |
---|
71 | CC c; |
---|
72 | parameter Real p = 1; |
---|
73 | Real x; |
---|
74 | equation |
---|
75 | der(x) = -p*x + 1; |
---|
76 | c.f = x; |
---|
77 | end A; |
---|
78 | |
---|
79 | model B "A simple model using arrays or basic types" |
---|
80 | parameter Integer N = 3; |
---|
81 | parameter Real p = 1; |
---|
82 | Real x[N]; |
---|
83 | CC c; |
---|
84 | equation |
---|
85 | x[1] = c.e; |
---|
86 | x[N] = c.f; |
---|
87 | for i in 2:N loop |
---|
88 | x[i] = x[i-1]+p; |
---|
89 | end for; |
---|
90 | end B; |
---|
91 | |
---|
92 | model C "A model using arrays of simple models without arrays" |
---|
93 | parameter Integer N = 3; |
---|
94 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
95 | A a[N](p = p); |
---|
96 | S s(p = 20); |
---|
97 | equation |
---|
98 | connect(s.c, a[1].c); |
---|
99 | for i in 1:N-1 loop |
---|
100 | connect(a[i].c, a[i+1].c); |
---|
101 | end for; |
---|
102 | end C; |
---|
103 | |
---|
104 | model D "A model using arrays of models with arrays of basic types (same dimensions)" |
---|
105 | parameter Integer N = 3; |
---|
106 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
107 | B b[N](p = p, each N = 3); |
---|
108 | S s(p = 3); |
---|
109 | equation |
---|
110 | connect(s.c, b[1].c); |
---|
111 | for i in 1:N-1 loop |
---|
112 | connect(b[i].c, b[i+1].c); |
---|
113 | end for; |
---|
114 | end D; |
---|
115 | |
---|
116 | model E "A model using arrays of models with arrays of basic types (same dimensions)" |
---|
117 | parameter Integer N = 3; |
---|
118 | parameter Real p[N] = {1.0, 1.5, 2.0}; |
---|
119 | B b[N](p = p, N = {3, 4, 5}); |
---|
120 | S s(p = 3); |
---|
121 | equation |
---|
122 | for i in 1:N-1 loop |
---|
123 | connect(b[i].c, b[i+1].c); |
---|
124 | end for; |
---|
125 | end E; |
---|
126 | end ConnectEquations; |
---|
127 | end TestArray; |
---|