this is the shape of the API

This commit is contained in:
Sam Hatchett
2013-02-01 18:11:39 -05:00
parent 4df40ebc3d
commit ab87f72e29
4 changed files with 104 additions and 80 deletions

View File

@@ -45,6 +45,7 @@
2298EBE116B17E440088A6DC /* lemontiger.c in Sources */ = {isa = PBXBuildFile; fileRef = 2298EBDF16B17E440088A6DC /* lemontiger.c */; };
2298EBE216B17E440088A6DC /* lemontiger.h in Headers */ = {isa = PBXBuildFile; fileRef = 2298EBE016B17E440088A6DC /* lemontiger.h */; };
22EF555716BC744C00F3988A /* testLemonTiger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 22EF555516BC744C00F3988A /* testLemonTiger.cpp */; };
22EF555A16BC7FF500F3988A /* libepanet.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC0630554660B00DB518D /* libepanet.dylib */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -55,6 +56,13 @@
remoteGlobalIDString = D2AAC0620554660B00DB518D;
remoteInfo = epanet;
};
22EF555816BC7FCC00F3988A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = D2AAC0620554660B00DB518D;
remoteInfo = epanet;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -114,6 +122,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
22EF555A16BC7FF500F3988A /* libepanet.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -247,6 +256,7 @@
buildRules = (
);
dependencies = (
22EF555916BC7FCC00F3988A /* PBXTargetDependency */,
);
name = TestLemonTiger;
productName = TestLemonTiger;
@@ -354,6 +364,11 @@
target = D2AAC0620554660B00DB518D /* epanet */;
targetProxy = 22322FAF1068370B00641384 /* PBXContainerItemProxy */;
};
22EF555916BC7FCC00F3988A /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = D2AAC0620554660B00DB518D /* epanet */;
targetProxy = 22EF555816BC7FCC00F3988A /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
@@ -542,6 +557,7 @@
22EF555316BC740400F3988A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};

View File

@@ -1,104 +1,111 @@
//
// testLemonTiger.cpp
// epanet
//
// Created by Sam Hatchett on 2/1/13.
//
//
#include "testLemonTiger.h"
#include "epanet2.h"
using namespace std;
void checkErr(int err, std::string function);
int main(int argc, char * argv[]) {
cout << "Lemon Tiger TEST" << endl;
int err = 0; //error code
long stime = 0; //simulation time point, = t = Htime
long step = 1; //time to next time point, = tstep = hydstep
long tleft = 0; //time left in the simulation
int id, id2, id3; // some node id
float value; // some node/link value
int TIME_A = 3600*3;
int TIME_B = 3600*6; //two time points for testing
int TIME_C = 3600*10;
cout << "Lemon Tiger TEST" << endl
<< "________________" << endl;
/* Asychronous solver (old epanet) */
printf("*****Original EPANET results******\n");
long tstep = 0;
long simulationTime = 0;
long nextEventH = 0;
long simTimeRemaining = 0;
if (err=ENopen(argv[1], argv[2], "")) return err;
try {
/* Batch solver (old epanet) */
cout << "*****Original EPANET results******" << endl;
checkErr( ENopen(argv[1], argv[2], ""), "ENopen" );
checkErr( ENopenH(), "ENopenH" );
checkErr( ENinitH(EN_SAVE), "ENinitH" );
do {
/* Solve for hydraulics & advance to next time period */
tstep = 0;
checkErr( ENrunH(&simulationTime), "ENrunH" );
checkErr( ENnextH(&nextEventH), "ENnextH" );
// gather hydraulic results
} while (nextEventH > 0);
// hydraulics are done
checkErr( ENcloseH(), "ENcloseH" );
cout << "Running WQ..." << endl;
checkErr( ENopenQ(), "ENopenQ" );
checkErr( ENinitQ(EN_SAVE), "ENinitQ" );
do {
checkErr( ENrunQ(&simulationTime), "ENrunQ" );
checkErr( ENstepQ(&simTimeRemaining), "ENstepQ" );
// wq results
} while (simTimeRemaining > 0);
// water quality is done
checkErr( ENcloseQ(), "ENcloseQ" );
// everything is done
checkErr( ENclose(), "ENclose" );
for (ENopenH(), ENinitH(1), step=1;
// must save intermediate results to disk (initH(1)), otherwise WQ solver won't execute
step>0; ENnextH(&step)) {
ENrunH(&stime);
}
ENcloseH();
nextEventH = 0;
simTimeRemaining = 0;
simulationTime = 0;
printf("\nReset time pointer and run WQ.\n");
for (step=1, ENopenQ(), ENinitQ(0); // this operation resets the internal time pointer (back to 0)
step>0; ENnextQ(&step)) {
/* stepwise solver (LemonTiger) */
cout << "*****LemonTiger results******" << endl;
ENrunQ(&stime);
checkErr( ENopen(argv[1], argv[2], NULL), "ENopen" );
checkErr( ENopenH(), "ENopenH" );
checkErr( ENinitH(EN_SAVE), "ENinitH" );
checkErr( ENopenQ(), "ENopenQ" );
checkErr( ENinitQ(EN_SAVE), "ENinitQ" );
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" );
// wq results
} while (simTimeRemaining > 0);
// all done
checkErr( ENcloseH(), "ENcloseH" );
checkErr( ENcloseQ(), "ENcloseQ" );
checkErr( ENclose(), "ENclose" );
// grab some results
if (stime == TIME_A || stime == TIME_B || stime == TIME_C) {
printf("WQ simulation time = %d sec, step = %d sec.\n", stime, step);
ENgetnodevalue(id, EN_QUALITY, &value);
printf("Node 184's quality = \t%f.\n", value);
ENgetnodevalue(id3, EN_QUALITY, &value);
printf("Node 199's quality = \t%f.\n", value);
} catch (int err) {
cerr << "exiting with error " << err << endl;
}
}
ENcloseQ();
ENclose();
/* Sychronous solver (LemonTiger) */
printf("\n\n*****LemonTiger results******\n\n");
if (err=ENopen(argv[1], argv[2], "")) return err;
for (ENopeninitHQ(), tleft=Dur; tleft>0; ) {
//ENrunstepHQ(&stime, &tleft);
ENrunnextHQ(&stime, &tleft); //well I know it should be tstep
if (stime == TIME_A || stime == TIME_B || stime == TIME_C) {
//if (! (stime%1800)){
printf("Simulation = %d sec, time left = %d sec.\n", stime, tleft);
ENgetnodevalue(id, EN_HEAD, &value);
printf("Node 184's head = \t%f.\n", value);
ENgetnodevalue(id, EN_QUALITY, &value);
printf("Node 184's quality = \t%f.\n", value);
ENgetnodevalue(id3, EN_HEAD, &value);
printf("Node 199's head = \t%f.\n", value);
ENgetnodevalue(id3, EN_QUALITY, &value);
printf("Node 199's quality = \t%f.\n", value);
ENgetlinkvalue(id2, EN_FLOW, &value);
printf("Link 101's flowrate = \t%f. \n", value);
printf("\n");
void checkErr(int err, std::string function) {
if (err > 0) {
cerr << "Error in " << function << ": " << err << endl;
char errmsg[1024];
ENgeterror(err, errmsg, 1024);
cerr << errmsg << endl;
throw err;
}
}
ENcloseHQ();
ENclose();
}
}

View File

@@ -10,5 +10,6 @@
#define __epanet__testLemonTiger__
#include <iostream>
#include <vector>
#endif /* defined(__epanet__testLemonTiger__) */

View File

@@ -178,7 +178,7 @@ extern "C" {
int DLLEXPORT ENopenH(void);
int DLLEXPORT ENinitH(int);
int DLLEXPORT ENrunH(long *);
int DLLEXPORT ENnextH(long *);
int DLLEXPORT ENnextH(long *tstep);
int DLLEXPORT ENcloseH(void);
int DLLEXPORT ENsavehydfile(char *);
int DLLEXPORT ENusehydfile(char *);