Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Nov 29, 2024
1 parent 53ee4f3 commit 426a360
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
14 changes: 7 additions & 7 deletions fluids/flow_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@

LONG_RADIUS_NOZZLE = 'long radius nozzle'
ISA_1932_NOZZLE = 'ISA 1932 nozzle'
VENTURI_NOZZLE = 'venuri nozzle'
VENTURI_NOZZLE = 'venturi nozzle'

AS_CAST_VENTURI_TUBE = 'as cast convergent venturi tube'
MACHINED_CONVERGENT_VENTURI_TUBE = 'machined convergent venturi tube'
Expand Down Expand Up @@ -2391,7 +2391,7 @@ def differential_pressure_meter_beta(D, D2, meter_type):
'ISO 5167 orifice', 'Miller quarter circle orifice', 'Hollingshead venturi sharp',
'segmental orifice', 'Miller conical orifice', 'Miller segmental orifice',
'quarter circle orifice', 'Hollingshead v cone', 'wedge meter', 'eccentric orifice',
'venuri nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'venturi nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'ISO 15377 quarter-circle orifice', 'Hollingshead venturi smooth',
'Hollingshead orifice', 'cone meter', 'Hollingshead wedge', 'Miller orifice',
'long radius nozzle', 'ISO 15377 conical orifice', 'unspecified meter',
Expand Down Expand Up @@ -2468,7 +2468,7 @@ def differential_pressure_meter_C_epsilon(D, D2, m, P1, P2, rho, mu, k,
'ISO 5167 orifice', 'Miller quarter circle orifice', 'Hollingshead venturi sharp',
'segmental orifice', 'Miller conical orifice', 'Miller segmental orifice',
'quarter circle orifice', 'Hollingshead v cone', 'wedge meter', 'eccentric orifice',
'venuri nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'venturi nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'ISO 15377 quarter-circle orifice', 'Hollingshead venturi smooth',
'Hollingshead orifice', 'cone meter', 'Hollingshead wedge', 'Miller orifice',
'long radius nozzle', 'ISO 15377 conical orifice', 'unspecified meter',
Expand Down Expand Up @@ -2576,7 +2576,7 @@ def differential_pressure_meter_C_epsilon(D, D2, m, P1, P2, rho, mu, k,
C = CONE_METER_C
elif meter_type == WEDGE_METER:
beta = diameter_ratio_wedge_meter(D=D, H=D2)
epsilon = nozzle_expansibility(D=D, Do=D2, P1=P1, P2=P1, k=k, beta=beta)
epsilon = nozzle_expansibility(D=D, Do=D2, P1=P1, P2=P2, k=k, beta=beta)
C = C_wedge_meter_ISO_5167_6_2017(D=D, H=D2)
elif meter_type == HOLLINGSHEAD_ORIFICE:
v = m/((0.25*pi*D*D)*rho)
Expand Down Expand Up @@ -2604,7 +2604,7 @@ def differential_pressure_meter_C_epsilon(D, D2, m, P1, P2, rho, mu, k,
Re_D = rho*v*D/mu
beta = diameter_ratio_wedge_meter(D=D, H=D2)
C = float(bisplev(beta, log(Re_D), wedge_Hollingshead_tck))
epsilon = nozzle_expansibility(D=D, Do=D2, P1=P1, P2=P1, k=k, beta=beta)
epsilon = nozzle_expansibility(D=D, Do=D2, P1=P1, P2=P2, k=k, beta=beta)
elif meter_type == UNSPECIFIED_METER:
epsilon = orifice_expansibility(D, D2, P1, P2, k) # Default to orifice type expansibility
if C_specified is None:
Expand Down Expand Up @@ -2694,7 +2694,7 @@ def differential_pressure_meter_solver(D, rho, mu, k=None, D2=None, P1=None, P2=
'ISO 5167 orifice', 'Miller quarter circle orifice', 'Hollingshead venturi sharp',
'segmental orifice', 'Miller conical orifice', 'Miller segmental orifice',
'quarter circle orifice', 'Hollingshead v cone', 'wedge meter', 'eccentric orifice',
'venuri nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'venturi nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'ISO 15377 quarter-circle orifice', 'Hollingshead venturi smooth',
'Hollingshead orifice', 'cone meter', 'Hollingshead wedge', 'Miller orifice',
'long radius nozzle', 'ISO 15377 conical orifice', 'unspecified meter',
Expand Down Expand Up @@ -2841,7 +2841,7 @@ def differential_pressure_meter_dP(D, D2, P1, P2, C=None,
'ISO 5167 orifice', 'Miller quarter circle orifice', 'Hollingshead venturi sharp',
'segmental orifice', 'Miller conical orifice', 'Miller segmental orifice',
'quarter circle orifice', 'Hollingshead v cone', 'wedge meter', 'eccentric orifice',
'venuri nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'venturi nozzle', 'rough welded convergent venturi tube', 'ISA 1932 nozzle',
'ISO 15377 quarter-circle orifice', 'Hollingshead venturi smooth',
'Hollingshead orifice', 'cone meter', 'Hollingshead wedge', 'Miller orifice',
'long radius nozzle', 'ISO 15377 conical orifice', 'unspecified meter',
Expand Down
32 changes: 9 additions & 23 deletions fluids/numerics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4791,45 +4791,31 @@ def py_splev(x, tck, ext=0, t=None, c=None, k=None):
return sp


def py_bisplev(x, y, tck, dx=0, dy=0):
"""Evaluate a bivariate B-spline or its derivatives. For scalars, returns a
float; for other inputs, mimics the formats of SciPy's `bisplev`.
def py_bisplev(x, y, tck):
"""Evaluate a bivariate B-spline.
Parameters
----------
x : float or list[float]
x value (rank 1), [-]
y : float or list[float]
y value (rank 1), [-]
x : float
x value, [-]
y : float
y value, [-]
tck : tuple(list, list, list, int, int)
Tuple of knot locations, coefficients, and the degree of the spline,
[tx, ty, c, kx, ky], [-]
dx : int, optional
Order of partial derivative with respect to `x`, [-]
dy : int, optional
Order of partial derivative with respect to `y`, [-]
Returns
-------
values : float or list[list[float]]
Calculated values from spline or their derivatives; according to the
same format as SciPy's `bisplev`, [-]
value : float
Calculated values from spline, [-]
Notes
-----
Use `bisplrep` to generate the `tck` representation; there is no Python
port of it.
"""
tx, ty, c, kx, ky = tck
if isinstance(x, (float, int)):
x = [x]
if isinstance(y, (float, int)):
y = [y]

z = [[bispev_inner(tx, ty, c, kx, ky, xi, yi) for yi in y] for xi in x]
if len(x) == len(y) == 1:
return z[0][0]
return z
return bispev_inner(tx, ty, c, kx, ky, x, y)


def fpbspl(t, n, k, x, l, h, hh):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_flow_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_differential_pressure_meter_discharge():

# wedge meter
m = differential_pressure_meter_solver(D=0.07366, D2=0.05, P1=200000.0, P2=183000.0, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
assert_close(m, 18.010019841564873)
assert_close(m, 16.064473363867993)

with pytest.raises(ValueError):
differential_pressure_meter_solver(D=.07366, m=7.702338, P2=183000.0, rho=999.1, mu=0.0011, k=1.33, meter_type='ISO 5167 orifice', taps='D')
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_differential_pressure_meter_diameter():
assert_close(D2, 0.05)

# wedge meter
D2 = differential_pressure_meter_solver(D=0.07366, m=18.010019841564873, P1=200000.0, P2=183000.0, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
D2 = differential_pressure_meter_solver(D=0.07366, m=16.064473363867993, P1=200000.0, P2=183000.0, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
assert_close(D2, 0.05)


Expand Down Expand Up @@ -320,7 +320,7 @@ def test_differential_pressure_meter_P2():
assert_close(P2, 183000.0)

# Wedge meter
P2 = differential_pressure_meter_solver(D=0.07366, m=18.010019841564873, P1=200000.0, D2=0.05, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
P2 = differential_pressure_meter_solver(D=0.07366, m=16.064473363867993, P1=200000.0, D2=0.05, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
assert_close(P2, 183000.0)

def test_differential_pressure_meter_P1():
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_differential_pressure_meter_P1():
assert_close(P1, 200000)

# Wedge meter
P1 = differential_pressure_meter_solver(D=0.07366, m=18.010019841564873, P2=183000.0, D2=0.05, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
P1 = differential_pressure_meter_solver(D=0.07366, m=16.064473363867993, P2=183000.0, D2=0.05, rho=999.1, mu=0.0011, k=1.33, meter_type=WEDGE_METER)
assert_close(P1, 200000)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_numerics.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_bisplev():
zs = np.linspace(0, 1, 10)

ys_scipy = bisplev(xs, zs, tck)
ys = my_bisplev(xs, zs, my_tck)
ys = [[my_bisplev(xi, zi, my_tck) for zi in zs] for xi in xs]
assert_allclose(ys, ys_scipy)

ys_scipy = bisplev(0.5, .7, tck)
Expand Down

0 comments on commit 426a360

Please sign in to comment.