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