# wntr.epanet.toolkit module¶

The wntr.epanet.toolkit module is a Python extensions for the EPANET Programmers Toolkit DLLs.

Contents

 runepanet(inpfile) Run an EPANET command-line simulation ENepanet([inpfile, rptfile, binfile]) Wrapper class to load the EPANET DLL object, then perform operations on the EPANET object that is created when a file is loaded. EpanetException ENgetwarning(code[, sec])
exception wntr.epanet.toolkit.EpanetException[source]

Bases: exceptions.Exception

wntr.epanet.toolkit.runepanet(inpfile)[source]

Run an EPANET command-line simulation

Parameters: inpfile : str The input file name
class wntr.epanet.toolkit.ENepanet(inpfile='', rptfile='', binfile='')[source]

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

Attributes: ENlib

Methods

 ENclose() Frees all memory and files used by EPANET ENcloseH() Frees data allocated by hydraulics solver ENcloseQ() Frees data allocated by water quality solver ENgetcount(iCode) Retrieves the number of components of a given type in the network ENgetflowunits() Retrieves flow units code ENgetlinkindex(sId) Retrieves index of a link with specific ID ENgetlinkvalue(iIndex, iCode) Retrieves parameter value for a link ENgetnodeindex(sId) Retrieves index of a node with specific ID ENgetnodevalue(iIndex, iCode) Retrieves parameter value for a node ENinitH(iFlag) Initializes hydraulic analysis ENinitQ(iSaveflag) Initializes water quality analysis ENnextH() Determines time until next hydraulic event ENnextQ() Advances water quality simulation to next hydraulic event ENopen([inpfile, rptfile, binfile]) Opens an EPANET input file and reads in network data ENopenH() Sets up data structures for hydraulic analysis ENopenQ() Sets up data structures for water quality analysis ENreport() Writes report to report file ENrunH() Solves hydraulics for conditions at time t ENrunQ() Retrieves hydraulic and water quality results at time t ENsaveH() Solves for network hydraulics in all time periods ENsavehydfile(filename) Copies binary hydraulics file to disk ENsaveinpfile(inpfile) Saves EPANET input file ENsolveH() Solves for network hydraulics in all time periods ENsolveQ() Solves for network water quality in all time periods ENusehydfile(filename) Opens previously saved binary hydraulics file isOpen() Checks to see if the file is open
errcode = 0

Return code from the EPANET library functions

Warnflag = False

A warning occurred at some point during EPANET execution

Errflag = False

A fatal error occurred at some point during EPANET execution

inpfile = 'temp.inp'

The name of the EPANET input file

rptfile = 'temp.rpt'

The report file to generate

binfile = 'temp.bin'

The optional binary output file

ENlib = None

The variable that holds the ctypes Library object

isOpen()[source]

Checks to see if the file is open

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)
ENclose()[source]

Frees all memory and files used by EPANET

ENsolveH()[source]

Solves for network hydraulics in all time periods

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.

ENopenH()[source]

Sets up data structures for hydraulic analysis

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)
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)
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)
ENcloseH()[source]

Frees data allocated by hydraulics solver

ENsavehydfile(filename)[source]

Copies binary hydraulics file to disk

Parameters: filename : str Name of file
ENusehydfile(filename)[source]

Opens previously saved binary hydraulics file

Parameters: filename : str Name of file
ENsolveQ()[source]

Solves for network water quality in all time periods

ENopenQ()[source]

Sets up data structures for water quality analysis

ENinitQ(iSaveflag)[source]

Initializes water quality analysis

Parameters: iSaveflag : int EN_SAVE (1) if results saved to file, EN_NOSAVE (0) if not
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)
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)
ENcloseQ()[source]

Frees data allocated by water quality solver

ENreport()[source]

Writes report to report file

ENgetcount(iCode)[source]

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

Parameters: iCode : int Component code (see toolkit.optComponentCounts) Number of components in network
ENgetflowunits()[source]

Retrieves flow units code

Returns: Code of flow units in use (see toolkit.optFlowUnits)
ENgetnodeindex(sId)[source]

Retrieves index of a node with specific ID

Parameters: sId : int Node ID Index of node in list of nodes
ENgetnodevalue(iIndex, iCode)[source]

Retrieves parameter value for a node

Parameters: iIndex: int Node index iCode : int Node parameter code (see toolkit.optNodeParams) Value of node’s parameter
ENgetlinkindex(sId)[source]

Retrieves index of a link with specific ID

ENgetlinkvalue(iIndex, iCode)[source]
ENsaveinpfile(inpfile)[source]