def model(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": True}) m.fs.params = PropertyInterrogatorBlock() m.fs.P01 = PressureChanger( default={ "property_package": m.fs.params, "thermodynamic_assumption": ThermodynamicAssumption.isentropic }) m.fs.HX02 = HeatExchanger1D( default={ "shell_side": { "property_package": m.fs.params }, "tube_side": { "property_package": m.fs.params } }) m.fs.F03 = Flash(default={"property_package": m.fs.params}) return m
def test_interrogator_rxn_block_comp_call(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.rxn_params = ReactionInterrogatorBlock( default={"property_package": m.fs.params}) m.fs.props = m.fs.params.state_block_class( [0], default={"parameters": m.fs.params}) m.fs.rxns = m.fs.rxn_params.reaction_block_class([0], default={ "parameters": m.fs.rxn_params, "state_block": m.fs.props }) # Check get_term methods return an unindexed dummy var assert m.fs.rxns[0].prop_comp["A"] is \ m.fs.rxns[0]._dummy_var_comp["A"] assert m.fs.rxns[0].prop_comp["B"] is \ m.fs.rxns[0]._dummy_var_comp["B"] # Check that get_term calls were logged correctly assert m.fs.rxn_params.required_properties == {"prop_comp": ["fs.rxns"]}
def test_interrogator_initialize_method(): # Initialize method should return an TypeError m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.rxn_params = ReactionInterrogatorBlock( default={"property_package": m.fs.params}) m.fs.props = m.fs.params.state_block_class( [0], default={"parameters": m.fs.params}) m.fs.rxns = m.fs.rxn_params.reaction_block_class([0], default={ "parameters": m.fs.rxn_params, "state_block": m.fs.props }) with pytest.raises(TypeError, match="Models constructed using the Reaction " "Interrogator package cannot be used to solve a " "flowsheet. Please rebuild your flowsheet using a " "valid reaction package."): m.fs.rxns.initialize()
def test_interrogator_state_block_methods(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.props = m.fs.params.build_state_block([0]) # Check get_term methods return an unindexed dummy var assert m.fs.props[0].get_material_flow_terms("Liq", "A") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_enthalpy_flow_terms("Liq") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_material_density_terms("Liq", "A") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_energy_density_terms("Liq") is \ m.fs.props[0]._dummy_var # Check that get_term calls were logged correctly assert m.fs.params.required_properties == { "material flow terms": ["fs.props"], "material density terms": ["fs.props"], "enthalpy flow terms": ["fs.props"], "energy density terms": ["fs.props"] }
def test_interrogator_state_block_methods_custom_phase_comps(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock( default={ "phase_list": { "P1": LiquidPhase, "P2": None }, "component_list": { "c1": Solute, "c2": None } }) m.fs.props = m.fs.params.build_state_block([0]) # Check get_term methods return an unindexed dummy var assert m.fs.props[0].get_material_flow_terms("P1", "c1") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_enthalpy_flow_terms("P1") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_material_density_terms("P1", "c1") is \ m.fs.props[0]._dummy_var assert m.fs.props[0].get_energy_density_terms("P1") is \ m.fs.props[0]._dummy_var # Check that get_term calls were logged correctly assert m.fs.params.required_properties == { "material flow terms": ["fs.props"], "material density terms": ["fs.props"], "enthalpy flow terms": ["fs.props"], "energy density terms": ["fs.props"] }
def test_interrogator_parameter_block(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() # Check that parameter block has expected attributes assert isinstance(m.fs.params.required_properties, dict) assert len(m.fs.params.required_properties) == 0
def test_units_metadata(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() units_meta = m.fs.params.get_metadata().get_derived_units assert_units_equivalent(units_meta('length'), pyunits.m) assert_units_equivalent(units_meta('pressure'), pyunits.Pa)
def test_interrogator_parameter_block_custom_phase_error(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) with pytest.raises(ConfigurationError, match="fs.params invalid phase type foo \(for phase " "P1\). Type must be a subclass of Phase."): m.fs.params = PropertyInterrogatorBlock( default={"phase_list": { "P1": "foo", "P2": None }})
def test_interrogator_parameter_block_custom_comp_error(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) with pytest.raises(ConfigurationError, match="fs.params invalid component type foo \(for " "component c1\). Type must be a subclass of " "Component."): m.fs.params = PropertyInterrogatorBlock( default={"component_list": { "c1": "foo", "c2": None }})
def test_interrogator_report_method(): # Display method should return an TypeError m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.props = m.fs.params.build_state_block([0]) with pytest.raises(TypeError, match="Models constructed using the Property " "Interrogator package should not be used for report " "methods."): m.fs.props.report()
def test_interrogator_initialize_method(): # Initialize method should return an TypeError m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.props = m.fs.params.build_state_block([0]) with pytest.raises(TypeError, match="Models constructed using the Property " "Interrogator package cannot be used to solve a " "flowsheet. Please rebuild your flowsheet using a " "valid property package."): m.fs.props.initialize()
def test_interrogator_state_block_phase_call(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.props = m.fs.params.build_state_block([0]) # Check get_term methods return an unindexed dummy var assert m.fs.props[0].prop_phase["Liq"] is \ m.fs.props[0]._dummy_var_phase["Liq"] assert m.fs.props[0].prop_phase["Vap"] is \ m.fs.props[0]._dummy_var_phase["Vap"] # Check that get_term calls were logged correctly assert m.fs.params.required_properties == {"prop_phase": ["fs.props"]}
def test_interrogator_state_block_unindexed_call(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.props = m.fs.params.build_state_block([0]) # Check get_term methods return an unindexed dummy var assert m.fs.props[0].prop_unindexed is \ m.fs.props[0]._dummy_var # Call again to make sure duplicates are skipped in required_properties assert m.fs.props[0].prop_unindexed is \ m.fs.props[0]._dummy_var # Check that get_term calls were logged correctly assert m.fs.params.required_properties == {"prop_unindexed": ["fs.props"]}
def test_Separator_3(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.S01 = Separator( default={ "property_package": m.fs.params, "material_balance_type": MaterialBalanceType.componentPhase, "split_basis": SplittingType.componentFlow, "outlet_list": ["a", "B", "c"], "ideal_separation": False, "has_phase_equilibrium": False }) assert len(m.fs.params.required_properties) == 3 for k in m.fs.params.required_properties.keys(): assert k in ["material flow terms", "pressure", "temperature"]
def test_interrogator_rxn_block_dh_rxn_call(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.rxn_params = ReactionInterrogatorBlock( default={"property_package": m.fs.params}) m.fs.props = m.fs.params.build_state_block([0]) m.fs.rxns = m.fs.rxn_params.build_reaction_block( [0], default={"state_block": m.fs.props}) # Check get_term methods return an unindexed dummy var assert m.fs.rxns[0].dh_rxn["R1"] is \ m.fs.rxns[0]._dummy_reaction_idx["R1"] assert m.fs.rxns[0].dh_rxn["R1"] is \ m.fs.rxns[0]._dummy_reaction_idx["R1"] # Check that get_term calls were logged correctly assert m.fs.rxn_params.required_properties == {"dh_rxn": ["fs.rxns"]}
def model(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": True}) m.fs.params = PropertyInterrogatorBlock() m.fs.rxn_params = ReactionInterrogatorBlock( default={"property_package": m.fs.params}) m.fs.R01 = CSTR( default={ "property_package": m.fs.params, "reaction_package": m.fs.rxn_params, "has_heat_of_reaction": True }) m.fs.R02 = PFR(default={ "property_package": m.fs.params, "reaction_package": m.fs.rxn_params }) return m
def test_ideal_Separator_3(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock() m.fs.S01 = Separator( default={ "property_package": m.fs.params, "num_outlets": 2, "ideal_separation": True, "split_basis": SplittingType.componentFlow, "ideal_split_map": { ("A"): "outlet_1", ("B"): "outlet_2" } }) # Ideal Separator should require no property calls # Only dummy state variables are required assert len(m.fs.params.required_properties) == 0
def test_interrogator_parameter_block_custom_phase_comps(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock( default={ "phase_list": { "P1": LiquidPhase, "P2": None }, "component_list": { "c1": Solute, "c2": None } }) # Check that parameter block has expected attributes assert isinstance(m.fs.params.required_properties, dict) assert len(m.fs.params.required_properties) == 0 assert m.fs.params.phase_list == ["P1", "P2"] assert m.fs.params.component_list == ["c1", "c2"]
def test_interrogator_rxn_block_unindexed_call_custom_phase_comp(): m = ConcreteModel() m.fs = FlowsheetBlock(default={"dynamic": False}) m.fs.params = PropertyInterrogatorBlock( default={ "phase_list": { "P1": LiquidPhase, "P2": None }, "component_list": { "c1": Solute, "c2": None } }) m.fs.rxn_params = ReactionInterrogatorBlock( default={"property_package": m.fs.params}) m.fs.props = m.fs.params.build_state_block([0]) m.fs.rxns = m.fs.rxn_params.build_reaction_block( [0], default={"state_block": m.fs.props}) # Check phase and component lists assert m.fs.rxn_params.phase_list == ["P1", "P2"] assert m.fs.rxn_params.component_list == ["c1", "c2"] # Check get_term methods return an unindexed dummy var assert m.fs.rxns[0].prop_unindexed is \ m.fs.rxns[0]._dummy_var # Call again to make sure duplicates are skipped in required_properties assert m.fs.rxns[0].prop_unindexed is \ m.fs.rxns[0]._dummy_var # Check that get_term calls were logged correctly assert m.fs.rxn_params.required_properties == { "prop_unindexed": ["fs.rxns"] }