Actual source code: water.h

  1: #ifndef WATER_H
  2: #define WATER_H

  4: #include <petscsnes.h>
  5: #include <petscdmnetwork.h>

  7: #define MAXLINE               1000
  8: #define VERTEX_TYPE_RESERVOIR 0
  9: #define VERTEX_TYPE_JUNCTION  1
 10: #define VERTEX_TYPE_TANK      2
 11: #define EDGE_TYPE_PIPE        0
 12: #define EDGE_TYPE_PUMP        1
 13: #define PIPE_STATUS_OPEN      0
 14: #define PIPE_STATUS_CLOSED    1
 15: #define PIPE_STATUS_CV        2

 17: #define GPM_CFS 0.0022280023234587 /* Scaling constant for GPM to CFS conversion */

 19: typedef struct {
 20:   PetscInt compkey_edge;
 21:   PetscInt compkey_vtx;
 22: } AppCtx_Water;

 24: typedef struct {
 25:   PetscInt    id;         /* id */
 26:   PetscScalar elev;       /* elevation (ft) */
 27:   PetscScalar demand;     /* demand (gpm) */
 28:   PetscInt    dempattern; /* demand pattern id */
 29: } Junction;

 31: typedef struct {
 32:   PetscInt    id;          /* id */
 33:   PetscScalar head;        /* head (ft) */
 34:   PetscInt    headpattern; /* head pattern */
 35: } Reservoir;

 37: typedef struct {
 38:   PetscInt    id;          /* id */
 39:   PetscScalar elev;        /* elevation (ft) */
 40:   PetscScalar initlvl;     /* initial level (ft) */
 41:   PetscScalar minlvl;      /* minimum level (ft) */
 42:   PetscScalar maxlvl;      /* maximum level (ft) */
 43:   PetscScalar diam;        /* diameter (ft) */
 44:   PetscScalar minvolume;   /* minimum volume (ft^3) */
 45:   PetscInt    volumecurve; /* Volume curve id */
 46: } Tank;

 48: struct _p_VERTEX_Water {
 49:   PetscInt  id;   /* id */
 50:   PetscInt  type; /* vertex type (junction, reservoir) */
 51:   Junction  junc; /* junction data */
 52:   Reservoir res;  /* reservoir data */
 53:   Tank      tank; /* tank data */
 54: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
 55: typedef struct _p_VERTEX_Water *VERTEX_Water;

 57: typedef struct {
 58:   PetscInt    id;        /* id */
 59:   PetscInt    node1;     /* From node */
 60:   PetscInt    node2;     /* to node */
 61:   PetscScalar length;    /* length (ft) */
 62:   PetscScalar diam;      /* diameter (inches) */
 63:   PetscScalar roughness; /* roughness (dimensionless) */
 64:   PetscScalar minorloss; /* minor losses */
 65:   char        stat[16];  /* Status */
 66:   PetscInt    status;    /* Pipe status (see PIPE_STATUS_XXX definition on top) */
 67:   PetscScalar n;         /* Exponent for h = kQ^n */
 68:   PetscScalar k;
 69: } Pipe;

 71: typedef struct {
 72:   PetscInt id;           /* id */
 73:   PetscInt node1;        /* From node */
 74:   PetscInt node2;        /* to node */
 75:   char     param[16];    /* curve parameter (HEAD or ENERGY or EFFICIENCY) */
 76:   PetscInt paramid;      /* Id of the curve parameter in the CURVE data */
 77:   struct {               /* one point curve */
 78:     PetscScalar flow[3]; /* flow (gpm) */
 79:     PetscScalar head[3]; /* head (ft) */
 80:     PetscInt    npt;     /* Number of given points */
 81:   } headcurve;
 82:   /* Parameters for pump headloss equation hL = h0 - rQ^n */
 83:   PetscScalar h0;
 84:   PetscScalar r;
 85:   PetscScalar n;
 86: } Pump;

 88: struct _p_EDGE_Water {
 89:   PetscInt id;   /* id */
 90:   PetscInt type; /* edge type (pump, pipe) */
 91:   Pipe     pipe; /* pipe data */
 92:   Pump     pump; /* pump data */
 93: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
 94: typedef struct _p_EDGE_Water *EDGE_Water;

 96: /* EPANET top-level data structure */
 97: struct _p_WATERDATA {
 98:   PetscInt     nvertex;
 99:   PetscInt     nedge;
100:   PetscInt     njunction;
101:   PetscInt     nreservoir;
102:   PetscInt     ntank;
103:   PetscInt     npipe;
104:   PetscInt     npump;
105:   VERTEX_Water vertex;
106:   EDGE_Water   edge;
107: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
108: typedef struct _p_WATERDATA WATERDATA;

110: extern PetscErrorCode WaterReadData(WATERDATA *, char *);
111: extern PetscErrorCode GetListofEdges_Water(WATERDATA *, PetscInt *);
112: extern PetscErrorCode WaterSetInitialGuess(DM, Vec);
113: extern PetscErrorCode WaterFormFunction(SNES, Vec, Vec, void *);
114: extern PetscErrorCode FormFunction_Water(DM, Vec, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
115: extern PetscErrorCode SetInitialGuess_Water(DM, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
116: extern PetscScalar    Flow_Pipe(Pipe *, PetscScalar, PetscScalar);
117: extern PetscScalar    Flow_Pump(Pump *, PetscScalar, PetscScalar);
118: #endif