wntr.epanet.toolkit module

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

Contents

runepanet(inpfile[, rptfile, binfile])

Run an EPANET command-line simulation

ENepanet([inpfile, rptfile, binfile, version])

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: Exception

wntr.epanet.toolkit.runepanet(inpfile, rptfile=None, binfile=None)[source]

Run an EPANET command-line simulation

Parameters

inpfile (str) – The input file name

class wntr.epanet.toolkit.ENepanet(inpfile='', rptfile='', binfile='', version=2.2)[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.

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)

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

int – 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

int – 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 hydraulics file to output

ENusehydfile(filename)[source]

Opens previously saved binary hydraulics file

Parameters

filename (str) – Name of hydraulics file to use

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

int – 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

int – 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)

Returns

int – 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

Returns

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)

Returns

Value of node’s parameter

ENgetlinkindex(sId)[source]

Retrieves index of a link with specific ID

Parameters

sId (int) – Link ID

Returns

Index of link in list of links

ENgetlinkvalue(iIndex, iCode)[source]

Retrieves parameter value for a link

Parameters
  • iIndex (int) – Link index

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

Returns

Value of link’s parameter

ENsaveinpfile(inpfile)[source]

Saves EPANET input file

Parameters

inpfile (str) – EPANET INP output file