Esempio n. 1
0
def test_build():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.ideal = BTXParameterBlock()
    m.fs.sap = SaponificationParameterBlock()

    m.fs.trans = Translator(default={
        "inlet_property_package": m.fs.ideal,
        "outlet_property_package": m.fs.sap
    })

    assert hasattr(m.fs.trans, "inlet")
    assert len(m.fs.trans.inlet.vars) == 4
    assert hasattr(m.fs.trans.inlet, "flow_mol")
    assert hasattr(m.fs.trans.inlet, "mole_frac")
    assert hasattr(m.fs.trans.inlet, "temperature")
    assert hasattr(m.fs.trans.inlet, "pressure")

    assert hasattr(m.fs.trans, "outlet")
    assert len(m.fs.trans.outlet.vars) == 4
    assert hasattr(m.fs.trans.outlet, "flow_vol")
    assert hasattr(m.fs.trans.outlet, "conc_mol_comp")
    assert hasattr(m.fs.trans.outlet, "temperature")
    assert hasattr(m.fs.trans.outlet, "pressure")
Esempio n. 2
0
def test_initialize():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = BTXParameterBlock()

    m.fs.ff = FeedFlash(default={"property_package": m.fs.properties})

    m.fs.ff.flow_mol.fix(1)
    m.fs.ff.temperature.fix(368)
    m.fs.ff.pressure.fix(101325)
    m.fs.ff.mole_frac[0, "benzene"].fix(0.5)
    m.fs.ff.mole_frac[0, "toluene"].fix(0.5)

    assert degrees_of_freedom(m) == 0

    m.fs.ff.initialize(outlvl=5, optarg={'tol': 1e-6})

    assert (pytest.approx(101325.0,
                          abs=1e3) == m.fs.ff.outlet.pressure[0].value)
    assert (pytest.approx(368.00,
                          abs=1e-0) == m.fs.ff.outlet.temperature[0].value)
    assert (pytest.approx(1.0, abs=1e-2) == m.fs.ff.outlet.flow_mol[0].value)
    assert (pytest.approx(0.355, abs=1e-3) == m.fs.ff.control_volume.
            properties_out[0].flow_mol_phase["Vap"].value)
Esempio n. 3
0
    def btx(self):
        m = ConcreteModel()
        m.fs = FlowsheetBlock(default={"dynamic": False})

        m.fs.properties = BTXParameterBlock()

        m.fs.unit = Flash(default={"property_package": m.fs.properties})

        return m
Esempio n. 4
0
    def btx(self):
        m = ConcreteModel()
        m.fs = FlowsheetBlock(default={"dynamic": False})

        m.fs.properties = BTXParameterBlock(default={"valid_phase": 'Liq'})

        m.fs.unit = HX1D(default={
                "shell_side": {"property_package": m.fs.properties},
                "tube_side": {"property_package": m.fs.properties},
                "flow_type": HeatExchangerFlowPattern.countercurrent})

        return m
Esempio n. 5
0
def test_build():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = BTXParameterBlock()

    m.fs.ff = FeedFlash(default={"property_package": m.fs.properties})

    assert hasattr(m.fs.ff, "flow_mol")
    assert hasattr(m.fs.ff, "mole_frac")
    assert hasattr(m.fs.ff, "temperature")
    assert hasattr(m.fs.ff, "pressure")

    assert hasattr(m.fs.ff, "outlet")
    assert len(m.fs.ff.outlet.vars) == 4
    assert hasattr(m.fs.ff.outlet, "flow_mol")
    assert hasattr(m.fs.ff.outlet, "mole_frac")
    assert hasattr(m.fs.ff.outlet, "temperature")
    assert hasattr(m.fs.ff.outlet, "pressure")

    assert hasattr(m.fs.ff, "isothermal")
Esempio n. 6
0
def test_config_validation():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = BTXParameterBlock(default={"valid_phase": 'Liq'})

    with pytest.raises(ConfigurationError):
        m.fs.HX_co_current = HX1D(
            default={"shell_side": {"property_package": m.fs.properties,
                                    "transformation_scheme": "BACKWARD"},
                     "tube_side": {"property_package": m.fs.properties,
                                   "transformation_scheme": "FORWARD"},
                     "flow_type": HeatExchangerFlowPattern.cocurrent})

    with pytest.raises(ConfigurationError):
        m.fs.HX_counter_current = HX1D(
            default={"shell_side": {"property_package": m.fs.properties,
                                    "transformation_method":
                                    "dae.finite_difference"},
                     "tube_side": {"property_package": m.fs.properties,
                                   "transformation_method":
                                   "dae.collocation"},
                     "flow_type": HeatExchangerFlowPattern.countercurrent})
Esempio n. 7
0
from idaes.ui.report import degrees_of_freedom

# -----------------------------------------------------------------------------
# See if ipopt is available and set up solver
if SolverFactory('ipopt').available():
    solver = SolverFactory('ipopt')
    solver.options = {'tol': 1e-6, 'mu_init': 1e-8, 'bound_push': 1e-8}
else:
    solver = None

# -----------------------------------------------------------------------------
# Create a flowsheet for test
m = ConcreteModel()
m.fs = FlowsheetBlock(default={"dynamic": False})

m.fs.properties = BTXParameterBlock(default={"valid_phase": ('Liq', 'Vap')})
m.fs.flash = FL(default={"property_package": m.fs.properties})


def test_build():
    assert len(m.fs.flash.config) == 9
    assert not m.fs.flash.config.has_holdup
    assert m.fs.flash.config.material_balance_type == \
        MaterialBalanceType.componentPhase
    assert m.fs.flash.config.energy_balance_type == \
        EnergyBalanceType.enthalpyTotal
    assert m.fs.flash.config.momentum_balance_type == \
        MomentumBalanceType.pressureTotal
    assert m.fs.flash.config.has_heat_transfer
    assert m.fs.flash.config.has_pressure_change
Esempio n. 8
0
# See if ipopt is available and set up solver
if SolverFactory('ipopt').available():
    solver = SolverFactory('ipopt')
    solver.options = {'tol': 1e-6,
                      'mu_init': 1e-8,
                      'bound_push': 1e-8}
else:
    solver = None

# -----------------------------------------------------------------------------
m = ConcreteModel()
# Create a flowsheet object to test inlet state blocks
m.fs = FlowsheetBlock(default={"dynamic": False})

# vapor-liquid
m.fs.properties_vl = BTXParameterBlock(default={"valid_phase":
                                       ('Liq', 'Vap')})
m.fs.state_block_vl = m.fs.properties_vl.state_block_class(
    default={"parameters": m.fs.properties_vl,
             "defined_state": True})

# liquid only
m.fs.properties_l = BTXParameterBlock(default={"valid_phase": 'Liq'})
m.fs.state_block_l = m.fs.properties_l.state_block_class(
    default={"parameters": m.fs.properties_l,
             "has_phase_equilibrium": False,
             "defined_state": True})

# vapor only
m.fs.properties_v = BTXParameterBlock(default={"valid_phase": 'Vap'})
m.fs.state_block_v = m.fs.properties_v.state_block_class(
    default={"parameters": m.fs.properties_v,
from idaes.core.util.exceptions import ConfigurationError

# -----------------------------------------------------------------------------
# See if ipopt is available and set up solver
if SolverFactory('ipopt').available():
    solver = SolverFactory('ipopt')
    solver.options = {'tol': 1e-6, 'mu_init': 1e-8, 'bound_push': 1e-8}
else:
    solver = None

# -----------------------------------------------------------------------------
# Create a flowsheet for test
m = ConcreteModel()
m.fs = FlowsheetBlock(default={"dynamic": False})

m.fs.properties = BTXParameterBlock(default={"valid_phase": 'Liq'})

# Default options
m.fs.HX_co_current = HX1D(
    default={
        "shell_side": {
            "property_package": m.fs.properties
        },
        "tube_side": {
            "property_package": m.fs.properties
        },
        "flow_type": HeatExchangerFlowPattern.cocurrent
    })
# Default options
m.fs.HX_counter_current = HX1D(
    default={