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.
double cl2dose(char *SourceID, double Ctarget)
{
int i, nnodes, sourceindex, violation;
double c, csource;
long t, tstep;
EN_open(ph,
"example3.inp",
"example3.rpt",
"");
csource = 0.0;
do {
csource = csource + 0.1;
violation = 0;
do {
if (t > 432000) {
for (i=1; i<=nnodes; i++) {
if (c < Ctarget) {
violation = 1;
break;
}
}
}
} while (!violation && tstep > 0);
} while (violation && csource <= 4.0);
return csource;
}
int EN_getnodeindex(EN_Project ph, char *id, int *out_index)
Gets the index of a node given its ID name.
int EN_nextQ(EN_Project ph, long *out_tStep)
Advances a water quality simulation over the time until the next hydraulic event.
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...
Current computed quality (read only)
Definition: epanet2_enums.h:51
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_getnodevalue(EN_Project ph, int index, int property, double *out_value)
Retrieves a property value for a node.
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_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:229
Number of nodes (junctions + tanks + reservoirs)
Definition: epanet2_enums.h:162
Quality source strength.
Definition: epanet2_enums.h:44
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.
int EN_getcount(EN_Project ph, int object, int *out_count)
Retrieves the number of objects of a given type in a project.