-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlowlineObj.m
596 lines (488 loc) · 19.9 KB
/
FlowlineObj.m
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
classdef FlowlineObj < handle
%FlowlineObj. Flowline Class
% FlowlineObj represents a flowline connecting different elements in the
% surface for a network. It allows calculation of pressure/temperature
% profile along the flowline.
%
% Properties
% - Qsc : flowrate at standard conditions [Sm3/d]
% - Qi : flowrate flowline inlet [m3/d]
% - Qo : flowrate flowline outlet [m3/d]
% - Pi : pressure flowline outlet [kPa]
% - Po : pressure flowline inlet [kPa]
% - Ti : temperature flowline inlet [C]
% - To : temperature flowline outlet [C]
% - rhosc : density at standard conditions [kg/m3]
% - tTinf : flowline surounding temperature [K]
% - tln : flowline length [m]
% - tdi : flowline internal diameter [m]
% - trg : flowline roughness [m]
% - tuc : flowline global heat coefficient [kW/m2.K]
% - tin : flowline inclination (0 = hztal) [rad]
% - tsl : flowline segment length [m]
% - BOmodel : black oil model
% - CalculationType : {forward | backward}
%
% Constant properties
% - g : gravity acceleration [m/s2]
%
% Dependent properties
% - status : programming property (to be used in further versions)
% - Tprofile : flowline temperature profile [C]
% - Pprofile : flowline pressure profile [kPa]
% - tlengthp : flowline length profile [m]
%
% Methods
% - SolveFlowline
% Depending on the calculation type, calculates P, T and Q on the
% other flowline nozzle.
% - PlotPprofile
% Plotting pressure profile along the flowline length.
% - PlotTprofile
% Plotting temperature profile along the flowline length.
% - PlotPTprofile
% Plotting temperature and pressure profile along the flowline
% length.
% ------------------------------------------------------------------------
% Development
% By: Ruben Ensalzado
% 2016
% Rev 00 160521 original release
% improvement in Tprofile and Pprofile calculations
properties
BOmodel
Qsc
rhosc
Qi
Qo
Pi
Po
Ti
To
tTinf
tln
tdi
trg
tuc
tin
tsl
CalculationType
end
properties (Constant)
g = 9.81;
end
properties (Dependent)
status
Tprofile
Pprofile
tlengthp
end
methods (Hidden)
% -- initialization method --
function TU = FlowlineObj
TU.CalculationType = 'forward';
TU.tsl = 2;
TU.tin = 0;
end
end
methods
% -- error verification methods --
function set.CalculationType(TU, uType)
if strcmpi(uType, 'forward') || strcmpi(uType, 'backward')
TU.CalculationType = uType;
else
errrm = ['The available types are:';...
'- forward ';...
'- backward '];
error('FlowlineObj:BadArgument', ...
'%s \n\t%s \n\t%s \n', ...
errrm(1, :), errrm(2, :), errrm(3, :))
end
end
function set.BOmodel(TU, uBO)
if strcmpi(class(uBO), 'BOObj')
TU.BOmodel = uBO;
else
error('FlowlineObj:BadArgument', ...
'The fluid model object has to be class BOObj')
end
end
function set.Qsc(TU, uQsc)
if size(uQsc, 1) == 3 && size(uQsc, 2) == 1
TU.Qsc = uQsc;
else
error('FlowlineObj:BadArgument', ...
'Qsc must be a 3x1 double array.')
end
end
end
methods
% -- dependent properties --
function status = get.status(TU)
%Status. Independent property verification
req = zeros(9, 1);
req(1) = isempty(TU.Qi) && isempty(TU.Qo);
req(2) = isempty(TU.Pi) && isempty(TU.Po);
req(3) = isempty(TU.Ti) && isempty(TU.To);
req(4) = isempty(TU.tln);
req(5) = isempty(TU.tTinf);
req(6) = isempty(TU.tdi);
req(7) = isempty(TU.trg);
req(8) = isempty(TU.tuc);
if all(~req)
status = true;
else
status = false;
end
end
function Tprofile = get.Tprofile(TU)
%FlowlineTemperatureProfile
%Units
% T0 : C
switch lower(TU.CalculationType)
case 'forward'
T0 = TU.Ti + 273.15;
case 'backward'
T0 = TU.To + 273.15;
end
[piping, dy, n] = mpiping(TU);
props = mprops(TU, n, 'Tprofile');
[dtm, dti] = dtmatrix(TU, T0, n, dy, props, piping);
Tprofile = dtm\dti;
end
function Pprofile = get.Pprofile(TU)
%FlowlinePressureProfile.
%Units
% P0 : kPa
% Pprofile : kPa
switch lower(TU.CalculationType)
case 'forward'
P0 = TU.Pi;
case 'backward'
P0 = TU.Po;
end
[piping, dy, n] = mpiping(TU);
props = mprops(TU, n, 'Pprofile');
[dpm, dpi] = dpmatrix(TU, P0, n, dy, props, piping);
Pprofile = (dpm\dpi)/1e3;
end
function tlengthp = get.tlengthp(TU)
%FlowlinelengthProfile.
%Units
% tln : m
% tsl : m
sn = round(TU.tln/TU.tsl) + 1;
tlengthp = linspace(0, TU.tln, sn + 1)';
end
end
methods
function SolveFlowline(TU)
switch lower(TU.CalculationType)
case 'forward'
TU.Po = TU.Pprofile(end);
TU.To = TU.Tprofile(end) - 273.15;
case 'backward'
TU.Pi = TU.Pprofile(1);
TU.Ti = TU.Tprofile(1) - 273.15;
end
TU.QCalculation
end
end
methods (Hidden = true)
% -- auxiliary functions --
function ff = colebrook(~, Re, edr)
%FictionFactor. Colebrook and White (1931)
if Re <= 2000
ff = 64/Re;
else
fff = @(f) (2/log(10))*log(edr/3.7 + 2.51/(Re*sqrt(f))) + 1/sqrt(f);
dff = @(f) -((2/log(10)*(2.51*0.5/Re)*(edr/3.7 + 2.51/(Re*sqrt(f)))^(-1)*f^(-1.5)) + 0.5*f^(-1.5));
eff = 1;
ff0 = 1e-3;
while eff > 1e-8
ff = ff0 - fff(ff0)/dff(ff0);
eff = abs(ff - ff0);
ff0 = ff;
end
end
end
function [dtm, dti] = dtmatrix(TU, T0, n, dy, props, piping)
%DTmatrix. Temperature profile linear system matrix
% rho : density
% cpf : heat capacity
% Tin : medium temperature
% di : flowline internal diameter
% uc : flowline U coefficient
% qf : fluid volumetric flowrate
rho = props(2:end, 1); % kg/m3
cpf = props(2:end, 2); % kJ/kg.K
Tin = props(2:end, 3); % K
di = piping(2:end, 1); % m
uc = piping(2:end, 3); % kW/m2.K
qf = piping(2:end, 4); % m3/s
mf = rho.*qf; % kg/s
ai = dy*pi*di; % m2
dti = zeros(n + 1, 1);
switch lower(TU.CalculationType)
case 'forward'
dtm = sparse([2:n+1 2:n+1], [1:n 2:n+1], [(ai.*uc - 2*mf.*cpf) ...
(ai.*uc + 2*mf.*cpf)]);
dtm(1, 1) = 1;
dti(1) = T0;
dti(2:n+1) = 2*ai.*uc.*Tin;
case 'backward'
dtm = sparse([1:n 1:n], [1:n 2:n+1], [(ai.*uc - 2*mf.*cpf) ...
(ai.*uc + 2*mf.*cpf)]);
dtm(end, end) = 1;
dti(end) = T0;
dti(1:end-1) = 2*ai.*uc.*Tin;
end
end
function [dpm, dpi] = dpmatrix(TU, P0, n, dy, props, piping)
%DPmatrix. Pressure profile linear system matrix
% rho : density
% vnu : dynamic viscosity
% di : flowline internal diameter
% rg : flowline roughness (E)
% um : fluid velocity
% in : flowline inclination
% ga : gravity acceleration
% ted : flowline relative roughness (E/di)
% ff : friction factor
% tRe : Reynolds number
rho = props(2:end, 1); % kg/m3
vnu = props(2:end, 2)./rho; % m2/s
di = piping(2:end, 1); % m
rg = piping(2:end, 2); % m
um = piping(2:end, 5); % m/s
in = cos(pi/2 - piping(2:end, 7)); % -
ga = TU.g; % m/s2
ted = rg./di; % -
ff = zeros(n , 1); % -
tRe = um.*di./vnu; % -
for i = 1:n
ff(i) = colebrook(TU, tRe(i), ted(i));
end
dpi = zeros(n + 1, 1);
switch lower(TU.CalculationType)
case 'forward'
dpm = sparse([2:n+1 1:n+1], [1:n 1:n+1], ...
[-ones(1, n), ones(1, n + 1)]);
dpi(1) = P0*1000; % Pa
dpi(2:end) = -dy*rho.*(ga.*in + ff.*um.^2./(2*di));
case 'backward'
dpm = sparse([1:n 1:n+1], [1:n 1:n+1], ...
[-ones(1, n), ones(1, n + 1)]);
dpi(end) = P0*1000; % Pa
dpi(1:end-1) = -dy*rho.*(ga.*in + ff.*um.^2./(2*di));
end
end
function [piping, dy, sn] = mpiping(TU)
%Mpiping. Piping parameter values
% ln : flowline length
% di : flowline internal diameter
% uc : flowline U coeffiecient
% rg : flowline roughness
% in : inclination
% sl : minimum length of piping segment
% sn : number of segments
% dy : length of piping segment
switch lower(TU.CalculationType)
case 'forward'
Q = TU.Qi;
case 'backward'
Q = TU.Qo;
end
ln = TU.tln; % m
di = TU.tdi; % m
uc = TU.tuc; % kW/m2.K
rg = TU.trg; % m
in = TU.tin; % rad
sl = TU.tsl; % m
sn = round(ln/sl) + 1;
dy = ln/sn; % m
piping = zeros(sn + 1, 6);
piping(:, 1) = di; % m
piping(:, 2) = rg; % m
piping(:, 3) = uc; % kW/m2.K
piping(:, 4) = Q/(3600*24); % m3/s
piping(:, 5) = Q/(900*24*pi*di^2); % m/s
piping(:, 6) = TU.tlengthp; % m
piping(:, 7) = in; % -
end
function props = mprops(TU, n, type)
%Mprops. Fluid property values
% emurho : density emulsion
% emuCp : specific heat capacity emulsion
% emuvnu : dynamic viscosity emulsion
switch type
case 'Tprofile'
props = zeros(n + 1, 3);
props(:, 1) = emurho(TU)*16.0186; % kg/m3
props(:, 2) = emuCp(TU)*4.2216; % kJ/kg.K
props(:, 3) = TU.tTinf + 273.15; % K
case 'Pprofile'
props = zeros(n + 1, 2);
props(:, 1) = emurho(TU)*16.0186; % kg/m3
props(:, 2) = emuvnu(TU)/1e3; % Pa.s
end
end
function mCp = emuCp(TU)
%SpecificHeat. (emulsion) Average with weight fraction
%Units
% mCp : BTU/lb.R
switch lower(TU.CalculationType)
case 'forward'
qo = TU.Qi;
case 'backward'
qo = TU.Qo;
end
Fo = qo*TU.BOmodel.orho;
Fw = qo*(TU.BOmodel.WC/1e2)*TU.BOmodel.wrho;
mCp = (TU.BOmodel.oCp*Fo + TU.BOmodel.wCp*Fw)/(Fw + Fo);
end
function mrho = emurho(TU)
%Density. (emulsion) Mass balance
%Units
% mrho : lb/ft3
switch lower(TU.CalculationType)
case 'forward'
qo = TU.Qi;
case 'backward'
qo = TU.Qo;
end
qw = qo*TU.BOmodel.WC/1e2;
mrho = (qo*TU.BOmodel.orho + qw*TU.BOmodel.wrho)/(qo + qw);
end
function mnu = emuvnu(TU)
%Viscosity. (emulsion) Richardson model
%Units
% mnu : cP
tTprofile = TU.Tprofile;
n = size(tTprofile, 1);
mnu = zeros(n, 1);
for i = 1:n
TU.BOmodel.T = 1.8*tTprofile(i) - 460;
mnu(i) = TU.BOmodel.emu;
end
end
function nT = conversionT(~, oT, type)
%conversionT. Temperature
switch lower(type)
case 'c'
nT = (oT - 32)/1.8;
case 'f'
nT = oT*1.8 + 32;
end
end
function nP = conversionP(~, oP, type)
%conversationP. Pressure
switch lower(type)
case 'psi'
nP = oP*14.7/101.325;
case 'kpa'
nP = oP*101.325/14.7;
end
end
function QCalculation(TU)
%Qcalculation. Flowrate at actual conditions
%Units
% P: kPa
% T: C
if isempty(TU.Qsc)
return
end
TU.BOmodel.P = conversionP(TU, TU.Po, 'psi');
TU.BOmodel.T = conversionT(TU, TU.To, 'F');
qs2r = TU.BOmodel.qsc2ac;
qiac = qs2r*TU.Qsc;
switch lower(TU.CalculationType)
case 'forward'
TU.Qo = sum(qiac);
case 'backward'
TU.Qi = sum(qiac);
end
end
end
methods
% -- information and plotting methods --
function PlotPprofile(TU)
%PlotPprofile. Plot length - pressure
% Plotting the pressure profile of the well along its length
if ~TU.status
error('FlowlineObj:NotEnoughArguments', ...
'The flowline element must be properly defined')
end
figure
axes
hold on
grid on
dprofile = TU.tlengthp;
pprofile = TU.Pprofile;
plot(dprofile, pprofile, '--o', 'MarkerFaceColor', 'b')
set(gca, 'YLim', [round(min(pprofile*0.95)) round(max(pprofile*1.05))], ...
'XLim', [round(min(dprofile*0.95)) round(max(dprofile*1.05))], ...
'FontName', 'Segoe UI')
xlabel(gca, 'Flowline length (m)')
ylabel(gca, 'Pressure (kPa)')
title(gca, 'Pressure profile in the flowline')
legend('Pressure drop along the flowline', 'Location', 'southwest');
hold off
end
function PlotTprofile(TU)
%PlotTprofile. Plot temperature - length
% Plotting the temperature profile of the well along its length
if ~TU.status
error('FlowlineObj:NotEnoughArguments', ...
'The flowline element must be properly defined')
end
figure
axes
hold on
grid on
dprofile = TU.tlengthp;
tprofile = TU.Tprofile;
plot(dprofile, tprofile, '--o', 'MarkerFaceColor', 'b')
set(gca, 'YLim', [round(min(tprofile*0.95)) round(max(tprofile*1.05))], ...
'XLim', [round(min(dprofile*0.95)) round(max(dprofile*1.05))], ...
'FontName', 'Segoe UI')
xlabel(gca, 'Flowline length (m)')
ylabel(gca, 'Temperature (K)')
title(gca, 'Temperature profile in the flowline')
legend('Tempeture gradient along the flowline', 'Location', 'southwest');
hold off
end
function PlotPTprofile(TU)
%PlotPTprofile. Plot temperature - length
% Plotting the temperature profile of the well along its length
if ~TU.status
error('FlowlineObj:NotEnoughArguments', ...
'The flowline element must be properly defined')
end
figure
dprofile = TU.tlengthp;
tprofile = TU.Tprofile;
pprofile = TU.Pprofile;
cat = axes('XAxisLocation', 'bottom', 'YAxisLocation', 'left', ...
'Box', 'on');
psp = get(cat, 'Position');
cap = axes('Position', psp, 'XAxisLocation', 'top', ...
'YAxisLocation', 'right', 'Box', 'on', 'Color','none');
ylabel('Temperature (K)', 'Parent', cat)
xlabel('Flowline length (m)', 'Parent', cat)
ylabel('Pressure (kPa)', 'Parent', cap)
xlabel('Flowline length (m)', 'Parent', cap)
set(cat, 'YLim', [round(min(tprofile*0.95)) round(max(tprofile*1.05))], ...
'XLim', [round(min(dprofile*0.95)) round(max(dprofile*1.05))], ...
'FontName', 'Segoe UI')
set(cap, 'YLim', [round(min(pprofile*0.95)) round(max(pprofile*1.05))], ...
'XLim', [round(min(dprofile*0.95)) round(max(dprofile*1.05))], ...
'FontName', 'Segoe UI')
line(dprofile, pprofile, 'Parent', cap, 'Color', 'r', ...
'LineStyle','--')
line(dprofile, tprofile, 'Parent', cat, 'Color', 'b',...
'LineStyle','--')
grid on
end
end
end