xref: /petsc/src/snes/tutorials/network/water/water.h (revision 9dd11ecf0918283bb567d8b33a92f53ac4ea7840)
1 #pragma once
2 
3 #include <petscsnes.h>
4 #include <petscdmnetwork.h>
5 
6 #define MAXLINE               1000
7 #define VERTEX_TYPE_RESERVOIR 0
8 #define VERTEX_TYPE_JUNCTION  1
9 #define VERTEX_TYPE_TANK      2
10 #define EDGE_TYPE_PIPE        0
11 #define EDGE_TYPE_PUMP        1
12 #define PIPE_STATUS_OPEN      0
13 #define PIPE_STATUS_CLOSED    1
14 #define PIPE_STATUS_CV        2
15 
16 #define GPM_CFS 0.0022280023234587 /* Scaling constant for GPM to CFS conversion */
17 
18 typedef struct {
19   PetscInt compkey_edge;
20   PetscInt compkey_vtx;
21 } AppCtx_Water;
22 
23 typedef struct {
24   PetscInt    id;         /* id */
25   PetscScalar elev;       /* elevation (ft) */
26   PetscScalar demand;     /* demand (gpm) */
27   PetscInt    dempattern; /* demand pattern id */
28 } Junction;
29 
30 typedef struct {
31   PetscInt    id;          /* id */
32   PetscScalar head;        /* head (ft) */
33   PetscInt    headpattern; /* head pattern */
34 } Reservoir;
35 
36 typedef struct {
37   PetscInt    id;          /* id */
38   PetscScalar elev;        /* elevation (ft) */
39   PetscScalar initlvl;     /* initial level (ft) */
40   PetscScalar minlvl;      /* minimum level (ft) */
41   PetscScalar maxlvl;      /* maximum level (ft) */
42   PetscScalar diam;        /* diameter (ft) */
43   PetscScalar minvolume;   /* minimum volume (ft^3) */
44   PetscInt    volumecurve; /* Volume curve id */
45 } Tank;
46 
47 struct _p_VERTEX_Water {
48   PetscInt  id;   /* id */
49   PetscInt  type; /* vertex type (junction, reservoir) */
50   Junction  junc; /* junction data */
51   Reservoir res;  /* reservoir data */
52   Tank      tank; /* tank data */
53 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
54 typedef struct _p_VERTEX_Water *VERTEX_Water;
55 
56 typedef struct {
57   PetscInt    id;        /* id */
58   PetscInt    node1;     /* From node */
59   PetscInt    node2;     /* to node */
60   PetscScalar length;    /* length (ft) */
61   PetscScalar diam;      /* diameter (inches) */
62   PetscScalar roughness; /* roughness (dimensionless) */
63   PetscScalar minorloss; /* minor losses */
64   char        stat[16];  /* Status */
65   PetscInt    status;    /* Pipe status (see PIPE_STATUS_XXX definition on top) */
66   PetscScalar n;         /* Exponent for h = kQ^n */
67   PetscScalar k;
68 } Pipe;
69 
70 typedef struct {
71   PetscInt id;           /* id */
72   PetscInt node1;        /* From node */
73   PetscInt node2;        /* to node */
74   char     param[16];    /* curve parameter (HEAD or ENERGY or EFFICIENCY) */
75   PetscInt paramid;      /* Id of the curve parameter in the CURVE data */
76   struct {               /* one point curve */
77     PetscScalar flow[3]; /* flow (gpm) */
78     PetscScalar head[3]; /* head (ft) */
79     PetscInt    npt;     /* Number of given points */
80   } headcurve;
81   /* Parameters for pump headloss equation hL = h0 - rQ^n */
82   PetscScalar h0;
83   PetscScalar r;
84   PetscScalar n;
85 } Pump;
86 
87 struct _p_EDGE_Water {
88   PetscInt id;   /* id */
89   PetscInt type; /* edge type (pump, pipe) */
90   Pipe     pipe; /* pipe data */
91   Pump     pump; /* pump data */
92 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
93 typedef struct _p_EDGE_Water *EDGE_Water;
94 
95 /* EPANET top-level data structure */
96 struct _p_WATERDATA {
97   PetscInt     nvertex;
98   PetscInt     nedge;
99   PetscInt     njunction;
100   PetscInt     nreservoir;
101   PetscInt     ntank;
102   PetscInt     npipe;
103   PetscInt     npump;
104   VERTEX_Water vertex;
105   EDGE_Water   edge;
106 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
107 typedef struct _p_WATERDATA WATERDATA;
108 
109 extern PetscErrorCode WaterReadData(WATERDATA *, char *);
110 extern PetscErrorCode GetListofEdges_Water(WATERDATA *, PetscInt *);
111 extern PetscErrorCode WaterSetInitialGuess(DM, Vec);
112 extern PetscErrorCode WaterFormFunction(SNES, Vec, Vec, void *);
113 extern PetscErrorCode FormFunction_Water(DM, Vec, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
114 extern PetscErrorCode SetInitialGuess_Water(DM, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
115 extern PetscScalar    Flow_Pipe(Pipe *, PetscScalar, PetscScalar);
116 extern PetscScalar    Flow_Pump(Pump *, PetscScalar, PetscScalar);
117