# Path: ht/conv_free_enclosed.py
# def Nu_Nusselt_Rayleigh_Holling_Herwig(Pr, Gr, buoyancy=True):
#     r'''Calculates the Nusselt number for natural convection between two
#     theoretical flat horizontal plates. The height between the plates is infinite, and
#     one of the other dimensions of the plates is much larger than the other.
# 
#     This correlation is for the horizontal plate Rayleigh-Benard classic heat
#     transfer problem, not for real finite geometry plates.
# 
#     This model is a non-linear equation which is solved numerically.
#     The model can calculate `Nu` for `Ra` ranges between 350 and larger
#     numbers; [1]_ recommends :math:`10^{5} < Ra < 10^{15}`.
# 
#     .. math::
#         \text{Nu} = \frac{{Ra}^{1/3}}{[0.05\ln(\frac{0.078}{16}{Ra}^{1.323})
#         + 2D]^{4/3}}
# 
#     .. math::
#         D = -\frac{14.94}{{Ra}^{0.25}} + 3.43
# 
#     Parameters
#     ----------
#     Pr : float
#         Prandtl number with respect to fluid properties [-]
#     Gr : float
#         Grashof number with respect to fluid properties and plate - plate
#         temperature difference [-]
#     buoyancy : bool, optional
#         Whether or not the plate's free convection is buoyancy assisted (hot
#         plate) or not, [-]
# 
#     Returns
#     -------
#     Nu : float
#         Nusselt number with respect to height between the two plates, [-]
# 
#     Notes
#     -----
#     A range of calculated values are provided in [1]_; they all match the
#     results of this function. This model is recommended in [2]_.
# 
#     For :math:`Ra < 1708`, `Nu` = 1; for cases not assited by `buoyancy`,
#     `Nu` is also 1.
# 
#     No success has been found finding an analytical solution in the major CAS
#     packages, but the nonlinear function is in fact a function of one variable;
#     this means a pade or chebyshev expansion could be performed.
# 
# 
#     Examples
#     --------
#     >>> Nu_Nusselt_Rayleigh_Holling_Herwig(5.54, 3.21e8, buoyancy=True)
#     77.54656801896913
# 
#     References
#     ----------
#     .. [1] Hölling, M., and H. Herwig. "Asymptotic Analysis of Heat Transfer in
#        Turbulent Rayleigh–Bénard Convection." International Journal of Heat and
#        Mass Transfer 49, no. 5 (March 1, 2006): 1129-36.
#        https://doi.org/10.1016/j.ijheatmasstransfer.2005.09.002.
#     .. [2] Gesellschaft, V. D. I., ed. VDI Heat Atlas. 2nd ed. 2010 edition.
#        Berlin ; New York: Springer, 2010.
#     '''
#     if not buoyancy:
#         return 1.0
#     Rac = 1708 # Constant
# 
#     Ra = Gr*Pr
#     if Ra < Rac:
#         return 1.0
# 
#     Ra_third = Ra**(1.0/3.0)
#     D2 = 2.0*(-14.94*Ra**-0.25 + 3.43)
#     Nu_guess = Ra_third*(0.1/2.0*log(.078/16.0*Ra**1.323) + D2)**(-4.0/3.0)
#     return secant(Nu_Nusselt_Rayleigh_Holling_Herwig_err, Nu_guess, args=(Ra, Ra_third, D2))


from ht import *
from ht.conv_free_enclosed import Nu_Nusselt_Rayleigh_Holling_Herwig
from fluids.numerics import assert_close, assert_close1d, assert_close2d, numpy as np
    from scipy.interpolate import bisplrep, UnivariateSpline
    from ht.conv_free_enclosed import tck_uninstulated_Catton, ratios_uninsulated_Catton, Racs_uninstulated_Catton
    from ht.conv_free_enclosed import ratios_insulated_Catton, Racs_instulated_Catton, tck_insulated_Catton
    from fluids.optional import pychebfun
    from ht.conv_free_enclosed import insulated_disk_coeffs, uninsulated_disk_coeffs
import pytest
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

from __future__ import division
try:
except:
    pass


def test_Nu_Nusselt_Rayleigh_Holling_Herwig():
    Ras = [10.0**n for n in range(5, 16)]
    Nus_expect = [4.566, 8.123, 15.689, 31.526, 64.668, 134.135, 279.957, 586.404, 1230.938, 2587.421, 5443.761]
    Nus_calc = [round(Nu_Nusselt_Rayleigh_Holling_Herwig(1., Gr), 3) for Gr in Ras]
    assert_close1d(Nus_expect, Nus_calc)


# Path: ht/conv_free_enclosed.py
# def Nu_Nusselt_Rayleigh_Holling_Herwig(Pr, Gr, buoyancy=True):
#     r'''Calculates the Nusselt number for natural convection between two
#     theoretical flat horizontal plates. The height between the plates is infinite, and
#     one of the other dimensions of the plates is much larger than the other.
# 
#     This correlation is for the horizontal plate Rayleigh-Benard classic heat
#     transfer problem, not for real finite geometry plates.
# 
#     This model is a non-linear equation which is solved numerically.
#     The model can calculate `Nu` for `Ra` ranges between 350 and larger
#     numbers; [1]_ recommends :math:`10^{5} < Ra < 10^{15}`.
# 
#     .. math::
#         \text{Nu} = \frac{{Ra}^{1/3}}{[0.05\ln(\frac{0.078}{16}{Ra}^{1.323})
#         + 2D]^{4/3}}
# 
#     .. math::
#         D = -\frac{14.94}{{Ra}^{0.25}} + 3.43
# 
#     Parameters
#     ----------
#     Pr : float
#         Prandtl number with respect to fluid properties [-]
#     Gr : float
#         Grashof number with respect to fluid properties and plate - plate
#         temperature difference [-]
#     buoyancy : bool, optional
#         Whether or not the plate's free convection is buoyancy assisted (hot
#         plate) or not, [-]
# 
#     Returns
#     -------
#     Nu : float
#         Nusselt number with respect to height between the two plates, [-]
# 
#     Notes
#     -----
#     A range of calculated values are provided in [1]_; they all match the
#     results of this function. This model is recommended in [2]_.
# 
#     For :math:`Ra < 1708`, `Nu` = 1; for cases not assited by `buoyancy`,
#     `Nu` is also 1.
# 
#     No success has been found finding an analytical solution in the major CAS
#     packages, but the nonlinear function is in fact a function of one variable;
#     this means a pade or chebyshev expansion could be performed.
# 
# 
#     Examples
#     --------
#     >>> Nu_Nusselt_Rayleigh_Holling_Herwig(5.54, 3.21e8, buoyancy=True)
#     77.54656801896913
# 
#     References
#     ----------
#     .. [1] Hölling, M., and H. Herwig. "Asymptotic Analysis of Heat Transfer in
#        Turbulent Rayleigh–Bénard Convection." International Journal of Heat and
#        Mass Transfer 49, no. 5 (March 1, 2006): 1129-36.
#        https://doi.org/10.1016/j.ijheatmasstransfer.2005.09.002.
#     .. [2] Gesellschaft, V. D. I., ed. VDI Heat Atlas. 2nd ed. 2010 edition.
#        Berlin ; New York: Springer, 2010.
#     '''
#     if not buoyancy:
#         return 1.0
#     Rac = 1708 # Constant
# 
#     Ra = Gr*Pr
#     if Ra < Rac:
#         return 1.0
# 
#     Ra_third = Ra**(1.0/3.0)
#     D2 = 2.0*(-14.94*Ra**-0.25 + 3.43)
#     Nu_guess = Ra_third*(0.1/2.0*log(.078/16.0*Ra**1.323) + D2)**(-4.0/3.0)
#     return secant(Nu_Nusselt_Rayleigh_Holling_Herwig_err, Nu_guess, args=(Ra, Ra_third, D2))


# Path: tests/test_conv_free_enclosed.py
from ht import *
from ht.conv_free_enclosed import Nu_Nusselt_Rayleigh_Holling_Herwig
from fluids.numerics import assert_close, assert_close1d, assert_close2d, numpy as np
    from scipy.interpolate import bisplrep, UnivariateSpline
    from ht.conv_free_enclosed import tck_uninstulated_Catton, ratios_uninsulated_Catton, Racs_uninstulated_Catton
    from ht.conv_free_enclosed import ratios_insulated_Catton, Racs_instulated_Catton, tck_insulated_Catton
    from fluids.optional import pychebfun
    from ht.conv_free_enclosed import insulated_disk_coeffs, uninsulated_disk_coeffs
import pytest

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

from __future__ import division
try:
except:
    pass


def test_Nu_Nusselt_Rayleigh_Holling_Herwig():
    Ras = [10.0**n for n in range(5, 16)]
    Nus_expect = [4.566, 8.123, 15.689, 31.526, 64.668, 134.135, 279.957, 586.404, 1230.938, 2587.421, 5443.761]
    Nus_calc = [round(Nu_Nusselt_Rayleigh_Holling_Herwig(1., Gr), 3) for Gr in Ras]
    assert_close1d(Nus_expect, Nus_calc)


    assert 1 == Nu_Nusselt_Rayleigh_Holling_Herwig(1., 100., buoyancy=True)