EPANET
types.h
1 /*
2  ******************************************************************************
3  Project: OWA EPANET
4  Version: 2.3
5  Module: types.h
6  Description: symbolic constants and data types used throughout EPANET
7  Authors: see AUTHORS
8  Copyright: see AUTHORS
9  License: see LICENSE
10  Last Updated: 04/19/2025
11  ******************************************************************************
12 */
13 
14 #ifndef TYPES_H
15 #define TYPES_H
16 
17 #include <stdio.h>
18 
19 #include "hash.h"
20 
21 /*
22 -------------------------------------------
23  Definition of 4-byte integers & reals
24 -------------------------------------------
25 */
26 typedef float REAL4;
27 typedef int INT4;
28 
29 /*
30 ----------------------------------------------
31  Various constants
32 ----------------------------------------------
33 */
34 #define CODEVERSION 20301
35 #define MAGICNUMBER 516114521
36 #define ENGINE_VERSION 201 // Used for binary hydraulics file
37 #define EOFMARK 0x1A // Use 0x04 for UNIX systems
38 #define MAXTITLE 3 // Max. # title lines
39 #define TITLELEN 79 // Max. # characters in a title line
40 #define MAXID 31 // Max. # characters in ID name
41 #define MAXMSG 255 // Max. # characters in message text
42 #define MAXLINE 1024 // Max. # characters read from input line
43 #define MAXFNAME 259 // Max. # characters in file name
44 #define MAXTOKS 40 // Max. items per line of input
45 #define TRUE 1
46 #define FALSE 0
47 #define FULL 2
48 #define BIG 1.E10
49 #define TINY 1.E-6
50 #define MISSING -1.E10 // Missing value indicator
51 #define SET_CLOSED -1.E10 // Link set closed indicator
52 #define SET_OPEN 1.E10 // Link set open indicator
53 
54 #define DIFFUS 1.3E-8 // Diffusivity of chlorine
55  // @ 20 deg C (sq ft/sec)
56 #define VISCOS 1.1E-5 // Kinematic viscosity of water
57  // @ 20 deg C (sq ft/sec)
58 #define MINPDIFF 0.1 // PDA min. pressure difference (psi or m)
59 #define SEPSTR " \t\n\r" // Token separator characters
60 #ifdef M_PI
61  #define PI M_PI
62 #else
63  #define PI 3.141592654
64 #endif
65 
66 /*
67 ----------------------------------------------
68  Flow units conversion factors
69 ----------------------------------------------
70 */
71 #define GPMperCFS 448.831
72 #define AFDperCFS 1.9837
73 #define MGDperCFS 0.64632
74 #define IMGDperCFS 0.5382
75 #define LPSperCFS 28.317
76 #define LPMperCFS 1699.0
77 #define CMSperCFS 0.028317
78 #define CMHperCFS 101.94
79 #define CMDperCFS 2446.6
80 #define MLDperCFS 2.4466
81 #define M3perFT3 0.028317
82 #define LperFT3 28.317
83 #define MperFT 0.3048
84 #define PSIperFT 0.4333
85 #define KPAperPSI 6.895
86 #define BARperPSI 0.068948
87 #define KWperHP 0.7457
88 #define SECperDAY 86400
89 
90 /*
91 ---------------------------------------------------------------------
92  Macros to test for successful allocation of memory and to free it
93 ---------------------------------------------------------------------
94 */
95 #define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
96 #define FREE(x) do { free(x); (x) = NULL; } while(0)
97 
98 /*
99 ---------------------------------------------------------------------
100  Conversion macros to be used in place of functions
101 ---------------------------------------------------------------------
102 */
103 #define INT(x) ((int)(x)) // integer portion of x
104 #define FRAC(x) ((x)-(int)(x)) // fractional part of x
105 #define ABS(x) (((x)<0) ? -(x) : (x)) // absolute value of x
106 #define MIN(x,y) (((x)<=(y)) ? (x) : (y)) // minimum of x and y
107 #define MAX(x,y) (((x)>=(y)) ? (x) : (y)) // maximum of x and y
108 #define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))
109  // round-off of x
110 #define MOD(x,y) ((x)%(y)) // x modulus y
111 #define SQR(x) ((x)*(x)) // x-squared
112 #define SGN(x) (((x)<0) ? (-1) : (1)) // sign of x
113 #define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
114  // uppercase char of x
115 /*
116 ------------------------------------------------------
117  Macro to evaluate function x with error checking
118  (Fatal errors are numbered higher than 100)
119 ------------------------------------------------------
120 */
121 #define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
122 
123 /*
124 ----------------------------------------------
125  Enumerated Data Types
126 ----------------------------------------------
127 */
128 
129 typedef enum {
130  NODE,
131  LINK,
132  TIMEPAT,
133  CURVE,
134  CONTROL,
135  RULE
136 } ObjectType;
137 
138 typedef enum {
139  JUNCTION,
140  RESERVOIR,
141  TANK
142 } NodeType;
143 
144 typedef enum {
145  CVPIPE, // pipe with check valve
146  PIPE, // pipe
147  PUMP, // pump
148  PRV, // pressure reducing valve
149  PSV, // pressure sustaining valve
150  PBV, // pressure breaker valve
151  FCV, // flow control valve
152  TCV, // throttle control valve
153  GPV, // general purpose valve
154  PCV // positional control valve
155 } LinkType;
156 
157 typedef enum {
158  USE, // use hydraulics file from previous run
159  SAVE, // save hydraulics file after current run
160  SCRATCH // use temporary hydraulics file
161 } HydFiletype;
162 
163 typedef enum {
164  NONE, // no quality analysis
165  CHEM, // analyze a chemical
166  AGE, // analyze water age
167  TRACE // trace % of flow from a source
168 } QualType;
169 
170 typedef enum {
171  VOLUME_CURVE, // volume curve
172  PUMP_CURVE, // pump curve
173  EFFIC_CURVE, // efficiency curve
174  HLOSS_CURVE, // head loss curve
175  GENERIC_CURVE, // generic curve
176  VALVE_CURVE // positional valve loss curve
177 } CurveType;
178 
179 typedef enum {
180  CONST_HP, // constant horsepower
181  POWER_FUNC, // power function
182  CUSTOM, // user-defined custom curve
183  NOCURVE
184 } PumpType;
185 
186 typedef enum {
187  CONCEN, // inflow concentration
188  MASS, // mass inflow booster
189  SETPOINT, // setpoint booster
190  FLOWPACED // flow paced booster
191 } SourceType;
192 
193 typedef enum {
194  LOWLEVEL, // act when grade below set level
195  HILEVEL, // act when grade above set level
196  TIMER, // act when set time reached
197  TIMEOFDAY // act when time of day occurs
198 } ControlType;
199 
200 typedef enum {
201  XHEAD, // pump cannot deliver head (closed)
202  TEMPCLOSED, // temporarily closed
203  CLOSED, // closed
204  OPEN, // open
205  ACTIVE, // valve active (partially open)
206  XFLOW, // pump exceeds maximum flow
207  XFCV, // FCV cannot supply flow
208  XPRESSURE, // valve cannot supply pressure
209  FILLING, // tank filling
210  EMPTYING, // tank emptying
211  OVERFLOWING // tank overflowing
212 } StatusType;
213 
214 typedef enum {
215  HW, // Hazen-Williams
216  DW, // Darcy-Weisbach
217  CM // Chezy-Manning
218 } HeadLossType;
219 
220 typedef enum {
221  US, // US
222  SI // SI (metric)
223 } UnitsType;
224 
225 typedef enum {
226  CFS, // cubic feet per second
227  GPM, // gallons per minute
228  MGD, // million gallons per day
229  IMGD, // imperial million gal. per day
230  AFD, // acre-feet per day
231  LPS, // liters per second
232  LPM, // liters per minute
233  MLD, // megaliters per day
234  CMH, // cubic meters per hour
235  CMD, // cubic meters per day
236  CMS // cubic meters per second
237 } FlowUnitsType;
238 
239 typedef enum {
240  PSI, // pounds per square inch
241  KPA, // kiloPascals
242  METERS, // meters
243  BAR, // bar
244  FEET, // feet
245  DEFAULTUNIT // default based on unit system (SI or US)
246 } PressureUnitsType;
247 
248 typedef enum {
249  LOW, // lower limit
250  HI, // upper limit
251  PREC // precision
252 } RangeType;
253 
254 typedef enum {
255  MIX1, // complete mix model
256  MIX2, // 2-compartment model
257  FIFO, // first in, first out model
258  LIFO // last in, first out model
259 } MixType;
260 
261 typedef enum {
262  SERIES, // point time series
263  AVG, // time-averages
264  MIN, // minimum values
265  MAX, // maximum values
266  RANGE // max - min values
267 } StatisticType;
268 
269 typedef enum {
270  ELEV = 0, // nodal elevation
271  DEMAND, // nodal demand flow
272  HEAD, // nodal hydraulic head
273  PRESSURE, // nodal pressure
274  QUALITY, // nodal water quality
275 
276  LENGTH, // link length
277  DIAM, // link diameter
278  FLOW, // link flow rate
279  VELOCITY, // link flow velocity
280  HEADLOSS, // link head loss
281  LINKQUAL, // avg. water quality in link
282  STATUS, // link status
283  SETTING, // pump/valve setting
284  REACTRATE, // avg. reaction rate in link
285  FRICTION, // link friction factor
286 
287  POWER, // pump power output
288  TIME, // simulation time
289  VOLUME, // tank volume
290  CLOCKTIME, // simulation time of day
291  FILLTIME, // time to fill a tank
292  DRAINTIME, // time to drain a tank
293  MAXVAR // total number of variable fields
294 } FieldType;
295 
296 typedef enum {
297  _TITLE, _JUNCTIONS, _RESERVOIRS, _TANKS, _PIPES, _PUMPS,
298  _VALVES, _CONTROLS, _RULES, _DEMANDS, _SOURCES, _EMITTERS,
299  _PATTERNS, _CURVES, _QUALITY, _STATUS, _ROUGHNESS, _ENERGY,
300  _REACTIONS, _MIXING, _REPORT, _TIMES, _OPTIONS,
301  _COORDS, _VERTICES, _LABELS, _BACKDROP, _TAGS, _LEAKAGE, _END
302 } SectionType;
303 
304 typedef enum {
305  STATHDR, // hydraulic status header
306  ENERHDR, // energy usage header
307  NODEHDR, // node results header
308  LINKHDR // link results header
309 } HdrType;
310 
311 typedef enum {
312  NEGATIVE = -1, // flow in reverse of pre-assigned direction
313  ZERO_FLOW = 0, // zero flow
314  POSITIVE = 1 // flow in pre-assigned direction
315 } FlowDirection;
316 
317 typedef enum {
318  DDA, // demand driven analysis
319  PDA // pressure driven analysis
320 } DemandModelType;
321 
322 /*
323 ------------------------------------------------------
324  Fundamental Data Structures
325 ------------------------------------------------------
326 */
327 
328 struct IDstring // Holds component ID label
329 {
330  char ID[MAXID+1];
331 };
332 
333 typedef struct // Time Pattern Object
334 {
335  char ID[MAXID+1]; // pattern ID
336  char *Comment; // pattern comment
337  int Length; // pattern length
338  double *F; // pattern factors
339 } Spattern;
340 
341 typedef struct // Curve Object
342 {
343  char ID[MAXID+1]; // curve ID
344  char *Comment; // curve comment
345  CurveType Type; // curve type
346  int Npts; // number of points
347  int Capacity; // size of X & Y arrays
348  double *X; // x-values
349  double *Y; // y-values
350 } Scurve;
351 
352 struct Sdemand // Demand List Item
353 {
354  double Base; // baseline demand
355  int Pat; // pattern index
356  char *Name; // demand category name
357  struct Sdemand *next; // next demand list item
358 };
359 typedef struct Sdemand *Pdemand; // Pointer to demand list
360 
361 typedef struct // Energy Usage Object
362 {
363  double TimeOnLine; // hours pump is online
364  double Efficiency; // total time wtd. efficiency
365  double KwHrsPerFlow; // total kw-hrs per unit of flow
366  double KwHrs; // total kw-hrs consumed
367  double MaxKwatts; // max. kw consumed
368  double TotalCost; // total pumping cost
369  double CurrentPower; // current pump power (kw)
370  double CurrentEffic; // current pump efficiency
371 } Senergy;
372 
373 struct Ssource // Water Quality Source Object
374 {
375  double C0; // base concentration/mass
376  int Pat; // pattern index
377  double Smass; // actual mass flow rate
378  SourceType Type; // type of source
379 };
380 typedef struct Ssource *Psource; // Pointer to source object
381 
382 struct Svertices // Coordinates of a link's vertices
383 {
384  double *X; // array of x-coordinates
385  double *Y; // array of y-coordinates
386  int Npts; // number of vertex points
387  int Capacity; // capacity of coordinate arrays
388 };
389 typedef struct Svertices *Pvertices; // Pointer to a link's vertices
390 
391 typedef struct // Node Object
392 {
393  char ID[MAXID+1]; // node ID
394  double X; // x-coordinate
395  double Y; // y-coordinate
396  double El; // elevation
397  Pdemand D; // demand pointer
398  Psource S; // source pointer
399  double C0; // initial quality
400  double Ke; // emitter coeff.
401  int Rpt; // reporting flag
402  int ResultIndex; // saved result index
403  NodeType Type; // node type
404  char *Comment; // node comment
405  char *Tag; // optional category tag
406 } Snode;
407 
408 typedef struct // Link Object
409 {
410  char ID[MAXID+1]; // link ID
411  int N1; // start node index
412  int N2; // end node index
413  double Diam; // diameter
414  double Len; // length
415  double Kc; // pipe roughness, pump speed, valve setting
416  double Km; // minor loss coeff.
417  double Kb; // bulk react. coeff.
418  double Kw; // wall react. coef.
419  double R; // flow resistance
420  double Rc; // reaction coeff.
421  double LeakArea; // leak area (sq mm per 100 pipe length units
422  double LeakExpan; // leak expansion (sq mm per unit of head)
423  LinkType Type; // link type
424  StatusType InitStatus; // initial status
425  double InitSetting; // initial setting
426  Pvertices Vertices; // internal vertex coordinates
427  int Rpt; // reporting flag
428  int ResultIndex; // saved result index
429  char *Comment; // link comment
430  char *Tag; // optional category tag
431 } Slink;
432 
433 typedef struct // Tank Object
434 {
435  int Node; // node index of tank
436  double A; // tank area
437  double Hmin; // minimum water elev
438  double Hmax; // maximum water elev
439  double H0; // initial water elev
440  double Vmin; // minimum volume
441  double Vmax; // maximum volume
442  double V0; // initial volume
443  double Kb; // bulk reaction coeff.
444  double V; // tank volume
445  double C; // concentration
446  int Pat; // fixed grade time pattern
447  int Vcurve; // volume v. elev. curve index
448  MixType MixModel; // type of mixing model
449  double V1frac; // mixing compartment fraction
450  int CanOverflow; // tank can overflow or not
451 } Stank;
452 
453 typedef struct // Pump Object
454 {
455  int Link; // link index of pump
456  int Ptype; // pump curve type
457  double Q0; // initial flow
458  double Qmax; // maximum flow
459  double Hmax; // maximum head
460  double H0; // shutoff head
461  double R; // flow coeffic.
462  double N; // flow exponent
463  int Hcurve; // head v. flow curve index
464  int Ecurve; // effic. v. flow curve index
465  int Upat; // utilization pattern index
466  int Epat; // energy cost pattern index
467  double Ecost; // unit energy cost
468  Senergy Energy; // energy usage statistics
469 } Spump;
470 
471 typedef struct // Valve Object
472 {
473  int Link; // link index of valve
474  int Curve; // positional loss coeff. curve
475 } Svalve;
476 
477 typedef struct // Control Statement
478 {
479  int Link; // link index
480  int Node; // control node index
481  long Time; // control time
482  double Grade; // control grade
483  double Setting; // new link setting
484  StatusType Status; // new link status
485  ControlType Type; // control type
486  int isEnabled; // control enabled?
487 } Scontrol;
488 
489 typedef struct // Field Object of Report Table
490 {
491  char Name[MAXID+1]; // name of reported variable
492  char Units[MAXID+1]; // units of reported variable
493  int Enabled; // enabled if in table
494  int Precision; // number of decimal places
495  double RptLim[2]; // lower/upper report limits
496 } SField;
497 
498 struct Sadjlist // Node Adjacency List Item
499 {
500  int node; // index of connecting node
501  int link; // index of connecting link
502  struct Sadjlist *next; // next item in list
503 };
504 typedef struct Sadjlist *Padjlist; // Pointer to adjacency list
505 
506 struct Sseg // Pipe Segment List Item
507 {
508  double v; // segment volume
509  double c; // segment water quality
510  struct Sseg *prev; // previous segment in list
511 };
512 typedef struct Sseg *Pseg; // Pointer to pipe segment list
513 
514 typedef struct s_Premise // Rule Premise Clause
515 {
516  int logop; // logical operator (IF, AND, OR)
517  int object; // NODE or LINK
518  int index; // object's index
519  int variable; // pressure, flow, etc.
520  int relop; // relational operator (=, >, <, etc.)
521  int status; // variable's status (OPEN, CLOSED)
522  double value; // variable's value
523  struct s_Premise *next; // next premise clause
524 } Spremise;
525 
526 typedef struct s_Action // Rule Action Clause
527 {
528  int link; // link index
529  int status; // link's status
530  double setting; // link's setting
531  struct s_Action *next;
532 } Saction;
533 
534 typedef struct // Control Rule Structure
535 {
536  char label[MAXID+1]; // rule label
537  double priority; // priority level
538  int isEnabled; // is the rule enabled?
539  Spremise *Premises; // list of premises
540  Saction *ThenActions; // list of THEN actions
541  Saction *ElseActions; // list of ELSE actions
542 } Srule;
543 
544 typedef struct s_ActionItem // Action List Item
545 {
546  int ruleIndex; // index of rule action belongs to
547  Saction *action; // an action clause
548  struct s_ActionItem *next; // next action on the list
549 } SactionList;
550 
551 typedef struct // Mass Balance Components
552 {
553  double initial; // initial mass in system
554  double inflow; // mass inflow to system
555  double outflow; // mass outflow from system
556  double reacted; // mass reacted in system
557  double final; // final mass in system
558  double ratio; // ratio of mass added to mass lost
559  int segCount; // total number of pipe segments used
560 } SmassBalance;
561 
562 typedef struct
563 {
564  double totalInflow;
565  double totalOutflow;
566  double consumerDemand;
567  double emitterDemand;
568  double leakageDemand;
569  double deficitDemand;
570  double storageDemand;
571  double ratio;
572 } SflowBalance;
573 
574 typedef struct // Node Leakage Object
575 {
576  double qfa; // fixed area leakage flow
577  double qva; // variable area leakage flow
578  double cfa; // fixed area leakage coeff.
579  double cva; // variable area leakage coeff.
580 } Sleakage;
581 
582 /*
583 ------------------------------------------------------
584  Wrapper Data Structures
585 ------------------------------------------------------
586 */
587 
588 // Input File Parser Wrapper
589 typedef struct {
590  FILE *InFile; // Input file handle
591 
592  char
593  DefPatID[MAXID + 1], // Default demand pattern ID
594  InpFname[MAXFNAME + 1], // Input file name
595  *Tok[MAXTOKS], // Array of token strings
596  Comment[MAXMSG + 1], // Comment text
597  LineComment[MAXMSG + 1]; // Full line comment
598 
599  int
600  MaxNodes, // Node count from input file */
601  MaxLinks, // Link count " " "
602  MaxJuncs, // Junction count " " "
603  MaxPipes, // Pipe count " " "
604  MaxTanks, // Tank count " " "
605  MaxPumps, // Pump count " " "
606  MaxValves, // Valve count " " "
607  MaxControls, // Control count " " "
608  MaxRules, // Rule count " " "
609  MaxPats, // Pattern count " " "
610  MaxCurves, // Curve count " " "
611  Ntokens, // Number of tokens in line of input
612  Ntitle, // Number of title lines
613  ErrTok, // Index of error-producing token
614  Unitsflag, // Unit system flag
615  Flowflag, // Flow units flag
616  Pressflag; // Pressure units flag
617 
618  Spattern *PrevPat; // Previous pattern processed
619  Scurve *PrevCurve; // Previous curve processed
620  double *X; // Temporary array for curve data
621 
622 } Parser;
623 
624 // Time Step Wrapper
625 typedef struct {
626 
627  long
628  Tstart, // Starting time of day
629  Hstep, // Nominal hyd. time step
630  Pstep, // Time pattern time step
631  Pstart, // Starting pattern time
632  Rstep, // Reporting time step
633  Rstart, // Time when reporting starts
634  Rtime, // Next reporting time
635  Htime, // Current hyd. time
636  Hydstep, // Actual hydraulic time step
637  Qstep, // Quality time step
638  Qtime, // Current quality time
639  Rulestep, // Rule evaluation time step
640  Dur; // Duration of simulation
641 
642 } Times;
643 
644 // Reporting Wrapper
645 typedef struct {
646 
647  FILE *RptFile; // Report file handle
648 
649  int
650  Nperiods, // Number of reporting periods
651  PageSize, // Lines/page in output report/
652  Rptflag, // Report flag
653  Tstatflag, // Report time series statistic flag
654  Summaryflag, // Report summary flag
655  Messageflag, // Error/warning message flag
656  Statflag, // Status report flag
657  Energyflag, // Energy report flag
658  Nodeflag, // Node report flag
659  Linkflag, // Link report flag
660  Fprinterr; // File write error flag
661 
662  long
663  LineNum, // Current line number
664  PageNum; // Current page number
665 
666  char
667  Atime[13], // Clock time (hrs:min:sec)
668  Rpt1Fname[MAXFNAME+1], // Primary report file name
669  Rpt2Fname[MAXFNAME+1], // Secondary report file name
670  DateStamp[26]; // Current date & time
671 
672  SField Field[MAXVAR]; // Output reporting fields
673 
674  void (*reportCallback)(void*,void*,const char*); // user-supplied reporting callback
675  void *reportCallbackUserData; // user-supplied reporting context
676 
677 } Report;
678 
679 // Output File Wrapper
680 typedef struct {
681 
682  char
683  HydFname[MAXFNAME+1], // Hydraulics file name
684  OutFname[MAXFNAME+1]; // Binary output file name
685 
686  int
687  Outflag, // Output file flag
688  Hydflag, // Hydraulics flag
689  SaveHflag, // Hydraulic results saved flag
690  SaveQflag, // Quality results saved flag
691  Saveflag; // General purpose save flag
692 
693  long
694  HydOffset, // Hydraulics file byte offset
695  OutOffset1, // 1st output file byte offset
696  OutOffset2; // 2nd output file byte offset
697 
698  FILE
699  *OutFile, // Output file handle
700  *HydFile, // Hydraulics file handle
701  *TmpOutFile; // Temporary file handle
702 
703 } Outfile;
704 
705 // Rule-Based Controls Wrapper
706 typedef struct {
707 
708  SactionList *ActionList; // Linked list of action items
709  int RuleState; // State of rule interpreter
710  int Errcode; // Rule parser error code
711  long Time1; // Start of rule evaluation time interval
712  Spremise *LastPremise; // Previous premise clause
713  Saction *LastThenAction; // Previous THEN action
714  Saction *LastElseAction; // Previous ELSE action
715 
716 } Rules;
717 
718 // Sparse Matrix Wrapper
719 typedef struct {
720 
721  double
722  *Aii, // Diagonal matrix coeffs.
723  *Aij, // Non-zero, off-diagonal matrix coeffs.
724  *F, // Right hand side vector
725  *temp; // Array used by linear eqn. solver
726 
727  int
728  Ncoeffs, // Number of non-zero matrix coeffs
729  *Order, // Node-to-row of re-ordered matrix
730  *Row, // Row-to-node of re-ordered matrix
731  *Ndx, // Index of link's coeff. in Aij
732  *XLNZ, // Start position of each column in NZSUB
733  *NZSUB, // Row index of each coeff. in each column
734  *LNZ, // Position of each coeff. in Aij array
735  *link, // Array used by linear eqn. solver
736  *first; // Array used by linear eqn. solver
737 
738 } Smatrix;
739 
740 // Hydraulics Solver Wrapper
741 typedef struct {
742 
743  double
744  *NodeHead, // Node hydraulic heads
745  *NodeDemand, // Node total demand (consumer + emitter + leakage)
746  *FullDemand, // Required consumer demand
747  *DemandFlow, // Demand flow from nodes
748  *EmitterFlow, // Emitter flow from nodes
749  *LeakageFlow, // Leakage flow from nodes
750  *LinkFlow, // Link flows
751  *LinkSetting, // Link settings
752  Htol, // Hydraulic head tolerance
753  Qtol, // Flow rate tolerance
754  RQtol, // Flow resistance tolerance
755  Hexp, // Exponent in headloss formula
756  Qexp, // Exponent in emitter formula
757  Pexp, // Exponent in demand formula
758  Pmin, // Pressure needed for any demand
759  Preq, // Pressure needed for full demand
760  Dmult, // Demand multiplier
761  Hacc, // Relative flow change limit
762  FlowChangeLimit, // Absolute flow change limit
763  HeadErrorLimit, // Hydraulic head error limit
764  DampLimit, // Solution damping threshold
765  Viscos, // Kin. viscosity (sq ft/sec)
766  SpGrav, // Specific gravity
767  Epump, // Global pump efficiency
768  Dsystem, // Total system demand
769  Ecost, // Base energy cost per kwh
770  Dcost, // Energy demand charge/kw/day
771  Emax, // Peak energy usage
772  RelativeError, // Total flow change / total flow
773  MaxHeadError, // Max. error for link head loss
774  MaxFlowChange, // Max. change in link flow
775  DemandReduction, // % demand reduction at pressure deficient nodes
776  LeakageLoss, // % system leakage loss
777  RelaxFactor, // Relaxation factor for flow updating
778  *P, // Inverse of head loss derivatives
779  *Y, // Flow correction factors
780  *Xflow; // Inflow - outflow at each node
781 
782  int
783  DefPat, // Default demand pattern
784  Epat, // Energy cost time pattern
785  DemandModel, // Fixed or pressure dependent
786  Formflag, // Head loss formula flag
787  EmitBackFlag, // Emitter backflow flag
788  Iterations, // Number of hydraulic trials taken
789  MaxIter, // Max. hydraulic trials allowed
790  ExtraIter, // Extra hydraulic trials
791  CheckFreq, // Hydraulic trials between status checks
792  MaxCheck, // Hydraulic trials limit on status checks
793  OpenHflag, // Hydraulic system opened flag
794  Haltflag, // Flag to halt simulation
795  DeficientNodes, // Number of pressure deficient nodes
796  HasLeakage; // TRUE if project has non-zero leakage parameters
797 
798  Sleakage *Leakage; // Array of node leakage parameters
799 
800  StatusType
801  *LinkStatus, // Link status
802  *OldStatus; // Previous link/tank status
803 
805  FlowBalance; // Flow balance components
806 
807  Smatrix smatrix; // Sparse matrix storage
808 
809 } Hydraul;
810 
811 // Forward declaration of the Mempool structure defined in mempool.h
812 struct Mempool;
813 
814 // Water Quality Solver Wrapper
815 typedef struct {
816 
817  int
818  Qualflag, // Water quality analysis flag
819  OpenQflag, // Quality system opened flag
820  Reactflag, // Reaction indicator
821  OutOfMemory, // Out of memory indicator
822  TraceNode, // Source node for flow tracing
823  *SortedNodes; // Topologically sorted node indexes
824 
825  char
826  ChemName[MAXID + 1], // Name of chemical
827  ChemUnits[MAXID + 1]; // Units of chemical
828 
829  double
830  Ctol, // Water quality tolerance
831  Diffus, // Diffusivity (sq ft/sec)
832  Wbulk, // Avg. bulk reaction rate
833  Wwall, // Avg. wall reaction rate
834  Wtank, // Avg. tank reaction rate
835  Wsource, // Avg. mass inflow
836  Rfactor, // Roughness-reaction factor
837  Sc, // Schmidt Number
838  Bucf, // Bulk reaction units conversion factor
839  Tucf, // Tank reaction units conversion factor
840  BulkOrder, // Bulk flow reaction order
841  WallOrder, // Pipe wall reaction order
842  TankOrder, // Tank reaction order
843  Kbulk, // Global bulk reaction coeff.
844  Kwall, // Global wall reaction coeff.
845  Climit, // Limiting potential quality
846  SourceQual, // External source quality
847  *NodeQual, // Reported node quality state
848  *PipeRateCoeff; // Pipe reaction rate coeffs.
849 
850  struct Mempool
851  *SegPool; // Memory pool for water quality segments
852 
853  Pseg
854  FreeSeg, // Pointer to unused segment
855  *FirstSeg, // First (downstream) segment in each pipe
856  *LastSeg; // Last (upstream) segment in each pipe
857 
858  FlowDirection
859  *FlowDir; // Flow direction for each pipe
860 
862  MassBalance; // Mass balance components
863 
864 } Quality;
865 
866 // Pipe Network Wrapper
867 typedef struct {
868 
869  int
870  Nnodes, // Number of network nodes
871  Ntanks, // Number of tanks
872  Njuncs, // Number of junction nodes
873  Nlinks, // Number of network links
874  Npipes, // Number of pipes
875  Npumps, // Number of pumps
876  Nvalves, // Number of valves
877  Ncontrols, // Number of simple controls
878  Nrules, // Number of control rules
879  Npats, // Number of time patterns
880  Ncurves; // Number of data curves
881 
882  Snode *Node; // Node array
883  Slink *Link; // Link array
884  Stank *Tank; // Tank array
885  Spump *Pump; // Pump array
886  Svalve *Valve; // Valve array
887  Spattern *Pattern; // Time pattern array
888  Scurve *Curve; // Data curve array
889  Scontrol *Control; // Simple controls array
890  Srule *Rule; // Rule-based controls array
891  HashTable
892  *NodeHashTable, // Hash table for Node ID names
893  *LinkHashTable; // Hash table for Link ID names
894  Padjlist *Adjlist; // Node adjacency lists
895 
896 } Network;
897 
898 // Overall Project Wrapper
899 typedef struct Project {
900 
901  Network network; // Pipe network wrapper
902  Parser parser; // Input file parser wrapper
903  Times times; // Time step wrapper
904  Report report; // Reporting wrapper
905  Outfile outfile; // Output file wrapper
906  Rules rules; // Rule-based controls wrapper
907  Hydraul hydraul; // Hydraulics solver wrapper
908  Quality quality; // Water quality solver wrapper
909 
910  double Ucf[MAXVAR]; // Unit conversion factors
911 
912  int
913  Openflag, // Project open flag
914  Warnflag; // Warning flag
915 
916  char
917  Msg[MAXMSG+1], // General-purpose string: errors, messages
918  Title[MAXTITLE][TITLELEN+1], // Project title
919  MapFname[MAXFNAME+1], // Map file name
920  TmpHydFname[MAXFNAME+1], // Temporary hydraulics file name
921  TmpOutFname[MAXFNAME+1], // Temporary output file name
922  TmpStatFname[MAXFNAME+1]; // Temporary statistic file name
923 
924  void (* viewprog) (char *); // Pointer to progress viewing function
925 
926 } Project, *EN_Project;
927 
928 #endif
Definition: types.h:433
Definition: types.h:373
Definition: types.h:534
Definition: hash.c:21
struct Project * EN_Project
The EPANET Project wrapper object.
Definition: epanet2_2.h:49
Definition: types.h:589
Definition: types.h:506
Definition: types.h:477
Definition: types.h:352
Definition: types.h:382
Definition: types.h:333
Definition: types.h:551
Definition: types.h:361
Definition: types.h:453
Definition: types.h:471
Definition: types.h:706
Definition: types.h:514
Definition: types.h:867
Definition: types.h:328
Definition: mempool.c:36
Definition: types.h:899
Definition: types.h:498
Definition: types.h:526
Definition: types.h:341
Definition: types.h:489
Definition: types.h:719
Definition: types.h:815
Definition: types.h:544
Definition: types.h:391
Definition: types.h:741
Definition: types.h:625
Definition: types.h:574
Definition: types.h:562
Definition: types.h:645
Definition: types.h:680