-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVeZ.java
More file actions
232 lines (209 loc) · 6.74 KB
/
Copy pathVeZ.java
File metadata and controls
232 lines (209 loc) · 6.74 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
import ee.ioc.cs.vsle.api.Subtask;
// Class name: veZ
// Description: hydraulic volume elasticity form Z
//
// Input variables (poles)
// Q1 - volumetric flow at the left port
// Q2 - volumetric flow at the right port
//
// Output variables (poles)
// p1 - pressure at the left port
// p2 - pressure at the right port
//
// External iteration variables:
// p1 - output value of the pressure p1 for this element
// p1e - output value of the pressure p1 to another element
// p2 - output value of the pressure p2 for this element
// p2e - output value of the pressure p2 to another element
//
// Volume elasticity parameters
// l - volume lenght
// d - volume diameter
//
// Flow characteristics
// C - volume elasticity
//
// 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: p1
// 2: p2
//
// Created: 01.12.2007
// Last modified: 07.05.2009
//-------------------------------------------------------------------
class VeZ {
/*@
specification VeZ {
double Q1, Q2;
double p1e, p2e;
double p1, p2;
double dp1;
double l, d, V;
String res_type;
double flp1, flp2, flp3, flp4, flp5, flp6, flp7;
double initp1e;
double tau;
double betam;
double Pi;
// 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_c1, argp_c1, resp_c1, respres_c1;
double initp_c2, argp_c2, resp_c2, respres_c2;
alias (double) initp = (initp_c1, initp_c2);
alias (double) argp = (argp_c1, argp_c2);
alias (double) resp = (resp_c1, resp_c2);
alias (double) respres = (respres_c1, respres_c2);
// Collecting outputs
alias (double) out = ( p1, p2, p1e, p2e );
alias (double[]) result = ( state, nextstate, out );
// Fluid parameters
alias (double) fluid_par = (flp1,flp2,flp3,flp4,flp5,flp6,flp7);
// Organizing iterations
argp_c1 = p1e;
argp_c2 = p2e;
respres_c1 = p1e;
respres_c2 = p2e;
resp_c1 = p1;
resp_c2 = p2;
// Evaluating initial states
initval1 = initp1e;
initval2 = initp1e;
initp_c1 = initp1e;
initp_c2 = initp1e;
// Equations
V = l * Pi * d * d / 4;
// Method specification
[ Flow |- fluid_par, pfl-> betam ],
tau, Q1, Q2, V, initp1e,
oldstate, state, fluid_par -> result { veZ_next };
// Parameters values
l = 0.1;
d = 0.1;
Pi = 3.1415926;
// Initial values
initp1e = 5E6;
}@*/
//============================================================
// [ Flow |- fluid_par, pfl-> betam ],
// tau, Q1, Q2, V, initp1e,
// oldstate, state, fluid_par -> result { veZ_next };
// result = ( state, nextstate, out );
// out = ( p1c, p2c, p1e, p2e );
//============================================================
public double[][] veZ_next ( Subtask st, double tau,
double Q1, double Q2, double V,
double initp1e, double[] oldstate,
double[] state, double[] fluid_par ) {
double[][] result = { new double[state.length],
new double[state.length],
new double[4]};
double pfl;
double delta, betam;
double dp1;
double C;
double k1, k2, k3, k4;
double p1, p2;
//System.out.println("veZ_next: start: tau="+tau+" Q1a="+Q1a+" Q2a="+Q2a+
// " V="+V+" initp1c="+initp1c+" initp2c="+initp2c);
//System.out.println("veZ_next: use_flag_c= " + use_flag_c);
//print_ar (" ******veZ_next input: oldstate ", (double[]) oldstate);
//print_ar (" ******veZ_next input: state ", (double[]) state);
try {
//----------------------------------------------------------------------
// Initial approximation calculations for steady-state conditions
if ( tau == 0 ) {
p1 = initp1e;
p2 = initp1e;
// Preparing output
// state
result[0][0] = p1;
result[0][1] = p2;
// nextstate
result[1][0] = p1;
result[1][1] = p2;
// out
result[2][0] = p1;
result[2][1] = p2;
result[2][2] = p1;
result[2][3] = p2;
//print_ar (" ******veZ_next static output: state, nextstate ", result[1]);
}
//----------------------------------------------------------------------
// Dynamics calculations
if ( tau > 0 ) {
delta =1 / tau;
p1 = state[0];
p2 = state[1];
pfl = (p1 + p2) / 2;
//System.out.println("VeZ_next: pfl= " + pfl);
//Subtask: Preparing parameters, executing and getting output parameters
Object[] in = new Object[2];
in[0] = fluid_par;
in[1] = pfl;
Object[] out = st.run(in);
betam = (Double)out[0];
//System.out.println("VeZ_next: betam= " + betam);
// Computing the difference
C = V * betam;
dp1 = delta * (Q1 - Q2) / C;
// System.out.println("VeZ_next: dp1c="+dp1c);
// Computing of the Runge-Kutta coefficients
k1 = dp1;
k2 = k1 + k1/2;
k3 = k1 + k2/2;
k4 = k1 + k3;
// Computing nextstate values
p1 = state[0] + (k1 + 2*k2 + 2*k3 + k4)/6;
p2 = p1;
if ( p1 < (-1E5)) { p1 = -1E5; }
if ( p2 < (-1E5)) { p2 = -1E5; }
// Preparing output
// state
result[0][0] = state[0];
result[0][1] = state[1];
// nextstate
result[1][0] = p1;
result[1][1] = p2;
// out
result[2][0] = p1;
result[2][1] = p2;
result[2][2] = p1;
result[2][3] = p2;
// System.out.println("VeZ_next: p1, p1="+p1+" p2, p2="+p2);
// print_ar (" ******VeZ_next dynamic output: state ", result[0]);
// print_ar (" ******VeZ_next dynamic output: nextstate ", result[1]);
}
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
//============================================================
// void print_ar (String ar_name, double[] ar)
//============================================================
// public void print_ar (String ar_name, double[] ar) {
// System.out.print(ar_name + ":");
// for (int i = 0; i < ar.length; i++ ) {
// System.out.print(" " + ar[i]);
// }
// System.out.println();
// }
}