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