Beispiel #1
0
    def test_get_eos_properties(self):
        omega = CoolPropWrapper._get_eos_property("Acetone", "acentric")
        assert omega == (0.3071, pyunits.dimensionless)

        mw = CoolPropWrapper._get_eos_property("Acetone", "molar_mass")
        assert mw[0] == 0.05807914
        assert_units_equivalent(mw[1], pyunits.kg/pyunits.mol)
Beispiel #2
0
    def m(self):
        # Clear cached components to ensure clean slate
        CoolPropWrapper.flush_cached_components()

        m = ConcreteModel()

        m.fs = FlowsheetBlock(default={'dynamic': False})

        configuration = {
            # Specifying components
            "components": {
                'benzene': {"type": Component,
                            "dens_mol_liq_comp": CoolPropWrapper,
                            "enth_mol_liq_comp": CoolPropWrapper,
                            "enth_mol_ig_comp": CoolPropWrapper,
                            "entr_mol_liq_comp": CoolPropWrapper,
                            "entr_mol_ig_comp": CoolPropWrapper,
                            "pressure_sat_comp": CoolPropWrapper,
                            "parameter_data": {
                                "mw": CoolPropWrapper,
                                "dens_mol_crit": CoolPropWrapper,
                                "pressure_crit": CoolPropWrapper,
                                "temperature_crit": CoolPropWrapper,
                                "omega": CoolPropWrapper}}},
            # Specifying phases
            "phases":  {'Liq': {"type": LiquidPhase,
                                "equation_of_state": Cubic,
                                "equation_of_state_options": {
                                    "type": CubicType.PR}}},

            # Set base units of measurement
            "base_units": {"time": pyunits.s,
                           "length": pyunits.m,
                           "mass": pyunits.kg,
                           "amount": pyunits.mol,
                           "temperature": pyunits.K},

            # Specifying state definition
            "state_definition": FTPx,
            "state_bounds": {"flow_mol": (0, 100, 1000, pyunits.mol/pyunits.s),
                             "temperature": (273.15, 300, 500, pyunits.K),
                             "pressure": (5e4, 1e5, 1e6, pyunits.Pa)},
            "pressure_ref": (101325, pyunits.Pa),
            "temperature_ref": (298.15, pyunits.K),

            "parameter_data": {"PR_kappa": {("benzene", "benzene"): 0.000}}}

        m.fs.props = GenericParameterBlock(default=configuration)

        m.fs.state = m.fs.props.build_state_block(
            [0], default={"defined_state": True})

        m.fs.state[0].flow_mol.fix(1)
        m.fs.state[0].pressure.fix(101325)
        m.fs.state[0].temperature.fix(300)
        m.fs.state[0].mole_frac_comp["benzene"].fix(1)

        return m
Beispiel #3
0
    def test_load_component_by_alias(self):
        # Load CO2 data using one of its aliases
        prop_dict = CoolPropWrapper._load_component_data("R744")

        assert CoolPropWrapper._cached_components["R744"] is prop_dict
        assert "R744" in CoolPropWrapper._cached_components

        # Retrieve CO2 data using its normal name
        prop_dict2 = CoolPropWrapper._get_component_data("CO2")

        assert prop_dict2 is prop_dict
        assert "CO2" in CoolPropWrapper._cached_components
        assert CoolPropWrapper._cached_components["CO2"] is \
            CoolPropWrapper._cached_components["R744"]
Beispiel #4
0
    def test_get_component_alias(self):
        # Load oxygen properties using aliases
        prop_dict = CoolPropWrapper._get_component_data("R732")

        assert CoolPropWrapper._cached_components["Oxygen"] is prop_dict
        assert "R732" in CoolPropWrapper._cached_components
        assert CoolPropWrapper._cached_components["R732"] is \
            CoolPropWrapper._cached_components["Oxygen"]
Beispiel #5
0
    def test_get_parameter_value(self):
        Tc = CoolPropWrapper.get_parameter_value(
            "Acetone", "temperature_crit")
        assert Tc == (508.1, pyunits.K)

        Pc = CoolPropWrapper.get_parameter_value(
            "Acetone", "pressure_crit")
        assert Pc == (4700000.0, pyunits.Pa)

        rhoc = CoolPropWrapper.get_parameter_value(
            "Acetone", "dens_mol_crit")
        assert rhoc[0] == 4699.999999999999
        assert_units_equivalent(rhoc[1], pyunits.mol/pyunits.m**3)

        hc = CoolPropWrapper.get_parameter_value(
            "Acetone", "enth_mol_crit")
        assert hc[0] == 31614.73051047263
        assert_units_equivalent(hc[1], pyunits.J/pyunits.mol)

        sc = CoolPropWrapper.get_parameter_value(
            "Acetone", "entr_mol_crit")
        assert sc[0] == 72.97112978635582
        assert_units_equivalent(sc[1], pyunits.J/pyunits.mol/pyunits.K)

        omega = CoolPropWrapper.get_parameter_value("Acetone", "omega")
        assert omega == (0.3071, pyunits.dimensionless)

        mw = CoolPropWrapper.get_parameter_value("Acetone", "mw")
        assert mw[0] == 0.05807914
        assert_units_equivalent(mw[1], pyunits.kg/pyunits.mol)
Beispiel #6
0
    def test_load_component(self):
        # Clear cached components to be sure
        CoolPropWrapper._cached_components = {}

        # Load parameters for oxygen
        prop_dict = CoolPropWrapper._load_component_data("Oxygen")

        assert prop_dict is not None
        assert "Oxygen" in CoolPropWrapper._cached_components
        assert CoolPropWrapper._cached_components["Oxygen"] is prop_dict
        assert isinstance(prop_dict, dict)
        for k in ["STATES", "ANCILLARIES"]:
            assert k in prop_dict
Beispiel #7
0
    def test_get_critical_properties(self):
        Tc = CoolPropWrapper._get_critical_property(
            "Acetone", "T")
        assert Tc == (508.1, pyunits.K)

        Pc = CoolPropWrapper._get_critical_property(
            "Acetone", "p")
        assert Pc == (4700000.0, pyunits.Pa)

        rhoc = CoolPropWrapper._get_critical_property(
            "Acetone", "rhomolar")
        assert rhoc[0] == 4699.999999999999
        assert_units_equivalent(rhoc[1], pyunits.mol/pyunits.m**3)

        hc = CoolPropWrapper._get_critical_property(
            "Acetone", "hmolar")
        assert hc[0] == 31614.73051047263
        assert_units_equivalent(hc[1], pyunits.J/pyunits.mol)

        sc = CoolPropWrapper._get_critical_property(
            "Acetone", "smolar")
        assert sc[0] == 72.97112978635582
        assert_units_equivalent(sc[1], pyunits.J/pyunits.mol/pyunits.K)
Beispiel #8
0
    def m(self):
        # Clear cached components to ensure clean slate
        CoolPropWrapper.flush_cached_components()

        m = ConcreteModel()

        m.fs = FlowsheetBlock(default={'dynamic': False})

        # NBP reference state: h=0, s=0 for saturated liquid at 1 atmosphere
        CoolProp.set_reference_state('benzene', 'NBP')

        # Get Tsat for benezene at 1 atm
        Tref = CoolProp.PropsSI("T", "P", 101325, "Q", 0.5, "PR::benzene")

        configuration = {
            # Specifying components
            "components": {
                'benzene': {"type": Component,
                            "elemental_composition": {'H': 6, 'C': 6},
                            "dens_mol_liq_comp": CoolPropWrapper,
                            "enth_mol_ig_comp": Constant,
                            "entr_mol_ig_comp": Constant,
                            "parameter_data": {
                                "mw": CoolPropWrapper,
                                "dens_mol_crit": CoolPropWrapper,
                                "pressure_crit": CoolPropWrapper,
                                "temperature_crit": CoolPropWrapper,
                                "omega": CoolPropWrapper,
                                "cp_mol_ig_comp_coeff": 0,
                                "enth_mol_form_ig_comp_ref": 0,
                                "entr_mol_form_ig_comp_ref": 0}}},
            # Specifying phases
            "phases":  {'Vap': {"type": VaporPhase,
                                "equation_of_state": Cubic,
                                "equation_of_state_options": {
                                    "type": CubicType.PR}}},

            # Set base units of measurement
            "base_units": {"time": pyunits.s,
                           "length": pyunits.m,
                           "mass": pyunits.kg,
                           "amount": pyunits.mol,
                           "temperature": pyunits.K},

            # Specifying state definition
            "state_definition": FTPx,
            "state_bounds": {"flow_mol": (0, 100, 1000, pyunits.mol/pyunits.s),
                             "temperature": (273.15, 300, 730, pyunits.K),
                             "pressure": (5e4, 1e5, 1e6, pyunits.Pa)},
            "pressure_ref": (101325, pyunits.Pa),
            "temperature_ref": (Tref, pyunits.K),

            "parameter_data": {"PR_kappa": {("benzene", "benzene"): 0.000}}}

        m.fs.props = GenericParameterBlock(default=configuration)

        m.fs.state = m.fs.props.build_state_block(
            [0], default={"defined_state": True})

        m.fs.state[0].flow_mol.fix(1)
        m.fs.state[0].mole_frac_comp["benzene"].fix(1)

        return m
Beispiel #9
0
    def test_get_component(self):
        prop_dict = CoolPropWrapper._get_component_data("Oxygen")

        assert CoolPropWrapper._cached_components["Oxygen"] is prop_dict
Beispiel #10
0
 def test_load_component_invalid(self):
     with pytest.raises(RuntimeError,
                        match="Failed to find component foo in CoolProp "
                        "JSON database."):
         CoolPropWrapper._load_component_data("foo")
Beispiel #11
0
    def test_flush_cached_components(self):
        CoolPropWrapper.flush_cached_components()

        assert CoolPropWrapper._cached_components == {}