Exemple #1
0
def enthalpy_second_derivatives(SA, CT, p):
    r"""Calculates the following three second-order derivatives of specific
    enthalpy (h),
    (1) h_SA_SA, second-order derivative with respect to Absolute Salinity
        at constant CT & p.
    (2) h_SA_CT, second-order derivative with respect to SA & CT at
        constant p.
    (3) h_CT_CT, second-order derivative with respect to CT at constant SA
        and p.

    Parameters
    ----------
    SA : array_like
         Absolute salinity [g kg :sup:`-1`]
    CT : array_like
         Conservative Temperature [:math:`^\circ` C (TEOS-10)]
    p : array_like
        pressure [dbar]

    Returns
    -------
    h_SA_SA : array_like
              The second derivative of specific enthalpy with respect to
              Absolute Salinity at constant CT & p. [J/(kg (g/kg)^2)]
    h_SA_CT : array_like
              The second derivative of specific enthalpy with respect to SA and
              CT at constant p. [J/(kg K(g/kg))]
    h_CT_CT : array_like
              The second derivative of specific enthalpy with respect to CT at
              constant SA and p. [J/(kg K^2)]

    References
    ----------
    .. [1] IOC, SCOR and IAPSO, 2010: The international thermodynamic equation
    of seawater -  2010: Calculation and use of thermodynamic properties.
    Intergovernmental Oceanographic Commission, Manuals and Guides No. 56,
    UNESCO (English), 196 pp. See Eqns. (A.11.18), (A.11.15) and (A.11.12.)

    .. [2] McDougall T.J., P.M. Barker, R. Feistel and D.R. Jackett, 2011:  A
    computationally efficient 48-term expression for the density of seawater in
    terms of Conservative Temperature, and related properties of seawater.  To
    be submitted to Ocean Science Discussions.

    Modifications:
    2011-03-29. Trevor McDougall.
    """

    # NOTE: The Matlab version 3.0 mentions that this function is unchanged,
    # but that's not true!

    pt0 = pt_from_CT(SA, CT)
    abs_pt0 = Kelvin + pt0
    t = pt_from_t(SA, pt0, 0, p)
    temp_ratio = (Kelvin + t) / abs_pt0

    rec_gTT_pt0 = 1 / gibbs(n0, n2, n0, SA, pt0, 0)
    rec_gTT_t = 1 / gibbs(n0, n2, n0, SA, t, p)
    gST_pt0 = gibbs(n1, n1, n0, SA, pt0, 0)
    gST_t = gibbs(n1, n1, n0, SA, t, p)
    gS_pt0 = gibbs(n1, n0, n0, SA, pt0, 0)

    part = ((temp_ratio * gST_pt0 * rec_gTT_pt0 - gST_t * rec_gTT_t) /
            (abs_pt0))

    factor = gS_pt0 / cp0

    # h_CT_CT is naturally well-behaved as SA approaches zero.
    def enthalpy_derivative_CT_CT(SA, CT, p):
        return (cp0 ** 2 * ((temp_ratio * rec_gTT_pt0 - rec_gTT_t) /
                                                         (abs_pt0 * abs_pt0)))

    # h_SA_SA has a singularity at SA = 0, and blows up as SA approaches zero.
    def enthalpy_derivative_SA_SA(SA, CT, p):
        SA[SA < 1e-100] = 1e-100  # NOTE: Here is the changes from 2.0 to 3.0.
        h_CT_CT = enthalpy_derivative_CT_CT(SA, CT, p)
        return (gibbs(n2, n0, n0, SA, t, p) -
                temp_ratio * gibbs(n2, n0, n0, SA, pt0, 0) +
                temp_ratio * gST_pt0 ** 2 * rec_gTT_pt0 -
                gST_t ** 2 * rec_gTT_t - 2.0 * gS_pt0 * part +
                factor ** 2 * h_CT_CT)

    """h_SA_CT should not blow up as SA approaches zero. The following lines of
    code ensure that the h_SA_CT output of this function does not blow up in
    this limit.  That is, when SA < 1e-100 g/kg, we force the h_SA_CT output to
    be the same as if SA = 1e-100 g/kg."""

    def enthalpy_derivative_SA_CT(SA, CT, p):
        h_CT_CT = enthalpy_derivative_CT_CT(SA, CT, p)
        return cp0 * part - factor * h_CT_CT

    return (enthalpy_derivative_SA_SA(SA, CT, p),
            enthalpy_derivative_SA_CT(SA, CT, p),
            enthalpy_derivative_CT_CT(SA, CT, p))
Exemple #2
0
def enthalpy_first_derivatives(SA, CT, p):
    r"""Calculates the following three derivatives of specific enthalpy (h)
    (1) h_SA, the derivative with respect to Absolute Salinity at
        constant CT and p, and
    (2) h_CT, derivative with respect to CT at constant SA and p.
    (3) h_P, derivative with respect to pressure (in Pa) at constant SA and CT.

    Parameters
    ----------
    SA : array_like
         Absolute salinity [g kg :sup:`-1`]
    CT : array_like
         Conservative Temperature [:math:`^\circ` C (TEOS-10)]
    p : array_like
        pressure [dbar]

    Returns
    -------
    h_SA : array_like
           The first derivative of specific enthalpy with respect to Absolute
           Salinity at constant CT and p. [J/(kg (g/kg))]  i.e. [J/g]
    h_CT : array_like
           The first derivative of specific enthalpy with respect to CT at
           constant SA and p. [J/(kg K)]
    h_P : array_like
          The first partial derivative of specific enthalpy with respect to
          pressure (in Pa) at fixed SA and CT.  Note that h_P is specific
          volume (1/rho.)

    See Also
    --------
    TODO

    Notes
    -----
    TODO


    References
    ----------
    .. [1] IOC, SCOR and IAPSO, 2010: The international thermodynamic equation
    of seawater -  2010: Calculation and use of thermodynamic properties.
    Intergovernmental Oceanographic Commission, Manuals and Guides No. 56,
    UNESCO (English), 196 pp. See Eqns. (A.11.18), (A.11.15) and (A.11.12.)

    Modifications:
    2010-09-24. Trevor McDougall.
    """

    # FIXME: The gsw 3.0 has the gibbs derivatives "copy-and-pasted" here
    # instead of the calls to the library! Why?

    pt0 = pt_from_CT(SA, CT)
    t = pt_from_t(SA, pt0, 0, p)
    temp_ratio = (Kelvin + t) / (Kelvin + pt0)

    def enthalpy_derivative_SA(SA, CT, p):
        return (gibbs(n1, n0, n0, SA, t, p) -
                temp_ratio * gibbs(n1, n0, n0, SA, pt0, 0))

    def enthalpy_derivative_CT(SA, CT, p):
        return cp0 * temp_ratio

    def enthalpy_derivative_p(SA, CT, p):
        return gibbs(n0, n0, n1, SA, t, p)

    return (enthalpy_derivative_SA(SA, CT, p),
            enthalpy_derivative_CT(SA, CT, p),
            enthalpy_derivative_p(SA, CT, p),)