wntr.network.model module

The wntr.network.model module includes methods to define a water network model.

class wntr.network.model.WaterNetworkModel(inp_file_name=None)[source]

Bases: object

Water network model class.

Parameters:

inp_file_name: string (optional)

Directory and filename of EPANET inp file to load into the WaterNetworkModel object.

Attributes

control_name_list Returns a list of the names of all controls.
curve_name_list Returns a list of the names of all curves.
junction_name_list Returns a list of the names of all junctions.
link_name_list Returns a list of the names of all links.
node_name_list Returns a list of the names of all nodes.
num_controls Returns the number of controls in the water network model.
num_curves Returns the number of curves in the water network model.
num_junctions Returns the number of junctions in the water network model.
num_links Returns the number of links in the water network model.
num_nodes Returns the number of nodes in the water network model.
num_patterns Returns the number of patterns in the water network model.
num_pipes Returns the number of pipes in the water network model.
num_pumps Returns the number of pumps in the water network model.
num_reservoirs Returns the number of reservoirs in the water network model.
num_sources Returns the number of sources in the water network model.
num_tanks Returns the number of tanks in the water network model.
num_valves Returns the number of valves in the water network model.
pattern_name_list Returns a list of the names of all patterns.
pipe_name_list Returns a list of the names of all pipes.
pump_name_list Returns a list of the names of all pumps.
reservoir_name_list Returns a list of the names of all reservoirs.
source_name_list Returns a list of the names of all sources.
tank_name_list Returns a list of the names of all tanks.
valve_name_list Returns a list of the names of all valves.

Methods

add_control(name, control_object) Adds a control to the water network model.
add_curve(name, curve_type, xy_tuples_list) Adds a curve to the water network model.
add_junction(name[, base_demand, …]) Adds a junction to the water network model.
add_pattern(name[, pattern]) Adds a pattern to the water network model.
add_pipe(name, start_node_name, end_node_name) Adds a pipe to the water network model.
add_pump(name, start_node_name, end_node_name) Adds a pump to the water network model.
add_pump_outage(pump_name, start_time, end_time) Adds a pump outage to the water network model.
add_reservoir(name[, base_head, …]) Adds a reservoir to the water network model.
add_source(name, node_name, source_type, quality) Adds a source to the water network model.
add_tank(name[, elevation, init_level, …]) Adds a tank to the water network model.
add_valve(name, start_node_name, end_node_name) Adds a valve to the water network model.
controls() Returns a generator to iterate over all controls.
curves() Returns a generator to iterate over all curves.
get_control(name) Returns the control object of a specific control.
get_curve(name) Returns the curve object of a specific curve.
get_graph_deep_copy() Returns a deep copy of the WaterNetworkModel networkx graph.
get_link(name) Returns the link object of a specific link.
get_links_for_node(node_name[, flag]) Returns a list of links connected to a node.
get_node(name) Returns the node object of a specific node.
get_node_coordinates([name]) Returns node coordinates.
get_pattern(name) Returns the pattern object of a specific pattern.
get_source(name) Returns the source object of a specific source.
junctions() Returns a generator to iterate over all junctions.
links([link_type]) Returns a generator to iterate over all links of link_type.
nodes([node_type]) Returns a generator to iterate over all nodes of a specific node type.
patterns() Returns a generator to iterate over all patterns.
pipes() Returns a generator to iterate over all pipes.
pumps() Returns a generator to iterate over all pumps.
query_link_attribute(attribute[, operation, …]) Query link attributes, for example get all pipe diameters > threshold.
query_node_attribute(attribute[, operation, …]) Query node attributes, for example get all nodes with elevation <= threshold.
read_inpfile(filename) Defines water network model components from an EPANET INP file.
remove_control(name) Removes a control from the water network model.
remove_curve(name) Removes a curve from the water network model.
remove_link(name[, with_control]) Removes a link from the water network model.
remove_node(name[, with_control]) Removes a node from the water network model.
remove_pattern(name) Removes a pattern from the water network model.
remove_source(name) Removes a source from the water network model.
reservoirs() Returns a generator to iterate over all reservoirs.
reset_demand(demand[, pattern_prefix]) Resets demands using values in a DataFrame.
reset_initial_values() Resets all initial values in the network.
scale_node_coordinates(scale) Scales node coordinates, using 1:scale.
set_node_coordinates(name, coordinates) Sets the node coordinates in the networkx graph.
sources() Returns a generator to iterate over all sources.
split_pipe(pipe_name_to_split, …[, …]) Splits a pipe by adding a junction and one new pipe segment.
tanks() Returns a generator to iterate over all tanks.
valves() Returns a generator to iterate over all valves.
write_inpfile(filename[, units]) Writes the current water network model to an EPANET INP file.
add_junction(name, base_demand=0.0, demand_pattern=None, elevation=0.0, coordinates=None)[source]

Adds a junction to the water network model.

Parameters:

name : string

Name of the junction.

base_demand : float

Base demand at the junction.

demand_pattern : string or Pattern

Name of the demand pattern or the actual Pattern object

elevation : float

Elevation of the junction.

coordinates : tuple of floats

X-Y coordinates of the node location.

add_tank(name, elevation=0.0, init_level=3.048, min_level=0.0, max_level=6.096, diameter=15.24, min_vol=None, vol_curve=None, coordinates=None)[source]

Adds a tank to the water network model.

Parameters:

name : string

Name of the tank.

elevation : float

Elevation at the Tank.

init_level : float

Initial tank level.

min_level : float

Minimum tank level.

max_level : float

Maximum tank level.

diameter : float

Tank diameter.

min_vol : float

Minimum tank volume.

vol_curve : Curve object

Curve object

coordinates : tuple of floats

X-Y coordinates of the node location.

Raises:

ValueError

If init_level greater than max_level or less than min_level

add_reservoir(name, base_head=0.0, head_pattern=None, coordinates=None)[source]

Adds a reservoir to the water network model.

Parameters:

name : string

Name of the reservoir.

base_head : float, optional

Base head at the reservoir.

head_pattern : string or Pattern

Name of the head pattern or the actual Pattern object

coordinates : tuple of floats, optional

X-Y coordinates of the node location.

add_pipe(name, start_node_name, end_node_name, length=304.8, diameter=0.3048, roughness=100, minor_loss=0.0, status='OPEN', check_valve_flag=False)[source]

Adds a pipe to the water network model.

Parameters:

name : string

Name of the pipe.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

length : float, optional

Length of the pipe.

diameter : float, optional

Diameter of the pipe.

roughness : float, optional

Pipe roughness coefficient.

minor_loss : float, optional

Pipe minor loss coefficient.

status : string, optional

Pipe status. Options are ‘Open’ or ‘Closed’.

check_valve_flag : bool, optional

True if the pipe has a check valve. False if the pipe does not have a check valve.

add_pump(name, start_node_name, end_node_name, info_type='POWER', info_value=50.0, speed=1.0, pattern=None)[source]

Adds a pump to the water network model.

Parameters:

name : string

Name of the pump.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

info_type : string, optional

Type of information provided for a pump. Options are ‘POWER’ or ‘HEAD’.

info_value : float or Curve object, optional

Float value of power in KW. Head curve object.

speed: float

Relative speed setting (1.0 is normal speed)

pattern: str or Pattern

ID of pattern for speed setting

add_valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, setting=0.0)[source]

Adds a valve to the water network model.

Parameters:

name : string

Name of the valve.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

diameter : float, optional

Diameter of the valve.

valve_type : string, optional

Type of valve. Options are ‘PRV’, etc.

minor_loss : float, optional

Pipe minor loss coefficient.

setting : float or string, optional

pressure setting for PRV, PSV, or PBV, flow setting for FCV, loss coefficient for TCV, name of headloss curve for GPV.

add_pattern(name, pattern=None)[source]

Adds a pattern to the water network model.

The pattern can be either a list of values (list, numpy array, etc.) or a Pattern object. The Pattern class has options to automatically create certain types of patterns, such as a single, on/off pattern (previously created using the start_time and stop_time arguments to this function) – see the class documentation for examples.

Warning

Patterns must be added to the model prior to adding any model element that uses the pattern, such as junction demands, sources, etc. Patterns are linked by reference, so changes to a pattern affects all elements using that pattern.

Warning

Patterns always use the global water network model options.time values. Patterns will not be resampled to match these values, it is assumed that patterns created using Pattern(…) or Pattern.BinaryPattern(…) object used the same pattern timestep value as the global value, and they will be treated accordingly.

Parameters:

name : string

Name of the pattern.

pattern : list of floats or Pattern

A list of floats that make up the pattern, or a Pattern object.

Raises:

ValueError

If adding a pattern with name that already exists.

add_curve(name, curve_type, xy_tuples_list)[source]

Adds a curve to the water network model.

Parameters:

name : string

Name of the curve.

curve_type : string

Type of curve. Options are HEAD, EFFICIENCY, VOLUME, HEADLOSS.

xy_tuples_list : list of (x, y) tuples

List of X-Y coordinate tuples on the curve.

add_source(name, node_name, source_type, quality, pattern=None)[source]

Adds a source to the water network model.

Parameters:

name : string

Name of the source

node_name: string

Injection node.

source_type: string

Source type, options = CONCEN, MASS, FLOWPACED, or SETPOINT

quality: float

Source strength in Mass/Time for MASS and Mass/Volume for CONCEN, FLOWPACED, or SETPOINT

pattern: string or Pattern object

Pattern name or object

add_control(name, control_object)[source]

Adds a control to the water network model.

Parameters:

name : string

control object name.

control_object : Control object

Control object.

add_pump_outage(pump_name, start_time, end_time)[source]

Adds a pump outage to the water network model.

Parameters:

pump_name : string

The name of the pump to be affected by an outage.

start_time : int

The time at which the outage starts.

end_time : int

The time at which the outage stops.

Removes a link from the water network model.

Parameters:

name: string

Name of the link to be removed

with_control: bool

If with_control is True, then any controls that target the link being removed will also be removed. If with_control is False, no controls will be removed.

remove_node(name, with_control=True)[source]

Removes a node from the water network model.

Parameters:

name: string

Name of the node to be removed

with_control: bool

If with_control is True, then any controls that target the link being removed will also be removed. If with_control is False, no controls will be removed.

remove_pattern(name)[source]

Removes a pattern from the water network model.

Parameters:

name : string

The name of the pattern object to be removed.

remove_curve(name)[source]

Removes a curve from the water network model.

Parameters:

name : string

The name of the curve object to be removed.

remove_source(name)[source]

Removes a source from the water network model.

Parameters:

name : string

The name of the source object to be removed.

remove_control(name)[source]

Removes a control from the water network model. If the control is not present, an exception is raised.

Parameters:

name : string

The name of the control object to be removed.

split_pipe(pipe_name_to_split, new_pipe_name, new_junction_name, add_pipe_at_node='end', split_at_point=0.5)[source]

Splits a pipe by adding a junction and one new pipe segment.

This method is convenient when adding leaks to a pipe. It provides an initially zero-demand node at some point along the pipe and then reconnects the original pipe to this node and adds a new pipe to the other side. Hydraulic paths are maintained. The new junction can then have a leak added to it.

It is important to note that check valves are not added to the new pipe. By allowing the new pipe to be connected at either the start or the end of the old pipe, this allows the split to occur before or after the check valve. Additionally, no controls will be added to the new pipe; the old pipe will keep any controls. Again, this allows the split to occur before or after a “valve” that is controled by opening or closing a pipe.

This method keeps ‘pipe_name_to_split’, resizes it, and adds a new pipe to keep total length equal. The pipe will be split at a new junction placed at a point ‘split_at_point’ of the way between the start and end (in that direction). The new pipe can be added to ‘add_pipe_at_node’ of either start or end. For example, if add_pipe_at_node='start', then the original pipe will go from the new junction to the original end node, and the new pipe will go from the original start node to the new junction.

The new pipe will have the same diameter, roughness, minor loss, and base status of the original pipe. The new junction will have a base demand of 0, an elevation equal to the ‘split_at_point’ x 100% of the elevation between the original start and end nodes, coordinates at ‘split_at_point’ between the original start and end nodes, and will use the default demand pattern.

Parameters:

pipe_name_to_split: string

The name of the pipe to split.

new_pipe_name: string

The name of the new pipe to be added as the split part of the pipe.

new_junction_name: string

The name of the new junction to be added.

add_pipe_at_node: string

Either ‘start’ or ‘end’, ‘end’ is default. The new pipe goes between this original node and the new junction.

split_at_point: float

Between 0 and 1, the position along the original pipe where the new junction will be located.

Returns:

tuple

returns (original_pipe, new_junction, new_pipe) objects

Raises:

ValueError

The link is not a pipe, split_at_point is out of bounds, add_pipe_at_node is invalid.

RuntimeError

The new_junction_name or new_pipe_name is already in use.

reset_demand(demand, pattern_prefix='ResetDemand')[source]

Resets demands using values in a DataFrame.

New demands are specified in a pandas DataFrame indexed by simulation time (in seconds) and one column for each node. The method resets node demands by creating a new demand pattern for each node and resetting the base demand to 1. The demand pattern is resampled to match the water network model pattern timestep. This method can be used to reset demands in a water network model to demands from a pressure dependent demand simualtion.

Parameters:

demand : pandas DataFrame

A pandas DataFrame containing demands (index = time, columns = node names)

pattern_prefix: string

Pattern prefix, default = ‘ResetDemand’

get_node(name)[source]

Returns the node object of a specific node.

Parameters:

name : string

Name of the node.

Returns:

Node object.

Returns the link object of a specific link.

Parameters:

name : string

Name of the link.

Returns:

Link object.

get_pattern(name)[source]

Returns the pattern object of a specific pattern.

Parameters:

name : string

Name of the pattern.

Returns:

Pattern object, the pattern does not exist, returns [1.0] (constant pattern)

get_curve(name)[source]

Returns the curve object of a specific curve.

Parameters:

name : string

Name of the curve.

Returns:

Curve object.

get_source(name)[source]

Returns the source object of a specific source.

Parameters:

name: string

Name of the source

Returns:

Source object.

get_control(name)[source]

Returns the control object of a specific control.

Parameters:

name: string

Name of the control

Returns:

Control object.

Returns a list of links connected to a node.

Parameters:

node_name : string

Name of the node.

flag : string

Options are ‘ALL’, ‘INLET’, ‘OUTLET’. ‘ALL’ returns all links connected to the node. ‘INLET’ returns links that have the specified node as an end node. ‘OUTLET’ returns links that have the specified node as a start node.

Returns:

A list of link names connected to the node

get_node_coordinates(name=None)[source]

Returns node coordinates.

Parameters:

name: string

Name of the node.

Returns:

A tuple containing the coordinates of the specified node.

Note: If name is None, this method will return a dictionary

with the coordinates of all nodes keyed by node name.

get_graph_deep_copy()[source]

Returns a deep copy of the WaterNetworkModel networkx graph.

Returns:WaterNetworkModel networkx graph.
query_node_attribute(attribute, operation=None, value=None, node_type=None)[source]

Query node attributes, for example get all nodes with elevation <= threshold.

Parameters:

attribute: string

Node attribute.

operation: numpy operator

Numpy operator, options include np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal.

value: float or int

Threshold

node_type: Node type

Node type, options include wntr.network.model.Node, wntr.network.model.Junction, wntr.network.model.Reservoir, wntr.network.model.Tank, or None. Default = None. Note None and wntr.network.model.Node produce the same results.

Returns:

A dictionary of node names to attribute where node_type satisfies the

operation threshold.

Notes

If operation and value are both None, the dictionary will contain the attributes for all nodes with the specified attribute.

Query link attributes, for example get all pipe diameters > threshold.

Parameters:

attribute: string

Link attribute

operation: numpy operator

Numpy operator, options include np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal.

value: float or int

Threshold

link_type: Link type

Link type, options include wntr.network.model.Link, wntr.network.model.Pipe, wntr.network.model.Pump, wntr.network.model.Valve, or None. Default = None. Note None and wntr.network.model.Link produce the same results.

Returns:

A dictionary of link names to attributes where link_type satisfies the

operation threshold.

Notes

If operation and value are both None, the dictionary will contain the attributes for all links with the specified attribute.

num_nodes

Returns the number of nodes in the water network model.

num_junctions

Returns the number of junctions in the water network model.

num_tanks

Returns the number of tanks in the water network model.

num_reservoirs

Returns the number of reservoirs in the water network model.

Returns the number of links in the water network model.

num_pipes

Returns the number of pipes in the water network model.

num_pumps

Returns the number of pumps in the water network model.

num_valves

Returns the number of valves in the water network model.

num_patterns

Returns the number of patterns in the water network model.

num_curves

Returns the number of curves in the water network model.

num_sources

Returns the number of sources in the water network model.

num_controls

Returns the number of controls in the water network model.

nodes(node_type=None)[source]

Returns a generator to iterate over all nodes of a specific node type. If no node type is specified, the generator iterates over all nodes.

Parameters:

node_type: Node type

Node type, options include wntr.network.model.Node, wntr.network.model.Junction, wntr.network.model.Reservoir, wntr.network.model.Tank, or None. Default = None. Note None and wntr.network.model.Node produce the same results.

Returns:

A generator in the format (name, object).

junctions()[source]

Returns a generator to iterate over all junctions.

Returns:A generator in the format (name, object).
tanks()[source]

Returns a generator to iterate over all tanks.

Returns:A generator in the format (name, object).
reservoirs()[source]

Returns a generator to iterate over all reservoirs.

Returns:A generator in the format (name, object).

Returns a generator to iterate over all links of link_type. If no link_type is passed, this method iterates over all links.

Return a generator to iterate over all links of a specific link type. If no link type is specified, the generator iterates over all links.

Parameters:

link_type: Link type

Link type, options include wntr.network.model.Link, wntr.network.model.Pipe, wntr.network.model.Pump, wntr.network.model.Valve, or None. Default = None. Note None and wntr.network.model.Link produce the same results.

Returns:

A generator in the format (name, object).

pipes()[source]

Returns a generator to iterate over all pipes.

Returns:A generator in the format (name, object).
pumps()[source]

Returns a generator to iterate over all pumps.

Returns:A generator in the format (name, object).
valves()[source]

Returns a generator to iterate over all valves.

Returns:A generator in the format (name, object).
patterns()[source]

Returns a generator to iterate over all patterns.

Returns:A generator in the format (name, object).
curves()[source]

Returns a generator to iterate over all curves.

Returns:A generator in the format (name, object).
sources()[source]

Returns a generator to iterate over all sources.

Returns:A generator in the format (name, object).
controls()[source]

Returns a generator to iterate over all controls.

Returns:A generator in the format (name, object).
node_name_list

Returns a list of the names of all nodes.

junction_name_list

Returns a list of the names of all junctions.

tank_name_list

Returns a list of the names of all tanks.

reservoir_name_list

Returns a list of the names of all reservoirs.

Returns a list of the names of all links.

pipe_name_list

Returns a list of the names of all pipes.

pump_name_list

Returns a list of the names of all pumps.

valve_name_list

Returns a list of the names of all valves.

pattern_name_list

Returns a list of the names of all patterns.

curve_name_list

Returns a list of the names of all curves.

source_name_list

Returns a list of the names of all sources.

control_name_list

Returns a list of the names of all controls.

set_node_coordinates(name, coordinates)[source]

Sets the node coordinates in the networkx graph.

Parameters:

name : string

Name of the node.

coordinates : tuple

X-Y coordinates.

scale_node_coordinates(scale)[source]

Scales node coordinates, using 1:scale. Scale should be in meters.

Parameters:

scale : float

Coordinate scale multiplier.

reset_initial_values()[source]

Resets all initial values in the network.

read_inpfile(filename)[source]

Defines water network model components from an EPANET INP file.

Parameters:

filename : string

Name of the INP file.

write_inpfile(filename, units=None)[source]

Writes the current water network model to an EPANET INP file.

Parameters:

filename : string

Name of the inp file.

units : str, int or FlowUnits

Name of the units being written to the inp file.

class wntr.network.model.Node(name)[source]

Bases: object

The base node class.

Parameters:

name : string

Name of the node

Attributes

initial_quality Returns the initial quality (concentration) of the node.
name Returns the name of the node.
name

Returns the name of the node.

initial_quality

Returns the initial quality (concentration) of the node. Can be a float or list of floats.

Bases: object

The base link class.

Parameters:

link_name : string

Name of the link

start_node_name : string

Name of the start node

end_node_name : string

Name of the end node

Attributes

end_node Returns name of end node
name Returns the name of the link
start_node Returns name of start node

Methods

get_initial_status() Get the initial status for pumps and valves
set_initial_status(status) Set the initial status for pumps and valves
set_initial_status(status)[source]

Set the initial status for pumps and valves

..warning::
This will override the current status - don’t do it during (or after) simulation
get_initial_status()[source]

Get the initial status for pumps and valves

start_node

Returns name of start node

end_node

Returns name of end node

name

Returns the name of the link

class wntr.network.model.Junction(name, base_demand=0.0, demand_pattern=None, elevation=0.0)[source]

Bases: wntr.network.model.Node

Junction class that is inherited from Node

Parameters:

name : string

Name of the junction.

base_demand : float, optional

Base demand at the junction. Internal units must be cubic meters per second (m^3/s).

demand_pattern : Pattern object, optional

Demand pattern.

elevation : float, optional

Elevation of the junction. Internal units must be meters (m).

Attributes

base_demand Returns the first base demand (first entry in demands_timeseries_list)
demand_pattern_name Returns the first base demand pattern name (first entry in demands_timeseries_list)
initial_quality Returns the initial quality (concentration) of the node.
name Returns the name of the node.
pressure Returns pressure (head - elevation)

Methods

add_leak(wn, area[, discharge_coeff, …]) Add a leak to a junction.
discard_leak_controls(wn) Specify that user-defined controls will be used to start and stop the leak.
leak_present() Check if the junction has a leak or not.
remove_leak(wn) Remove a leak from a junction.
set_leak_end_time(wn, t) Set an end time for the leak.
set_leak_start_time(wn, t) Set a start time for the leak.
nominal_pressure = None

The nominal pressure attribute is used for pressure-dependent demand. This is the lowest pressure at which the customer receives the full requested demand.

minimum_pressure = None

The minimum pressure attribute is used for pressure-dependent demand simulations. Below this pressure, the customer will not receive any water.

pressure

Returns pressure (head - elevation)

base_demand

Returns the first base demand (first entry in demands_timeseries_list)

demand_pattern_name

Returns the first base demand pattern name (first entry in demands_timeseries_list)

add_leak(wn, area, discharge_coeff=0.75, start_time=None, end_time=None)[source]

Add a leak to a junction. Leaks are modeled by:

Q = discharge_coeff*area*sqrt(2*g*h)

where:
Q is the volumetric flow rate of water out of the leak g is the acceleration due to gravity h is the guage head at the junction, P_g/(rho*g); Note that this is not the hydraulic head (P_g + elevation)
Parameters:

wn: wntr WaterNetworkModel

Water network model containing the junction with the leak. This information is needed because the WaterNetworkModel object stores all controls, including when the leak starts and stops.

area: float

Area of the leak in m^2.

discharge_coeff: float

Leak discharge coefficient; Takes on values between 0 and 1.

start_time: int

Start time of the leak in seconds. If the start_time is None, it is assumed that an external control will be used to start the leak (otherwise, the leak will not start).

end_time: int

Time at which the leak is fixed in seconds. If the end_time is None, it is assumed that an external control will be used to end the leak (otherwise, the leak will not end).

remove_leak(wn)[source]

Remove a leak from a junction.

Parameters:

wn: wntr WaterNetworkModel

Water network model

leak_present()[source]

Check if the junction has a leak or not. Note that this does not check whether or not the leak is active (i.e., if the current time is between leak_start_time and leak_end_time).

Returns:bool: True if a leak is present, False if a leak is not present
set_leak_start_time(wn, t)[source]

Set a start time for the leak. This internally creates a TimeControl object and adds it to the network for you. Please make sure all user-defined controls for starting the leak have been removed before using this method (see WaterNetworkModel.remove_leak() or WaterNetworkModel.discard_leak()).

Parameters:

wn: wntr WaterNetworkModel

Water network model

t: int

Leak end time in seconds

set_leak_end_time(wn, t)[source]

Set an end time for the leak. This internally creates a TimeControl object and adds it to the network for you. Please make sure all user-defined controls for ending the leak have been removed before using this method (see WaterNetworkModel.remove_leak() or WaterNetworkModel.discard_leak()).

Parameters:

wn: wntr WaterNetworkModel

Water network model

t: int

Leak end time in seconds

discard_leak_controls(wn)[source]

Specify that user-defined controls will be used to start and stop the leak. This will remove any controls set up through Junction.add_leak(), Junction.set_leak_start_time(), or Junction.set_leak_end_time().

Parameters:

wn: wntr WaterNetworkModel

Water network model

class wntr.network.model.Tank(name, elevation=0.0, init_level=3.048, min_level=0.0, max_level=6.096, diameter=15.24, min_vol=None, vol_curve_name=None)[source]

Bases: wntr.network.model.Node

Tank class that is inherited from Node

Parameters:

name : string

Name of the tank.

elevation : float, optional

Elevation at the Tank. Internal units must be meters (m).

init_level : float, optional

Initial tank level. Internal units must be meters (m).

min_level : float, optional

Minimum tank level. Internal units must be meters (m)

max_level : float, optional

Maximum tank level. Internal units must be meters (m)

diameter : float, optional

Tank diameter. Internal units must be meters (m)

min_vol : float, optional

Minimum tank volume. Internal units must be cubic meters (m^3)

vol_curve : Curve object, optional

Curve object

Attributes

initial_quality Returns the initial quality (concentration) of the node.
level Returns tank level (head - elevation)
name Returns the name of the node.

Methods

add_leak(wn, area[, discharge_coeff, …]) Add a leak to a tank.
leak_present() Check if the tank has a leak or not.
remove_leak(wn) Remove a leak from a tank.
set_leak_end_time(wn, t) Set an end time for the leak.
set_leak_start_time(wn, t) Set a start time for the leak.
use_external_leak_control(wn) Specify that user-defined controls will be used to start and stop the leak.
level

Returns tank level (head - elevation)

add_leak(wn, area, discharge_coeff=0.75, start_time=None, end_time=None)[source]

Add a leak to a tank. Leaks are modeled by:

Q = discharge_coeff*area*sqrt(2*g*h)

where:
Q is the volumetric flow rate of water out of the leak g is the acceleration due to gravity h is the guage head at the bottom of the tank, P_g/(rho*g); Note that this is not the hydraulic head (P_g + elevation)

Note that WNTR assumes the leak is at the bottom of the tank.

Parameters:

wn: WaterNetworkModel object

The WaterNetworkModel object containing the tank with the leak. This information is needed because the WaterNetworkModel object stores all controls, including when the leak starts and stops.

area: float

Area of the leak in m^2.

discharge_coeff: float

Leak discharge coefficient; Takes on values between 0 and 1.

start_time: int

Start time of the leak in seconds. If the start_time is None, it is assumed that an external control will be used to start the leak (otherwise, the leak will not start).

end_time: int

Time at which the leak is fixed in seconds. If the end_time is None, it is assumed that an external control will be used to end the leak (otherwise, the leak will not end).

remove_leak(wn)[source]

Remove a leak from a tank.

Parameters:

wn: wntr WaterNetworkModel

Water network model

leak_present()[source]

Check if the tank has a leak or not. Note that this does not check whether or not the leak is active (i.e., if the current time is between leak_start_time and leak_end_time).

Returns:bool: True if a leak is present, False if a leak is not present
set_leak_start_time(wn, t)[source]

Set a start time for the leak. This internally creates a TimeControl object and adds it to the network for you. Please make sure all user-defined controls for starting the leak have been removed before using this method (see WaterNetworkModel.remove_leak() or WaterNetworkModel.discard_leak()).

Parameters:

wn: wntr WaterNetworkModel

Water network model

t: int

start time in seconds

set_leak_end_time(wn, t)[source]

Set an end time for the leak. This internally creates a TimeControl object and adds it to the network for you. Please make sure all user-defined controls for ending the leak have been removed before using this method (see WaterNetworkModel.remove_leak() or WaterNetworkModel.discard_leak()).

Parameters:

wn: wntr WaterNetworkModel

Water network model

t: int

end time in seconds

use_external_leak_control(wn)[source]

Specify that user-defined controls will be used to start and stop the leak. This will remove any controls set up through Tank.add_leak(), Tank.set_leak_start_time(), or Tank.set_leak_end_time().

Parameters:

wn: wntr WaterNetworkModel

Water network model

class wntr.network.model.Reservoir(name, base_head=0.0, head_pattern=None)[source]

Bases: wntr.network.model.Node

Reservoir class that is inherited from Node

Parameters:

name : string

Name of the reservoir.

base_head : float, optional

Base head at the reservoir. Internal units must be meters (m).

head_pattern : Pattern object, optional

Head pattern.

Attributes

base_head
head_pattern_name
initial_quality Returns the initial quality (concentration) of the node.
name Returns the name of the node.
class wntr.network.model.Pipe(name, start_node_name, end_node_name, length=304.8, diameter=0.3048, roughness=100, minor_loss=0.0, status='OPEN', check_valve_flag=False)[source]

Bases: wntr.network.model.Link

Pipe class that is inherited from Link

Parameters:

name : string

Name of the pipe

start_node_name : string

Name of the start node

end_node_name : string

Name of the end node

length : float, optional

Length of the pipe. Internal units must be meters (m)

diameter : float, optional

Diameter of the pipe. Internal units must be meters (m)

roughness : float, optional

Pipe roughness coefficient

minor_loss : float, optional

Pipe minor loss coefficient

status : string, optional

Pipe status. Options are ‘Open’ or ‘Closed’

check_valve_flag : bool, optional

True if the pipe has a check valve False if the pipe does not have a check valve

Attributes

end_node Returns name of end node
name Returns the name of the link
start_node Returns name of start node

Methods

get_initial_status() Get the initial status for pumps and valves
set_initial_status(status) Set the initial status for pumps and valves
class wntr.network.model.Pump(name, start_node_name, end_node_name, info_type='POWER', info_value=50.0, base_speed=1.0, speed_pattern=None)[source]

Bases: wntr.network.model.Link

Pump class that is inherited from Link

Parameters:

name : string

Name of the pump

start_node_name : string

Name of the start node

end_node_name : string

Name of the end node

info_type : string, optional

Type of information provided about the pump. Options are ‘POWER’ or ‘HEAD’.

info_value : float or curve type, optional

Where power is a fixed value in KW, while a head curve is a Curve object.

base_speed: float

Relative speed setting (1.0 is normal speed)

speed_pattern: Pattern object, optional

Speed pattern

Attributes

curve_name Returns the pump curve name
end_node Returns name of end node
name Returns the name of the link
setting Alias to speed for consistency with other link types
start_node Returns name of start node

Methods

get_design_flow() Returns the design flow value for the pump.
get_head_curve_coefficients() Returns the A, B, C coefficients for a 1-point or a 3-point pump curve.
get_initial_status() Get the initial status for pumps and valves
set_initial_status(status) Set the initial status for pumps and valves
curve_name

Returns the pump curve name

setting

Alias to speed for consistency with other link types

get_head_curve_coefficients()[source]

Returns the A, B, C coefficients for a 1-point or a 3-point pump curve. Coefficient can only be calculated for pump curves.

For a single point curve the coefficients are generated according to the following equation:

A = 4/3 * H_1 B = 1/3 * H_1/Q_1^2 C = 2

For a three point curve the coefficients are generated according to the following equation:

When the first point is a zero flow: (All INP files we have come across)

A = H_1 C = ln((H_1 - H_2)/(H_1 - H_3))/ln(Q_2/Q_3) B = (H_1 - H_2)/Q_2^C

When the first point is not zero, numpy fsolve is called to solve the following system of equation:

H_1 = A - B*Q_1^C H_2 = A - B*Q_2^C H_3 = A - B*Q_3^C

Multi point curves are currently not supported

Parameters:

pump_name : string

Name of the pump

Returns:

Tuple of pump curve coefficient (A, B, C). All floats.

get_design_flow()[source]

Returns the design flow value for the pump. Equals to the first point on the pump curve.

class wntr.network.model.Valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, setting=0.0)[source]

Bases: wntr.network.model.Link

Valve class that is inherited from Link

Parameters:

name : string

Name of the valve

start_node_name : string

Name of the start node

end_node_name : string

Name of the end node

diameter : float, optional

Diameter of the valve. Internal units must be meters (m)

valve_type : string, optional

Type of valve. Options are ‘PRV’, etc

minor_loss : float, optional

Pipe minor loss coefficient

setting : float or string, optional

Valve setting or name of headloss curve for GPV

Attributes

end_node Returns name of end node
name Returns the name of the link
start_node Returns name of start node

Methods

get_initial_status() Get the initial status for pumps and valves
set_initial_status(status) Set the initial status for pumps and valves