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

BSM2 full flowsheet #1038

Merged
merged 84 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
557d05e
dewtering unit model
Apr 20, 2023
7407aed
Merge branch 'watertap-org:main' into dewatering
agarciadiego Apr 20, 2023
68c0eac
removing imports
Apr 20, 2023
5f4828c
black
Apr 20, 2023
3e72529
black and doc error
Apr 21, 2023
c60a871
testing scaling
Apr 21, 2023
8e2d74f
pylint errors 1
Apr 21, 2023
b594424
change blk to self
Apr 21, 2023
157dff9
pylint errors 2
Apr 21, 2023
a63274c
adding test and list error
Apr 25, 2023
9d6b6fc
thickener unit model
Apr 25, 2023
5dadf22
unit consistency check
Apr 25, 2023
265e414
Merge branch 'main' into dewatering
agarciadiego Apr 25, 2023
5b164da
applying comments
Apr 26, 2023
3fad339
fix typo
Apr 27, 2023
87ed9d4
fix typo 2
Apr 27, 2023
757a094
Update watertap/unit_models/thickener.py
agarciadiego Apr 27, 2023
ee1d1de
Update watertap/unit_models/dewatering.py
agarciadiego Apr 27, 2023
366e5bf
chaine unit name in tests
Apr 27, 2023
fe75437
changing class name
Apr 27, 2023
5156ca9
cleanup unused imports and add time index to TSS in dewaterer
adam-a-a Apr 27, 2023
b2627fd
remove unused imports from test_dewatering
adam-a-a Apr 27, 2023
84585e5
more cleanup
adam-a-a Apr 27, 2023
bcb7440
BSM2 full flowsheet
May 22, 2023
1c9cdbd
gettting branch up-to-date
May 22, 2023
d7d74fd
rewriting flowsheet
May 23, 2023
0b3fedf
commenting translator error
May 24, 2023
04767d1
import and prop cleanup
May 24, 2023
a1e51d3
fixing failed import
May 24, 2023
b03fdbb
fiing import
agarciadiego May 25, 2023
38278a9
Merge branch 'dewatering' of https://github.com/agarciadiego/watertap…
agarciadiego May 25, 2023
d4e810e
fixing expresions that give values below 0
agarciadiego May 29, 2023
4ea2049
Merge branch 'main' of https://github.com/watertap-org/watertap into …
agarciadiego May 29, 2023
2b386e8
Merge branch 'watertap-org:main' into dewatering
agarciadiego May 29, 2023
33ef52e
Merge branch 'dewatering' of https://github.com/agarciadiego/watertap…
agarciadiego May 29, 2023
3462c51
changing to smooth max
agarciadiego Jun 2, 2023
b505ae3
fixing smooth max
agarciadiego Jun 2, 2023
fe71b3a
fixing units error
agarciadiego Jun 2, 2023
94c253b
uncommenting einitialization error
agarciadiego Jun 2, 2023
8a7fd52
starting to review and debug
adam-a-a Jun 16, 2023
56cb35a
Merge branch 'upmain' into issue934dewatering
Jul 5, 2023
0da8a32
Correct unit convertion, bar to Pa
Jul 6, 2023
f126d92
Revised AD model that reproduce results from the paper
Jul 19, 2023
d7035c4
Add domains to avoid evaluation of log(negative)
Jul 19, 2023
7fef06e
Update ADM1 flowsheet test to be consistent with the paper
Jul 19, 2023
5c1dafd
Update temprature bounds and intial values
Jul 24, 2023
d3eccda
Merge branch 'upmain' into issue934dewatering
Jul 24, 2023
c8682b1
BSM2 flowsheet pass with uniform temperature
Jul 26, 2023
d49e553
merging conlfict
agarciadiego Jul 26, 2023
64b0ebe
Modify models to use default solver options in BSM2 flowsheet, pass
Jul 26, 2023
7386f46
Update tests
Jul 26, 2023
d480ba5
Merge branch 'dewatering' into issue934dewatering
agarciadiego Jul 26, 2023
54233be
Merge pull request #1 from lxhowl/issue934dewatering
agarciadiego Jul 26, 2023
b9c0ed7
Update ASM model variations and translators
Jul 28, 2023
54f094d
Update ADM model variation and tests
Jul 28, 2023
c29e058
Merge branch 'main' of https://github.com/watertap-org/watertap into …
agarciadiego Jul 28, 2023
277b3ce
deleteing old files and rearranging
agarciadiego Jul 28, 2023
28bdf74
running black
agarciadiego Jul 28, 2023
acff3ef
deleting unused imports
agarciadiego Jul 28, 2023
d234765
thermo vapor test
agarciadiego Jul 28, 2023
a31e480
Merge commit 'c29e058a81ac179e2c2e90e41d0988b843e4bc7c' into issue934…
Jul 31, 2023
9256f98
Merge commit '277b3cea57e9981a3838852a88a93d75183d1290' into issue934…
Jul 31, 2023
9c4f74b
Merge commit 'acff3ef4871dd2738889d97c179d6054aad064ec' into issue934…
Jul 31, 2023
4fada63
Run black and update electroNP flowsheet used AD
Jul 31, 2023
d22c6cb
Merge pull request #3 from lxhowl/issue934dewatering
agarciadiego Jul 31, 2023
040f03b
skip mac test
agarciadiego Aug 1, 2023
bd92e1d
Merge branch 'main' into dewatering
agarciadiego Aug 9, 2023
f511281
decoopling PRs
agarciadiego Aug 11, 2023
be043a2
Merge branch 'dewatering' of https://github.com/agarciadiego/watertap…
agarciadiego Aug 11, 2023
c5fcd6c
changing translator and test
agarciadiego Aug 11, 2023
43920cc
changing names of bsm2 test
agarciadiego Aug 11, 2023
478854d
Merge branch 'dewatering' of https://github.com/agarciadiego/watertap…
adam-a-a Aug 14, 2023
a7437ab
run black and remove some unused imports
adam-a-a Aug 14, 2023
9bdd2f1
cleanup more unused imports on ASM_ADM_integration
adam-a-a Aug 14, 2023
688b1b2
rename BSM2 flowsheet and test
adam-a-a Aug 14, 2023
d58d035
rename flowsheet and test again; remove unused imports
adam-a-a Aug 14, 2023
82a207b
Merge branch 'main' into dewatering
adam-a-a Aug 16, 2023
840f25c
reorganize BSM2 flowsheet and clean up
adam-a-a Aug 17, 2023
d1d4743
Merge branch 'dewatering' of https://github.com/agarciadiego/watertap…
adam-a-a Aug 17, 2023
f47a825
rename BSM2 folder to full_water_resource_recovery_facility
adam-a-a Aug 17, 2023
77daf7e
renamed
adam-a-a Aug 17, 2023
f4afeac
fix pydantic
adam-a-a Aug 17, 2023
438b9b0
fix import
adam-a-a Aug 17, 2023
3c78ca7
Merge branch 'main' into dewatering
adam-a-a Aug 17, 2023
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
422 changes: 422 additions & 0 deletions watertap/examples/flowsheets/case_studies/BSM2/ASM_ADM_integration.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#################################################################################
# WaterTAP Copyright (c) 2020-2023, The Regents of the University of California,
# through Lawrence Berkeley National Laboratory, Oak Ridge National Laboratory,
# National Renewable Energy Laboratory, and National Energy Technology
# Laboratory (subject to receipt of any required approvals from the U.S. Dept.
# of Energy). All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. These files are also available online at the URL
# "https://github.com/watertap-org/watertap/"
#################################################################################
"""
Tests for ADM1 flowsheet example.

Verified against results from:

Rosen, C. and Jeppsson, U., 2006.
Aspects on ADM1 Implementation within the BSM2 Framework.
Department of Industrial Electrical Engineering and Automation, Lund University, Lund, Sweden, pp.1-35.

"""

# Some more information about this module
__author__ = "Alejandro Garciadiego, Xinhong Liu"

import pytest
import pytest

from pyomo.environ import assert_optimal_termination, value
from pyomo.util.check_units import assert_units_consistent

from idaes.core.util.model_statistics import degrees_of_freedom

import numpy as np
import pandas as pd
from idaes.core.solvers import get_solver
import idaes.core.util.scaling as iscale
from pyomo.opt import TerminationCondition, SolverStatus

from idaes.core.util.model_statistics import degrees_of_freedom

from watertap.examples.flowsheets.case_studies.BSM2.ASM_ADM_integration import (
build_flowsheet,
)


class TestASM1Flowsheet:
@pytest.fixture(scope="class")
def model(self):
m, res = build_flowsheet()

m.results = res

return m

@pytest.mark.integration
def test_structure(self, model):
assert_units_consistent(model)
assert degrees_of_freedom(model) == 0
assert_optimal_termination(model.results)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"""

# Some more information about this module
__author__ = "Andrew Lee"
__author__ = "Andrew Lee, Xinhong Liu"

import pyomo.environ as pyo
from pyomo.network import Arc, SequentialDecomposition
Expand Down Expand Up @@ -185,10 +185,10 @@ def mass_transfer_R4(self, t):
m.fs.FeedWater.conc_mass_comp[0, "X_I"].fix(51.2 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_S"].fix(202.32 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_BH"].fix(28.17 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_BA"].fix(1e-6 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_P"].fix(1e-6 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_O"].fix(1e-6 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_NO"].fix(1e-6 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_BA"].fix(0 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_P"].fix(0 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_O"].fix(0 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_NO"].fix(0 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_NH"].fix(31.56 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "S_ND"].fix(6.95 * pyo.units.g / pyo.units.m**3)
m.fs.FeedWater.conc_mass_comp[0, "X_ND"].fix(10.59 * pyo.units.g / pyo.units.m**3)
Expand Down Expand Up @@ -294,7 +294,7 @@ def function(unit):
seq.run(m, function)

# Solve overall flowsheet to close recycle loop
solver = get_solver(options={"bound_push": 1e-8})
solver = get_solver()
results = solver.solve(m)
check_solve(results, checkpoint="closing recycle", logger=_log, fail_flag=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_structure(self, model):
assert degrees_of_freedom(model) == 0
assert_optimal_termination(model.results)

@pytest.mark.requires_idaes_solver
@pytest.mark.integration
def test_results(self, model):
# Treated water
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_flowsheet():
m.fs.R1.inlet.flow_vol.fix(170 * pyo.units.m**3 / pyo.units.day)
m.fs.R1.inlet.temperature.fix(308.15 * pyo.units.K)
m.fs.R1.inlet.pressure.fix(1 * pyo.units.atm)
m.fs.R1.inlet.conc_mass_comp[0, "S_su"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "S_su"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "S_aa"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "S_fa"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "S_va"].fix(1 * pyo.units.mg / pyo.units.liter)
Expand All @@ -72,7 +72,7 @@ def build_flowsheet():
m.fs.R1.inlet.conc_mass_comp[0, "X_ch"].fix(5000 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_pr"].fix(20000 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_li"].fix(5000 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_su"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_su"].fix(0.0 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_aa"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_fa"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.R1.inlet.conc_mass_comp[0, "X_c4"].fix(10 * pyo.units.mg / pyo.units.liter)
Expand All @@ -90,9 +90,9 @@ def build_flowsheet():
m.fs.R1.liquid_outlet.temperature.fix(308.15 * pyo.units.K)

# TO DO: Fix initialization
m.fs.R1.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
m.fs.R1.initialize(outlvl=idaeslog.INFO_HIGH)

solver = get_solver(options={"bound_push": 1e-8})
solver = get_solver()

results = solver.solve(m, tee=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_results(self, model):
)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_su"]
) == pytest.approx(1.193e-2, rel=1e-2)
) == pytest.approx(1.195e-2, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_aa"]
) == pytest.approx(5.31e-3, rel=1e-2)
Expand All @@ -82,25 +82,25 @@ def test_results(self, model):
) == pytest.approx(0.01578, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_ac"]
) == pytest.approx(0.17319, rel=1e-2)
) == pytest.approx(0.19763, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_h2"]
) == pytest.approx(2.35e-7, rel=1e-2)
) == pytest.approx(2.36e-7, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_ch4"]
) == pytest.approx(0.0541, rel=1e-2)
) == pytest.approx(0.05508, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_IC"]
) == pytest.approx(0.15436 * 12, rel=1e-2)
) == pytest.approx(0.15268 * 12, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_IN"]
) == pytest.approx(0.13022 * 14, rel=1e-2)
) == pytest.approx(0.13023 * 14, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "S_I"]
) == pytest.approx(0.32869, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "X_c"]
) == pytest.approx(0.3086, rel=1e-2)
) == pytest.approx(0.30869, rel=1e-2)
assert value(
model.fs.R1.liquid_outlet.conc_mass_comp[0, "X_ch"]
) == pytest.approx(0.02794, rel=1e-2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_results(self, model):
) == pytest.approx(19.4947, rel=1e-4)
assert value(
model.fs.electroNP.treated.conc_mass_comp[0, "S_I"]
) == pytest.approx(0.026604, rel=1e-4)
) == pytest.approx(0.026599, rel=1e-4)
assert value(
model.fs.electroNP.treated.conc_mass_comp[0, "S_N2"]
) == pytest.approx(0, abs=1e-4)
Expand Down
10 changes: 7 additions & 3 deletions watertap/property_models/activated_sludge/asm1_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import idaes.core.util.scaling as iscale

# Some more information about this module
__author__ = "Andrew Lee, Adam Atia"

__author__ = "Andrew Lee, Adam Atia, Xinhong Liu"

# Set up logger
_log = idaeslog.getLogger(__name__)
Expand Down Expand Up @@ -283,7 +282,7 @@ def build(self):
self.temperature = pyo.Var(
domain=pyo.NonNegativeReals,
initialize=298.15,
bounds=(293.15, 323.15),
bounds=(273.15, 323.15),
doc="Temperature",
units=pyo.units.K,
)
Expand Down Expand Up @@ -359,6 +358,11 @@ def energy_density_expression(self):
rule=energy_density_expression, doc="Energy density term"
)

iscale.set_scaling_factor(self.flow_vol, 1e1)
iscale.set_scaling_factor(self.temperature, 1e-1)
iscale.set_scaling_factor(self.pressure, 1e-6)
iscale.set_scaling_factor(self.conc_mass_comp, 1e1)

def get_material_flow_terms(self, p, j):
return self.material_flow_expression[j]

Expand Down
19 changes: 11 additions & 8 deletions watertap/property_models/activated_sludge/asm1_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# Some more information about this module
__author__ = "Andrew Lee"
__author__ = "Andrew Lee, Xinhong Liu"


# Set up logger
Expand Down Expand Up @@ -465,13 +465,10 @@ def rate_expression_rule(b, r):
# R7: Hydrolysis of entrapped organics
return b.reaction_rate[r] == pyo.units.convert(
b.params.k_h
* (b.conc_mass_comp_ref["X_S"] / b.conc_mass_comp_ref["X_BH"])
* b.conc_mass_comp_ref["X_S"]
/ (
b.params.K_X
+ (
b.conc_mass_comp_ref["X_S"]
/ b.conc_mass_comp_ref["X_BH"]
)
b.params.K_X * b.conc_mass_comp_ref["X_BH"]
+ b.conc_mass_comp_ref["X_S"]
)
* (
(
Expand All @@ -493,7 +490,13 @@ def rate_expression_rule(b, r):
# R8: Hydrolysis of entrapped organic nitrogen
return b.reaction_rate[r] == (
b.reaction_rate["R7"]
* (b.conc_mass_comp_ref["X_ND"] / b.conc_mass_comp_ref["X_S"])
* (
b.conc_mass_comp_ref["X_ND"]
/ (
b.conc_mass_comp_ref["X_S"]
+ 1e-10 * pyo.units.kg / pyo.units.m**3
)
)
)
else:
raise BurntToast()
Expand Down
4 changes: 2 additions & 2 deletions watertap/property_models/activated_sludge/asm2d_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import idaes.logger as idaeslog

# Some more information about this module
__author__ = "Andrew Lee, Adam Atia"
__author__ = "Andrew Lee, Adam Atia, Xinhong Liu"


# Set up logger
Expand Down Expand Up @@ -319,7 +319,7 @@ def build(self):
self.temperature = pyo.Var(
domain=pyo.NonNegativeReals,
initialize=298.15,
bounds=(298.14, 323.15),
bounds=(273.15, 323.15),
doc="Temperature",
units=pyo.units.K,
)
Expand Down
Loading
Loading