Skip to content

Commit

Permalink
Merge branch 'VMD' of https://github.com/ElmiraShamlou/watertap into VMD
Browse files Browse the repository at this point in the history
  • Loading branch information
ElmiraShamlou committed Dec 9, 2024
2 parents c225233 + c35900e commit 01f0519
Show file tree
Hide file tree
Showing 47 changed files with 2,341 additions and 2,129 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
pip show idaes-pse
echo '::endgroup::'
echo '::group::Output of "idaes get-extensions" command'
idaes get-extensions --verbose
idaes get-extensions --extra petsc --verbose
echo '::endgroup::'
- name: Add coverage report pytest options
if: matrix.coverage
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
pip show idaes-pse
echo '::endgroup::'
echo '::group::Output of "idaes get-extensions" command'
idaes get-extensions --verbose
idaes get-extensions --extra petsc --verbose
echo '::endgroup::'
- name: Run pytest
run: |
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
pip show idaes-pse
echo '::endgroup::'
echo '::group::Output of "idaes get-extensions" command'
idaes get-extensions --verbose
idaes get-extensions --extra petsc --verbose
echo '::endgroup::'
- name: Install Jupyter kernel
run: |
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
author = "NAWI"

# The full version, including alpha/beta/rc tags
release = "1.1.dev0"
release = "1.2.dev0"
# The short X.Y version
version = "1.1.dev0"
version = "1.2.dev0"
# -- General configuration ---------------------------------------------------


Expand Down
6 changes: 3 additions & 3 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create a Conda environment (in this example, named ``watertap``) where WaterTAP

.. code-block:: shell
conda create --name watertap --yes python=3.8 pip=21.1
conda create --name watertap --yes python=3.11
Activate the ``watertap`` environment using the command given below. If the environment was activated successfully, the environment's name will be displayed in the terminal prompt such as ``(watertap) project-directory $``.

Expand Down Expand Up @@ -58,7 +58,7 @@ Create a Conda environment (in this example, named ``watertap``) where WaterTAP

.. code-block:: shell
conda create --name watertap --yes python=3.8 pip=21.1
conda create --name watertap --yes python=3.11
Activate the ``watertap`` environment using the command given below. If the environment was activated successfully, the environment's name will be displayed in the terminal prompt such as ``(watertap) project-directory $``.

Expand Down Expand Up @@ -143,7 +143,7 @@ Create a Conda environment (in this example, named ``watertap-dev``) where Water

.. code-block:: shell
conda create --name watertap-dev --yes python=3.8 pip=21.1 && conda activate watertap-dev
conda create --name watertap-dev --yes python=3.11 && conda activate watertap-dev
Clone the WaterTAP repository to your local development machine using ``git clone``, then enter the newly created ``watertap`` subdirectory:

Expand Down
2 changes: 0 additions & 2 deletions docs/technical_reference/flowsheets/extended_BSM2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ Additional Variables
"Reactor 7 oxygen mass transfer coefficient",":math:`KLa_{R7}`", "240", ":math:`\text{hr}^{-1}`"
"Dissolved oxygen concentration at equilibrium",":math:`S_{O, eq}`", "8e-3", ":math:`\text{hr}^{-1}`"



Additional Constraints
----------------------

Expand Down
18 changes: 14 additions & 4 deletions docs/technical_reference/property_models/mc_aq_sol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Parameters
.. csv-table::
:header: "Description", "Symbol", "Parameter", "Index", "Units"

"Component molecular weight :sup:`1`", ":math:`m_N`", "mw_comp", "[j]", ":math:`\text{kg mol}^{-1}`"
"Component molecular weight :sup:`1`", ":math:`MW`", "mw_comp", "[j]", ":math:`\text{kg mol}^{-1}`"
"Stokes radius of solute", ":math:`r_h`", "radius_stokes_comp", "[j]", ":math:`\text{m}`"
"Molar volume of solute", ":math:`V`", "molar_volume_phase_comp", "[p, j]", ":math:`\text{m}^3 \text{ mol}^{-1}`"
"Dynamic viscosity", ":math:`\mu`", "visc_d_phase", "[p]", ":math:`\text{Pa s}`"
Expand Down Expand Up @@ -112,7 +112,11 @@ Properties
"Debye-Huckel constant A", ":math:`A`", "deby_huckel_constant", "none", ":math:`\text{dimensionless}`"
"Ionic Strength", ":math:`I`", "ionic_strength_molal", "none", ":math:`\text{mol kg}^{-1}`"
"Mass diffusivity of solute", ":math:`D`", "diffus_phase_comp", "[p, j]", ":math:`\text{m}^2 \text{ s}^{-1}`"

"Specific enthalpy", ":math:`\widehat{H}`", "enth_mass_phase", "[p]", ":math:`\text{J/kg}`"
"Enthalpy flow", ":math:`H`", "enth_flow", "None", ":math:`\text{J/s}`"
"Saturation pressure", ":math:`P_v`", "pressure_sat", "None", ":math:`\text{Pa}`"
"Total hardness as CaCO3",":math:`TH`","total_hardness", "None", ":math:`\text{mg/L}`"
"Total dissolved solids",":math:`TDS`","total_dissolved_solids", "None", ":math:`\text{mg/L}`"


Relationships
Expand All @@ -137,7 +141,13 @@ Relationships
"Phase electrical conductivity", ":math:`\lambda=\Lambda\sum_{j\in cation}{\left|z_j\right|n_j}`"
"Debye-Huckel constant", ":math:`A=\frac{\left(2 \pi N_A\right)^{0.5}}{log(10)} \left(\frac{\textbf{e}^2}{4 \pi \epsilon \epsilon_0 kT}\right)^{\frac{3}{2}}`"
"Ionic strength", ":math:`I=0.5\sum_{j\in ion}{z_j^2b_j}`"
"Component mass diffusivity :sup:`5`", ":math:`D\text{ specified in data argument}` or :math:`D \text{ }[\text{m}^2 \text{ s}^{-1}]=\frac{\chi_{1}}{(\mu \text{ }[\text{cP}])^{\chi_{2}}(V \text{ }[\text{cm}^3 \text{ mol}^{-1}])^{\chi_{3}}}`"
"Component mass diffusivity :sup:`5`", ":math:`D\text{ specified in data argument}` or :math:`D \text{ }=\frac{\chi_{1}}{(\mu \text{ }[\text{cP}])^{\chi_{2}}(V \text{ }[\text{cm}^3 \text{ mol}^{-1}])^{\chi_{3}}}`"
"Specific enthalpy", "Equations 25-27 in Nayar et al. (2016)"
"Enthalpy flow", ":math:`H = \sum_{j} M_j \cdotp \widehat{H}`"
"Saturation pressure", "Equations 5 and 6 in Nayar et al. (2016)"
"Total hardness as CaCO3",":math:`TH = \sum_{j \in \text{polyvalent cation set}} {n_j z_j} \frac{MW_{CaCO3}}{z_{CaCO3}}`"
"Total dissolved solids",":math:`TDS = \sum_{j \in \text{ion set}} m_j`"


.. note::

Expand Down Expand Up @@ -166,7 +176,7 @@ Physical/chemical constants

Scaling
-------
A comprehensive scaling factor calculation method is coded in this property package. Among the state variables (:math:`N, T, \text{and } p`), default scaling factors for :math:`T` and :math:`p` were set and do not need users' input, while, for :math:`N`, usually require a user input via an interface. The coding interface to set defalut scaling factor for :math:`N` and call the scaling calculation for other variables is the following.
A comprehensive scaling factor calculation method is coded in this property package. Among the state variables (:math:`N, T, \text{and } p`), default scaling factors for :math:`T` and :math:`p` were set and do not need users' input, while, for :math:`N`, usually require a user input via an interface. The coding interface to set default scaling factor for :math:`N` and call the scaling calculation for other variables is the following.

.. code-block::
Expand Down
12 changes: 3 additions & 9 deletions docs/technical_reference/property_models/seawater.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ Properties
"Latent heat of vaporization", ":math:`h_{vap}`", "dh_vap_mass", "None", ":math:`\text{J/kg}`"
"Diffusivity", ":math:`D`", "diffus_phase_comp", "[p]", ":math:`\text{m}^2\text{/s}`"
"Boiling point elevation", ":math:`BPE`", "boiling_point_elevation_phase", "[p]", ":math:`\text{K}`"


**The properties make use of the average molecular weight of sea salt, ≈ 31.40 g/mol, reported in the Reference-Composition Salinity Scale (Millero et al., 2008) to convert to moles.**

.. csv-table::
:header: "Description", "Symbol", "Variable", "Index", "Units"

"Component mole flowrate", ":math:`N_j`", "flow_mol_phase_comp", "[p, j]", ":math:`\text{mole/s}`"
"Component mole fraction", ":math:`y_j`", "mole_frac_phase_comp", "[p, j]", ":math:`\text{dimensionless}`"
"Molality", ":math:`Cm`", "molality_phase_comp", "['TDS']", ":math:`\text{mole/kg}`"
"Osmotic pressure", ":math:`\pi`", "pressure_osm_phase", "None", ":math:`\text{Pa}`"

**The properties make use of the average molecular weight of sea salt, ≈ 31.40 g/mol, reported in the Reference-Composition Salinity Scale (Millero et al., 2008) to convert to moles.**


Relationships
-------------
.. csv-table::
Expand All @@ -87,8 +83,6 @@ Relationships
"Diffusivity", "Equation 6 in Bartholomew et al. (2019)"
"Boiling point elevation", "Equation 36 in Sharqawy et al. (2010)"



Note: Osmotic pressure calculation (based on equation 48 in Nayar et al. (2016)) uses the density of water as a function of temperature (:math:`\rho_w`) and the ideal gas constant (:math:`R\text{, 8.314 J/mol}\cdotp\text{K}`), in addition to previously defined variables.

Scaling
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# update with a tag from the nawi-hub/idaes-pse
# when a version of IDAES newer than the latest stable release from PyPI
# will become needed for the watertap development
"idaes-pse==2.6.0rc0",
"idaes-pse==2.6.0",
]

# Arguments marked as "Required" below must be included for upload to PyPI.
Expand All @@ -37,7 +37,7 @@
setup(
name="watertap",
url="https://github.com/watertap-org/watertap",
version="1.1.dev0",
version="1.2.dev0",
description="WaterTAP modeling library",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
20 changes: 20 additions & 0 deletions tutorials/parameter_sweep_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
"*10/12/2023*\n"
]
},
{
"cell_type": "markdown",
"id": "cc2d54f8",
"metadata": {},
"source": [
"Please cite this notebook as\n",
"\n",
"```bibtex\n",
"@misc{howtouse_parameter_sweep,\n",
" title = \"Getting Started with the WaterTAP Parameter Sweep Tool (Citation Only)\",\n",
" keywords = \"eagle, IDAES, NAWI, parallel programming, parameter sweep, pyomo, sampling, water treatment, WaterTAP\",\n",
" author = \"Kinshuk Panda and Ben Knueven and Alexander Dudchenko and Ethan Young and Jeffrey Allen and Samuel Helman\",\n",
" year = \"2023\",\n",
" language = \"American English\",\n",
" series = \"Presented at the Advanced Process Systems Engineering Stakeholder Summit, 11-12 October 2023, Falls Church, Virginia\",\n",
" type = \"Other\",\n",
"}\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "a7a1d0df",
Expand Down
16 changes: 13 additions & 3 deletions watertap/core/membrane_channel_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class FrictionFactor(Enum):
"dynamic",
ConfigValue(
default=False,
domain=In([False]),
domain=Bool,
description="Dynamic model flag - must be False",
doc="""Indicates whether this model will be dynamic or not.
**default** - False. Membrane units do not yet support dynamic
Expand All @@ -120,7 +120,7 @@ class FrictionFactor(Enum):
"has_holdup",
ConfigValue(
default=False,
domain=In([False]),
domain=Bool,
description="Holdup construction flag - must be False",
doc="""Indicates whether holdup terms should be constructed or not.
**default** - False. Membrane units do not have defined volume, thus
Expand Down Expand Up @@ -1011,7 +1011,17 @@ def calculate_scaling_factors(self):

# helper for validating configuration arguments for this CV
def validate_membrane_config_args(unit):

if unit.config.dynamic and unit.config.has_holdup:
if not (
(unit.config.pressure_change_type != PressureChangeType.fixed_per_stage)
or (
unit.config.mass_transfer_coefficient
== MassTransferCoefficient.calculated
)
):
raise ConfigurationError(
f"dynamics=True and has_holdup=True will not work while pressure_change_type={unit.config.pressure_change_type} and mass_tranfer_coefficient={unit.config.mass_transfer_coefficient}\n. To enable dynamics, choose any other configuration option for pressure_change_type or mass_transfer_coefficient."
)
if (
unit.config.pressure_change_type is not PressureChangeType.fixed_per_stage
and unit.config.has_pressure_change is False
Expand Down
7 changes: 7 additions & 0 deletions watertap/core/plugins/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ def __init__(self, **kwds):

self._value_cache = pyo.ComponentMap()

def __getattr__(self, attr):
# if not available here, ask the base_solver
try:
return getattr(pyo.SolverFactory(self._base_solver), attr)
except AttributeError:
raise

def restore_initial_values(self, blk):
for var in blk.component_data_objects(pyo.Var, descend_into=True):
var.set_value(self._value_cache[var], skip_validation=True)
Expand Down
51 changes: 51 additions & 0 deletions watertap/costing/tests/test_costing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

import pytest

from pyomo.util.check_units import assert_units_consistent
import pyomo.environ as pyo
import idaes.core as idc

from watertap.costing.watertap_costing_package import WaterTAPCosting
import watertap.flowsheets.lsrro.lsrro as lsrro


@pytest.mark.component
Expand Down Expand Up @@ -134,3 +136,52 @@ def test_watertap_costing_package():
m.fs.costing.capital_recovery_factor.fix()
# no error, wacc, capital_recovery_factor fixed
m.fs.costing.initialize()


@pytest.mark.component
def test_breakdowns():
m = lsrro.build()

m.fs.BoosterPumps[:].control_volume.work[0.0].value = 42e6
m.fs.EnergyRecoveryDevices[:].control_volume.work[0.0].value = -42e6

m.fs.costing.add_specific_electrical_carbon_intensity(
m.fs.product.properties[0].flow_vol
)

assert_units_consistent(m)

m.fs.costing.initialize()

total_LCOW = pyo.value(m.fs.costing.LCOW)

summed_aggregates = pyo.value(
sum(m.fs.costing.LCOW_aggregate_direct_capex.values())
+ sum(m.fs.costing.LCOW_aggregate_indirect_capex.values())
+ sum(m.fs.costing.LCOW_aggregate_fixed_opex.values())
+ sum(m.fs.costing.LCOW_aggregate_variable_opex.values())
# electricity is counted both in the aggregate variable opex
# per unit and per flow, so it is double-counted in this sum
- m.fs.costing.LCOW_aggregate_variable_opex["electricity"]
)
assert pytest.approx(total_LCOW) == summed_aggregates

summed_components = pyo.value(
sum(m.fs.costing.LCOW_component_direct_capex.values())
+ sum(m.fs.costing.LCOW_component_indirect_capex.values())
+ sum(m.fs.costing.LCOW_component_fixed_opex.values())
+ sum(m.fs.costing.LCOW_component_variable_opex.values())
)
assert pytest.approx(total_LCOW) == summed_components

sec = pyo.value(m.fs.costing.specific_energy_consumption)
summed_sec = pyo.value(
sum(m.fs.costing.specific_energy_consumption_component.values())
)
assert pytest.approx(sec) == summed_sec

seci = pyo.value(m.fs.costing.specific_electrical_carbon_intensity)
summed_seci = pyo.value(
sum(m.fs.costing.specific_electrical_carbon_intensity_component.values())
)
assert pytest.approx(seci) == summed_seci
Loading

0 comments on commit 01f0519

Please sign in to comment.