wntr.network.base module

The wntr.network.base module includes base classes for network elements and the network model.

Contents

Node(wn, name)

Base class for nodes.

Link(wn, link_name, start_node_name, ...)

Base class for links.

Registry(wn)

Base class for registries.

NodeType(value)

Enum class for node types.

LinkType(value)

Enum class for link types.

LinkStatus(value)

Enum class for link statuses.

AbstractModel()

Base class for water network models.

Subject()

Base class for the subject in an observer design pattern.

Observer()

Base class for the observer in an observer design pattern.

class wntr.network.base.AbstractModel[source]

Bases: object

Base class for water network models.

class wntr.network.base.Subject[source]

Bases: object

Base class for the subject in an observer design pattern.

class wntr.network.base.Observer[source]

Bases: object

Base class for the observer in an observer design pattern.

class wntr.network.base.Node(wn, name)[source]

Bases: object

Base class for nodes.

For details about the different subclasses, see one of the following: Junction, Tank, and Reservoir

Constructor

This is an abstract class and should not be instantiated directly.

Parameters
  • wn (WaterNetworkModel) – WaterNetworkModel object

  • name (string) – Name of the node (must be unique among nodes of all types)

Attributes

name

The name of the node (read only)

node_type

The node type (read only)

coordinates

The node coordinates, (x,y)

initial_quality

The initial quality (concentration) at the node

tag

A tag or label for the node

Read-only simulation results

The following attributes are read-only. The values are the final calculated value from a simulation.

head

(read-only) the current simulation head at the node (total head)

demand

(read-only) the current simulation demand at the node (actual demand)

leak_demand

(read-only) the current simulation leak demand at the node

leak_status

(read-only) the current simulation leak status at the node

leak_area

(read-only) the current simulation leak area at the node

leak_discharge_coeff

(read-only) the current simulation leak discharge coefficient

property head

(read-only) the current simulation head at the node (total head)

Type

float

property demand

(read-only) the current simulation demand at the node (actual demand)

Type

float

property pressure

(read-only) the current simulation pressure at the node

Type

float

property quality

(read-only) the current simulation quality at the node

Type

float

property leak_demand

(read-only) the current simulation leak demand at the node

Type

float

property leak_status

(read-only) the current simulation leak status at the node

Type

bool

property leak_area

(read-only) the current simulation leak area at the node

Type

float

property leak_discharge_coeff

(read-only) the current simulation leak discharge coefficient

Type

float

property node_type

The node type (read only)

Type

str

property name

The name of the node (read only)

Type

str

property tag

A tag or label for the node

Type

str

property initial_quality

The initial quality (concentration) at the node

Type

float

property coordinates

The node coordinates, (x,y)

Type

tuple

to_dict()[source]

Dictionary representation of the node

Bases: object

Base class for links.

For details about the different subclasses, see one of the following: Pipe, Pump, and Valve

Constructor

This is an abstract class and should not be instantiated directly.

Parameters
  • wn (WaterNetworkModel) – WaterNetworkModel object

  • 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

name

The link name (read-only)

link_type

the link type (read only)

start_node

The start node object.

start_node_name

The name of the start node (read only)

end_node

The end node object.

end_node_name

The name of the end node (read only)

initial_status

The initial status (Opened, Closed, Active) of the Link

initial_setting

The initial setting for the link (if Active)

tag

A tag or label for this link

vertices

A list of curve points, in the direction of start node to end node.

Read-only simulation results

The following attributes are read-only. The values are the final calculated value from a simulation.

flow

(read-only) current simulated flow through the link

headloss

(read-only) current simulated headloss

quality

(read-only) current simulated average link quality

status

(abstract) current status of the link

setting

(read-only) current simulated setting of the link

the link type (read only)

Type

str

property initial_status

The initial status (Opened, Closed, Active) of the Link

Type

LinkStatus

property initial_setting

The initial setting for the link (if Active)

Type

float

property start_node

The start node object.

Type

Node

property end_node

The end node object.

Type

Node

property start_node_name

The name of the start node (read only)

Type

str

property end_node_name

The name of the end node (read only)

Type

str

property name

The link name (read-only)

Type

str

property flow

(read-only) current simulated flow through the link

Type

float

property velocity

(read-only) current simulated velocity through the link

Type

float

abstract property status

(abstract) current status of the link

Type

LinkStatus

property quality

(read-only) current simulated average link quality

Type

float

property headloss

(read-only) current simulated headloss

Type

float

property setting

(read-only) current simulated setting of the link

Type

float

property tag

A tag or label for this link

Type

str

property vertices

A list of curve points, in the direction of start node to end node.

The vertices should be listed as a list of (x,y) tuples when setting.

to_dict()[source]

Dictionary representation of the link

class wntr.network.base.Registry(wn)[source]

Bases: collections.abc.MutableMapping

Base class for registries.

Parameters

wn (WaterNetworkModel) – WaterNetworkModel object

usage()[source]

Generator to get the usage for all objects in the registry

Yields
  • key (str) – The name of the object in the registry

  • value (tuple of (str, str)) – Tuple of (name, typestr) of the external items using the object

get_usage(key)[source]

Get a set of items using an object by key.

Returns

set of 2-tuples – Set of (name, typestr) of the external object using the item

orphaned()[source]

Get a list of orphaned usages.

If removed without appropriate checks, it is possible that a some other item will point to an object that has been deleted. (This is why the user should always use the “remove_*” methods). This method returns a list of names for objects that are referenced, but no longer exist.

Returns

set – The names of any orphaned items

unused()[source]

Get a list of items which are unused by other objects in the model.

In most cases, this method will give little information. For nodes, however, this method could be important to identify a node which has become completely disconnected from the network. For patterns or curves, it may be used to find extra patterns or curves that are no longer necessary (or which the user forgot ot assign). It is not terribly useful for links.

Returns

set – The names of any unused objects in the registry

clear_usage(key)[source]

if key in usage, clear usage[key]

add_usage(key, *args)[source]

add args to usage[key]

remove_usage(key, *args)[source]

remove args from usage[key]

to_dict()[source]

Dictionary representation of the registry

to_list()[source]

List representation of the registry

clear() None.  Remove all items from D.
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values
class wntr.network.base.NodeType(value)[source]

Bases: enum.IntEnum

Enum class for node types.

Enum Members

Junction

node is a junction

Reservoir

node is a reservoir

Tank

node is a tank

Junction = 0

node is a junction

Reservoir = 1

node is a reservoir

Tank = 2

node is a tank

class wntr.network.base.LinkType(value)[source]

Bases: enum.IntEnum

Enum class for link types.

Enum Members

CV

pipe with a check valve

Pipe

pipe with no check valve

Pump

a pump of any type

PRV

a pressure reducing valve

PSV

a pressure sustaining valve

PBV

a pressure breaker valve

FCV

a flow control valve

TCV

a throttle control valve

GPV

a general purpose valve

Valve

a valve of any type

CV = 0

pipe with a check valve

Pipe = 1

pipe with no check valve

Pump = 2

a pump of any type

PRV = 3

a pressure reducing valve

PSV = 4

a pressure sustaining valve

PBV = 5

a pressure breaker valve

FCV = 6

a flow control valve

TCV = 7

a throttle control valve

GPV = 8

a general purpose valve

Valve = 9

a valve of any type

class wntr.network.base.LinkStatus(value)[source]

Bases: enum.IntEnum

Enum class for link statuses.

Warning

This is NOT the class for determining output status from an EPANET binary file. The class for output status is wntr.epanet.util.LinkTankStatus.

Enum Members

Closed

pipe/valve/pump is closed

Opened

pipe/valve/pump is open

Active

valve is partially open or pump has a specific setting

CV

pipe has a check valve

Open

alias for Opened

Closed = 0

pipe/valve/pump is closed

Open = 1

alias for Opened

Opened = 1

pipe/valve/pump is open

Active = 2

valve is partially open or pump has a specific setting

CV = 3

pipe has a check valve