#!/usr/bin/python
# -*- coding: utf-8 -*-

from lib.meos import MEoS
from lib import unidades


class R134a(MEoS):
    """Multiparameter equation of state for R134a"""
    name = "1,1,1,2-tetrafluoroethane"
    CASNumber = "811-97-2"
    formula = "CF3CH2F"
    synonym = "R134a"
    rhoc = unidades.Density(511.9)
    Tc = unidades.Temperature(374.21)
    Pc = unidades.Pressure(4059.28, "kPa")
    M = 102.032  # g/mol
    Tt = unidades.Temperature(169.85)
    Tb = unidades.Temperature(247.076)
    f_acent = 0.32684
    momentoDipolar = unidades.DipoleMoment(2.058, "Debye")
    id = 236
    # id = 1235

    Fi1 = {"ao_log": [1, -1.629789],
           "pow": [0, 1, -0.5, -0.75],
           "ao_pow": [-1.019535, 9.047135, -9.723916, -3.92717],
           "ao_exp": [], "titao": []}

    Fi2 = {"ao_log": [1, -1],
           "pow": [0, 1, -0.25],
           "ao_pow": [10.78497786, 8.612977410, -24.37548384],
           "ao_exp": [7.451784998, -4.239239505, 6.445739825],
           "titao": [-4.103830338, -2.561528683, -2.084607363]}

    CP2 = {"ao": 19.4006,
           "an": [0.258531, -1.29665e-4], "pow": [1, 2],
           "ao_exp": [], "exp": [],
           "ao_hyp": [], "hyp": []}

    # TDOO: Add Huber-Ely meos, file in todo folder
    helmholtz1 = {
        "__type__": "Helmholtz",
        "__name__": "Helmholtz equation of state for R-134a of Tillner-Roth & Baehr (1994).",
        "__doi__": {"autor": "Tillner-Roth, R. and Baehr, H.D.",
                    "title": "An international standard formulation of the thermodynamic properties of 1,1,1,2-tetrafluoroethane (HFC-134a) for temperatures from 170 K to 455 K at pressures up to 70 MPa", 
                    "ref": "J. Phys. Chem. Ref. Data 23, 657 (1994)",
                    "doi": "10.1063/1.555958"}, 
        "__test__": 
            #Table 8, Pag 696
            """
            >>> st=R134a(T=169.85, x=0.5)
            >>> print "%0.2f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            169.85 0.00039 1591.1 0.02817 71.454 334.94 0.4126 1.9639 0.7922 0.5029 1.1838 0.5853 1119.9 126.79
            >>> st=R134a(T=180, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            180 0.00113 1564.2 0.07701 83.482 340.88 0.4813 1.9
113 0.7912 0.5267 1.1871 0.6096 1068.3 130.05
            >>> st=R134a(T=200, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas
.cp.kJkgK, st.Liquido.w, st.Gas.w)
            200 0.00631 1510.4 0.38977 107.39 353.05 0.6073 1.8356 0.8015 0.5732 1.2057 0.5386 967.60 135.98
            >>> st=R134a(T=220, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            220 0.02443 1455.1 1.3850 131.77 365.65 0.7234 1.7865 0.8193 0.6203 1.2331 0.7109 869.85 141.00
            >>> st=R134a(T=250, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            250 0.11561 1367.8 5.9545 169.56 384.60 0.8841 1.7442 0.8514 0.6961 1.2864 0.8044 728.38 145.98
            >>> st=R134a(T=300, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            300 0.70282 1199.6 34.192 237.18 413.26 1.1286 1.7155 0.9144 0.8426 1.4324 1.0438 497.88 143.87
            >>> st=R134a(T=.350, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            350 2.4610 951.31 140.99 316.49 429.02 1.3674 1.6889 1.0036 1.0300 1.9613 1.8493 254.05 120.33
            >>> st=R134a(T=360, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            360 3.0404 870.11 193.58 336.05 427.07 1.4207 1.6735 1.0389 1.0853 2.4367 2.6063 196.04 111.24
            >>> st=R134a(T=370, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            370 3.7278 740.31 293.89 360.64 417.68 1.4856 1.6398 1.1145 1.1690 5.1048 6.8621 127.23 99.370
            >>> st=R134a(T=374, x=0.5)
            >>> print "%0.0f %0.5f %0.1f %0.5f %0.3f %0.2f %0.4f %0.4f %0.4f %0.4f %0.4f %0.4f %0.1f %0.2f" % (\
                st.T, st.P.MPa, st.Liquido.rho, st.Gas.rho, st.Liquido.h.kJkg, st.Gas.h.kJkg, \
                st.Liquido.s.kJkgK, st.Gas.s.kJkgK, st.Liquido.cv.kJkgK, st.Gas.cv.kJkgK, \
                st.Liquido.cp.kJkgK, st.Gas.cp.kJkgK, st.Liquido.w, st.Gas.w)
            374 4.0416 587.91 434.05 380.85 399.50 1.5387 1.5885 1.2120 1.2409 101.66 137.23 92.401 91.389
            """
            #Table 9, Pag 700
            """
            >>> st=R134a(T=170, P=1e4)
            >>> print "%0.6g %0.5g %0.5g %0.5g %0.4g %0.5g %0.5g %0.5g" % (\
                st.T, st.rho, st.u.kJkg, st.h.kJkg, st.s.kJkgK, st.cv.kJkgK, st.cp.kJkgK, st.w)
            170 1590.7 71.636 0.4136 0.7921 1.1838 1119.2
            >>> st=R134a(T=210, P=2e4)
            >>> print "%0.6g %0.5g %0.5g %0.5g %0.4g %0.5g %0.5g %0.5g" % (\
                st.T, st.rho, st.u.kJkg, st.h.kJkg, st.s.kJkgK, st.cv.kJkgK, st.cp.kJkgK, st.w)
            210 1483.0 119.52 0.6664 0.8098 1.2186 918.36
            >>> st=R134a(T=305, P=3e4)
            >>> print "%0.6g %0.5g %0.5g %0.5g %0.4g %0.5g %0.5g %0.5g" % (\
                st.T, st.rho, st.u.kJkg, st.h.kJkg, st.s.kJkgK, st.cv.kJkgK, st.cp.kJkgK, st.w)
            305 1.2137 431.60 2.0221 0.7662 0.8501 165.14
            >>> st=R134a(T=440, P=4e4)
            >>> print "%0.6g %0.5g %0.5g %0.5g %0.4g %0.5g %0.5g %0.5g" % (\
                st.T, st.rho, st.u.kJkg, st.h.kJkg, st.s.kJkgK, st.cv.kJ