ENepanet#

module wntr.epanet.toolkit

class ENepanet[source]#

Bases: object

Wrapper class to load the EPANET DLL object, then perform operations on the EPANET object that is created when a file is loaded.

This simulator is thread safe only for EPANET version=2.2.

Parameters:
  • inpfile (str) – Input file to use

  • rptfile (str) – Output file to report to

  • binfile (str) – Results file to generate

  • version (float) – EPANET version to use (either 2.0 or 2.2)


ENaddcontrol(iType, iLinkIndex, dSetting, iNodeIndex, dLevel)[source]#

Add a new simple control

Parameters:
  • iType (int) – the type of control

  • iLinkIndex (int) – the index of the link

  • dSetting (float) – the new link setting value

  • iNodeIndex (int) – Set to 0 for time of day or timer

  • dLevel (float) – the level to compare against

Returns:

the new control number

Return type:

int

ENclose()[source]#

Frees all memory and files used by EPANET

ENcloseH()[source]#

Frees data allocated by hydraulics solver

ENcloseQ()[source]#

Frees data allocated by water quality solver

ENdeletecontrol(iControlIndex)[source]#

Delete a control.

Parameters:

iControlIndex (int) – the simple control to delete

ENgetcontrol(iIndex)[source]#

Get values defined by a control.

Parameters:

iIndex (int) – the control number

ENgetcount(iCode)[source]#

Retrieves the number of components of a given type in the network

Parameters:

iCode (int) – Component code (see toolkit.optComponentCounts)

Returns:

Number of components in network

Return type:

int

ENgetflowunits()[source]#

Retrieves flow units code

Return type:

Code of flow units in use (see toolkit.optFlowUnits)

ENgetlinkindex(sId)[source]#

Retrieves index of a link with specific ID

Parameters:

sId (int) – Link ID

Return type:

Index of link in list of links

ENgetlinktype(iIndex)[source]#

Retrieves a link’s type given its index.

Parameters:

iIndex (int) – The index of the link

Returns:

the link type as an integer

Return type:

int

ENgetlinkvalue(iIndex, iCode)[source]#

Retrieves parameter value for a link

Parameters:
  • iIndex (int) – Link index

  • iCode (int) – Link parameter code (see toolkit.optLinkParams)

Return type:

Value of link’s parameter

ENgetnodeid(iIndex)[source]#

Gets the ID name of a node given its index.

Parameters:

iIndex (int) – a node’s index (starting from 1).

Returns:

the node name

Return type:

str

ENgetnodeindex(sId)[source]#

Retrieves index of a node with specific ID

Parameters:

sId (int) – Node ID

Return type:

Index of node in list of nodes

ENgetnodetype(iIndex)[source]#

Retrieves a node’s type given its index.

Parameters:

iIndex (int) – The index of the node

Returns:

the node type as an integer

Return type:

int

ENgetnodevalue(iIndex, iCode)[source]#

Retrieves parameter value for a node

Parameters:
  • iIndex (int) – Node index

  • iCode (int) – Node parameter code (see toolkit.optNodeParams)

Return type:

Value of node’s parameter

ENgettimeparam(eParam)[source]#

Get a time parameter value

Parameters:

eParam (int) – the time parameter to get

Returns:

the value of the time parameter, in seconds

Return type:

long

ENinitH(iFlag)[source]#

Initializes hydraulic analysis

Parameters:

iFlag (2-digit flag) – 2-digit flag where 1st (left) digit indicates if link flows should be re-initialized (1) or not (0) and 2nd digit indicates if hydraulic results should be saved to file (1) or not (0)

ENinitQ(iSaveflag)[source]#

Initializes water quality analysis

Parameters:

iSaveflag (int) – EN_SAVE (1) if results saved to file, EN_NOSAVE (0) if not

ENnextH()[source]#

Determines time until next hydraulic event

This function is used in a loop with ENrunH() to run an extended period hydraulic simulation. See ENsolveH() for an example.

Returns:

Time (seconds) until next hydraulic event (0 marks end of simulation period)

Return type:

int

ENnextQ()[source]#

Advances water quality simulation to next hydraulic event

This function is used in a loop with ENrunQ() to run an extended period water quality simulation. See ENsolveQ() for an example.

Returns:

Time (seconds) until next hydraulic event (0 marks end of simulation period)

Return type:

int

ENopen(inpfile=None, rptfile=None, binfile=None)[source]#

Opens an EPANET input file and reads in network data

Parameters:
  • inpfile (str) – EPANET INP file (default to constructor value)

  • rptfile (str) – Output file to create (default to constructor value)

  • binfile (str) – Binary output file to create (default to constructor value)

ENopenH()[source]#

Sets up data structures for hydraulic analysis

ENopenQ()[source]#

Sets up data structures for water quality analysis

ENreport()[source]#

Writes report to report file

ENrunH()[source]#

Solves hydraulics for conditions at time t

This function is used in a loop with ENnextH() to run an extended period hydraulic simulation. See ENsolveH() for an example.

Returns:

Current simulation time (seconds)

Return type:

int

ENrunQ()[source]#

Retrieves hydraulic and water quality results at time t

This function is used in a loop with ENnextQ() to run an extended period water quality simulation. See ENsolveQ() for an example.

Returns:

Current simulation time (seconds)

Return type:

int

ENsaveH()[source]#

Solves for network hydraulics in all time periods

Must be called before ENreport() if no water quality simulation made. Should not be called if ENsolveQ() will be used.

ENsavehydfile(filename)[source]#

Copies binary hydraulics file to disk

Parameters:

filename (str) – Name of hydraulics file to output

ENsaveinpfile(inpfile)[source]#

Saves EPANET input file

Parameters:

inpfile (str) – EPANET INP output file

ENsetcontrol(iIndex, iType, iLinkIndex, dSetting, iNodeIndex, dLevel)[source]#

Change values on a simple control

Parameters:
  • iIndex (int) – the control index

  • iType (int) – the type of control comparison

  • iLinkIndex (int) – the link being changed

  • dSetting (float) – the setting to change to

  • iNodeIndex (int) – the node being compared against, Set to 0 for time of day or timer

  • dLevel (float) – the level being checked

Warning

There is an error in EPANET 2.2 that sets the dLevel parameter to 0.0 on Macs regardless of the value the user passes in. This means that to use this toolkit functionality on a Mac, the user must delete and create a new control to change the level.

ENsetlinkvalue(iIndex, iCode, fValue)[source]#

Set the value on a link

Parameters:
  • iIndex (int) – the link index

  • iCode (int) – the parameter enum integer

  • fValue (float) – the value to set on the link

ENsetnodevalue(iIndex, iCode, fValue)[source]#

Set the value on a node

Parameters:
  • iIndex (int) – the node index

  • iCode (int) – the parameter enum integer

  • fValue (float) – the value to set on the node

ENsettimeparam(eParam, lValue)[source]#

Set a time parameter value

Parameters:
  • eParam (int) – the time parameter to set

  • lValue (long) – the value to set, in seconds

ENsolveH()[source]#

Solves for network hydraulics in all time periods

ENsolveQ()[source]#

Solves for network water quality in all time periods

ENusehydfile(filename)[source]#

Opens previously saved binary hydraulics file

Parameters:

filename (str) – Name of hydraulics file to use

__init__(inpfile='', rptfile='', binfile='', version=2.2)[source]#
isOpen()[source]#

Checks to see if the file is open