-
Notifications
You must be signed in to change notification settings - Fork 57
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
OARO 1D Model #1172
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 e76dbf0
getting test update from f2277f90
bknueven cad632e
Merge branch 'main' into oaro1d
bknueven 16c08d3
test
luohezhiming 27643ac
Merge remote-tracking branch 'upstream/main' into oaro1d
bknueven a4dae9f
light refactor of OARO0D
bknueven 1eb1c79
carrying over to OARO1D
bknueven f454554
starting to work on OARO1D test
bknueven ba0b4c9
add missing abstract method
bknueven 3ffabdb
checkpoint: one extra DOF in basic model
bknueven 7d35890
add
luohezhiming 4766c52
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming ef81bae
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 168bbaf
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming a09b4e9
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 44a22e8
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 1c1a135
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 401f997
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 258f6fe
delete redundant files
luohezhiming 2c994c3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 5b6baed
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 0afa551
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 479fb6d
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming b393ed0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 708ad0a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 5a69761
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 112415a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 93737c0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 3162e34
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 637b32d
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming ea4e066
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 84a2900
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 17bc5e3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming f816483
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming fea68e3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming c19fba5
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming dd86d76
Merge branch 'main' into oaro1d
adam-a-a 17dadcc
checking out last save by ben but passing off to zach/chenyu
adam-a-a 0754d21
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 9dcece1
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming a5325c9
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming c4bc3ef
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming bb8ca41
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 5afdc55
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 35ecf79
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming fb2a100
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 40b4de5
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 72f6f25
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming ece1d2f
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming a861a5b
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming d58a9a7
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 4968282
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming acfd9f6
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming a97fbe3
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 2fc2425
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 581dec0
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 3202970
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 625e610
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 2a37aca
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 1fa9316
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming c2a4f7d
Merge branch 'main' into OARO1D_chenyu
luohezhiming baff470
temporary edits
luohezhiming 3fe45d1
Add OARO 1D Model
luohezhiming da8fd13
delete practice files
luohezhiming 74811ea
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming a69c2ca
Merge branch 'main' into OARO1D_chenyu
luohezhiming 034fb48
code plinting
luohezhiming a89268c
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 3667a77
Merge branch 'main' into OARO1D_chenyu
luohezhiming b9994a7
code linting
luohezhiming 55c06dd
add test for water recovery
luohezhiming 09cf01e
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 70e1847
Merge branch 'main' into OARO1D_chenyu
luohezhiming 02cc515
rename test function name
luohezhiming 4070fa1
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 0d6fe1a
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 6c58099
minor revision
luohezhiming 59fb667
Merge branch 'main' into OARO1D_chenyu
luohezhiming 9a9d4db
add requires_idaes_solver
luohezhiming 25e34d9
reverse bound
luohezhiming 85f15b3
minor revisons
luohezhiming 598a1ab
relax deltaP bound
luohezhiming 0b8d450
add bound to deltaP
luohezhiming 0f09c3c
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 568d5b0
Merge branch 'main' into OARO1D_chenyu
adam-a-a 2c19ca0
Merge branch 'main' into OARO1D_chenyu
adam-a-a 5f82e05
Merge branch 'main' of https://github.com/watertap-org/watertap
luohezhiming 7f0532a
Merge branch 'main' into OARO1D_chenyu
luohezhiming 619a58f
resolve config number issue
luohezhiming c400188
Merge branch 'OARO1D_chenyu' of https://github.com/luohezhiming/water…
luohezhiming db6f5cf
Merge branch 'main' into OARO1D_chenyu
zacharybinger 4f6d2c3
Merge branch 'main' into OARO1D_chenyu
ksbeattie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 240 additions & 0 deletions
240
watertap/unit_models/osmotically_assisted_reverse_osmosis_1D.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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), | ||
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) | ||
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) | ||
|
||
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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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