EPANET  2.1
types.h
1 /*
2 ***********************************************************************
3 
4 TYPES.H -- Global constants and data types for EPANET program
5 
6 VERSION: 2.00
7 DATE: 5/8/00
8  9/7/00
9  10/25/00
10  3/1/01
11  12/6/01
12  6/24/02
13  8/15/07 (2.00.11)
14  2/14/08 (2.00.12)
15 AUTHOR: L. Rossman
16  US EPA - NRMRL
17 
18 **********************************************************************
19 */
20 #ifndef TYPES_H
21 #define TYPES_H
22 
23 /*********************************************************/
24 /* All floats have been re-declared as doubles (7/3/07). */
25 /*********************************************************/
26 /*
27 -------------------------------------------
28  Definition of 4-byte integers & reals
29 -------------------------------------------
30 */
31 typedef float REAL4; //(2.00.11 - LR)
32 typedef int INT4; //(2.00.12 - LR)
33 
34 /*
35 -----------------------------
36  Global Constants
37 -----------------------------
38 */
39 /*** Updated ***/
40 #define CODEVERSION 20100
41 #define MAGICNUMBER 516114521
42 #define ENGINE_VERSION 201
43 #define EOFMARK 0x1A /* Use 0x04 for UNIX systems */
44 #define MAXTITLE 3 /* Max. # title lines */
45 #define MAXID 31 /* Max. # characters in ID name */ //(2.00.11 - LR)
46 #define MAXMSG 79 /* Max. # characters in message text */
47 #define MAXLINE 255 /* Max. # characters read from input line */
48 #define MAXFNAME 259 /* Max. # characters in file name */
49 #define MAXTOKS 40 /* Max. items per line of input */
50 #define TZERO 1.E-4 /* Zero time tolerance */
51 #define TRUE 1
52 #define FALSE 0
53 #define FULL 2
54 #define BIG 1.E10
55 #define TINY 1.E-6
56 #define MISSING -1.E10
57 #define PI 3.141592654
58 
59 /*** Updated 9/7/00 ***/
60 /* Various conversion factors */
61 #define GPMperCFS 448.831
62 #define AFDperCFS 1.9837
63 #define MGDperCFS 0.64632
64 #define IMGDperCFS 0.5382
65 #define LPSperCFS 28.317
66 #define LPMperCFS 1699.0
67 #define CMHperCFS 101.94
68 #define CMDperCFS 2446.6
69 #define MLDperCFS 2.4466
70 #define M3perFT3 0.028317
71 #define LperFT3 28.317
72 #define MperFT 0.3048
73 #define PSIperFT 0.4333
74 #define KPAperPSI 6.895
75 #define KWperHP 0.7457
76 #define SECperDAY 86400
77 
78 #define DIFFUS 1.3E-8 /* Diffusivity of chlorine */
79  /* @ 20 deg C (sq ft/sec) */
80 #define VISCOS 1.1E-5 /* Kinematic viscosity of water */
81  /* @ 20 deg C (sq ft/sec) */
82 
83 #define SEPSTR " \t\n\r" /* Token separator characters */
84 
85 /*
86 ---------------------------------------------------------------------
87  Macro to test for successful allocation of memory
88 ---------------------------------------------------------------------
89 */
90 #define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
91 #define FREE(x) (free((x)))
92 
93 /*
94 ---------------------------------------------------------------------
95  Conversion macros to be used in place of functions
96 ---------------------------------------------------------------------
97 */
98 #define INT(x) ((int)(x)) /* integer portion of x */
99 #define FRAC(x) ((x)-(int)(x)) /* fractional part of x */
100 #define ABS(x) (((x)<0) ? -(x) : (x)) /* absolute value of x */
101 #define MIN(x,y) (((x)<=(y)) ? (x) : (y)) /* minimum of x and y */
102 #define MAX(x,y) (((x)>=(y)) ? (x) : (y)) /* maximum of x and y */
103 #define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))
104  /* round-off of x */
105 #define MOD(x,y) ((x)%(y)) /* x modulus y */
106 #define SQR(x) ((x)*(x)) /* x-squared */
107 #define SGN(x) (((x)<0) ? (-1) : (1)) /* sign of x */
108 #define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
109  /* uppercase char of x */
110 /*
111 ------------------------------------------------------
112  Macro to evaluate function x with error checking
113  (Fatal errors are numbered higher than 100)
114 ------------------------------------------------------
115 */
116 #define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
117 
118 /*
119 ------------------------------------------------------
120  Macro to find Pump index of Link[x]
121  (Diameter = pump index for pump links)
122 ------------------------------------------------------
123 */
124 #define PUMPINDEX(x) (ROUND(Link[(x)].Diam))
125 
126 /*
127 ------------------------------------------------------
128  Global Data Structures
129 ------------------------------------------------------
130 */
131 
132 struct IDstring /* Holds component ID labels */
133 {
134  char ID[MAXID+1];
135 };
136 
137 struct Floatlist /* Element of list of floats */
138 {
139  double value;
140  struct Floatlist *next;
141 };
142 typedef struct Floatlist SFloatlist;
143 
144 struct Tmplist /* Element of temp list for Pattern & Curve data */
145 {
146  int i;
147  char ID[MAXID+1];
148  SFloatlist *x;
149  SFloatlist *y;
150  struct Tmplist *next;
151 };
152 typedef struct Tmplist STmplist;
153 
154 typedef struct /* TIME PATTERN OBJECT */
155 {
156  char ID[MAXID+1]; /* Pattern ID */
157  int Length; /* Pattern length */
158  double *F; /* Pattern factors */
159 } Spattern;
160 
161 typedef struct /* CURVE OBJECT */
162 {
163  char ID[MAXID+1]; /* Curve ID */
164  int Type; /* Curve type */
165  int Npts; /* Number of points */
166  double *X; /* X-values */
167  double *Y; /* Y-values */
168 } Scurve;
169 
170 typedef struct /* Coord OBJECT */
171 {
172  char ID[MAXID+1]; /* Coord ID */
173  double X; /* X-value */
174  double Y; /* Y-value */
175  char HaveCoords; /* Coordinates flag */
176 } Scoord;
177 
178 struct Sdemand /* DEMAND CATEGORY OBJECT */
179 {
180  double Base; /* Baseline demand */
181  int Pat; /* Pattern index */
182  struct Sdemand *next; /* Next record */
183 };
184 typedef struct Sdemand *Pdemand; /* Pointer to demand object */
185 
186 struct Ssource /* WQ SOURCE OBJECT */
187 {
188  /*int Node;*/ /* Node index of source */
189  double C0; /* Base concentration/mass */
190  int Pat; /* Pattern index */
191  double Smass; /* Actual mass flow rate */
192  char Type; /* SourceType (see below) */
193 };
194 typedef struct Ssource *Psource; /* Pointer to WQ source object */
195 
196 typedef struct /* NODE OBJECT */
197 {
198  char ID[MAXID+1]; /* Node ID */
199  double El; /* Elevation */
200  Pdemand D; /* Demand pointer */
201  Psource S; /* Source pointer */
202  double C0; /* Initial quality */
203  double Ke; /* Emitter coeff. */
204  char Rpt; /* Reporting flag */
205 } Snode;
206 
207 typedef struct /* LINK OBJECT */
208 {
209  char ID[MAXID+1]; /* Link ID */
210  int N1; /* Start node index */
211  int N2; /* End node index */
212  double Diam; /* Diameter */
213  double Len; /* Length */
214  double Kc; /* Roughness */
215  double Km; /* Minor loss coeff. */
216  double Kb; /* Bulk react. coeff */
217  double Kw; /* Wall react. coeff */
218  double R; /* Flow resistance */
219  double Rc; /* Reaction cal */
220  char Type; /* Link type */
221  char Stat; /* Initial status */
222  char Rpt; /* Reporting flag */
223 } Slink;
224 
225 typedef struct /* TANK OBJECT */
226 {
227  int Node; /* Node index of tank */
228  double A; /* Tank area */
229  double Hmin; /* Minimum water elev */
230  double Hmax; /* Maximum water elev */
231  double H0; /* Initial water elev */
232  double Vmin; /* Minimum volume */
233  double Vmax; /* Maximum volume */
234  double V0; /* Initial volume */
235  double Kb; /* Reaction coeff. (1/days) */
236  double V; /* Tank volume */
237  double C; /* Concentration */
238  int Pat; /* Fixed grade time pattern */
239  int Vcurve; /* Vol.- elev. curve index */
240  char MixModel; /* Type of mixing model */
241  /* (see MixType below) */
242  double V1max; /* Mixing compartment size */
243 } Stank;
244 
245 typedef struct /* PUMP OBJECT */
246 {
247  int Link; /* Link index of pump */
248  int Ptype; /* Pump curve type */
249  /* (see PumpType below) */
250  double Q0; /* Initial flow */
251  double Qmax; /* Maximum flow */
252  double Hmax; /* Maximum head */
253  double H0; /* Shutoff head */
254  double R; /* Flow coeffic. */
255  double N; /* Flow exponent */
256  int Hcurve; /* Head v. flow curve index */
257  int Ecurve; /* Effic. v. flow curve index */
258  int Upat; /* Utilization pattern index */
259  int Epat; /* Energy cost pattern index */
260  double Ecost; /* Unit energy cost */
261  double Energy[6]; /* Energy usage statistics: */
262  /* 0 = pump utilization */
263  /* 1 = avg. efficiency */
264  /* 2 = avg. kW/flow */
265  /* 3 = avg. kwatts */
266  /* 4 = peak kwatts */
267  /* 5 = cost/day */
268 } Spump;
269 
270 typedef struct /* VALVE OBJECT */
271 {
272  int Link; /* Link index of valve */
273 } Svalve;
274 
275 typedef struct /* CONTROL STATEMENT */
276 {
277  int Link; /* Link index */
278  int Node; /* Control node index */
279  long Time; /* Control time */
280  double Grade; /* Control grade */
281  double Setting; /* New link setting */
282  char Status; /* New link status */
283  char Type; /* Control type */
284  /* (see ControlType below) */
285 } Scontrol;
286 
287 struct Sadjlist /* NODE ADJACENCY LIST ITEM */
288 {
289  int node; /* Index of connecting node */
290  int link; /* Index of connecting link */
291  struct Sadjlist *next; /* Next item in list */
292 };
293 /* Pointer to adjacency list item */
294 typedef struct Sadjlist *Padjlist;
295 
296 struct Sseg /* PIPE SEGMENT record used */
297 { /* for WQ routing */
298  double v; /* Segment volume */
299  double c; /* Water quality value */
300  struct Sseg *prev; /* Record for previous segment */
301 };
302 typedef struct Sseg *Pseg; /* Pointer to pipe segment */
303 
304 typedef struct /* FIELD OBJECT of report table */
305 {
306  char Name[MAXID+1]; /* Name of reported variable */
307  char Units[MAXID+1]; /* Units of reported variable */
308  char Enabled; /* Enabled if in table */
309  int Precision; /* Number of decimal places */
310  double RptLim[2]; /* Lower/upper report limits */
311 } SField;
312 
313 
314 /*
315 ----------------------------------------------
316  Global Enumeration Variables
317 ----------------------------------------------
318 */
319  enum Hydtype /* Hydraulics solution option: */
320  {USE, /* use from previous run */
321  SAVE, /* save after current run */
322  SCRATCH}; /* use temporary file */
323 
324  enum QualType /* Water quality analysis option: */
325  {NONE, /* no quality analysis */
326  CHEM, /* analyze a chemical */
327  AGE, /* analyze water age */
328  TRACE}; /* trace % of flow from a source */
329 
330  enum NodeType /* Type of node: */
331  {JUNC, /* junction */
332  RESERV, /* reservoir */
333  TANK}; /* tank */
334 
335  enum LinkType /* Type of link: */
336  {CV, /* pipe with check valve */
337  PIPE, /* regular pipe */
338  PUMP, /* pump */
339  PRV, /* pressure reducing valve */
340  PSV, /* pressure sustaining valve */
341  PBV, /* pressure breaker valve */
342  FCV, /* flow control valve */
343  TCV, /* throttle control valve */
344  GPV}; /* general purpose valve */
345 
346  enum CurveType /* Type of curve: */
347  {V_CURVE, /* volume curve */
348  P_CURVE, /* pump curve */
349  E_CURVE, /* efficiency curve */
350  H_CURVE}; /* head loss curve */
351 
352  enum PumpType /* Type of pump curve: */
353  {CONST_HP, /* constant horsepower */
354  POWER_FUNC, /* power function */
355  CUSTOM, /* user-defined custom curve */
356  NOCURVE};
357 
358  enum SourceType /* Type of source quality input */
359  {CONCEN, /* inflow concentration */
360  MASS, /* mass inflow booster */
361  SETPOINT, /* setpoint booster */
362  FLOWPACED}; /* flow paced booster */
363 
364  enum ControlType /* Control condition type: */
365  {LOWLEVEL, /* act when grade below set level */
366  HILEVEL, /* act when grade above set level */
367  TIMER, /* act when set time reached */
368  TIMEOFDAY}; /* act when time of day occurs */
369 
370  enum StatType /* Link/Tank status: */
371  {XHEAD, /* pump cannot deliver head (closed) */
372  TEMPCLOSED, /* temporarily closed */
373  CLOSED, /* closed */
374  OPEN, /* open */
375  ACTIVE, /* valve active (partially open) */
376  XFLOW, /* pump exceeds maximum flow */
377  XFCV, /* FCV cannot supply flow */
378  XPRESSURE, /* valve cannot supply pressure */
379  FILLING, /* tank filling */
380  EMPTYING}; /* tank emptying */
381 
382  enum FormType /* Head loss formula: */
383  {HW, /* Hazen-Williams */
384  DW, /* Darcy-Weisbach */
385  CM}; /* Chezy-Manning */
386 
387  enum UnitsType /* Unit system: */
388  {US, /* US */
389  SI}; /* SI (metric) */
390 
391  enum FlowUnitsType /* Flow units: */
392  {CFS, /* cubic feet per second */
393  GPM, /* gallons per minute */
394  MGD, /* million gallons per day */
395  IMGD, /* imperial million gal. per day */
396  AFD, /* acre-feet per day */
397  LPS, /* liters per second */
398  LPM, /* liters per minute */
399  MLD, /* megaliters per day */
400  CMH, /* cubic meters per hour */
401  CMD}; /* cubic meters per day */
402 
403  enum PressUnitsType /* Pressure units: */
404  {PSI, /* pounds per square inch */
405  KPA, /* kiloPascals */
406  METERS}; /* meters */
407 
408  enum RangeType /* Range limits: */
409  {LOW, /* lower limit */
410  HI, /* upper limit */
411  PREC}; /* precision */
412 
413  enum MixType /* Tank mixing regimes */
414  {MIX1, /* 1-compartment model */
415  MIX2, /* 2-compartment model */
416  FIFO, /* First in, first out model */
417  LIFO}; /* Last in, first out model */
418 
419  enum TstatType /* Time series statistics */
420  {SERIES, /* none */
421  AVG, /* time-averages */
422  MIN, /* minimum values */
423  MAX, /* maximum values */
424  RANGE}; /* max - min values */
425 
426 #define MAXVAR 21 /* Max. # types of network variables */
427  /* (equals # items enumed below) */
428  enum FieldType /* Network variables: */
429  {ELEV, /* nodal elevation */
430  DEMAND, /* nodal demand flow */
431  HEAD, /* nodal hydraulic head */
432  PRESSURE, /* nodal pressure */
433  QUALITY, /* nodal water quality */
434 
435  LENGTH, /* link length */
436  DIAM, /* link diameter */
437  FLOW, /* link flow rate */
438  VELOCITY, /* link flow velocity */
439  HEADLOSS, /* link head loss */
440  LINKQUAL, /* avg. water quality in link */
441  STATUS, /* link status */
442  SETTING, /* pump/valve setting */
443  REACTRATE, /* avg. reaction rate in link */
444  FRICTION, /* link friction factor */
445 
446  POWER, /* pump power output */
447  TIME, /* simulation time */
448  VOLUME, /* tank volume */
449  CLOCKTIME, /* simulation time of day */
450  FILLTIME, /* time to fill a tank */
451  DRAINTIME}; /* time to drain a tank */
452 
453 enum SectType {_TITLE,_JUNCTIONS,_RESERVOIRS,_TANKS,_PIPES,_PUMPS,
454  _VALVES,_CONTROLS,_RULES,_DEMANDS,_SOURCES,_EMITTERS,
455  _PATTERNS,_CURVES,_QUALITY,_STATUS,_ROUGHNESS,_ENERGY,
456  _REACTIONS,_MIXING,_REPORT,_TIMES,_OPTIONS,
457  _COORDS,_VERTICES,_LABELS,_BACKDROP,_TAGS,_END};
458 
459 enum HdrType /* Type of table heading */
460  {STATHDR, /* Hydraulic Status */
461  ENERHDR, /* Energy Usage */
462  NODEHDR, /* Node Results */
463  LINKHDR}; /* Link Results */
464 
465 #endif
Definition: types.h:275
Definition: types.h:245
Definition: types.h:154
Definition: types.h:132
Definition: types.h:137
Definition: types.h:161
Definition: types.h:304
Definition: types.h:287
Definition: types.h:170
Definition: types.h:186
Definition: types.h:296
Definition: types.h:144
Definition: types.h:270
Definition: types.h:196
Definition: types.h:178
Definition: types.h:225