Exemplo n.º 1
0
def enthalpyvap(temp=None,
                pres=None,
                dvap=None,
                dliq=None,
                chkvals=False,
                chktol=_CHKTOL,
                temp0=None,
                dvap0=None,
                dliq0=None,
                chkbnd=False,
                mathargs=None):
    """Calculate water vapour enthalpy.
    
    Calculate the enthalpy of water vapour for liquid water and water
    vapour in equilibrium.
    
    :arg temp: Temperature in K.
    :type temp: float or None
    :arg pres: Pressure in Pa.
    :type pres: float or None
    :arg dvap: Water vapour density in kg/m3. If unknown, pass None
        (default) and it will be calculated.
    :type dvap: float or None
    :arg dliq: Liquid water density in kg/m3. If unknown, pass None
        (default) and it will be calculated.
    :type dliq: float or None
    :arg bool chkvals: If True (default False) and all values are given,
        this function will calculate the disequilibrium and raise a
        warning if the results are not within a given tolerance.
    :arg float chktol: Tolerance to use when checking values (default
        _CHKTOL).
    :arg temp0: Initial guess for the temperature in K. If None (default)
        then `_approx_p` is used.
    :type temp0: float or None
    :arg dvap0: Initial guess for the water vapour density in kg/m3. If
        None (default) then `_approx_t` is used.
    :type dvap0: float or None
    :arg dliq0: Initial guess for the liquid water density in kg/m3. If
        None (default) then `_approx_t` is used.
    :type dliq0: float or None
    :arg bool chkbnd: If True then warnings are raised when the given
        values are valid but outside the recommended bounds (default
        False).
    :arg mathargs: Keyword arguments to the root-finder
        :func:`_newton <maths3.newton>` (e.g. maxiter, rtol). If None
        (default) then no arguments are passed and default parameters
        will be used.
    :returns: Enthalpy in J/kg.
    :raises ValueError: If neither of temp or pres is provided.
    :raises ValueError: If the temperature is above the critical point.
    :raises RuntimeWarning: If the relative disequilibrium is more than
        chktol, if chkvals is True and all values are given.
    
    :Examples:
    
    >>> enthalpyvap(temp=300.)
    2549854.10109
    >>> enthalpyvap(pres=1e4)
    2583858.67179
    """
    temp, pres, dvap, dliq = eq_tp(temp=temp,
                                   pres=pres,
                                   dvap=dvap,
                                   dliq=dliq,
                                   chkvals=chkvals,
                                   chktol=chktol,
                                   temp0=temp0,
                                   dvap0=dvap0,
                                   dliq0=dliq0,
                                   chkbnd=chkbnd,
                                   mathargs=mathargs)
    hv = flu2.enthalpy(temp, dvap)
    return hv
Exemplo n.º 2
0
def enthalpyevap(salt=None,airf=None,temp=None,pres=None,dhum=None,
    dliq=None,chkvals=False,chktol=_CHKTOL,salt0=None,airf0=None,
    temp0=None,pres0=None,dhum0=None,dliq0=None,chkbnd=False,
    useext=False,mathargs=None):
    """Calculate sea-air enthalpy of evaporation.
    
    Calculate the specific enthalpy of evaporation for sea-air.
    
    :arg salt: Salinity in kg/kg. If unknown, pass None (default) and it
        will be calculated.
    :type salt: float or None
    :arg airf: Humid air dry fraction in kg/kg. If unknown, pass None
        (default) and it will be calculated.
    :type airf: float or None
    :arg temp: Temperature in K. If unknown, pass None (default) and it
        will be calculated.
    :type temp: float or None
    :arg pres: Pressure in Pa. If unknown, pass None (default) and it
        will be calculated.
    :type pres: float or None
    :arg dliq: Seawater liquid water density in kg/m3. If unknown, pass
        None (default) and it will be calculated.
    :type dliq: float or None
    :arg dhum: Humid air density in kg/m3. If unknown, pass None
        (default) and it will be calculated.
    :type dhum: float or None
    :arg bool chkvals: If True (default False) and all values are given,
        this function will calculate the disequilibrium and raise a
        warning if the results are not within a given tolerance.
    :arg float chktol: Tolerance to use when checking values (default
        _CHKTOL).
    :arg salt0: Initial guess for the salinity in kg/kg. If None
        (default) then the appropriate `_approx_*` is used.
    :type salt0: float or None
    :arg airf0: Initial guess for the humid air dry fraction in kg/kg.
        If None (default) then the appropriate `_approx_*` is used.
    :type airf0: float or None
    :arg temp0: Initial guess for the temperature in K. If None
        (default) then the appropriate `_approx_*` is used.
    :type temp0: float or None
    :arg pres0: Initial guess for the pressure in Pa. If None (default)
        then the appropriate `_approx_*` is used.
    :type pres0: float or None
    :arg dliq0: Initial guess for the liquid water density in kg/m3. If
        None (default) then `flu3a._dliq_default` is used.
    :type dliq0: float or None
    :arg dhum0: Initial guess for the liquid water density in kg/m3. If
        None (default) then the appropriate `_approx_*` is used.
    :type dhum0: float or None
    :arg bool chkbnd: If True then warnings are raised when the given
        values are valid but outside the recommended bounds (default
        False).
    :arg bool useext: If False (default) then the salt contribution is
        calculated from _GSCOEFFS; if True, from _GSCOEFFS_EXT.
    :arg mathargs: Keyword arguments to the root-finder
        :func:`_newton <maths3.newton>` (e.g. maxiter, rtol). If None
        (default) then no arguments are passed and default parameters
        will be used.
    :returns: Enthalpy in J/kg.
    :raises ValueError: If fewer than three of salt, airf, temp, and
        pres are provided.
    :raises RuntimeWarning: If the relative disequilibrium is more than
        chktol, if chkvals is True and all values are given.
    
    :Examples:
    
    >>> enthalpyevap(salt=0.035,airf=0.99,pres=1e5)
    2464765.77588
    >>> enthalpyevap(salt=0.035,temp=300.,pres=1e5)
    2434570.55229
    """
    salt, airf, temp, pres, dhum, dliq = eq_satp(salt=salt,airf=airf,temp=temp,
        pres=pres,dhum=dhum,dliq=dliq,chkvals=chkvals,chktol=chktol,salt0=salt0,
        airf0=airf0,temp0=temp0,pres0=pres0,dhum0=dhum0,dliq0=dliq0,
        chkbnd=chkbnd,useext=useext,mathargs=mathargs)
    
    # Calculate water vapour enthalpy
    fh = _air_f(0,0,0,airf,temp,dhum)
    fh_a = _air_f(1,0,0,airf,temp,dhum)
    fh_t = _air_f(0,1,0,airf,temp,dhum)
    fh_d = _air_f(0,0,1,airf,temp,dhum)
    fh_at = _air_f(1,1,0,airf,temp,dhum)
    fh_ad = _air_f(1,0,1,airf,temp,dhum)
    fh_td = _air_f(0,1,1,airf,temp,dhum)
    fh_dd = _air_f(0,0,2,airf,temp,dhum)
    ch = 2*fh_d + dhum*fh_dd
    hh = fh - temp*fh_t + dhum*fh_d
    hh_a = fh_a - temp*fh_at + temp*dhum/ch*fh_ad*fh_td
    hv = hh - airf*hh_a
    hl = flu2.enthalpy(temp,dliq)
    
    # Treat pure water case separately to avoid numerical errors
    if salt == 0:
        hevap = hv - hl
        return hevap
    
    gs = _sal_g(0,0,0,salt,temp,pres,useext=useext)
    gs_s = _sal_g(1,0,0,salt,temp,pres,useext=useext)
    gs_t = _sal_g(0,1,0,salt,temp,pres,useext=useext)
    gs_st = _sal_g(1,1,0,salt,temp,pres,useext=useext)
    hls = gs - temp*gs_t - salt*(gs_s - temp*gs_st)
    hevap = hv - hl - hls
    return hevap
Exemplo n.º 3
0
def enthalpysubl(temp=None,
                 pres=None,
                 dvap=None,
                 chkvals=False,
                 chktol=_CHKTOL,
                 temp0=None,
                 pres0=None,
                 dvap0=None,
                 chkbnd=False,
                 mathargs=None):
    """Calculate enthalpy of sublimation.
    
    Calculate the specific enthalpy of sublimation.
    
    :arg temp: Temperature in K.
    :type temp: float or None
    :arg pres: Pressure in Pa.
    :type pres: float or None
    :arg dvap: Water vapour density in kg/m3. If unknown, pass None
        (default) and it will be calculated.
    :type dvap: float or None
    :arg bool chkvals: If True (default False) and all values are given,
        this function will calculate the disequilibrium and raise a
        warning if the results are not within a given tolerance.
    :arg float chktol: Tolerance to use when checking values (default
        _CHKTOL).
    :arg temp0: Initial guess for the temperature in K. If None
        (default) then `_approx_p` is used.
    :type temp0: float or None
    :arg pres0: Initial guess for the pressure in Pa. If None (default)
        then `_approx_t` is used.
    :type pres0: float or None
    :arg dvap0: Initial guess for the water vapour density in kg/m3. If
        None (default) then `_approx_t` or `_approx_p` is used.
    :type dvap0: float or None
    :arg bool chkbnd: If True then warnings are raised when the given
        values are valid but outside the recommended bounds (default
        False).
    :arg mathargs: Keyword arguments to the root-finder
        :func:`_newton <maths3.newton>` (e.g. maxiter, rtol). If None
        (default) then no arguments are passed and default parameters
        will be used.
    :returns: Enthalpy in J/kg.
    :raises ValueError: If neither of temp or pres is provided.
    :raises RuntimeWarning: If the relative disequilibrium is more than
        chktol, if chkvals is True and all values are given.
    
    :Examples:
    
    >>> enthalpysubl(temp=270.)
    2835165.65442
    >>> enthalpysubl(pres=100.)
    2838101.44416
    """
    temp, pres, dvap = eq_tp(temp=temp,
                             pres=pres,
                             dvap=dvap,
                             chkvals=chkvals,
                             chktol=chktol,
                             temp0=temp0,
                             pres0=pres0,
                             dvap0=dvap0,
                             chkbnd=chkbnd,
                             mathargs=mathargs)
    hv = flu2.enthalpy(temp, dvap)
    hi = ice2.enthalpy(temp, pres)
    hsubl = hv - hi
    return hsubl