Skip to content
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
113 changes: 68 additions & 45 deletions idaes/models/properties/modular_properties/base/generic_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,10 @@ def initialize(
# For systems where the state variables fully define the
# phase equilibrium, we cannot activate the equilibrium
# constraint at this stage.
if "flow_mol_phase_comp" not in b.define_state_vars():
if (
"flow_mol_phase_comp" not in b.define_state_vars()
and "mole_frac_phase_comp" not in b.define_state_vars()
):
c.activate()

for pp in b.params._pe_pairs:
Expand Down Expand Up @@ -2858,21 +2861,27 @@ def build(self):
self.params.config.state_definition.define_state(self)

# Add equilibrium temperature variable if required
if self.params.config.phases_in_equilibrium is not None and (
not self.config.defined_state or self.always_flash
):

t_units = self.params.get_metadata().default_units.TEMPERATURE
if self.temperature.value is not None:
t_value = value(self.temperature)
if self.params.config.phases_in_equilibrium is not None:
if self.always_flash:
has_phase_equilibrium = True
elif self.config.defined_state:
has_phase_equilibrium = False
else:
t_value = None
self._teq = Var(
self.params._pe_pairs,
initialize=t_value,
doc="Temperature for calculating phase equilibrium",
units=t_units,
)
has_phase_equilibrium = self.config.has_phase_equilibrium

if has_phase_equilibrium:
t_units = self.params.get_metadata().default_units.TEMPERATURE
if self.temperature.value is not None:
t_value = value(self.temperature)
else:
t_value = None
self._teq = Var(
self.params._pe_pairs,
initialize=t_value,
doc="Temperature for calculating phase equilibrium",
units=t_units,
bounds=self.temperature.bounds,
)

# Create common components for each property package
for p in self.phase_list:
Expand All @@ -2888,37 +2897,42 @@ def enth_mol_eqn(b):
b.enth_mol_phase[p] * b.phase_frac[p] for p in b.phase_list
)

# Add phase equilibrium constraints if necessary
if self.params.config.phases_in_equilibrium is not None and (
not self.config.defined_state or self.always_flash
):
if self.params.config.phases_in_equilibrium is not None:
if self.always_flash:
has_phase_equilibrium = True
elif self.config.defined_state:
has_phase_equilibrium = False
else:
has_phase_equilibrium = self.config.has_phase_equilibrium

pe_form_config = self.params.config.phase_equilibrium_state
for pp in self.params._pe_pairs:
pe_form_config[pp].phase_equil(self, pp)

def rule_equilibrium(b, phase1, phase2, j):
if (phase1, j) not in b.phase_component_set or (
phase2,
j,
) not in b.phase_component_set:
return Constraint.Skip
config = b.params.get_component(j).config
try:
e_mthd = config.phase_equilibrium_form[
(phase1, phase2)
].return_expression
except KeyError:
e_mthd = config.phase_equilibrium_form[
(phase2, phase1)
].return_expression
if e_mthd is None:
raise GenericPropertyPackageError(b, "phase_equilibrium_form")
return e_mthd(self, phase1, phase2, j)
if has_phase_equilibrium:

self.equilibrium_constraint = Constraint(
self.params._pe_pairs, self.component_list, rule=rule_equilibrium
)
pe_form_config = self.params.config.phase_equilibrium_state
for pp in self.params._pe_pairs:
pe_form_config[pp].phase_equil(self, pp)

def rule_equilibrium(b, phase1, phase2, j):
if (phase1, j) not in b.phase_component_set or (
phase2,
j,
) not in b.phase_component_set:
return Constraint.Skip
config = b.params.get_component(j).config
try:
e_mthd = config.phase_equilibrium_form[
(phase1, phase2)
].return_expression
except KeyError:
e_mthd = config.phase_equilibrium_form[
(phase2, phase1)
].return_expression
if e_mthd is None:
raise GenericPropertyPackageError(b, "phase_equilibrium_form")
return e_mthd(self, phase1, phase2, j)

self.equilibrium_constraint = Constraint(
self.params._pe_pairs, self.component_list, rule=rule_equilibrium
)

# Add inherent reaction constraints if necessary
if self.params.has_inherent_reactions and (
Expand Down Expand Up @@ -5503,12 +5517,15 @@ def _temperature_pressure_bubble_dew(b, name):
abbrv = "t" + abbrv
bounds = (b.temperature.lb, b.temperature.ub)
units = b.params.get_metadata().default_units.TEMPERATURE
init = b.temperature.value
elif splt[0] == "pressure":
abbrv = "p" + abbrv
bounds = (b.pressure.lb, b.pressure.ub)
units_meta = b.params.get_metadata().derived_units
units = units_meta.PRESSURE
init = b.pressure.value
else:
init = None
_raise_dev_burnt_toast()

docstring_var += splt[0]
Expand All @@ -5521,7 +5538,13 @@ def _temperature_pressure_bubble_dew(b, name):
setattr(
b,
name,
Var(b.params._pe_pairs, doc=docstring_var, bounds=bounds, units=units),
Var(
b.params._pe_pairs,
doc=docstring_var,
bounds=bounds,
initialize=init,
units=units,
),
)
setattr(
b,
Expand Down
Loading
Loading