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", "");
EN_solveH(ph);
// 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
EN_openQ(ph);
// 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;
break;
}
}
}
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
EN_closeQ(ph);
return csource;
}
EN_getnodeindex
int EN_getnodeindex(EN_Project ph, char *id, int *out_index)
Gets the index of a node given its ID name.
EN_nextQ
int EN_nextQ(EN_Project ph, long *out_tStep)
Advances a water quality simulation over the time until the next hydraulic event.
EN_runQ
int EN_runQ(EN_Project ph, long *out_currentTime)
Makes hydraulic and water quality results at the start of the current time period available to a proj...
EN_QUALITY
Current computed quality (read only)
Definition: epanet2_enums.h:51
EN_open
int EN_open(EN_Project ph, const char *inpFile, const char *rptFile, const char *outFile)
Opens an EPANET input file & reads in network data.
EN_getnodevalue
int EN_getnodevalue(EN_Project ph, int index, int property, double *out_value)
Retrieves a property value for a node.
EN_setnodevalue
int EN_setnodevalue(EN_Project ph, int index, int property, double value)
Sets a property value for a node.
EN_Project
struct Project * EN_Project
The EPANET Project wrapper object.
Definition: epanet2_2.h:49
EN_solveH
int EN_solveH(EN_Project ph)
Runs a complete hydraulic simulation with results for all time periods written to a temporary hydraul...
EN_createproject
int EN_createproject(EN_Project *ph)
Creates an EPANET project.
EN_closeQ
int EN_closeQ(EN_Project ph)
Closes the water quality solver, freeing all of its allocated memory.
EN_initQ
int EN_initQ(EN_Project ph, int saveFlag)
Initializes a network prior to running a water quality analysis.
EN_CHEM
Chemical fate and transport.
Definition: epanet2_enums.h:229
EN_NODECOUNT
Number of nodes (junctions + tanks + reservoirs)
Definition: epanet2_enums.h:162
EN_SOURCEQUAL
Quality source strength.
Definition: epanet2_enums.h:44
EN_setqualtype
int EN_setqualtype(EN_Project ph, int qualType, char *chemName, char *chemUnits, char *traceNode)
Sets the type of water quality analysis to run.
EN_deleteproject
int EN_deleteproject(EN_Project ph)
Deletes a currently opened EPANET project.
EN_openQ
int EN_openQ(EN_Project ph)
Opens a project's water quality solver.
epanet2_2.h
EN_getcount
int EN_getcount(EN_Project ph, int object, int *out_count)
Retrieves the number of objects of a given type in a project.