xref: /petsc/src/ts/tutorials/network/wash.h (revision 2abc8c78ac72572cda759d150e59af39d6b8ec49)
1 #ifndef WASH_H
2 #define WASH_H
3 
4 #include <petscdmnetwork.h>
5 #include "pipe.h"
6 
7 typedef enum {NONE,JUNCTION=1,RESERVOIR=2,VALVE=3,DEMAND=4,INFLOW=5,STAGE=6,TANK=7} VertexType;
8 
9 typedef struct {
10   PetscInt    rid;  /*reservoir id*/
11   PetscScalar hres; /*Reservoir water column*/
12 } Reservoir;
13 
14 typedef struct {
15   PetscInt    vid;  /*valve id*/
16   PetscScalar tau;  /*valve aperture*/
17   PetscScalar cdag;
18   PetscScalar qout;
19 } Valve;
20 
21 /* junction              */
22 /*-----------------------*/
23 struct _p_Junction{
24   PetscInt      id;        /* global index */
25   PetscInt      tag;       /* external id */
26   VertexType    type;
27   PetscInt      isEnd;                /* -1: left end; 0: not an end; 1: right end */
28   PetscInt      nedges_in,nedges_out; /* number of connected in/out edges */
29   Mat           *jacobian;
30   PetscReal     latitude, longitude;  /* GPS data */
31 
32   /* boundary data structures */
33   Reservoir     reservoir;
34   Valve         valve;
35 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));
36 typedef struct _p_Junction *Junction;
37 
38 extern PetscErrorCode JunctionCreateJacobian(DM,PetscInt,Mat*,Mat*[]);
39 extern PetscErrorCode JunctionDestroyJacobian(DM,PetscInt,Junction);
40 
41 /* wash                   */
42 /*------------------------*/
43 struct _p_Wash
44 {
45   MPI_Comm    comm;
46   PetscInt    nedge,nvertex;           /* local number of components */
47   PetscInt    Nedge,Nvertex;           /* global number of components */
48   PetscInt    *edgelist;               /* local edge list */
49   Vec         localX,localXdot;        /* vectors used in local function evalutation */
50   PetscInt    nnodes_loc;              /* num of global and local nodes */
51 
52   /* Junction */
53   Junction    junction;
54   PetscInt    *vtype;
55 
56   /* Pipe */
57   Pipe        pipe;
58   PetscScalar Q0,H0,QL,HL;    /* left and right boundary conditions for wash-network (not individual pipe) */
59 
60   /* Events */
61   PetscInt    close_valve;
62 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));
63 typedef struct _p_Wash *Wash;
64 
65 extern PetscErrorCode WashNetworkCreate(MPI_Comm,PetscInt,Wash*);
66 extern PetscErrorCode WashNetworkCleanUp(Wash);
67 #endif
68