-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTug.java
More file actions
254 lines (236 loc) · 7.54 KB
/
Copy pathTug.java
File metadata and controls
254 lines (236 loc) · 7.54 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
// Class name: Tubeg
//
// Description: hydraulic tube L-R-C, dead right end
// four-pole model form G
//
// Created: 22.09.2008
// Last modified: 14.02.2012; 02.05.2012; 18.12.2012
//
// Input variable (pole):
// p1 - pressure at the left port
//
// Output variable (pole):
// Q1 - volumetric flow at the left port
//
// Internal iteration variables:
// p2e0 - steady state output pressure at the right port
// p30 - steady state medial pressure
//
// External iteration variables:
// p2c - output value of the pressure p2 for this element
// p2e - output value of the pressure p2 to another element
//
// Tube parameters:
// A - inner cross section
// d - inner diameter
// E - 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
//
// Calculation parameters:
// tau - inverse value of yhe timestep, (1/delta)
// delta - timestep
//
// State components:
// 1: Q1
// 2: p2
//
// Created: 22.09.2008
// Last modified: 14.02.2012; 02.05.2012
//-------------------------------------------------------------------
//import java.text.*;
import ee.ioc.cs.vsle.api.Subtask;
class Tug {
/*@ specification Tug {
double p1;
double Q1;
double p2;
double tau;
double l, d, K, s;
double kr, kC, kL;
double flp1, flp2, flp3, flp4, flp5, flp6, flp7;
double initQ1;
double initp2;
// 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);
// Collecting outputs
alias (double) out = ( 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);
// Evaluating initial state
initval1 = initQ1;
initval2 = initp2;
// Equations
kC = 1;
kL = 1;
// Method specification
[ Flow |- fluid_par, tube_par, pfl-> RL, RT, L, C ],
tau, p1, kC, kL, kr, oldstate, state,
fluid_par, tube_par -> result { tubeg_next };
// Default conditions:
kr = 2;
l = 0.25;
d = 0.04;
K = 2.1e11;
s = 0.003;
initQ1 = 0;
initp2 = 21.15e6;
}@*/
//===================================================================
// [ Flow |- fluid_par, tube_par, pfl-> RL, RT, L, C ],
// tau, p1, kC, kL, kr, oldstate, state,
// fluid_par, tube_par -> result { tubeg_next };
// out = (Q1);
// result = (state, nextstate, out);
//===================================================================
public double[][] tubeg_next ( Subtask st, double tau,
double p1, double kC,
double kL, double kr,
double[] oldstate, double[] state,
double[] fluid_par,
double[] tube_par) {
double[][] result= { new double[state.length],
new double[state.length],
new double[1]};
double Q1;
double 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 = 0;
p2 = p1;
// Preparing output
// state
result[0][0] = Q1;
result[0][1] = p2;
// nextstate
result[1][0] = Q1;
result[1][1] = p2;
// out
result[2][0] = 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];
// Calculating Runge-Kutta coefficients
dQ1 = deltaQ1 (delta, kL, L, p1, p2, kr, RL, RT, Q1);
dp2 = deltap2 ( delta, kC, C, Q1);
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);
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);
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);
kq14 = dQ1 + kq13;
kp24 = dp2 + kp23;
//System.out.println("tubeG_next: kq11="+kq11+" kq12="+kq12+
// " kq13="+kq13+" kq14="+kq14);
//System.out.println("tubeG_next: kp31="+kp31+" kp32="+kp32+
// " kp33="+kp33+" kp34="+kp34);
// Computing of the nextstate values:
Q1 = state[0] + ( kq11 + 2 * kq12 + 2 * kq13 + kq14) / 6;
p2 = state[1] + ( kp21 + 2 * kp22 + 2 * kp23 + kp24) / 6;
if ( p2 < (-1.0E+5)) { p2 = -1.0E+5; }
// if ( p2 > (2.2E+7)) { p2 = 2.2E+7; }
// 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] = 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;
}
//===================================================================
// deltap3 ( delta, kC, C, Q1 )
//===================================================================
public double deltap2 ( double delta, double kC, double C,
double Q1 ) {
double dp2;
dp2 = delta/kC/ C * Q1;
return dp2;
}
}