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