Skip to content

Commit

Permalink
Update wnd.py to support new quadratic approximations in water netw…
Browse files Browse the repository at this point in the history
…ork model, improve documentation, and correct typos
  • Loading branch information
tristantc committed Jan 22, 2025
1 parent 50dd92e commit d2d8795
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions gdplib/water_network/wnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
The user can create each instance like this:
build_model(approximation='none')
build_model(approximation='quadratic')
build_model(approximation='quadratic_nonzero_origin')
build_model(approximation='quadratic_zero_origin')
build_model(approximation='piecewise')
The general model description can be summarized as follows:
Expand Down Expand Up @@ -83,7 +84,7 @@
# TU mass balances in the disjunct.


def build_model(approximation='quadratic'):
def build_model(approximation='none'):
"""
Builds a Pyomo ConcreteModel for Water Network Design.
Generates a Pyomo model for the water network design problem with the specified approximation for the capital cost term of the active treatment units.
Expand Down Expand Up @@ -300,7 +301,6 @@ def _to_stream_filter(m, val):

# Concentration of component j in feedstream i
for j, i, k in m.contaminant * (m.FSU * ['dm'] | m.FSU * m.inTU | m.feed_streams):
# print(j,i,k)
if i in m.feed:
m.conc[j, i, k].fix(feed.loc[k, j])
else:
Expand Down Expand Up @@ -533,7 +533,7 @@ def _no_cost(disj):
@m.Disjunction(m.TU)
def unit_exists_or_not(m, unit):
'''Disjunction: Unit exists or not.
This disjunctiont specifies if the treatment unit exists or does not exist.
This disjunction specifies if the treatment unit exists or does not exist.
Parameters
----------
Expand Down Expand Up @@ -700,7 +700,7 @@ def _unit_exists_onetoone_filter(unit_exists, val):
]
# Setting inlet flowrate bounds for the active treatment units.
unit_exists.flow_bound = pyo.ConstraintList(
doc='Flowrate bounds to/from active RU'
doc='Flowrate bounds to/from active TU'
)
[
unit_exists.flow_bound.add(
Expand Down Expand Up @@ -907,10 +907,14 @@ def _func(model, i, j, xp):
@unit_exists.Constraint(doc='Cost active TU')
def costTU(unit_exists):
"""Constraint: Cost of active treatment unit.
The constraint ensures that the cost of the active treatment unit is equal to the sum of an investment cost which is proportional to the total flow to 0.7 exponent and an operating cost which is proportional to the flow.
If approximation is quadratic, the investment cost is approximated by a quadratic function of the flow rate.
The constraint defines the cost of the active treatment unit as the sum of an investment cost and an operating cost.
The investment cost is proportional to the total flow raised to the power of 0.7 and the operating cost is proportional to the flow.
Based on the approximation given, the concave investment cost is calculated as follows:
If approximation is quadratic zero origin, the investment cost is approximated by a quadratic function of the flow rate with the origin at zero.
If approximation is quadratic nonzero origin, the investment cost is approximated by a quadratic function of the flow rate with origin different from zero. This approximation has a better fit than the quadratic zero origin.
If approximation is piecewise, the investment cost is approximated by a piecewise linear function of the flow rate.
If approximation is none, the investment cost is equal to the flow rate to the 0.7 exponent, the original concave function.
If approximation is none, the investment cost is equal to the flow rate raised to 0.7, the original concave function.
Parameters
----------
Expand All @@ -923,9 +927,9 @@ def costTU(unit_exists):
The constraint that the cost of the active treatment unit is equal to the sum of an investment cost and an operating cost.
"""
for mt, t in unit_exists.streams:
if approximation == 'quadratic':
if approximation == 'quadratic_zero_origin':
new_var = unit_exists.cost_var[unit]
elif approximation == 'quadratic2':
elif approximation == 'quadratic_nonzero_origin':
new_var = _g(unit_exists.flow[mt, unit])
elif approximation == 'piecewise':
new_var = unit_exists.cost_var[mt, unit]
Expand Down

0 comments on commit d2d8795

Please sign in to comment.