Exemple #1
0
    def test_assert_units_consistent_on_datas(self):
        u = units
        m = ConcreteModel()
        m.S = Set(initialize=[1, 2, 3])
        m.x = Var(m.S, units=u.m)
        m.t = Var(m.S, units=u.s)
        m.v = Var(m.S, units=u.m / u.s)
        m.unitless = Var(m.S)

        @m.Constraint(m.S)
        def vel_con(m, i):
            return m.v[i] == m.x[i] / m.t[i]

        @m.Constraint(m.S)
        def unitless_con(m, i):
            return m.unitless[i] == 42.0

        @m.Constraint(m.S)
        def sqrt_con(m, i):
            return sqrt(m.v[i]) == sqrt(m.x[i] / m.t[i])

        m.obj = Objective(expr=m.v, sense=maximize)

        assert_units_consistent(m)  # check model
        assert_units_consistent(m.x)  # check var
        assert_units_consistent(m.t)  # check var
        assert_units_consistent(m.v)  # check var
        assert_units_consistent(m.unitless)  # check var
        assert_units_consistent(m.vel_con)  # check constraint
        assert_units_consistent(m.unitless_con)  # check unitless constraint

        assert_units_consistent(m.x[2])  # check var data
        assert_units_consistent(m.t[2])  # check var data
        assert_units_consistent(m.v[2])  # check var data
        assert_units_consistent(m.unitless[2])  # check var
        assert_units_consistent(m.vel_con[2])  # check constraint data
        assert_units_consistent(
            m.unitless_con[2])  # check unitless constraint data

        assert_units_equivalent(m.x[2], m.x[1])  # check var data
        assert_units_equivalent(m.t[2], u.s)  # check var data
        assert_units_equivalent(m.v[2], u.m / u.s)  # check var data
        assert_units_equivalent(m.unitless[2],
                                u.dimensionless)  # check var data unitless
        assert_units_equivalent(m.unitless[2], None)  # check var
        assert_units_equivalent(m.vel_con[2].body,
                                u.m / u.s)  # check constraint data
        assert_units_equivalent(
            m.unitless_con[2].body,
            u.dimensionless)  # check unitless constraint data

        @m.Constraint(m.S)
        def broken(m, i):
            return m.x[i] == 42.0 * m.v[i]

        with self.assertRaises(UnitsError):
            assert_units_consistent(m)
        with self.assertRaises(UnitsError):
            assert_units_consistent(m.broken)
        with self.assertRaises(UnitsError):
            assert_units_consistent(m.broken[1])

        # all of these should still work
        assert_units_consistent(m.x)  # check var
        assert_units_consistent(m.t)  # check var
        assert_units_consistent(m.v)  # check var
        assert_units_consistent(m.unitless)  # check var
        assert_units_consistent(m.vel_con)  # check constraint
        assert_units_consistent(m.unitless_con)  # check unitless constraint

        assert_units_consistent(m.x[2])  # check var data
        assert_units_consistent(m.t[2])  # check var data
        assert_units_consistent(m.v[2])  # check var data
        assert_units_consistent(m.unitless[2])  # check var
        assert_units_consistent(m.vel_con[2])  # check constraint data
        assert_units_consistent(
            m.unitless_con[2])  # check unitless constraint data
Exemple #2
0
def test_units(build_downcomer):
    assert_units_consistent(build_downcomer)
Exemple #3
0
def test_units(build_drum):
    assert_units_consistent(build_drum)
Exemple #4
0
def test_unit_consistency(boiler):
    assert_units_consistent(boiler)
Exemple #5
0
def add_costing(m):
    prtrt = m.fs.pretreatment
    desal = m.fs.desalination
    psttrt = m.fs.posttreatment

    # Add costing package for zero-order units
    m.fs.zo_costing = ZeroOrderCosting()
    m.fs.ro_costing = WaterTAPCosting()

    # Add costing to zero order units
    # Pre-treatment units
    # This really looks like it should be a feed block in its own right
    # prtrt.intake.costing = UnitModelCostingBlock(default={
    #     "flowsheet_costing_block": m.fs.zo_costing})

    prtrt.ferric_chloride_addition.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.chlorination.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.static_mixer.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.storage_tank_1.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.media_filtration.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.backwash_handling.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.anti_scalant_addition.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    prtrt.cartridge_filtration.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )

    # RO Train
    # RO equipment is costed using more detailed costing package
    desal.P1.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.ro_costing}
    )
    desal.RO.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.ro_costing}
    )
    if m.erd_type == "pressure_exchanger":
        # desal.S1.costing = UnitModelCostingBlock(default={
        #     "flowsheet_costing_block": m.fs.ro_costing})
        desal.M1.costing = UnitModelCostingBlock(
            default={"flowsheet_costing_block": m.fs.ro_costing}
        )
        desal.PXR.costing = UnitModelCostingBlock(
            default={"flowsheet_costing_block": m.fs.ro_costing}
        )
        desal.P2.costing = UnitModelCostingBlock(
            default={"flowsheet_costing_block": m.fs.ro_costing}
        )
    elif m.erd_type == "pump_as_turbine":
        pass
        # desal.ERD.costing = UnitModelCostingBlock(default={
        #     "flowsheet_costing_block": m.fs.ro_costing})
    else:
        raise ConfigurationError(
            f"erd_type was {m.erd_type}, costing only implemented "
            "for pressure_exchanger or pump_as_turbine"
        )

    # For non-zero order unit operations, we need to register costed flows
    # separately.
    # However, to keep costs consistent, we will register these with the ZO
    # Costing package
    m.fs.zo_costing.cost_flow(desal.P1.work_mechanical[0], "electricity")
    if m.erd_type == "pressure_exchanger":
        m.fs.zo_costing.cost_flow(desal.P2.work_mechanical[0], "electricity")
    elif m.erd_type == "pump_as_turbine":
        pass
        # m.fs.zo_costing.cost_flow(
        #     desal.ERD.work_mechanical[0], "electricity")
    else:
        raise ConfigurationError(
            f"erd_type was {m.erd_type}, costing only implemented "
            "for pressure_exchanger or pump_as_turbine"
        )

    # Post-treatment units
    psttrt.storage_tank_2.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    psttrt.uv_aop.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    psttrt.co2_addition.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    psttrt.lime_addition.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    psttrt.storage_tank_3.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )

    # Product and disposal
    m.fs.municipal.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )
    m.fs.landfill.costing = UnitModelCostingBlock(
        default={"flowsheet_costing_block": m.fs.zo_costing}
    )

    # Aggregate unit level costs and calculate overall process costs
    m.fs.zo_costing.cost_process()
    m.fs.ro_costing.cost_process()

    # Combine results from costing packages and calculate overall metrics
    @m.Expression()
    def total_capital_cost(b):
        return (
            pyunits.convert(
                m.fs.zo_costing.total_capital_cost, to_units=pyunits.USD_2018
            )
            + m.fs.ro_costing.total_investment_cost
        )

    @m.Expression()
    def total_operating_cost(b):
        return (
            pyunits.convert(
                m.fs.zo_costing.total_fixed_operating_cost,
                to_units=pyunits.USD_2018 / pyunits.year,
            )
            + pyunits.convert(
                m.fs.zo_costing.total_variable_operating_cost,
                to_units=pyunits.USD_2018 / pyunits.year,
            )
            + m.fs.ro_costing.total_operating_cost
        )

    @m.Expression()
    def LCOW(b):
        return (
            b.total_capital_cost * b.fs.zo_costing.capital_recovery_factor
            + b.total_operating_cost
        ) / (
            pyunits.convert(
                b.fs.municipal.properties[0].flow_vol,
                to_units=pyunits.m**3 / pyunits.year,
            )
            * b.fs.zo_costing.utilization_factor
        )

    assert_units_consistent(m)
Exemple #6
0
 def test_units_consistent(self, iron_oc):
     assert_units_consistent(iron_oc)
Exemple #7
0
 def test_units(self, iapws):
     assert_units_consistent(iapws)
     assert_units_equivalent(iapws.fs.unit.work_mechanical[0], units.W)
     assert_units_equivalent(iapws.fs.unit.deltaP[0], units.Pa)
Exemple #8
0
 def test_units_FcTP(self, btx_fctp):
     assert_units_consistent(btx_fctp)
Exemple #9
0
 def test_units(self, phe):
     assert_units_equivalent(phe.fs.unit.Re_hot[0], pyunits.dimensionless)
     assert_units_equivalent(phe.fs.unit.Re_cold[0], pyunits.dimensionless)
     assert_units_consistent(phe)
Exemple #10
0
    def test_build(self, system_frame):
        m = system_frame

        # model set up
        assert isinstance(m, ConcreteModel)
        assert isinstance(m.fs, FlowsheetBlock)
        assert isinstance(m.fs.properties, props.NaClParameterBlock)
        assert isinstance(m.fs.costing, Block)

        # unit models
        fs = m.fs
        assert isinstance(fs.feed, Feed)
        assert isinstance(fs.S1, Separator)
        assert isinstance(fs.P1, Pump)
        assert isinstance(fs.PXR, PressureExchanger)
        assert isinstance(fs.P2, Pump)
        assert isinstance(fs.M1, Mixer)
        assert isinstance(fs.RO, ReverseOsmosis0D)
        assert isinstance(fs.product, Product)
        assert isinstance(fs.disposal, Product)

        # unit model options
        # separator
        assert isinstance(fs.S1.P1, Port)
        assert isinstance(fs.S1.PXR, Port)
        # mixer
        assert isinstance(fs.M1.P1, Port)
        assert isinstance(fs.M1.P2, Port)
        assert isinstance(fs.M1.pressure_equality_constraints, Constraint)
        # RO
        assert isinstance(fs.RO.deltaP, Var)

        # additional expressions
        assert isinstance(fs.recovery, Expression)
        assert isinstance(fs.annual_water_production, Expression)
        assert isinstance(fs.specific_energy_consumption, Expression)

        # costing blocks
        blk_str_list = ['P1', 'P2', 'RO', 'PXR']
        for blk_str in blk_str_list:
            blk = getattr(fs, blk_str)
            c_blk = getattr(blk, 'costing')
            assert isinstance(c_blk, Block)
            assert isinstance(getattr(c_blk, 'capital_cost'), Var)
            assert isinstance(getattr(c_blk, 'operating_cost'), Var)

        var_str_list = [
            'capital_cost_total', 'investment_cost_total',
            'operating_cost_MLC', 'operating_cost_total', 'LCOW'
        ]
        for var_str in var_str_list:
            var = getattr(fs.costing, var_str)
            assert isinstance(var, Var)

        # arcs
        arc_dict = {
            fs.s01: (fs.feed.outlet, fs.S1.inlet),
            fs.s02: (fs.S1.P1, fs.P1.inlet),
            fs.s03: (fs.P1.outlet, fs.M1.P1),
            fs.s04: (fs.M1.outlet, fs.RO.inlet),
            fs.s05: (fs.RO.permeate, fs.product.inlet),
            fs.s06: (fs.RO.retentate, fs.PXR.high_pressure_inlet),
            fs.s07: (fs.PXR.high_pressure_outlet, fs.disposal.inlet),
            fs.s08: (fs.S1.PXR, fs.PXR.low_pressure_inlet),
            fs.s09: (fs.PXR.low_pressure_outlet, fs.P2.inlet),
            fs.s10: (fs.P2.outlet, fs.M1.P2)
        }
        for arc, port_tpl in arc_dict.items():
            assert arc.source is port_tpl[0]
            assert arc.destination is port_tpl[1]

        # units
        assert_units_consistent(fs)
Exemple #11
0
 def test_units_FTPz(self, btx_ftpz, btx_fctp):
     assert_units_consistent(btx_ftpz)
 def test_units(self, sapon):
     assert_units_consistent(sapon)
     assert_units_equivalent(sapon.fs.unit.heat_duty[0], units.W)
     assert_units_equivalent(sapon.fs.unit.deltaP[0], units.Pa)
Exemple #13
0
 def test_unit_consistency(self, frame):
     assert_units_consistent(frame)
Exemple #14
0
    def test_assert_units_consistent_equivalent(self):
        u = units
        m = ConcreteModel()
        m.dx = Var(units=u.m, initialize=0.10188943773836046)
        m.dy = Var(units=u.m, initialize=0.0)
        m.vx = Var(units=u.m / u.s, initialize=0.7071067769802851)
        m.vy = Var(units=u.m / u.s, initialize=0.7071067769802851)
        m.t = Var(units=u.min,
                  bounds=(1e-5, 10.0),
                  initialize=0.0024015570927624456)
        m.theta = Var(bounds=(0, 0.49 * 3.14),
                      initialize=0.7853981693583533,
                      units=u.radians)
        m.a = Param(initialize=-32.2, units=u.ft / u.s**2)
        m.x_unitless = Var()

        m.obj = Objective(expr=m.dx, sense=maximize)
        m.vx_con = Constraint(expr=m.vx == 1.0 * u.m / u.s * cos(m.theta))
        m.vy_con = Constraint(expr=m.vy == 1.0 * u.m / u.s * sin(m.theta))
        m.dx_con = Constraint(expr=m.dx == m.vx * u.convert(m.t, to_units=u.s))
        m.dy_con = Constraint(
            expr=m.dy == m.vy * u.convert(m.t, to_units=u.s) + 0.5 *
            (u.convert(m.a, to_units=u.m / u.s**2)) *
            (u.convert(m.t, to_units=u.s))**2)
        m.ground = Constraint(expr=m.dy == 0)
        m.unitless_con = Constraint(expr=m.x_unitless == 5.0)

        assert_units_consistent(m)  # check model
        assert_units_consistent(m.dx)  # check var - this should never fail
        assert_units_consistent(
            m.x_unitless)  # check unitless var - this should never fail
        assert_units_consistent(m.vx_con)  # check constraint
        assert_units_consistent(m.unitless_con)  # check unitless constraint

        assert_units_equivalent(m.dx, m.dy)  # check var
        assert_units_equivalent(m.x_unitless,
                                u.dimensionless)  # check unitless var
        assert_units_equivalent(m.x_unitless, None)  # check unitless var
        assert_units_equivalent(m.vx_con.body, u.m / u.s)  # check constraint
        assert_units_equivalent(m.unitless_con.body,
                                u.dimensionless)  # check unitless constraint
        assert_units_equivalent(m.dx, m.dy)  # check var
        assert_units_equivalent(m.x_unitless,
                                u.dimensionless)  # check unitless var
        assert_units_equivalent(m.x_unitless, None)  # check unitless var
        assert_units_equivalent(m.vx_con.body, u.m / u.s)  # check constraint

        m.broken = Constraint(expr=m.dy == 42.0 * u.kg)
        with self.assertRaises(UnitsError):
            assert_units_consistent(m)
        assert_units_consistent(m.dx)
        assert_units_consistent(m.vx_con)
        with self.assertRaises(UnitsError):
            assert_units_consistent(m.broken)

        self.assertTrue(check_units_equivalent(m.dx, m.dy))
        self.assertFalse(check_units_equivalent(m.dx, m.vx))
def test_unit_consistency(model):
    assert_units_consistent(model)
    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=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) == 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)
Exemple #17
0
 def test_units(self, sapon):
     assert_units_consistent(sapon)
     assert_units_equivalent(sapon.fs.unit.heat_duty[0], units.W)
     assert_units_equivalent(sapon.fs.unit.deltaP[0], units.Pa)
     assert_units_equivalent(sapon.fs.unit.rate_reaction_extent[0, "R1"],
                             units.mol / units.s)
Exemple #18
0
    def test_build(self):
        model = ConcreteModel()
        model.params = GenericParameterBlock(
            default=configuration_Dowling_2015)

        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

        assert 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)
        }

        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 == 33.943875e5
        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.737325e5
        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.45985e5
        assert model.params.oxygen.temperature_crit.value == 154.58

        assert_units_consistent(model)
Exemple #19
0
 def test_units(self, btx):
     assert_units_consistent(btx)
     assert_units_equivalent(btx.fs.unit.work_mechanical[0], units.W)
     assert_units_equivalent(btx.fs.unit.deltaP[0], units.Pa)
Exemple #20
0
def test_units_consistent():
    assert_units_consistent(m.fs)
    assert_units_consistent(m.fs1)
Exemple #21
0
 def test_units(self, sapon):
     assert_units_consistent(sapon)
     assert_units_equivalent(sapon.fs.unit.work_mechanical[0], units.W)
     assert_units_equivalent(sapon.fs.unit.deltaP[0], units.Pa)
Exemple #22
0
 def test_units(self, valve_model):
     assert_units_consistent(valve_model)
     assert_units_equivalent(valve_model.fs.valve.flow_var[0],
                             units.mol / units.s)
Exemple #23
0
def test_seawater_data():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={'dynamic': False})
    m.fs.properties = DSPMDEParameterBlock(
        default={
            "solute_list": ["Ca_2+", "SO4_2-", "Na_+", "Cl_-", "Mg_2+"],
            "diffusivity_data": {
                ("Liq", "Ca_2+"): 0.792e-9,
                ("Liq", "SO4_2-"): 1.06e-9,
                ("Liq", "Na_+"): 1.33e-9,
                ("Liq", "Cl_-"): 2.03e-9,
                ("Liq", "Mg_2+"): 0.706e-9
            },
            "mw_data": {
                "H2O": 18e-3,
                "Na_+": 23e-3,
                "Ca_2+": 40e-3,
                "Mg_2+": 24e-3,
                "Cl_-": 35e-3,
                "SO4_2-": 96e-3
            },
            "stokes_radius_data": {
                "Na_+": 0.184e-9,
                "Ca_2+": 0.309e-9,
                "Mg_2+": 0.347e-9,
                "Cl_-": 0.121e-9,
                "SO4_2-": 0.230e-9
            },
            "charge": {
                "Na_+": 1,
                "Ca_2+": 2,
                "Mg_2+": 2,
                "Cl_-": -1,
                "SO4_2-": -2
            },
        })

    m.fs.stream = stream = m.fs.properties.build_state_block(
        [0], default={'defined_state': True})

    mass_flow_in = 1 * pyunits.kg / pyunits.s
    feed_mass_frac = {
        'Na_+': 11122e-6,
        'Ca_2+': 382e-6,
        'Mg_2+': 1394e-6,
        'SO4_2-': 2136e-6,
        'Cl_-': 20300e-6
    }
    for ion, x in feed_mass_frac.items():
        mol_comp_flow = x * pyunits.kg / pyunits.kg * mass_flow_in / stream[
            0].mw_comp[ion]

        stream[0].flow_mol_phase_comp['Liq', ion].fix(mol_comp_flow)

    H2O_mass_frac = 1 - sum(x for x in feed_mass_frac.values())
    H2O_mol_comp_flow = H2O_mass_frac * pyunits.kg / pyunits.kg * mass_flow_in / stream[
        0].mw_comp['H2O']

    stream[0].flow_mol_phase_comp['Liq', 'H2O'].fix(H2O_mol_comp_flow)
    stream[0].temperature.fix(298.15)
    stream[0].pressure.fix(101325)

    stream[0].assert_electroneutrality(tol=1e-2)

    metadata = m.fs.properties.get_metadata().properties
    for v_name in metadata:
        getattr(stream[0], v_name)
    assert stream[0].is_property_constructed('conc_mol_phase_comp')

    assert_units_consistent(m)

    check_dof(m, fail_flag=True)

    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1,
                                        index=('Liq', 'H2O'))
    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1,
                                        index=('Liq', 'Na_+'))
    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1,
                                        index=('Liq', 'Cl_-'))
    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1e1,
                                        index=('Liq', 'Ca_2+'))
    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1e1,
                                        index=('Liq', 'SO4_2-'))
    m.fs.properties.set_default_scaling('flow_mol_phase_comp',
                                        1,
                                        index=('Liq', 'Mg_2+'))
    calculate_scaling_factors(m)

    # check if any variables are badly scaled
    badly_scaled_var_list = list(badly_scaled_var_generator(m))
    assert len(badly_scaled_var_list) == 0

    stream.initialize()

    # check if any variables are badly scaled
    badly_scaled_var_list = list(badly_scaled_var_generator(m))
    assert len(badly_scaled_var_list) == 0

    results = solver.solve(m)
    assert_optimal_termination(results)

    assert value(stream[0].flow_vol_phase['Liq']) == pytest.approx(0.001,
                                                                   rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq', 'H2O']) == pytest.approx(
        53.59256, rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq',
                                               'Na_+']) == pytest.approx(
                                                   0.4836, rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq',
                                               'Ca_2+']) == pytest.approx(
                                                   0.00955, rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq',
                                               'Mg_2+']) == pytest.approx(
                                                   0.05808, rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq',
                                               'Cl_-']) == pytest.approx(
                                                   0.58, rel=1e-3)
    assert value(stream[0].flow_mol_phase_comp['Liq',
                                               'SO4_2-']) == pytest.approx(
                                                   0.02225, rel=1e-3)
    assert value(stream[0].dens_mass_phase['Liq']) == pytest.approx(1000,
                                                                    rel=1e-3)
    assert value(stream[0].pressure_osm) == pytest.approx(28.593e5, rel=1e-3)
    assert value(stream[0].flow_vol) == pytest.approx(0.001, rel=1e-3)

    assert value(
        sum(stream[0].conc_mass_phase_comp['Liq', j]
            for j in m.fs.properties.solute_set)) == pytest.approx(35.334,
                                                                   rel=1e-3)
    assert value(
        sum(stream[0].mass_frac_phase_comp['Liq', j]
            for j in m.fs.properties.solute_set)) == pytest.approx(35334e-6,
                                                                   rel=1e-3)
    assert value(
        sum(stream[0].mass_frac_phase_comp['Liq', j]
            for j in m.fs.properties.component_list)) == pytest.approx(
                1, rel=1e-3)
    assert value(
        sum(stream[0].mole_frac_phase_comp['Liq', j]
            for j in m.fs.properties.component_list)) == pytest.approx(
                1, rel=1e-3)

    assert value(stream[0].conc_mol_phase_comp['Liq',
                                               'Na_+']) == pytest.approx(
                                                   483.565, rel=1e-3)
    assert value(stream[0].conc_mol_phase_comp['Liq',
                                               'Cl_-']) == pytest.approx(
                                                   580, rel=1e-3)
    assert value(stream[0].conc_mol_phase_comp['Liq',
                                               'Ca_2+']) == pytest.approx(
                                                   9.55, rel=1e-3)
    assert value(stream[0].conc_mol_phase_comp['Liq',
                                               'SO4_2-']) == pytest.approx(
                                                   22.25, rel=1e-3)
    assert value(stream[0].conc_mol_phase_comp['Liq',
                                               'Mg_2+']) == pytest.approx(
                                                   58.08, rel=1e-3)

    assert value(stream[0].conc_mass_phase_comp['Liq',
                                                'Na_+']) == pytest.approx(
                                                    11.122, rel=1e-3)
    assert value(stream[0].conc_mass_phase_comp['Liq',
                                                'Cl_-']) == pytest.approx(
                                                    20.3, rel=1e-3)
    assert value(stream[0].conc_mass_phase_comp['Liq',
                                                'Ca_2+']) == pytest.approx(
                                                    0.382, rel=1e-3)
    assert value(stream[0].conc_mass_phase_comp['Liq',
                                                'SO4_2-']) == pytest.approx(
                                                    2.136, rel=1e-3)
    assert value(stream[0].conc_mass_phase_comp['Liq',
                                                'Mg_2+']) == pytest.approx(
                                                    1.394, rel=1e-3)

    assert value(stream[0].mole_frac_phase_comp['Liq',
                                                'Na_+']) == pytest.approx(
                                                    8.833e-3, rel=1e-3)
    assert value(stream[0].mole_frac_phase_comp['Liq',
                                                'Cl_-']) == pytest.approx(
                                                    1.059e-2, rel=1e-3)
    assert value(stream[0].mole_frac_phase_comp['Liq',
                                                'Ca_2+']) == pytest.approx(
                                                    1.744e-4, rel=1e-3)
    assert value(stream[0].mole_frac_phase_comp['Liq',
                                                'SO4_2-']) == pytest.approx(
                                                    4.064e-4, rel=1e-3)
    assert value(stream[0].mole_frac_phase_comp['Liq',
                                                'Mg_2+']) == pytest.approx(
                                                    1.061e-3, rel=1e-3)

    assert value(stream[0].mass_frac_phase_comp['Liq',
                                                'Na_+']) == pytest.approx(
                                                    1.112e-2, rel=1e-3)
    assert value(stream[0].mass_frac_phase_comp['Liq',
                                                'Cl_-']) == pytest.approx(
                                                    2.03e-2, rel=1e-3)
    assert value(stream[0].mass_frac_phase_comp['Liq',
                                                'Ca_2+']) == pytest.approx(
                                                    3.82e-4, rel=1e-3)
    assert value(stream[0].mass_frac_phase_comp['Liq',
                                                'SO4_2-']) == pytest.approx(
                                                    2.136e-3, rel=1e-3)
    assert value(stream[0].mass_frac_phase_comp['Liq',
                                                'Mg_2+']) == pytest.approx(
                                                    1.394e-3, rel=1e-3)
Exemple #24
0
 def test_units(self, sapon):
     assert_units_consistent(sapon)
Exemple #25
0
 def test_units(self, model):
     assert_units_consistent(model)
     assert_units_equivalent(model.fs.unit.heat_duty[0], units.W)
Exemple #26
0
 def test_units(self, btx):
     assert_units_consistent(btx)
Exemple #27
0
 def test_unit_consistency(self, model):
     assert_units_consistent(model.fs.unit)
Exemple #28
0
 def test_units(self, iapws):
     assert_units_consistent(iapws)
    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

        assert 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)
        }

        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)
Exemple #30
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) == 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=_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) == 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)