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_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_parameter_block():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    m.fs.params = PropertyInterrogatorBlock()
    m.fs.rxn_params = ReactionInterrogatorBlock(
        default={"property_package": m.fs.params})

    # Check that parameter block has expected attributes
    assert isinstance(m.fs.rxn_params.required_properties, dict)
    assert len(m.fs.rxn_params.required_properties) == 0
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_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"]
    }
def test_interrogator_rxn_block_unindexed_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].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"]
    }