xref: /petsc/src/ts/tutorials/network/pipe.h (revision 030f984af8d8bb4c203755d35bded3c05b3d83ce)
1 #ifndef PIPE_H
2 #define PIPE_H
3 
4 #define GRAV 9.806
5 #define PIPE_CHARACTERISTIC 10000000.0
6 
7 #include <petsc.h>
8 
9 typedef struct {
10   PetscScalar q;       /* flow rate */
11   PetscScalar h;       /* pressure */
12 } PipeField;
13 
14 typedef struct {
15   PetscScalar Q0,H0;       /* boundary values in upstream */
16   PetscScalar QL,HL;       /* boundary values in downstream */
17 } PipeBoundary;
18 
19 /* pipe                 */
20 /*----------------------*/
21 struct _p_Pipe
22 {
23   /* identification variables */
24   PetscInt    id;
25   PetscInt    networkid; /* which network this pipe belongs */
26 
27   /* solver objects */
28   Vec         x;
29   PipeField   *xold;
30   PetscReal   dt;
31   DM          da;
32   PetscInt    nnodes;   /* number of nodes in da discretization */
33   Mat         *jacobian;
34 
35   /* physics */
36   PetscReal   length;   /* pipe length */
37   PetscReal   a;        /* natural flow speed */
38   PetscReal   fric;     /* friction */
39   PetscReal   D;        /* diameter */
40   PetscReal   A;        /* area of cross section */
41   PetscReal   R;
42   PetscReal   rad;
43   PipeBoundary boundary; /* boundary conditions for H and Q */
44 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));
45 
46 typedef struct _p_Pipe *Pipe;
47 
48 extern PetscErrorCode PipeCreate(MPI_Comm,Pipe*);
49 extern PetscErrorCode PipeDestroy(Pipe*);
50 extern PetscErrorCode PipeSetParameters(Pipe,PetscReal,PetscReal,PetscReal,PetscReal);
51 extern PetscErrorCode PipeSetUp(Pipe);
52 extern PetscErrorCode PipeCreateJacobian(Pipe,Mat*,Mat*[]);
53 extern PetscErrorCode PipeDestroyJacobian(Pipe);
54 
55 extern PetscErrorCode PipeComputeSteadyState(Pipe, PetscScalar, PetscScalar);
56 extern PetscErrorCode PipeIFunctionLocal(DMDALocalInfo*,PetscReal,PipeField*,PipeField*,PipeField*,Pipe);
57 extern PetscErrorCode PipeIFunctionLocal_Lax(DMDALocalInfo*,PetscReal,PipeField*,PipeField*,PetscScalar*,Pipe);
58 extern PetscErrorCode PipeRHSFunctionLocal(DMDALocalInfo*,PetscReal,PipeField*,PetscScalar*,Pipe);
59 extern PetscErrorCode PipeMonitor(TS,PetscInt,PetscReal,Vec,void *);
60 
61 extern PetscErrorCode PipeCreateJacobian(Pipe,Mat*,Mat*[]);
62 extern PetscErrorCode PipeDestroyJacobian(Pipe);
63 #endif
64