File: test_two_phase_voidage.py

package info (click to toggle)
python-fluids 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,384 kB
  • sloc: python: 59,459; f90: 1,033; javascript: 49; makefile: 47
file content (313 lines) | stat: -rw-r--r-- 9,675 bytes parent folder | download
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
'''Chemical Engineering Design Library (ChEDL). Utilities for process modeling.
Copyright (C) 2016, 2017 Caleb Bell <Caleb.Andrew.Bell@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''

import pytest

from fluids.numerics import assert_close, assert_close1d, linspace
from fluids.two_phase_voidage import (
    Armand,
    Baroczy,
    Beattie_Whalley,
    Chisholm_Armand,
    Chisholm_voidage,
    Cicchitti,
    Dix,
    Domanski_Didion,
    Duckler,
    Fauske,
    Fourar_Bories,
    Graham,
    Gregory_Scott,
    Guzhov,
    Harms,
    Huq_Loth,
    Kawahara,
    Kopte_Newell_Chato,
    Lin_Kwok,
    Lockhart_Martinelli_Xtt,
    McAdams,
    Nicklin_Wilkes_Davidson,
    Nishino_Yamazaki,
    Rouhani_1,
    Rouhani_2,
    Smith,
    Steiner,
    Sun_Duffey_Peng,
    Tandon_Varma_Gupta,
    Thom,
    Turner_Wallis,
    Woldesemayat_Ghajar,
    Xu_Fang_voidage,
    Yashar,
    Zivi,
    density_two_phase,
    gas_liquid_viscosity,
    gas_liquid_viscosity_methods,
    homogeneous,
    liquid_gas_voidage,
    liquid_gas_voidage_methods,
    two_phase_voidage_experimental,
)


def test_Thom():
#    >>> from sympy import *
#    >>> x, rhol, rhog, mug, mul = symbols('x, rhol, rhog, mug, mul')
#    >>> Z = (rhol/rhog)**Rational(555,1000)*(mug/mul)**Rational(111,1000)
#    >>> gamma = Z**1.6
#    >>> alpha = (gamma*x/(1 + x*(gamma-1)))
#    >>> alpha
#    x*((mug/mul)**(111/1000)*(rhol/rhog)**(111/200))**1.6/(x*(((mug/mul)**(111/1000)*(rhol/rhog)**(111/200))**1.6 - 1) + 1)
#    >>> alpha.subs([(x, .4), (rhol, 800), (rhog, 2.5), (mul, 1E-3), (mug, 1E-5)])
#    0.980138792146901


    assert_close(Thom(.4, 800, 2.5, 1E-3, 1E-5), 0.9801482164042417)


def test_Zivi():
    assert_close(Zivi(.4, 800, 2.5), 0.9689339909056356)


def test_Smith():
    assert_close(Smith(.4, 800, 2.5), 0.959981235534199)

    # Quick test function, to ensure results are the same regardless of
    # the form of the expression
    def Smith2(x, rhol, rhog):
        K = 0.4
        first = 1 + rhog/rhol*K*(1/x-1)
        second = rhog/rhol*(1-K)*(1/x-1)
        third = ((rhol/rhog + K*(1/x-1))/(1 + K*(1/x -1)))**0.5
        return (first + second*third)**-1

    alpha_1 = [Smith(i, 800, 2.5) for i in linspace(1E-9,.99)]
    alpha_2 = [Smith2(i, 800, 2.5) for i in linspace(1E-9, .99)]
    assert_close1d(alpha_1, alpha_2)


def test_Fauske():
    assert_close(Fauske(.4, 800, 2.5), 0.9226347262627932)


def test_Chisholm_voidage():
    assert_close(Chisholm_voidage(.4, 800, 2.5), 0.949525900374774)


def test_Turner_Wallis():
    assert_close(Turner_Wallis(.4, 800, 2.5, 1E-3, 1E-5), 0.8384824581634625)


### Section 2

def test_homogeneous():
    assert_close(homogeneous(.4, 800, 2.5), 0.995334370139969)
    assert_close(homogeneous(1, 800, 2.5), 1)
    assert_close(homogeneous(0, 800, 2.5), 0)
    # 1./(1. + (1-x)/x*(rhog/rhol))


def test_Chisholm_Armand():
    assert_close(Chisholm_Armand(.4, 800, 2.5), 0.9357814394262114)


def test_Armand():
    assert_close(Armand(.4, 800, 2.5), 0.8291135303265941)


def test_Nishino_Yamazaki():
    assert_close(Nishino_Yamazaki(.4, 800, 2.5), 0.931694583962682)


def test_Guzhov():
    assert_close(Guzhov(.4, 800, 2.5, 1, .3), 0.7626030108534588)


def test_Kawahara():
    alphas_calc = [Kawahara(.4, 800, 2.5, D) for D in [0.001, 100E-6, 1E-7]]
    alphas_exp = [0.8291135303265941, 0.9276148194410238, 0.8952146812696503]
    assert_close1d(alphas_calc, alphas_exp)


### Drift flux models


def test_Lockhart_Martinelli_Xtt():
    assert_close(Lockhart_Martinelli_Xtt(0.4, 800, 2.5, 1E-3, 1E-5), 0.12761659240532292)
    assert_close(Lockhart_Martinelli_Xtt(0.4, 800, 2.5, 1E-3, 1E-5, n=0.2), 0.12761659240532292)


def test_Baroczy():
    assert_close(Baroczy(.4, 800, 2.5, 1E-3, 1E-5), 0.9453544598460807)


def test_Tandon_Varma_Gupta():
    alphas_calc = [Tandon_Varma_Gupta(.4, 800, 2.5, 1E-3, 1E-5, m, 0.3) for m in [1, .1]]
    assert_close1d(alphas_calc, [0.9228265670341428, 0.8799794756817589])


def test_Harms():
    assert_close(Harms(.4, 800, 2.5, 1E-3, 1E-5, m=1, D=0.3), 0.9653289762907554)


def test_Domanski_Didion():
    assert_close(Domanski_Didion(.4, 800, 2.5, 1E-3, 1E-5), 0.9355795597059169)
    assert_close(Domanski_Didion(.002, 800, 2.5, 1E-3, 1E-5), 0.32567078492010837)


def test_Graham():
    assert_close(Graham(.4, 800, 2.5, 1E-3, 1E-5, m=1, D=0.3), 0.6403336287530644)
    assert 0 == Graham(.4, 800, 2.5, 1E-3, 1E-5, m=.001, D=0.3)


def test_Yashar():
    assert_close(Yashar(.4, 800, 2.5, 1E-3, 1E-5, m=1, D=0.3), 0.7934893185789146)


def test_Huq_Loth():
    assert_close(Huq_Loth(.4, 800, 2.5), 0.9593868838476147)


def test_Kopte_Newell_Chato():
    assert_close(Kopte_Newell_Chato(.4, 800, 2.5, m=1, D=0.3), 0.6864466770087425)
    assert_close(Kopte_Newell_Chato(.4, 800, 2.5, m=.01, D=0.3), 0.995334370139969)


def test_Steiner():
    assert_close(Steiner(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3), 0.895950181381335)


def test_Rouhani_1():
    assert_close(Rouhani_1(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3), 0.8588420244136714)


def test_Rouhani_2():
    assert_close(Rouhani_2(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3), 0.44819733138968865)


def test_Nicklin_Wilkes_Davidson():
    assert_close(Nicklin_Wilkes_Davidson(0.4, 800., 2.5, m=1, D=0.3), 0.6798826626721431)


def test_Gregory_Scott():
    assert_close(Gregory_Scott(0.4, 800., 2.5), 0.8364154370924108)


def test_Dix():
    assert_close(Dix(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3), 0.8268737961156514)


def test_Sun_Duffey_Peng():
    assert_close(Sun_Duffey_Peng(0.4, 800., 2.5, sigma=0.02, m=1, D=0.3, P=1E5, Pc=7E6), 0.7696546506515833)


def test_Woldesemayat_Ghajar():
    assert_close(Woldesemayat_Ghajar(0.4, 800., 2.5, sigma=0.2, m=1, D=0.3, P=1E6, angle=45.0), 0.7640815513429202)


def test_Xu_Fang_voidage():
    assert_close(Xu_Fang_voidage(0.4, 800., 2.5, m=1, D=0.3), 0.9414660089942093)


def test_liquid_gas_voidage():
    voidage = liquid_gas_voidage(m=0.6, x=0.1, rhol=915., rhog=2.67, mul=180E-6, mug=14E-6, sigma=0.0487, D=0.05)
    assert_close(voidage, 0.9744097632663492)

    kwargs = dict(m=0.6, x=0.1, rhol=915., rhog=2.67, mul=180E-6, mug=14E-6, sigma=0.0487, D=0.05, P=1e5, Pc=1e7)
    for m in liquid_gas_voidage_methods(**kwargs):
        liquid_gas_voidage(Method=m, **kwargs)

    with pytest.raises(Exception):
        liquid_gas_voidage(Method='BADMETHOD', **kwargs)

    assert len(liquid_gas_voidage_methods(**kwargs)) == 29

def test_density_two_phase():
    assert_close(density_two_phase(.4, 800.0, 2.5), 481.0)


def test_two_phase_voidage_experimental():
    alpha = two_phase_voidage_experimental(481.0, 800.0, 2.5)
    assert_close(alpha, 0.4)


def test_Beattie_Whalley():
    mu = Beattie_Whalley(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2)
    assert_close(mu, 1.7363806909512365e-05)


def test_McAdams():
    mu = McAdams(x=0.4, mul=1E-3, mug=1E-5)
    assert_close(mu, 2.4630541871921184e-05)


def test_Cicchitti():
    mu = Cicchitti(x=0.4, mul=1E-3, mug=1E-5)
    assert_close(mu, 0.000604)


def test_Lin_Kwok():
    mu = Lin_Kwok(x=0.4, mul=1E-3, mug=1E-5)
    assert_close(mu, 3.515119398126066e-05)

def test_Fourar_Bories():
    mu = Fourar_Bories(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2)
    assert_close(mu, 2.127617150298565e-05)


def tets_Duckler():
    mu =  Duckler(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2)
    assert_close(mu, 1.2092040385066917e-05)


    def Duckler1(x, mul, mug, rhol, rhog):
        # Effective property models for homogeneous two-phase flows.
        # different formulation
        rhom = 1./(x/rhog + (1. - x)/rhol)
        return rhom*(x*(mug/rhog) + (1. - x)*mul/rhol)


    mu = Duckler1(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2)
    assert_close(mu, 1.2092040385066917e-05)


def test_gas_liquid_viscosity():
    mu = gas_liquid_viscosity(x=0.4, mul=1E-3, mug=1E-5)
    assert_close(2.4630541871921184e-05, mu)

    mu = gas_liquid_viscosity(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2, Method='Duckler')
    assert_close(mu, 1.2092040385066917e-05)

    simple_methods = gas_liquid_viscosity_methods()
    assert list(sorted(simple_methods)) == list(sorted(['McAdams', 'Cicchitti', 'Lin Kwok']))

    all_methods = gas_liquid_viscosity_methods(rhol=1000.0, rhog=2.)
    all_methods_expect = ['Beattie Whalley', 'Fourar Bories', 'Duckler', 'McAdams', 'Cicchitti', 'Lin Kwok']
    assert list(sorted(all_methods)) == list(sorted(all_methods_expect))

    for m in all_methods_expect:
        gas_liquid_viscosity(x=0.4, mul=1E-3, mug=1E-5, rhol=850.0, rhog=1.2, Method=m)



    with pytest.raises(Exception):
        gas_liquid_viscosity(x=0.4, mul=1E-3, mug=1E-5, Method='NOTAMETHOD')