Пример #1
0
def test_config():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = PhysicalParameterTestBlock()

    m.fs.unit = HeatExchanger(
        default={
            "shell": {
                "property_package": m.fs.properties
            },
            "tube": {
                "property_package": m.fs.properties
            }
        })

    # Check unit config arguments
    # There are 8 to 10 arguments since you can add a side 1 and 2 config by
    # side_1, side_2, or whatever the user named them
    assert len(m.fs.unit.config) >= 8 and len(m.fs.unit.config) <= 10

    assert not m.fs.unit.config.dynamic
    assert not m.fs.unit.config.has_holdup
    assert isinstance(m.fs.unit.config.shell, ConfigBlock)
    assert isinstance(m.fs.unit.config.tube, ConfigBlock)
    assert m.fs.unit.config.delta_temperature_callback is \
        delta_temperature_lmtd_callback
    assert m.fs.unit.config.flow_pattern == \
        HeatExchangerFlowPattern.countercurrent

    # Check shell config
    assert len(m.fs.unit.config.shell) == 7
    assert m.fs.unit.config.shell.material_balance_type == \
        MaterialBalanceType.useDefault
    assert m.fs.unit.config.shell.energy_balance_type == \
        EnergyBalanceType.useDefault
    assert m.fs.unit.config.shell.momentum_balance_type == \
        MomentumBalanceType.pressureTotal
    assert not m.fs.unit.config.shell.has_phase_equilibrium
    assert not m.fs.unit.config.shell.has_pressure_change
    assert m.fs.unit.config.shell.property_package is m.fs.properties

    # Check tube config
    assert len(m.fs.unit.config.tube) == 7
    assert m.fs.unit.config.tube.material_balance_type == \
        MaterialBalanceType.useDefault
    assert m.fs.unit.config.tube.energy_balance_type == \
        EnergyBalanceType.useDefault
    assert m.fs.unit.config.tube.momentum_balance_type == \
        MomentumBalanceType.pressureTotal
    assert not m.fs.unit.config.tube.has_phase_equilibrium
    assert not m.fs.unit.config.tube.has_pressure_change
    assert m.fs.unit.config.tube.property_package is m.fs.properties
Пример #2
0
def test_config():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = PhysicalParameterTestBlock()

    m.fs.unit = HeatExchanger(
        default={
            "side_1": {
                "property_package": m.fs.properties
            },
            "side_2": {
                "property_package": m.fs.properties
            }
        })

    # Check unit config arguments
    assert len(m.fs.unit.config) == 6

    assert not m.fs.unit.config.dynamic
    assert not m.fs.unit.config.has_holdup
    assert isinstance(m.fs.unit.config.side_1, ConfigBlock)
    assert isinstance(m.fs.unit.config.side_2, ConfigBlock)
    assert m.fs.unit.config.delta_temperature_callback is \
        delta_temperature_lmtd_callback
    assert m.fs.unit.config.flow_pattern == \
        HeatExchangerFlowPattern.countercurrent

    # Check side_1 config
    assert len(m.fs.unit.config.side_1) == 7
    assert m.fs.unit.config.side_1.material_balance_type == \
        MaterialBalanceType.componentPhase
    assert m.fs.unit.config.side_1.energy_balance_type == \
        EnergyBalanceType.enthalpyTotal
    assert m.fs.unit.config.side_1.momentum_balance_type == \
        MomentumBalanceType.pressureTotal
    assert not m.fs.unit.config.side_1.has_phase_equilibrium
    assert not m.fs.unit.config.side_1.has_pressure_change
    assert m.fs.unit.config.side_1.property_package is m.fs.properties

    # Check side_2 config
    assert len(m.fs.unit.config.side_2) == 7
    assert m.fs.unit.config.side_2.material_balance_type == \
        MaterialBalanceType.componentPhase
    assert m.fs.unit.config.side_2.energy_balance_type == \
        EnergyBalanceType.enthalpyTotal
    assert m.fs.unit.config.side_2.momentum_balance_type == \
        MomentumBalanceType.pressureTotal
    assert not m.fs.unit.config.side_2.has_phase_equilibrium
    assert not m.fs.unit.config.side_2.has_pressure_change
    assert m.fs.unit.config.side_2.property_package is m.fs.properties
Пример #3
0
    def sapon(self):
        m = ConcreteModel()
        m.fs = FlowsheetBlock(default={"dynamic": False})

        m.fs.properties = SaponificationParameterBlock()

        m.fs.unit = HeatExchanger(
            default={
                "shell": {
                    "property_package": m.fs.properties
                },
                "tube": {
                    "property_package": m.fs.properties
                },
                "flow_pattern": HeatExchangerFlowPattern.crossflow
            })

        return m
Пример #4
0
    def iapws(self):
        m = ConcreteModel()
        m.fs = FlowsheetBlock(default={"dynamic": False})

        m.fs.properties = iapws95.Iapws95ParameterBlock()

        m.fs.unit = HeatExchanger(
            default={
                "shell": {
                    "property_package": m.fs.properties
                },
                "tube": {
                    "property_package": m.fs.properties
                },
                "flow_pattern": HeatExchangerFlowPattern.countercurrent
            })

        return m
Пример #5
0
    def btx(self):
        m = ConcreteModel()
        m.fs = FlowsheetBlock(default={"dynamic": False})

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

        m.fs.unit = HeatExchanger(
            default={
                "shell": {
                    "property_package": m.fs.properties
                },
                "tube": {
                    "property_package": m.fs.properties
                },
                "flow_pattern": HeatExchangerFlowPattern.cocurrent
            })

        return m
Пример #6
0
def test_costing():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.properties = iapws95.Iapws95ParameterBlock()

    m.fs.unit = HeatExchanger(
        default={
            "shell": {
                "property_package": m.fs.properties
            },
            "tube": {
                "property_package": m.fs.properties
            },
            "flow_pattern": HeatExchangerFlowPattern.countercurrent
        })
    #   Set inputs
    m.fs.unit.inlet_1.flow_mol[0].fix(100)
    m.fs.unit.inlet_1.enth_mol[0].fix(4000)
    m.fs.unit.inlet_1.pressure[0].fix(101325)

    m.fs.unit.inlet_2.flow_mol[0].fix(100)
    m.fs.unit.inlet_2.enth_mol[0].fix(3500)
    m.fs.unit.inlet_2.pressure[0].fix(101325)

    m.fs.unit.area.fix(1000)
    m.fs.unit.overall_heat_transfer_coefficient.fix(100)

    assert degrees_of_freedom(m) == 0

    m.fs.unit.initialize()

    m.fs.unit.get_costing()
    calculate_variable_from_constraint(m.fs.unit.costing.base_cost,
                                       m.fs.unit.costing.base_cost_eq)

    calculate_variable_from_constraint(m.fs.unit.costing.purchase_cost,
                                       m.fs.unit.costing.cp_cost_eq)

    results = solver.solve(m)
    assert m.fs.unit.costing.purchase_cost.value == \
                                            pytest.approx(52442.7363,1e-5)
Пример #7
0
def test_same_name():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    with pytest.raises(NameError):
        m.fs.unit = HeatExchanger(default={"cold_side_name": "shell"})
Пример #8
0
def test_bad_option():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    with pytest.raises(KeyError):
        m.fs.unit = HeatExchanger(default={"I'm a bad option": "hot"})