Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_linspace():
from fluids.numerics import linspace
calc = linspace(-3,10, endpoint=True, num=8)
expect = np.linspace(-3,10, endpoint=True, num=8)
assert_allclose(calc, expect)
calc = linspace(-3,10, endpoint=False, num=20)
expect = np.linspace(-3,10, endpoint=False, num=20)
assert_allclose(calc, expect)
calc = linspace(0,1e-10, endpoint=False, num=3)
expect = np.linspace(0,1e-10, endpoint=False, num=3)
assert_allclose(calc, expect)
calc = linspace(0,1e-10, endpoint=False, num=2)
expect = np.linspace(0,1e-10, endpoint=False, num=2)
assert_allclose(calc, expect)
calc = linspace(0,1e-10, endpoint=False, num=1)
expect = np.linspace(0,1e-10, endpoint=False, num=1)
assert_allclose(calc, expect)
calc, calc_step = linspace(0,1e-10, endpoint=False, num=2, retstep=True)
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_plate_enhancement_factor_fuzz():
# Confirm it's correct to within 1E-7
for x in linspace(1E-5, 100, 3):
for y in linspace(1E-5, 100, 3):
a = plate_enlargement_factor(x, y)
b = plate_enlargement_factor_numerical(x, y)
assert_close(a, b, rtol=1E-7)
def test_geometry_tank_fuzz_h_from_V():
T = TANK(L=1.2, L_over_D=3.5, sideA='torispherical', sideB='torispherical', sideA_f=1., horizontal=True, sideA_k=0.06, sideB_f=1., sideB_k=0.06)
T.set_chebyshev_approximators(deg_forward=100, deg_backwards=600)
# test V_from_h - pretty easy to get right
for h in linspace(0, T.h_max, 30):
# It's the top and the bottom of the tank that works poorly
V1 = T.V_from_h(h, 'full')
V2 = T.V_from_h(h, 'chebyshev')
assert_close(V1, V2, rtol=1E-7, atol=1E-7)
with pytest.raises(Exception):
T.V_from_h(1E-5, 'NOTAMETHOD')
# reverse - the spline is also pretty easy, with a limited number of points
# when the required precision is low
T.set_table(n=150)
for V in linspace(0, T.V_total, 30):
h1 = T.h_from_V(V, 'brenth')
h2 = T.h_from_V(V, 'spline')
assert_close(h1, h2, rtol=1E-5, atol=1E-6)
assert_allclose(calc, expect)
calc = linspace(0,1e-10, endpoint=False, num=2)
expect = np.linspace(0,1e-10, endpoint=False, num=2)
assert_allclose(calc, expect)
calc = linspace(0,1e-10, endpoint=False, num=1)
expect = np.linspace(0,1e-10, endpoint=False, num=1)
assert_allclose(calc, expect)
calc, calc_step = linspace(0,1e-10, endpoint=False, num=2, retstep=True)
expect, expect_step = np.linspace(0,1e-10, endpoint=False, num=2, retstep=True)
assert_allclose(calc, expect)
assert_allclose(calc_step, expect_step)
calc, calc_step = linspace(0,1e-10, endpoint=False, num=1, retstep=True)
expect, expect_step = np.linspace(0,1e-10, endpoint=False, num=1, retstep=True)
assert_allclose(calc, expect)
assert isnan(calc_step)
# Cannot compare against numpy expect_step - it did not use to give nan in older versions
calc, calc_step = linspace(100, 1000, endpoint=False, num=21, retstep=True)
expect, expect_step = np.linspace(100, 1000, endpoint=False, num=21, retstep=True)
assert_allclose(calc, expect)
assert_allclose(calc_step, expect_step)
References
----------
.. [1] ASTM E11 - 17 - Standard Specification for Woven Wire Test Sieve
Cloth and Test Sieves.
.. [2] ISO 3310-1:2016 - Test Sieves -- Technical Requirements and Testing
-- Part 1: Test Sieves of Metal Wire Cloth.
'''
if d_min is not None:
d_min = float(d_min)
if d_max is not None:
d_max = float(d_max)
if method == 'logarithmic':
return logspace(log10(d_min), log10(d_max), pts)
elif method == 'linear':
return linspace(d_min, d_max, pts)
elif method[0] in ('R', 'r'):
ratio = 10**(1.0/float(method[1:]))
if d_min is not None and d_max is not None:
raise ValueError('For geometric (Renard) series, only '
'one of `d_min` and `d_max` should be provided')
if d_min is not None:
ds = [d_min]
for i in range(pts-1):
ds.append(ds[-1]*ratio)
return ds
elif d_max is not None:
ds = [d_max]
for i in range(pts-1):
ds.append(ds[-1]/ratio)
return list(reversed(ds))
elif method in sieve_spacing_options:
volumes in the tank, for a fully defined tank. Normally run by the
h_from_V method, this may be run prior to its use with a custom
specification. Either the number of points on the table, or the
vertical distance between steps may be specified.
Parameters
----------
n : float, optional
Number of points in the interpolation table, [-]
dx : float, optional
Vertical distance between steps in the interpolation table, [m]
'''
if dx:
self.heights = linspace(0.0, self.h_max, int(self.h_max/dx)+1)
else:
self.heights = linspace(0.0, self.h_max, n)
self.volumes = [self.V_from_h(h) for h in self.heights]
from scipy.interpolate import UnivariateSpline
self.interp_h_from_V = UnivariateSpline(self.volumes, self.heights, ext=3, s=0.0)
self.table = True