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

Hydraulics linearization #285

Merged
merged 58 commits into from
Apr 1, 2024

Conversation

Sourabhhkt
Copy link
Contributor

@Sourabhhkt Sourabhhkt commented Dec 5, 2023

Fixes/Addresses/Summary/Motivation:

Co-optimize method had two non-linearities: Hazen-William Rule and Pump Cost rule. These non-linearities result in a very slow computation by non-linear solvers. We make piecewise linearization of the term flow raised to the power 1.85 in the RHS of Hazen-Williams equation. In the LHS of the same equation, we model the product of pressure change and diameter selection binaries with a set of linear constraints. Finally, for the variable (electricity) component of the pump cost is modeled by compartmentalization of the volumetric flow through the pump. Thus, the formulation is completely linearized.

Changes proposed in this PR:

  • the term in RHS of Hazen-William equation is modeled using a piecewise linear function.
    Brief idea: Consider a non-linear function of one variable with any point on the curve represented by (x, f(x)). We can fit a piecewise linear function as an approximation to f(x). Say the new point (x, y) is an approximation of the original point as shown in the figure below. Then, it is possible to model this (x, y) as a system of linear constraints. This can be done by introducing logarithmic number of binary variables as the number of sections of piecewise linear graph. Refer section 2 of https://link.springer.com/chapter/10.1007/978-1-4614-1927-3_10
    Piecewise_linear_fit

  • For LHS of the Hazen-William equation, we have a multiplication of non-negative continuous variable(pressure drop) and binary variable(diameter choice). When we have such a product, it can be modeled using linear constraints. For example, consider a term P = Hz where H is a non-negative continuous variable with upper bound M and z is a binary variable. Then we can model P using
    a) P>=0 b) P<=H c) P<=Mz d) P>= H - M(1-z)

  • In Pump cost rule, the variable cost is modeled using comparmentalization of flow. For example, say the section which the flow is in is 20000bbl/day to 30000bbl/day. Then the variable cost would be modeled as vρgΔH*20000

  • The documentation of hydraulics is updated to reflect the proposed changes in the formulation.

  • Node pressure rule for co_optimize method is corrected in the documentation. Earlier it had flipped sign of pump head and valve release.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my
contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.md file
    at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has
    rights to intellectual property that includes these contributions, I represent that I have
    received permission to make contributions and grant the required license on behalf of that
    employer.

@tarnold17 tarnold17 added the Priority:Normal Normal Priority Issue or PR label Dec 5, 2023
@@ -4280,7 +4435,7 @@ def PumpCostRule(b, l1, l2):
* mh.p_rhog
* 1e3 # convert the kUSD/kWh to kUSD/Ws
* sum(
b.v_PumpHead[l1, l2, t]
1609
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider exploring alternative methods to linearize the pump cost function in the co-optimize approach rather than replacing the pump head with constant values. Co-optimize is designed to incorporate pump cost within the objective function, accounting for elevation changes and frictional losses. Using a constant pump head overlooks the critical impact of elevation changes and frictional losses in the network on the objective cost. Without variable pump heads, hydraulic post-processing might suffice instead of co-optimize.

Additionally, it's important to note that we cannot use a constant number from a small case study and generalize it to all other case studies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment and feedback! The pricing for the variable component of pump now has the pump head variable. The linearization is now done based on the flow. Say grid size for flow is 10000 bbl/day. Then for 0<flow<10000, the flow is assumed to be constant 0, for flow 10000<flow<20000, the flow is assumed to be constant 10000, and so on.

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Attention: Patch coverage is 95.94595% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 88.64%. Comparing base (889ed4d) to head (3950d9f).

Files Patch % Lines
...anagement/strategic_produced_water_optimization.py 94.05% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #285      +/-   ##
==========================================
+ Coverage   88.37%   88.64%   +0.26%     
==========================================
  Files          23       23              
  Lines        5059     5203     +144     
==========================================
+ Hits         4471     4612     +141     
- Misses        588      591       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@melody-shellman melody-shellman removed their request for review January 5, 2024 15:39
Copy link
Contributor

@tarnold17 tarnold17 left a comment

Choose a reason for hiding this comment

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

Nice work - looks good for the most part to me, but a bit of cleanup is needed.

Also, would it be possible to develop a Jupyter notebook tutorial showing/explaining how to use the Hydraulics.co_optimize_linearized method? That would be a nice touch if wouldn't take too long to put together.

docs/model_library/Hydraulics/index.rst Outdated Show resolved Hide resolved
docs/model_library/Hydraulics/index.rst Outdated Show resolved Hide resolved
docs/model_library/Hydraulics/index.rst Outdated Show resolved Hide resolved
docs/model_library/Hydraulics/index.rst Outdated Show resolved Hide resolved
docs/model_library/Hydraulics/index.rst Outdated Show resolved Hide resolved
Sourabhhkt and others added 23 commits March 13, 2024 21:11
Binary variable description update
error message for solver not found.
Uncommented y_BeneficialReuse fixing
Removed opt solver and made it to the solver specified by the user
Added jupyter notebook  to test hydraulics co_optimize and post_process.
…lics, support all hydraulics options in report generation
Copy link
Contributor

@tarnold17 tarnold17 left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Contributor

@ElmiraShamlou ElmiraShamlou left a comment

Choose a reason for hiding this comment

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

Approved. Great work!

@tarnold17 tarnold17 merged commit 721d92a into project-pareto:main Apr 1, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants