def test_vol_mol_phase_no_methods(m): with pytest.raises(ConfigurationError, match="does not have a method defined to use when " "calculating molar volume and density for component a " "in phase liq. Each component must define a method for " "either vol_mol_liq_comp or dens_mol_liq_comp."): Ideal.vol_mol_phase(m.props[1], "Liq")
def test_vol_mol_phase(): m = ConcreteModel() # Dummy params block m.params = DummyParameterBlock( default={ "components": { "a": { "dens_mol_liq_comp": dummy_call }, "b": { "dens_mol_liq_comp": dummy_call }, "c": { "vol_mol_liq_comp": dummy_call } }, "phases": { "Vap": { "type": VaporPhase, "equation_of_state": Ideal }, "Liq": { "type": LiquidPhase, "equation_of_state": Ideal } }, "base_units": { "time": pyunits.s, "length": pyunits.m, "mass": pyunits.kg, "amount": pyunits.mol, "temperature": pyunits.K }, "state_definition": modules[__name__], "pressure_ref": 1e5, "temperature_ref": 300 }) m.props = m.params.state_block_class([1], default={ "defined_state": False, "parameters": m.params }) # Add common variables m.props[1].pressure = Var(initialize=101325) m.props[1].temperature = Var(initialize=300, units=pyunits.K) m.props[1]._teq = Var([("Vap", "Liq")], initialize=300) m.props[1].mole_frac_phase_comp = Var(m.params.phase_list, m.params.component_list, initialize=0.5) for p in m.params.phase_list: if p == "Vap": assert str(Ideal.vol_mol_phase( m.props[1], p)) == ("kg*m**2/J/s**2*(8.314462618*(J)/mol/K)*" "props[1].temperature/props[1].pressure") else: assert str(Ideal.vol_mol_phase(m.props[1], p)) == str( 1 / 42 * m.props[1].mole_frac_phase_comp["Liq", "a"] + 1 / 42 * m.props[1].mole_frac_phase_comp["Liq", "b"] + 42 * m.props[1].mole_frac_phase_comp["Liq", "c"])