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

OARO 1D Model #1172

Merged
merged 92 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
dcb9b87
adding 1d oaro but DOF = -9
adam-a-a Oct 26, 2022
e76dbf0
getting test update from f2277f90
bknueven Nov 17, 2022
cad632e
Merge branch 'main' into oaro1d
bknueven Nov 17, 2022
16c08d3
test
luohezhiming Nov 18, 2022
27643ac
Merge remote-tracking branch 'upstream/main' into oaro1d
bknueven Feb 8, 2023
a4dae9f
light refactor of OARO0D
bknueven Feb 8, 2023
1eb1c79
carrying over to OARO1D
bknueven Feb 8, 2023
f454554
starting to work on OARO1D test
bknueven Feb 8, 2023
ba0b4c9
add missing abstract method
bknueven Feb 8, 2023
3ffabdb
checkpoint: one extra DOF in basic model
bknueven Feb 8, 2023
7d35890
add
luohezhiming Mar 16, 2023
4766c52
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Mar 16, 2023
ef81bae
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Mar 22, 2023
168bbaf
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Mar 27, 2023
a09b4e9
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Mar 30, 2023
44a22e8
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Mar 31, 2023
1c1a135
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 5, 2023
401f997
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 10, 2023
258f6fe
delete redundant files
luohezhiming Apr 11, 2023
2c994c3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 17, 2023
5b6baed
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 21, 2023
0afa551
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 24, 2023
479fb6d
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Apr 28, 2023
b393ed0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 9, 2023
708ad0a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 12, 2023
5a69761
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 17, 2023
112415a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 19, 2023
93737c0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 25, 2023
3162e34
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 26, 2023
637b32d
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming May 29, 2023
ea4e066
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 5, 2023
84a2900
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 7, 2023
17bc5e3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 12, 2023
f816483
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 13, 2023
fea68e3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 14, 2023
c19fba5
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 20, 2023
dd86d76
Merge branch 'main' into oaro1d
adam-a-a Jun 21, 2023
17dadcc
checking out last save by ben but passing off to zach/chenyu
adam-a-a Jun 21, 2023
0754d21
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 22, 2023
9dcece1
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 22, 2023
a5325c9
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jun 27, 2023
c4bc3ef
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 5, 2023
bb8ca41
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 7, 2023
5afdc55
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 11, 2023
35ecf79
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 12, 2023
fb2a100
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 17, 2023
40b4de5
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 19, 2023
72f6f25
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Jul 21, 2023
ece1d2f
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 2, 2023
a861a5b
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 7, 2023
d58a9a7
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 9, 2023
4968282
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 19, 2023
acfd9f6
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 23, 2023
a97fbe3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 24, 2023
2fc2425
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Aug 25, 2023
581dec0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Sep 4, 2023
3202970
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Sep 20, 2023
625e610
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Sep 25, 2023
2a37aca
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 2, 2023
1fa9316
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 3, 2023
c2a4f7d
Merge branch 'main' into OARO1D_chenyu
luohezhiming Oct 4, 2023
baff470
temporary edits
luohezhiming Oct 5, 2023
3fe45d1
Add OARO 1D Model
luohezhiming Oct 16, 2023
da8fd13
delete practice files
luohezhiming Oct 16, 2023
74811ea
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 16, 2023
a69c2ca
Merge branch 'main' into OARO1D_chenyu
luohezhiming Oct 16, 2023
034fb48
code plinting
luohezhiming Oct 16, 2023
a89268c
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 16, 2023
3667a77
Merge branch 'main' into OARO1D_chenyu
luohezhiming Oct 16, 2023
b9994a7
code linting
luohezhiming Oct 16, 2023
55c06dd
add test for water recovery
luohezhiming Oct 19, 2023
09cf01e
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 19, 2023
70e1847
Merge branch 'main' into OARO1D_chenyu
luohezhiming Oct 19, 2023
02cc515
rename test function name
luohezhiming Oct 19, 2023
4070fa1
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 20, 2023
0d6fe1a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Oct 23, 2023
6c58099
minor revision
luohezhiming Oct 23, 2023
59fb667
Merge branch 'main' into OARO1D_chenyu
luohezhiming Oct 23, 2023
9a9d4db
add requires_idaes_solver
luohezhiming Oct 23, 2023
25e34d9
reverse bound
luohezhiming Oct 23, 2023
85f15b3
minor revisons
luohezhiming Oct 23, 2023
598a1ab
relax deltaP bound
luohezhiming Oct 24, 2023
0b8d450
add bound to deltaP
luohezhiming Oct 24, 2023
0f09c3c
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Nov 6, 2023
568d5b0
Merge branch 'main' into OARO1D_chenyu
adam-a-a Nov 8, 2023
2c19ca0
Merge branch 'main' into OARO1D_chenyu
adam-a-a Nov 9, 2023
5f82e05
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming Nov 9, 2023
7f0532a
Merge branch 'main' into OARO1D_chenyu
luohezhiming Nov 9, 2023
619a58f
resolve config number issue
luohezhiming Nov 9, 2023
c400188
Merge branch 'OARO1D_chenyu' of https://github.com/luohezhiming/water…
luohezhiming Nov 9, 2023
db6f5cf
Merge branch 'main' into OARO1D_chenyu
zacharybinger Nov 9, 2023
4f6d2c3
Merge branch 'main' into OARO1D_chenyu
ksbeattie Nov 9, 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
73 changes: 34 additions & 39 deletions watertap/unit_models/osmotically_assisted_reverse_osmosis_0D.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from idaes.core import declare_process_block_class, FlowDirection
from idaes.core.util import scaling as iscale
from idaes.core.util.misc import add_object_reference
from watertap.core import (
MembraneChannel0DBlock,
MassTransferCoefficient,
Expand Down Expand Up @@ -47,48 +48,50 @@ class OsmoticallyAssistedReverseOsmosisData(OsmoticallyAssistedReverseOsmosisBas

_add_has_full_reporting(CONFIG)

def _add_membrane_channel_and_geometry(
self, side="feed_side", flow_direction=FlowDirection.forward
):
if not isinstance(side, str):
raise TypeError(
f"{side} is not a string. Please provide a string for the side argument."
)
def _add_membrane_channels_and_geometry(self):

# Build membrane channel control volume
setattr(
self,
side,
MembraneChannel0DBlock(
dynamic=False,
has_holdup=False,
property_package=self.config.property_package,
property_package_args=self.config.property_package_args,
),
)
mem_side = getattr(self, side)
channel_kwargs = {
"dynamic": False,
"has_holdup": False,
"property_package": self.config.property_package,
"property_package_args": self.config.property_package_args,
}
self.feed_side = MembraneChannel0DBlock(**channel_kwargs)
self.permeate_side = MembraneChannel0DBlock(**channel_kwargs)

if (self.config.pressure_change_type != PressureChangeType.fixed_per_stage) or (
self.config.mass_transfer_coefficient == MassTransferCoefficient.calculated
):
if not hasattr(self, "length") and not hasattr(self, "width"):
self._add_length_and_width()
mem_side.add_geometry(
length_var=self.length,
width_var=self.width,
flow_direction=flow_direction,
self._add_length_and_width()
add_geometry_kwargs = {
"length_var": self.length,
"width_var": self.width,
}
self.feed_side.add_geometry(
flow_direction=FlowDirection.forward, **add_geometry_kwargs
)
if not hasattr(self, "eq_area"):
add_eq_area = True
else:
add_eq_area = False
self._add_area(include_constraint=add_eq_area)
self.permeate_side.add_geometry(
flow_direction=FlowDirection.backward, **add_geometry_kwargs
)
self._add_area(include_constraint=True)
else:
mem_side.add_geometry(
length_var=None, width_var=None, flow_direction=flow_direction
add_geometry_kwargs = {
"length_var": None,
"width_var": None,
}
self.feed_side.add_geometry(
flow_direction=FlowDirection.forward, **add_geometry_kwargs
)
self.permeate_side.add_geometry(
flow_direction=FlowDirection.backward, **add_geometry_kwargs
)
self._add_area(include_constraint=False)

def _add_deltaP(self, side):
mem_side = self.component(side)
add_object_reference(mem_side, "deltaP_stage", mem_side.deltaP)

def _add_mass_transfer(self):

units_meta = self.config.property_package.get_metadata().get_derived_units
Expand Down Expand Up @@ -164,11 +167,3 @@ def calculate_scaling_factors(self):
v = self.permeate_side.mass_transfer_term[t, p, j]
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, sf)

if hasattr(self, "length"):
if iscale.get_scaling_factor(self.length) is None:
iscale.set_scaling_factor(self.length, 1)

if hasattr(self, "width"):
if iscale.get_scaling_factor(self.width) is None:
iscale.set_scaling_factor(self.width, 1)
240 changes: 240 additions & 0 deletions watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
###############################################################################
# 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/"
#
###############################################################################

# Import Pyomo libraries
from pyomo.environ import (
Var,
NonNegativeReals,
NegativeReals,
value,
)

from idaes.core import declare_process_block_class, FlowDirection, useDefault
from idaes.core.util import scaling as iscale
from watertap.core import (
MembraneChannel1DBlock,
PressureChangeType,
)
from watertap.core.membrane_channel1d import CONFIG_Template
from watertap.unit_models.osmotically_assisted_reverse_osmosis_base import (
OsmoticallyAssistedReverseOsmosisBaseData,
_add_has_full_reporting,
)
import idaes.logger as idaeslog


__author__ = "Adam Atia, Chenyu Wang"

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


@declare_process_block_class("OsmoticallyAssistedReverseOsmosis1D")
class OsmoticallyAssistedReverseOsmosis1DData(
OsmoticallyAssistedReverseOsmosisBaseData
):
"""
Standard 1D OARO Unit Model Class:
- one dimensional model
- steady state only
- single liquid phase only
"""

CONFIG = CONFIG_Template()

_add_has_full_reporting(CONFIG)

def _process_config(self):
super()._process_config()
if self.config.transformation_method is useDefault:
_log.warning(
"Discretization method was "
"not specified for the "
"reverse osmosis module. "
"Defaulting to finite "
"difference method."
)
self.config.transformation_method = "dae.finite_difference"

if self.config.transformation_scheme is useDefault:
_log.warning(
"Discretization scheme was "
"not specified for the "
"reverse osmosis module."
"Defaulting to backward finite "
"difference."
)
self.config.transformation_scheme = "BACKWARD"

def _add_membrane_channels_and_geometry(self):

# Build membrane channel control volume
channel_kwargs = {
"dynamic": self.config.dynamic,
"has_holdup": self.config.has_holdup,
"area_definition": self.config.area_definition,
"property_package": self.config.property_package,
"property_package_args": self.config.property_package_args,
"transformation_method": self.config.transformation_method,
"transformation_scheme": self.config.transformation_scheme,
"finite_elements": self.config.finite_elements,
"collocation_points": self.config.collocation_points,
}

self.feed_side = MembraneChannel1DBlock(**channel_kwargs)
self.permeate_side = MembraneChannel1DBlock(**channel_kwargs)

self._add_length_and_width()
add_geometry_kwargs = {
"length_var": self.length,
"width_var": self.width,
}
self.feed_side.add_geometry(
flow_direction=FlowDirection.forward, **add_geometry_kwargs
)
self.permeate_side.add_geometry(
flow_direction=FlowDirection.backward, **add_geometry_kwargs
)
self._add_area(include_constraint=True)

def _add_deltaP(self, side):
if not isinstance(side, str):
raise TypeError(

Check warning on line 112 in watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py

View check run for this annotation

Codecov / codecov/patch

watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py#L112

Added line #L112 was not covered by tests
f"{side} is not a string. Please provide a string for the side argument."
)

units_meta = self.config.property_package.get_metadata().get_derived_units
mem_side = getattr(self, side)
setattr(
mem_side,
"deltaP_stage",
Var(
self.flowsheet().config.time,
initialize=-1e5,
bounds=(-1e6, 0),
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember the bounds of pressure drop causing some issues in the multi-stage 0D OARO flowsheet. If my recollection is correct, should we remove these bounds? Even if it isn't correct, can we remove these bounds and still ensure (or even improve) model stability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some of unknown reasons, once I relax the lower bound to None, the Linux tests all failed, Windows still pass so it is hard to debug.

Copy link
Contributor

@zacharybinger zacharybinger Nov 8, 2023

Choose a reason for hiding this comment

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

Instead of relaxing the bounds to None, did you try 0? I guess it doesn't matter since you changed the bounds back to a negative value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, my upper bound is set as 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh yes, I had the bounds backwards in my head since the deltaP values are negative, my mistake

domain=NegativeReals,
units=units_meta("pressure"),
doc=f"Pressure drop across {side}",
),
)
if self.config.pressure_change_type == PressureChangeType.fixed_per_stage:

@mem_side.Constraint(
self.flowsheet().config.time,
self.length_domain,
doc="Fixed pressure drop across unit",
)
def eq_pressure_drop(b, t, x):
return mem_side.deltaP_stage[t] == b.length * mem_side.dP_dx[t, x]

else:

@mem_side.Constraint(
self.flowsheet().config.time, doc="Pressure drop across unit"
)
def eq_pressure_drop(b, t):
return mem_side.deltaP_stage[t] == sum(
mem_side.dP_dx[t, x] * b.length / b.nfe
for x in b.difference_elements
)

def _add_mass_transfer(self):

units_meta = self.config.property_package.get_metadata().get_derived_units

# mass transfer
def mass_transfer_phase_comp_initialize(b, t, x, p, j):
return value(
self.feed_side.properties[t, x].get_material_flow_terms("Liq", j)
* self.recovery_mass_phase_comp[t, "Liq", j]
)

self.mass_transfer_phase_comp = Var(
self.flowsheet().config.time,
self.difference_elements,
self.config.property_package.phase_list,
self.config.property_package.component_list,
initialize=mass_transfer_phase_comp_initialize,
bounds=(0.0, 1e6),
domain=NonNegativeReals,
units=units_meta("mass")
* units_meta("time") ** -1
* units_meta("length") ** -1,
doc="Mass transfer to permeate",
)

@self.Constraint(
self.flowsheet().config.time,
self.difference_elements,
self.config.property_package.phase_list,
self.config.property_package.component_list,
doc="Mass transfer term",
)
def eq_mass_transfer_term(self, t, x, p, j):
return (
self.mass_transfer_phase_comp[t, x, p, j]
== -self.feed_side.mass_transfer_term[t, x, p, j]
)

# Feed and permeate-side connection
@self.Constraint(
self.flowsheet().config.time,
self.difference_elements,
self.config.property_package.phase_list,
self.config.property_package.component_list,
doc="Mass transfer from feed to permeate",
)
def eq_connect_mass_transfer(b, t, x, p, j):
return (
b.permeate_side.mass_transfer_term[t, x, p, j]
== -b.feed_side.mass_transfer_term[t, x, p, j]
)

@self.Constraint(
self.flowsheet().config.time,
self.difference_elements,
self.config.property_package.phase_list,
self.config.property_package.component_list,
doc="Permeate production",
)
def eq_permeate_production(b, t, x, p, j):
return (
-b.feed_side.mass_transfer_term[t, x, p, j]
== b.width * b.flux_mass_phase_comp[t, x, p, j]
)

def calculate_scaling_factors(self):

super().calculate_scaling_factors()

for (t, x, p, j), v in self.mass_transfer_phase_comp.items():
sf = iscale.get_scaling_factor(
self.feed_side.properties[t, x].get_material_flow_terms(p, j)
)
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, sf)
v = self.feed_side.mass_transfer_term[t, x, p, j]
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, sf)

Check warning on line 228 in watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py

View check run for this annotation

Codecov / codecov/patch

watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py#L228

Added line #L228 was not covered by tests
v = self.permeate_side.mass_transfer_term[t, x, p, j]
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, sf)

Check warning on line 231 in watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py

View check run for this annotation

Codecov / codecov/patch

watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py#L231

Added line #L231 was not covered by tests

if hasattr(self.feed_side, "deltaP_stage"):
for v in self.feed_side.deltaP_stage.values():
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, 1e-4)
if hasattr(self.permeate_side, "deltaP_stage"):
for v in self.permeate_side.deltaP_stage.values():
if iscale.get_scaling_factor(v) is None:
iscale.set_scaling_factor(v, 1e-4)
Loading
Loading