-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTubeG.java
More file actions
360 lines (300 loc) · 9.77 KB
/
Copy pathTubeG.java
File metadata and controls
360 lines (300 loc) · 9.77 KB
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
// Class name: TubeG
//
// Description: hydraulic tube L-R-C,
// four-pole model form G
//
// Created: 01.12.2007
// Last modified: 14.02.2012 18.12.2012
//
// Input variables (poles):
// Q2 - input volumetric flow at the right port
// p1 - intput pressure at the left port
//
// Output variables (poles):
// Q1 - output volumetric flow at the left port
// p2 - output pressure at the right port
//
// Internal iteration variables:
// p20 - steady state output pressure at the right port
//
// External iteration variables:
// p2 - output value of the pressure p2 for this element
// p2e - output value of the pressure p2 to another element
//
// Tube parameters:
// d - inner diameter
// K - module of elasticity of the tube material
// l - length
// s - thickness of the tube walls
//
// Flow parameters:
// AL - coefficient of hydraulical friction at laminar flow
// lambda - coefficient of hydraulical friction at
// turbulent flow
// zeta - coefficient of local hydraulic resistance
//
// Model parameters:
// C - volume elasticity
// RL - resistance at laminar flow
// RT - resistance at turbulent flow
// L - inertia of the flow
// kC - coefficient of correcting the value C
// kL - coefficient of correcting the value L
// kr - coefficient of correcting the stationary resistances
// in dynamic
// nc - number of similar connected tubes
//
// Iteration parameters:
// epsap - allowed absolute iteration error for pressure
// epsr - allowed relative iteration error for pressure
//
// Calculation parameters:
// tau - inverse value of yhe timestep, (1/delta)
// delta - timestep
//
// State components:
// 1: Q1e
// 2: p2
//-------------------------------------------------------------------
//import java.text.*;
import ee.ioc.cs.vsle.api.Subtask;
class TubeG {
/*@ specification TubeG {
double p1, Q2;
double Q1, p2e;
double p2;
double tau;
double l, d, K, s;
double nc, kr;
double kC, kL;
double epsap, epsr;
double flp1, flp2, flp3, flp4, flp5, flp6, flp7;
double Pi;
double initQ1;
double initp2e;
// State variables
double initval1, initval2;
double oldval1, oldval2;
double val1, val2;
double nextval1, nextval2;
double finalval1, finalval2;
alias (double) initstate = (initval1, initval2);
alias (double) oldstate = (oldval1, oldval2);
alias (double) state = (val1, val2);
alias (double) nextstate = (nextval1, nextval2);
alias (double) finalstate= (finalval1, finalval2);
// Iterable variables
double initp_c, argp_c, resp_c, respres_c;
alias (double) initp = (initp_c);
alias (double) argp = (argp_c);
alias (double) resp = (resp_c);
alias (double) respres = (respres_c);
// Errors
double errorap_c, errorr_c;
alias (double) errorap = (errorap_c);
alias (double) errorr = (errorr_c);
// Collecting outputs
alias (double) out = (p2, Q1);
alias (double[]) result = (state, nextstate, out);
// Fluid parameters
alias (double) fluid_par = (flp1,flp2,flp3,flp4,flp5,flp6,flp7);
// Tube parameters
alias (double) tube_par = (l, d, K, s);
// Organizing iterations
argp_c = p2e;
respres_c = p2e;
resp_c = p2;
// Evaluating initial state
initval1 = initQ1;
initval2 = initp2e;
initp_c = initp2e;
// Equations
kC = Pi/2*(2/Pi)^(1/nc);
kL = Pi/2*(2/Pi)^(1/nc);
// Method specification
[ Flow |- fluid_par, tube_par, pfl-> RL, RT, L, C ],
tau, Q2, p1, nc, kC, kL, kr,
epsap, epsr, oldstate, state, fluid_par, tube_par
-> result { tubeG_next };
// Default conditions:
nc = 1;
kr = 2;
Pi = 3.1415926;
l = 2;
d = 0.019;
K = 2.1e11;
s = 0.003;
epsap = 1e-8;
epsr = 1e-8;
initQ1 = 2.48e-7;
initp2e = 21.15e6;
}@*/
//===================================================================
public double[][] tubeG_next (Subtask st, double tau, double Q2,
double p1, double nc, double kC,
double kL, double kr,
double epsap, double epsr,
double[] oldstate, double[] state,
double[] fluid_par,
double[] tube_par) {
double[][] result= { new double[state.length],
new double[state.length],
new double[2]};
double errstap, errstr;
double Q1;
double p20, p2;
double delta, pfl;
double RL, RT, L, C;
double dQ1, dp2;
double kq11, kq12, kq13, kq14;
double dq11, dq12, dq13;
double kp21, kp22, kp23, kp24;
double dp21, dp22, dp23;
//LSS.print_ar (" ******tubeG_next: state ",state);
try {
//-------------------------------------------------------------------
// Initial approximate calculations for steady-state conditions
if ( tau == 0 ) {
Q1 = Q2;
p2 = state[1];
pfl = p1;
// System.out.println("tubeG_next: initial pfl= " + pfl);
// Subtask: Preparing parameters, executing and
// getting output parameters
Object[] in = new Object[3];
in[0] = fluid_par;
in[1] = tube_par;
in[2] = pfl;
Object[] out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
L = (Double)out[2];
C = (Double)out[3];
// System.out.println("tubeG_next: RL="+
// RL+" RT="+RT+" L="+L+" C="+C);
p20 = p1 - (RL + RT * Math.abs(Q2)) * Q2;
// System.out.println("tubeG_next: p2c0="+p2c0);
//-------------------------------------------------------------------
// Calculations of steady-state conditions
for ( int i=1; i <= 5; i++) {
pfl = (p20 + p1)/2;
//System.out.println("tubeG_next: pfl=" + pfl);
// Subtask: Preparing parameters, executing and
// getting output parameters
in[2] = pfl;
out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
L = (Double)out[2];
C = (Double)out[3];
p2 = p1 - (RL + RT * Math.abs(Q2)) * Q2;
// System.out.println("tubeG_next: p2=" + p2);
errstap = Math.abs(p2 - p20);
errstr = Math.abs(p2 - p20)/p2;
if ((errstap < epsap) & (errstr < epsr)) break;
p20 = p2;
}
if ( p2 < 0 ) { p2 = 0; }
if ( p2 > ( 3E7)) { p2 = 3E7; }
// Preparing output
// state
result[0][0] = Q1;
result[0][1] = p2;
// nextstate
result[1][0] = Q1;
result[1][1] = p2;
// out
result[2][0] = p2;
result[2][1] = Q1;
}
//-------------------------------------------------------------------
// Dynamics calculations
if ( tau > 0 ) {
delta = 1 / tau;
Q1 = state[0];
p2 = state[1];
pfl = (p2 + p1) / 2;
//System.out.println("tubeG_next: pfl= " + pfl);
// Subtask: Preparing parameters, executing and
// getting output parameters
Object[] in = new Object[3];
in[0] = fluid_par;
in[1] = tube_par;
in[2] = pfl;
Object[] out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
L = (Double)out[2];
C = (Double)out[3];
// System.out.println("tubeG_next: RL="+RL+" RT="+RT+" L="+L+" C="+C);
// Calculating Runge-Kutta coefficients
dQ1 = deltaQ1 (delta, kL, L, p1, p2, kr, RL, RT, Q1);
dp2 = deltap2 ( delta, kC, C, Q1, Q2);
kq11 = dQ1;
kp21 = dp2;
dq11 = Q1 + kq11 / 2;
dp21 = p2 + kp21 / 2;
dQ1 = deltaQ1 (delta, kL, L, p1, dp21, kr, RL, RT, dq11);
dp2 = deltap2 ( delta, kC, C, dq11, Q2);
kq12 = dQ1 + kq11 / 2;
kp22 = dp2 + kp21 / 2;
dq12 = Q1 + kq12 / 2;
dp22 = p2 + kp22 / 2;
dQ1 = deltaQ1 (delta, kL, L, p1, dp22, kr, RL, RT, dq12);
dp2 = deltap2 ( delta, kC, C, dq12, Q2);
kq13 = dQ1 + kq12 / 2;
kp23 = dp2 + kp22 / 2;
dq13 = Q1 + kq13 / 2;
dp23 = p2 + kp23 / 2;
dQ1 = deltaQ1 (delta, kL, L, p1, dp23, kr, RL, RT, dq13);
dp2 = deltap2 ( delta, kC, C, dq13, Q2);
kq14 = dQ1 + kq13;
kp24 = dp2 + kp23;
// System.out.println("tubeG_next: kq11="+kq11+" kq12="+kq12+
// " kq13="+kq13+" kq14="+kq14);
// System.out.println("tubeG_next: kp21="+kp21+" kp22="+kp22+
// " kp23="+kp23+" kp24="+kp24);
// Computing nextstate values:
Q1 = state[0] + (kq11 + 2 * kq12 + 2 * kq13 + kq14) / 6;
p2 = state[1] + (kp21 + 2 * kp22 + 2 * kp23 + kp24) / 6;
if ( p2 < (-1E5)) { p2 = -1E5; }
if ( p2 > ( 3E7)) { p2 = 3E7; }
// Preparing output
// state
result[0][0] = state[0];
result[0][1] = state[1];
// nextstate
result[1][0] = Q1;
result[1][1] = p2;
// out
result[2][0] = p2;
result[2][1] = Q1;
}
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
//===================================================================
// deltaQ1e ( delta, kL, L, p1, p2, kr, RL, RT, Q1)
//===================================================================
public double deltaQ1 ( double delta, double kL, double L,
double p1, double p2, double kr,
double RL, double RT,
double Q1) {
double dQ1;
dQ1 = delta/kL/L *
(p1 - p2 - kr*(RL + RT*Math.abs(Q1)) * Q1);
return dQ1;
}
//===================================================================
// deltap2c ( delta, kC, C, Q1, Q2 )
//===================================================================
public double deltap2 ( double delta, double kC, double C,
double Q1, double Q2) {
double dp2;
dp2 = delta/kC/ C * ( Q1 - Q2);
return dp2;
}
}