def test_compressor(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.properties = props.WaterParameterBlock() m.fs.compressor = Compressor(default={"property_package": m.fs.properties}) # m.fs.compressor.control_volume.display() # scaling m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Vap", "H2O")) m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) iscale.set_scaling_factor(m.fs.compressor.control_volume.work, 1e-6) iscale.calculate_scaling_factors(m) # state variables m.fs.compressor.inlet.flow_mass_phase_comp[0, "Vap", "H2O"].fix(1) m.fs.compressor.inlet.flow_mass_phase_comp[0, "Liq", "H2O"].fix(1e-8) m.fs.compressor.inlet.temperature[0].fix(350) # K m.fs.compressor.inlet.pressure[0].fix(0.5e5) # Pa # specifications m.fs.compressor.pressure_ratio.fix(2) m.fs.compressor.efficiency.fix(0.8) # check build assert_units_consistent(m) assert degrees_of_freedom(m) == 0 # initialize m.fs.compressor.initialize() # solve solver = get_solver() results = solver.solve(m, tee=False) assert_optimal_termination(results) assert pytest.approx(1.1534e5, rel=1e-4) == value( m.fs.compressor.control_volume.work[0] ) assert pytest.approx(1e-08, rel=1e-4) == value( m.fs.compressor.outlet.flow_mass_phase_comp[0, "Liq", "H2O"] ) assert pytest.approx(1.0, rel=1e-4) == value( m.fs.compressor.outlet.flow_mass_phase_comp[0, "Vap", "H2O"] ) assert pytest.approx(429.57, rel=1e-4) == value( m.fs.compressor.outlet.temperature[0] ) assert pytest.approx(1.0e5, rel=1e-4) == value(m.fs.compressor.outlet.pressure[0]) m.fs.compressor.report() perf_dict = m.fs.compressor._get_performance_contents() assert perf_dict == { "vars": { "Pressure ratio": m.fs.compressor.pressure_ratio, "Efficiency": m.fs.compressor.efficiency, "Work": m.fs.compressor.control_volume.work[0], } }
def test_complete_condense(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.properties = props.WaterParameterBlock() m.fs.unit = Condenser(default={"property_package": m.fs.properties}) # scaling m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Vap", "H2O")) m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) iscale.set_scaling_factor(m.fs.unit.control_volume.heat, 1e-6) iscale.calculate_scaling_factors(m) # state variables m.fs.unit.inlet.flow_mass_phase_comp[0, "Vap", "H2O"].fix(1) m.fs.unit.inlet.flow_mass_phase_comp[0, "Liq", "H2O"].fix(1e-8) m.fs.unit.inlet.temperature[0].fix(400) # K m.fs.unit.inlet.pressure[0].fix(0.5e5) # Pa m.fs.unit.outlet.temperature[0].fix(340) # K # solving assert_units_consistent(m) assert degrees_of_freedom(m) == 0 m.fs.unit.initialize() solver = get_solver() results = solver.solve(m, tee=False) assert_optimal_termination(results) report_io = StringIO() m.fs.unit.report(ostream=report_io) output = """ ==================================================================================== Unit : fs.unit Time: 0.0 ------------------------------------------------------------------------------------ Unit Performance Variables: Key : Value : Fixed : Bounds Heat duty : -2.4358e+06 : False : (None, None) ------------------------------------------------------------------------------------ Stream Table Inlet Outlet flow_mass_phase_comp ('Liq', 'H2O') 1.0000e-08 1.0000 flow_mass_phase_comp ('Vap', 'H2O') 1.0000 1.0000e-10 temperature 400.00 340.00 pressure 50000. 50000. ==================================================================================== """ assert output == report_io.getvalue()
def test_complete_condense(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.properties = props.WaterParameterBlock() m.fs.unit = Condenser(default={"property_package": m.fs.properties}) # scaling m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Vap", "H2O")) m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) iscale.set_scaling_factor(m.fs.unit.control_volume.heat, 1e-6) iscale.calculate_scaling_factors(m) # state variables m.fs.unit.inlet.flow_mass_phase_comp[0, "Vap", "H2O"].fix(1) m.fs.unit.inlet.flow_mass_phase_comp[0, "Liq", "H2O"].fix(1e-8) m.fs.unit.inlet.temperature[0].fix(400) # K m.fs.unit.inlet.pressure[0].fix(0.5e5) # Pa m.fs.unit.outlet.temperature[0].fix(340) # K # solving assert_units_consistent(m) assert degrees_of_freedom(m) == 0 m.fs.unit.initialize() solver = get_solver() results = solver.solve(m, tee=False) assert_optimal_termination(results) assert pytest.approx(-2.4358e6, rel=1e-4) == value(m.fs.unit.control_volume.heat[0]) assert pytest.approx(1.0, rel=1e-4) == value( m.fs.unit.outlet.flow_mass_phase_comp[0, "Liq", "H2O"]) assert pytest.approx(1e-10, rel=1e-4) == value( m.fs.unit.outlet.flow_mass_phase_comp[0, "Vap", "H2O"]) assert pytest.approx(5.0e4, rel=1e-4) == value(m.fs.unit.outlet.pressure[0]) m.fs.unit.report() perf_dict = m.fs.unit._get_performance_contents() assert perf_dict == { "vars": { "Heat duty": m.fs.unit.control_volume.heat[0] } }
def build(m): # Properties m.fs.properties_feed = props_sw.SeawaterParameterBlock() m.fs.properties_vapor = props_w.WaterParameterBlock() # Evaporator m.fs.evaporator = Evaporator( default={ "property_package_feed": m.fs.properties_feed, "property_package_vapor": m.fs.properties_vapor, }) # Compressor m.fs.compressor = Compressor( default={"property_package": m.fs.properties_vapor}) # Connections m.fs.s01 = Arc(source=m.fs.evaporator.outlet_vapor, destination=m.fs.compressor.inlet) m.fs.s02 = Arc(source=m.fs.compressor.outlet, destination=m.fs.evaporator.inlet_condenser) TransformationFactory("network.expand_arcs").apply_to(m)
def test_evaporator(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.properties_feed = props_sw.SeawaterParameterBlock() m.fs.properties_vapor = props_w.WaterParameterBlock() m.fs.evaporator = Evaporator( default={ "property_package_feed": m.fs.properties_feed, "property_package_vapor": m.fs.properties_vapor, }) # scaling m.fs.properties_feed.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) m.fs.properties_feed.set_default_scaling("flow_mass_phase_comp", 1e2, index=("Liq", "TDS")) m.fs.properties_vapor.set_default_scaling("flow_mass_phase_comp", 1, index=("Vap", "H2O")) m.fs.properties_vapor.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) iscale.set_scaling_factor(m.fs.evaporator.area, 1e-3) iscale.set_scaling_factor(m.fs.evaporator.U, 1e-3) iscale.set_scaling_factor(m.fs.evaporator.delta_temperature_in, 1e-1) iscale.set_scaling_factor(m.fs.evaporator.delta_temperature_out, 1e-1) iscale.set_scaling_factor(m.fs.evaporator.lmtd, 1e-1) # iscale.set_scaling_factor(m.fs.evaporator.heat_transfer, 1e-6) iscale.calculate_scaling_factors(m) # assert False # state variables # Feed inlet m.fs.evaporator.inlet_feed.flow_mass_phase_comp[0, "Liq", "H2O"].fix(10) m.fs.evaporator.inlet_feed.flow_mass_phase_comp[0, "Liq", "TDS"].fix(0.05) m.fs.evaporator.inlet_feed.temperature[0].fix(273.15 + 50.52) # K m.fs.evaporator.inlet_feed.pressure[0].fix(1e5) # Pa # Condenser inlet m.fs.evaporator.inlet_condenser.flow_mass_phase_comp[0, "Vap", "H2O"].fix(0.5) m.fs.evaporator.inlet_condenser.flow_mass_phase_comp[0, "Liq", "H2O"].fix(1e-8) m.fs.evaporator.inlet_condenser.temperature[0].fix(400) # K m.fs.evaporator.inlet_condenser.pressure[0].fix(0.5e5) # Pa # Evaporator/condenser specifications m.fs.evaporator.outlet_brine.temperature[0].fix(273.15 + 60) m.fs.evaporator.U.fix(1e3) # W/K-m^2 m.fs.evaporator.area.fix(100) # m^2 # check build assert_units_consistent(m) assert degrees_of_freedom(m) == 0 # initialize m.fs.evaporator.initialize() # solve solver = get_solver() results = solver.solve(m, tee=False) assert_optimal_termination(results) # check values, TODO: make a report for the evaporator # m.fs.evaporator.display() vapor_blk = m.fs.evaporator.feed_side.properties_vapor[0] assert vapor_blk.flow_mass_phase_comp["Vap", "H2O"].value == pytest.approx( 0.3540, rel=1e-3) assert m.fs.evaporator.lmtd.value == pytest.approx(12.30, rel=1e-3) assert m.fs.evaporator.feed_side.heat_transfer.value == pytest.approx( 1.230e6, rel=1e-3)
def test_compressor(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.properties = props.WaterParameterBlock() m.fs.compressor = Compressor(default={"property_package": m.fs.properties}) # m.fs.compressor.control_volume.display() # scaling m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Vap", "H2O")) m.fs.properties.set_default_scaling("flow_mass_phase_comp", 1, index=("Liq", "H2O")) iscale.set_scaling_factor(m.fs.compressor.control_volume.work, 1e-6) iscale.calculate_scaling_factors(m) # state variables m.fs.compressor.inlet.flow_mass_phase_comp[0, "Vap", "H2O"].fix(1) m.fs.compressor.inlet.flow_mass_phase_comp[0, "Liq", "H2O"].fix(1e-8) m.fs.compressor.inlet.temperature[0].fix(350) # K m.fs.compressor.inlet.pressure[0].fix(0.5e5) # Pa # specifications m.fs.compressor.pressure_ratio.fix(2) m.fs.compressor.efficiency.fix(0.8) # check build assert_units_consistent(m) assert degrees_of_freedom(m) == 0 # initialize m.fs.compressor.initialize() # solve solver = get_solver() results = solver.solve(m, tee=False) assert_optimal_termination(results) report_io = StringIO() m.fs.compressor.report(ostream=report_io) output = """ ==================================================================================== Unit : fs.compressor Time: 0.0 ------------------------------------------------------------------------------------ Unit Performance Variables: Key : Value : Fixed : Bounds Efficiency : 0.80000 : True : (1e-08, 1) Pressure ratio : 2.0000 : True : (1, 10) Work : 1.1534e+05 : False : (None, None) ------------------------------------------------------------------------------------ Stream Table Inlet Outlet flow_mass_phase_comp ('Liq', 'H2O') 1.0000e-08 1.0000e-08 flow_mass_phase_comp ('Vap', 'H2O') 1.0000 1.0000 temperature 350.00 429.57 pressure 50000. 1.0000e+05 ==================================================================================== """ assert output == report_io.getvalue()