-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thesis_Multiphase_Flow_Regime_Model.py
1106 lines (934 loc) · 25.7 KB
/
Thesis_Multiphase_Flow_Regime_Model.py
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""Copy of Thesis_colab.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1SrQ0o9HZ0bviXZUCRzN0MXjpDr--cIY5
"""
from math import *
import math
import matplotlib.pyplot as plt
import statistics
plt.style.use('classic')
plt.rcParams.update({'font.size': 8})
def data(): #Input
global rho_l, rho_g, vis_l, vis_g, A, phi, eps, g, diameter, sigma, Usg_input, Usl_input
global EPS, usl_max_slug_input
global L_l, L_r, p_out, RT, Pnormal, C_valve, Usl_min_input, Usl_max_input, Usl_step_input
global Usg_min_input, Usg_max_input, Usg_step_input
#Flow regime map
diameter=0.15 #m (pipe diameter)
A=pi*(diameter**2)/4 #m2 (pipe area)
rho_g=11.8 #kg/m3 (gas density)
rho_l=776 #kg/m3 (liquid density)
vis_l=0.001 #Pa.s (liquid viscosity)
vis_g=0.0001 #Pa.s (gas viscosity)
rad=-1 #degrees (pipe inclination)
phi=math.radians(rad)
eps=0.000025 #m (roughness)
g=9.8 #kg.m/s2 (gravity constant)
sigma=0.016 #N/m (surface tension)
#Severe Slugging
L_l=200 #m (line length)
L_r=15 #m (riser length)
p_out=100000 #Pa (pressure separator)
RT=100000 #J/kg (gas Constant*temperature)
Pnormal=100000 #Pa (pressure inlet)
C_valve=0 #(valve constant)
EPS=0.0001
#For Holdup Curve and Severe Slugging Model
Usl_input=0.3 #m/s
Usg_input=0.5 #m/s
#Map Boundary
Usl_min_input=1e-3
Usl_max_input=50
Usg_min_input=0
Usg_max_input=50
Usg_step_input=100
########################################################################################################
def boe():
global U_ls
U_ls=Pnormal*U_sg/((rho_l-rho_g)*g*L_r*(U_sg)/(U_sg+U_sl))
def annular():
global Y, Z, voidannular, alfa_check, void_min
#Velocity
alfa = alfa_annular
alfa_check=alfa
U_l=U_sl/(1-alfa)
U_g=U_sg/alfa
#Geometry
S_l=diameter*pi
S_i=diameter*pi*(alfa)**(1/2)
d_f=(diameter/2)*(1-alfa**(1/2))
Dh_l=(4*(1-alfa)*A)/S_l
Dh_g=diameter-2*d_f
#Friction
N_re_l=rho_l*abs(U_l)*Dh_l/vis_l
N_re_g=rho_g*abs(U_g)*Dh_g/vis_g
if N_re_g>4000:
C_g=0.046
n_g=0.2
else:
C_g=16
n_g=1
if N_re_l>4000:
C_l=0.046
n_l=0.2
else:
C_l=16
n_l=1
lambda_l_blasius=C_l*N_re_l**(-n_l)
lambda_g_blasius=C_l*N_re_g**(-n_g)
lambda_g=lambda_g_blasius
lambda_l=lambda_l_blasius
lambda_i=lambda_g*(1+150*(1-alfa**1/2))
F_w=(1/2)*rho_l*lambda_l*abs(U_l)*U_l*S_l/(A)
F_i=(1/2)*rho_g*lambda_i*abs(U_g)*(U_g)*S_i/(A)
#Gravity
G_l=rho_l*g*sin(phi)
G_g=rho_g*g*sin(phi)
#Holdup equation
voidannular=-F_w/(1-alfa)+F_i*(1/(1-alfa)+(1/alfa))-(G_l-G_g)
void_min=g*(rho_l-rho_g)*diameter*sin(phi/2)*(3*alfa/2-1)-1/16*C_l*rho_l*(rho_l*Dh_l/vis_l)**(-n_l)*(U_sl)**(2-n_l)*((1/2+3*alfa/4)/(1/2-alfa/4)**3)
def bubble_slug():
global void_bubble_slug
#Geometry
theta_b=pi*(1-alfa_b)+(3*pi/2)*(1-2*(1-alfa_b)+(1-alfa_b)**(1/3)-alfa_b**(1/3))
S_lb=theta_b*diameter
S_gb=pi*diameter-S_lb
S_ib=diameter*sin(theta_b)
Dh_lb=(4*(1-alfa_b)*A)/S_lb
Dh_gb=(4*(alfa_b)*A)/(S_gb+S_ib)
#Velocity
U_gb=U_t-(alfa_s/alfa_b)*(U_t-U_gs)
U_lb=U_t-((1-alfa_s)/(1-alfa_b))*(U_t-U_ls)
#Friction
N_re_lb=rho_l*abs(U_lb)*Dh_lb/vis_l
N_re_gb=rho_g*abs(U_gb)*Dh_gb/vis_g
lambda_l_haaland=(1/(1.8*log((6.9/N_re_lb)+(eps/(3.7*Dh_lb))**1.11)))**2
lambda_g_haaland=(1/(1.8*log((6.9/N_re_gb)+(eps/(3.7*Dh_gb))**1.11)))**2
lambda_gb=max(lambda_g_haaland,64/N_re_gb)
lambda_lb=max(lambda_l_haaland,64/N_re_lb)
lambda_ib=lambda_gb
F_lb=(S_lb/(8*A))*rho_l*lambda_lb*abs(U_lb)*U_lb
F_gb=(S_gb/(8*A))*rho_g*lambda_gb*abs(U_gb)*U_gb
F_ib=(S_ib/(8*A))*rho_g*lambda_ib*abs(U_gb-U_lb)*(U_gb-U_lb)
#Holdup Equation
void_bubble_slug=F_ib+(1-alfa_b)*F_gb-alfa_b*F_lb-alfa_b*(1-alfa_b)*sin(phi)*(rho_l-rho_g)
def stratified():
global void_strat, U_gTD, U_g, h_l, U_gKH, Usl_limit
#Geometry
theta=pi*(1-alfa)+(3*pi/2)*(1-2*(1-alfa)+(1-alfa)**(1/3)-alfa**(1/3))
h_l=diameter*(1-cos(theta))/2
S_l=theta*diameter
S_g=pi*diameter-S_l
S_i=diameter*sin(theta)
Dh_l=(4*(1-alfa)*A)/S_l
Dh_g=(4*(alfa)*A)/(S_g+S_i)
#Flow
U_l=U_sl/(1-alfa)
U_g=U_sg/alfa
#Taitel Duckler
C_2=1-h_l/diameter
A_g=alfa*A
U_gTD=C_2*(g*(rho_l-rho_g)*A_g*cos(phi)/(rho_g*S_i))**0.5
N_re_l=rho_l*abs(U_l)*Dh_l/vis_l
N_re_g=rho_g*abs(U_g)*Dh_g/vis_g
#Friction Haaland (page 45)
lambda_l_haaland=(1/(1.8*log((6.9/N_re_l)+(eps/(3.7*Dh_l))**1.11)))**2
lambda_g_haaland=(1/(1.8*log((6.9/N_re_g)+(eps/(3.7*Dh_g))**1.11)))**2
lambda_g=max(lambda_g_haaland,64/N_re_g)
lambda_l=max(lambda_l_haaland,64/N_re_l)
lambda_i_haaland=lambda_g
lambda_i=(lambda_i_haaland)
F_l=rho_l*lambda_l*abs(U_l)*U_l*S_l/(8*A)
F_g=rho_g*lambda_g*abs(U_g)*U_g*S_g/(8*A)
F_i=rho_g*lambda_i*abs(U_g-U_l)*(U_g-U_l)*S_i/(8*A)
#Gravity
G_l=(1-alfa)*rho_l*g*sin(phi)
G_g=alfa*rho_g*g*sin(phi)
#Holdup equation
void_strat=F_i+(1-alfa)*F_g-alfa*F_l-alfa*(1-alfa)*sin(phi)*(rho_l-rho_g)
def slug():
global H_slug, SF, U_t, U_gs, U_ls, alfa_s
#void fraction slug
alfa_s= (U_sg+U_sl)/(83*(g*sigma/rho_l)**0.25+(U_sg+U_sl))
#slip relation
S_D=(1-alfa_s)/(0.95-alfa_s) #distribution
U_os=1.18*(g*sigma*(rho_l-rho_g)/rho_l**2)**(1/4)*(1-alfa_s)**(1/2) #rising velocity of gas in slug
U_ls=((U_sg+U_sl)-S_D*alfa_s*U_os)/(alfa_s*(S_D-1)+1) #there is 2 others
U_gs=S_D*(U_ls+U_os)
U_ov=0.35*(g*diameter*(rho_l-rho_g)/rho_l)**(1/2)
U_oh=0.54*(g*diameter*(rho_l-rho_g)/rho_l)**(1/2)
Fr_lim=3.6
Fr=(U_sg+U_sl)/(g*diameter*(rho_l-rho_g)/rho_l)**0.5
C_o_1=1.05+0.15*(sin(phi))**2
U_o_1=-U_ov*sin(phi)+U_oh*cos(phi)
U_b_1=C_o_1*(U_sg+U_sl)+U_o_1
C_o_2=1.2
U_o_2=-U_ov*sin(phi)
U_b_2=C_o_2*(U_sg+U_sl)+U_o_2
U_b=max(U_b_1, U_b_2)
U_t=U_b
#find alfa_b from stratified holdup equation
bisectvoid_bubble_slug()
#bubble velocity
U_gb=U_t-(alfa_s/alfa_b)*(U_t-U_gs)
U_lb=U_t-((1-alfa_s)/(1-alfa_b))*(U_t-U_ls)
#slug geometry
SF=1-(U_sg-U_gs*alfa_s)/(U_t*(alfa_b-alfa_s))
H_slug=SF*(1-alfa_s)+(1-SF)*(1-alfa_b)
def bubble():
global d_max, d_cb, d_cd, check_null, alfa
U_m=U_sl+U_sg
alfa=U_sg/U_m
rho_m=alfa*rho_g+(1-alfa)*rho_l
vis_m=alfa*vis_g+(1-alfa)*vis_l
N_re_m=rho_m*abs(U_m)*diameter/vis_m
if N_re_m>4000:
C_m=0.046
n_m=0.2
else:
C_m=16
n_m=1
lambda_m_blasius=C_m*N_re_m**(-n_m)
lambda_m=lambda_m_blasius
epsilon=2*lambda_m*U_m**3/diameter
d_max=(0.725+4.15*alfa**0.5)*(sigma/rho_l)**0.6*(epsilon)**-0.4
d_cd=2*(0.4*sigma/((rho_l-rho_g)*g))**0.5
d_cb=(3/8)*(rho_l/(rho_l-rho_g))*(lambda_m*U_m**2)/(g*cos(phi))
#there are 2 other equation
A=1.53*(g*sigma*(rho_l-rho_g)/rho_l**2)**(1/4)*(1-alfa)**0.5*sin(phi)
B=U_sg/alfa-1.2*U_m
check_null=A-B
########################################################################################################
def bisectvoid_annular():
global alfa_annular
data()
x=0.5
dx=diameter/10
tol=1e-5
a=x-dx
alfa_annular=a
annular()
fa=voidannular
b=x+dx
alfa_annular=b
annular()
fb=voidannular
count=0
countmax=100
while (fa > 0)==(fb > 0):
count=count+1
dx=dx*2
a=x-dx
a=max(a,1e-6)
alfa_annular=a
annular()
fa=voidannular
if (fa > 0)!=(fb > 0):
break
if count>=countmax:
break
b=x+dx
b=min(b,0.9999)
alfa_annular=b
annular()
fb=voidannular
count=0
while abs(b-a) > 2.0*tol*max(abs(b),1.0):
c=a+0.5*(b-a)
alfa_annular=c
annular()
fc=voidannular
count=count+1
if (fb > 0)==(fc > 0):
b=c
fb=fc
else:
a=c
fa=fc
if count>=countmax:
break
alfa_annular=b
def bisectvoid_strat():
global alfa
data()
x=0.5
dx=diameter/10
tol=1e-5
a=x-dx
alfa=a
stratified()
fa=void_strat
b=x+dx
alfa=b
stratified()
fb=void_strat
count=0
countmax=100
while (fa > 0)==(fb > 0):
count=count+1
dx=dx*2
a=x-dx
a=max(a,1e-6)
alfa=a
stratified()
fa=void_strat
if (fa > 0)!=(fb > 0):
break
if count>=countmax:
break
b=x+dx
b=min(0.99999,b)
alfa=b
stratified()
fb=void_strat
count=0
while abs(b-a) > 2.0*tol*max(abs(b),1.0):
c=a+0.5*(b-a)
alfa=c
stratified()
fc=void_strat
count=count+1
if (fb > 0)==(fc > 0):
b=c
fb=fc
else:
a=c
fa=fc
if count>=countmax:
break
alfa=b
def bisectvoid_bubble():
global alfa
data()
x=0.5
dx=1/100
tol=1e-5
a=x-dx
alfa=a
bubble()
fa=check_null
b=x+dx
alfa=b
bubble()
fb=check_null
count=0
countmax=100
while (fa > 0)==(fb > 0):
count=count+1
dx=dx*2
a=x-dx
a=max(a,1e-6)
alfa=a
bubble()
fa=check_null
if (fa > 0)!=(fb > 0):
break
if count>=countmax:
break
b=x+dx
b=min(b,0.9999)
alfa=b
bubble()
fb=check_null
count=0
while abs(b-a) > 2.0*tol*max(abs(b),1.0):
c=a+0.5*(b-a)
alfa=c
bubble()
fc=check_null
count=count+1
if (fb > 0)==(fc > 0):
b=c
fb=fc
else:
a=c
fa=fc
if count>=countmax:
break
alfa=b
def bisectvoid_bubble_slug():
global alfa_b
data()
x=0.5
dx=diameter/10
tol=1e-5
a=x-dx
alfa_b=a
bubble_slug()
fa=void_bubble_slug
b=x+dx
alfa_b=b
bubble_slug()
fb=void_bubble_slug
count=0
countmax=100
while (fa > 0)==(fb > 0):
count=count+1
dx=dx*2
a=x-dx
a=max(a,1e-5)
alfa_b=a
bubble_slug()
fa=void_bubble_slug
if (fa > 0)!=(fb > 0):
break
if count>=countmax:
break
b=x+dx
b=min(0.99999,b)
alfa_b=b
bubble_slug()
fb=void_bubble_slug
count=0
while abs(b-a) > 2.0*tol*max(abs(b),1.0):
c=a+0.5*(b-a)
alfa_b=c
bubble_slug()
fc=void_bubble_slug
count=count+1
if (fb > 0)==(fc > 0):
b=c
fb=fc
else:
a=c
fa=fc
if count>=countmax:
break
alfa_b=b
def bisectvoid_annular_min():
global alfa_annular
data()
x=0.5
dx=diameter/10
tol=1e-5
a=x-dx
alfa_annular=a
annular()
fa=void_min
b=x+dx
alfa_annular=b
annular()
fb=void_min
count=0
countmax=100
while (fa > 0)==(fb > 0):
count=count+1
dx=dx*2
a=x-dx
a=max(a,1e-6)
alfa_annular=a
annular()
fa=void_min
if (fa > 0)!=(fb > 0):
break
if count>=countmax:
break
b=x+dx
b=min(b,0.9999)
alfa_annular=b
annular()
fb=void_min
count=0
while abs(b-a) > 2.0*tol*max(abs(b),1.0):
c=a+0.5*(b-a)
alfa_annular=c
annular()
fc=void_min
count=count+1
if (fb > 0)==(fc > 0):
b=c
fb=fc
else:
a=c
fa=fc
if count>=countmax:
break
alfa_annular=b
########################################################################################################
def test_barnea_1():
global lowerbound, higherbound, U_sl
Accuracy=1e-5
lowerbound=Usl_min_input
higherbound=Usl_max_input
countmax=100
count=0
while ((higherbound - lowerbound) > Accuracy ):
count=count+1
U_sl= 0.5*(lowerbound+higherbound)
bisectvoid_annular_min()
alfa_min=alfa_check
bisectvoid_annular()
if count>=countmax:
break
if alfa_min<0.76:
if alfa_check<0.76: #slug flow criterion b
higherbound=U_sl
else:
lowerbound=U_sl
else:
if alfa_check<alfa_min: #slug flow criterion a
higherbound=U_sl
else:
lowerbound=U_sl
def test_bendiksen_espedal_1():
global lowerbound, higherbound, U_sl
Accuracy=1e-5
lowerbound=Usl_min_input
higherbound=Usl_max_input
countmax=100
count=0
while ((higherbound - lowerbound) > Accuracy ):
count=count+1
U_sl= 0.5*(lowerbound+higherbound)
slug()
bisectvoid_strat()
H_strat=1-alfa
if count>=countmax:
break
if H_slug>=H_strat: #no slug (SF=0)
lowerbound=U_sl
else:
higherbound=U_sl
def test_barnea_bubble():
global lowerbound, higherbound, U_sl
Accuracy=1e-5
lowerbound=Usl_min_input
higherbound=Usl_max_input
countmax=100
count=0
while ((higherbound - lowerbound) > Accuracy ):
count=count+1
U_sl= 0.5*(lowerbound+higherbound)
bubble()
if count>=countmax:
break
if alfa<0.52:
if d_max<=min(d_cd,d_cb): #slug flow/elongated bubble
higherbound=U_sl
else:
lowerbound=U_sl
else:
lowerbound=U_sl
def test_taitel_duckler_2(): #or Inviscid Kelvin Helmholtz
global lowerbound, higherbound, U_sl
Accuracy=1e-5
lowerbound=Usl_min_input
higherbound=Usl_max_input
countmax=100
count=0
while ((higherbound - lowerbound) > Accuracy ):
count=count+1
U_sl= 0.5*(lowerbound+higherbound)
bisectvoid_strat()
stratified()
if count>=countmax:
break
if U_g > U_gTD: #wavy stratified flow
higherbound=U_sl
else:
lowerbound=U_sl
def test_Boe():
global lowerbound, higherbound, U_sl
Accuracy=1e-5
lowerbound=Usl_min_input
higherbound=Usl_max_input
countmax=100
count=0
while ((higherbound - lowerbound) > Accuracy ):
count=count+1
U_sl= 0.5*(lowerbound+higherbound)
bisectvoid_strat()
boe()
if count>=countmax:
break
if U_sl > U_ls: #severe slugging
higherbound=U_sl
else:
lowerbound=U_sl
########################################################################################################
def maptrans_barnea_1(): #2
global barnea_1_Usl, barnea_1_Usg, U_sg
data()
barnea_1_Usg=[0]*Usg_step_input
barnea_1_Usl=[0]*Usg_step_input
dx=(Usg_max_input-Usg_min_input)/Usg_step_input
U_sg=Usg_min_input
for i in range(0,Usg_step_input):
U_sg=U_sg+dx
test_barnea_1()
U_sl= 0.5*(lowerbound+higherbound)
if U_sl<0:
barnea_1_Usl[i]=0
else:
barnea_1_Usl[i]=U_sl
barnea_1_Usg[i]=U_sg
def maptrans_bendiksen_espedal_1(): #4
global bendiksen_1_Usl, bendiksen_1_Usg, U_sg
data()
bendiksen_1_Usg=[0]*Usg_step_input
bendiksen_1_Usl=[0]*Usg_step_input
dx=(Usg_max_input-Usg_min_input)/Usg_step_input
U_sg=Usg_min_input
for i in range(0,Usg_step_input):
U_sg=U_sg+dx
test_bendiksen_espedal_1()
U_sl= 0.5*(lowerbound+higherbound)
if U_sl<0:
bendiksen_1_Usl[i]=0
else:
bendiksen_1_Usl[i]=U_sl
bendiksen_1_Usg[i]=U_sg
def maptrans_barnea_bubble(): #6
global bubble_Usl, bubble_Usg, U_sg
data()
bubble_Usg=[0]*Usg_step_input
bubble_Usl=[0]*Usg_step_input
dx=(Usg_max_input-Usg_min_input)/Usg_step_input
U_sg=Usg_min_input
for i in range(0,Usg_step_input):
U_sg=U_sg+dx
test_barnea_bubble()
U_sl= 0.5*(lowerbound+higherbound)
if U_sl<0:
bubble_Usl[i]=0
else:
bubble_Usl[i]=U_sl
bubble_Usg[i]=U_sg
def maptrans_taitel_duckler_2(): #8
global taitel_2_Usl, taitel_2_Usg, U_sg
data()
taitel_2_Usg=[0]*Usg_step_input
taitel_2_Usl=[0]*Usg_step_input
dx=(Usg_max_input-Usg_min_input)/Usg_step_input
U_sg=Usg_min_input
for i in range(0,Usg_step_input):
U_sg=U_sg+dx
test_taitel_duckler_2()
U_sl= 0.5*(lowerbound+higherbound)
if U_sl<0:
taitel_2_Usl[i]=0
else:
taitel_2_Usl[i]=U_sl
taitel_2_Usg[i]=U_sg
def maptrans_boe(): #10
global Boe_Usl, Boe_Usg, U_sg
data()
Boe_Usg=[0]*Usg_step_input
Boe_Usl=[0]*Usg_step_input
dx=(Usg_max_input-Usg_min_input)/Usg_step_input
U_sg=Usg_min_input
for i in range(0,Usg_step_input):
U_sg=U_sg+dx
test_Boe()
U_sl= 0.5*(lowerbound+higherbound)
if U_sl<0:
Boe_Usl[i]=0
else:
Boe_Usl[i]=U_sl
Boe_Usg[i]=U_sg
def maptrans():
maptrans_barnea_1()
maptrans_bendiksen_espedal_1()
maptrans_barnea_bubble()
maptrans_taitel_duckler_2()
maptrans_boe()
def holdup_curve():
global Usl_res, Usg_res, U_sg, U_sl
global H_annular_Usl_res, H_slug_Usl_res, H_stratified_Usl_res
global H_annular_Usg_res, H_slug_Usg_res, H_stratified_Usg_res
data()
Usl_res=[0]*20
Usg_res=[0]*20
H_annular_Usl_res=[0]*20
H_slug_Usl_res=[0]*20
H_stratified_Usl_res=[0]*20
H_annular_Usg_res=[0]*20
H_slug_Usg_res=[0]*20
H_stratified_Usg_res=[0]*20
for i in range(0,20):
U_sg=(i+1)/10
Usg_res[i]=U_sg
U_sl=Usl_input
bisectvoid_annular()
H_annular_Usl_res[i]=1-alfa_annular
slug()
H_slug_Usl_res[i]=H_slug
bisectvoid_strat()
H_stratified_Usl_res[i]=1-alfa
for i in range(0,20):
U_sl=(i+1)/10
Usl_res[i]=U_sl
U_sg=Usg_input
bisectvoid_annular()
H_annular_Usg_res[i]=1-alfa_annular
slug()
H_slug_Usg_res[i]=H_slug
bisectvoid_strat()
H_stratified_Usg_res[i]=1-alfa
########################################################################################################
def slug_boundary():
global p_max_ratio, usg_r_res, usl_r_res, p_res
global um_r_res, gravity_res, friction_res, H_res, t_res
data()
p_res=[0]*Nstep
usg_r_res=[0]*Nstep
usl_r_res=[0]*Nstep
um_r_res=[0]*Nstep
friction_res=[0]*Nstep
gravity_res=[0]*Nstep
H_res=[0]*Nstep
t_res=[0]*Nstep
#Pipe Geometry
D=diameter
A=pi*D**2/4
sinangle=sin(phi)
#Properties
Lambda=0.05
Rog_r=rho_g
Rol=rho_l
visl=vis_l
#Slip
S=1.2
uo=0.35*sqrt(9.81*D)
#Initial value
Rom=Rol
alfa_r=0
p=p_out+Rom*9.81*L_r
p_bend=p_out
z=0.0001
U_level=0
Ug_r=0
Um=Uslin_boundary
Rog_l=p/RT
for i in range(0,Nstep):
#Friction
Re=Rol*abs(Um)*D/visl
#Friction Haaland
lambda_haaland=(1/(1.8*log((6.9/Re)+(eps/(3.7*D))**1.11)))**2
Lambda=max(lambda_haaland,64/Re)
Fric=0.5*Lambda*Rol*Um*abs(Um)*(-z+(1-alfa_r)*L_r)/D
#Additional friction
Lambda_stagnant=10
Fric_stagnant=0.5*Lambda_stagnant*Rol*U_level*abs(U_level)*(-z+(1-alfa_r)*L_r)/D
Fric_valve=C_valve*Rol*Um*abs(Um)
Fric=Fric+Fric_stagnant+Fric_valve
#Gravity
Grav_l=-Rol*9.81*abs(z*sinangle)
Grav_r=Rom*9.81*L_r
Grav=Grav_l+Grav_r
#Simplification Variable (1)
LRo=-z*Rol+L_r*Rom
#U's Value
Um_old=Um
Um=Um_old+DeltaT*((p-p_out)-Fric-Grav-Fric_valve)/LRo
Ug_r=S*Um+uo
Usg_l=(Um-Uslin_boundary)*(Um>0)*(z>0)
Usl_l=(Uslin_boundary*(z>0)+Um*(z<0))*(Um>0)+Um*(Um<0)
Usg_r=(alfa_r*Ug_r*(z>0)+Um*(z<0))*(Um>0)+Um*(Um<0)
Usl_r=(Um-alfa_r*Ug_r)*(Um>0)*(z>0)
U=Usg_l-Usg_r-Usl_l+Usl_r
#Alfa Value
alfa_r_old=alfa_r
alfa_r=alfa_r_old+0.5*DeltaT*U/(-z+L_r)
alfa_r=max(0,alfa_r)
alfa_r=min(1,alfa_r)
#Gas Properties
Rog_l=p/RT
#Real Volume
L_g=L_l+z
#Level
U_level=(-Uslin_boundary+Um)
z_old=z
z=z_old+DeltaT*U_level
dHdt=((1-alfa_r)-(1-alfa_r_old))/DeltaT
z=(z<0)*z+(z>0)*EPS
U_level=U_level*(z<0)
#Pressure Value
p_old=p
p=p_old+DeltaT*(Usgin_boundary*Pnormal-Usg_l*p_old)/L_g-DeltaT*(p_old*U_level)/L_g
#Mixture Density
Rog_r=Rog_l
Rom=alfa_r*Rog_r+(1-alfa_r)*Rol
p_res[i]=p/100000
usg_r_res[i]=Usg_r
usl_r_res[i]=Usl_r
um_r_res[i]=Um
friction_res[i]=Fric
gravity_res[i]=Grav
H_res[i]=1-alfa_r
t_res[i]=i
p_res_half_mean=statistics.mean(p_res[15000:30000])
p_max_ratio=max(p_res[15000:30000])/p_res_half_mean-1
def boundary():
global transition_Usg, transition_Usl, Usgin_boundary, Uslin_boundary, nUsl_lines, Nstep, DeltaT
Nstep=30000
DeltaT=0.01
#start
nUsl_lines=25
Usl_test_1=[0]*16
Usl_test_2=[0]*9
for n in range (0,16):
Usl_test_1[n]=n/10+0.1
for n in range (0,9):
Usl_test_2[n]=n+2
Usl_test=Usl_test_1+Usl_test_2
transition_Usg=[0]*nUsl_lines
transition_Usl=[0]*nUsl_lines
for n in range (0,nUsl_lines):
Usl_boundary=Usl_test[n]
tol=0.01
countMax=20
dx=1
x=1
a=x
Usgin_boundary=x
Uslin_boundary=Usl_boundary
slug_boundary()
fa=p_max_ratio-0.1
b=x+dx
Usgin_boundary=b
Uslin_boundary=Usl_boundary
slug_boundary()
fb=p_max_ratio-0.1
count=0
while (fa>0)==(fb>0):
a=b
b=b+dx
Usgin_boundary=b
Uslin_boundary=Usl_boundary
slug_boundary()
fb=p_max_ratio-0.1
if (fa>0)!=(fb>0):
break
count=count+1
if (count>countMax):
break
count=0
while abs (b-a)>2*tol*max(abs(b),1):
c=a+0.5*(b-a)
Usgin_boundary=c
Uslin_boundary=Usl_boundary
slug_boundary()
fc=p_max_ratio-0.1
if (fb>0)==(fc>0):
b=c
fb=fc
else:
a=c
fa=fc
count=count+1
if (count>countMax):
break
Usg_boundary=c
transition_Usg[n]=Usg_boundary
transition_Usl[n]=Usl_boundary
def simplified_severe_slugging():
global Uslin_boundary, Usgin_boundary, Nstep, DeltaT
data()
Nstep=100000
DeltaT=0.01
Usgin_boundary=Usg_input
Uslin_boundary=Usl_input
slug_boundary()
########################################################################################################
def plot1(): #flow regime map and severe slugging stability
maptrans()
#boundary()
y1=barnea_1_Usg
x1=barnea_1_Usl
legend_y1='Annular Stability'
y2=bendiksen_1_Usg
x2=bendiksen_1_Usl
legend_y2='Slug Stability'
y3=bubble_Usg
x3=bubble_Usl
legend_y3='Bubble Stability'
y4=taitel_2_Usg
x4=taitel_2_Usl
legend_y4='Stratified Stability'
#y5=Boe_Usg
#x5=Boe_Usl
#legend_y5='Boe Stability'