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;
SaveQflag = FALSE;
if (!Openflag) return(102);
if (!SaveHflag) return(104);
// !LT! todo - check for SaveHflag / set sequential/step mode
//if (!SaveHflag) return(104);
/* Open WQ solver */
ERRCODE(openqual());

View File

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

View File

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

View File

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