How to use the fluids.numerics.secant 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.

github CalebBell / fluids / tests / test_flow_meter.py View on Github external
    solve_Dc = lambda beta : float(secant(err, .7, args=(beta,)))
github CalebBell / fluids / fluids / drag.py View on Github external
Cd = Barati_high(Re)
        V2 = (4/3.*g*D*(rhop-rho)/rho/Cd)**0.5
        return (V-V2)
    return fsolve(err, 1.)'''
    v_lam = g*D*D*(rhop-rho)/(18*mu)
    Re_lam = Reynolds(V=v_lam, D=D, rho=rho, mu=mu)
    if Re_lam < 0.01 or Method == 'Stokes':
        return v_lam

    Re_almost = rho*D/mu
    main = 4/3.*g*D*(rhop-rho)/rho
    V_max = 1E6/rho/D*mu  # where the correlation breaks down, Re=1E6

    # Begin the solver with 1/100 th the velocity possible at the maximum
    # Reynolds number the correlation is good for
    return secant(_v_terminal_err, V_max/100, xtol=1E-12, args=(Method, Re_almost, main))
github CalebBell / fluids / fluids / compressible.py View on Github external
except:
            Pcf = P_isothermal_critical_flow(P=P1, fd=fd, D=D, L=L)
            try:
                return ridder(isothermal_gas_err_P2, a=Pcf, b=P1, args=(rho, fd, P1, L, D, m))
            except:
                m_max = isothermal_gas(rho, fd, P1=P1, P2=Pcf, L=L, D=D)
                raise ValueError('The desired mass flow rate cannot be achieved ' # numba: delete
                                 'with the specified upstream pressure of %f Pa; the maximum flowrate is %f ' # numba: delete
                                 'kg/s at a downstream pressure of %f' %(P1, m_max, Pcf)) # numba: delete
#                raise ValueError("Failed") # numba: uncomment
            # A solver which respects its boundaries is required here.
            # ridder cuts the time down from 2 ms to 200 mircoseconds.
            # Is is believed Pcf and P1 will always bracked the root, however
            # leave the commented code for testing
    elif D is None and P2 is not None and P1 is not None and L is not None and m is not None:
        return secant(isothermal_gas_err_D, 0.1, args=(m, rho, fd, P1, P2, L))
    else:
        raise ValueError('This function solves for either mass flow, upstream \
pressure, downstream pressure, diameter, or length; all other inputs \
github CalebBell / fluids / fluids / jet_pump.py View on Github external
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)
github CalebBell / ht / ht / boiling_flow.py View on Github external
----------
    .. [1] Thome, J. R., V. Dupont, and A. M. Jacobi. "Heat Transfer Model for 
       Evaporation in Microchannels. Part I: Presentation of the Model." 
       International Journal of Heat and Mass Transfer 47, no. 14-16 (July 
       2004): 3375-85. doi:10.1016/j.ijheatmasstransfer.2004.01.006.
    .. [2] Dupont, V., J. R. Thome, and A. M. Jacobi. "Heat Transfer Model for 
       Evaporation in Microchannels. Part II: Comparison with the Database." 
       International Journal of Heat and Mass Transfer 47, no. 14-16 (July 
       2004): 3387-3401. doi:10.1016/j.ijheatmasstransfer.2004.01.007.
    .. [3] Bertsch, Stefan S., Eckhard A. Groll, and Suresh V. Garimella. 
       "Review and Comparative Analysis of Studies on Saturated Flow Boiling in
       Small Channels." Nanoscale and Microscale Thermophysical Engineering 12,
       no. 3 (September 4, 2008): 187-227. doi:10.1080/15567260802317357.
    '''
    if q is None and Te is not None:
        q = secant(to_solve_q_Thome, 1E4, args=( m, x, D, rhol, rhog, kl, kg, mul, mug, Cpl, Cpg, sigma, Hvap, Psat, Pc, Te))
        return Thome(m=m, x=x, D=D, rhol=rhol, rhog=rhog, kl=kl, kg=kg, mul=mul, mug=mug, Cpl=Cpl, Cpg=Cpg, sigma=sigma, Hvap=Hvap, Psat=Psat, Pc=Pc, q=q)
    elif q is None and Te is None:
        raise ValueError('Either q or Te is needed for this correlation')
    C_delta0 = 0.3E-6
    G = m/(pi/4*D**2)
    Rel = G*D*(1-x)/mul
    Reg = G*D*x/mug
    qref = 3328*(Psat/Pc)**-0.5
    if q is None: q = 1e4 # Make numba happy, their bug, never gets ran
    fopt = (q/qref)**1.74
    tau = 1./fopt
    
    vp = G*(x/rhog + (1-x)/rhol)
    Bo = rhol*D/sigma*vp**2 # Not standard definition
    nul = mul/rhol
    delta0 = D*0.29*(3*(nul/vp/D)**0.5)**0.84*((0.07*Bo**0.41)**-8 + 0.1**-8)**(-1/8.)
github CalebBell / fluids / fluids / compressible.py View on Github external
raise ValueError('Given outlet pressure is not physically possible ' # numba: delete
'due to the formation of choked flow at P2=%f, specified outlet pressure was %f' % (Pcf, P2)) # numba: delete
#            raise ValueError("Not possible") # numba: uncomment
        if P2 > P1:
            raise ValueError('Specified outlet pressure is larger than the '
                             'inlet pressure; fluid will flow backwards.')
        return (0.0625*pi*pi*D**4*rho/(P1*(fd*L/D + 2.0*log(P1/P2)))*(P1*P1 - P2*P2))**0.5
    elif L is None and P1 is not None and P2 is not None and D is not None and m is not None:
        return D*(pi*pi*D**4*rho*(P1*P1 - P2*P2) - 32.0*P1*m*m*log(P1/P2))/(16.0*P1*fd*m*m)
    elif P1 is None and L is not None and P2 is not None and D is not None and m is not None:
        Pcf = P_upstream_isothermal_critical_flow(P=P2, fd=fd, D=D, L=L)

        try:
            # Use the explicit solution for P2 with different P1 guesses;
            # newton doesn't like solving for m.
            P1 = secant(isothermal_gas_err_P2_basis, (P2+Pcf)/2., args=(P2, rho, fd, m, L, D))
            if not (P2 <= P1):
                raise ValueError("Failed")
            return P1
        except:
            try:
                return ridder(isothermal_gas_err_P1, a=P2, b=Pcf, args=(fd, rho, P2, L, D, m))
            except:
                m_max = isothermal_gas(rho, fd, P1=Pcf, P2=P2, L=L, D=D)
                raise ValueError('The desired mass flow rate of %f kg/s cannot ' # numba: delete
                                 'be achieved with the specified downstream pressure; the maximum flowrate is ' # numba: delete
                                 '%f kg/s at an upstream pressure of %f Pa' %(m, m_max, Pcf)) # numba: delete
#                raise ValueError("Failed") # numba: uncomment
    elif P2 is None and L is not None and P1 is not None and D is not None and m is not None:
        try:
            Pcf = P_isothermal_critical_flow(P=P1, fd=fd, D=D, L=L)
            m_max = isothermal_gas(rho, fd, P1=P1, P2=Pcf, L=L, D=D)
github CalebBell / fluids / fluids / compressible.py View on Github external
----------
    .. [1] Coelho, Paulo M., and Carlos Pinho. "Considerations about Equations
       for Steady State Flow in Natural Gas Pipelines." Journal of the
       Brazilian Society of Mechanical Sciences and Engineering 29, no. 3
       (September 2007): 262-73. doi:10.1590/S1678-58782007000300005.
    .. [2] Menon, E. Shashi. Gas Pipeline Hydraulics. 1st edition. Boca Raton,
       FL: CRC Press, 2005.
    '''
    c3 = 1.181102362204724409448818897637795275591 # 0.03/inch or 150/127
    c4 = 0.09144
    c5 = 125.1060
    if Q is None and L is not None and D is not None and P1 is not None and P2 is not None:
        return (c5*E*Ts/Ps*D**2.5*((P1**2-P2**2)
                /(L*SG*Zavg*Tavg*(1 + c4/D + c3*D)))**0.5)
    elif D is None and L is not None and Q is not None and P1 is not None and P2 is not None:
        return secant(_to_solve_Spitzglass_high, 0.5, args=(Q, SG, Tavg, L, P1, P2, Ts, Ps, Zavg, E))
    elif P1 is None and L is not None and Q is not None and D is not None and P2 is not None:
        return ((D**6*E**2*P2**2*Ts**2*c5**2
                 + D**2*L*Ps**2*Q**2*SG*Tavg*Zavg*c3
                 + D*L*Ps**2*Q**2*SG*Tavg*Zavg
                 + L*Ps**2*Q**2*SG*Tavg*Zavg*c4)/(D**6*E**2*Ts**2*c5**2))**0.5
    elif P2 is None and L is not None and Q is not None and D is not None and P1 is not None:
        return ((D**6*E**2*P1**2*Ts**2*c5**2
                 - D**2*L*Ps**2*Q**2*SG*Tavg*Zavg*c3
                 - D*L*Ps**2*Q**2*SG*Tavg*Zavg
                 - L*Ps**2*Q**2*SG*Tavg*Zavg*c4)/(D**6*E**2*Ts**2*c5**2))**0.5
    elif L is None and P2 is not None and Q is not None and D is not None and P1 is not None:
        return (D**6*E**2*Ts**2*c5**2*(P1**2 - P2**2)
                /(Ps**2*Q**2*SG*Tavg*Zavg*(D**2*c3 + D + c4)))
    else:
        raise ValueError('This function solves for either flow, upstream \
pressure, downstream pressure, diameter, or length; all other inputs \
github CalebBell / fluids / fluids / packed_tower.py View on Github external
.. [2] Piche, Simon R., Faical Larachi, and Bernard P. A. Grandjean.
       "Improving the Prediction of Irrigated Pressure Drop in Packed
       Absorption Towers." The Canadian Journal of Chemical Engineering 79,
       no. 4 (August 1, 2001): 584-94. doi:10.1002/cjce.5450790417.
    '''
    dp = 6.0*(1.0 - voidage)/specific_area
    Re = Vg*rhog*dp/mug
    f0 = C1/Re + C2/Re**0.5 + C3
    dP_dry = 3/4.*f0*(1-voidage)/voidage**4.65*rhog*H/dp*Vg*Vg
    c = (-C1/Re - C2/(2*Re**0.5))/f0
    Frl = Vl**2*specific_area/(g*voidage**4.65)
    h0 = 0.555*Frl**(1/3.)
    
    c1 = 1.0/(H*rhol*g)
    c1 *= c1
    return secant(_Stichlmair_wet_err, dP_dry, args=(h0, c1, dP_dry, H, voidage, c))
github CalebBell / fluids / fluids / flow_meter.py View on Github external
... meter_type='ISO 5167 orifice', taps='D')
    0.04999999990831885
    '''
    if m is None and D is not None and D2 is not None and P1 is not None and P2 is not None:
        # Diameter to mass flow ratio
        m_D_guess = 40
        if rho < 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.')