Compile LemonTiger as a Win32 DLL. Use "LemonTiger.h" to access its functions. Added one new function - ENrunnextHQ().

This commit is contained in:
JinduanChen
2013-01-28 15:14:10 -05:00
parent ca2bc04cba
commit 719114cb2e
12 changed files with 419 additions and 368 deletions

1
.gitignore vendored
View File

@@ -84,6 +84,7 @@ xcuserdata
!xcschemes !xcschemes
# Visual Studio 2012 # Visual Studio 2012
*.suo
*.sdf *.sdf
*.filters *.filters
*.user *.user

BIN
Debug/LemonTigerJ.dll Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
#v4.0:v110:false
Debug|Win32|C:\Users\owner\Documents\GitHub\epanet\|

BIN
Debug/LemonTigerJ.lib Normal file

Binary file not shown.

27
Debug/LemonTigerJ.log Normal file
View File

@@ -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

Binary file not shown.

View File

@@ -11,7 +11,6 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="include\epanet2.h" />
<ClInclude Include="src\enumstxt.h" /> <ClInclude Include="src\enumstxt.h" />
<ClInclude Include="src\funcs.h" /> <ClInclude Include="src\funcs.h" />
<ClInclude Include="src\hash.h" /> <ClInclude Include="src\hash.h" />
@@ -45,7 +44,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v110</PlatformToolset>
</PropertyGroup> </PropertyGroup>

View File

@@ -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

View File

@@ -2,13 +2,12 @@
#include "vars.h" #include "vars.h"
#include "funcs.h" #include "funcs.h"
#include "toolkit.h" #include "toolkit.h"
#include "lemontiger.h"
extern char OutOfMemory; extern char OutOfMemory;
extern int Haltflag; extern int Haltflag;
int ENopeninitHQ() { int DLLEXPORT ENopeninitHQ() {
int errcode = 0; int errcode = 0;
if (Hstep % Qstep) { if (Hstep % Qstep) {
@@ -36,102 +35,67 @@ int ENopeninitHQ() {
return errcode; return errcode;
} }
long timestepLT(void) 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,
** Input: none nextqual() will update the tank vols */
** 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;
/* Normal time step is hydraulic time step */ int nexthydLT(long *tstep);
tstep = Hstep; /* 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 */ void updateTanklevels();
n = ((Htime+Pstart)/Pstep) + 1; /* Next pattern period */ //Prior to running hydraulic simulation, update the tank levels.
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 */ int DLLEXPORT ENrunnextHQ(long* pstime, /*Simulation time pointer*/
t = Rtime - Htime; long* ptstep /*next time step*/ ) {
if (t > 0 && t < tstep) tstep = t; /* 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 */ /* if needed, push forward hydraulic simulation, similar to runqual() */
tanktimestep(&tstep); if (Qtime == Htime)
/* 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 */
{ {
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 *pstime = Htime;
{ hydstep = Htime - Qtime;
Htime++; /* Force completion of analysis */
} /* Perform water quality routing over this time step */
*tstep = hydstep; 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); return(errcode);
} }
int DLLEXPORT ENrunstepHQ(long* pstime /* Simulation time pointer */
void updateTanklevels() { ,long* ptleft /* Time left in the simulation*/) {
int i,n;
for (i=1; i<=Ntanks; i++) /* The LemonTiger equivalence of ENstepQ, hydraulic solver is called on-demand */
{
/* 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);
}
}
int ENrunstepHQ(long* pstime /* Simulation time pointer */
, long* ptleft /* Time left in the simulation*/) {
long hydtime; /* Hydraulic solution time */ long hydtime; /* Hydraulic solution time */
long hydstep; /* Hydraulic time step */ long hydstep; /* Hydraulic time step */
int errcode = 0; int errcode = 0;
@@ -224,7 +188,8 @@ int ENrunstepHQ(long* pstime /* Simulation time pointer */
return(errcode); return(errcode);
} }
int ENcloseHQ() {
int DLLEXPORT ENcloseHQ() {
int errcode = 0; int errcode = 0;
if ( (errcode = ENcloseQ()) || (errcode = ENcloseH()) ) if ( (errcode = ENcloseQ()) || (errcode = ENcloseH()) )
return errcode; 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);
}
}

View File

@@ -1,11 +1,239 @@
#ifndef LEMONTIGER_H #ifndef LEMONTIGER_H
#define 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

View File

@@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include "types.h" #include "types.h"
#include "vars.h" #include "vars.h"
#include "toolkit.h"
#include "lemontiger.h" #include "lemontiger.h"
@@ -54,6 +53,7 @@ int main(int argc, char* argv[]) {
printf("\nReset time pointer and run WQ.\n"); printf("\nReset time pointer and run WQ.\n");
for (step=1, ENopenQ(), ENinitQ(0); // this operation resets the internal time pointer (back to 0) for (step=1, ENopenQ(), ENinitQ(0); // this operation resets the internal time pointer (back to 0)
step>0; ENnextQ(&step)) { step>0; ENnextQ(&step)) {
ENrunQ(&stime); ENrunQ(&stime);
@@ -77,10 +77,10 @@ int main(int argc, char* argv[]) {
if (err=ENopen(argv[1], argv[2], "")) return err; if (err=ENopen(argv[1], argv[2], "")) return err;
for (ENopeninitHQ(), tleft=Dur; tleft>0; ) { 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 == TIME_A || stime == TIME_B || stime == TIME_C) {
//if (! (stime%1800)){ //if (! (stime%1800)){
printf("Simulation = %d sec, time left = %d sec.\n", stime, tleft); printf("Simulation = %d sec, time left = %d sec.\n", stime, tleft);

View File

@@ -20,28 +20,13 @@ AUTHOR: L. Rossman
/*** New compile directives ***/ //(2.00.11 - LR) /*** New compile directives ***/ //(2.00.11 - LR)
//#define CLE /* Compile as a command line executable */ //#define CLE /* Compile as a command line executable */
#define CLE_LT /* LemonTiger test */
//#define SOL /* Compile as a shared object library */ //#define SOL /* Compile as a shared object library */
//#define DLL /* Compile as a Windows DLL */ //#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 #define DLLEXPORT __declspec(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 the EPANET toolkit constants // --- Define the EPANET toolkit constants
@@ -253,8 +238,23 @@ extern "C" {
int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetstatusreport(int);
int DLLEXPORT ENsetqualtype(int, char *, char *, char *); 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) #if defined(__cplusplus)
} }
#endif #endif
#endif #endif //TOOLKIT_H