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 Anoxic CSTR Costing #1186

Merged
merged 32 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1245716
Add anoxic cstr costing
MarcusHolly Nov 7, 2023
4fe4d9a
Add costing to BSM2 flowsheet
MarcusHolly Nov 7, 2023
a21cb8e
Fix pylint issue
MarcusHolly Nov 7, 2023
94ec318
Add electricity intensity to system-level metrics in flowsheet
MarcusHolly Nov 7, 2023
e7a9539
Merge branch 'main' into anoxic_tank_cost
MarcusHolly Nov 17, 2023
6658fa9
Add CSTR unit model based on IDAES CSTR
MarcusHolly Nov 18, 2023
dbb3211
Update CSTR costing method
MarcusHolly Nov 18, 2023
e1477bf
Use new CSTR model in BSM2 flowsheet
MarcusHolly Nov 18, 2023
816409d
Add tests for CSTR unit model
MarcusHolly Nov 20, 2023
82e719f
Ignore mixer costs in BSM2 flowsheet for now
MarcusHolly Nov 20, 2023
fbcc50b
Merge branch 'main' into anoxic_tank_cost
MarcusHolly Nov 20, 2023
228d8fe
Remove unused imports
MarcusHolly Nov 20, 2023
9e18c86
Address pylint issue
MarcusHolly Nov 20, 2023
835d9a8
Add default costing method for cstr
MarcusHolly Nov 20, 2023
df546bc
Add LCOW into cost testing
MarcusHolly Nov 20, 2023
fbc092d
Update init file
MarcusHolly Nov 20, 2023
b62db8f
Remove duplicate import
MarcusHolly Nov 20, 2023
7386242
Change HRT to a Var and add an HRT constraint in unit model
MarcusHolly Nov 20, 2023
ae15d4a
Update costing test to use BSM2 flowsheet conditions
MarcusHolly Nov 20, 2023
3bccd1e
Revert HRT back to a mutable parameter
MarcusHolly Nov 20, 2023
65870ff
Treat HRT as a variable and modify costing appropriately
MarcusHolly Nov 20, 2023
af96904
Use cost_by_flow_volume utility function
MarcusHolly Nov 20, 2023
390eb5a
Revert changes made to BSM2 flowsheet
MarcusHolly Nov 21, 2023
9e2b42b
Merge branch 'main' into anoxic_tank_cost
adam-a-a Nov 22, 2023
55c4503
Address Adam's comments
MarcusHolly Nov 27, 2023
fb2a438
Merge branch 'anoxic_tank_cost' of https://github.com/MarcusHolly/wat…
MarcusHolly Nov 27, 2023
b9d2c71
Update class name/import
MarcusHolly Nov 27, 2023
5babe49
Address merge conflict
MarcusHolly Nov 28, 2023
fc56ef6
Make units explicit in unit costing test
MarcusHolly Nov 29, 2023
d49433b
Add check asserting units are consistent
MarcusHolly Nov 30, 2023
c06f4a5
Merge branch 'main' into anoxic_tank_cost
MarcusHolly Dec 1, 2023
e92f616
Merge branch 'main' into anoxic_tank_cost
adam-a-a Dec 5, 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
4 changes: 3 additions & 1 deletion watertap/costing/costing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import pyomo.environ as pyo
from idaes.core import declare_process_block_class
from idaes.core.base.costing_base import FlowsheetCostingBlockData
from idaes.models.unit_models import Mixer, HeatExchanger
from idaes.models.unit_models import Mixer, HeatExchanger, CSTR

from watertap.core.util.misc import is_constant_up_to_units

from watertap.costing.unit_models.mixer import cost_mixer
from watertap.costing.unit_models.heat_exchanger import cost_heat_exchanger
from watertap.costing.unit_models.cstr import cost_cstr


@declare_process_block_class("WaterTAPCostingBlock")
Expand All @@ -33,6 +34,7 @@ class WaterTAPCostingBlockData(FlowsheetCostingBlockData):
unit_mapping = {
Mixer: cost_mixer,
HeatExchanger: cost_heat_exchanger,
CSTR: cost_cstr,
}

def build(self):
Expand Down
69 changes: 69 additions & 0 deletions watertap/costing/unit_models/cstr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#################################################################################
# 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/"
#################################################################################

import pyomo.environ as pyo
from ..util import (
register_costing_parameter_block,
make_capital_cost_var,
)


def build_cstr_cost_param_block(blk):
# Source: https://www.fwrj.com/articles/9812.pdf
blk.sizing_cost = pyo.Var(
initialize=0.34,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the unit cost for the largest size shown in the range from the reference. Perhaps we should choose a value like the mean or median.

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 reason I chose the largest size is because the flowrate in BSM2 actually goes way beyond the ranges listed in this reference. The largest flow in the reference is 100,000 GPD (378.5 m3/day) whereas the BSM2 feed flowrate is 20648 m3/day. So I didn't think it made sense to choose a mean or median value. Although if we intend on using this CSTR for non-BSM2 purposes, then it would make more sense to use an average value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough!

doc="Reactor sizing cost",
units=pyo.units.USD_1998 / pyo.units.m**3,
)


@register_costing_parameter_block(
build_rule=build_cstr_cost_param_block,
parameter_block_name="cstr",
)
def cost_cstr(blk):
"""
CSTR costing method
"""
cost_cstr_capital(
blk,
blk.costing_package.cstr.sizing_cost,
)


def cost_cstr_capital(blk, sizing_cost):
"""
Generic function for costing an ElectroNP system.
"""
make_capital_cost_var(blk)

blk.sizing_cost = pyo.Expression(expr=sizing_cost)

flow_in = pyo.units.convert(
blk.unit_model.control_volume.properties_in[0].flow_vol,
to_units=pyo.units.m**3 / pyo.units.hr,
)

HRT = pyo.units.convert(
blk.unit_model.volume[0]
/ blk.unit_model.control_volume.properties_in[0].flow_vol,
to_units=pyo.units.hr,
)

print(f"base_currency: {blk.costing_package.base_currency}")
blk.capital_cost_constraint = pyo.Constraint(
expr=blk.capital_cost
== pyo.units.convert(
HRT * flow_in * blk.sizing_cost,
to_units=blk.costing_package.base_currency,
)
)
MarcusHolly marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.cstr import AnoxicCSTR

from watertap.unit_models.translators.translator_asm1_adm1 import Translator_ASM1_ADM1
from watertap.unit_models.translators.translator_adm1_asm1 import Translator_ADM1_ASM1
Expand All @@ -38,9 +39,6 @@
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,
)
Expand All @@ -49,9 +47,8 @@
ADM1_vaporParameterBlock,
)

from idaes.core import FlowsheetBlock
from idaes.core import FlowsheetBlock, UnitModelCostingBlock
from idaes.models.unit_models import (
CSTR,
Feed,
Mixer,
Separator,
Expand All @@ -65,6 +62,7 @@
ASM1ReactionParameterBlock,
)
from watertap.core.util.initialization import assert_degrees_of_freedom
from watertap.costing import WaterTAPCosting
from pyomo.util.check_units import assert_units_consistent


Expand All @@ -79,15 +77,14 @@ def main():
results = solve(m)

add_costing(m)
m.fs.costing.initialize()
# Assert DOF = 0 after adding costing
# assert_degrees_of_freedom(m, 0)

# TODO: initialize costing after adding to flowsheet
# m.fs.costing.initialize()

# results = solve(m)
results = solve(m)

display_results(m)
display_costing(m)

return m, results

Expand All @@ -113,11 +110,11 @@ def build():
property_package=m.fs.props_ASM1, inlet_list=["feed_water", "recycle"]
)
# First reactor (anoxic) - standard CSTR
m.fs.R1 = CSTR(
m.fs.R1 = AnoxicCSTR(
property_package=m.fs.props_ASM1, reaction_package=m.fs.ASM1_rxn_props
)
# Second reactor (anoxic) - standard CSTR
m.fs.R2 = CSTR(
m.fs.R2 = AnoxicCSTR(
property_package=m.fs.props_ASM1, reaction_package=m.fs.ASM1_rxn_props
)
# Third reactor (aerobic) - CSTR with injection
Expand Down Expand Up @@ -442,7 +439,30 @@ def function(unit):

def add_costing(m):
# TODO: implement unit model and flowsheet level costing
pass
m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyo.units.USD_2020

# Costing Blocks
m.fs.R1.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.R2.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)

m.fs.RADM.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)

# Leaving out mixer costs for now
# m.fs.MX1.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
# m.fs.MX6.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
# m.fs.MX2.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
# m.fs.MX3.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
# m.fs.MX4.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)

# process costing and add system level metrics
m.fs.costing.cost_process()
m.fs.costing.add_electricity_intensity(m.fs.FeedWater.properties[0].flow_vol)
m.fs.costing.add_annual_water_production(m.fs.Treated.properties[0].flow_vol)
m.fs.costing.add_LCOW(m.fs.Treated.properties[0].flow_vol)
m.fs.costing.add_specific_energy_consumption(m.fs.Treated.properties[0].flow_vol)

m.fs.objective = pyo.Objective(expr=m.fs.costing.LCOW)


def solve(blk, solver=None):
Expand Down Expand Up @@ -484,5 +504,28 @@ def display_results(m):
m.fs.component(u).report()


def display_costing(m):
print(
"Energy consumption: %.1f kWh/m3"
% pyo.value(m.fs.costing.specific_energy_consumption)
)
print(
"Electricity intensity: %.1f kWh/m3"
% pyo.value(m.fs.costing.electricity_intensity)
)
print("Levelized cost of water: %.2f $/m3" % pyo.value(m.fs.costing.LCOW))

print(
"Total operating cost: %.2f $/yr" % pyo.value(m.fs.costing.total_operating_cost)
)

print("Total capital cost: %.2f $" % pyo.value(m.fs.costing.total_capital_cost))

print(
"Total annualized cost: %.2f $/yr"
% pyo.value(m.fs.costing.total_annualized_cost)
)


if __name__ == "__main__":
m, results = main()
1 change: 1 addition & 0 deletions watertap/unit_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
from .thickener import Thickener
from .dewatering import DewateringUnit
from .electroNP_ZO import ElectroNPZO
from .cstr import AnoxicCSTR
84 changes: 84 additions & 0 deletions watertap/unit_models/cstr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
###############################################################################
# WaterTAP Copyright (c) 2021, 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/"
#
###############################################################################
"""
Anoxic CSTR unit model for BSM2 and plant-wide wastewater treatment modeling.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename filename to anoxic_cstr instead of cstr. Either that, or rename the class which is currently named AnoxicCSTR. The only dilemma I see with this sort of naming is that anoxic is not anaerobic, technically. So maybe it makes more sense to rename the class as CSTR, which would just build on top of IDAES' CSTR and be the WaterTAP version,

This unit inherits from the IDAES CSTR unit.
"""

# Import IDAES cores
from idaes.core import (
declare_process_block_class,
)
from idaes.models.unit_models.cstr import CSTRData

import idaes.logger as idaeslog

from pyomo.environ import (
Constraint,
NonNegativeReals,
Var,
units as pyunits,
)

from watertap.costing.unit_models.cstr import cost_cstr

__author__ = "Marcus Holly"


# Set up logger
_log = idaeslog.getLogger(__name__)


@declare_process_block_class("AnoxicCSTR")
class AnoxicCSTRData(CSTRData):
"""
Anoxic CSTR unit block for BSM2
"""

CONFIG = CSTRData.CONFIG()

def build(self):
"""
Begin building model.
Args:
None
Returns:
None
"""

# Call UnitModel.build to set up dynamics
super(AnoxicCSTRData, self).build()

self.HRT = Var(
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that we used the acronym (HRT) in ZO models previously. I spelled it out in my recent PR and I think @agarciadiego did too. We should be consistent and spell it out here too.

self.flowsheet().time,
initialize=4,
domain=NonNegativeReals,
units=pyunits.s,
doc="Hydraulic retention time",
)

def CSTR_retention_time_rule(self, t):
return (
self.HRT[t]
== self.volume[t] / self.control_volume.properties_in[t].flow_vol
)

self.CSTR_retention_time = Constraint(
self.flowsheet().time,
rule=CSTR_retention_time_rule,
doc="Total CSTR retention time",
)

@property
def default_costing_method(self):
return cost_cstr
Loading
Loading