Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakshi21299 committed Apr 11, 2024
2 parents 37dd191 + edff9c6 commit 70d52f2
Show file tree
Hide file tree
Showing 29 changed files with 3,656 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- install-mode: user
pip-install-target: ".[testing]"
- install-mode: dev
python-version: '3.8'
python-version: '3.9'
cov-report: true
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
- name: Install (dev mode)
run: |
pip --no-cache-dir install --progress-bar off -r requirements-dev.txt
Expand Down
152 changes: 150 additions & 2 deletions docs/model_library/Hydraulics/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ a) Hydraulics.false: This option allows the user to skip the hydraulics computat
b) Hydraulics.post_process: In this method, the basic PARETO strategic model is solved as step 1, and then using the optimal flows and network design, the hydraulics block containing constraints for pressure balances and losses is solved as step 2. In this case, as only the hydraulics model block solved for the objective of minimizing cost, the optimal values for variables included in the main strategic model and obtained from step 1 remain unaffected.

c) Hydraulics.co_optimize: In this method, the hydraulics model block is solved together with the strategic model. However, as the flow and diameter are variables in the strategic model, the addition of hydraulics block makes the model a mixed integer nonlinear programming (MINLP) model. In order to solve this MINLP model, the strategic model without the hydraulics constraints is solved as step 1 to determine a good initial state for all variables and constraints.

d) Hydraulics.co_optimize_linearized: This is a linearized approximated model for the co_optimize method designed to give solutions quickly in a realistic time frame.

Note: The MINLP as currently implemented requires the following MINLP solvers: SCIP and BARON. The model is first solved using BARON (if available) to determine a feasible solution and then using SCIP.
Some subtle differences in model components such as in the definition of variables and parameters have been made to avoid nonlinearities and allow the user to use the same solver for solving the post-process method as used for the strategic model. These differences will be shown in the description of mathematical notation and formulation below.
Expand Down Expand Up @@ -189,12 +191,21 @@ Allows pumping only if a pump exists in a pipeline.

.. math::
\textcolor{blue}{\tilde{l},l \in LLA}:
\textcolor{red}{P_{l,t}} + \textcolor{green}{\zeta_{l}} \cdot \textcolor{green}{\rho.g}
= \textcolor{red}{P_{\tilde{l},t}} + \textcolor{green}{\zeta_{\tilde{l}}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{l,\tilde{l},t}^{Valve}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{\tilde{l},l,t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Valve}} \cdot \textcolor{green}{\rho.g}
.. math::
\textcolor{blue}{\tilde{l},l \notin LLA}:
\textcolor{red}{P_{l,t}} + \textcolor{green}{\zeta_{l}} \cdot \textcolor{green}{\rho.g}
= \textcolor{red}{P_{\tilde{l},t}} + \textcolor{green}{\zeta_{\tilde{l}}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Valve}} \cdot \textcolor{green}{\rho.g}
**Pump cost rule:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}`

Expand All @@ -205,4 +216,141 @@ Allows pumping only if a pump exists in a pipeline.
\textcolor{red}{C_{l,\tilde{l}}^{Pump}} = \textcolor{green}{\nu^{Pump}} \cdot \textcolor{red}{y_{l,\tilde{l},[t]}^{Pump}}
+ \textcolor{green}{\nu^{Electricity}} \cdot \textcolor{green}{\rho.g} \cdot \sum_{t \in T}\textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{red}{F_{l,\tilde{l},t}^{Piped}}
**Linearizing the Equations/constraints specific to the co_optimize method**

**Parameters**
:math:`\textcolor{green}{\Delta_I}` = Length of interval of flows for building piecewise linear model
:math:`M` = Large enough constant

**Binary Variables**

:math:`\textcolor{red}{z_{l,\tilde{l},t, i}},i\in \{0,1,2,..., \lceil 70000/\textcolor{green}{\Delta_I}\rceil - 1\}` = Intermediate binary variables to determine the section of the piecewise linear graph.


**Continuous Variables**

:math:`\textcolor{red}{\lambda_{l,\tilde{l},t,i}}, i\in \{0,1,2,..., \lceil 70000/\textcolor{green}{\Delta_I}\rceil\}` = Intermediate continuous variables, convex combination multipliers.

:math:`\textcolor{red}{term_{l,\tilde{l},t}}` = Continuous variables for flow raised to the power 1.85 (in RHS of Hazen-Williams).

:math:`\textcolor{red}{term2_{l,\tilde{l},t, d}}` = Continuous variables for the product of pressure drop and binary to select diameter (in LHS of Hazen-Williams).

:math:`\textcolor{red}{ec_{l,\tilde{l},t}}` = Node pressure

:math:`\textcolor{red}{Z^{Hydraulics}}` = Continuous variables for electricity cost for a particular pump at particular time period.


**Effective diameter rule:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}`

We remove this constraint. When effective diameter is required, we would use the expression of binaries.

**Setting term in RHS:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}`

Set the right hand side term flow to the power 1.85 in Hazen-Williams equation.

.. math::
\textcolor{red}{F_{l,\tilde{l},t}^{Piped}}
= \sum_{i \in \{0,1,2,..,\lceil 70000/\textcolor{green}{\Delta_I} \rceil\}}i \cdot \textcolor{green}{\Delta_I} \cdot \textcolor{red}{\lambda_{l, \tilde{l}, t, i}}
.. math::
\textcolor{red}{term_{l,\tilde{l},t}}
= \sum_{i \in \{0,1,2,..,\lceil 70000/\textcolor{green}{\Delta_I} \rceil\}}(1.84 \times 10^{-6} \cdot i \cdot \textcolor{green}{\Delta_I})^{1.85} \cdot \textcolor{red}{\lambda_{l,\tilde{l},t, i}}
**Sum of convex multipliers is one** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}`


.. math::
\sum_{i \in \{0,1,2,..,\lceil 70000/\textcolor{green}{\Delta_I} \rceil - 1\}} \textcolor{red}{z_{l,\tilde{l},t, i}} = 1
**Sum of binaries determining the section of pieccewise linear is one** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}`


.. math::
\sum_{i \in \{0,1,2,..,\lceil 70000/\textcolor{green}{\Delta_I} \rceil\}} \textcolor{red}{\lambda_{l,\tilde{l},t, i}} = 1
**Only two convex multipliers are non-zero** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}, \textcolor{blue}{j \in} \textcolor{blue}{\{0,1,2,..,\lceil 70000/\Delta_I \rceil-1\}}`

.. math::
\textcolor{red}{\lambda_{l,\tilde{l},t, 1} } \leq z_1
.. math::
\textcolor{red}{\lambda_{l,\tilde{l},t, i} } \leq z_i + z_{i-1} \forall i \in \{2,3,...,\lceil 70000/\Delta_I \rceil-1\}
.. math::
\textcolor{red}{\lambda_{l,\tilde{l},t, \lceil 70000/\Delta_I \rceil} } \leq z_{\lceil 70000/\Delta_I \rceil-1}
**Setting term in LHS:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}, \textcolor{blue}{d \in D}`

Set the product of pressure change and binary diameter selection variables by the following set of constraints.

.. math::
\textcolor{red}{term2_{l,\tilde{l},t,d}} \leq \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}}
.. math::
\textcolor{red}{term2_{l,\tilde{l},t,d}} \leq M \cdot \textcolor{red}{y^{Pipeline}_{l,\tilde{l}, d}}
.. math::
\textcolor{red}{term2_{l,\tilde{l},t,d}} \geq \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}} - M \cdot (1 - \textcolor{red}{y^{Pipeline}_{l,\tilde{l}, d}})
**Hazen-Williams based frictional head loss calculation:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}`

Calculate head loss using Hazen-Williams equation. Note that units for all terms in this equation are in SI units so, appropriate conversion factors must be added.

.. math::
\sum_{d \in D}\textcolor{red}{term2_{l,\tilde{l},t,d}} \cdot (\textcolor{green}{D_{l,\tilde{l}}^{Existing}} + \textcolor{green}{\delta_{d}^{Pipeline}})^{4.87}
= 10.704 \cdot \textcolor{red}{term_{l,\tilde{l},t}^{Piped}} / (\textcolor{green}{\iota^{CHW}})^{1.85} \cdot \textcolor{green}{\lambda_{l,\tilde{l}}^{Pipeline}}
**Node pressure rule:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{t \in T}`

Pressure constraint based on Bernoulli's energy balance equation.

.. math::
\textcolor{blue}{\tilde{l},l \in LLA}:
\textcolor{red}{P_{l,t}} + \textcolor{green}{\zeta_{l}} \cdot \textcolor{green}{\rho.g}
= \textcolor{red}{P_{\tilde{l},t}} + \textcolor{green}{\zeta_{\tilde{l}}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{\tilde{l},l,t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Valve}} \cdot \textcolor{green}{\rho.g}
.. math::
\textcolor{blue}{\tilde{l},l \notin LLA}:
\textcolor{red}{P_{l,t}} + \textcolor{green}{\zeta_{l}} \cdot \textcolor{green}{\rho.g}
= \textcolor{red}{P_{\tilde{l},t}} + \textcolor{green}{\zeta_{\tilde{l}}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Friction, HW}} \cdot \textcolor{green}{\rho.g}
- \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} \cdot \textcolor{green}{\rho.g}
+ \textcolor{red}{H_{l,\tilde{l},t}^{Valve}} \cdot \textcolor{green}{\rho.g}
**Electricity cost rule:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}, \textcolor{blue}{j \in} \textcolor{blue}{\{0,1,2,..,\lceil 70000/\Delta_I \rceil-1\}}`

Calculate electricity (variable) cost of pump at every time period.

.. math::
\textcolor{red}{ec_{l,\tilde{l},t}} \geq \textcolor{green}{\nu^{Electricity}} \cdot \textcolor{green}{\rho.g} \cdot j \cdot \textcolor{green}{\Delta_I} \cdot \textcolor{red}{H_{l,\tilde{l},t}^{Pump}} - M (1 - z_j)
**Pump cost rule:** :math:`\forall \textcolor{blue}{l,\tilde{l} \in LLA}`

Allows pumping only if a pump exists in a pipeline.

.. math::
\textcolor{red}{C_{l,\tilde{l}}^{Pump}} = \textcolor{green}{\nu^{Pump}} \cdot \textcolor{red}{y_{l,\tilde{l},[t]}^{Pump}}
+ \sum_{t \in T} \textcolor{red}{ec_{l,\tilde{l},t}}
125 changes: 125 additions & 0 deletions docs/utilities/Earthquake_Distance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Earthquake Distance Function
============================



The following function is used to conveniently acquire earthquake data for subsurface risk analysis.

+--------------------------------+---------------------------------------+
| Function | Section |
+================================+=======================================+
| calculate_earthquake_distances | :ref:`calculate_earthquake_distances` |
+--------------------------------+---------------------------------------+



.. _calculate_earthquake_distances:

Calculate Earthquake Distances
------------------------------

**Method Description:**

This method uses the `API <https://earthquake.usgs.gov/fdsnws/event/1/>`_ of the USGS `Earthquake Hazards Program <https://www.usgs.gov/programs/earthquake-hazards>`_ and the `RESTful API <https://maps.texnet.beg.utexas.edu/arcgis/rest/services/catalog/catalog_all/MapServer/0/>`_ of the `TexNet Earthquake Catalog <https://www.beg.utexas.edu/texnet-cisr/texnet/earthquake-catalog/>`_ to collect earthquake data and calculate distances from input saltwater disposal (SWD) well coordinates.
The method accepts the following input arguments:

- swd_latlons:
REQUIRED. Defines a list of dictionaries with a SWD well ID (swd_id), its decimal latitude (lat) and longitude (lon).
For example::

[
{"swd_id": 1, "lat": 32.262, "lon": -101.931},
{"swd_id": 2, "lat": 31.682, "lon": -104.401},
]

The SWD well IDs will be reported in the output list.

- api:
OPTIONAL. Specifies either the USGS or TexNet API.

* ``"usgs"``: Use the USGS API (default)
* ``"texnet"``: Use the TexNet API

- max_radius_mi:
OPTIONAL. Specifies the maximum radius in miles from a SWD well for earthquake data collection.
By default, it is 5.59 miles.

- min_magnitude:
OPTIONAL. Specifies the minimum earthquake magnitude for earthquake data colleciton.
By default, it is 3.

- min_date:
OPTIONAL. Specifies the minimum date in YYYY-MM-DD for earthquake data collection.
By default, it is None, which indicates no limit.

- max_date:
OPTIONAL. Specifies the maximum date in YYYY-MM-DD for earthquake data collection.
By default, it is None, which indicates no limit.

- save:
OPTIONAL. Specifies an output filename in \*.csv or \*.xlsx.
If this argument is specified, the output will be saved as a file.
It only supports the CSV and XLSX formats.
The XLSX format requires the pandas and openpyxl modules.
By default, it is None, which means no output file.

- overwrite:
OPTIONAL. Specifies whether or not to overwrite the save output file.
If a file given in the save argument exists, passing True to this argument will overwrite the file.
By default, it is False.

The output of this method is a list of dictionaries containing the input SWD well ID (swd_id), earthquake ID (eq_id), event time (time), distance in miles to the SWD well (distance_mi), and its magnitude (magnitude).
For example::

[
{
"swd_id": 1,
"eq_id": "tx2024fukh",
"time": "2024-03-23 01:36:02",
"distance_mi": 0.9231348790234829,
"magnitude": 3
},
{
"swd_id": 2,
"eq_id": "tx2024emvg",
"time": "2024-03-04 15:31:07",
"distance_mi": 2.200703681215228,
"magnitude": 3.3
}
]


**How to Use**

Example of how this method is used::

swd_latlons = [
{"swd_id": 1, "lat": 32.251, "lon": -101.940},
{"swd_id": 2, "lat": 31.651, "lon": -104.410},
]

earthquake_distances = calculate_earthquake_distances(
swd_latlons, "texnet", save="eq_dist_texnet_results.csv", overwrite=True
)
earthquake_distances = calculate_earthquake_distances(
swd_latlons, "texnet", save="eq_dist_texnet_results.xlsx", overwrite=True
)
print("# TexNet API\n", json.dumps(earthquake_distances, indent=1))

earthquake_distances = calculate_earthquake_distances(swd_latlons)
print("# USGS API\n", json.dumps(earthquake_distances, indent=1))

earthquake_distances = calculate_earthquake_distances(
swd_latlons, min_date="2024-03-20"
)
print("# USGS API\n", json.dumps(earthquake_distances, indent=1))

earthquake_distances = calculate_earthquake_distances(
swd_latlons, max_date="2024-03-20"
)
print("# USGS API\n", json.dumps(earthquake_distances, indent=1))

earthquake_distances = calculate_earthquake_distances(
swd_latlons, min_date="2024-03-23", max_date="2024-03-23"
)
print("# USGS API\n", json.dumps(earthquake_distances, indent=1))
1 change: 1 addition & 0 deletions docs/utilities/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ PARETO project provides a set of user-friendly utility methods to display and an

Get_Data
Results
Earthquake_Distance

Loading

0 comments on commit 70d52f2

Please sign in to comment.