How to use the fluids.numerics.brenth function in fluids

To help you get started, weâ€™ve selected a few fluids examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

CalebBell / fluids / fluids / jet_pump.py View on Github
``````return ((-2*A_nozzle**2*P1 + 2*A_nozzle**2*P2 + Kp*Qp**2*rhop + Qp**2*rhop)/(C*rhop*(Ks + 1)))**0.5*(A_mixing - A_nozzle)/A_nozzle
except ValueError:
return -1j
elif Qp is None:
return A_nozzle*((2*A_mixing**2*P1 - 2*A_mixing**2*P2 - 4*A_mixing*A_nozzle*P1 + 4*A_mixing*A_nozzle*P2 + 2*A_nozzle**2*P1 - 2*A_nozzle**2*P2 + C*Ks*Qs**2*rhop + C*Qs**2*rhop)/(rhop*(Kp + 1)))**0.5/(A_mixing - A_nozzle)
elif d_nozzle is None:
def err(d_nozzle):
return P1 - liquid_jet_pump_ancillary(rhop=rhop, rhos=rhos, Kp=Kp, Ks=Ks, d_nozzle=d_nozzle, d_mixing=d_mixing, Qp=Qp, Qs=Qs,
P1=None, P2=P2)
return brenth(err, 1E-9, d_mixing*20)
elif d_mixing is None:
def err(d_mixing):
return P1 - liquid_jet_pump_ancillary(rhop=rhop, rhos=rhos, Kp=Kp, Ks=Ks, d_nozzle=d_nozzle, d_mixing=d_mixing, Qp=Qp, Qs=Qs,
P1=None, P2=P2)
try:
return brenth(err, 1E-9, d_nozzle*20)
except:
return secant(err, d_nozzle*2)``````
CalebBell / fluids / fluids / particle_size_distribution.py View on Github
``````# dist.cdf(dist.dn(0)-1e-35) == 0
# dist.cdf(dist.dn(0)-1e-36) == input
# dn(0) == 1.9663615597466143e-20
#            def err(d):
#                cdf = self.cdf(d, n=n)
#                if cdf == 0:
#                    cdf = -1
#                return cdf
#            return brenth(err, self.d_minimum, self.d_excessive, maxiter=1000, xtol=1E-200)

elif fraction > 1:
raise ValueError('Fraction less than 1')
# As the dn may be incredibly small, it is required for the absolute
# tolerance to not be happy - it needs to continue iterating as long
# as necessary to pin down the answer
return brenth(lambda d:self.cdf(d, n=n) -fraction,
self.d_minimum, self.d_excessive, maxiter=1000, xtol=1E-200)``````
CalebBell / fluids / fluids / flow_meter.py View on Github
``````if rho &lt; 100.0:
m_D_guess *= 1e-2
return secant(err_dp_meter_solver_m, m_D_guess, args=(D, D2, P1, P2, rho, mu, k, meter_type, taps, tap_position, C_specified))*D
elif D2 is None and D is not None and m is not None and P1 is not None and P2 is not None:
args = (D, m, P1, P2, rho, mu, k, meter_type, taps, tap_position, C_specified)
try:
return brenth(err_dp_meter_solver_D2, D*(1-1E-9), D*5E-3, args=args)
except:
try:
return secant(err_dp_meter_solver_D2, D*.3, args=args, high=D, low=D*1e-10)
except:
return secant(err_dp_meter_solver_D2, D*.75, args=args, high=D, low=D*1e-10)
elif P2 is None and D is not None and D2 is not None and m is not None and P1 is not None:
args = (D, D2, m, P1, rho, mu, k, meter_type, taps, tap_position, C_specified)
try:
return brenth(err_dp_meter_solver_P2, P1*(1-1E-9), P1*0.5, args=args)
except:
return secant(err_dp_meter_solver_P2, P1*0.5, low=P1*1e-10, args=args, high=P1, bisection=True)
elif P1 is None and D is not None and D2 is not None and m is not None and P2 is not None:
args = (D, D2, m, P2, rho, mu, k, meter_type, taps, tap_position, C_specified)
try:
return brenth(err_dp_meter_solver_P1, P2*(1+1E-9), P2*1.4, args=args)
except:
return secant(err_dp_meter_solver_P1, P2*1.5, args=args, low=P2, bisection=True)
else:
raise ValueError('Solver is capable of solving for one of P1, P2, D2, or m only.')``````
CalebBell / fluids / fluids / geometry.py View on Github
``````Returns
-------
h : float
Height of liquid at which the volume is as desired, [m]
'''
if method == 'spline':
if not self.table:
self.set_table()
return float(self.interp_h_from_V(V))
elif method == 'chebyshev':
if not self.chebyshev:
self.set_chebyshev_approximators()
return self.h_from_V_cheb(V)
elif method == 'brenth':
to_solve = lambda h : self.V_from_h(h, method='full') - V
return brenth(to_solve, self.h_max, 0)
else:
raise Exception("Allowable methods are 'full' or 'chebyshev', "
"or 'brenth'.")``````

fluids

Fluid dynamics component of Chemical Engineering Design Library (ChEDL)

MIT