Exemplo n.º 1
0
    def test_equality_constraint(self, model):
        sc.constraint_scaling_transform(model.c2, 1e-3)
        # Do transformation again to be sure that, despite being called twice in
        # a row, the transformation only happens once.
        sc.constraint_scaling_transform(model.c2, 1e-3)
        assert model.c2.lower.value == pytest.approx(1)
        assert model.c2.body() == pytest.approx(model.x.value / 1e3)
        assert model.c2.upper.value == pytest.approx(1)
        assert sc.get_constraint_transform_applied_scaling_factor(
            model.c2) is 1e-3

        # Check overwrite protection
        sc.constraint_scaling_transform(model.c2, 5, overwrite=False)
        assert model.c2.lower.value == pytest.approx(1)
        assert model.c2.body() == pytest.approx(model.x.value / 1e3)
        assert model.c2.upper.value == pytest.approx(1)
        assert sc.get_constraint_transform_applied_scaling_factor(
            model.c2) is 1e-3

        sc.constraint_scaling_transform_undo(model.c2)
        assert sc.get_constraint_transform_applied_scaling_factor(
            model.c2) is None
        assert model.c2.lower.value == pytest.approx(1e3)
        assert model.c2.body() == pytest.approx(model.x.value)
        assert model.c2.upper.value == pytest.approx(1e3)
    def test_scaling(self, model):
        iscale.calculate_scaling_factors(model)

        assert (
            iscale.get_constraint_transform_applied_scaling_factor(
                model.fs.unit.water_recovery_equation[0]
            )
            == 1e5
        )
        assert (
            iscale.get_constraint_transform_applied_scaling_factor(
                model.fs.unit.mass_balance[0]
            )
            == 1e5
        )
        assert (
            iscale.get_constraint_transform_applied_scaling_factor(
                model.fs.unit.solute_removal_equation[0, "cod"]
            )
            == 1e5
        )
        assert (
            iscale.get_constraint_transform_applied_scaling_factor(
                model.fs.unit.solute_treated_equation[0, "cod"]
            )
            == 1e5
        )
Exemplo n.º 3
0
    def test_scaling(self, model):
        iscale.set_scaling_factor(
            model.fs.unit.liquid_phase.properties_out[0].fug_phase_comp[
                "Liq", "CO2"], 1e-5)
        iscale.set_scaling_factor(
            model.fs.unit.liquid_phase.properties_out[0].fug_phase_comp[
                "Liq", "H2O"], 1e-3)

        iscale.calculate_scaling_factors(model.fs.unit)

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_material_balance[0, "CO2"]) == 1
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_material_balance[0, "H2O"]) == 1
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_material_balance[0, "MEA"]) is None
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_material_balance[0, "N2"]) == 1e8
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_material_balance[0, "O2"]) == 1e8

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_phase_equilibrium[0, "CO2"]) == 1e-5
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_phase_equilibrium[0, "H2O"]) == 1e-3

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_temperature_equality[0]) == 1e-2

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_enthalpy_balance[0]) == 1

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.unit_pressure_balance[0]) == 1e-5
Exemplo n.º 4
0
    def test_scaling(self, model):
        iscale.calculate_scaling_factors(model)

        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.water_recovery_equation[0]) == 1e5
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.solute_treated_equation[0, "A"]) == 1e5
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.solute_treated_equation[0, "B"]) == 1e5
        assert iscale.get_constraint_transform_applied_scaling_factor(
            model.fs.unit.solute_treated_equation[0, "C"]) == 1e5
def test_base_build():
    m = pyo.ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    m.fs.pp = PhysicalParameterTestBlock()
    m.fs.cv = ControlVolume1DBlock(
        default={
            "property_package": m.fs.pp,
            "transformation_method": "dae.finite_difference",
            "transformation_scheme": "BACKWARD",
            "finite_elements": 10,
        })
    m.fs.cv.add_geometry()
    m.fs.cv.add_state_blocks(has_phase_equilibrium=False)
    m.fs.cv.add_material_balances(
        balance_type=MaterialBalanceType.componentTotal,
        has_phase_equilibrium=False)
    m.fs.cv.add_energy_balances(balance_type=EnergyBalanceType.enthalpyTotal,
                                has_heat_transfer=True,
                                has_work_transfer=True)
    # add momentum balance
    m.fs.cv.add_momentum_balances(
        balance_type=MomentumBalanceType.pressureTotal,
        has_pressure_change=True)

    m.fs.cv.apply_transformation()

    # The scaling factors used for this test were selected to be easy values to
    # test, they do not represent typical scaling factors.
    iscale.set_scaling_factor(m.fs.cv.heat, 11)
    iscale.set_scaling_factor(m.fs.cv.work, 12)
    iscale.calculate_scaling_factors(m)
    # Make sure the heat and work scaling factors are set and not overwitten
    # by the defaults in calculate_scaling_factors
    for (t, x), v in m.fs.cv.heat.items():
        assert iscale.get_scaling_factor(v) == 11
    for (t, x), v in m.fs.cv.work.items():
        assert iscale.get_scaling_factor(v) == 12

    # Didn't specify a deltaP scaling factor, so by default pressure in scaling
    # factor * 10 is used.
    for v in m.fs.cv.deltaP.values():  #deltaP is time indexed
        assert iscale.get_scaling_factor(v) == 1040

    # check scaling on mass, energy, and pressure balances.
    for c in m.fs.cv.material_balances.values():
        # this uses the minmum material flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 112
    for c in m.fs.cv.enthalpy_balances.values():
        # this uses the minmum enthalpy flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 110
    for c in m.fs.cv.pressure_balance.values():
        # This uses the inlet pressure scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 104
Exemplo n.º 6
0
def test_basic_scaling():
    m = pyo.ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    m.fs.pp = PhysicalParameterTestBlock()
    # Set flag to include inherent reactions
    m.fs.pp._has_inherent_reactions = True

    m.fs.cv = ControlVolume1DBlock(
        default={
            "property_package": m.fs.pp,
            "transformation_method": "dae.finite_difference",
            "transformation_scheme": "BACKWARD",
            "finite_elements": 10
        })

    m.fs.cv.add_geometry()
    m.fs.cv.add_state_blocks(has_phase_equilibrium=False)

    m.fs.cv.add_material_balances(
        balance_type=MaterialBalanceType.componentTotal,
        has_phase_equilibrium=False)

    m.fs.cv.add_energy_balances(balance_type=EnergyBalanceType.enthalpyTotal)

    m.fs.cv.add_momentum_balances(
        balance_type=MomentumBalanceType.pressureTotal,
        has_pressure_change=True)

    m.fs.cv.apply_transformation()

    iscale.calculate_scaling_factors(m)

    # check scaling on select variables
    assert iscale.get_scaling_factor(m.fs.cv.area) == 1
    for (t, x), v in m.fs.cv.deltaP.items():
        assert iscale.get_scaling_factor(
            v) == 1040  # 10x the properties pressure scaling factor
    for t in m.fs.time:
        for x in m.fs.cv.length_domain:
            assert iscale.get_scaling_factor(
                m.fs.cv.properties[t, x].flow_vol) == 100

    # check scaling on mass, energy, and pressure balances.
    for c in m.fs.cv.material_balances.values():
        # this uses the minimum material flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 112
    for c in m.fs.cv.enthalpy_balances.values():
        # this uses the minimum enthalpy flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 110
    for c in m.fs.cv.pressure_balance.values():
        # This uses the inlet pressure scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 104
def test_basic_scaling():
    m = pyo.ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    m.fs.pp = PhysicalParameterTestBlock()
    # Set flag to include inherent reactions
    m.fs.pp._has_inherent_reactions = True

    m.fs.cv = ControlVolume0DBlock(default={"property_package": m.fs.pp})

    m.fs.cv.add_geometry()
    m.fs.cv.add_state_blocks(has_phase_equilibrium=False)

    m.fs.cv.add_material_balances(
        balance_type=MaterialBalanceType.componentTotal,
        has_phase_equilibrium=False)

    m.fs.cv.add_energy_balances(
        balance_type=EnergyBalanceType.enthalpyTotal)

    m.fs.cv.add_momentum_balances(
        balance_type=MomentumBalanceType.pressureTotal,
        has_pressure_change=True)

    iscale.calculate_scaling_factors(m)

    # check scaling on select variables
    assert iscale.get_scaling_factor(m.fs.cv.volume[0]) == 1e-2
    assert iscale.get_scaling_factor(
        m.fs.cv.deltaP[0]) == 1040  # 10x the properties pressure scaling factor
    assert iscale.get_scaling_factor(m.fs.cv.properties_in[0].flow_vol) == 100

    # check scaling on mass, energy, and pressure balances.
    for c in m.fs.cv.material_balances.values():
        # this uses the minimum material flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 112
    for c in m.fs.cv.enthalpy_balances.values():
        # this uses the minimum enthalpy flow term scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 110
    for c in m.fs.cv.pressure_balance.values():
        # This uses the inlet pressure scale
        assert iscale.get_constraint_transform_applied_scaling_factor(c) == 104