Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in SmoothVLE2 initialization #1563

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ def calculate_teq(blk, pp):
vapor_phase,
raoult_comps,
henry_comps,
_,
l_only_comps,
v_only_comps,
) = identify_VL_component_list(blk, pp)

if v_only_comps is None:
if len(v_only_comps) == 0:
if blk.is_property_constructed("temperature_bubble"):
Tbub = value(blk.temperature_bubble[pp])
else:
Expand All @@ -258,7 +258,7 @@ def calculate_teq(blk, pp):
else:
t1 = value(blk.temperature)

if v_only_comps is None:
if len(l_only_comps) == 0:
if blk.is_property_constructed("temperature_dew"):
Tdew = value(blk.temperature_bubble[pp])
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
units as pyunits,
)

from idaes.core.base.phases import PhaseType
from idaes.core.util.exceptions import ConfigurationError

from idaes.models.properties.modular_properties.base.generic_property import (
GenericParameterBlock,
)
Expand All @@ -41,7 +44,8 @@
from idaes.models.properties.modular_properties.eos.ideal import Ideal
from idaes.models.properties.modular_properties.eos.ceos import Cubic, CubicType
from idaes.models.properties.modular_properties.phase_equil.forms import fugacity
from idaes.core.util.exceptions import ConfigurationError

from idaes.models.properties.modular_properties.pure.NIST import NIST


@pytest.mark.unit
Expand Down Expand Up @@ -339,3 +343,162 @@ def test_calculate_ceos_derivative_slacks(frame):

assert value(gp["Vap"]) == pytest.approx(EPS_INIT, abs=1e-8)
assert value(gn["Vap"]) == pytest.approx(EPS_INIT, abs=1e-8)


class TestWithNonCondensable:
# TODO These tests could be fleshed out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would this TODO entail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly adding in tests for the values of gp, gn, _teq, and other VLE variables both to make sure the model isn't changing and that the answer is reasonable. Right now, I'm testing that 1) the model initialization doesn't end up with an error and 2) bubble/dew points are not erroneously created.

@pytest.fixture()
def H2O_H2_model(self):
m = ConcreteModel()

# Create a dummy parameter block
m.params = GenericParameterBlock(
components={
"H2O": {
"parameter_data": {
"pressure_crit": (220.6e5, pyunits.Pa),
"temperature_crit": (647, pyunits.K),
"omega": 0.344,
"pressure_sat_comp_coeff": { # NIST <- Stull 1947
"A": 4.6543,
"B": 1435.264,
"C": -64.848,
},
},
"pressure_sat_comp": NIST,
"phase_equilibrium_form": {("Vap", "Liq"): fugacity},
},
"H2": {
"valid_phase_types": [PhaseType.vaporPhase],
"parameter_data": {
"pressure_crit": (13e5, pyunits.Pa),
"temperature_crit": (33.2, pyunits.K),
"omega": -0.218,
},
},
},
phases={
"Liq": {
"equation_of_state": Cubic,
"equation_of_state_options": {"type": CubicType.PR},
},
"Vap": {
"equation_of_state": Cubic,
"equation_of_state_options": {"type": CubicType.PR},
},
},
state_definition=FTPx,
pressure_ref=100000.0,
temperature_ref=300,
base_units={
"time": pyunits.s,
"length": pyunits.m,
"mass": pyunits.kg,
"amount": pyunits.mol,
"temperature": pyunits.K,
},
phases_in_equilibrium=[("Vap", "Liq")],
phase_equilibrium_state={("Vap", "Liq"): CubicComplementarityVLE},
parameter_data={
"PR_kappa": {
("H2O", "H2O"): 0.000,
("H2", "H2O"): 0.000,
("H2O", "H2"): 0.000,
("H2", "H2"): 0.000,
}
},
)

# Create a dummy state block
m.props = m.params.state_block_class([1], parameters=m.params)

return m

@pytest.mark.unit
def test_calculate_teq_permanent_gas(self, H2O_H2_model):
m = H2O_H2_model
m.props[1].pressure.set_value(1e5)
m.props[1].temperature.set_value(300)
CubicComplementarityVLE.calculate_teq(m.props[1], ("Vap", "Liq"))
assert not m.props[1].is_property_constructed("temperature_dew")
assert not m.props[1].is_property_constructed("temperature_bubble")


class TestWithNonVolatile:
# TODO These tests could be fleshed out
@pytest.fixture()
def H2O_TEG_model(self):
m = ConcreteModel()

# Create a dummy parameter block
m.params = GenericParameterBlock(
components={
"H2O": {
"parameter_data": {
"pressure_crit": (220.6e5, pyunits.Pa),
"temperature_crit": (647, pyunits.K),
"omega": 0.344,
"pressure_sat_comp_coeff": { # NIST <- Stull 1947
"A": 4.6543,
"B": 1435.264,
"C": -64.848,
},
},
"pressure_sat_comp": NIST,
"phase_equilibrium_form": {("Vap", "Liq"): fugacity},
},
"TEG": { # Triethylene Glycol
"valid_phase_types": [PhaseType.liquidPhase],
# Values from WolframAlpha
"parameter_data": {
"pressure_crit": (3.3e6, pyunits.Pa),
"temperature_crit": (797, pyunits.K),
"omega": 0.51,
},
},
},
phases={
"Liq": {
"equation_of_state": Cubic,
"equation_of_state_options": {"type": CubicType.PR},
},
"Vap": {
"equation_of_state": Cubic,
"equation_of_state_options": {"type": CubicType.PR},
},
},
state_definition=FTPx,
pressure_ref=100000.0,
temperature_ref=300,
base_units={
"time": pyunits.s,
"length": pyunits.m,
"mass": pyunits.kg,
"amount": pyunits.mol,
"temperature": pyunits.K,
},
phases_in_equilibrium=[("Vap", "Liq")],
phase_equilibrium_state={("Vap", "Liq"): CubicComplementarityVLE},
parameter_data={
"PR_kappa": {
("H2O", "H2O"): 0.000,
("TEG", "H2O"): 0.000,
("H2O", "TEG"): 0.000,
("TEG", "TEG"): 0.000,
}
},
)

# Create a dummy state block
m.props = m.params.state_block_class([1], parameters=m.params)

return m

@pytest.mark.unit
def test_calculate_teq_permanent_gas(self, H2O_TEG_model):
m = H2O_TEG_model
m.props[1].pressure.set_value(1e5)
m.props[1].temperature.set_value(300)
CubicComplementarityVLE.calculate_teq(m.props[1], ("Vap", "Liq"))
assert not m.props[1].is_property_constructed("temperature_dew")
assert not m.props[1].is_property_constructed("temperature_bubble")
Loading