pretty output
This commit is contained in:
@@ -1,21 +1,40 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#include "testLemonTiger.h"
|
#include "testLemonTiger.h"
|
||||||
#include "toolkit.h"
|
#include "toolkit.h"
|
||||||
|
|
||||||
|
#define COLW 15
|
||||||
|
#define OUTPRECISION 6
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double head;
|
||||||
|
double demand;
|
||||||
|
double quality;
|
||||||
|
} singleState_t;
|
||||||
|
|
||||||
|
typedef map<int, singleState_t> networkState_t; // nodeIndex, state
|
||||||
|
typedef map<long, networkState_t> result_t; // time, networkState
|
||||||
|
// access results by, for instance, resultsContainer[time][nodeIndex].head
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void checkErr(int err, std::string function);
|
void checkErr(int err, std::string function);
|
||||||
void hydStats();
|
void saveHydResults(networkState_t* networkState);
|
||||||
void qualStats();
|
void saveQualResults(networkState_t* networkState);
|
||||||
|
void printResults(result_t* state1, result_t* state2, std::ostream& out);
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
|
|
||||||
|
// create storage structures for results.
|
||||||
|
result_t epanetResults, lemonTigerResults;
|
||||||
|
|
||||||
cout << "Lemon Tiger TEST" << endl
|
cout << "Lemon Tiger TEST" << endl
|
||||||
<< "________________" << endl;
|
<< "________________" << endl;
|
||||||
|
|
||||||
|
|
||||||
long tstep = 0;
|
|
||||||
long simulationTime = 0;
|
long simulationTime = 0;
|
||||||
long nextEventH = 0, nextEventQ = 0;
|
long nextEventH = 0, nextEventQ = 0;
|
||||||
long simTimeRemaining = 0;
|
long simTimeRemaining = 0;
|
||||||
@@ -32,15 +51,14 @@ int main(int argc, char * argv[]) {
|
|||||||
cout << "Running hydraulics..." << endl;
|
cout << "Running hydraulics..." << endl;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
/* Solve for hydraulics & advance to next time period */
|
/* Solve for hydraulics & advance to next time period */
|
||||||
tstep = 0;
|
|
||||||
|
|
||||||
checkErr( ENrunH(&simulationTime), "ENrunH" );
|
checkErr( ENrunH(&simulationTime), "ENrunH" );
|
||||||
checkErr( ENnextH(&nextEventH), "ENnextH" );
|
checkErr( ENnextH(&nextEventH), "ENnextH" );
|
||||||
|
|
||||||
hydStats();
|
|
||||||
|
|
||||||
// gather hydraulic results
|
// gather hydraulic results
|
||||||
|
saveHydResults(&epanetResults[simulationTime]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} while (nextEventH > 0);
|
} while (nextEventH > 0);
|
||||||
// hydraulics are done
|
// hydraulics are done
|
||||||
@@ -56,7 +74,8 @@ int main(int argc, char * argv[]) {
|
|||||||
checkErr( ENrunQ(&simulationTime), "ENrunQ" );
|
checkErr( ENrunQ(&simulationTime), "ENrunQ" );
|
||||||
checkErr( ENnextQ(&nextEventH), "ENstepQ" );
|
checkErr( ENnextQ(&nextEventH), "ENstepQ" );
|
||||||
|
|
||||||
qualStats();
|
// gather quality results
|
||||||
|
saveQualResults(&epanetResults[simulationTime]);
|
||||||
|
|
||||||
} while (nextEventH > 0);
|
} while (nextEventH > 0);
|
||||||
// water quality is done
|
// water quality is done
|
||||||
@@ -83,22 +102,15 @@ int main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
cout << "Running stepwise hydraulics and water quality..." << endl;
|
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;
|
|
||||||
|
|
||||||
checkErr( ENrunH(&simulationTime), "ENrunH" );
|
checkErr( ENrunH(&simulationTime), "ENrunH" );
|
||||||
checkErr( ENrunQ(&simulationTime), "ENrunQ" );
|
checkErr( ENrunQ(&simulationTime), "ENrunQ" );
|
||||||
|
|
||||||
//stats();
|
|
||||||
|
|
||||||
checkErr( ENnextH(&nextEventH), "ENnextH" );
|
checkErr( ENnextH(&nextEventH), "ENnextH" );
|
||||||
checkErr( ENnextQ(&nextEventQ), "ENstepQ" );
|
checkErr( ENnextQ(&nextEventQ), "ENstepQ" );
|
||||||
|
|
||||||
//hydStats();
|
saveHydResults(&lemonTigerResults[simulationTime]);
|
||||||
qualStats();
|
saveQualResults(&lemonTigerResults[simulationTime]);
|
||||||
|
|
||||||
// wq results
|
|
||||||
//cout << simulationTime << "\t\t" << nextEventH << endl;
|
|
||||||
|
|
||||||
} while (nextEventH > 0);
|
} while (nextEventH > 0);
|
||||||
cout << "\t\t\tdone." << endl;
|
cout << "\t\t\tdone." << endl;
|
||||||
@@ -109,34 +121,100 @@ int main(int argc, char * argv[]) {
|
|||||||
checkErr( ENclose(), "ENclose" );
|
checkErr( ENclose(), "ENclose" );
|
||||||
|
|
||||||
|
|
||||||
|
// summarize the results
|
||||||
|
printResults(&epanetResults, &lemonTigerResults, cout);
|
||||||
|
|
||||||
|
|
||||||
} catch (int err) {
|
} catch (int err) {
|
||||||
cerr << "exiting with error " << err << endl;
|
cerr << "exiting with error " << err << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void saveHydResults(networkState_t* networkState) {
|
||||||
void hydStats() {
|
int nNodes;
|
||||||
long htime;
|
float head, demand;
|
||||||
int nodeIndex;
|
ENgetcount(EN_NODECOUNT, &nNodes);
|
||||||
float head;
|
|
||||||
ENgettimeparam(EN_HTIME, &htime);
|
for (int iNode = 1; iNode <= nNodes; iNode++) {
|
||||||
ENgetnodeindex((char*)"NewportTank", &nodeIndex);
|
ENgetnodevalue(iNode, EN_HEAD, &head);
|
||||||
ENgetnodevalue(nodeIndex, EN_HEAD, &head);
|
ENgetnodevalue(iNode, EN_DEMAND, &demand);
|
||||||
cout << htime << "\t\th = " << head << endl;
|
(*networkState)[iNode].head = head;
|
||||||
|
(*networkState)[iNode].demand = demand;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void qualStats() {
|
|
||||||
long htime;
|
void saveQualResults(networkState_t* networkState) {
|
||||||
int nodeIndex;
|
int nNodes;
|
||||||
float quality;
|
float quality;
|
||||||
ENgettimeparam(EN_HTIME, &htime);
|
ENgetcount(EN_NODECOUNT, &nNodes);
|
||||||
ENgetnodeindex((char*)"NewportTank", &nodeIndex);
|
|
||||||
ENgetnodevalue(nodeIndex, EN_QUALITY, &quality);
|
for (int iNode = 1; iNode <= nNodes; iNode++) {
|
||||||
cout << htime << "\t\tc = " << quality << endl;
|
ENgetnodevalue(iNode, EN_QUALITY, &quality);
|
||||||
|
(*networkState)[iNode].quality = quality;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printResults(result_t* results1, result_t* results2, std::ostream &out) {
|
||||||
|
|
||||||
|
result_t::const_iterator resultIterator;
|
||||||
|
|
||||||
|
for (resultIterator = (*results1).begin(); resultIterator != (*results1).end(); ++resultIterator) {
|
||||||
|
// get the current frame
|
||||||
|
const long time = resultIterator->first;
|
||||||
|
const networkState_t state1 = resultIterator->second;
|
||||||
|
|
||||||
|
// see if this time is indexed in the second state container
|
||||||
|
if ((*results2).find(time) == (*results2).end()) {
|
||||||
|
// nope.
|
||||||
|
out << "time " << time << " not found in second result set" << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// get the second result set's state
|
||||||
|
const networkState_t state2 = (*results2)[time];
|
||||||
|
|
||||||
|
// print the current simulation time
|
||||||
|
out << left;
|
||||||
|
out << setfill('*') << setw(100) << "*" << endl;
|
||||||
|
out << setfill(' ');
|
||||||
|
out << setw(4) << "T = " << setw(6) << time;
|
||||||
|
out << "|" << setw(3*COLW) << "EPANET";
|
||||||
|
out << "|" << setw(3*COLW) << "LemonTiger" << endl;
|
||||||
|
out << setw(10) << "Index" << "|";
|
||||||
|
out << setw(COLW) << "Demand" << setw(COLW) << "Head" << setw(COLW) << "Quality" << "|";
|
||||||
|
out << setw(COLW) << "Demand" << setw(COLW) << "Head" << setw(COLW) << "Quality" << endl;
|
||||||
|
out << setprecision(OUTPRECISION);
|
||||||
|
|
||||||
|
// loop through the nodes in the networkState objs, and print out the results for this time period
|
||||||
|
networkState_t::const_iterator networkIterator;
|
||||||
|
for (networkIterator = state1.begin(); networkIterator != state1.end(); ++networkIterator) {
|
||||||
|
int nodeIndex = networkIterator->first;
|
||||||
|
// trusting that all nodes are present...
|
||||||
|
const singleState_t nodeState1 = networkIterator->second;
|
||||||
|
const singleState_t nodeState2 = state2.at(nodeIndex);
|
||||||
|
|
||||||
|
// epanet
|
||||||
|
out << setw(10) << nodeIndex << "|";
|
||||||
|
out << setw(COLW) << nodeState1.demand;
|
||||||
|
out << setw(COLW) << nodeState1.head;
|
||||||
|
out << setw(COLW) << nodeState1.quality;
|
||||||
|
|
||||||
|
// lemontiger
|
||||||
|
out << "|";
|
||||||
|
out << setw(COLW) << nodeState2.demand;
|
||||||
|
out << setw(COLW) << nodeState2.head;
|
||||||
|
out << setw(COLW) << nodeState2.quality;
|
||||||
|
out << endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void checkErr(int err, std::string function) {
|
void checkErr(int err, std::string function) {
|
||||||
if (err > 0) {
|
if (err > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user