Feature wrapper (#136)
this quite sizable commit does several things, but is primarily focussed on building a toolkit that can run simultaneous simulations/analyses within a shared memory space. Versions <=2.1 use a long list of global variables that prevent multiple instantiations on linux systems without resorting to compilation tricks (like duplicate binaries or similar via static linkage). This version uses a single "Project" pointer to encapsulate the network and analysis data. There are no changes to existing algo implementations other than to accomodate dereferencing of the passed-in pointers. A more detailed list of major changes below: - mirrors all “ENxxxx” function calls with “EN_xxxx” versions (note the underscore) that take an extra first parameter: a pointer to an EN_Project struct, which contains all network, hydraulic, quality, and associated data. - tweaks some code formatting to make it more readable - removes some deprecated/commented code that was sufficiently old - fixes implicit type-cast warnings * Added ENaddnode and ENaddlink functions * More memory reallocations * Added ENInit, ENsetheadcurveindex * Added ENdeletelink and ENdeletenode * restored default behavior for float types * fixed type * Added docstrings for ENinit * cleanup change * moves global rule variables to vars.h * migrates rule structs to typedefs for better readability * char types to proper enums fixes #93 * Change some variable declarations for compatibility Changes to keep compatibility with C89 compilers: variables must be declared at the top of the functions. Remove the use of EN_LinkType in function call as it is not compatible with ENgetnodetype. * Moved declaration of idstodelete to top of function * Updated ENinit function and headers Updated header files with new functions Updated def file with new functions For ENinit changes names of parameters #98 Added enum for headloss formula * Missed these files in 1a033fc * migrates char types to enums fixes #93, supports unified link/node type enums, rather than public/private redefinitions * removing links in reverse-index order maintains proper indexing fixes #96 * style * clarifies curve getter units issue (dox) closes #95 * fixes link/node confusion in ENsetlinktype partially reverts a3bce95dc330a5a297634a303d438e2e1bc41cc9 * partial compilation fix * fixes dox issue * fixes allocation issues with enums - updates style in various places - introduces FlowDirection enum - use snprintf to prevent overflow * fixes enum type cast * updated mac project settings * Use of _snprintf on Windows and remove DLLEXPORT from mempool.h snprintf it not compatible on Windows so we use _snprintf mempool gave starnge compilation errors while removing DLLEXPORT worked. Not sure why these functions needed to be exposed in the DLL? * Revert "Use of _snprintf on Windows and remove DLLEXPORT from mempool.h" This reverts commit 6238f77d47fa0feaabe5836043c006937de433a2. * use of _snprintf instead of snprintf on Windows and removed DLLEXPORT from mempool.h Had compilation errors on mempool.h. Removed DLLEXPORT so solve it. Not sure why there was a need to expose these functions? * Shift indices for Links in ENaddnode Need to shift indices for Links not just Pipes since a pump could be connected directly to a reservoir. Also set the defult base demand to zero (was 5). * Set defualts for madatory link properties in ENaddlink and small fix for ENsetheadcurveindex Relates to #102 and closes #103 * wraps globals into structs, duplicates api functions with objective versions * parse and serialize Comment field for network elements related to #47 * adds getter for head/efficiency curve in EN_getlinkvalue * adds getter for event node index … to return the index of the junction (tank) that triggered the event. * fixes edge case in parsing … where inp files without demands in [JUNCTIONS] and without any [DEMAND] categories will fail. * adds freeing function for project pointer * removes redundant string literals, fixes overrun issue in error message getter function * check for hydraulics already closed * moving error definitions to data file * deprecates ENR err message getter (unused) * updates location of errors data file also begins to expose blind structs to curves and patterns, anticipating buildout of APIs for those. * updates CLI output to reflect executable name as invoked relates to #109 * Feature nrtest (#131) * Initial commit EPANET testing tools. * Initial commit for epanet-nrtestsuite * SWIG wrapper for EPANET outputapi (#118) * Removed pervious version of outputapi and wrapper * SWIG wrapper for EPANET outputapi * Patching cmake build script fixed target for outputapi * Build failing on deprecated test script * Minor changes. Responding to review comments. * Feature nrtest (#121) * Configured python setup to automatically build nrtest tools. * Working on build / testing automation * Adding EPANET 2.0.12 benchmark * Updated Travis yml to run nrtest * Fixing InsecurePlatformWarning * Fixing InsecurePlatformWarning again * Fixing InsecurePlatformWarning * Fixing InsecurePlatformWarning * Fixing InsecurePlatformWarning * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Working on configuring python environment and building test tools under Travis CI. * Making gen-config.sh and run-nrtest.sh executable * Debugging .travis.yml * Debugging .travis.yml * Debugging .travis.yml again * Debugging .travis.yml again * debugging travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * debugging Travis setup * Fixing bug with __strncpy_chk destlen < len * nrtesting clean up * re-implements fixes from:5eead5ae403c788567a4* removes extraneous build files, moves cmake and updates travis * mirror of 9b37035560f9683f1514b439f7586a5c17bca5bf * Move some variable declarations * More variable declarations * Fix TmpDir * Allocate _defaultModel * Fix EN_addcurve funcrion * Fix for inpfile * Fix writeRuleinInp call * Set MAXMSG to 79 chars * Fix for flow direction * Refactoring testing related python packages and SWIG wrapper bug fix (#139) * Eliminated epanet-reader package. Removed numpy dependency from epanet-output. Fixed reference counting bug in SWIG wrapper. Added error checking to run_nrtest.sh. Added nrtest package to requirements file. * changing buildhome directory * Fixing bug related to preprocessor definition of PI
This commit is contained in:
227
src/vars.h
227
src/vars.h
@@ -1,211 +1,16 @@
|
||||
/*
|
||||
************************************************************************
|
||||
Global Variables for EPANET Program
|
||||
|
||||
VERSION: 2.00
|
||||
DATE: 5/8/00
|
||||
6/24/02
|
||||
2/14/08 (2.00.12)
|
||||
AUTHOR: L. Rossman
|
||||
US EPA - NRMRL
|
||||
|
||||
************************************************************************
|
||||
*/
|
||||
#ifndef VARS_H
|
||||
#define VARS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hash.h"
|
||||
|
||||
EXTERN FILE *InFile, /* Input file pointer */
|
||||
*OutFile, /* Output file pointer */
|
||||
*RptFile, /* Report file pointer */
|
||||
*HydFile, /* Hydraulics file pointer */
|
||||
*TmpOutFile; /* Temporary file handle */
|
||||
EXTERN long HydOffset, /* Hydraulics file byte offset */
|
||||
OutOffset1, /* 1st output file byte offset */
|
||||
OutOffset2; /* 2nd output file byte offset */
|
||||
EXTERN char Msg[MAXMSG+1], /* Text of output message */
|
||||
InpFname[MAXFNAME+1], /* Input file name */
|
||||
Rpt1Fname[MAXFNAME+1], /* Primary report file name */
|
||||
Rpt2Fname[MAXFNAME+1], /* Secondary report file name */
|
||||
HydFname[MAXFNAME+1], /* Hydraulics file name */
|
||||
OutFname[MAXFNAME+1], /* Binary output file name */
|
||||
MapFname[MAXFNAME+1], /* Map file name */
|
||||
TmpFname[MAXFNAME+1], /* Temporary file name */ //(2.00.12 - LR)
|
||||
TmpDir[MAXFNAME+1], /* Temporary directory name */ //(2.00.12 - LR)
|
||||
Title[MAXTITLE][MAXMSG+1], /* Problem title */
|
||||
ChemName[MAXID+1], /* Name of chemical */
|
||||
ChemUnits[MAXID+1], /* Units of chemical */
|
||||
DefPatID[MAXID+1], /* Default demand pattern ID */
|
||||
|
||||
/*** Updated 6/24/02 ***/
|
||||
Atime[13], /* Clock time (hrs:min:sec) */
|
||||
|
||||
Outflag, /* Output file flag */ //(2.00.12 - LR)
|
||||
Hydflag, /* Hydraulics flag */
|
||||
Qualflag, /* Water quality flag */
|
||||
Reactflag, /* Reaction indicator */ //(2.00.12 - LR)
|
||||
Unitsflag, /* Unit system flag */
|
||||
Flowflag, /* Flow units flag */
|
||||
Pressflag, /* Pressure units flag */
|
||||
Formflag, /* Hydraulic formula flag */
|
||||
Rptflag, /* Report flag */
|
||||
Summaryflag, /* Report summary flag */
|
||||
Messageflag, /* Error/warning message flag */
|
||||
Statflag, /* Status report flag */
|
||||
Energyflag, /* Energy report flag */
|
||||
Nodeflag, /* Node report flag */
|
||||
Linkflag, /* Link report flag */
|
||||
Tstatflag, /* Time statistics flag */
|
||||
Warnflag, /* Warning flag */
|
||||
Openflag, /* Input processed flag */
|
||||
OpenHflag, /* Hydraul. system opened flag */
|
||||
SaveHflag, /* Hydraul. results saved flag */
|
||||
OpenQflag, /* Quality system opened flag */
|
||||
SaveQflag, /* Quality results saved flag */
|
||||
Saveflag, /* General purpose save flag */
|
||||
Coordflag; /* Load coordinates flag */
|
||||
EXTERN int MaxNodes, /* Node count from input file */
|
||||
MaxLinks, /* Link count from input file */
|
||||
MaxJuncs, /* Junction count */
|
||||
MaxPipes, /* Pipe count */
|
||||
MaxTanks, /* Tank count */
|
||||
MaxPumps, /* Pump count */
|
||||
MaxValves, /* Valve count */
|
||||
MaxControls, /* Control count */
|
||||
MaxRules, /* Rule count */
|
||||
MaxPats, /* Pattern count */
|
||||
MaxCurves, /* Curve count */
|
||||
Nnodes, /* Number of network nodes */
|
||||
Ntanks, /* Number of tanks */
|
||||
Njuncs, /* Number of junction nodes */
|
||||
Nlinks, /* Number of network links */
|
||||
Npipes, /* Number of pipes */
|
||||
Npumps, /* Number of pumps */
|
||||
Nvalves, /* Number of valves */
|
||||
Ncontrols, /* Number of simple controls */
|
||||
Nrules, /* Number of control rules */
|
||||
Npats, /* Number of time patterns */
|
||||
Ncurves, /* Number of data curves */
|
||||
Nperiods, /* Number of reporting periods */
|
||||
Ncoeffs, /* Number of non-0 matrix coeffs*/
|
||||
DefPat, /* Default demand pattern */
|
||||
Epat, /* Energy cost time pattern */
|
||||
MaxIter, /* Max. hydraulic trials */
|
||||
ExtraIter, /* Extra hydraulic trials */
|
||||
TraceNode, /* Source node for flow tracing */
|
||||
PageSize, /* Lines/page in output report */
|
||||
CheckFreq, /* Hydraulics solver parameter */
|
||||
MaxCheck; /* Hydraulics solver parameter */
|
||||
EXTERN double Ucf[MAXVAR], /* Unit conversion factors */
|
||||
Ctol, /* Water quality tolerance */
|
||||
Htol, /* Hydraulic head tolerance */
|
||||
Qtol, /* Flow rate tolerance */
|
||||
RQtol, /* Flow resistance tolerance */
|
||||
Hexp, /* Exponent in headloss formula */
|
||||
Qexp, /* Exponent in orifice formula */
|
||||
Dmult, /* Demand multiplier */
|
||||
Hacc, /* Hydraulics solution accuracy */
|
||||
DampLimit, /* Solution damping threshold */ //(2.00.12 - LR)
|
||||
BulkOrder, /* Bulk flow reaction order */
|
||||
WallOrder, /* Pipe wall reaction order */
|
||||
TankOrder, /* Tank reaction order */
|
||||
Kbulk, /* Global bulk reaction coeff. */
|
||||
Kwall, /* Global wall reaction coeff. */
|
||||
Climit, /* Limiting potential quality */
|
||||
Rfactor, /* Roughness-reaction factor */
|
||||
Diffus, /* Diffusivity (sq ft/sec) */
|
||||
Viscos, /* Kin. viscosity (sq ft/sec) */
|
||||
SpGrav, /* Specific gravity */
|
||||
Ecost, /* Base energy cost per kwh */
|
||||
Dcost, /* Energy demand charge/kw/day */
|
||||
Epump, /* Global pump efficiency */
|
||||
Emax, /* Peak energy usage */
|
||||
Dsystem, /* Total system demand */
|
||||
Wbulk, /* Avg. bulk reaction rate */
|
||||
Wwall, /* Avg. wall reaction rate */
|
||||
Wtank, /* Avg. tank reaction rate */
|
||||
Wsource; /* Avg. mass inflow */
|
||||
EXTERN long Tstart, /* Starting time of day (sec) */
|
||||
Hstep, /* Nominal hyd. time step (sec) */
|
||||
Qstep, /* Quality time step (sec) */
|
||||
Pstep, /* Time pattern time step (sec) */
|
||||
Pstart, /* Starting pattern time (sec) */
|
||||
Rstep, /* Reporting time step (sec) */
|
||||
Rstart, /* Time when reporting starts */
|
||||
Rtime, /* Next reporting time */
|
||||
Htime, /* Current hyd. time (sec) */
|
||||
Qtime, /* Current quality time (sec) */
|
||||
Hydstep, /* Actual hydraulic time step */
|
||||
Rulestep, /* Rule evaluation time step */
|
||||
Dur; /* Duration of simulation (sec) */
|
||||
EXTERN SField Field[MAXVAR]; /* Output reporting fields */
|
||||
|
||||
/* Array pointers not allocated and freed in same routine */
|
||||
EXTERN char *LinkStatus, /* Link status */
|
||||
*OldStat; /* Previous link/tank status */
|
||||
EXTERN double *NodeDemand, /* Node actual demand */
|
||||
*NodeQual, /* Node actual quality */
|
||||
*E, /* Emitter flows */
|
||||
*LinkSetting, /* Link settings */
|
||||
*Q, /* Link flows */
|
||||
*PipeRateCoeff, /* Pipe reaction rate */
|
||||
*X, /* General purpose array */
|
||||
*TempQual; /* General purpose array for water quality */
|
||||
EXTERN double *NodeHead; /* Node heads */
|
||||
EXTERN double *QTankVolumes;
|
||||
EXTERN double *QLinkFlow;
|
||||
EXTERN STmplist *Patlist; /* Temporary time pattern list */
|
||||
EXTERN STmplist *Curvelist; /* Temporary list of curves */
|
||||
EXTERN Spattern *Pattern; /* Time patterns */
|
||||
EXTERN Scurve *Curve; /* Curve data */
|
||||
EXTERN Scoord *Coord; /* Coordinate data */
|
||||
EXTERN Snode *Node; /* Node data */
|
||||
EXTERN Slink *Link; /* Link data */
|
||||
EXTERN Stank *Tank; /* Tank data */
|
||||
EXTERN Spump *Pump; /* Pump data */
|
||||
EXTERN Svalve *Valve; /* Valve data */
|
||||
EXTERN Scontrol *Control; /* Control data */
|
||||
EXTERN ENHashTable *NodeHashTable, *LinkHashTable; /* Hash tables for ID labels */
|
||||
EXTERN Padjlist *Adjlist; /* Node adjacency lists */
|
||||
EXTERN double _relativeError;
|
||||
EXTERN int _iterations; /* Info about hydraulic solution */
|
||||
|
||||
/*
|
||||
** NOTE: Hydraulic analysis of the pipe network at a given point in time
|
||||
** is done by repeatedly solving a linearized version of the
|
||||
** equations for conservation of flow & energy:
|
||||
**
|
||||
** A*H = F
|
||||
**
|
||||
** where H = vector of heads (unknowns) at each node,
|
||||
** F = vector of right-hand side coeffs.
|
||||
** A = square matrix of coeffs.
|
||||
** and both A and F are updated at each iteration until there is
|
||||
** negligible change in pipe flows.
|
||||
**
|
||||
** Each row (or column) of A corresponds to a junction in the pipe
|
||||
** network. Each link (pipe, pump or valve) in the network has a
|
||||
** non-zero entry in the row-column of A that corresponds to its
|
||||
** end points. This results in A being symmetric and very sparse.
|
||||
** The following arrays are used to efficiently manage this sparsity:
|
||||
*/
|
||||
|
||||
EXTERN double *Aii, /* Diagonal coeffs. of A */
|
||||
*Aij, /* Non-zero, off-diagonal coeffs. of A */
|
||||
*F; /* Right hand side coeffs. */
|
||||
EXTERN double *P, /* Inverse headloss derivatives */
|
||||
*Y; /* Flow correction factors */
|
||||
EXTERN int *Order, /* Node-to-row of A */
|
||||
*Row, /* Row-to-node of A */
|
||||
*Ndx; /* Index of link's coeff. in Aij */
|
||||
/*
|
||||
** The following arrays store the positions of the non-zero coeffs.
|
||||
** of the lower triangular portion of A whose values are stored in Aij:
|
||||
*/
|
||||
EXTERN int *XLNZ, /* Start position of each column in NZSUB */
|
||||
*NZSUB, /* Row index of each coeff. in each column */
|
||||
*LNZ; /* Position of each coeff. in Aij array */
|
||||
|
||||
#endif
|
||||
/*
|
||||
************************************************************************
|
||||
Global Variables for EPANET Program
|
||||
************************************************************************
|
||||
*/
|
||||
#ifndef VARS_H
|
||||
#define VARS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hash.h"
|
||||
|
||||
// this single global variable is used only when the library is called in "legacy mode"
|
||||
// with the 2.1-style API.
|
||||
EXTERN EN_Project *_defaultModel;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user