trying to incorporate some of the stepwise solution functionality into the regular epanet toolkit functions.

This commit is contained in:
sam hatchett
2013-02-04 16:29:04 -05:00
parent ab87f72e29
commit afc80b6b13
4 changed files with 80 additions and 29 deletions

View File

@@ -742,7 +742,8 @@ int DLLEXPORT ENopenQ()
OpenQflag = FALSE; OpenQflag = FALSE;
SaveQflag = FALSE; SaveQflag = FALSE;
if (!Openflag) return(102); if (!Openflag) return(102);
if (!SaveHflag) return(104); // !LT! todo - check for SaveHflag / set sequential/step mode
//if (!SaveHflag) return(104);
/* Open WQ solver */ /* Open WQ solver */
ERRCODE(openqual()); ERRCODE(openqual());

View File

@@ -188,7 +188,10 @@ void initqual()
Wsource = 0.0; Wsource = 0.0;
/* Re-position hydraulics file */ /* Re-position hydraulics file */
fseek(HydFile,HydOffset,SEEK_SET); if (!OpenHflag) {
fseek(HydFile,HydOffset,SEEK_SET);
}
/* Set elapsed times to zero */ /* Set elapsed times to zero */
Htime = 0; Htime = 0;
@@ -220,7 +223,9 @@ int runqual(long *t)
if (Qtime == Htime) if (Qtime == Htime)
{ {
errcode = gethyd(&hydtime, &hydstep); errcode = gethyd(&hydtime, &hydstep);
Htime = hydtime + hydstep; if (!OpenHflag) { // test for sequential vs stepwise
Htime = hydtime + hydstep;
}
} }
return(errcode); return(errcode);
} }
@@ -343,10 +348,14 @@ int gethyd(long *hydtime, long *hydstep)
{ {
int errcode = 0; int errcode = 0;
/* Read hydraulic results from file */ // if hydraulics are not open, then we're operating in sequential mode.
if (!readhyd(hydtime)) return(307); // else hydraulics are open, so use the hydraulic results in memory rather than reading from the temp file.
if (!readhydstep(hydstep)) return(307); if (!OpenHflag) {
Htime = *hydtime; /* Read hydraulic results from file */
if (!readhyd(hydtime)) return(307);
if (!readhydstep(hydstep)) return(307);
Htime = *hydtime;
}
/* Save current results to output file */ /* Save current results to output file */
if (Htime >= Rtime) if (Htime >= Rtime)
@@ -1067,7 +1076,10 @@ void tankmix1(int i, long dt)
/* Determine tank & volumes */ /* Determine tank & volumes */
vold = Tank[i].V; vold = Tank[i].V;
n = Tank[i].Node; n = Tank[i].Node;
Tank[i].V += D[n]*dt; if (!OpenHflag) {
Tank[i].V += D[n]*dt;
}
vin = VolIn[n]; vin = VolIn[n];
/* Compute inflow concen. */ /* Compute inflow concen. */

View File

@@ -1,11 +1,12 @@
#include "testLemonTiger.h" #include "testLemonTiger.h"
#include "epanet2.h" #include "toolkit.h"
using namespace std; using namespace std;
void checkErr(int err, std::string function); void checkErr(int err, std::string function);
void stats();
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
@@ -15,44 +16,63 @@ int main(int argc, char * argv[]) {
long tstep = 0; long tstep = 0;
long simulationTime = 0; long simulationTime = 0;
long nextEventH = 0; long nextEventH = 0, nextEventQ = 0;
long simTimeRemaining = 0; long simTimeRemaining = 0;
try { try {
/* Batch solver (old epanet) */ /* Batch solver (old epanet) */
cout << "*****Original EPANET results******" << endl; cout << "*****Original EPANET results******" << endl;
checkErr( ENopen(argv[1], argv[2], ""), "ENopen" ); checkErr( ENopen(argv[1], argv[2], "out.bin"), "ENopen" );
checkErr( ENopenH(), "ENopenH" ); checkErr( ENopenH(), "ENopenH" );
checkErr( ENinitH(EN_SAVE), "ENinitH" ); checkErr( ENinitH(EN_SAVE), "ENinitH" );
cout << "Running hydraulics..." << endl;
do { do {
/* Solve for hydraulics & advance to next time period */ /* Solve for hydraulics & advance to next time period */
tstep = 0; tstep = 0;
checkErr( ENrunH(&simulationTime), "ENrunH" ); checkErr( ENrunH(&simulationTime), "ENrunH" );
checkErr( ENnextH(&nextEventH), "ENnextH" ); checkErr( ENnextH(&nextEventH), "ENnextH" );
stats();
// gather hydraulic results // gather hydraulic results
} while (nextEventH > 0); } while (nextEventH > 0);
// hydraulics are done // hydraulics are done
checkErr( ENcloseH(), "ENcloseH" ); checkErr( ENcloseH(), "ENcloseH" );
cout << "\t\t\tdone." << endl;
cout << "Running WQ..." << endl; cout << "Running WQ..." << endl;
checkErr( ENopenQ(), "ENopenQ" ); checkErr( ENopenQ(), "ENopenQ" );
checkErr( ENinitQ(EN_SAVE), "ENinitQ" ); checkErr( ENinitQ(EN_SAVE), "ENinitQ" );
do { do {
//long htime;
//ENgettimeparam(EN_HTIME, &htime);
//cout << "Htime = " << htime << endl;
checkErr( ENrunQ(&simulationTime), "ENrunQ" ); checkErr( ENrunQ(&simulationTime), "ENrunQ" );
checkErr( ENstepQ(&simTimeRemaining), "ENstepQ" );
//ENgettimeparam(EN_HTIME, &htime);
//cout << "Htime = " << htime << endl;
checkErr( ENnextQ(&nextEventH), "ENstepQ" );
//ENgettimeparam(EN_HTIME, &htime);
//cout << "Htime = " << htime << endl;
// wq results // wq results
//cout << simulationTime << "\t\t" << nextEventH << endl;
} while (simTimeRemaining > 0); } while (nextEventH > 0);
// water quality is done // water quality is done
checkErr( ENcloseQ(), "ENcloseQ" ); checkErr( ENcloseQ(), "ENcloseQ" );
cout << "\t\t\tdone." << endl;
// everything is done // everything is done
checkErr( ENclose(), "ENclose" ); checkErr( ENclose(), "ENclose" );
@@ -65,27 +85,34 @@ int main(int argc, char * argv[]) {
/* stepwise solver (LemonTiger) */ /* stepwise solver (LemonTiger) */
cout << "*****LemonTiger results******" << endl; cout << "*****LemonTiger results******" << endl;
checkErr( ENopen(argv[1], argv[2], NULL), "ENopen" ); checkErr( ENopen(argv[1], argv[2], "out2.bin"), "ENopen" );
checkErr( ENopenH(), "ENopenH" ); checkErr( ENopenH(), "ENopenH" );
checkErr( ENinitH(EN_SAVE), "ENinitH" ); checkErr( ENinitH(EN_NOSAVE), "ENinitH" );
checkErr( ENopenQ(), "ENopenQ" ); checkErr( ENopenQ(), "ENopenQ" );
checkErr( ENinitQ(EN_SAVE), "ENinitQ" ); checkErr( ENinitQ(EN_NOSAVE), "ENinitQ" );
cout << "Running stepwise hydraulics and water quality..." << endl;
do { do {
/* Solve for hydraulics & advance to next time period */ /* Solve for hydraulics & advance to next time period */
tstep = 0; tstep = 0;
checkErr( ENrunH(&simulationTime), "ENrunH" ); checkErr( ENrunH(&simulationTime), "ENrunH" );
checkErr( ENnextH(&nextEventH), "ENnextH" );
// hydraulic results
checkErr( ENrunQ(&simulationTime), "ENrunQ" ); checkErr( ENrunQ(&simulationTime), "ENrunQ" );
checkErr( ENstepQ(&simTimeRemaining), "ENstepQ" );
//stats();
checkErr( ENnextH(&nextEventH), "ENnextH" );
checkErr( ENnextQ(&nextEventQ), "ENstepQ" );
stats();
// wq results // wq results
//cout << simulationTime << "\t\t" << nextEventH << endl;
} while (nextEventH > 0);
cout << "\t\t\tdone." << endl;
} while (simTimeRemaining > 0);
// all done // all done
checkErr( ENcloseH(), "ENcloseH" ); checkErr( ENcloseH(), "ENcloseH" );
checkErr( ENcloseQ(), "ENcloseQ" ); checkErr( ENcloseQ(), "ENcloseQ" );
@@ -99,6 +126,17 @@ int main(int argc, char * argv[]) {
void stats() {
long htime;
int nodeIndex;
float head, volume;
ENgettimeparam(EN_HTIME, &htime);
ENgetnodeindex((char*)"1", &nodeIndex);
ENgetnodevalue(nodeIndex, EN_HEAD, &head);
cout << htime << "\t\t" << head << endl;
}
void checkErr(int err, std::string function) { void checkErr(int err, std::string function) {
if (err > 0) { if (err > 0) {

View File

@@ -331,7 +331,7 @@ Link 330 OPEN IF Node 1 ABOVE 19.1
;Tank Model ;Tank Model
[TIMES] [TIMES]
Duration 24:00 Duration 6:00
Hydraulic Timestep 1:00 Hydraulic Timestep 1:00
Quality Timestep 0:05 Quality Timestep 0:05
Pattern Timestep 1:00 Pattern Timestep 1:00