Ejemplo n.º 1
0
def test_fluid_props():
    has_CoolProp()
#    tots = [sum([getattr(f, prop) for f in coolprop_fluids.values()]) for prop in ['Tmin', 'Tmax', 'Pmax', 'Tc', 'Pc', 'Tt', 'omega']]
#    tots_exp = [18589.301, 71575.0, 31017000000.0, 45189.59849999997, 440791794.7987591, 18589.301, 30.90243968446593]


#    assert_close1d(tots_exp, tots)

    assert len(coolprop_fluids) == len(coolprop_dict)
    assert len(coolprop_dict) == 105
    assert all([check_CAS(i) for i in coolprop_dict])
Ejemplo n.º 2
0
    def __init__(self, backend, fluid,
                 T=None, P=None, zs=None,  Hfs=None,
                 Gfs=None, Sfs=None,):
        if not CoolProp_constants_set:
            if has_CoolProp():
                set_coolprop_constants()
            else:
                raise ValueError("CoolProp is not installed")

        self.Hfs = Hfs
        self.Gfs = Gfs
        self.Sfs = Sfs

        self.backend = backend
        self.fluid = fluid

        self.skip_comp = skip_comp = (backend in ('IF97') or fluid in ('water') or '&' not in fluid)
        if zs is None:
            zs = [1.0]
        self.zs = zs
        self.N = N = len(zs)
        if skip_comp or N == 1:
            zs_key = None
        else:
            zs_key = tuple(zs)
        if T is not None and P is not None:
            self.T = T
            self.P = P
            try:
                key = [backend, fluid, P, T, CPPT_INPUTS, self.prefer_phase, zs_key]
                AS = caching_state_CoolProp(*key)
            except:
                key = [backend, fluid, P, T, CPPT_INPUTS, CPunknown, zs_key]
                AS = caching_state_CoolProp(*key)
            self.key = key
            self._cache_easy_properties(AS)
Ejemplo n.º 3
0
import json
from math import isnan
from fluids.numerics import linspace, assert_close, derivative, assert_close1d
from chemicals.vapor_pressure import *
from thermo.vapor_pressure import *
from thermo.vapor_pressure import SANJARI, EDALAT, AMBROSE_WALTON, LEE_KESLER_PSAT, BOILING_CRITICAL, COOLPROP, VDI_PPDS, VDI_TABULAR, WAGNER_MCGARRY, ANTOINE_EXTENDED_POLING, ANTOINE_POLING, WAGNER_POLING, DIPPR_PERRY_8E
from thermo.utils import TDependentProperty
from chemicals.identifiers import check_CAS
import chemicals
from thermo.coolprop import has_CoolProp
from math import *


@pytest.mark.CoolProp
@pytest.mark.meta_T_dept
@pytest.mark.skipif(not has_CoolProp(), reason='CoolProp is missing')
def test_VaporPressure_CoolProp():
    EtOH = VaporPressure(Tb=351.39,
                         Tc=514.0,
                         Pc=6137000.0,
                         omega=0.635,
                         CASRN='64-17-5')
    assert_close(EtOH.calculate(305.0, COOLPROP),
                 11592.205263402893,
                 rtol=1e-7)


@pytest.mark.meta_T_dept
def test_VaporPressure():
    # Ethanol, test as many methods asa possible at once
    EtOH = VaporPressure(Tb=351.39,
Ejemplo n.º 4
0
    def load_all_methods(self, load_data=True):
        r'''Method which picks out coefficients for the specified chemical
        from the various dictionaries and DataFrames storing it. All data is
        stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`,
        and :obj:`all_methods` as a set of methods for which the data exists for.

        Called on initialization only. See the source code for the variables at
        which the coefficients are stored. The coefficients can safely be
        altered once the class is initialized. This method can be called again
        to reset the parameters.
        '''
        self.T_limits = T_limits = {}
        methods = []
        Tmins, Tmaxs = [], []
        if load_data:
            if self.CASRN in vapor_pressure.Psat_data_WagnerMcGarry.index:
                methods.append(WAGNER_MCGARRY)
                A, B, C, D, self.WAGNER_MCGARRY_Pc, self.WAGNER_MCGARRY_Tc, self.WAGNER_MCGARRY_Tmin = vapor_pressure.Psat_values_WagnerMcGarry[
                    vapor_pressure.Psat_data_WagnerMcGarry.index.get_loc(
                        self.CASRN)].tolist()
                self.WAGNER_MCGARRY_coefs = [A, B, C, D]
                Tmins.append(self.WAGNER_MCGARRY_Tmin)
                Tmaxs.append(self.WAGNER_MCGARRY_Tc)
                T_limits[WAGNER_MCGARRY] = (self.WAGNER_MCGARRY_Tmin,
                                            self.WAGNER_MCGARRY_Tc)

            if self.CASRN in vapor_pressure.Psat_data_WagnerPoling.index:
                methods.append(WAGNER_POLING)
                A, B, C, D, self.WAGNER_POLING_Tc, self.WAGNER_POLING_Pc, Tmin, self.WAGNER_POLING_Tmax = vapor_pressure.Psat_values_WagnerPoling[
                    vapor_pressure.Psat_data_WagnerPoling.index.get_loc(
                        self.CASRN)].tolist()
                # Some Tmin values are missing; Arbitrary choice of 0.1 lower limit
                self.WAGNER_POLING_Tmin = Tmin if not isnan(
                    Tmin) else self.WAGNER_POLING_Tmax * 0.1
                self.WAGNER_POLING_coefs = [A, B, C, D]
                Tmins.append(Tmin)
                Tmaxs.append(self.WAGNER_POLING_Tmax)
                T_limits[WAGNER_POLING] = (self.WAGNER_POLING_Tmin,
                                           self.WAGNER_POLING_Tmax)

            if self.CASRN in vapor_pressure.Psat_data_AntoineExtended.index:
                methods.append(ANTOINE_EXTENDED_POLING)
                A, B, C, Tc, to, n, E, F, self.ANTOINE_EXTENDED_POLING_Tmin, self.ANTOINE_EXTENDED_POLING_Tmax = vapor_pressure.Psat_values_AntoineExtended[
                    vapor_pressure.Psat_data_AntoineExtended.index.get_loc(
                        self.CASRN)].tolist()
                self.ANTOINE_EXTENDED_POLING_coefs = [Tc, to, A, B, C, n, E, F]
                Tmins.append(self.ANTOINE_EXTENDED_POLING_Tmin)
                Tmaxs.append(self.ANTOINE_EXTENDED_POLING_Tmax)
                T_limits[ANTOINE_EXTENDED_POLING] = (
                    self.ANTOINE_EXTENDED_POLING_Tmin,
                    self.ANTOINE_EXTENDED_POLING_Tmax)

            if self.CASRN in vapor_pressure.Psat_data_AntoinePoling.index:
                methods.append(ANTOINE_POLING)
                A, B, C, self.ANTOINE_POLING_Tmin, self.ANTOINE_POLING_Tmax = vapor_pressure.Psat_values_AntoinePoling[
                    vapor_pressure.Psat_data_AntoinePoling.index.get_loc(
                        self.CASRN)].tolist()
                self.ANTOINE_POLING_coefs = [A, B, C]
                Tmins.append(self.ANTOINE_POLING_Tmin)
                Tmaxs.append(self.ANTOINE_POLING_Tmax)
                T_limits[ANTOINE_POLING] = (self.ANTOINE_POLING_Tmin,
                                            self.ANTOINE_POLING_Tmax)

            if self.CASRN in vapor_pressure.Psat_data_Perrys2_8.index:
                methods.append(DIPPR_PERRY_8E)
                C1, C2, C3, C4, C5, self.Perrys2_8_Tmin, self.Perrys2_8_Tmax = vapor_pressure.Psat_values_Perrys2_8[
                    vapor_pressure.Psat_data_Perrys2_8.index.get_loc(
                        self.CASRN)].tolist()
                self.Perrys2_8_coeffs = [C1, C2, C3, C4, C5]
                Tmins.append(self.Perrys2_8_Tmin)
                Tmaxs.append(self.Perrys2_8_Tmax)
                T_limits[DIPPR_PERRY_8E] = (self.Perrys2_8_Tmin,
                                            self.Perrys2_8_Tmax)
            if has_CoolProp() and self.CASRN in coolprop_dict:
                methods.append(COOLPROP)
                self.CP_f = coolprop_fluids[self.CASRN]
                Tmins.append(self.CP_f.Tmin)
                Tmaxs.append(self.CP_f.Tc)
                T_limits[COOLPROP] = (self.CP_f.Tmin, self.CP_f.Tc)

            if self.CASRN in miscdata.VDI_saturation_dict:
                methods.append(VDI_TABULAR)
                Ts, props = lookup_VDI_tabular_data(self.CASRN, 'P')
                self.VDI_Tmin = Ts[0]
                self.VDI_Tmax = Ts[-1]
                self.tabular_data[VDI_TABULAR] = (Ts, props)
                Tmins.append(self.VDI_Tmin)
                Tmaxs.append(self.VDI_Tmax)
                T_limits[VDI_TABULAR] = (self.VDI_Tmin, self.VDI_Tmax)

            if self.CASRN in vapor_pressure.Psat_data_VDI_PPDS_3.index:
                Tm, Tc, Pc, A, B, C, D = vapor_pressure.Psat_values_VDI_PPDS_3[
                    vapor_pressure.Psat_data_VDI_PPDS_3.index.get_loc(
                        self.CASRN)].tolist()
                self.VDI_PPDS_coeffs = [A, B, C, D]
                self.VDI_PPDS_Tc = Tc
                self.VDI_PPDS_Tm = Tm
                self.VDI_PPDS_Pc = Pc
                methods.append(VDI_PPDS)
                Tmins.append(self.VDI_PPDS_Tm)
                Tmaxs.append(self.VDI_PPDS_Tc)
                T_limits[VDI_PPDS] = (self.VDI_PPDS_Tm, self.VDI_PPDS_Tc)
        if all((self.Tb, self.Tc, self.Pc)):
            methods.append(BOILING_CRITICAL)
            Tmins.append(0.01)
            Tmaxs.append(self.Tc)
            T_limits[BOILING_CRITICAL] = (0.01, self.Tc)
        if all((self.Tc, self.Pc, self.omega)):
            methods.append(LEE_KESLER_PSAT)
            methods.append(AMBROSE_WALTON)
            methods.append(SANJARI)
            methods.append(EDALAT)
            if self.eos:
                methods.append(EOS)
                T_limits[EOS] = (0.1 * self.Tc, self.Tc)
            Tmins.append(0.01)
            Tmaxs.append(self.Tc)
            T_limits[LEE_KESLER_PSAT] = T_limits[AMBROSE_WALTON] = T_limits[
                SANJARI] = T_limits[EDALAT] = (0.01, self.Tc)
        self.all_methods = set(methods)
        if Tmins and Tmaxs:
            self.Tmin = min(Tmins)
            self.Tmax = max(Tmaxs)
Ejemplo n.º 5
0
    def load_all_methods(self, load_data=True):
        r'''Method which picks out coefficients for the specified chemical
        from the various dictionaries and DataFrames storing it. All data is
        stored as attributes. This method also sets :obj:`Tmin`, :obj:`Tmax`,
        and :obj:`all_methods` as a set of methods for which the data exists for.

        Called on initialization only. See the source code for the variables at
        which the coefficients are stored. The coefficients can safely be
        altered once the class is initialized. This method can be called again
        to reset the parameters.
        '''
        methods = []
        self.T_limits = T_limits = {}
        if load_data:
            if has_CoolProp() and self.CASRN in coolprop_dict:
                methods.append(COOLPROP)
                self.CP_f = coolprop_fluids[self.CASRN]
                T_limits[COOLPROP] = (self.CP_f.Tt, self.CP_f.Tc * .9999)
            if self.CASRN in miscdata.VDI_saturation_dict:
                methods.append(VDI_TABULAR)
                Ts, props = lookup_VDI_tabular_data(self.CASRN, 'Hvap')
                self.VDI_Tmin = Ts[0]
                self.VDI_Tmax = Ts[-1]
                self.tabular_data[VDI_TABULAR] = (Ts, props)
                T_limits[VDI_TABULAR] = (self.VDI_Tmin, self.VDI_Tmax)

            if self.CASRN in phase_change.phase_change_data_Alibakhshi_Cs.index and self.Tc is not None:
                methods.append(ALIBAKHSHI)
                self.Alibakhshi_C = float(
                    phase_change.phase_change_data_Alibakhshi_Cs.at[self.CASRN,
                                                                    'C'])
                T_limits[ALIBAKHSHI] = (self.Tc * .3, max(self.Tc - 100., 0))
            if self.CASRN in phase_change.Hvap_data_CRC.index and not isnan(
                    phase_change.Hvap_data_CRC.at[self.CASRN, 'HvapTb']):
                methods.append(CRC_HVAP_TB)
                self.CRC_HVAP_TB_Tb = float(
                    phase_change.Hvap_data_CRC.at[self.CASRN, 'Tb'])
                self.CRC_HVAP_TB_Hvap = float(
                    phase_change.Hvap_data_CRC.at[self.CASRN, 'HvapTb'])
                if self.Tc is not None:
                    T_limits[CRC_HVAP_TB] = (self.Tc * .001, self.Tc)
                else:
                    T_limits[CRC_HVAP_TB] = (self.CRC_HVAP_TB_Tb,
                                             self.CRC_HVAP_TB_Tb)
            if self.CASRN in phase_change.Hvap_data_CRC.index and not isnan(
                    phase_change.Hvap_data_CRC.at[self.CASRN, 'Hvap298']):
                methods.append(CRC_HVAP_298)
                self.CRC_HVAP_298 = float(
                    phase_change.Hvap_data_CRC.at[self.CASRN, 'Hvap298'])
                if self.Tc is not None:
                    T_limits[CRC_HVAP_298] = (self.Tc * .001, self.Tc)
                else:
                    T_limits[CRC_HVAP_298] = (298.15, 298.15)
            if self.CASRN in phase_change.Hvap_data_Gharagheizi.index:
                methods.append(GHARAGHEIZI_HVAP_298)
                self.GHARAGHEIZI_HVAP_298_Hvap = float(
                    phase_change.Hvap_data_Gharagheizi.at[self.CASRN,
                                                          'Hvap298'])
                if self.Tc is not None:
                    T_limits[GHARAGHEIZI_HVAP_298] = (self.Tc * .001, self.Tc)
                else:
                    T_limits[GHARAGHEIZI_HVAP_298] = (298.15, 298.15)
            if self.CASRN in phase_change.phase_change_data_Perrys2_150.index:
                methods.append(DIPPR_PERRY_8E)
                Tc, C1, C2, C3, C4, self.Perrys2_150_Tmin, self.Perrys2_150_Tmax = phase_change.phase_change_values_Perrys2_150[
                    phase_change.phase_change_data_Perrys2_150.index.get_loc(
                        self.CASRN)].tolist()
                self.Perrys2_150_coeffs = [Tc, C1, C2, C3, C4]
                T_limits[DIPPR_PERRY_8E] = (self.Perrys2_150_Tmin,
                                            self.Perrys2_150_Tmax)
            if self.CASRN in phase_change.phase_change_data_VDI_PPDS_4.index:
                Tc, A, B, C, D, E = phase_change.phase_change_values_VDI_PPDS_4[
                    phase_change.phase_change_data_VDI_PPDS_4.index.get_loc(
                        self.CASRN)].tolist()
                self.VDI_PPDS_coeffs = [A, B, C, D, E]
                self.VDI_PPDS_Tc = Tc
                methods.append(VDI_PPDS)
                T_limits[VDI_PPDS] = (0.1 * self.VDI_PPDS_Tc, self.VDI_PPDS_Tc)
        if all((self.Tc, self.omega)):
            methods.extend(self.CSP_methods)
            for m in self.CSP_methods:
                T_limits[m] = (1e-4, self.Tc)
        if all((self.Tc, self.Pc)):
            methods.append(CLAPEYRON)
            T_limits[CLAPEYRON] = (1e-4, self.Tc)
        if all((self.Tb, self.Tc, self.Pc)):
            methods.extend(self.boiling_methods)
            for m in self.boiling_methods:
                T_limits[m] = (1e-4, self.Tc)
        self.all_methods = set(methods)