コード例 #1
0
def test_convergence_evaluation_specification_file_unfixedvar_mutableparam():
    ceval_class = cb._class_import(ceval_unfixedvar_mutableparam_str)
    ceval = ceval_class()
    import idaes.core.util.convergence.tests.conv_eval_classes as cev
    assert ceval.__class__ == cev.ConvEvalUnfixedVarMutableParam().__class__

    spec = ceval.get_specification()
    fname = os.path.join(wrtdir, 'ceval_unfixedvar_mutableparam.3.42.json')
    cb.write_sample_file(spec, fname,
                         ceval_unfixedvar_mutableparam_str,
                         n_points=3, seed=42)

    baseline_fname = os.path.join(
            currdir,
            'ceval_unfixedvar_mutableparam.3.42.baseline.json')

    with open(fname) as FILE:
        test = json.load(FILE)
    with open(baseline_fname) as FILE:
        baseline = json.load(FILE)
    assertStructuredAlmostEqual(baseline, test, abstol=1e-8)

    # expect an exception because var is not fixed
    with pytest.raises(ValueError):
        inputs, samples, global_results = \
            cb.run_convergence_evaluation_from_sample_file(fname)

    if os.path.exists(fname):
        os.remove(fname)
コード例 #2
0
    def test_build(self):
        model = ConcreteModel()

        model.param = GenericParameterBlock(default=configuration)

        assert isinstance(model.param.phase_list, Set)
        assert len(model.param.phase_list) == 2
        for i in model.param.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.param.Liq.is_liquid_phase()
        assert model.param.Vap.is_vapor_phase()

        assert isinstance(model.param.component_list, Set)
        assert len(model.param.component_list) == 2
        for i in model.param.component_list:
            assert i in ['bmimPF6',
                         'carbon_dioxide']
            assert isinstance(model.param.get_component(i), Component)

        assert isinstance(model.param._phase_component_set, Set)
        assert len(model.param._phase_component_set) == 3
        for i in model.param._phase_component_set:
            assert i in [("Liq", "bmimPF6"), ("Liq", "carbon_dioxide"),
                         ("Vap", "carbon_dioxide")]

        assert model.param.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.param.config.state_bounds,
            { "flow_mol": (0, 100, 1000, pyunits.mol/pyunits.s),
              "temperature": (10, 300, 500, pyunits.K),
              "pressure": (5e-4, 1e5, 1e10, pyunits.Pa) },
            item_callback=lambda x: value(x) * (
                pyunits.get_units(x) or pyunits.dimensionless)._get_pint_unit()
        )

        assert model.param.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE}

        assert isinstance(model.param.phase_equilibrium_idx, Set)
        assert len(model.param.phase_equilibrium_idx) == 1
        for i in model.param.phase_equilibrium_idx:
            assert i in ["PE1"]

        assert model.param.phase_equilibrium_list == {
            "PE1": {"carbon_dioxide": ("Vap", "Liq")}}

        assert model.param.pressure_ref.value == 101325
        assert model.param.temperature_ref.value == 298.15

        assert model.param.bmimPF6.mw.value == 284.18E-3
        assert model.param.bmimPF6.pressure_crit.value == 24e5
        assert model.param.bmimPF6.temperature_crit.value == 860

        assert model.param.carbon_dioxide.mw.value == 44.010E-3
        assert model.param.carbon_dioxide.pressure_crit.value == 71.8e5
        assert model.param.carbon_dioxide.temperature_crit.value == 304.1

        assert_units_consistent(model)
コード例 #3
0
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=config_dict)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 2
        for i in model.params.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.params.Liq.is_liquid_phase()
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 2
        for i in model.params.component_list:
            assert i in ['benzene', 'toluene']
            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 4
        for i in model.params._phase_component_set:
            assert i in [("Liq", "benzene"), ("Liq", "toluene"),
                         ("Vap", "benzene"), ("Vap", "toluene")]

        assert model.params.config.state_definition == FcPh

        assertStructuredAlmostEqual(
            model.params.config.state_bounds,
            {
                "flow_mol_comp": (0, 100, 1000, pyunits.mol / pyunits.s),
                "enth_mol": (1e4, 5e4, 2e5, pyunits.J / pyunits.mol),
                "temperature": (273.15, 300, 450, pyunits.K),
                "pressure": (5e4, 1e5, 1e6, pyunits.Pa)
            },
            item_callback=_as_quantity,
        )

        assert model.params.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE
        }

        assert isinstance(model.params.phase_equilibrium_idx, Set)
        assert len(model.params.phase_equilibrium_idx) == 2
        for i in model.params.phase_equilibrium_idx:
            assert i in ["PE1", "PE2"]

        assert model.params.phase_equilibrium_list == {
            "PE1": {
                "benzene": ("Vap", "Liq")
            },
            "PE2": {
                "toluene": ("Vap", "Liq")
            }
        }

        assert model.params.pressure_ref.value == 1e5
        assert model.params.temperature_ref.value == 300

        assert_units_consistent(model)
コード例 #4
0
def test_convergence_evaluation_stats_from_to():
    ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str)
    ceval = ceval_class()
    import idaes.core.util.convergence.tests.conv_eval_classes as cev
    assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__

    spec = ceval.get_specification()
    fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.43.json')
    cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str,
                         n_points=3, seed=43)

    inputs, samples, results = \
        cb.run_convergence_evaluation_from_sample_file(fname)

    s = cb.save_convergence_statistics(inputs, results)
    d = s.to_dict()
    s2 = cb.Stats(from_dict=d)
    fname1 = os.path.join(wrtdir, 'stats1.json')

    with open(fname1, "w") as f:
        s.to_json(f)
    with open(fname1) as FILE:
        baseline = json.load(FILE)

    buf = io.StringIO()
    s2.to_json(buf)
    test = json.loads(buf.getvalue())
    assertStructuredAlmostEqual(baseline, test, abstol=1e-8)

    s3 = cb.Stats(from_json=fname1)
    buf = io.StringIO()
    s3.to_json(buf)
    test = json.loads(buf.getvalue())
    assertStructuredAlmostEqual(baseline, test, abstol=1e-8)

    if os.path.exists(fname):
        os.remove(fname)
    if os.path.exists(fname1):
        os.remove(fname1)
コード例 #5
0
def test_convergence_evaluation_specification_file_fixedvar_mutableparam():
    ceval_class = cb._class_import(ceval_fixedvar_mutableparam_str)
    ceval = ceval_class()
    import idaes.core.util.convergence.tests.conv_eval_classes as cev
    assert ceval.__class__ == cev.ConvEvalFixedVarMutableParam().__class__

    spec = ceval.get_specification()
    fname = os.path.join(wrtdir, 'ceval_fixedvar_mutableparam.3.42.json')
    cb.write_sample_file(spec, fname, ceval_fixedvar_mutableparam_str,
                         n_points=3, seed=42)

    baseline_fname = os.path.join(
            currdir,
            'ceval_fixedvar_mutableparam.3.42.baseline.json')

    with open(fname) as FILE:
        test = json.load(FILE)
    with open(baseline_fname) as FILE:
        baseline = json.load(FILE)
    assertStructuredAlmostEqual(baseline, test, abstol=1e-8)

    if os.path.exists(fname):
        os.remove(fname)
コード例 #6
0
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=configuration_vap)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 1
        for i in model.params.phase_list:
            assert i in ["Vap"]
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 13
        for i in model.params.component_list:
            assert i in [
                'hydrogen', 'methane', 'ethane', 'propane', 'nbutane',
                'ibutane', 'ethylene', 'propene', 'butene', 'pentene',
                'hexene', 'heptene', 'octene'
            ]

            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 13
        for i in model.params._phase_component_set:
            assert i in [("Vap", "hydrogen"), ("Vap", "methane"),
                         ("Vap", "ethane"), ("Vap", "propane"),
                         ("Vap", "nbutane"), ("Vap", "ibutane"),
                         ("Vap", "ethylene"), ("Vap", "propene"),
                         ("Vap", "butene"), ("Vap", "pentene"),
                         ("Vap", "hexene"), ("Vap", "heptene"),
                         ("Vap", "octene")]

        assert model.params.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.params.config.state_bounds,
            {
                "flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
                "temperature": (273.15, 300, 1500, pyunits.K),
                "pressure": (5e4, 1e5, 1e7, pyunits.Pa)
            },
            item_callback=_as_quantity,
        )

        assert model.params.pressure_ref.value == 101325
        assert model.params.temperature_ref.value == 298.15

        assert model.params.hydrogen.mw.value == 2.016E-3
        assert model.params.hydrogen.pressure_crit.value == 12.9e5
        assert model.params.hydrogen.temperature_crit.value == 33.2

        assert model.params.methane.mw.value == 16.043E-3
        assert model.params.methane.pressure_crit.value == 46e5
        assert model.params.methane.temperature_crit.value == 190.4

        assert model.params.ethane.mw.value == 30.070E-3
        assert model.params.ethane.pressure_crit.value == 48.8e5
        assert model.params.ethane.temperature_crit.value == 305.4

        assert model.params.propane.mw.value == 44.094E-3
        assert model.params.propane.pressure_crit.value == 42.5e5
        assert model.params.propane.temperature_crit.value == 369.8

        assert model.params.nbutane.mw.value == 58.124E-3
        assert model.params.nbutane.pressure_crit.value == 38.0e5
        assert model.params.nbutane.temperature_crit.value == 425.2

        assert model.params.ibutane.mw.value == 58.124E-3
        assert model.params.ibutane.pressure_crit.value == 36.5e5
        assert model.params.ibutane.temperature_crit.value == 408.2

        assert model.params.ethylene.mw.value == 28.054E-3
        assert model.params.ethylene.pressure_crit.value == 50.5e5
        assert model.params.ethylene.temperature_crit.value == 282.4

        assert model.params.propene.mw.value == 42.081E-3
        assert model.params.propene.pressure_crit.value == 46.2e5
        assert model.params.propene.temperature_crit.value == 365.0

        assert model.params.butene.mw.value == 56.104E-3
        assert model.params.butene.pressure_crit.value == 40.2e5
        assert model.params.butene.temperature_crit.value == 419.3

        assert model.params.pentene.mw.value == 70.135E-3
        assert model.params.pentene.pressure_crit.value == 40.5e5
        assert model.params.pentene.temperature_crit.value == 464.7

        assert model.params.hexene.mw.value == 84.162E-3
        assert model.params.hexene.pressure_crit.value == 31.7e5
        assert model.params.hexene.temperature_crit.value == 504.0

        assert model.params.heptene.mw.value == 98.189E-3
        assert model.params.heptene.pressure_crit.value == 25.4e5
        assert model.params.heptene.temperature_crit.value == 537.2

        assert model.params.octene.mw.value == 112.216E-3
        assert model.params.octene.pressure_crit.value == 26.2e5
        assert model.params.octene.temperature_crit.value == 566.6
        assert_units_consistent(model)
コード例 #7
0
def compare_files(out_file, base_file, abstol, reltol, exception, formatter):
    try:
        if filecmp.cmp(out_file, base_file):
            return True
    except:
        pass

    with open(out_file, 'r') as f1, open(base_file, 'r') as f2:
        out_file_contents = f1.read()
        base_file_contents = f2.read()

    # Filter files independently and then compare filtered contents
    out_filtered = filter_file_contents(out_file_contents.strip().split('\n'))
    base_filtered = filter_file_contents(
        base_file_contents.strip().split('\n'))

    if len(out_filtered) != len(base_filtered):
        # it is likely that a solver returned a (slightly) nonzero
        # value for a variable that is normally 0.  Try to look for
        # sequences like "['varname:', 'Value:', 1e-9]" that appear
        # in one result but not the other and remove them.
        i = 0
        while i < len(base_filtered):
            try:
                unittest.assertStructuredAlmostEqual(
                    out_filtered[i],
                    base_filtered[i],
                    abstol=abstol,
                    reltol=reltol,
                    allow_second_superset=False,
                    exception=exception)
                i += 1
                continue
            except exception:
                pass

            try:
                index_of_out_i_in_base = base_filtered.index(
                    out_filtered[i], i)
            except ValueError:
                index_of_out_i_in_base = float('inf')
            try:
                index_of_base_i_in_out = out_filtered.index(
                    base_filtered[i], i)
            except ValueError:
                index_of_base_i_in_out = float('inf')
            if index_of_out_i_in_base < index_of_base_i_in_out:
                extra = base_filtered
                n = index_of_out_i_in_base
            else:
                extra = out_filtered
                n = index_of_base_i_in_out
            extra_terms = extra[i:n]
            try:
                assert len(extra_terms) % 3 == 0
                assert all(str(_)[-1] == ":" for _ in extra_terms[0::3])
                assert all(str(_) == "Value:" for _ in extra_terms[1::3])
                assert all(abs(_) < abstol for _ in extra_terms[2::3])
            except:
                # This does not match the pattern we are looking
                # for: quit processing, and let the next
                # assertStructuredAlmostEqual raise the appropriate
                # failureException
                break
            extra[i:n] = []

    try:
        unittest.assertStructuredAlmostEqual(out_filtered,
                                             base_filtered,
                                             abstol=abstol,
                                             reltol=reltol,
                                             allow_second_superset=False,
                                             exception=exception,
                                             formatter=formatter)
    except exception:
        # Print helpful information when file comparison fails
        print('---------------------------------')
        print('BASELINE FILE')
        print('---------------------------------')
        print(base_file_contents)
        print('=================================')
        print('---------------------------------')
        print('TEST OUTPUT FILE')
        print('---------------------------------')
        print(out_file_contents)
        raise
    return True
コード例 #8
0
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=configuration)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 2
        for i in model.params.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.params.Liq.is_liquid_phase()
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 3
        for i in model.params.component_list:
            assert i in ['nitrogen',
                         'argon',
                         'oxygen']
            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 6
        for i in model.params._phase_component_set:
            assert i in [
                ("Liq", "nitrogen"), ("Liq", "argon"), ("Liq", "oxygen"),
                ("Vap", "nitrogen"), ("Vap", "argon"), ("Vap", "oxygen")]

        assert model.params.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.params.config.state_bounds,
            { "flow_mol": (0, 100, 1000, pyunits.mol/pyunits.s),
              "temperature": (10, 300, 350, pyunits.K),
              "pressure": (5e4, 1e5, 1e7, pyunits.Pa) },
            item_callback=_as_quantity,
        )

        assert model.params.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE}

        assert isinstance(model.params.phase_equilibrium_idx, Set)
        assert len(model.params.phase_equilibrium_idx) == 3
        for i in model.params.phase_equilibrium_idx:
            assert i in ["PE1", "PE2", "PE3"]

        assert model.params.phase_equilibrium_list == {
            "PE1": {"nitrogen": ("Vap", "Liq")},
            "PE2": {"argon": ("Vap", "Liq")},
            "PE3": {"oxygen": ("Vap", "Liq")}}

        assert model.params.pressure_ref.value == 101325
        assert model.params.temperature_ref.value == 298.15

        assert model.params.nitrogen.mw.value == 28.0135E-3
        assert model.params.nitrogen.pressure_crit.value == 34e5
        assert model.params.nitrogen.temperature_crit.value == 126.2

        assert model.params.argon.mw.value == 39.948E-3
        assert model.params.argon.pressure_crit.value == 48.98e5
        assert model.params.argon.temperature_crit.value == 150.86

        assert model.params.oxygen.mw.value == 31.999E-3
        assert model.params.oxygen.pressure_crit.value == 50.43e5
        assert model.params.oxygen.temperature_crit.value == 154.58

        assert_units_consistent(model)
コード例 #9
0
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=configuration)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 2
        for i in model.params.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.params.Liq.is_liquid_phase()
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 2
        for i in model.params.component_list:
            assert i in ['H2O', 'CO2']
            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 3
        for i in model.params._phase_component_set:
            assert i in [("Liq", "H2O"), ("Vap", "H2O"), ("Vap", "CO2")]

        assert model.params.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.params.config.state_bounds,
            {
                "flow_mol": (0, 10, 20, pyunits.mol / pyunits.s),
                "temperature": (273.15, 323.15, 1000, pyunits.K),
                "pressure": (5e4, 108900, 1e7, pyunits.Pa),
                "mole_frac_comp": {
                    "H2O": (0, 0.5, 1),
                    "CO2": (0, 0.5, 1)
                }
            },
            item_callback=_as_quantity,
        )

        assert model.params.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE
        }

        assert isinstance(model.params.phase_equilibrium_idx, Set)
        assert len(model.params.phase_equilibrium_idx) == 1
        for i in model.params.phase_equilibrium_idx:
            assert i in ["PE1"]

        assert model.params.phase_equilibrium_list == {
            "PE1": {
                "H2O": ("Vap", "Liq")
            }
        }

        assert model.params.pressure_ref.value == 101325
        assert model.params.temperature_ref.value == 298.15

        assert model.params.H2O.mw.value == 18.0153E-3
        assert model.params.H2O.pressure_crit.value == 220.64E5
        assert model.params.H2O.temperature_crit.value == 647

        assert model.params.CO2.mw.value == 44.0095E-3
        assert model.params.CO2.pressure_crit.value == 73.825E5
        assert model.params.CO2.temperature_crit.value == 304.23

        assert_units_consistent(model)
コード例 #10
0
ファイル: test_HC_PR.py プロジェクト: xiangyuy/idaes-pse
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=configuration)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 2
        for i in model.params.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.params.Liq.is_liquid_phase()
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 13
        for i in model.params.component_list:
            assert i in ['hydrogen',
                         'methane',
                         'ethane',
                         'propane',
                         'nbutane',
                         'ibutane',
                         'ethylene',
                         'propene',
                         'butene',
                         'pentene',
                         'hexene',
                         'heptene',
                         'octene']

            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 24
        for i in model.params._phase_component_set:
            assert i in [
                ("Liq", "ethane"), ("Vap", "hydrogen"), ("Vap", "methane"),
                ("Vap", "ethane"), ("Liq", "propane"), ("Liq", "nbutane"),
                ("Liq", "ibutane"), ("Vap", "propane"), ("Vap", "nbutane"),
                ("Vap", "ibutane"), ("Liq", "ethylene"), ("Liq", "propene"),
                ("Liq", "butene"), ("Vap", "ethylene"), ("Vap", "propene"),
                ("Vap", "butene"), ("Liq", "pentene"), ("Liq", "hexene"),
                ("Liq", "heptene"), ("Vap", "pentene"), ("Vap", "hexene"),
                ("Vap", "heptene"), ("Liq", "octene"), ("Vap", "octene")]

        assert model.params.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.params.config.state_bounds,
            { "flow_mol": (0, 100, 1000, pyunits.mol/pyunits.s),
              "temperature": (273.15, 300, 1500, pyunits.K),
              "pressure": (5e4, 1e5, 1e7, pyunits.Pa) },
            item_callback=lambda x: value(x) * (
                pyunits.get_units(x) or pyunits.dimensionless)._get_pint_unit()
        )

        assert model.params.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE}

        assert isinstance(model.params.phase_equilibrium_idx, Set)
        assert len(model.params.phase_equilibrium_idx) == 11
        for i in model.params.phase_equilibrium_idx:
            assert i in ["PE1", "PE2", "PE3", "PE4", "PE5", "PE6",
                         "PE7", "PE8", "PE9", "PE10", "PE11"]

        assert model.params.phase_equilibrium_list == {
            "PE1": {"ethane": ("Vap", "Liq")},
            "PE2": {"propane": ("Vap", "Liq")},
            "PE3": {"nbutane": ("Vap", "Liq")},
            "PE4": {"ibutane": ("Vap", "Liq")},
            "PE5": {"ethylene": ("Vap", "Liq")},
            "PE6": {"propene": ("Vap", "Liq")},
            "PE7": {"butene": ("Vap", "Liq")},
            "PE8": {"pentene": ("Vap", "Liq")},
            "PE9": {"hexene": ("Vap", "Liq")},
            "PE10": {"heptene": ("Vap", "Liq")},
            "PE11": {"octene": ("Vap", "Liq")}}

        assert model.params.pressure_ref.value == 101325
        assert model.params.temperature_ref.value == 298.15

        assert model.params.hydrogen.mw.value == 2.016E-3
        assert model.params.hydrogen.pressure_crit.value == 12.9e5
        assert model.params.hydrogen.temperature_crit.value == 33.2

        assert model.params.methane.mw.value == 16.043E-3
        assert model.params.methane.pressure_crit.value == 46e5
        assert model.params.methane.temperature_crit.value == 190.4

        assert model.params.ethane.mw.value == 30.070E-3
        assert model.params.ethane.pressure_crit.value == 48.8e5
        assert model.params.ethane.temperature_crit.value == 305.4

        assert model.params.propane.mw.value == 44.094E-3
        assert model.params.propane.pressure_crit.value == 42.5e5
        assert model.params.propane.temperature_crit.value == 369.8

        assert model.params.nbutane.mw.value == 58.124E-3
        assert model.params.nbutane.pressure_crit.value == 38.0e5
        assert model.params.nbutane.temperature_crit.value == 425.2

        assert model.params.ibutane.mw.value == 58.124E-3
        assert model.params.ibutane.pressure_crit.value == 36.5e5
        assert model.params.ibutane.temperature_crit.value == 408.2

        assert model.params.ethylene.mw.value == 28.054E-3
        assert model.params.ethylene.pressure_crit.value == 50.5e5
        assert model.params.ethylene.temperature_crit.value == 282.4

        assert model.params.propene.mw.value == 42.081E-3
        assert model.params.propene.pressure_crit.value == 46.2e5
        assert model.params.propene.temperature_crit.value == 365.0

        assert model.params.butene.mw.value == 56.104E-3
        assert model.params.butene.pressure_crit.value == 40.2e5
        assert model.params.butene.temperature_crit.value == 419.3

        assert model.params.pentene.mw.value == 70.135E-3
        assert model.params.pentene.pressure_crit.value == 40.5e5
        assert model.params.pentene.temperature_crit.value == 464.7

        assert model.params.hexene.mw.value == 84.162E-3
        assert model.params.hexene.pressure_crit.value == 31.7e5
        assert model.params.hexene.temperature_crit.value == 504.0

        assert model.params.heptene.mw.value == 98.189E-3
        assert model.params.heptene.pressure_crit.value == 25.4e5
        assert model.params.heptene.temperature_crit.value == 537.2

        assert model.params.octene.mw.value == 112.216E-3
        assert model.params.octene.pressure_crit.value == 26.2e5
        assert model.params.octene.temperature_crit.value == 566.6
        assert_units_consistent(model)
コード例 #11
0
ファイル: test_BTIdeal.py プロジェクト: xiangyuy/idaes-pse
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(default=configuration)

        assert isinstance(model.params.phase_list, Set)
        assert len(model.params.phase_list) == 2
        for i in model.params.phase_list:
            assert i in ["Liq", "Vap"]
        assert model.params.Liq.is_liquid_phase()
        assert model.params.Vap.is_vapor_phase()

        assert isinstance(model.params.component_list, Set)
        assert len(model.params.component_list) == 2
        for i in model.params.component_list:
            assert i in ['benzene', 'toluene']
            assert isinstance(model.params.get_component(i), Component)

        assert isinstance(model.params._phase_component_set, Set)
        assert len(model.params._phase_component_set) == 4
        for i in model.params._phase_component_set:
            assert i in [("Liq", "benzene"), ("Liq", "toluene"),
                         ("Vap", "benzene"), ("Vap", "toluene")]

        assert model.params.config.state_definition == FTPx

        assertStructuredAlmostEqual(
            model.params.config.state_bounds, {
                "flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
                "temperature": (273.15, 300, 450, pyunits.K),
                "pressure": (5e4, 1e5, 1e6, pyunits.Pa)
            },
            item_callback=lambda x: value(x) *
            (pyunits.get_units(x) or pyunits.dimensionless)._get_pint_unit())

        assert model.params.config.phase_equilibrium_state == {
            ("Vap", "Liq"): SmoothVLE
        }

        assert isinstance(model.params.phase_equilibrium_idx, Set)
        assert len(model.params.phase_equilibrium_idx) == 2
        for i in model.params.phase_equilibrium_idx:
            assert i in ["PE1", "PE2"]

        assert model.params.phase_equilibrium_list == {
            "PE1": {
                "benzene": ("Vap", "Liq")
            },
            "PE2": {
                "toluene": ("Vap", "Liq")
            }
        }

        assert model.params.pressure_ref.value == 1e5
        assert model.params.temperature_ref.value == 300

        assert model.params.benzene.mw.value == 78.1136E-3
        assert model.params.benzene.pressure_crit.value == 48.9e5
        assert model.params.benzene.temperature_crit.value == 562.2

        assert model.params.toluene.mw.value == 92.1405E-3
        assert model.params.toluene.pressure_crit.value == 41e5
        assert model.params.toluene.temperature_crit.value == 591.8

        assert_units_consistent(model)