-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResG.java
More file actions
230 lines (219 loc) · 6.49 KB
/
Copy pathResG.java
File metadata and controls
230 lines (219 loc) · 6.49 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
// Class name: ResG
//
// Description: local hydraulic resistor,
// four-pole model form G
//
// Created: 01.12.2007
// Last modified: 14.02.2012 18.12.2012
//
// Input variables (poles):
// Q2 - volumetric flow at the right port
// p1 - pressure at the left port
//
// Output variables (poles):
// Q1 - volumefric flow at the left port
// p2e - pressure at the right port
//
// Internal iteration variables:
// p20 - steady state output pressure at the right port
// p2 - "disconnected" internal calculated value
// of the pressure p2
//
// External iteration variables:
// p2e - output value of the pressure p2 to another element
//
// Resistance parameters:
// d - diameter of the channel
// l - length of the channel
//
// 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:
// RL - resistance at laminar flow
// RT - resistance at turbulent flow
// L - inertia of the flow
//
// Calculation parameters:
// tau - inverse value of yhe timestep, (1/delta)
// delta - timestep
//
// State components:
// 1: p2
//-------------------------------------------------------------
import ee.ioc.cs.vsle.api.Subtask;
class ResG {
/*@ specification ResG {
double p1, Q2;
double Q1, p2e;
double p2;
double tau;
double l, d;
String res_type;
double dlt, kE, mu, dltpN, QN, A;
double pmax;
double epsap, epsr;
double flp1, flp2, flp3, flp4, flp5, flp6, flp7;
double initp2e;
// State variables
double initval1;
double oldval1;
double val1;
double nextval1;
double finalval1;
alias (double) initstate = (initval1);
alias (double) oldstate = (oldval1);
alias (double) state = (val1);
alias (double) nextstate = (nextval1);
alias (double) finalstate = (finalval1);
// 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);
// Collecting outputs
alias (double) out = (p2, Q1);
alias (double[]) result = (nextstate, out);
// Fluid parameters
alias (double) fluid_par=(flp1,flp2,flp3,flp4,flp5,flp6,flp7);
// Hydraulic resistor parameters
alias (double) res_par=(l,d,dlt,kE,mu,dltpN,QN,A);
// Organizing iterations
argp_c = p2e;
respres_c = p2e;
resp_c = p2;
// Evaluating initial state
initval1 = initp2e;
initp_c = initp2e;
// Method specification
[ Flow |- fluid_par, res_par, res_type, pfl-> RL, RT, L ],
tau, Q2, p1, epsap, epsr, pmax, state,
fluid_par, res_par, res_type -> result {resG_next};
// Default conditions:
l = 0.02;
d = 0.003;
pmax = 1.5e6;
res_type = "RRa";
dlt = 5e-6;
kE = 2;
mu = 0.7;
dltpN = 2e5;
QN = 6.2e-4;
A = 1e-4;
epsap = 1e-8;
epsr = 1e-8;
initp2e = 1.5e6;
}@*/
//=============================================================
// [ Flow |- fluid_par, res_par, res_type, pfl-> RL, RT, L ],
// tau, Q2, p1, epsap, epsr, pmax, state,
// fluid_par, res_par, res_type -> result {resG_next};
//
// out = (p2, Q1);
// result = (state, nextstate, out);
//=============================================================
public double[][] resG_next ( Subtask st, double tau,
double Q2, double p1,
double epsap, double epsr,
double pmax,
double[] state,
double[] fluid_par,
double[] res_par,
String res_type ) {
double[][] result = { new double[state.length],
new double[2] };
double pfl, RL, RT;
double Q1;
double errstap, errstr;
double p2, p20;
p2 = 0;
try {
//-------------------------------------------------------------
// Static calculations
if ( tau == 0 ) {
pfl = p1;
Q1 = Q2;
//System.out.println("resG_next: pfl= " + pfl);
// Subtask: Preparing parameters, executing and
// getting output parameters
Object[] in = new Object[4];
in[0] = fluid_par;
in[1] = res_par;
in[2] = res_type;
in[3] = pfl;
Object[] out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
//System.out.println
//("resG_next: RL="+RL+" RT="+RT+" L="+L);
p20 = p1 - (RL + RT * Math.abs(Q2)) * Q2;
//System.out.println("resG_next: p20=" + p20);
for ( int i=1; i <= 10; i++) {
pfl = (p20 + p1)/2;
//System.out.println(
//"resG_next: changed pfl=" + pfl);
// Subtask: Preparing parameters, executing and
// getting output parameters
in[3] = pfl;
out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
p2 = p1 - (RL + RT * Math.abs(Q2)) * Q2;
//System.out.println("resG_next: p2= " + p2);
errstap = Math.abs(p2 - p20);
errstr = Math.abs(p2 - p20)/p2;
if ((errstap < epsap) & (errstr < epsr)) break;
p20 = p2;
if ( p2 >= pmax) { p2 = pmax; }
if ( p2 <= (-1e-05) ) { p2 = -1e-05; }
}
Q1 = Q2;
//System.out.println("resG_next: p2=" + p2);
// Preparing output
// nextstate
result[0][0] = p2;
// out
result[1][0] = p2;
result[1][1] = Q1;
}
//-------------------------------------------------------------
// Dynamics calculations
if ( tau > 0 ) {
p2 = state[0];
pfl = (p2 + p1)/2;
if (pfl < 1e3) { pfl = 1e3; }
// Subtask: Preparing parameters, executing and
// getting output parameters
Object[] in = new Object[4];
in[0] = fluid_par;
in[1] = res_par;
in[2] = res_type;
in[3] = pfl;
Object[] out = st.run(in);
RL = (Double)out[0];
RT = (Double)out[1];
p2 = p1 - (RL + RT*Math.abs(Q2)) * Q2;
//System.out.println("resG_next: p2=" + p2);
if (p2 >= pmax) { p2 = pmax; }
if (p2 < -1e5) { p2 = -1e5; }
Q1 = Q2;
//System.out.println("resG_next: p2=" + p2);
// Preparing output
// nextstate
result[0][0] = p2;
// out
result[1][0] = p2;
result[1][1] = Q1;
}
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
}