diff --git a/.gitignore b/.gitignore index d70f877..2167a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,7 @@ xcuserdata !xcschemes # Visual Studio 2012 +*.suo *.sdf *.filters *.user diff --git a/Debug/LemonTigerJ.dll b/Debug/LemonTigerJ.dll new file mode 100644 index 0000000..e15dedf Binary files /dev/null and b/Debug/LemonTigerJ.dll differ diff --git a/Debug/LemonTigerJ.lastbuildstate b/Debug/LemonTigerJ.lastbuildstate new file mode 100644 index 0000000..9a7e7ba --- /dev/null +++ b/Debug/LemonTigerJ.lastbuildstate @@ -0,0 +1,2 @@ +#v4.0:v110:false +Debug|Win32|C:\Users\owner\Documents\GitHub\epanet\| diff --git a/Debug/LemonTigerJ.lib b/Debug/LemonTigerJ.lib new file mode 100644 index 0000000..3fb12a8 Binary files /dev/null and b/Debug/LemonTigerJ.lib differ diff --git a/Debug/LemonTigerJ.log b/Debug/LemonTigerJ.log new file mode 100644 index 0000000..25ab7a8 --- /dev/null +++ b/Debug/LemonTigerJ.log @@ -0,0 +1,27 @@ +Build started 1/28/2013 3:11:19 PM. + 1>Project "C:\Users\owner\Documents\GitHub\epanet\LemonTigerJ.vcxproj" on node 2 (Build target(s)). + 1>ClCompile: + C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /I.\include /Zi /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _WINDLL /D _CRT_SECURE_NO_WARNINGS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc110.pdb" /Gd /TC /analyze- /errorReport:prompt src\testLT.c + testLT.c + Link: + C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\owner\Documents\GitHub\epanet\Debug\LemonTigerJ.dll" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\owner\Documents\GitHub\epanet\Debug\LemonTigerJ.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\owner\Documents\GitHub\epanet\Debug\LemonTigerJ.lib" /MACHINE:X86 /DLL Debug\epanet.obj + Debug\hash.obj + Debug\hydraul.obj + Debug\inpfile.obj + Debug\input1.obj + Debug\input2.obj + Debug\input3.obj + Debug\lemontiger.obj + Debug\mempool.obj + Debug\output.obj + Debug\quality.obj + Debug\report.obj + Debug\rules.obj + Debug\smatrix.obj + Debug\testLT.obj + LemonTigerJ.vcxproj -> C:\Users\owner\Documents\GitHub\epanet\Debug\LemonTigerJ.dll + 1>Done Building Project "C:\Users\owner\Documents\GitHub\epanet\LemonTigerJ.vcxproj" (Build target(s)). + +Build succeeded. + +Time Elapsed 00:00:01.13 diff --git a/LemonTigerJ.v11.suo b/LemonTigerJ.v11.suo index 4f787f3..d4ca826 100644 Binary files a/LemonTigerJ.v11.suo and b/LemonTigerJ.v11.suo differ diff --git a/LemonTigerJ.vcxproj b/LemonTigerJ.vcxproj index cab68ab..7ffa87b 100644 --- a/LemonTigerJ.vcxproj +++ b/LemonTigerJ.vcxproj @@ -11,7 +11,6 @@ - @@ -45,7 +44,7 @@ - Application + DynamicLibrary true v110 diff --git a/include/epanet2.h b/include/epanet2.h deleted file mode 100755 index d1d37f1..0000000 --- a/include/epanet2.h +++ /dev/null @@ -1,251 +0,0 @@ -/* -** EPANET2.H -** -** C/C++ header file for EPANET Programmers Toolkit -** -** Last updated on 2/14/08 (2.00.12) -*/ - -#ifndef EPANET2_H -#define EPANET2_H - -// --- Define the EPANET toolkit constants - -#define EN_ELEVATION 0 /* Node parameters */ -#define EN_BASEDEMAND 1 -#define EN_PATTERN 2 -#define EN_EMITTER 3 -#define EN_INITQUAL 4 -#define EN_SOURCEQUAL 5 -#define EN_SOURCEPAT 6 -#define EN_SOURCETYPE 7 -#define EN_TANKLEVEL 8 -#define EN_DEMAND 9 -#define EN_HEAD 10 -#define EN_PRESSURE 11 -#define EN_QUALITY 12 -#define EN_SOURCEMASS 13 -#define EN_INITVOLUME 14 -#define EN_MIXMODEL 15 -#define EN_MIXZONEVOL 16 - -#define EN_TANKDIAM 17 -#define EN_MINVOLUME 18 -#define EN_VOLCURVE 19 -#define EN_MINLEVEL 20 -#define EN_MAXLEVEL 21 -#define EN_MIXFRACTION 22 -#define EN_TANK_KBULK 23 - -#define EN_TANKVOLUME 24 /* TNT */ - -#define EN_DIAMETER 0 /* Link parameters */ -#define EN_LENGTH 1 -#define EN_ROUGHNESS 2 -#define EN_MINORLOSS 3 -#define EN_INITSTATUS 4 -#define EN_INITSETTING 5 -#define EN_KBULK 6 -#define EN_KWALL 7 -#define EN_FLOW 8 -#define EN_VELOCITY 9 -#define EN_HEADLOSS 10 -#define EN_STATUS 11 -#define EN_SETTING 12 -#define EN_ENERGY 13 -#define EN_LINKQUAL 14 /* TNT */ - -#define EN_DURATION 0 /* Time parameters */ -#define EN_HYDSTEP 1 -#define EN_QUALSTEP 2 -#define EN_PATTERNSTEP 3 -#define EN_PATTERNSTART 4 -#define EN_REPORTSTEP 5 -#define EN_REPORTSTART 6 -#define EN_RULESTEP 7 -#define EN_STATISTIC 8 -#define EN_PERIODS 9 -#define EN_STARTTIME 10 /* Added TNT 10/2/2009 */ - -#define EN_NODECOUNT 0 /* Component counts */ -#define EN_TANKCOUNT 1 -#define EN_LINKCOUNT 2 -#define EN_PATCOUNT 3 -#define EN_CURVECOUNT 4 -#define EN_CONTROLCOUNT 5 - -#define EN_JUNCTION 0 /* Node types */ -#define EN_RESERVOIR 1 -#define EN_TANK 2 - -#define EN_CVPIPE 0 /* Link types */ -#define EN_PIPE 1 -#define EN_PUMP 2 -#define EN_PRV 3 -#define EN_PSV 4 -#define EN_PBV 5 -#define EN_FCV 6 -#define EN_TCV 7 -#define EN_GPV 8 - -#define EN_NONE 0 /* Quality analysis types */ -#define EN_CHEM 1 -#define EN_AGE 2 -#define EN_TRACE 3 - -#define EN_CONCEN 0 /* Source quality types */ -#define EN_MASS 1 -#define EN_SETPOINT 2 -#define EN_FLOWPACED 3 - -#define EN_CFS 0 /* Flow units types */ -#define EN_GPM 1 -#define EN_MGD 2 -#define EN_IMGD 3 -#define EN_AFD 4 -#define EN_LPS 5 -#define EN_LPM 6 -#define EN_MLD 7 -#define EN_CMH 8 -#define EN_CMD 9 - -#define EN_TRIALS 0 /* Misc. options */ -#define EN_ACCURACY 1 -#define EN_TOLERANCE 2 -#define EN_EMITEXPON 3 -#define EN_DEMANDMULT 4 - -#define EN_LOWLEVEL 0 /* Control types */ -#define EN_HILEVEL 1 -#define EN_TIMER 2 -#define EN_TIMEOFDAY 3 - -#define EN_AVERAGE 1 /* Time statistic types. */ -#define EN_MINIMUM 2 -#define EN_MAXIMUM 3 -#define EN_RANGE 4 - -#define EN_MIX1 0 /* Tank mixing models */ -#define EN_MIX2 1 -#define EN_FIFO 2 -#define EN_LIFO 3 - -#define EN_NOSAVE 0 /* Save-results-to-file flag */ -#define EN_SAVE 1 -#define EN_INITFLOW 10 /* Re-initialize flow flag */ - - - -// --- define WINDOWS - -#undef WINDOWS -#ifdef _WIN32 - #define WINDOWS -#endif -#ifdef __WIN32__ - #define WINDOWS -#endif - -// --- define DLLEXPORT - -#ifndef DLLEXPORT - #ifdef DLL - #if defined(CYGWIN) - #define DLLEXPORT __stdcall - #elif defined(WINDOWS) - #ifdef __cplusplus - #define DLLEXPORT extern "C" __declspec(dllexport) - #else - #define DLLEXPORT __declspec(dllexport) - #endif - #else - #ifdef __cplusplus - #define DLLEXPORT extern "C" - #else - #define DLLEXPORT - #endif - #endif - #else - #define DLLEXPORT - #endif -#endif - -// --- declare the EPANET toolkit functions -#ifdef __cplusplus -extern "C" { -#endif - int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *)); - int DLLEXPORT ENopen(char *, char *, char *); - int DLLEXPORT ENsaveinpfile(char *); - int DLLEXPORT ENclose(void); - - int DLLEXPORT ENsolveH(void); - int DLLEXPORT ENsaveH(void); - int DLLEXPORT ENopenH(void); - int DLLEXPORT ENinitH(int); - int DLLEXPORT ENrunH(long *); - int DLLEXPORT ENnextH(long *); - int DLLEXPORT ENcloseH(void); - int DLLEXPORT ENsavehydfile(char *); - int DLLEXPORT ENusehydfile(char *); - - int DLLEXPORT ENsolveQ(void); - int DLLEXPORT ENopenQ(void); - int DLLEXPORT ENinitQ(int); - int DLLEXPORT ENrunQ(long *); - int DLLEXPORT ENnextQ(long *); - int DLLEXPORT ENstepQ(long *); - int DLLEXPORT ENcloseQ(void); - - int DLLEXPORT ENwriteline(char *); - int DLLEXPORT ENreport(void); - int DLLEXPORT ENresetreport(void); - int DLLEXPORT ENsetreport(char *); - - int DLLEXPORT ENgetcontrol(int, int *, int *, float *, - int *, float *); - int DLLEXPORT ENgetcount(int, int *); - int DLLEXPORT ENgetoption(int, float *); - int DLLEXPORT ENgettimeparam(int, long *); - int DLLEXPORT ENgetflowunits(int *); - int DLLEXPORT ENgetpatternindex(char *, int *); - int DLLEXPORT ENgetpatternid(int, char *); - int DLLEXPORT ENgetpatternlen(int, int *); - int DLLEXPORT ENgetpatternvalue(int, int, float *); - int DLLEXPORT ENgetqualtype(int *, int *); - int DLLEXPORT ENgeterror(int, char *, int); - - int DLLEXPORT ENgetnodeindex(char *, int *); - int DLLEXPORT ENgetnodeid(int, char *); - int DLLEXPORT ENgetnodetype(int, int *); - int DLLEXPORT ENgetnodevalue(int, int, float *); - - int DLLEXPORT ENgetnumdemands(int, int *); - int DLLEXPORT ENgetbasedemand(int, int, float *); - int DLLEXPORT ENgetdemandpattern(int, int, int *); - - int DLLEXPORT ENgetlinkindex(char *, int *); - int DLLEXPORT ENgetlinkid(int, char *); - int DLLEXPORT ENgetlinktype(int, int *); - int DLLEXPORT ENgetlinknodes(int, int *, int *); - int DLLEXPORT ENgetlinkvalue(int, int, float *); - - int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues); - - int DLLEXPORT ENgetversion(int *); - - int DLLEXPORT ENsetcontrol(int, int, int, float, int, float); - int DLLEXPORT ENsetnodevalue(int, int, float); - int DLLEXPORT ENsetlinkvalue(int, int, float); - int DLLEXPORT ENaddpattern(char *); - int DLLEXPORT ENsetpattern(int, float *, int); - int DLLEXPORT ENsetpatternvalue(int, int, float); - int DLLEXPORT ENsettimeparam(int, long); - int DLLEXPORT ENsetoption(int, float); - int DLLEXPORT ENsetstatusreport(int); - int DLLEXPORT ENsetqualtype(int, char *, char *, char *); -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/src/lemontiger.c b/src/lemontiger.c index eff0c04..7d6d447 100644 --- a/src/lemontiger.c +++ b/src/lemontiger.c @@ -2,13 +2,12 @@ #include "vars.h" #include "funcs.h" #include "toolkit.h" -#include "lemontiger.h" extern char OutOfMemory; extern int Haltflag; -int ENopeninitHQ() { +int DLLEXPORT ENopeninitHQ() { int errcode = 0; if (Hstep % Qstep) { @@ -36,102 +35,67 @@ int ENopeninitHQ() { return errcode; } -long timestepLT(void) -/* -**---------------------------------------------------------------- -** Input: none -** Output: returns time step until next change in hydraulics -** Purpose: computes time step to advance hydraulic simulation, but don't update tank levels -** Let nextqual() to do the job. -**---------------------------------------------------------------- -*/ -{ - long n,t,tstep; +long timestepLT(); +/* computes the length of the time step to next hydraulic simulation, but don't + update tank volumne and tank levels. During a sync HQ simulation, + nextqual() will update the tank vols */ - /* Normal time step is hydraulic time step */ - tstep = Hstep; +int nexthydLT(long *tstep); +/* finds length of next time step but don't save + results to hydraulics file. ignore reporting functions. */ - /* Revise time step based on time until next demand period */ - n = ((Htime+Pstart)/Pstep) + 1; /* Next pattern period */ - t = n*Pstep - Htime; /* Time till next period */ - if (t > 0 && t < tstep) tstep = t; +void updateTanklevels(); +//Prior to running hydraulic simulation, update the tank levels. - /* Revise time step based on time until next reporting period */ - t = Rtime - Htime; - if (t > 0 && t < tstep) tstep = t; +int DLLEXPORT ENrunnextHQ(long* pstime, /*Simulation time pointer*/ + long* ptstep /*next time step*/ ) { +/* The lemonTiger equivalent of ENnextQ, hydraulic solver is called on-demand*/ + long hydtime; /* Hydraulic solution time */ + long hydstep; /* Hydraulic time step */ + int errcode = 0; - /* Revise time step based on smallest time to fill or drain a tank */ - tanktimestep(&tstep); - - /* Revise time step based on smallest time to activate a control */ - controltimestep(&tstep); - - /* Evaluate rule-based controls (which will also update tank levels) */ - if (Nrules > 0) ruletimestep(&tstep); - - return(tstep); -} - -int nexthydLT(long *tstep) -/* -**-------------------------------------------------------------- -** Input: none -** Output: tstep = pointer to time step (in seconds) -** Returns: error code -** Purpose: finds length of next time step & updates tank -** levels and rule-based contol actions. don't save -** results to hydraulics file. don't consider Report time. -**-------------------------------------------------------------- -*/ -{ - long hydstep; /* Actual time step */ - int errcode = 0; /* Error code */ - - if (Haltflag) Htime = Dur; - - /* Compute next time step & update tank levels */ - *tstep = 0; - hydstep = 0; - if (Htime < Dur) hydstep = timestepLT(); - - /* Compute pumping energy */ - if (Dur == 0) addenergy(0); - else if (Htime < Dur) addenergy(hydstep); - - /* Update current time. */ - if (Htime < Dur) /* More time remains */ + /* if needed, push forward hydraulic simulation, similar to runqual() */ + if (Qtime == Htime) { - Htime += hydstep; + if ( (errcode = runhyd(&hydtime)) || + (errcode = nexthydLT(&hydstep)) + ) return errcode; + /* If simulating WQ: */ + if (Qualflag != NONE && Qtime < Dur) { + + /* Compute reaction rate coeffs. */ + if (Reactflag && Qualflag != AGE) ratecoeffs(); + + /* Initialize pipe segments (at time 0) or */ + /* else re-orient segments if flow reverses.*/ + if (Qtime == 0) initsegs(); + else reorientsegs(); + } + Htime = hydtime + hydstep; } - else - { - Htime++; /* Force completion of analysis */ - } - *tstep = hydstep; + *pstime = Htime; + hydstep = Htime - Qtime; + + /* Perform water quality routing over this time step */ + if (Qualflag != NONE && hydstep > 0) transport(hydstep); + + updateTanklevels(); + /* Update current time */ + if (OutOfMemory) errcode = 101; + if (!errcode) *ptstep = hydstep; + Qtime += hydstep; + + /* Save final output if no more time steps */ + if (!errcode && Saveflag && *ptstep == 0) errcode = savefinaloutput(); return(errcode); + } - -void updateTanklevels() { - int i,n; +int DLLEXPORT ENrunstepHQ(long* pstime /* Simulation time pointer */ + ,long* ptleft /* Time left in the simulation*/) { - for (i=1; i<=Ntanks; i++) - { - - /* Skip reservoirs */ - if (Tank[i].A == 0.0) continue; +/* The LemonTiger equivalence of ENstepQ, hydraulic solver is called on-demand */ - n = Tank[i].Node; - /* Check if tank full/empty within next second */ - if (Tank[i].V + D[n] >= Tank[i].Vmax) Tank[i].V = Tank[i].Vmax; - if (Tank[i].V - D[n] <= Tank[i].Vmin) Tank[i].V = Tank[i].Vmin; - - H[n] = tankgrade(i,Tank[i].V); - } -} - -int ENrunstepHQ(long* pstime /* Simulation time pointer */ - , long* ptleft /* Time left in the simulation*/) { long hydtime; /* Hydraulic solution time */ long hydstep; /* Hydraulic time step */ int errcode = 0; @@ -224,7 +188,8 @@ int ENrunstepHQ(long* pstime /* Simulation time pointer */ return(errcode); } -int ENcloseHQ() { + +int DLLEXPORT ENcloseHQ() { int errcode = 0; if ( (errcode = ENcloseQ()) || (errcode = ENcloseH()) ) return errcode; @@ -232,5 +197,85 @@ int ENcloseHQ() { } + + +long timestepLT(void) { +/* computes time step to advance hydraulic simulation, but don't + update tank levels. Instead, let nextqual() do the job. */ + long n,t,tstep; + + /* Normal time step is hydraulic time step */ + tstep = Hstep; + + /* Revise time step based on time until next demand period */ + n = ((Htime+Pstart)/Pstep) + 1; /* Next pattern period */ + t = n*Pstep - Htime; /* Time till next period */ + if (t > 0 && t < tstep) tstep = t; + + /* Revise time step based on time until next reporting period */ + t = Rtime - Htime; + if (t > 0 && t < tstep) tstep = t; + + /* Revise time step based on smallest time to fill or drain a tank */ + tanktimestep(&tstep); + + /* Revise time step based on smallest time to activate a control */ + controltimestep(&tstep); + + /* Evaluate rule-based controls (which will also update tank levels) */ + if (Nrules > 0) ruletimestep(&tstep); + + return(tstep); +} + + +int nexthydLT(long *tstep) { +/* finds length of next time step but don't updates tank volumnes and tank + levels and rule-based contol actions. don't save + results to hydraulics file. don't consider Report time. */ + long hydstep; /* Actual time step */ + int errcode = 0; /* Error code */ + + if (Haltflag) Htime = Dur; + + /* Compute next time step & update tank levels */ + *tstep = 0; + hydstep = 0; + if (Htime < Dur) hydstep = timestepLT(); + + /* Compute pumping energy */ + if (Dur == 0) addenergy(0); + else if (Htime < Dur) addenergy(hydstep); + + /* Update current time. */ + if (Htime < Dur) /* More time remains */ + { + Htime += hydstep; + } + else + { + Htime++; /* Force completion of analysis */ + } + *tstep = hydstep; + return(errcode); +} + + +void updateTanklevels() { //Prior to doing hydraulic simulation, update the tank levels + int i,n; + for (i=1; i<=Ntanks; i++) { + /* Skip reservoirs */ + if (Tank[i].A == 0.0) continue; + + n = Tank[i].Node; + /* Check if tank full/empty within next second */ + if (Tank[i].V + D[n] >= Tank[i].Vmax) Tank[i].V = Tank[i].Vmax; + if (Tank[i].V - D[n] <= Tank[i].Vmin) Tank[i].V = Tank[i].Vmin; + + H[n] = tankgrade(i,Tank[i].V); + } +} + + \ No newline at end of file diff --git a/src/lemontiger.h b/src/lemontiger.h index 885f429..c4d8787 100644 --- a/src/lemontiger.h +++ b/src/lemontiger.h @@ -1,11 +1,239 @@ #ifndef LEMONTIGER_H #define LEMONTIGER_H -int ENopeninitHQ(); +/*The header file to be included for USING Epanet LemonTiger DLL on WINDOWS platforms, +all original Epanet functions remain intact, and the new LT_functions are added. */ -int ENrunstepHQ(long*, long*); +/*Note that this file is not used by the functions in the toolkit itself. +Refer to toolkit.h for the internally used function declarations. */ + +#define DLLIMPORT __declspec(dllimport) + +// --- Define the EPANET toolkit constants + +#define EN_ELEVATION 0 /* Node parameters */ +#define EN_BASEDEMAND 1 +#define EN_PATTERN 2 +#define EN_EMITTER 3 +#define EN_INITQUAL 4 +#define EN_SOURCEQUAL 5 +#define EN_SOURCEPAT 6 +#define EN_SOURCETYPE 7 +#define EN_TANKLEVEL 8 +#define EN_DEMAND 9 +#define EN_HEAD 10 +#define EN_PRESSURE 11 +#define EN_QUALITY 12 +#define EN_SOURCEMASS 13 +#define EN_INITVOLUME 14 +#define EN_MIXMODEL 15 +#define EN_MIXZONEVOL 16 + +#define EN_TANKDIAM 17 +#define EN_MINVOLUME 18 +#define EN_VOLCURVE 19 +#define EN_MINLEVEL 20 +#define EN_MAXLEVEL 21 +#define EN_MIXFRACTION 22 +#define EN_TANK_KBULK 23 + +#define EN_TANKVOLUME 24 /* TNT */ + +#define EN_DIAMETER 0 /* Link parameters */ +#define EN_LENGTH 1 +#define EN_ROUGHNESS 2 +#define EN_MINORLOSS 3 +#define EN_INITSTATUS 4 +#define EN_INITSETTING 5 +#define EN_KBULK 6 +#define EN_KWALL 7 +#define EN_FLOW 8 +#define EN_VELOCITY 9 +#define EN_HEADLOSS 10 +#define EN_STATUS 11 +#define EN_SETTING 12 +#define EN_ENERGY 13 +#define EN_LINKQUAL 14 /* TNT */ + +#define EN_DURATION 0 /* Time parameters */ +#define EN_HYDSTEP 1 +#define EN_QUALSTEP 2 +#define EN_PATTERNSTEP 3 +#define EN_PATTERNSTART 4 +#define EN_REPORTSTEP 5 +#define EN_REPORTSTART 6 +#define EN_RULESTEP 7 +#define EN_STATISTIC 8 +#define EN_PERIODS 9 +#define EN_STARTTIME 10 /* Added TNT 10/2/2009 */ + +#define EN_NODECOUNT 0 /* Component counts */ +#define EN_TANKCOUNT 1 +#define EN_LINKCOUNT 2 +#define EN_PATCOUNT 3 +#define EN_CURVECOUNT 4 +#define EN_CONTROLCOUNT 5 + +#define EN_JUNCTION 0 /* Node types */ +#define EN_RESERVOIR 1 +#define EN_TANK 2 + +#define EN_CVPIPE 0 /* Link types */ +#define EN_PIPE 1 +#define EN_PUMP 2 +#define EN_PRV 3 +#define EN_PSV 4 +#define EN_PBV 5 +#define EN_FCV 6 +#define EN_TCV 7 +#define EN_GPV 8 + +#define EN_NONE 0 /* Quality analysis types */ +#define EN_CHEM 1 +#define EN_AGE 2 +#define EN_TRACE 3 + +#define EN_CONCEN 0 /* Source quality types */ +#define EN_MASS 1 +#define EN_SETPOINT 2 +#define EN_FLOWPACED 3 + +#define EN_CFS 0 /* Flow units types */ +#define EN_GPM 1 +#define EN_MGD 2 +#define EN_IMGD 3 +#define EN_AFD 4 +#define EN_LPS 5 +#define EN_LPM 6 +#define EN_MLD 7 +#define EN_CMH 8 +#define EN_CMD 9 + +#define EN_TRIALS 0 /* Misc. options */ +#define EN_ACCURACY 1 +#define EN_TOLERANCE 2 +#define EN_EMITEXPON 3 +#define EN_DEMANDMULT 4 + +#define EN_LOWLEVEL 0 /* Control types */ +#define EN_HILEVEL 1 +#define EN_TIMER 2 +#define EN_TIMEOFDAY 3 + +#define EN_AVERAGE 1 /* Time statistic types. */ +#define EN_MINIMUM 2 +#define EN_MAXIMUM 3 +#define EN_RANGE 4 + +#define EN_MIX1 0 /* Tank mixing models */ +#define EN_MIX2 1 +#define EN_FIFO 2 +#define EN_LIFO 3 + +#define EN_NOSAVE 0 /* Save-results-to-file flag */ +#define EN_SAVE 1 +#define EN_INITFLOW 10 /* Re-initialize flow flag */ + +// --- declare the EPANET toolkit functions + +#ifdef __cplusplus +extern "C" { +#endif + + int DLLIMPORT ENepanet(char *, char *, char *, void (*) (char *)); + int DLLIMPORT ENopen(char *, char *, char *); + int DLLIMPORT ENsaveinpfile(char *); + int DLLIMPORT ENclose(void); + + int DLLIMPORT ENsolveH(void); + int DLLIMPORT ENsaveH(void); + int DLLIMPORT ENopenH(void); + int DLLIMPORT ENinitH(int); + int DLLIMPORT ENrunH(long *); + int DLLIMPORT ENnextH(long *); + int DLLIMPORT ENcloseH(void); + int DLLIMPORT ENsavehydfile(char *); + int DLLIMPORT ENusehydfile(char *); + + int DLLIMPORT ENsolveQ(void); + int DLLIMPORT ENopenQ(void); + int DLLIMPORT ENinitQ(int); + int DLLIMPORT ENrunQ(long *); + int DLLIMPORT ENnextQ(long *); + int DLLIMPORT ENstepQ(long *); + int DLLIMPORT ENcloseQ(void); + + int DLLIMPORT ENwriteline(char *); + int DLLIMPORT ENreport(void); + int DLLIMPORT ENresetreport(void); + int DLLIMPORT ENsetreport(char *); + + int DLLIMPORT ENgetcontrol(int, int *, int *, float *, + int *, float *); + int DLLIMPORT ENgetcount(int, int *); + int DLLIMPORT ENgetoption(int, float *); + int DLLIMPORT ENgettimeparam(int, long *); + int DLLIMPORT ENgetflowunits(int *); + int DLLIMPORT ENgetpatternindex(char *, int *); + int DLLIMPORT ENgetpatternid(int, char *); + int DLLIMPORT ENgetpatternlen(int, int *); + int DLLIMPORT ENgetpatternvalue(int, int, float *); + int DLLIMPORT ENgetqualtype(int *, int *); + int DLLIMPORT ENgeterror(int, char *, int); + + int DLLIMPORT ENgetnodeindex(char *, int *); + int DLLIMPORT ENgetnodeid(int, char *); + int DLLIMPORT ENgetnodetype(int, int *); + int DLLIMPORT ENgetnodevalue(int, int, float *); + + int DLLIMPORT ENgetnumdemands(int, int *); + int DLLIMPORT ENgetbasedemand(int, int, float *); + int DLLIMPORT ENgetdemandpattern(int, int, int *); + + int DLLIMPORT ENgetlinkindex(char *, int *); + int DLLIMPORT ENgetlinkid(int, char *); + int DLLIMPORT ENgetlinktype(int, int *); + int DLLIMPORT ENgetlinknodes(int, int *, int *); + int DLLIMPORT ENgetlinkvalue(int, int, float *); + + int DLLIMPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues); + + int DLLIMPORT ENgetversion(int *); + + int DLLIMPORT ENsetcontrol(int, int, int, float, int, float); + int DLLIMPORT ENsetnodevalue(int, int, float); + int DLLIMPORT ENsetlinkvalue(int, int, float); + int DLLIMPORT ENaddpattern(char *); + int DLLIMPORT ENsetpattern(int, float *, int); + int DLLIMPORT ENsetpatternvalue(int, int, float); + int DLLIMPORT ENsettimeparam(int, long); + int DLLIMPORT ENsetoption(int, float); + int DLLIMPORT ENsetstatusreport(int); + int DLLIMPORT ENsetqualtype(int, char *, char *, char *); + + //LemonTiger functions + /* See testLT.c for a LemonTiger test */ + + //LT equivalent to ENopenH() + ENopenQ() + ENinitH() + ENinitQ() + int DLLIMPORT ENopeninitHQ(); + + //LT equivalent to ENrunQ() + ENnextQ(); + int DLLIMPORT ENrunnextHQ(long*, long*); + + //LT equivalent to ENrunQ() + ENstepQ(); + int DLLIMPORT ENrunstepHQ(long*, long*); + + //LT equivalent to ENcloseH() + ENcloseQ(); + int DLLIMPORT ENcloseHQ(); + + +#ifdef __cplusplus +}; +#endif + + + +#endif //LEMONTIGER_H -int ENcloseHQ(); -#endif \ No newline at end of file diff --git a/src/testLT.c b/src/testLT.c index ba173b8..9729186 100644 --- a/src/testLT.c +++ b/src/testLT.c @@ -5,7 +5,6 @@ #include #include "types.h" #include "vars.h" -#include "toolkit.h" #include "lemontiger.h" @@ -54,6 +53,7 @@ int main(int argc, char* argv[]) { 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)) { + ENrunQ(&stime); @@ -77,10 +77,10 @@ int main(int argc, char* argv[]) { if (err=ENopen(argv[1], argv[2], "")) return err; for (ENopeninitHQ(), tleft=Dur; tleft>0; ) { - ENrunstepHQ(&stime, &tleft); - - + //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); diff --git a/src/toolkit.h b/src/toolkit.h index 3e0501b..87b0a9b 100755 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -20,28 +20,13 @@ AUTHOR: L. Rossman /*** New compile directives ***/ //(2.00.11 - LR) //#define CLE /* Compile as a command line executable */ -#define CLE_LT /* LemonTiger test */ //#define SOL /* Compile as a shared object library */ //#define DLL /* Compile as a Windows DLL */ +//#define CLE_LT /* LemonTiger test */ //Jinduan Chen +#define DLL_LT /* Compile as a Windows DLL of LemonTiger */ -#ifndef DLLEXPORT - #ifdef DLL - #ifdef __cplusplus - #define DLLEXPORT extern "C" __declspec(dllexport) - #else - #define DLLEXPORT __declspec(dllexport) - #endif - #elif defined(CYGWIN) - #define DLLEXPORT __stdcall - #else - #ifdef __cplusplus - #define DLLEXPORT - #else - #define DLLEXPORT - #endif - #endif -#endif +#define DLLEXPORT __declspec(dllexport) // --- Define the EPANET toolkit constants @@ -253,8 +238,23 @@ extern "C" { int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetqualtype(int, char *, char *, char *); + //LemonTiger functions + /* See testLT.c for a LemonTiger test */ + + //LT equivalent to ENopenH() + ENopenQ() + ENinitH() + ENinitQ() + int DLLEXPORT ENopeninitHQ(); + + //LT equivalent to ENrunQ() + ENnextQ(); + int DLLEXPORT ENrunnextHQ(long*, long*); + + //LT equivalent to ENrunQ() + ENstepQ(); + int DLLEXPORT ENrunstepHQ(long*, long*); + + //LT equivalent to ENcloseH() + ENcloseQ(); + int DLLEXPORT ENcloseHQ(); + #if defined(__cplusplus) } #endif -#endif \ No newline at end of file +#endif //TOOLKIT_H \ No newline at end of file