Skip to content

Commit

Permalink
Fix issue with enthalpy based states trying to use EoS before constru…
Browse files Browse the repository at this point in the history
…ction (#1505)
  • Loading branch information
andrewlee94 authored Oct 18, 2024
1 parent 0e05ed1 commit 2515fe8
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,15 @@ def build(self):
pobj = self.params.get_phase(p)
pobj.config.equation_of_state.common(self, pobj)

# Check to see if state definition uses enthalpy
if self.is_property_constructed("enth_mol"):
# State definition uses enthalpy, need to add constraint on phase enthalpies
@self.Constraint(doc="Total molar enthalpy mixing rule")
def enth_mol_eqn(b):
return b.enth_mol == sum(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def energy_internal_mol_phase_comp(b, p, j):

@staticmethod
def enth_mol_phase(b, p):
return 1e2 * b.temperature
return 1e2 * pyunits.J / pyunits.mol / pyunits.K * b.temperature

@staticmethod
def enth_mol_phase_comp(b, p, j):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ def flow_mol_phase_comp_rule(b, p, j):
expr=1 == sum(b.mole_frac_comp[i] for i in b.component_list)
)

def rule_enth_mol(b):
return b.enth_mol == sum(
b.enth_mol_phase[p] * b.phase_frac[p] for p in b.phase_list
)

b.enth_mol_eq = Constraint(
rule=rule_enth_mol, doc="Total molar enthalpy mixing rule"
)

if len(b.phase_list) == 1:

def rule_total_mass_balance(b):
Expand Down Expand Up @@ -451,7 +442,7 @@ def calculate_scaling_factors(b):
b.sum_mole_frac_out, min(sf_mf.values()), overwrite=False
)

iscale.constraint_scaling_transform(b.enth_mol_eq, sf_h, overwrite=False)
iscale.constraint_scaling_transform(b.enth_mol_eqn, sf_h, overwrite=False)

if len(b.phase_list) == 1:
iscale.constraint_scaling_transform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ def rule_mole_frac_comp(b, j):

b.mole_frac_comp_eq = Constraint(b.component_list, rule=rule_mole_frac_comp)

def rule_enth_mol(b):
return b.enth_mol == sum(
b.enth_mol_phase[p] * b.phase_frac[p] for p in b.phase_list
)

b.enth_mol_eq = Constraint(
rule=rule_enth_mol, doc="Total molar enthalpy mixing rule"
)

if len(b.phase_list) == 1:

def rule_total_mass_balance(b):
Expand Down Expand Up @@ -456,7 +447,7 @@ def calculate_scaling_factors(b):
b.mole_frac_comp_eq[j], sf_j, overwrite=False
)

iscale.constraint_scaling_transform(b.enth_mol_eq, sf_h, overwrite=False)
iscale.constraint_scaling_transform(b.enth_mol_eqn, sf_h, overwrite=False)

if len(b.phase_list) == 1:
iscale.constraint_scaling_transform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
pytestmark = pytest.mark.unit


# Note: The state definition is set by importing functions for the relevant module above
@declare_process_block_class("DummyParameterBlock")
class DummyParameterData(GenericParameterData):
pass
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_mole_frac(self, caplog):

class Test1PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -263,7 +264,7 @@ def test_constraints(self, frame):

class Test1PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -389,7 +390,7 @@ def test_constraints(self, frame):

class Test2PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -551,7 +552,7 @@ def test_constraints(self, frame):

class Test2PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -712,7 +713,7 @@ def test_constraints(self, frame):

class Test3PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -862,7 +863,7 @@ def test_constraints(self, frame):

class Test3PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -1020,7 +1021,7 @@ def test_constraints(self, frame):


class TestCommon(object):
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import idaes.logger as idaeslog


# Note: The state definition is set by importing functions for the relevant module above
@declare_process_block_class("DummyParameterBlock")
class DummyParameterData(GenericParameterData):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import idaes.logger as idaeslog


# Note: The state definition is set by importing functions for the relevant module above
@declare_process_block_class("DummyParameterBlock")
class DummyParameterData(GenericParameterData):
pass
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_mole_frac(self, caplog):

class Test1PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -276,7 +277,7 @@ def test_constraints(self, frame):

class Test1PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -429,7 +430,7 @@ def test_constraints(self, frame):

class Test2PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -600,7 +601,7 @@ def test_constraints(self, frame):

class Test2PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -788,7 +789,7 @@ def test_constraints(self, frame):

class Test3PhaseDefinedStateFalseNoBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -947,7 +948,7 @@ def test_constraints(self, frame):

class Test3PhaseDefinedStateTrueWithBounds(object):
# Test define_state method with no bounds and defined_State = False
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down Expand Up @@ -1121,7 +1122,7 @@ def test_constraints(self, frame):


class TestCommon(object):
@pytest.fixture(scope="class")
@pytest.fixture()
def frame(self):
m = ConcreteModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import idaes.logger as idaeslog


# Note: The state definition is set by importing functions for the relevant module above
@declare_process_block_class("DummyParameterBlock")
class DummyParameterData(GenericParameterData):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from idaes.core.util.model_statistics import degrees_of_freedom, large_residuals_set


# Note: The state definition is set by importing functions for the relevant module above
@declare_process_block_class("DummyParameterBlock")
class DummyParameterData(GenericParameterData):
pass
Expand Down

0 comments on commit 2515fe8

Please sign in to comment.