OWA-EPANET Toolkit  2.2
Chlorine Dosage Example

This example illustrates how the Toolkit could be used to determine the lowest dose of chlorine applied at the entrance to a distribution system needed to ensure that a minimum residual is met throughout the system. We assume that the EPANET input file contains the proper set of kinetic coefficients that describe the rate at which chlorine will decay in the system being studied. In the example code, the ID label of the source node is contained in SourceID, the minimum residual target is given by Ctarget, and the target is only checked after a start-up duration of 5 days (432,000 seconds). To keep the code more readable, no error checking is made on the results returned from the Toolkit function calls.

#include "epanet2_2.h"
double cl2dose(char *SourceID, double Ctarget)
int i, nnodes, sourceindex, violation;
double c, csource;
long t, tstep;
// Open the toolkit & obtain a hydraulic solution
EN_open(ph, "example3.inp", "example3.rpt", "");
// Get the number of nodes and the source node's index
EN_getcount(ph, EN_NODECOUNT, &nnodes);
EN_getnodeindex(ph, SourceID, &sourceindex);
// Setup the system to analyze for chlorine
// (in case it was not done in the input file)
EN_setqualtype(ph, EN_CHEM, "Chlorine", "mg/L", "");
// Open the water quality solver
// Begin the search for the source concentration
csource = 0.0;
do {
// Update source concentration to next level
csource = csource + 0.1;
EN_setnodevalue(ph, sourceindex, EN_SOURCEQUAL, csource);
// Run WQ simulation checking for target violations
violation = 0;
EN_initQ(ph, 0);
do {
EN_runQ(ph, &t);
if (t > 432000) {
for (i=1; i<=nnodes; i++) {
if (c < Ctarget) {
violation = 1;
EN_nextQ(ph, &tstep);
// End WQ run if violation found
} while (!violation && tstep > 0);
// Continue search if violation found
} while (violation && csource <= 4.0);
// Close up the WQ solver and delete the project
return csource;
Current computed quality (read only)
Definition: epanet2_enums.h:51
int EN_getnodevalue(EN_Project ph, int index, int property, double *value)
Retrieves a property value for a node.
int EN_open(EN_Project ph, const char *inpFile, const char *rptFile, const char *outFile)
Opens an EPANET input file & reads in network data.
int EN_getcount(EN_Project ph, int object, int *count)
Retrieves the number of objects of a given type in a project.
int EN_setnodevalue(EN_Project ph, int index, int property, double value)
Sets a property value for a node.
struct Project * EN_Project
The EPANET Project wrapper object.
Definition: epanet2_2.h:49
int EN_solveH(EN_Project ph)
Runs a complete hydraulic simulation with results for all time periods written to a temporary hydraul...
int EN_getnodeindex(EN_Project ph, char *id, int *index)
Gets the index of a node given its ID name.
int EN_createproject(EN_Project *ph)
Creates an EPANET project.
int EN_closeQ(EN_Project ph)
Closes the water quality solver, freeing all of its allocated memory.
int EN_initQ(EN_Project ph, int saveFlag)
Initializes a network prior to running a water quality analysis.
Chemical fate and transport.
Definition: epanet2_enums.h:226
Number of nodes (junctions + tanks + reservoirs)
Definition: epanet2_enums.h:159
Quality source strength.
Definition: epanet2_enums.h:44
int EN_nextQ(EN_Project ph, long *tStep)
Advances a water quality simulation over the time until the next hydraulic event.
int EN_runQ(EN_Project ph, long *currentTime)
Makes hydraulic and water quality results at the start of the current time period available to a proj...
int EN_setqualtype(EN_Project ph, int qualType, char *chemName, char *chemUnits, char *traceNode)
Sets the type of water quality analysis to run.
int EN_deleteproject(EN_Project ph)
Deletes a currently opened EPANET project.
int EN_openQ(EN_Project ph)
Opens a project's water quality solver.