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

ASM2d/ADM1 Translator Update #1315

Merged
merged 13 commits into from
Feb 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ Equations and Relationships
"S_PO4 concentration", ":math:`S_{PO4, 3} = S_{PO4, 2} + (S_{F, in} * i_{PSF})`"
"S_IC concentration", ":math:`S_{IC, 3} = S_{IC, 2} + (S_{F, in} * i_{CSF}) - (S_{su} * Ci[S_{su}] * 1000 * 12) - (S_{aa} * Ci[S_{aa}] * 1000 * 12)`"

Equations and Relationships (With Decay)
----------------------------------------
Equations and Relationships (with biological phosphorus removal)
Copy link
Contributor

Choose a reason for hiding this comment

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

So is Decay omitted for the time being or is it somewhere else in this file and associated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use of the word decay was inaccurate to begin with. That is entirely handled in the reaction package (depending on whether the DecaySwitch is on(True) or off (False). Not sure if that answers your question...

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it- the decay switch isn't applied in the translator but is applied in the reaction package. Thanks!

----------------------------------------------------------------

.. csv-table::
:header: "Description", "Equation"
Expand Down Expand Up @@ -150,8 +150,8 @@ Equations and Relationships (With Decay)
"S_K concentration", ":math:`S_{K, 6} = S_{K, in} + (K_{XPP} * X_{PP, in})`"
"S_Mg concentration", ":math:`S_{Mg, 6} = S_{Mg, in} + (Mg_{XPP} * X_{PP, in})`"

Equations and Relationships (Without Decay)
-------------------------------------------
Equations and Relationships (without biological phosphorus removal)
-------------------------------------------------------------------

.. csv-table::
:header: "Description", "Equation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

# Import Pyomo libraries
import pyomo.environ as pyo
from pyomo.common.config import ConfigValue, In

from enum import Enum, auto
from pyomo.common.config import Bool, ConfigValue

# Import IDAES cores
from idaes.core import (
Expand All @@ -48,11 +46,6 @@
_log = idaeslog.getLogger(__name__)


class DecaySwitch(Enum):
on = auto()
off = auto()


@declare_process_block_class("ModifiedASM2dReactionParameterBlock")
class ModifiedASM2dReactionParameterData(ReactionParameterBlock):
"""
Expand All @@ -64,20 +57,14 @@ class ModifiedASM2dReactionParameterData(ReactionParameterBlock):
CONFIG.declare(
"decay_switch",
ConfigValue(
default=DecaySwitch.on,
domain=In(DecaySwitch),
default=True,
domain=Bool,
description="Switching function for decay",
doc="""
Switching function for handling decay in reaction rate expressions.

**default** - `DecaySwitch.on``

.. csv-table::
:header: "Configuration Options", "Description"

"``DecaySwitch.on``", "The decay of heterotrophs and autotrophs is dependent on the electron acceptor present"
"``DecaySwitch.off``", "The decay of heterotrophs and autotrophs does not change"
""",
doc="""Switching function for handling decay in reaction rate expressions,
**default** - True.
**Valid values:** {
**True** - the decay of heterotrophs and autotrophs is dependent on the electron acceptor present,
**False** - the decay of heterotrophs and autotrophs does not change""",
Copy link
Contributor

Choose a reason for hiding this comment

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

@MarcusHolly Does this need to be updated on the technical ref ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is updated automatically
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspected this but didn't check if any manually written description conflicted with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The manual descriptions of decay are all still accurate I believe.

),
)

Expand Down Expand Up @@ -1268,7 +1255,7 @@ def rate_expression_rule(b, r):
)
elif r == "R9":
# R9: Lysis
if self.params.config.decay_switch == DecaySwitch.on:
if self.params.config.decay_switch:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_H
* (
Expand All @@ -1283,7 +1270,7 @@ def rate_expression_rule(b, r):
* b.conc_mass_comp_ref["X_H"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif self.params.config.decay_switch == DecaySwitch.off:
else:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_H * b.conc_mass_comp_ref["X_H"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
Expand Down Expand Up @@ -1436,7 +1423,7 @@ def rate_expression_rule(b, r):
)
elif r == "R15":
# R15: Lysis of X_PAO
if self.params.config.decay_switch == DecaySwitch.on:
if self.params.config.decay_switch:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PAO
* (
Expand All @@ -1451,14 +1438,14 @@ def rate_expression_rule(b, r):
* b.conc_mass_comp_ref["X_PAO"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif self.params.config.decay_switch == DecaySwitch.off:
else:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PAO * b.conc_mass_comp_ref["X_PAO"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif r == "R16":
# R16: Lysis of X_PP
if self.params.config.decay_switch == DecaySwitch.on:
if self.params.config.decay_switch:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PP
* (
Expand All @@ -1473,14 +1460,14 @@ def rate_expression_rule(b, r):
* b.conc_mass_comp_ref["X_PP"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif self.params.config.decay_switch == DecaySwitch.off:
else:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PP * b.conc_mass_comp_ref["X_PP"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif r == "R17":
# R17: Lysis of X_PHA
if self.params.config.decay_switch == DecaySwitch.on:
if self.params.config.decay_switch:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PHA
* (
Expand All @@ -1495,7 +1482,7 @@ def rate_expression_rule(b, r):
* b.conc_mass_comp_ref["X_PHA"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif self.params.config.decay_switch == DecaySwitch.off:
else:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_PHA * b.conc_mass_comp_ref["X_PHA"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
Expand All @@ -1521,7 +1508,7 @@ def rate_expression_rule(b, r):
)
elif r == "R19":
# R19: Aerobic growth of X_AUT
if self.params.config.decay_switch == DecaySwitch.on:
if self.params.config.decay_switch:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_AUT
* (
Expand All @@ -1536,7 +1523,7 @@ def rate_expression_rule(b, r):
* b.conc_mass_comp_ref["X_AUT"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
)
elif self.params.config.decay_switch == DecaySwitch.off:
else:
return b.reaction_rate[r] == pyo.units.convert(
b.params.b_AUT * b.conc_mass_comp_ref["X_AUT"],
to_units=pyo.units.kg / pyo.units.m**3 / pyo.units.s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from idaes.core.util.testing import initialization_tester

from watertap.unit_models.translators.translator_asm2d_adm1 import Translator_ASM2d_ADM1

from watertap.property_models.anaerobic_digestion.modified_adm1_properties import (
ModifiedADM1ParameterBlock,
)
Expand All @@ -58,7 +59,6 @@

from watertap.property_models.activated_sludge.modified_asm2d_reactions import (
ModifiedASM2dReactionParameterBlock,
DecaySwitch,
)

from pyomo.util.check_units import assert_units_consistent
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_config():
outlet_state_defined=True,
)

assert len(m.fs.unit.config) == 12
assert len(m.fs.unit.config) == 13

assert m.fs.unit.config.outlet_state_defined == True
assert not m.fs.unit.config.dynamic
Expand All @@ -105,7 +105,7 @@ def test_config():


# -----------------------------------------------------------------------------
class TestAsm2dAdm1_decay_on(object):
class TestAsm2dAdm1_bioP_true(object):
@pytest.fixture(scope="class")
def asmadm(self):
m = ConcreteModel()
Expand All @@ -119,7 +119,6 @@ def asmadm(self):
)
m.fs.ASM2d_rxn_props = ModifiedASM2dReactionParameterBlock(
property_package=m.fs.props_ASM2d,
decay_switch=DecaySwitch.on,
)

m.fs.unit = Translator_ASM2d_ADM1(
Expand All @@ -129,6 +128,7 @@ def asmadm(self):
outlet_reaction_package=m.fs.ADM1_rxn_props,
has_phase_equilibrium=False,
outlet_state_defined=True,
bio_P=True,
)

m.fs.unit.inlet.flow_vol.fix(18446 * units.m**3 / units.day)
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_conservation(self, asmadm):


# -----------------------------------------------------------------------------
class TestAsm2dAdm1_decay_off(object):
class TestAsm2dAdm1_bioP_false(object):
@pytest.fixture(scope="class")
def asmadm(self):
m = ConcreteModel()
Expand All @@ -406,7 +406,6 @@ def asmadm(self):
)
m.fs.ASM2d_rxn_props = ModifiedASM2dReactionParameterBlock(
property_package=m.fs.props_ASM2d,
decay_switch=DecaySwitch.off,
)

m.fs.unit = Translator_ASM2d_ADM1(
Expand All @@ -416,6 +415,7 @@ def asmadm(self):
outlet_reaction_package=m.fs.ADM1_rxn_props,
has_phase_equilibrium=False,
outlet_state_defined=True,
bio_P=False,
)

m.fs.unit.inlet.flow_vol.fix(18446 * units.m**3 / units.day)
Expand Down
Loading
Loading