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 25 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
367 changes: 367 additions & 0 deletions watertap/examples/flowsheets/case_studies/BSM2/ASM1_ADM1_flowsheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,367 @@
#################################################################################
# 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/"
#################################################################################
__author__ = "Alejandro Garciadiego"

import pyomo.environ as pyo
from pyomo.environ import (
units,
)

from pyomo.network import Arc, SequentialDecomposition
from idaes.core import FlowsheetBlock
from idaes.core.util.model_statistics import degrees_of_freedom

from watertap.unit_models.anaerobic_digestor import AD
from watertap.unit_models.thickener import Thickener
from watertap.unit_models.dewatering import DewateringUnit

from watertap.unit_models.translators.translator_asm1_adm1 import Translator_ASM1_ADM1
from watertap.unit_models.translators.translator_adm1_asm1 import Translator_ADM1_ASM1
from idaes.models.unit_models import Separator, Mixer

from idaes.core.util.model_statistics import (
degrees_of_freedom,
large_residuals_set,
activated_inequalities_set,
)
import idaes.logger as idaeslog
from idaes.core.util.initialization import propagate_state
from idaes.core.solvers import get_solver
import idaes.core.util.scaling as iscale
from idaes.core.util.tables import (
create_stream_table_dataframe,
stream_table_dataframe_to_string,
)

from watertap.property_models.anaerobic_digestion.adm1_properties import (
ADM1ParameterBlock,
)
from watertap.property_models.activated_sludge.asm1_properties import (
ASM1ParameterBlock,
)
from watertap.property_models.anaerobic_digestion.adm1_reactions import (
ADM1ReactionParameterBlock,
)
from idaes.models.unit_models.separator import SplittingType
from watertap.property_models.anaerobic_digestion.adm1_properties_vapor import (
ADM1_vaporParameterBlock,
)

from idaes.core.util.tables import (
create_stream_table_dataframe,
stream_table_dataframe_to_string,
)

from watertap.examples.flowsheets.case_studies.activated_sludge.ASM1_flowsheet import (
build_flowsheet as build_ASM,
)

from watertap.core.util.initialization import check_solve


def build_flowsheet():
# Call ASM model
m, res = build_ASM()

m.del_component(m.fs.Sludge)
m.del_component(m.fs.stream1)
m.del_component(m.fs.stream102)
agarciadiego marked this conversation as resolved.
Show resolved Hide resolved

m.fs.props_ASM1 = ASM1ParameterBlock()
m.fs.props_ADM1 = ADM1ParameterBlock()
m.fs.props_vap = ADM1_vaporParameterBlock()
m.fs.ADM1_rxn_props = ADM1ReactionParameterBlock(property_package=m.fs.props_ADM1)

m.fs.asm_adm = Translator_ASM1_ADM1(
inlet_property_package=m.fs.props_ASM1,
outlet_property_package=m.fs.props_ADM1,
reaction_package=m.fs.ADM1_rxn_props,
has_phase_equilibrium=False,
outlet_state_defined=True,
)

m.fs.RADM = AD(
liquid_property_package=m.fs.props_ADM1,
vapor_property_package=m.fs.props_vap,
reaction_package=m.fs.ADM1_rxn_props,
has_heat_transfer=True,
has_pressure_change=False,
)

m.fs.adm_asm = Translator_ADM1_ASM1(
inlet_property_package=m.fs.props_ADM1,
outlet_property_package=m.fs.props_ASM1,
reaction_package=m.fs.ADM1_rxn_props,
has_phase_equilibrium=False,
outlet_state_defined=True,
)

m.fs.CL = Separator(
property_package=m.fs.props,
outlet_list=["underflow", "effluent"],
split_basis=SplittingType.componentFlow,
)

m.fs.TU = Thickener(property_package=m.fs.props_ASM1)
m.fs.DU = DewateringUnit(property_package=m.fs.props_ASM1)

m.fs.MX2 = Mixer(
property_package=m.fs.props_ASM1, inlet_list=["feed_water1", "recycle1"]
)
m.fs.MX3 = Mixer(
property_package=m.fs.props_ASM1, inlet_list=["feed_water2", "recycle2"]
)
m.fs.MX4 = Mixer(
property_package=m.fs.props_ASM1, inlet_list=["thickener", "clarifier"]
)

m.fs.FeedWater.temperature.fix(308.15 * pyo.units.K)
m.fs.SP6.split_fraction[:, "recycle"].fix(0.975)

# Clarifier
# TODO: Update once more detailed model available
m.fs.CL.split_fraction[0, "effluent", "H2O"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "S_I"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "S_S"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "X_I"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "X_S"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "X_BH"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "X_BA"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "X_P"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "S_O"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "S_NO"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "S_NH"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "S_ND"].fix(0.993)
m.fs.CL.split_fraction[0, "effluent", "X_ND"].fix(0.5192)
m.fs.CL.split_fraction[0, "effluent", "S_ALK"].fix(0.993)

m.fs.stream2adm = Arc(
source=m.fs.RADM.liquid_outlet, destination=m.fs.adm_asm.inlet
)
pyo.TransformationFactory("network.expand_arcs").apply_to(m)

m.fs.asm_adm.inlet.flow_vol.fix(170 * pyo.units.m**3 / pyo.units.day)
m.fs.asm_adm.inlet.temperature.fix(308.15 * units.K)
m.fs.asm_adm.inlet.pressure.fix(1 * units.atm)

m.fs.asm_adm.inlet.conc_mass_comp[0, "S_I"].fix(30 * pyo.units.mg / pyo.units.liter)
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_S"].fix(
8.89e-1 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_I"].fix(
2247 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_S"].fix(
96.8 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_BH"].fix(
5004 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_BA"].fix(
292 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_P"].fix(
884 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_O"].fix(
4.49e-1 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_NO"].fix(
10.14 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_NH"].fix(
1.86e-1 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_ND"].fix(
6.88e-1 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_ND"].fix(
6.92 * pyo.units.mg / pyo.units.liter
)
m.fs.asm_adm.inlet.alkalinity.fix(4.13 * units.mol / units.m**3)

m.fs.RADM.inlet.flow_vol.fix(170 * pyo.units.m**3 / pyo.units.day)
m.fs.RADM.inlet.temperature.fix(308.15 * pyo.units.K)
m.fs.RADM.inlet.pressure.fix(1 * pyo.units.atm)
m.fs.RADM.inlet.conc_mass_comp[0, "S_su"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_aa"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_fa"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_va"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_bu"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_pro"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_ac"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_h2"].fix(1e-5 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_ch4"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "S_IC"].fix(
40 * units.mmol / units.liter * 12 * units.mg / units.mmol
)
m.fs.RADM.inlet.conc_mass_comp[0, "S_IN"].fix(
10 * units.mmol / units.liter * 14 * units.mg / units.mmol
)
m.fs.RADM.inlet.conc_mass_comp[0, "S_I"].fix(20 * pyo.units.mg / pyo.units.liter)

m.fs.RADM.inlet.conc_mass_comp[0, "X_c"].fix(2000 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_ch"].fix(5000 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_pr"].fix(
20000 * pyo.units.mg / pyo.units.liter
)
m.fs.RADM.inlet.conc_mass_comp[0, "X_li"].fix(5000 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_su"].fix(1 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_aa"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_fa"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_c4"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_pro"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_ac"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_h2"].fix(10 * pyo.units.mg / pyo.units.liter)
m.fs.RADM.inlet.conc_mass_comp[0, "X_I"].fix(25000 * pyo.units.mg / pyo.units.liter)

m.fs.RADM.inlet.cations[0].fix(40 * pyo.units.mmol / pyo.units.liter)
m.fs.RADM.inlet.anions[0].fix(20 * pyo.units.mmol / pyo.units.liter)

m.fs.RADM.volume_liquid.fix(3400 * pyo.units.m**3)
m.fs.RADM.volume_vapor.fix(300 * pyo.units.m**3)

m.fs.RADM.liquid_outlet.temperature.fix(308.15 * pyo.units.K)
print(degrees_of_freedom(m))

# Apply scaling
iscale.calculate_scaling_factors(m.fs)

m.fs.asm_adm.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
m.fs.RADM.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream2adm)
m.fs.adm_asm.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})

print(degrees_of_freedom(m))
# assert degrees_of_freedom(m) == 0

m.fs.stream6adm = Arc(source=m.fs.SP6.waste, destination=m.fs.TU.inlet)
m.fs.stream3adm = Arc(source=m.fs.TU.underflow, destination=m.fs.MX4.thickener)
m.fs.stream7adm = Arc(source=m.fs.TU.overflow, destination=m.fs.MX3.recycle2)
m.fs.stream9adm = Arc(source=m.fs.CL.underflow, destination=m.fs.MX4.clarifier)
m.fs.stream4adm = Arc(source=m.fs.adm_asm.outlet, destination=m.fs.DU.inlet)
m.fs.stream5adm = Arc(source=m.fs.DU.overflow, destination=m.fs.MX2.recycle1)
m.fs.stream01 = Arc(source=m.fs.FeedWater.outlet, destination=m.fs.MX2.feed_water1)
m.fs.stream02 = Arc(source=m.fs.MX2.outlet, destination=m.fs.MX3.feed_water2)
m.fs.stream03 = Arc(source=m.fs.MX3.outlet, destination=m.fs.CL.inlet)
m.fs.stream04 = Arc(source=m.fs.CL.effluent, destination=m.fs.MX1.feed_water)

pyo.TransformationFactory("network.expand_arcs").apply_to(m)

propagate_state(m.fs.stream6adm)

m.fs.TU.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream3adm)
propagate_state(m.fs.stream7adm)

m.fs.DU.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream5adm)

m.fs.FeedWater.flow_vol.fix(20648 * pyo.units.m**3 / pyo.units.day)
propagate_state(m.fs.stream01)
m.fs.MX2.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream02)

m.fs.MX3.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream03)

m.fs.CL.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream04)

propagate_state(m.fs.stream9adm)
m.fs.MX4.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
propagate_state(m.fs.stream4adm)

m.fs.RADM.inlet.flow_vol.unfix()
m.fs.RADM.inlet.temperature.unfix()
m.fs.RADM.inlet.pressure.unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_su"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_aa"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_fa"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_va"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_bu"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_pro"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_ac"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_h2"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_ch4"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_IC"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_IN"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "S_I"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_c"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_ch"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_pr"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_li"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_su"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_aa"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_fa"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_c4"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_pro"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_ac"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_h2"].unfix()
m.fs.RADM.inlet.conc_mass_comp[0, "X_I"].unfix()
m.fs.RADM.inlet.cations[0].unfix()
m.fs.RADM.inlet.anions[0].unfix()

m.fs.stream10adm = Arc(source=m.fs.MX4.outlet, destination=m.fs.asm_adm.inlet)
pyo.TransformationFactory("network.expand_arcs").apply_to(m)

m.fs.asm_adm.inlet.flow_vol.unfix()
m.fs.asm_adm.inlet.temperature.unfix()
m.fs.asm_adm.inlet.pressure.unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_I"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_S"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_I"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_S"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_BH"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_BA"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_P"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_O"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_NO"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_NH"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "S_ND"].unfix()
m.fs.asm_adm.inlet.conc_mass_comp[0, "X_ND"].unfix()
m.fs.asm_adm.inlet.alkalinity.unfix()

print("3", degrees_of_freedom(m))
m.fs.stream1adm = Arc(source=m.fs.asm_adm.outlet, destination=m.fs.RADM.inlet)
pyo.TransformationFactory("network.expand_arcs").apply_to(m)
print("3", degrees_of_freedom(m))
# Initialize flowsheet
# Apply sequential decomposition - 1 iteration should suffice
# seq = SequentialDecomposition()
# seq.options.select_tear_method = "heuristic"
# seq.options.tear_method = "Wegstein"
# seq.options.iterLim = 1
#
# G = seq.create_graph(m)
#
# def function(unit):
# unit.initialize(outlvl=idaeslog.INFO_HIGH, optarg={"bound_push": 1e-8})
#
# seq.run(m, function)

# m.fs.pprint()
# print(large_residuals_set(m.fs))

# for var, sv in iscale.badly_scaled_var_generator(m):
# print(var,sv)

# solver = get_solver(options={"bound_push": 1e-8,"max_iter":0})
solver = get_solver(options={"bound_push": 1e-8})
results = solver.solve(m, tee=True)
print(degrees_of_freedom(m))
# pyo.assert_optimal_termination(results)
# m.display()

print(large_residuals_set(m))

return m, results
Loading