rethinking the python wrapper (#511)
* renames certain function parameter declarations and removes double pointer call from the deleteproject function * deprecates conditonal compilation, removes python-specific headers and function renaming * fixes tests and docs * fixes test
This commit is contained in:
@@ -9,7 +9,7 @@ Here are several examples of how the Toolkit can be used for different types of
|
||||
*/
|
||||
|
||||
/** @page Example1 Embedded Engine Example
|
||||
This example shows how simple it is for the Toolkit to provide a network analysis engine for other applications. There are three steps that the application would need to take:
|
||||
This example shows how simple it is for the Toolkit to provide a network analysis engine for other applications. There are three steps that the application would need to take:
|
||||
-# Have the application write network data to an EPANET-formatted input file.
|
||||
|
||||
-# Create a project and call @ref EN_runproject, supplying the name of the EPANET input file, the name of a Report file where status and error messages are written, and the name of a binary Output file which will contain analysis results.
|
||||
@@ -32,9 +32,9 @@ int runEpanet(char* inpFile, char* rptFile, char* outFile)
|
||||
EN_project ph;
|
||||
EN_createproject(&pH);
|
||||
errcode = EN_runproject(ph, inpFile, rptFile, outFile, &writeConsole);
|
||||
EN_deleteproject(&ph);
|
||||
EN_deleteproject(ph);
|
||||
return errcode;
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
@@ -62,12 +62,12 @@ void netbuilder()
|
||||
EN_Project ph;
|
||||
EN_createproject(&ph);
|
||||
EN_init(ph, "", "", EN_GPM, EN_HW);
|
||||
|
||||
|
||||
// Add the first junction node to the project with
|
||||
// an elevation of 700 ft and a demand of 0
|
||||
// an elevation of 700 ft and a demand of 0
|
||||
EN_addnode(ph, "J1", EN_JUNCTION, &index);
|
||||
EN_setjuncdata(ph, index, 700, 0, "");
|
||||
|
||||
|
||||
// Add the remaining two junctions with elevations of
|
||||
// 710 ft and demands of 250 and 500 gpm, respectively
|
||||
EN_addnode(ph, "J2", EN_JUNCTION, &index);
|
||||
@@ -84,7 +84,7 @@ void netbuilder()
|
||||
// and a diameter of 50.5 ft
|
||||
EN_addnode(ph, "T1", EN_TANK, &index);
|
||||
EN_settankdata(ph, index, 850, 120, 100, 150, 50.5, 0, "");
|
||||
|
||||
|
||||
// Add the pipes to the project, setting their length,
|
||||
// diameter, and roughness values
|
||||
EN_addlink(ph, "P1", EN_PIPE, "J1", "J2", &index);
|
||||
@@ -95,10 +95,10 @@ void netbuilder()
|
||||
EN_setpipedata(ph, index, 5280, 14, 100, 0);
|
||||
EN_addlink(ph, "P4", EN_PIPE, "J2", "J3", &index);
|
||||
EN_setpipedata(ph, index, 5280, 14, 100, 0);
|
||||
|
||||
|
||||
// Add a pump to the project
|
||||
EN_addlink(ph, "PUMP", EN_PUMP, "R1", "J1", &index);
|
||||
|
||||
|
||||
// Create a single point head curve (index = 1) and
|
||||
// assign it to the pump
|
||||
EN_addcurve(ph, "C1");
|
||||
@@ -109,53 +109,53 @@ void netbuilder()
|
||||
EN_saveinpfile(ph, "example2.inp");
|
||||
|
||||
// Delete the project
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
EN_deleteproject(ph);
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
/** @page Example3 Hydrant Rating Curve Example
|
||||
|
||||
This example illustrates how the Toolkit could be used to develop a hydrant rating curve used in fire flow studies. This curve shows the amount of flow available at a node in the system as a function of pressure. The curve is generated by running a number of steady state hydraulic analyses with the node of interest subjected to a different demand in each analysis. For this example we assume that the ID label of the node of interest is `MyNode` and that `N` different demand levels stored in the array `D` need to be examined. The corresponding pressures will be stored in `P`. To keep the code more readable, no error checking is made on the results returned from the Toolkit function calls.
|
||||
This example illustrates how the Toolkit could be used to develop a hydrant rating curve used in fire flow studies. This curve shows the amount of flow available at a node in the system as a function of pressure. The curve is generated by running a number of steady state hydraulic analyses with the node of interest subjected to a different demand in each analysis. For this example we assume that the ID label of the node of interest is `MyNode` and that `N` different demand levels stored in the array `D` need to be examined. The corresponding pressures will be stored in `P`. To keep the code more readable, no error checking is made on the results returned from the Toolkit function calls.
|
||||
|
||||
\code {.c}
|
||||
#include "epanet2_2.h"
|
||||
#include "epanet2_2.h"
|
||||
|
||||
void HydrantRating(char *MyNode, int N, double D[], double P[])
|
||||
{
|
||||
void HydrantRating(char *MyNode, int N, double D[], double P[])
|
||||
{
|
||||
EN_Project ph;
|
||||
int i, nodeindex;
|
||||
long t;
|
||||
double pressure;
|
||||
int i, nodeindex;
|
||||
long t;
|
||||
double pressure;
|
||||
|
||||
// Create a project
|
||||
EN_createproject(&ph);
|
||||
|
||||
|
||||
// Retrieve network data from an input file
|
||||
EN_open(ph, "example2.inp", "example2.rpt", "");
|
||||
|
||||
EN_open(ph, "example2.inp", "example2.rpt", "");
|
||||
|
||||
// Open the hydraulic solver
|
||||
EN_openH(ph);
|
||||
EN_openH(ph);
|
||||
|
||||
// Get the index of the node of interest
|
||||
EN_getnodeindex(ph, MyNode, &nodeindex);
|
||||
EN_getnodeindex(ph, MyNode, &nodeindex);
|
||||
|
||||
// Iterate over all demands
|
||||
for (i=1; i<N; i++)
|
||||
{
|
||||
for (i=1; i<N; i++)
|
||||
{
|
||||
// Set nodal demand, initialize hydraulics, make a
|
||||
// single period run, and retrieve pressure
|
||||
EN_setnodevalue(ph, nodeindex, EN_BASEDEMAND, D[i]);
|
||||
EN_initH(ph, 0);
|
||||
EN_runH(ph, &t);
|
||||
EN_getnodevalue(ph, nodeindex, EN_PRESSURE, &pressure);
|
||||
P[i] = pressure;
|
||||
}
|
||||
EN_setnodevalue(ph, nodeindex, EN_BASEDEMAND, D[i]);
|
||||
EN_initH(ph, 0);
|
||||
EN_runH(ph, &t);
|
||||
EN_getnodevalue(ph, nodeindex, EN_PRESSURE, &pressure);
|
||||
P[i] = pressure;
|
||||
}
|
||||
|
||||
// Close hydraulics solver & delete the project
|
||||
EN_closeH(ph);
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
EN_closeH(ph);
|
||||
EN_deleteproject(ph);
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
@@ -164,66 +164,66 @@ void HydrantRating(char *MyNode, int N, double D[], double P[])
|
||||
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.
|
||||
|
||||
\code {.c}
|
||||
#include "epanet2_2.h"
|
||||
#include "epanet2_2.h"
|
||||
|
||||
double cl2dose(char *SourceID, double Ctarget)
|
||||
{
|
||||
int i, nnodes, sourceindex, violation;
|
||||
double c, csource;
|
||||
double cl2dose(char *SourceID, double Ctarget)
|
||||
{
|
||||
int i, nnodes, sourceindex, violation;
|
||||
double c, csource;
|
||||
long t, tstep;
|
||||
EN_Project ph;
|
||||
|
||||
// Open the toolkit & obtain a hydraulic solution
|
||||
EN_createproject(&ph);
|
||||
EN_open(ph, "example3.inp", "example3.rpt", "");
|
||||
EN_solveH(ph);
|
||||
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);
|
||||
// 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", "");
|
||||
EN_setqualtype(ph, EN_CHEM, "Chlorine", "mg/L", "");
|
||||
|
||||
// Open the water quality solver
|
||||
EN_openQ(ph);
|
||||
EN_openQ(ph);
|
||||
|
||||
// Begin the search for the source concentration
|
||||
csource = 0.0;
|
||||
do {
|
||||
// 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);
|
||||
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++) {
|
||||
EN_getnodevalue(ph, i, EN_QUALITY, &c);
|
||||
if (c < Ctarget) {
|
||||
violation = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EN_nextQ(ph, &tstep);
|
||||
violation = 0;
|
||||
EN_initQ(ph, 0);
|
||||
do {
|
||||
EN_runQ(ph, &t);
|
||||
if (t > 432000) {
|
||||
for (i=1; i<=nnodes; i++) {
|
||||
EN_getnodevalue(ph, i, EN_QUALITY, &c);
|
||||
if (c < Ctarget) {
|
||||
violation = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EN_nextQ(ph, &tstep);
|
||||
|
||||
// End WQ run if violation found
|
||||
} while (!violation && tstep > 0);
|
||||
} while (!violation && tstep > 0);
|
||||
|
||||
// Continue search if violation found
|
||||
} while (violation && csource <= 4.0);
|
||||
} while (violation && csource <= 4.0);
|
||||
|
||||
// Close up the WQ solver and delete the project
|
||||
EN_closeQ(ph);
|
||||
EN_deleteproject(&ph);
|
||||
return csource;
|
||||
}
|
||||
// Close up the WQ solver and delete the project
|
||||
EN_closeQ(ph);
|
||||
EN_deleteproject(ph);
|
||||
return csource;
|
||||
}
|
||||
\endcode
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user