1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO is distributed under the terms of the ALSOC LICENSE as |
---|
9 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
10 | *----------------------------------------------------------------------- |
---|
11 | * Adapted by: Jonathan Ospino P. |
---|
12 | * $Id: TimeDelay.mso 2012$ |
---|
13 | *---------------------------------------------------------------------*# |
---|
14 | |
---|
15 | using "types"; |
---|
16 | |
---|
17 | Model TimeDelay |
---|
18 | |
---|
19 | ATTRIBUTES |
---|
20 | Pallete=true; |
---|
21 | Icon="icon/TimeDelay"; |
---|
22 | Info="== Time Delay block == |
---|
23 | |
---|
24 | It delays the value of the input signal t0 units |
---|
25 | to the right with respect to the time. |
---|
26 | The resulting value is assigned to the output variable. |
---|
27 | |
---|
28 | |
---|
29 | ****************** How does it work? *********************** |
---|
30 | |
---|
31 | The model uses the <<Approximation based on series |
---|
32 | of orthogonal collocation>> and <<Approximation based on series |
---|
33 | of orthogonal collocation with capacitive filter>> cases |
---|
34 | (see Quinto et. al,2009) and it solves them simultaneously. |
---|
35 | Finally, the output value is seleceted depending on whether |
---|
36 | or not the user specified a filter. |
---|
37 | |
---|
38 | ***************************************************************"; |
---|
39 | |
---|
40 | |
---|
41 | PARAMETERS |
---|
42 | |
---|
43 | t0 as Real(Brief="Time Delay value",Default=0,Unit='s'); |
---|
44 | N as Integer(Brief="Number of elements (1<=N<=100)", Lower=1, Upper=100, Default=100); |
---|
45 | Ntank as Integer(Brief="Number of tanks to be Used with the series of tanks (1<=N<=2000)", Lower=1, Upper=2000, Default=2000); |
---|
46 | |
---|
47 | Approach as Switcher(Brief="HINT: Use a filter just when...",Valid=["Tank series","Discretized","Discretized+filter","Capacitive series"],Default="Discretized"); |
---|
48 | alfa as Real(Brief="Unfiltered fraction",Default=0.94); |
---|
49 | a(3,3) as Real(Brief="Parameters used on the 2nd-Order approaches",Hidden=true); |
---|
50 | |
---|
51 | |
---|
52 | VARIABLES |
---|
53 | |
---|
54 | in In as Real(PosX=0,PosY=0.5,Protected=true); |
---|
55 | out Out as Real(PosX=1,PosY=0.5,Protected=true); |
---|
56 | |
---|
57 | x1(2*N+1) as Real(Hidden=true); # States for the 2nd-Order + FE approach(Discretized Model) |
---|
58 | x2(2*N+2) as Real(Hidden=true); # States for the 2nd-Order + FE + Filter approach (Discretized Model + Filter) |
---|
59 | x3(Ntank) as Real(Hidden=true); # States for the tank delay approach |
---|
60 | x4(3*N+1) as Real(Hidden=true); # States for the 2nd-Order + Filters + FE approach (Capacitive series) |
---|
61 | |
---|
62 | |
---|
63 | y1 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + FE approach |
---|
64 | y2 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + FE + Filter approach |
---|
65 | y3 as Real(Hidden=true); # Tentative store for the Output variable when tank delay approach |
---|
66 | y4 as Real(Hidden=true); # Tentative store for the Output variable when 2nd-Order + Filters + FE approach |
---|
67 | |
---|
68 | SET |
---|
69 | |
---|
70 | a(1,1:3)=[2, -1.5, -0.5]; |
---|
71 | a(2,1:3)=[-2, 4.5, -2.5]; |
---|
72 | a(3,1:3)=[0, 1, -1]; |
---|
73 | |
---|
74 | |
---|
75 | EQUATIONS |
---|
76 | |
---|
77 | #* The following IF-ELSE sentence assures that user |
---|
78 | can deactivate the action of the time delay block |
---|
79 | over its input signal by just setting t0 to 0. |
---|
80 | |
---|
81 | |
---|
82 | So, there are two posibilities: t>0 and t0=0. |
---|
83 | |
---|
84 | (1) t0>0 -> The block applies the time delay |
---|
85 | approach developed by (Quinto et al.,2009) |
---|
86 | considering the application or not of a |
---|
87 | capacitive filter. |
---|
88 | |
---|
89 | (2) t0=0 -> Since the previous case produces |
---|
90 | singularity problems when applied with t0=0, |
---|
91 | then an alternative path must be set in |
---|
92 | the current algorithm to success. |
---|
93 | *# |
---|
94 | |
---|
95 | if t0>0*'s' then |
---|
96 | # 2nd-Order + FE approach (Discretized Model) |
---|
97 | x1(1)=In; |
---|
98 | for i in [2:2:2*N] do |
---|
99 | t0*diff(x1(i))=N*(a(1,1)*x1(i-1)+a(1,2)*x1(i)+a(1,3)*x1(i+1)); |
---|
100 | t0*diff(x1(i+1))=N*(a(2,1)*x1(i-1)+a(2,2)*x1(i)+a(2,3)*x1(i+1)); |
---|
101 | end |
---|
102 | y1=x1(2*N+1); |
---|
103 | |
---|
104 | # 2nd-Order + FE + Filter approach (Discretized Model+Filter) |
---|
105 | x2(1)=In; |
---|
106 | for i in [2:2:2*N] do |
---|
107 | alfa*t0*diff(x2(i))=N*(a(1,1)*x2(i-1)+a(1,2)*x2(i)+a(1,3)*x2(i+1)); |
---|
108 | alfa*t0*diff(x2(i+1))=N*(a(2,1)*x2(i-1)+a(2,2)*x2(i)+a(2,3)*x2(i+1)); |
---|
109 | end |
---|
110 | (1-alfa)*t0*diff(x2(2*N+2)) = N*(x2(2*N+1)-x2(2*N+2)); |
---|
111 | y2=x2(2*N+2); |
---|
112 | |
---|
113 | # Tank series approach |
---|
114 | (t0/Ntank)*diff(x3(1))=In-x3(1); |
---|
115 | for i in [2:Ntank] do |
---|
116 | (t0/Ntank)*diff(x3(i))=x3(i-1)-x3(i); |
---|
117 | end |
---|
118 | y3=x3(Ntank); |
---|
119 | |
---|
120 | # 2nd-Order + Filters +FE approach (Capacitive series) |
---|
121 | x4(1) = In; |
---|
122 | for i in [2:3:3*N-1] do |
---|
123 | t0*diff(x4(i)) = 2*N*(a(1,1)*x4(i-1)+a(1,2)*x4(i)+a(1,3)*x4(i+1)); |
---|
124 | t0*diff(x4(i+1)) = 2*N*(a(2,1)*x4(i-1)+a(2,2)*x4(i)+a(2,3)*x4(i+1)); |
---|
125 | t0*diff(x4(i+2)) = 2*N*(a(3,2)*x4(i+1)+a(3,3)*x4(i+2)); |
---|
126 | end |
---|
127 | y4 = x4(3*N+1); |
---|
128 | else |
---|
129 | # 2nd-Order + FE approach (Discretized Model) |
---|
130 | x1(1)=In; |
---|
131 | for i in [2:2:2*N] do |
---|
132 | diff(x1(i))=0*'1/s'; |
---|
133 | diff(x1(i+1))=0*'1/s'; |
---|
134 | end |
---|
135 | y1=0; |
---|
136 | |
---|
137 | # 2nd-Order + FE + Filter approach (Discretized Model + Filter) |
---|
138 | x2(1)=In; |
---|
139 | for i in [2:2:2*N] do |
---|
140 | alfa*diff(x2(i))=0*'1/s'; |
---|
141 | alfa*diff(x2(i+1))=0*'1/s'; |
---|
142 | end |
---|
143 | (1-alfa)*diff(x2(2*N+2))=0*'1/s'; |
---|
144 | y2=0; |
---|
145 | |
---|
146 | # Tank series approach |
---|
147 | (t0/Ntank)*diff(x3(1))=0; |
---|
148 | for i in [2:Ntank] do |
---|
149 | (t0/Ntank)*diff(x3(i))=0; |
---|
150 | end |
---|
151 | y3=0; |
---|
152 | |
---|
153 | # 2nd-Order + Filters +FE approach (Capacitive series) |
---|
154 | x4(1) = In; |
---|
155 | for i in [2:3:3*N-1] do |
---|
156 | t0*diff(x4(i)) = 0; |
---|
157 | t0*diff(x4(i+1)) = 0; |
---|
158 | t0*diff(x4(i+2)) = 0; |
---|
159 | end |
---|
160 | y4 = 0; |
---|
161 | end |
---|
162 | |
---|
163 | if t0>0*'s' then |
---|
164 | switch Approach |
---|
165 | case "Discretized": |
---|
166 | Out=y1; |
---|
167 | case "Discretized+filter": |
---|
168 | Out=y2; |
---|
169 | case "Tank series": |
---|
170 | Out=y3; |
---|
171 | case "Capacitive series": |
---|
172 | Out=y4; |
---|
173 | end |
---|
174 | else |
---|
175 | switch Approach |
---|
176 | case "Discretized": |
---|
177 | Out=In; |
---|
178 | case "Discretized+filter": |
---|
179 | Out=In; |
---|
180 | case "Tank series": |
---|
181 | Out=In; |
---|
182 | case "Capacitive series": |
---|
183 | Out=In; |
---|
184 | end |
---|
185 | end |
---|
186 | |
---|
187 | |
---|
188 | INITIAL |
---|
189 | |
---|
190 | x1(2:2*N+1) = 0; |
---|
191 | x2(2:2*N+2) = 0; |
---|
192 | x3=0; |
---|
193 | x4(2:3*N+1) = 0; |
---|
194 | |
---|
195 | end |
---|
196 | |
---|
197 | |
---|
198 | #* FINAL REMARKS |
---|
199 | ------------- |
---|
200 | |
---|
201 | The following paragraphs show some remarks about the implementation of the |
---|
202 | the models included in the Quinto et al.'s file, so: |
---|
203 | |
---|
204 | |
---|
205 | A. Higher-Order Padé |
---|
206 | -------------------- |
---|
207 | This model was not implemented because it show many oscillations, even for the |
---|
208 | higher possible value. |
---|
209 | |
---|
210 | |
---|
211 | B. 2nd-Order Finite-Elements Approximation (2nd-Order + FE) |
---|
212 | ----------------------------------------------------------- |
---|
213 | This model did show very good results for N near to 100. |
---|
214 | |
---|
215 | |
---|
216 | C. 2nd-Order Finite-Elements Approximation with Filter (2nd-Order + FE + Filter) |
---|
217 | -------------------------------------------------------------------------------- |
---|
218 | This model did show very good results for N near to 100. |
---|
219 | |
---|
220 | |
---|
221 | D. 2nd-Order plus Filters Finite-Elements Approximation (2nd-Order + Filters + FE) |
---|
222 | ---------------------------------------------------------------------------------- |
---|
223 | This model did show very good results for N near to 100. |
---|
224 | |
---|
225 | |
---|
226 | E. Series of tanks Approximation (Tanks series) |
---|
227 | ----------------------------------------------- |
---|
228 | This model did show very good results for N near to 100. |
---|
229 | |
---|
230 | *# |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|