xref: /petsc/src/ts/tutorials/ex53.c (revision 1e1ea65d8de51fde77ce8a787efbef25e407badc)
165876a83SMatthew G. Knepley static char help[] = "Time dependent Biot Poroelasticity problem with finite elements.\n\
265876a83SMatthew G. Knepley We solve three field, quasi-static poroelasticity in a rectangular\n\
365876a83SMatthew G. Knepley domain, using a parallel unstructured mesh (DMPLEX) to discretize it.\n\
465876a83SMatthew G. Knepley Contributed by: Robert Walker <rwalker6@buffalo.edu>\n\n\n";
565876a83SMatthew G. Knepley 
665876a83SMatthew G. Knepley #include <petscdmplex.h>
765876a83SMatthew G. Knepley #include <petscsnes.h>
865876a83SMatthew G. Knepley #include <petscts.h>
965876a83SMatthew G. Knepley #include <petscds.h>
1065876a83SMatthew G. Knepley #include <petscbag.h>
1165876a83SMatthew G. Knepley 
1265876a83SMatthew G. Knepley #include <petsc/private/tsimpl.h>
1365876a83SMatthew G. Knepley 
1465876a83SMatthew G. Knepley /* This presentation of poroelasticity is taken from
1565876a83SMatthew G. Knepley 
1665876a83SMatthew G. Knepley @book{Cheng2016,
1765876a83SMatthew G. Knepley   title={Poroelasticity},
1865876a83SMatthew G. Knepley   author={Cheng, Alexander H-D},
1965876a83SMatthew G. Knepley   volume={27},
2065876a83SMatthew G. Knepley   year={2016},
2165876a83SMatthew G. Knepley   publisher={Springer}
2265876a83SMatthew G. Knepley }
2365876a83SMatthew G. Knepley 
2465876a83SMatthew G. Knepley For visualization, use
2565876a83SMatthew G. Knepley 
2665876a83SMatthew G. Knepley   -dm_view hdf5:${PETSC_DIR}/sol.h5 -monitor_solution hdf5:${PETSC_DIR}/sol.h5::append
2765876a83SMatthew G. Knepley 
2865876a83SMatthew G. Knepley The weak form would then be, using test function $(v, q, \tau)$,
2965876a83SMatthew G. Knepley 
3065876a83SMatthew G. Knepley             (q, \frac{1}{M} \frac{dp}{dt}) + (q, \alpha \frac{d\varepsilon}{dt}) + (\nabla q, \kappa \nabla p) = (q, g)
3165876a83SMatthew G. Knepley  -(\nabla v, 2 G \epsilon) - (\nabla\cdot v, \frac{2 G \nu}{1 - 2\nu} \varepsilon) + \alpha (\nabla\cdot v, p) = (v, f)
3265876a83SMatthew G. Knepley                                                                           (\tau, \nabla \cdot u - \varepsilon) = 0
3365876a83SMatthew G. Knepley */
3465876a83SMatthew G. Knepley 
3565876a83SMatthew G. Knepley typedef enum {SOL_QUADRATIC_LINEAR, SOL_QUADRATIC_TRIG, SOL_TRIG_LINEAR, SOL_TERZAGHI, SOL_MANDEL, SOL_CRYER, NUM_SOLUTION_TYPES} SolutionType;
3665876a83SMatthew G. Knepley const char *solutionTypes[NUM_SOLUTION_TYPES+1] = {"quadratic_linear", "quadratic_trig", "trig_linear", "terzaghi", "mandel", "cryer", "unknown"};
3765876a83SMatthew G. Knepley 
3865876a83SMatthew G. Knepley typedef struct {
3965876a83SMatthew G. Knepley   PetscScalar mu;    /* shear modulus */
4065876a83SMatthew G. Knepley   PetscScalar K_u;   /* undrained bulk modulus */
4165876a83SMatthew G. Knepley   PetscScalar alpha; /* Biot effective stress coefficient */
4265876a83SMatthew G. Knepley   PetscScalar M;     /* Biot modulus */
4365876a83SMatthew G. Knepley   PetscScalar k;     /* (isotropic) permeability */
4465876a83SMatthew G. Knepley   PetscScalar mu_f;  /* fluid dynamic viscosity */
4565876a83SMatthew G. Knepley   PetscScalar P_0;   /* magnitude of vertical stress */
4665876a83SMatthew G. Knepley } Parameter;
4765876a83SMatthew G. Knepley 
4865876a83SMatthew G. Knepley typedef struct {
4965876a83SMatthew G. Knepley   /* Domain and mesh definition */
5030602db0SMatthew G. Knepley   PetscReal    xmin[3];     /* Lower left bottom corner of bounding box */
5130602db0SMatthew G. Knepley   PetscReal    xmax[3];     /* Upper right top corner of bounding box */
5265876a83SMatthew G. Knepley   /* Problem definition */
5365876a83SMatthew G. Knepley   SolutionType solType;     /* Type of exact solution */
5465876a83SMatthew G. Knepley   PetscBag     bag;         /* Problem parameters */
5565876a83SMatthew G. Knepley   PetscReal    t_r;         /* Relaxation time: 4 L^2 / c */
5624b15d09SMatthew G. Knepley   PetscReal    dtInitial;   /* Override the choice for first timestep */
5765876a83SMatthew G. Knepley   /* Exact solution terms */
5865876a83SMatthew G. Knepley   PetscInt     niter; /* Number of series term iterations in exact solutions */
5965876a83SMatthew G. Knepley   PetscReal    eps;   /* Precision value for root finding */
6065876a83SMatthew G. Knepley   PetscReal   *zeroArray; /* Array of root locations */
6165876a83SMatthew G. Knepley } AppCtx;
6265876a83SMatthew G. Knepley 
6365876a83SMatthew G. Knepley static PetscErrorCode zero(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
6465876a83SMatthew G. Knepley {
6565876a83SMatthew G. Knepley   PetscInt c;
6665876a83SMatthew G. Knepley   for (c = 0; c < Nc; ++c) u[c] = 0.0;
6765876a83SMatthew G. Knepley   return 0;
6865876a83SMatthew G. Knepley }
6965876a83SMatthew G. Knepley 
7065876a83SMatthew G. Knepley /* Quadratic space and linear time solution
7165876a83SMatthew G. Knepley 
7265876a83SMatthew G. Knepley   2D:
7365876a83SMatthew G. Knepley   u = x^2
7465876a83SMatthew G. Knepley   v = y^2 - 2xy
7565876a83SMatthew G. Knepley   p = (x + y) t
7665876a83SMatthew G. Knepley   e = 2y
7765876a83SMatthew G. Knepley   f = <2 G, 4 G + 2 \lambda > - <alpha t, alpha t>
7865876a83SMatthew G. Knepley   g = 0
7965876a83SMatthew G. Knepley   \epsilon = / 2x     -y    \
8065876a83SMatthew G. Knepley              \ -y   2y - 2x /
8165876a83SMatthew G. Knepley   Tr(\epsilon) = e = div u = 2y
8265876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
8365876a83SMatthew G. Knepley     = 2 G < 2-1, 2 > + \lambda <0, 2> - alpha <t, t>
8465876a83SMatthew G. Knepley     = <2 G, 4 G + 2 \lambda> - <alpha t, alpha t>
8565876a83SMatthew G. Knepley   \frac{1}{M} \frac{dp}{dt} + \alpha \frac{d\varepsilon}{dt} - \nabla \cdot \kappa \nabla p
8665876a83SMatthew G. Knepley     = \frac{1}{M} \frac{dp}{dt} + \kappa \Delta p
8765876a83SMatthew G. Knepley     = (x + y)/M
8865876a83SMatthew G. Knepley 
8965876a83SMatthew G. Knepley   3D:
9065876a83SMatthew G. Knepley   u = x^2
9165876a83SMatthew G. Knepley   v = y^2 - 2xy
9265876a83SMatthew G. Knepley   w = z^2 - 2yz
9365876a83SMatthew G. Knepley   p = (x + y + z) t
9465876a83SMatthew G. Knepley   e = 2z
9565876a83SMatthew G. Knepley   f = <2 G, 4 G + 2 \lambda > - <alpha t, alpha t, alpha t>
9665876a83SMatthew G. Knepley   g = 0
9765876a83SMatthew G. Knepley   \varepsilon = / 2x     -y       0   \
9865876a83SMatthew G. Knepley                 | -y   2y - 2x   -z   |
9965876a83SMatthew G. Knepley                 \  0     -z    2z - 2y/
10065876a83SMatthew G. Knepley   Tr(\varepsilon) = div u = 2z
10165876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
10265876a83SMatthew G. Knepley     = 2 G < 2-1, 2-1, 2 > + \lambda <0, 0, 2> - alpha <t, t, t>
10365876a83SMatthew G. Knepley     = <2 G, 2G, 4 G + 2 \lambda> - <alpha t, alpha t, alpha t>
10465876a83SMatthew G. Knepley */
10565876a83SMatthew G. Knepley static PetscErrorCode quadratic_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
10665876a83SMatthew G. Knepley {
10765876a83SMatthew G. Knepley   PetscInt d;
10865876a83SMatthew G. Knepley 
10965876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
11065876a83SMatthew G. Knepley     u[d] = PetscSqr(x[d]) - (d > 0 ? 2.0 * x[d-1] * x[d] : 0.0);
11165876a83SMatthew G. Knepley   }
11265876a83SMatthew G. Knepley   return 0;
11365876a83SMatthew G. Knepley }
11465876a83SMatthew G. Knepley 
11565876a83SMatthew G. Knepley static PetscErrorCode linear_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
11665876a83SMatthew G. Knepley {
11765876a83SMatthew G. Knepley   u[0] = 2.0*x[dim-1];
11865876a83SMatthew G. Knepley   return 0;
11965876a83SMatthew G. Knepley }
12065876a83SMatthew G. Knepley 
12165876a83SMatthew G. Knepley static PetscErrorCode linear_linear_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
12265876a83SMatthew G. Knepley {
12365876a83SMatthew G. Knepley   PetscReal sum = 0.0;
12465876a83SMatthew G. Knepley   PetscInt  d;
12565876a83SMatthew G. Knepley 
12665876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
12765876a83SMatthew G. Knepley   u[0] = sum*time;
12865876a83SMatthew G. Knepley   return 0;
12965876a83SMatthew G. Knepley }
13065876a83SMatthew G. Knepley 
13165876a83SMatthew G. Knepley static PetscErrorCode linear_linear_p_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
13265876a83SMatthew G. Knepley {
13365876a83SMatthew G. Knepley   PetscReal sum = 0.0;
13465876a83SMatthew G. Knepley   PetscInt  d;
13565876a83SMatthew G. Knepley 
13665876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
13765876a83SMatthew G. Knepley   u[0] = sum;
13865876a83SMatthew G. Knepley   return 0;
13965876a83SMatthew G. Knepley }
14065876a83SMatthew G. Knepley 
14165876a83SMatthew G. Knepley static void f0_quadratic_linear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
14265876a83SMatthew G. Knepley                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
14365876a83SMatthew G. Knepley                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
14465876a83SMatthew G. Knepley                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
14565876a83SMatthew G. Knepley {
14665876a83SMatthew G. Knepley   const PetscReal G      = PetscRealPart(constants[0]);
14765876a83SMatthew G. Knepley   const PetscReal K_u    = PetscRealPart(constants[1]);
14865876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
14965876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
15065876a83SMatthew G. Knepley   const PetscReal K_d    = K_u - alpha*alpha*M;
15165876a83SMatthew G. Knepley   const PetscReal lambda = K_d - (2.0 * G) / 3.0;
15265876a83SMatthew G. Knepley   PetscInt        d;
15365876a83SMatthew G. Knepley 
15465876a83SMatthew G. Knepley   for (d = 0; d < dim-1; ++d) {
15565876a83SMatthew G. Knepley     f0[d] -= 2.0*G - alpha*t;
15665876a83SMatthew G. Knepley   }
15765876a83SMatthew G. Knepley   f0[dim-1] -= 2.0*lambda + 4.0*G - alpha*t;
15865876a83SMatthew G. Knepley }
15965876a83SMatthew G. Knepley 
16065876a83SMatthew G. Knepley static void f0_quadratic_linear_p(PetscInt dim, PetscInt Nf, PetscInt NfAux,
16165876a83SMatthew G. Knepley                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
16265876a83SMatthew G. Knepley                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
16365876a83SMatthew G. Knepley                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
16465876a83SMatthew G. Knepley {
16565876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
16665876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
16765876a83SMatthew G. Knepley   PetscReal       sum    = 0.0;
16865876a83SMatthew G. Knepley   PetscInt        d;
16965876a83SMatthew G. Knepley 
17065876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
17165876a83SMatthew G. Knepley   f0[0] += u_t ? alpha*u_t[uOff[1]] : 0.0;
17265876a83SMatthew G. Knepley   f0[0] += u_t ? u_t[uOff[2]]/M     : 0.0;
17365876a83SMatthew G. Knepley   f0[0] -= sum/M;
17465876a83SMatthew G. Knepley }
17565876a83SMatthew G. Knepley 
17665876a83SMatthew G. Knepley /* Quadratic space and trigonometric time solution
17765876a83SMatthew G. Knepley 
17865876a83SMatthew G. Knepley   2D:
17965876a83SMatthew G. Knepley   u = x^2
18065876a83SMatthew G. Knepley   v = y^2 - 2xy
18165876a83SMatthew G. Knepley   p = (x + y) cos(t)
18265876a83SMatthew G. Knepley   e = 2y
18365876a83SMatthew G. Knepley   f = <2 G, 4 G + 2 \lambda > - <alpha cos(t), alpha cos(t)>
18465876a83SMatthew G. Knepley   g = 0
18565876a83SMatthew G. Knepley   \epsilon = / 2x     -y    \
18665876a83SMatthew G. Knepley              \ -y   2y - 2x /
18765876a83SMatthew G. Knepley   Tr(\epsilon) = e = div u = 2y
18865876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
18965876a83SMatthew G. Knepley     = 2 G < 2-1, 2 > + \lambda <0, 2> - alpha <cos(t), cos(t)>
19065876a83SMatthew G. Knepley     = <2 G, 4 G + 2 \lambda> - <alpha cos(t), alpha cos(t)>
19165876a83SMatthew G. Knepley   \frac{1}{M} \frac{dp}{dt} + \alpha \frac{d\varepsilon}{dt} - \nabla \cdot \kappa \nabla p
19265876a83SMatthew G. Knepley     = \frac{1}{M} \frac{dp}{dt} + \kappa \Delta p
19365876a83SMatthew G. Knepley     = -(x + y)/M sin(t)
19465876a83SMatthew G. Knepley 
19565876a83SMatthew G. Knepley   3D:
19665876a83SMatthew G. Knepley   u = x^2
19765876a83SMatthew G. Knepley   v = y^2 - 2xy
19865876a83SMatthew G. Knepley   w = z^2 - 2yz
19965876a83SMatthew G. Knepley   p = (x + y + z) cos(t)
20065876a83SMatthew G. Knepley   e = 2z
20165876a83SMatthew G. Knepley   f = <2 G, 4 G + 2 \lambda > - <alpha cos(t), alpha cos(t), alpha cos(t)>
20265876a83SMatthew G. Knepley   g = 0
20365876a83SMatthew G. Knepley   \varepsilon = / 2x     -y       0   \
20465876a83SMatthew G. Knepley                 | -y   2y - 2x   -z   |
20565876a83SMatthew G. Knepley                 \  0     -z    2z - 2y/
20665876a83SMatthew G. Knepley   Tr(\varepsilon) = div u = 2z
20765876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
20865876a83SMatthew G. Knepley     = 2 G < 2-1, 2-1, 2 > + \lambda <0, 0, 2> - alpha <cos(t), cos(t), cos(t)>
20965876a83SMatthew G. Knepley     = <2 G, 2G, 4 G + 2 \lambda> - <alpha cos(t), alpha cos(t), alpha cos(t)>
21065876a83SMatthew G. Knepley */
21165876a83SMatthew G. Knepley static PetscErrorCode linear_trig_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
21265876a83SMatthew G. Knepley {
21365876a83SMatthew G. Knepley   PetscReal sum = 0.0;
21465876a83SMatthew G. Knepley   PetscInt  d;
21565876a83SMatthew G. Knepley 
21665876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
21765876a83SMatthew G. Knepley   u[0] = sum*PetscCosReal(time);
21865876a83SMatthew G. Knepley   return 0;
21965876a83SMatthew G. Knepley }
22065876a83SMatthew G. Knepley 
22165876a83SMatthew G. Knepley static PetscErrorCode linear_trig_p_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
22265876a83SMatthew G. Knepley {
22365876a83SMatthew G. Knepley   PetscReal sum = 0.0;
22465876a83SMatthew G. Knepley   PetscInt  d;
22565876a83SMatthew G. Knepley 
22665876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
22765876a83SMatthew G. Knepley   u[0] = -sum*PetscSinReal(time);
22865876a83SMatthew G. Knepley   return 0;
22965876a83SMatthew G. Knepley }
23065876a83SMatthew G. Knepley 
23165876a83SMatthew G. Knepley static void f0_quadratic_trig_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
23265876a83SMatthew G. Knepley                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
23365876a83SMatthew G. Knepley                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
23465876a83SMatthew G. Knepley                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
23565876a83SMatthew G. Knepley {
23665876a83SMatthew G. Knepley   const PetscReal G      = PetscRealPart(constants[0]);
23765876a83SMatthew G. Knepley   const PetscReal K_u    = PetscRealPart(constants[1]);
23865876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
23965876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
24065876a83SMatthew G. Knepley   const PetscReal K_d    = K_u - alpha*alpha*M;
24165876a83SMatthew G. Knepley   const PetscReal lambda = K_d - (2.0 * G) / 3.0;
24265876a83SMatthew G. Knepley   PetscInt        d;
24365876a83SMatthew G. Knepley 
24465876a83SMatthew G. Knepley   for (d = 0; d < dim-1; ++d) {
24565876a83SMatthew G. Knepley     f0[d] -= 2.0*G - alpha*PetscCosReal(t);
24665876a83SMatthew G. Knepley   }
24765876a83SMatthew G. Knepley   f0[dim-1] -= 2.0*lambda + 4.0*G - alpha*PetscCosReal(t);
24865876a83SMatthew G. Knepley }
24965876a83SMatthew G. Knepley 
25065876a83SMatthew G. Knepley static void f0_quadratic_trig_p(PetscInt dim, PetscInt Nf, PetscInt NfAux,
25165876a83SMatthew G. Knepley                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
25265876a83SMatthew G. Knepley                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
25365876a83SMatthew G. Knepley                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
25465876a83SMatthew G. Knepley {
25565876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
25665876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
25765876a83SMatthew G. Knepley   PetscReal       sum    = 0.0;
25865876a83SMatthew G. Knepley   PetscInt        d;
25965876a83SMatthew G. Knepley 
26065876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += x[d];
26165876a83SMatthew G. Knepley 
26265876a83SMatthew G. Knepley   f0[0] += u_t ? alpha*u_t[uOff[1]] : 0.0;
26365876a83SMatthew G. Knepley   f0[0] += u_t ? u_t[uOff[2]]/M     : 0.0;
26465876a83SMatthew G. Knepley   f0[0] += PetscSinReal(t)*sum/M;
26565876a83SMatthew G. Knepley }
26665876a83SMatthew G. Knepley 
26765876a83SMatthew G. Knepley /* Trigonometric space and linear time solution
26865876a83SMatthew G. Knepley 
26965876a83SMatthew G. Knepley u = sin(2 pi x)
27065876a83SMatthew G. Knepley v = sin(2 pi y) - 2xy
27165876a83SMatthew G. Knepley \varepsilon = / 2 pi cos(2 pi x)             -y        \
27265876a83SMatthew G. Knepley               \      -y          2 pi cos(2 pi y) - 2x /
27365876a83SMatthew G. Knepley Tr(\varepsilon) = div u = 2 pi (cos(2 pi x) + cos(2 pi y)) - 2 x
27465876a83SMatthew G. Knepley div \sigma = \partial_i \lambda \delta_{ij} \varepsilon_{kk} + \partial_i 2\mu\varepsilon_{ij}
27565876a83SMatthew G. Knepley   = \lambda \partial_j 2 pi (cos(2 pi x) + cos(2 pi y)) + 2\mu < -4 pi^2 sin(2 pi x) - 1, -4 pi^2 sin(2 pi y) >
27665876a83SMatthew G. Knepley   = \lambda < -4 pi^2 sin(2 pi x) - 2, -4 pi^2 sin(2 pi y) > + \mu < -8 pi^2 sin(2 pi x) - 2, -8 pi^2 sin(2 pi y) >
27765876a83SMatthew G. Knepley 
27865876a83SMatthew G. Knepley   2D:
27965876a83SMatthew G. Knepley   u = sin(2 pi x)
28065876a83SMatthew G. Knepley   v = sin(2 pi y) - 2xy
28165876a83SMatthew G. Knepley   p = (cos(2 pi x) + cos(2 pi y)) t
28265876a83SMatthew G. Knepley   e = 2 pi (cos(2 pi x) + cos(2 pi y)) - 2 x
28365876a83SMatthew G. Knepley   f = < -4 pi^2 sin(2 pi x) (2 G + lambda) - (2 G - 2 lambda), -4 pi^2 sin(2 pi y) (2G + lambda) > + 2 pi alpha t <sin(2 pi x), sin(2 pi y)>
28465876a83SMatthew G. Knepley   g = 0
28565876a83SMatthew G. Knepley   \varepsilon = / 2 pi cos(2 pi x)             -y        \
28665876a83SMatthew G. Knepley                 \      -y          2 pi cos(2 pi y) - 2x /
28765876a83SMatthew G. Knepley   Tr(\varepsilon) = div u = 2 pi (cos(2 pi x) + cos(2 pi y)) - 2 x
28865876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
28965876a83SMatthew G. Knepley     = 2 G < -4 pi^2 sin(2 pi x) - 1, -4 pi^2 sin(2 pi y) > + \lambda <-4 pi^2 sin(2 pi x) - 2, -4 pi^2 sin(2 pi y)> - alpha <-2 pi sin(2 pi x) t, -2 pi sin(2 pi y) t>
29065876a83SMatthew G. Knepley     = < -4 pi^2 sin(2 pi x) (2 G + lambda) - (2 G + 2 lambda), -4 pi^2 sin(2 pi y) (2G + lambda) > + 2 pi alpha t <sin(2 pi x), sin(2 pi y)>
29165876a83SMatthew G. Knepley   \frac{1}{M} \frac{dp}{dt} + \alpha \frac{d\varepsilon}{dt} - \nabla \cdot \kappa \nabla p
29265876a83SMatthew G. Knepley     = \frac{1}{M} \frac{dp}{dt} + \kappa \Delta p
29365876a83SMatthew G. Knepley     = (cos(2 pi x) + cos(2 pi y))/M - 4 pi^2 \kappa (cos(2 pi x) + cos(2 pi y)) t
29465876a83SMatthew G. Knepley 
29565876a83SMatthew G. Knepley   3D:
29665876a83SMatthew G. Knepley   u = sin(2 pi x)
29765876a83SMatthew G. Knepley   v = sin(2 pi y) - 2xy
29865876a83SMatthew G. Knepley   v = sin(2 pi y) - 2yz
29965876a83SMatthew G. Knepley   p = (cos(2 pi x) + cos(2 pi y) + cos(2 pi z)) t
30065876a83SMatthew G. Knepley   e = 2 pi (cos(2 pi x) + cos(2 pi y) + cos(2 pi z)) - 2 x - 2y
30165876a83SMatthew G. Knepley   f = < -4 pi^2 sin(2 pi x) (2 G + lambda) - (2 G + 2 lambda),  -4 pi^2 sin(2 pi y) (2 G + lambda) - (2 G + 2 lambda), -4 pi^2 sin(2 pi z) (2G + lambda) > + 2 pi alpha t <sin(2 pi x), sin(2 pi y), , sin(2 pi z)>
30265876a83SMatthew G. Knepley   g = 0
30365876a83SMatthew G. Knepley   \varepsilon = / 2 pi cos(2 pi x)            -y                     0         \
30465876a83SMatthew G. Knepley                 |         -y       2 pi cos(2 pi y) - 2x            -z         |
30565876a83SMatthew G. Knepley                 \          0                  -z         2 pi cos(2 pi z) - 2y /
30665876a83SMatthew G. Knepley   Tr(\varepsilon) = div u = 2 pi (cos(2 pi x) + cos(2 pi y) + cos(2 pi z)) - 2 x - 2 y
30765876a83SMatthew G. Knepley   div \sigma = \partial_i 2 G \epsilon_{ij} + \partial_i \lambda \varepsilon \delta_{ij} - \partial_i \alpha p \delta_{ij}
30865876a83SMatthew G. Knepley     = 2 G < -4 pi^2 sin(2 pi x) - 1, -4 pi^2 sin(2 pi y) - 1, -4 pi^2 sin(2 pi z) > + \lambda <-4 pi^2 sin(2 pi x) - 2, 4 pi^2 sin(2 pi y) - 2, -4 pi^2 sin(2 pi y)> - alpha <-2 pi sin(2 pi x) t, -2 pi sin(2 pi y) t, -2 pi sin(2 pi z) t>
30965876a83SMatthew G. Knepley     = < -4 pi^2 sin(2 pi x) (2 G + lambda) - (2 G + 2 lambda),  -4 pi^2 sin(2 pi y) (2 G + lambda) - (2 G + 2 lambda), -4 pi^2 sin(2 pi z) (2G + lambda) > + 2 pi alpha t <sin(2 pi x), sin(2 pi y), , sin(2 pi z)>
31065876a83SMatthew G. Knepley   \frac{1}{M} \frac{dp}{dt} + \alpha \frac{d\varepsilon}{dt} - \nabla \cdot \kappa \nabla p
31165876a83SMatthew G. Knepley     = \frac{1}{M} \frac{dp}{dt} + \kappa \Delta p
31265876a83SMatthew G. Knepley     = (cos(2 pi x) + cos(2 pi y) + cos(2 pi z))/M - 4 pi^2 \kappa (cos(2 pi x) + cos(2 pi y) + cos(2 pi z)) t
31365876a83SMatthew G. Knepley */
31465876a83SMatthew G. Knepley static PetscErrorCode trig_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
31565876a83SMatthew G. Knepley {
31665876a83SMatthew G. Knepley   PetscInt d;
31765876a83SMatthew G. Knepley 
31865876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
31965876a83SMatthew G. Knepley     u[d] = PetscSinReal(2.*PETSC_PI*x[d]) - (d > 0 ? 2.0 * x[d-1] * x[d] : 0.0);
32065876a83SMatthew G. Knepley   }
32165876a83SMatthew G. Knepley   return 0;
32265876a83SMatthew G. Knepley }
32365876a83SMatthew G. Knepley 
32465876a83SMatthew G. Knepley static PetscErrorCode trig_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
32565876a83SMatthew G. Knepley {
32665876a83SMatthew G. Knepley   PetscReal sum = 0.0;
32765876a83SMatthew G. Knepley   PetscInt  d;
32865876a83SMatthew G. Knepley 
32965876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += 2.*PETSC_PI*PetscCosReal(2.*PETSC_PI*x[d]) - (d < dim-1 ? 2.*x[d] : 0.0);
33065876a83SMatthew G. Knepley   u[0] = sum;
33165876a83SMatthew G. Knepley   return 0;
33265876a83SMatthew G. Knepley }
33365876a83SMatthew G. Knepley 
33465876a83SMatthew G. Knepley static PetscErrorCode trig_linear_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
33565876a83SMatthew G. Knepley {
33665876a83SMatthew G. Knepley   PetscReal sum = 0.0;
33765876a83SMatthew G. Knepley   PetscInt  d;
33865876a83SMatthew G. Knepley 
33965876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += PetscCosReal(2.*PETSC_PI*x[d]);
34065876a83SMatthew G. Knepley   u[0] = sum*time;
34165876a83SMatthew G. Knepley   return 0;
34265876a83SMatthew G. Knepley }
34365876a83SMatthew G. Knepley 
34465876a83SMatthew G. Knepley static PetscErrorCode trig_linear_p_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
34565876a83SMatthew G. Knepley {
34665876a83SMatthew G. Knepley   PetscReal sum = 0.0;
34765876a83SMatthew G. Knepley   PetscInt  d;
34865876a83SMatthew G. Knepley 
34965876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += PetscCosReal(2.*PETSC_PI*x[d]);
35065876a83SMatthew G. Knepley   u[0] = sum;
35165876a83SMatthew G. Knepley   return 0;
35265876a83SMatthew G. Knepley }
35365876a83SMatthew G. Knepley 
35465876a83SMatthew G. Knepley static void f0_trig_linear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
35565876a83SMatthew G. Knepley                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
35665876a83SMatthew G. Knepley                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
35765876a83SMatthew G. Knepley                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
35865876a83SMatthew G. Knepley {
35965876a83SMatthew G. Knepley   const PetscReal G      = PetscRealPart(constants[0]);
36065876a83SMatthew G. Knepley   const PetscReal K_u    = PetscRealPart(constants[1]);
36165876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
36265876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
36365876a83SMatthew G. Knepley   const PetscReal K_d    = K_u - alpha*alpha*M;
36465876a83SMatthew G. Knepley   const PetscReal lambda = K_d - (2.0 * G) / 3.0;
36565876a83SMatthew G. Knepley   PetscInt        d;
36665876a83SMatthew G. Knepley 
36765876a83SMatthew G. Knepley   for (d = 0; d < dim-1; ++d) {
36865876a83SMatthew G. Knepley     f0[d] += PetscSqr(2.*PETSC_PI)*PetscSinReal(2.*PETSC_PI*x[d])*(2.*G + lambda) + 2.0*(G + lambda) - 2.*PETSC_PI*alpha*PetscSinReal(2.*PETSC_PI*x[d])*t;
36965876a83SMatthew G. Knepley   }
37065876a83SMatthew G. Knepley   f0[dim-1] += PetscSqr(2.*PETSC_PI)*PetscSinReal(2.*PETSC_PI*x[dim-1])*(2.*G + lambda) - 2.*PETSC_PI*alpha*PetscSinReal(2.*PETSC_PI*x[dim-1])*t;
37165876a83SMatthew G. Knepley }
37265876a83SMatthew G. Knepley 
37365876a83SMatthew G. Knepley static void f0_trig_linear_p(PetscInt dim, PetscInt Nf, PetscInt NfAux,
37465876a83SMatthew G. Knepley                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
37565876a83SMatthew G. Knepley                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
37665876a83SMatthew G. Knepley                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
37765876a83SMatthew G. Knepley {
37865876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
37965876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
38065876a83SMatthew G. Knepley   const PetscReal kappa  = PetscRealPart(constants[4]);
38165876a83SMatthew G. Knepley   PetscReal       sum    = 0.0;
38265876a83SMatthew G. Knepley   PetscInt        d;
38365876a83SMatthew G. Knepley 
38465876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) sum += PetscCosReal(2.*PETSC_PI*x[d]);
38565876a83SMatthew G. Knepley   f0[0] += u_t ? alpha*u_t[uOff[1]] : 0.0;
38665876a83SMatthew G. Knepley   f0[0] += u_t ? u_t[uOff[2]]/M     : 0.0;
38765876a83SMatthew G. Knepley   f0[0] -= sum/M - 4*PetscSqr(PETSC_PI)*kappa*sum*t;
38865876a83SMatthew G. Knepley }
38965876a83SMatthew G. Knepley 
39065876a83SMatthew G. Knepley /* Terzaghi Solutions */
39165876a83SMatthew G. Knepley /* The analytical solutions given here are drawn from chapter 7, section 3, */
39265876a83SMatthew G. Knepley /* "One-Dimensional Consolidation Problem," from Poroelasticity, by Cheng.  */
39365876a83SMatthew G. Knepley static PetscErrorCode terzaghi_drainage_pressure(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
39465876a83SMatthew G. Knepley {
39565876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
39665876a83SMatthew G. Knepley   Parameter     *param;
39765876a83SMatthew G. Knepley   PetscErrorCode ierr;
39865876a83SMatthew G. Knepley 
39965876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
40065876a83SMatthew G. Knepley   if (time <= 0.0) {
40165876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
40265876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
40365876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
40465876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
40565876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
40665876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
40765876a83SMatthew G. Knepley     PetscScalar eta   = (3.0*alpha*G) / (3.0*K_d + 4.0*G);         /* -,       Cheng (B.11) */
40865876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
40965876a83SMatthew G. Knepley 
41065876a83SMatthew G. Knepley     u[0] = ((P_0*eta) / (G*S));
41165876a83SMatthew G. Knepley   } else {
41265876a83SMatthew G. Knepley     u[0] = 0.0;
41365876a83SMatthew G. Knepley   }
41465876a83SMatthew G. Knepley   return 0;
41565876a83SMatthew G. Knepley }
41665876a83SMatthew G. Knepley 
41765876a83SMatthew G. Knepley static PetscErrorCode terzaghi_initial_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
41865876a83SMatthew G. Knepley {
41965876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
42065876a83SMatthew G. Knepley   Parameter     *param;
42165876a83SMatthew G. Knepley   PetscErrorCode ierr;
42265876a83SMatthew G. Knepley 
42365876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
42465876a83SMatthew G. Knepley   {
42565876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
42665876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
42765876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
42830602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
42965876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G)); /* -,       Cheng (B.9)  */
43065876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                /* - */
43165876a83SMatthew G. Knepley 
43265876a83SMatthew G. Knepley     u[0] = 0.0;
43365876a83SMatthew G. Knepley     u[1] = ((P_0*L*(1.0 - 2.0*nu_u)) / (2.0*G*(1.0 - nu_u))) * (1.0 - zstar);
43465876a83SMatthew G. Knepley   }
43565876a83SMatthew G. Knepley   return 0;
43665876a83SMatthew G. Knepley }
43765876a83SMatthew G. Knepley 
43865876a83SMatthew G. Knepley static PetscErrorCode terzaghi_initial_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
43965876a83SMatthew G. Knepley {
44065876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
44165876a83SMatthew G. Knepley   Parameter     *param;
44265876a83SMatthew G. Knepley   PetscErrorCode ierr;
44365876a83SMatthew G. Knepley 
44465876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
44565876a83SMatthew G. Knepley   {
44665876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
44765876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
44865876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
44965876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
45065876a83SMatthew G. Knepley 
45165876a83SMatthew G. Knepley     u[0] = -(P_0*(1.0 - 2.0*nu_u)) / (2.0*G*(1.0 - nu_u));
45265876a83SMatthew G. Knepley   }
45365876a83SMatthew G. Knepley   return 0;
45465876a83SMatthew G. Knepley }
45565876a83SMatthew G. Knepley 
45665876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
45765876a83SMatthew G. Knepley {
45865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
45965876a83SMatthew G. Knepley   Parameter     *param;
46065876a83SMatthew G. Knepley   PetscErrorCode ierr;
46165876a83SMatthew G. Knepley 
46265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
46365876a83SMatthew G. Knepley   if (time < 0.0) {
46465876a83SMatthew G. Knepley     ierr = terzaghi_initial_u(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
46565876a83SMatthew G. Knepley   } else {
46665876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
46765876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
46865876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
46965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
47065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
47165876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
47230602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
47365876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
47465876a83SMatthew G. Knepley 
47565876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
47665876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
47765876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
47865876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
47965876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
48065876a83SMatthew G. Knepley 
48165876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
48265876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
48365876a83SMatthew G. Knepley     PetscScalar F2    = 0.0;
48465876a83SMatthew G. Knepley 
48565876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
48665876a83SMatthew G. Knepley       if (m%2 == 1) {
48765876a83SMatthew G. Knepley         F2 += (8.0 / PetscSqr(m*PETSC_PI)) * PetscCosReal(0.5*m*PETSC_PI*zstar) * (1.0 - PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar));
48865876a83SMatthew G. Knepley       }
48965876a83SMatthew G. Knepley     }
49065876a83SMatthew G. Knepley     u[0] = 0.0;
49165876a83SMatthew G. Knepley     u[1] = ((P_0*L*(1.0 - 2.0*nu_u)) / (2.0*G*(1.0 - nu_u))) * (1.0 - zstar) + ((P_0*L*(nu_u - nu)) / (2.0*G*(1.0 - nu_u)*(1.0 - nu)))*F2; /* m */
49265876a83SMatthew G. Knepley   }
49365876a83SMatthew G. Knepley   return 0;
49465876a83SMatthew G. Knepley }
49565876a83SMatthew G. Knepley 
49665876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
49765876a83SMatthew G. Knepley {
49865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
49965876a83SMatthew G. Knepley   Parameter     *param;
50065876a83SMatthew G. Knepley   PetscErrorCode ierr;
50165876a83SMatthew G. Knepley 
50265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
50365876a83SMatthew G. Knepley   if (time < 0.0) {
50465876a83SMatthew G. Knepley     ierr = terzaghi_initial_eps(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
50565876a83SMatthew G. Knepley   } else {
50665876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
50765876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
50865876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
50965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
51065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
51165876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
51230602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
51365876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
51465876a83SMatthew G. Knepley 
51565876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
51665876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
51765876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
51865876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
51965876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
52065876a83SMatthew G. Knepley 
52165876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
52265876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
52365876a83SMatthew G. Knepley     PetscScalar F2_z  = 0.0;
52465876a83SMatthew G. Knepley 
52565876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
52665876a83SMatthew G. Knepley       if (m%2 == 1) {
52765876a83SMatthew G. Knepley         F2_z += (-4.0 / (m*PETSC_PI*L)) * PetscSinReal(0.5*m*PETSC_PI*zstar) * (1.0 - PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar));
52865876a83SMatthew G. Knepley       }
52965876a83SMatthew G. Knepley     }
53065876a83SMatthew G. Knepley     u[0] = -((P_0*L*(1.0 - 2.0*nu_u)) / (2.0*G*(1.0 - nu_u)*L)) + ((P_0*L*(nu_u - nu)) / (2.0*G*(1.0 - nu_u)*(1.0 - nu)))*F2_z; /* - */
53165876a83SMatthew G. Knepley   }
53265876a83SMatthew G. Knepley   return 0;
53365876a83SMatthew G. Knepley }
53465876a83SMatthew G. Knepley 
53565876a83SMatthew G. Knepley // Pressure
53665876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
53765876a83SMatthew G. Knepley {
53865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
53965876a83SMatthew G. Knepley   Parameter     *param;
54065876a83SMatthew G. Knepley   PetscErrorCode ierr;
54165876a83SMatthew G. Knepley 
54265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
54365876a83SMatthew G. Knepley   if (time <= 0.0) {
54465876a83SMatthew G. Knepley     ierr = terzaghi_drainage_pressure(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
54565876a83SMatthew G. Knepley   } else {
54665876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
54765876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
54865876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
54965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
55065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
55165876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
55230602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
55365876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
55465876a83SMatthew G. Knepley 
55565876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
55665876a83SMatthew G. Knepley     PetscScalar eta   = (3.0*alpha*G) / (3.0*K_d + 4.0*G);         /* -,       Cheng (B.11) */
55765876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
55865876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
55965876a83SMatthew G. Knepley 
56065876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
56165876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
56265876a83SMatthew G. Knepley     PetscScalar F1    = 0.0;
56365876a83SMatthew G. Knepley 
56465876a83SMatthew G. Knepley     if (PetscAbsScalar((1/M + (alpha*eta)/G) - S) > 1.0e-10) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "S %g != check %g", S, (1/M + (alpha*eta)/G));
56565876a83SMatthew G. Knepley 
56665876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
56765876a83SMatthew G. Knepley       if (m%2 == 1) {
56865876a83SMatthew G. Knepley         F1 += (4.0 / (m*PETSC_PI)) * PetscSinReal(0.5*m*PETSC_PI*zstar) * PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar);
56965876a83SMatthew G. Knepley       }
57065876a83SMatthew G. Knepley     }
57165876a83SMatthew G. Knepley     u[0] = ((P_0*eta) / (G*S)) * F1; /* Pa */
57265876a83SMatthew G. Knepley   }
57365876a83SMatthew G. Knepley   return 0;
57465876a83SMatthew G. Knepley }
57565876a83SMatthew G. Knepley 
57665876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_u_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
57765876a83SMatthew G. Knepley {
57865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
57965876a83SMatthew G. Knepley   Parameter     *param;
58065876a83SMatthew G. Knepley   PetscErrorCode ierr;
58165876a83SMatthew G. Knepley 
58265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
58365876a83SMatthew G. Knepley   if (time <= 0.0) {
58465876a83SMatthew G. Knepley     u[0] = 0.0;
58565876a83SMatthew G. Knepley     u[1] = 0.0;
58665876a83SMatthew G. Knepley   } else {
58765876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
58865876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
58965876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
59065876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
59165876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
59265876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
59330602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
59465876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
59565876a83SMatthew G. Knepley 
59665876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
59765876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
59865876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
59965876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
60065876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
60165876a83SMatthew G. Knepley 
60265876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
60365876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
60465876a83SMatthew G. Knepley     PetscScalar F2_t  = 0.0;
60565876a83SMatthew G. Knepley 
60665876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
60765876a83SMatthew G. Knepley       if (m%2 == 1) {
60865876a83SMatthew G. Knepley         F2_t += (2.0*c / PetscSqr(L)) * PetscCosReal(0.5*m*PETSC_PI*zstar) * PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar);
60965876a83SMatthew G. Knepley       }
61065876a83SMatthew G. Knepley     }
61165876a83SMatthew G. Knepley     u[0] = 0.0;
61265876a83SMatthew G. Knepley     u[1] = ((P_0*L*(nu_u - nu)) / (2.0*G*(1.0 - nu_u)*(1.0 - nu)))*F2_t; /* m / s */
61365876a83SMatthew G. Knepley   }
61465876a83SMatthew G. Knepley   return 0;
61565876a83SMatthew G. Knepley }
61665876a83SMatthew G. Knepley 
61765876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_eps_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
61865876a83SMatthew G. Knepley {
61965876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
62065876a83SMatthew G. Knepley   Parameter     *param;
62165876a83SMatthew G. Knepley   PetscErrorCode ierr;
62265876a83SMatthew G. Knepley 
62365876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
62465876a83SMatthew G. Knepley   if (time <= 0.0) {
62565876a83SMatthew G. Knepley     u[0] = 0.0;
62665876a83SMatthew G. Knepley   } else {
62765876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
62865876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
62965876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
63065876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
63165876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
63265876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
63330602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
63465876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
63565876a83SMatthew G. Knepley 
63665876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
63765876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
63865876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
63965876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
64065876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
64165876a83SMatthew G. Knepley 
64265876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
64365876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
64465876a83SMatthew G. Knepley     PetscScalar F2_zt = 0.0;
64565876a83SMatthew G. Knepley 
64665876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
64765876a83SMatthew G. Knepley       if (m%2 == 1) {
64865876a83SMatthew G. Knepley         F2_zt += ((-m*PETSC_PI*c) / (L*L*L)) * PetscSinReal(0.5*m*PETSC_PI*zstar) * PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar);
64965876a83SMatthew G. Knepley       }
65065876a83SMatthew G. Knepley     }
65165876a83SMatthew G. Knepley     u[0] = ((P_0*L*(nu_u - nu)) / (2.0*G*(1.0 - nu_u)*(1.0 - nu)))*F2_zt; /* 1 / s */
65265876a83SMatthew G. Knepley   }
65365876a83SMatthew G. Knepley   return 0;
65465876a83SMatthew G. Knepley }
65565876a83SMatthew G. Knepley 
65665876a83SMatthew G. Knepley static PetscErrorCode terzaghi_2d_p_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
65765876a83SMatthew G. Knepley {
65865876a83SMatthew G. Knepley 
65965876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
66065876a83SMatthew G. Knepley   Parameter     *param;
66165876a83SMatthew G. Knepley   PetscErrorCode ierr;
66265876a83SMatthew G. Knepley 
66365876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
66465876a83SMatthew G. Knepley   if (time <= 0.0) {
66565876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
66665876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
66765876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
66865876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
66965876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
67065876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
67130602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
67265876a83SMatthew G. Knepley 
67365876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
67465876a83SMatthew G. Knepley     PetscScalar eta   = (3.0*alpha*G) / (3.0*K_d + 4.0*G);         /* -,       Cheng (B.11) */
67565876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
67665876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
67765876a83SMatthew G. Knepley 
67865876a83SMatthew G. Knepley     u[0] = -((P_0*eta) / (G*S)) * PetscSqr(0*PETSC_PI)*c / PetscSqr(2.0*L); /* Pa / s */
67965876a83SMatthew G. Knepley   } else {
68065876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
68165876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
68265876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
68365876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
68465876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
68565876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
68630602db0SMatthew G. Knepley     PetscReal   L     = user->xmax[1] - user->xmin[1]; /* m */
68765876a83SMatthew G. Knepley     PetscInt    N     = user->niter, m;
68865876a83SMatthew G. Knepley 
68965876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
69065876a83SMatthew G. Knepley     PetscScalar eta   = (3.0*alpha*G) / (3.0*K_d + 4.0*G);         /* -,       Cheng (B.11) */
69165876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
69265876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
69365876a83SMatthew G. Knepley 
69465876a83SMatthew G. Knepley     PetscReal   zstar = x[1] / L;                                  /* - */
69565876a83SMatthew G. Knepley     PetscReal   tstar = PetscRealPart(c*time) / PetscSqr(2.0*L);   /* - */
69665876a83SMatthew G. Knepley     PetscScalar F1_t  = 0.0;
69765876a83SMatthew G. Knepley     PetscScalar F1_zz = 0.0;
69865876a83SMatthew G. Knepley 
69965876a83SMatthew G. Knepley     if (PetscAbsScalar((1/M + (alpha*eta)/G) - S) > 1.0e-10) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "S %g != check %g", S, (1/M + (alpha*eta)/G));
70065876a83SMatthew G. Knepley 
70165876a83SMatthew G. Knepley     for (m = 1; m < 2*N+1; ++m) {
70265876a83SMatthew G. Knepley       if (m%2 == 1) {
70365876a83SMatthew G. Knepley         F1_t += ((-m*PETSC_PI*c) / PetscSqr(L)) * PetscSinReal(0.5*m*PETSC_PI*zstar) * PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar);
70465876a83SMatthew G. Knepley         F1_zz += (-m*PETSC_PI / PetscSqr(L)) * PetscSinReal(0.5*m*PETSC_PI*zstar) * PetscExpReal(-PetscSqr(m*PETSC_PI)*tstar);
70565876a83SMatthew G. Knepley       }
70665876a83SMatthew G. Knepley     }
70765876a83SMatthew G. Knepley     u[0] = ((P_0*eta) / (G*S)) * F1_t; /* Pa / s */
70865876a83SMatthew G. Knepley   }
70965876a83SMatthew G. Knepley   return 0;
71065876a83SMatthew G. Knepley }
71165876a83SMatthew G. Knepley 
71265876a83SMatthew G. Knepley /* Mandel Solutions */
71365876a83SMatthew G. Knepley static PetscErrorCode mandel_drainage_pressure(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
71465876a83SMatthew G. Knepley {
71565876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
71665876a83SMatthew G. Knepley   Parameter     *param;
71765876a83SMatthew G. Knepley   PetscErrorCode ierr;
71865876a83SMatthew G. Knepley 
71965876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
72065876a83SMatthew G. Knepley   if (time <= 0.0) {
72165876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
72265876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
72365876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
72465876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
72565876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
72665876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
72730602db0SMatthew G. Knepley     PetscReal   a     = 0.5*(user->xmax[0] - user->xmin[0]); /* m */
72865876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
72965876a83SMatthew G. Knepley 
73065876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
73165876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
73265876a83SMatthew G. Knepley     PetscScalar B     = alpha*M / K_u;                             /* -,       Cheng (B.12) */
73365876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
73465876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
73565876a83SMatthew G. Knepley 
73665876a83SMatthew G. Knepley     PetscScalar A1    = 3.0 / (B * (1.0 + nu_u));
73765876a83SMatthew G. Knepley     PetscReal   aa    = 0.0;
73865876a83SMatthew G. Knepley     PetscReal   p     = 0.0;
73965876a83SMatthew G. Knepley     PetscReal   time  = 0.0;
74065876a83SMatthew G. Knepley 
74165876a83SMatthew G. Knepley     for (n = 1; n < N+1; ++n) {
74265876a83SMatthew G. Knepley       aa = user->zeroArray[n-1];
74365876a83SMatthew G. Knepley       p += (PetscSinReal(aa) / (aa - PetscSinReal(aa)*PetscCosReal(aa))) * (PetscCosReal( (aa*x[0]) / a) - PetscCosReal(aa)) * PetscExpReal(-1.0*(aa*aa * PetscRealPart(c) * time)/(a*a));
74465876a83SMatthew G. Knepley     }
74565876a83SMatthew G. Knepley     u[0] = ((2.0 * P_0) / (a*A1)) * p;
74665876a83SMatthew G. Knepley   } else {
74765876a83SMatthew G. Knepley     u[0] = 0.0;
74865876a83SMatthew G. Knepley   }
74965876a83SMatthew G. Knepley   return 0;
75065876a83SMatthew G. Knepley }
75165876a83SMatthew G. Knepley 
75265876a83SMatthew G. Knepley static PetscErrorCode mandel_initial_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
75365876a83SMatthew G. Knepley {
75465876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
75565876a83SMatthew G. Knepley   Parameter     *param;
75665876a83SMatthew G. Knepley   PetscErrorCode ierr;
75765876a83SMatthew G. Knepley 
75865876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
75965876a83SMatthew G. Knepley   {
76065876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
76165876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
76265876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
76365876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
76465876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
76565876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
76630602db0SMatthew G. Knepley     PetscScalar a     = 0.5*(user->xmax[0] - user->xmin[0]); /* m */
76765876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
76865876a83SMatthew G. Knepley 
76965876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
77065876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
77165876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
77265876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
77365876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
77465876a83SMatthew G. Knepley 
77565876a83SMatthew G. Knepley     PetscScalar A_s   = 0.0;
77665876a83SMatthew G. Knepley     PetscScalar B_s   = 0.0;
77765876a83SMatthew G. Knepley     PetscScalar time  = 0.0;
77865876a83SMatthew G. Knepley     PetscScalar alpha_n = 0.0;
77965876a83SMatthew G. Knepley 
78065876a83SMatthew G. Knepley     for (n = 1; n < N+1; ++n) {
78165876a83SMatthew G. Knepley       alpha_n = user->zeroArray[n-1];
78265876a83SMatthew G. Knepley       A_s += ((PetscSinReal(alpha_n) * PetscCosReal(alpha_n)) / (alpha_n - PetscSinReal(alpha_n) * PetscCosReal(alpha_n))) * PetscExpReal(-1*(alpha_n*alpha_n*c*time)/(a*a));
78365876a83SMatthew G. Knepley       B_s += (PetscCosReal(alpha_n) / (alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n))) * PetscSinReal( (alpha_n * x[0])/a) * PetscExpReal(-1*(alpha_n*alpha_n*c*time)/(a*a));
78465876a83SMatthew G. Knepley     }
78565876a83SMatthew G. Knepley     u[0] = ((P_0*nu)/(2.0*G*a) - (P_0*nu_u)/(G*a) * A_s)* x[0] + P_0/G * B_s;
78665876a83SMatthew G. Knepley     u[1] = (-1*(P_0*(1.0-nu))/(2*G*a) + (P_0*(1-nu_u))/(G*a) * A_s)*x[1];
78765876a83SMatthew G. Knepley   }
78865876a83SMatthew G. Knepley   return 0;
78965876a83SMatthew G. Knepley }
79065876a83SMatthew G. Knepley 
79165876a83SMatthew G. Knepley static PetscErrorCode mandel_initial_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
79265876a83SMatthew G. Knepley {
79365876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
79465876a83SMatthew G. Knepley   Parameter     *param;
79565876a83SMatthew G. Knepley   PetscErrorCode ierr;
79665876a83SMatthew G. Knepley 
79765876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
79865876a83SMatthew G. Knepley   {
79965876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
80065876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
80165876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
80265876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
80365876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
80465876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
80530602db0SMatthew G. Knepley     PetscReal   a     = 0.5*(user->xmax[0] - user->xmin[0]); /* m */
80665876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
80765876a83SMatthew G. Knepley 
80865876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
80965876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
81065876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
81165876a83SMatthew G. Knepley     PetscReal   c     = PetscRealPart(kappa / S);                  /* m^2 / s, Cheng (B.16) */
81265876a83SMatthew G. Knepley 
81365876a83SMatthew G. Knepley     PetscReal   aa    = 0.0;
81465876a83SMatthew G. Knepley     PetscReal   eps_A = 0.0;
81565876a83SMatthew G. Knepley     PetscReal   eps_B = 0.0;
81665876a83SMatthew G. Knepley     PetscReal   eps_C = 0.0;
81765876a83SMatthew G. Knepley     PetscReal   time  = 0.0;
81865876a83SMatthew G. Knepley 
81965876a83SMatthew G. Knepley     for (n = 1; n < N+1; ++n) {
82065876a83SMatthew G. Knepley       aa     = user->zeroArray[n-1];
82165876a83SMatthew G. Knepley       eps_A += (aa * PetscExpReal( (-1.0*aa*aa*c*time)/(a*a))*PetscCosReal(aa)*PetscCosReal( (aa*x[0])/a)) / (a * (aa - PetscSinReal(aa)*PetscCosReal(aa)));
82265876a83SMatthew G. Knepley       eps_B += ( PetscExpReal( (-1.0*aa*aa*c*time)/(a*a))*PetscSinReal(aa)*PetscCosReal(aa)) / (aa - PetscSinReal(aa)*PetscCosReal(aa));
82365876a83SMatthew G. Knepley       eps_C += ( PetscExpReal( (-1.0*aa*aa*c*time)/(aa*aa))*PetscSinReal(aa)*PetscCosReal(aa)) / (aa - PetscSinReal(aa)*PetscCosReal(aa));
82465876a83SMatthew G. Knepley     }
82565876a83SMatthew G. Knepley     u[0] = (P_0/G)*eps_A + ( (P_0*nu)/(2.0*G*a)) - eps_B/(G*a) - (P_0*(1-nu))/(2*G*a) + eps_C/(G*a);
82665876a83SMatthew G. Knepley   }
82765876a83SMatthew G. Knepley   return 0;
82865876a83SMatthew G. Knepley }
82965876a83SMatthew G. Knepley 
83065876a83SMatthew G. Knepley // Displacement
83165876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
83265876a83SMatthew G. Knepley {
83365876a83SMatthew G. Knepley 
83465876a83SMatthew G. Knepley   Parameter  *param;
83565876a83SMatthew G. Knepley   PetscErrorCode ierr;
83665876a83SMatthew G. Knepley 
83765876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
83865876a83SMatthew G. Knepley 
83965876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
84065876a83SMatthew G. Knepley   if (time <= 0.0) {
84165876a83SMatthew G. Knepley     ierr = mandel_initial_u(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
84265876a83SMatthew G. Knepley   } else {
84365876a83SMatthew G. Knepley     PetscInt NITER = user->niter;
84465876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha;
84565876a83SMatthew G. Knepley     PetscScalar K_u = param->K_u;
84665876a83SMatthew G. Knepley     PetscScalar M = param->M;
84765876a83SMatthew G. Knepley     PetscScalar G = param->mu;
84865876a83SMatthew G. Knepley     PetscScalar k = param->k;
84965876a83SMatthew G. Knepley     PetscScalar mu_f = param->mu_f;
85065876a83SMatthew G. Knepley     PetscScalar F = param->P_0;
85165876a83SMatthew G. Knepley 
85265876a83SMatthew G. Knepley     PetscScalar K_d = K_u - alpha*alpha*M;
85365876a83SMatthew G. Knepley     PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
85465876a83SMatthew G. Knepley     PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
85565876a83SMatthew G. Knepley     PetscScalar kappa = k / mu_f;
85630602db0SMatthew G. Knepley     PetscReal   a = (user->xmax[0] - user->xmin[0]) / 2.0;
85765876a83SMatthew G. Knepley     PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / ( alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
85865876a83SMatthew G. Knepley 
85965876a83SMatthew G. Knepley     // Series term
86065876a83SMatthew G. Knepley     PetscScalar A_x = 0.0;
86165876a83SMatthew G. Knepley     PetscScalar B_x = 0.0;
86265876a83SMatthew G. Knepley 
86365876a83SMatthew G. Knepley     for (PetscInt n=1; n < NITER+1; n++) {
86465876a83SMatthew G. Knepley       PetscReal alpha_n = user->zeroArray[n-1];
86565876a83SMatthew G. Knepley 
86665876a83SMatthew G. Knepley       A_x += ( (PetscSinReal(alpha_n) * PetscCosReal(alpha_n)) / (alpha_n - PetscSinReal(alpha_n) * PetscCosReal(alpha_n))) * PetscExpReal( -1*(alpha_n*alpha_n*c*time)/(a*a));
86765876a83SMatthew G. Knepley       B_x += ( PetscCosReal(alpha_n) / (alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n))) * PetscSinReal( (alpha_n * x[0])/a) * PetscExpReal( -1*(alpha_n*alpha_n*c*time)/(a*a));
86865876a83SMatthew G. Knepley     }
86965876a83SMatthew G. Knepley     u[0] = ((F*nu)/(2.0*G*a) - (F*nu_u)/(G*a) * A_x)* x[0] + F/G * B_x;
87065876a83SMatthew G. Knepley     u[1] = (-1*(F*(1.0-nu))/(2*G*a) + (F*(1-nu_u))/(G*a) * A_x)*x[1];
87165876a83SMatthew G. Knepley   }
87265876a83SMatthew G. Knepley   return 0;
87365876a83SMatthew G. Knepley }
87465876a83SMatthew G. Knepley 
87565876a83SMatthew G. Knepley // Trace strain
87665876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
87765876a83SMatthew G. Knepley {
87865876a83SMatthew G. Knepley 
87965876a83SMatthew G. Knepley   Parameter  *param;
88065876a83SMatthew G. Knepley   PetscErrorCode ierr;
88165876a83SMatthew G. Knepley 
88265876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
88365876a83SMatthew G. Knepley 
88465876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
88565876a83SMatthew G. Knepley   if (time <= 0.0) {
88665876a83SMatthew G. Knepley     ierr = mandel_initial_eps(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
88765876a83SMatthew G. Knepley   } else {
88865876a83SMatthew G. Knepley     PetscInt NITER = user->niter;
88965876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha;
89065876a83SMatthew G. Knepley     PetscScalar K_u = param->K_u;
89165876a83SMatthew G. Knepley     PetscScalar M = param->M;
89265876a83SMatthew G. Knepley     PetscScalar G = param->mu;
89365876a83SMatthew G. Knepley     PetscScalar k = param->k;
89465876a83SMatthew G. Knepley     PetscScalar mu_f = param->mu_f;
89565876a83SMatthew G. Knepley     PetscScalar F = param->P_0;
89665876a83SMatthew G. Knepley 
89765876a83SMatthew G. Knepley     PetscScalar K_d = K_u - alpha*alpha*M;
89865876a83SMatthew G. Knepley     PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
89965876a83SMatthew G. Knepley     PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
90065876a83SMatthew G. Knepley     PetscScalar kappa = k / mu_f;
90165876a83SMatthew G. Knepley     //const PetscScalar B = (alpha*M)/(K_d + alpha*alpha * M);
90265876a83SMatthew G. Knepley 
90365876a83SMatthew G. Knepley     //const PetscScalar b = (YMAX - YMIN) / 2.0;
90430602db0SMatthew G. Knepley     PetscScalar a = (user->xmax[0] - user->xmin[0]) / 2.0;
90565876a83SMatthew G. Knepley     PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
90665876a83SMatthew G. Knepley 
90765876a83SMatthew G. Knepley     // Series term
90865876a83SMatthew G. Knepley     PetscScalar eps_A = 0.0;
90965876a83SMatthew G. Knepley     PetscScalar eps_B = 0.0;
91065876a83SMatthew G. Knepley     PetscScalar eps_C = 0.0;
91165876a83SMatthew G. Knepley 
91265876a83SMatthew G. Knepley     for (PetscInt n=1; n < NITER+1; n++)
91365876a83SMatthew G. Knepley     {
91465876a83SMatthew G. Knepley       PetscReal aa = user->zeroArray[n-1];
91565876a83SMatthew G. Knepley 
91665876a83SMatthew G. Knepley       eps_A += (aa * PetscExpReal( (-1.0*aa*aa*c*time)/(a*a))*PetscCosReal(aa)*PetscCosReal( (aa*x[0])/a)) / (a * (aa - PetscSinReal(aa)*PetscCosReal(aa)));
91765876a83SMatthew G. Knepley 
91865876a83SMatthew G. Knepley       eps_B += ( PetscExpReal( (-1.0*aa*aa*c*time)/(a*a))*PetscSinReal(aa)*PetscCosReal(aa)) / (aa - PetscSinReal(aa)*PetscCosReal(aa));
91965876a83SMatthew G. Knepley 
92065876a83SMatthew G. Knepley       eps_C += ( PetscExpReal( (-1.0*aa*aa*c*time)/(aa*aa))*PetscSinReal(aa)*PetscCosReal(aa)) / (aa - PetscSinReal(aa)*PetscCosReal(aa));
92165876a83SMatthew G. Knepley     }
92265876a83SMatthew G. Knepley 
92365876a83SMatthew G. Knepley     u[0] = (F/G)*eps_A + ( (F*nu)/(2.0*G*a)) - eps_B/(G*a) - (F*(1-nu))/(2*G*a) + eps_C/(G*a);
92465876a83SMatthew G. Knepley   }
92565876a83SMatthew G. Knepley   return 0;
92665876a83SMatthew G. Knepley 
92765876a83SMatthew G. Knepley }
92865876a83SMatthew G. Knepley 
92965876a83SMatthew G. Knepley // Pressure
93065876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
93165876a83SMatthew G. Knepley {
93265876a83SMatthew G. Knepley 
93365876a83SMatthew G. Knepley   Parameter  *param;
93465876a83SMatthew G. Knepley   PetscErrorCode ierr;
93565876a83SMatthew G. Knepley 
93665876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
93765876a83SMatthew G. Knepley 
93865876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
93965876a83SMatthew G. Knepley   if (time <= 0.0) {
94065876a83SMatthew G. Knepley     ierr = mandel_drainage_pressure(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
94165876a83SMatthew G. Knepley   } else {
94265876a83SMatthew G. Knepley     PetscInt NITER = user->niter;
94365876a83SMatthew G. Knepley 
94465876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha;
94565876a83SMatthew G. Knepley     PetscScalar K_u = param->K_u;
94665876a83SMatthew G. Knepley     PetscScalar M = param->M;
94765876a83SMatthew G. Knepley     PetscScalar G = param->mu;
94865876a83SMatthew G. Knepley     PetscScalar k = param->k;
94965876a83SMatthew G. Knepley     PetscScalar mu_f = param->mu_f;
95065876a83SMatthew G. Knepley     PetscScalar F = param->P_0;
95165876a83SMatthew G. Knepley 
95265876a83SMatthew G. Knepley     PetscScalar K_d = K_u - alpha*alpha*M;
95365876a83SMatthew G. Knepley     PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
95465876a83SMatthew G. Knepley     PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
95565876a83SMatthew G. Knepley     PetscScalar kappa = k / mu_f;
95665876a83SMatthew G. Knepley     PetscScalar B = (alpha*M)/(K_d + alpha*alpha * M);
95765876a83SMatthew G. Knepley 
95830602db0SMatthew G. Knepley     PetscReal   a  = (user->xmax[0] - user->xmin[0]) / 2.0;
95965876a83SMatthew G. Knepley     PetscReal   c  = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
96065876a83SMatthew G. Knepley     PetscScalar A1 = 3.0 / (B * (1.0 + nu_u));
96165876a83SMatthew G. Knepley     //PetscScalar A2 = (alpha * (1.0 - 2.0*nu)) / (1.0 - nu);
96265876a83SMatthew G. Knepley 
96365876a83SMatthew G. Knepley     // Series term
96465876a83SMatthew G. Knepley     PetscScalar aa = 0.0;
96565876a83SMatthew G. Knepley     PetscScalar p  = 0.0;
96665876a83SMatthew G. Knepley 
96765876a83SMatthew G. Knepley     for (PetscInt n=1; n < NITER+1; n++)
96865876a83SMatthew G. Knepley     {
96965876a83SMatthew G. Knepley       aa = user->zeroArray[n-1];
97065876a83SMatthew G. Knepley       p += (PetscSinReal(aa)/ (aa - PetscSinReal(aa)*PetscCosReal(aa))) * (PetscCosReal( (aa*x[0]) / a) - PetscCosReal(aa)) * PetscExpReal(-1.0*(aa*aa * c * time)/(a*a));
97165876a83SMatthew G. Knepley     }
97265876a83SMatthew G. Knepley     u[0] = ((2.0 * F) / (a*A1)) * p;
97365876a83SMatthew G. Knepley   }
97465876a83SMatthew G. Knepley   return 0;
97565876a83SMatthew G. Knepley }
97665876a83SMatthew G. Knepley 
97765876a83SMatthew G. Knepley // Time derivative of displacement
97865876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_u_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
97965876a83SMatthew G. Knepley {
98065876a83SMatthew G. Knepley 
98165876a83SMatthew G. Knepley   Parameter  *param;
98265876a83SMatthew G. Knepley   PetscErrorCode ierr;
98365876a83SMatthew G. Knepley 
98465876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
98565876a83SMatthew G. Knepley 
98665876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
98765876a83SMatthew G. Knepley 
98865876a83SMatthew G. Knepley   PetscInt NITER = user->niter;
98965876a83SMatthew G. Knepley   PetscScalar alpha = param->alpha;
99065876a83SMatthew G. Knepley   PetscScalar K_u = param->K_u;
99165876a83SMatthew G. Knepley   PetscScalar M = param->M;
99265876a83SMatthew G. Knepley   PetscScalar G = param->mu;
99365876a83SMatthew G. Knepley   PetscScalar F = param->P_0;
99465876a83SMatthew G. Knepley 
99565876a83SMatthew G. Knepley   PetscScalar K_d = K_u - alpha*alpha*M;
99665876a83SMatthew G. Knepley   PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
99765876a83SMatthew G. Knepley   PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
99865876a83SMatthew G. Knepley   PetscScalar kappa = param->k / param->mu_f;
99930602db0SMatthew G. Knepley   PetscReal   a = (user->xmax[0] - user->xmin[0]) / 2.0;
100065876a83SMatthew G. Knepley   PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
100165876a83SMatthew G. Knepley 
100265876a83SMatthew G. Knepley   // Series term
100365876a83SMatthew G. Knepley   PetscScalar A_s_t = 0.0;
100465876a83SMatthew G. Knepley   PetscScalar B_s_t = 0.0;
100565876a83SMatthew G. Knepley 
100665876a83SMatthew G. Knepley   for (PetscInt n=1; n < NITER+1; n++)
100765876a83SMatthew G. Knepley   {
100865876a83SMatthew G. Knepley     PetscReal alpha_n = user->zeroArray[n-1];
100965876a83SMatthew G. Knepley 
101065876a83SMatthew G. Knepley     A_s_t += (-1.0*alpha_n*alpha_n*c*PetscExpReal( (-1.0*alpha_n*alpha_n*time)/(a*a))*PetscSinReal( (alpha_n*x[0])/a) * PetscCosReal(alpha_n)) / ( a*a*(alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
101165876a83SMatthew G. Knepley     B_s_t += (-1.0*alpha_n*alpha_n*c*PetscExpReal( (-1.0*alpha_n*alpha_n*time)/(a*a))*PetscSinReal(  alpha_n) * PetscCosReal(alpha_n)) / ( a*a*(alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
101265876a83SMatthew G. Knepley   }
101365876a83SMatthew G. Knepley 
101465876a83SMatthew G. Knepley   u[0] = (F/G)*A_s_t - ( (F*nu_u*x[0])/(G*a))*B_s_t;
101565876a83SMatthew G. Knepley   u[1] = ( (F*x[1]*(1 - nu_u)) / (G*a))*B_s_t;
101665876a83SMatthew G. Knepley 
101765876a83SMatthew G. Knepley   return 0;
101865876a83SMatthew G. Knepley }
101965876a83SMatthew G. Knepley 
102065876a83SMatthew G. Knepley // Time derivative of trace strain
102165876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_eps_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
102265876a83SMatthew G. Knepley {
102365876a83SMatthew G. Knepley 
102465876a83SMatthew G. Knepley   Parameter  *param;
102565876a83SMatthew G. Knepley   PetscErrorCode ierr;
102665876a83SMatthew G. Knepley 
102765876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
102865876a83SMatthew G. Knepley 
102965876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
103065876a83SMatthew G. Knepley 
103165876a83SMatthew G. Knepley   PetscInt NITER = user->niter;
103265876a83SMatthew G. Knepley   PetscScalar alpha = param->alpha;
103365876a83SMatthew G. Knepley   PetscScalar K_u = param->K_u;
103465876a83SMatthew G. Knepley   PetscScalar M = param->M;
103565876a83SMatthew G. Knepley   PetscScalar G = param->mu;
103665876a83SMatthew G. Knepley   PetscScalar k = param->k;
103765876a83SMatthew G. Knepley   PetscScalar mu_f = param->mu_f;
103865876a83SMatthew G. Knepley   PetscScalar F = param->P_0;
103965876a83SMatthew G. Knepley 
104065876a83SMatthew G. Knepley   PetscScalar K_d = K_u - alpha*alpha*M;
104165876a83SMatthew G. Knepley   PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
104265876a83SMatthew G. Knepley   PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
104365876a83SMatthew G. Knepley   PetscScalar kappa = k / mu_f;
104465876a83SMatthew G. Knepley   //const PetscScalar B = (alpha*M)/(K_d + alpha*alpha * M);
104565876a83SMatthew G. Knepley 
104665876a83SMatthew G. Knepley   //const PetscScalar b = (YMAX - YMIN) / 2.0;
104730602db0SMatthew G. Knepley   PetscReal   a = (user->xmax[0] - user->xmin[0]) / 2.0;
104865876a83SMatthew G. Knepley   PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
104965876a83SMatthew G. Knepley 
105065876a83SMatthew G. Knepley   // Series term
105165876a83SMatthew G. Knepley   PetscScalar eps_As = 0.0;
105265876a83SMatthew G. Knepley   PetscScalar eps_Bs = 0.0;
105365876a83SMatthew G. Knepley   PetscScalar eps_Cs = 0.0;
105465876a83SMatthew G. Knepley 
105565876a83SMatthew G. Knepley   for (PetscInt n=1; n < NITER+1; n++)
105665876a83SMatthew G. Knepley   {
105765876a83SMatthew G. Knepley     PetscReal alpha_n = user->zeroArray[n-1];
105865876a83SMatthew G. Knepley 
105965876a83SMatthew G. Knepley     eps_As += (-1.0*alpha_n*alpha_n*alpha_n*c*PetscExpReal( (-1.0*alpha_n*alpha_n*c*time)/(a*a))*PetscCosReal(alpha_n)*PetscCosReal( (alpha_n*x[0])/a)) / ( alpha_n*alpha_n*alpha_n*(alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
106065876a83SMatthew G. Knepley     eps_Bs += (-1.0*alpha_n*alpha_n*c*PetscExpReal( (-1.0*alpha_n*alpha_n*c*time)/(a*a))*PetscSinReal(alpha_n)*PetscCosReal(alpha_n)) / (alpha_n*alpha_n * (alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
106165876a83SMatthew G. Knepley     eps_Cs += (-1.0*alpha_n*alpha_n*c*PetscExpReal( (-1.0*alpha_n*alpha_n*c*time)/(a*a))*PetscSinReal(alpha_n)*PetscCosReal(alpha_n)) / (alpha_n*alpha_n * (alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
106265876a83SMatthew G. Knepley   }
106365876a83SMatthew G. Knepley 
106465876a83SMatthew G. Knepley   u[0] = (F/G)*eps_As - ( (F*nu_u)/(G*a))*eps_Bs + ( (F*(1-nu_u))/(G*a))*eps_Cs;
106565876a83SMatthew G. Knepley   return 0;
106665876a83SMatthew G. Knepley 
106765876a83SMatthew G. Knepley }
106865876a83SMatthew G. Knepley 
106965876a83SMatthew G. Knepley // Time derivative of pressure
107065876a83SMatthew G. Knepley static PetscErrorCode mandel_2d_p_t(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
107165876a83SMatthew G. Knepley {
107265876a83SMatthew G. Knepley 
107365876a83SMatthew G. Knepley   Parameter  *param;
107465876a83SMatthew G. Knepley   PetscErrorCode ierr;
107565876a83SMatthew G. Knepley 
107665876a83SMatthew G. Knepley   AppCtx *user = (AppCtx *) ctx;
107765876a83SMatthew G. Knepley 
107865876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
107965876a83SMatthew G. Knepley 
108065876a83SMatthew G. Knepley   PetscInt NITER = user->niter;
108165876a83SMatthew G. Knepley 
108265876a83SMatthew G. Knepley   PetscScalar alpha = param->alpha;
108365876a83SMatthew G. Knepley   PetscScalar K_u = param->K_u;
108465876a83SMatthew G. Knepley   PetscScalar M = param->M;
108565876a83SMatthew G. Knepley   PetscScalar G = param->mu;
108665876a83SMatthew G. Knepley   PetscScalar k = param->k;
108765876a83SMatthew G. Knepley   PetscScalar mu_f = param->mu_f;
108865876a83SMatthew G. Knepley   PetscScalar F = param->P_0;
108965876a83SMatthew G. Knepley 
109065876a83SMatthew G. Knepley   PetscScalar K_d = K_u - alpha*alpha*M;
109165876a83SMatthew G. Knepley   PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
109265876a83SMatthew G. Knepley   PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
109365876a83SMatthew G. Knepley   PetscScalar kappa = k / mu_f;
109465876a83SMatthew G. Knepley 
109530602db0SMatthew G. Knepley   PetscReal   a = (user->xmax[0] - user->xmin[0]) / 2.0;
109665876a83SMatthew G. Knepley   PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
109765876a83SMatthew G. Knepley   //PetscScalar A1 = 3.0 / (B * (1.0 + nu_u));
109865876a83SMatthew G. Knepley   //PetscScalar A2 = (alpha * (1.0 - 2.0*nu)) / (1.0 - nu);
109965876a83SMatthew G. Knepley 
110065876a83SMatthew G. Knepley   // Series term
110165876a83SMatthew G. Knepley   PetscScalar P_s = 0.0;
110265876a83SMatthew G. Knepley 
110365876a83SMatthew G. Knepley   for (PetscInt n=1; n < NITER+1; n++)
110465876a83SMatthew G. Knepley   {
110565876a83SMatthew G. Knepley     PetscReal alpha_n = user->zeroArray[n-1];
110665876a83SMatthew G. Knepley 
110765876a83SMatthew G. Knepley     P_s += (-1.0*alpha_n*alpha_n*c*( -1.0*PetscCosReal(alpha_n) + PetscCosReal( (alpha_n*x[0])/a))*PetscExpReal( (-1.0*alpha_n*alpha_n*c*time)/(a*a))*PetscSinReal(alpha_n)) / ( a*a*(alpha_n - PetscSinReal(alpha_n)*PetscCosReal(alpha_n)));
110865876a83SMatthew G. Knepley   }
110965876a83SMatthew G. Knepley   u[0] = ( (2.0*F*(-2.0*nu + 3.0*nu_u))/(3.0*a*alpha*(1.0 - 2.0*nu)));
111065876a83SMatthew G. Knepley 
111165876a83SMatthew G. Knepley   return 0;
111265876a83SMatthew G. Knepley }
111365876a83SMatthew G. Knepley 
111465876a83SMatthew G. Knepley /* Cryer Solutions */
111565876a83SMatthew G. Knepley static PetscErrorCode cryer_drainage_pressure(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
111665876a83SMatthew G. Knepley {
111765876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
111865876a83SMatthew G. Knepley   Parameter     *param;
111965876a83SMatthew G. Knepley   PetscErrorCode ierr;
112065876a83SMatthew G. Knepley 
112165876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
112265876a83SMatthew G. Knepley   if (time <= 0.0) {
112365876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
112465876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
112565876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
112665876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
112765876a83SMatthew G. Knepley     PetscScalar B     = alpha*M / K_u; /* -, Cheng (B.12) */
112865876a83SMatthew G. Knepley 
112965876a83SMatthew G. Knepley     u[0] = P_0*B;
113065876a83SMatthew G. Knepley   } else {
113165876a83SMatthew G. Knepley     u[0] = 0.0;
113265876a83SMatthew G. Knepley   }
113365876a83SMatthew G. Knepley   return 0;
113465876a83SMatthew G. Knepley }
113565876a83SMatthew G. Knepley 
113665876a83SMatthew G. Knepley static PetscErrorCode cryer_initial_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
113765876a83SMatthew G. Knepley {
113865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
113965876a83SMatthew G. Knepley   Parameter     *param;
114065876a83SMatthew G. Knepley   PetscErrorCode ierr;
114165876a83SMatthew G. Knepley 
114265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
114365876a83SMatthew G. Knepley   {
114465876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
114565876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
114665876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
114730602db0SMatthew G. Knepley     PetscReal   R_0   = user->xmax[1];  /* m */
114865876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
114965876a83SMatthew G. Knepley 
115065876a83SMatthew G. Knepley     PetscScalar u_0   = -P_0*R_0*(1. - 2.*nu_u) / (2.*G*(1. + nu_u)); /* Cheng (7.407) */
115165876a83SMatthew G. Knepley     PetscReal   u_sc  = PetscRealPart(u_0)/R_0;
115265876a83SMatthew G. Knepley 
115365876a83SMatthew G. Knepley     u[0] = u_sc * x[0];
115465876a83SMatthew G. Knepley     u[1] = u_sc * x[1];
115565876a83SMatthew G. Knepley     u[2] = u_sc * x[2];
115665876a83SMatthew G. Knepley   }
115765876a83SMatthew G. Knepley   return 0;
115865876a83SMatthew G. Knepley }
115965876a83SMatthew G. Knepley 
116065876a83SMatthew G. Knepley static PetscErrorCode cryer_initial_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
116165876a83SMatthew G. Knepley {
116265876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
116365876a83SMatthew G. Knepley   Parameter     *param;
116465876a83SMatthew G. Knepley   PetscErrorCode ierr;
116565876a83SMatthew G. Knepley 
116665876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
116765876a83SMatthew G. Knepley   {
116865876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
116965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
117065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
117130602db0SMatthew G. Knepley     PetscReal   R_0   = user->xmax[1];  /* m */
117265876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
117365876a83SMatthew G. Knepley 
117465876a83SMatthew G. Knepley     PetscScalar u_0   = -P_0*R_0*(1. - 2.*nu_u) / (2.*G*(1. + nu_u)); /* Cheng (7.407) */
117565876a83SMatthew G. Knepley     PetscReal   u_sc  = PetscRealPart(u_0)/R_0;
117665876a83SMatthew G. Knepley 
117765876a83SMatthew G. Knepley     /* div R = 1/R^2 d/dR R^2 R = 3 */
117865876a83SMatthew G. Knepley     u[0] = 3.*u_sc;
117965876a83SMatthew G. Knepley     u[1] = 3.*u_sc;
118065876a83SMatthew G. Knepley     u[2] = 3.*u_sc;
118165876a83SMatthew G. Knepley   }
118265876a83SMatthew G. Knepley   return 0;
118365876a83SMatthew G. Knepley }
118465876a83SMatthew G. Knepley 
118565876a83SMatthew G. Knepley // Displacement
118665876a83SMatthew G. Knepley static PetscErrorCode cryer_3d_u(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
118765876a83SMatthew G. Knepley {
118865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
118965876a83SMatthew G. Knepley   Parameter     *param;
119065876a83SMatthew G. Knepley   PetscErrorCode ierr;
119165876a83SMatthew G. Knepley 
119265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
119365876a83SMatthew G. Knepley   if (time <= 0.0) {
119465876a83SMatthew G. Knepley     ierr = cryer_initial_u(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
119565876a83SMatthew G. Knepley   } else {
119665876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
119765876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
119865876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
119965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
120065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
120165876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
120230602db0SMatthew G. Knepley     PetscReal   R_0   = user->xmax[1];  /* m */
120365876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
120465876a83SMatthew G. Knepley 
120565876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
120665876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
120765876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
120865876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
120965876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
121065876a83SMatthew G. Knepley     PetscScalar u_inf = -P_0*R_0*(1. - 2.*nu) / (2.*G*(1. + nu));  /* m,       Cheng (7.388) */
121165876a83SMatthew G. Knepley 
121265876a83SMatthew G. Knepley     PetscReal   R      = PetscSqrtReal(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
121365876a83SMatthew G. Knepley     PetscReal   R_star = R/R_0;
121465876a83SMatthew G. Knepley     PetscReal   tstar  = PetscRealPart(c*time) / PetscSqr(R_0);    /* - */
121565876a83SMatthew G. Knepley     PetscReal   A_n    = 0.0;
121665876a83SMatthew G. Knepley     PetscScalar u_sc;
121765876a83SMatthew G. Knepley 
121865876a83SMatthew G. Knepley     for (n = 1; n < N+1; ++n) {
121965876a83SMatthew G. Knepley       const PetscReal x_n = user->zeroArray[n-1];
122065876a83SMatthew G. Knepley       const PetscReal E_n = PetscRealPart(PetscSqr(1 - nu)*PetscSqr(1 + nu_u)*x_n - 18.0*(1 + nu)*(nu_u - nu)*(1 - nu_u));
122165876a83SMatthew G. Knepley 
122265876a83SMatthew G. Knepley       /* m , Cheng (7.404) */
122365876a83SMatthew G. Knepley       A_n += PetscRealPart(
122465876a83SMatthew G. Knepley              (12.0*(1.0 + nu)*(nu_u - nu))/((1.0 - 2.0*nu)*E_n*PetscSqr(R_star)*x_n*PetscSinReal(PetscSqrtReal(x_n))) *
122565876a83SMatthew G. Knepley              (3.0*(nu_u - nu) * (PetscSinReal(R_star * PetscSqrtReal(x_n)) - R_star*PetscSqrtReal(x_n)*PetscCosReal(R_star * PetscSqrtReal(x_n)))
122665876a83SMatthew G. Knepley               + (1.0 - nu)*(1.0 - 2.0*nu)*PetscPowRealInt(R_star, 3)*x_n*PetscSinReal(PetscSqrtReal(x_n))) * PetscExpReal(-x_n * tstar));
122765876a83SMatthew G. Knepley     }
122865876a83SMatthew G. Knepley     u_sc = PetscRealPart(u_inf) * (R_star - A_n);
122965876a83SMatthew G. Knepley     u[0] = u_sc * x[0] / R;
123065876a83SMatthew G. Knepley     u[1] = u_sc * x[1] / R;
123165876a83SMatthew G. Knepley     u[2] = u_sc * x[2] / R;
123265876a83SMatthew G. Knepley   }
123365876a83SMatthew G. Knepley   return 0;
123465876a83SMatthew G. Knepley }
123565876a83SMatthew G. Knepley 
123665876a83SMatthew G. Knepley // Volumetric Strain
123765876a83SMatthew G. Knepley static PetscErrorCode cryer_3d_eps(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
123865876a83SMatthew G. Knepley {
123965876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
124065876a83SMatthew G. Knepley   Parameter     *param;
124165876a83SMatthew G. Knepley   PetscErrorCode ierr;
124265876a83SMatthew G. Knepley 
124365876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
124465876a83SMatthew G. Knepley   if (time <= 0.0) {
124565876a83SMatthew G. Knepley     ierr = cryer_initial_eps(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
124665876a83SMatthew G. Knepley   } else {
124765876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
124865876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
124965876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
125065876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
125165876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
125265876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
125330602db0SMatthew G. Knepley     PetscReal   R_0   = user->xmax[1];  /* m */
125465876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
125565876a83SMatthew G. Knepley 
125665876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
125765876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
125865876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
125965876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
126065876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
126165876a83SMatthew G. Knepley     PetscScalar u_inf = -P_0*R_0*(1. - 2.*nu) / (2.*G*(1. + nu));  /* m,       Cheng (7.388) */
126265876a83SMatthew G. Knepley 
126365876a83SMatthew G. Knepley     PetscReal   R      = PetscSqrtReal(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
126465876a83SMatthew G. Knepley     PetscReal   R_star = R/R_0;
126565876a83SMatthew G. Knepley     PetscReal   tstar  = PetscRealPart(c*time) / PetscSqr(R_0);    /* - */
126665876a83SMatthew G. Knepley     PetscReal   divA_n = 0.0;
126765876a83SMatthew G. Knepley 
126865876a83SMatthew G. Knepley     if (R_star < PETSC_SMALL) {
126965876a83SMatthew G. Knepley       for (n = 1; n < N+1; ++n) {
127065876a83SMatthew G. Knepley         const PetscReal x_n = user->zeroArray[n-1];
127165876a83SMatthew G. Knepley         const PetscReal E_n = PetscRealPart(PetscSqr(1 - nu)*PetscSqr(1 + nu_u)*x_n - 18.0*(1 + nu)*(nu_u - nu)*(1 - nu_u));
127265876a83SMatthew G. Knepley 
127365876a83SMatthew G. Knepley         divA_n += PetscRealPart(
127465876a83SMatthew G. Knepley                   (12.0*(1.0 + nu)*(nu_u - nu))/((1.0 - 2.0*nu)*E_n*PetscSqr(R_star)*x_n*PetscSinReal(PetscSqrtReal(x_n))) *
127565876a83SMatthew G. Knepley                   (3.0*(nu_u - nu) * PetscSqrtReal(x_n) * ((2.0 + PetscSqr(R_star*PetscSqrtReal(x_n))) - 2.0*PetscCosReal(R_star * PetscSqrtReal(x_n)))
127665876a83SMatthew G. Knepley                   + 5.0 * (1.0 - nu)*(1.0 - 2.0*nu)*PetscPowRealInt(R_star, 2)*x_n*PetscSinReal(PetscSqrtReal(x_n))) * PetscExpReal(-x_n * tstar));
127765876a83SMatthew G. Knepley       }
127865876a83SMatthew G. Knepley     } else {
127965876a83SMatthew G. Knepley       for (n = 1; n < N+1; ++n) {
128065876a83SMatthew G. Knepley         const PetscReal x_n = user->zeroArray[n-1];
128165876a83SMatthew G. Knepley         const PetscReal E_n = PetscRealPart(PetscSqr(1 - nu)*PetscSqr(1 + nu_u)*x_n - 18.0*(1 + nu)*(nu_u - nu)*(1 - nu_u));
128265876a83SMatthew G. Knepley 
128365876a83SMatthew G. Knepley         divA_n += PetscRealPart(
128465876a83SMatthew G. Knepley                   (12.0*(1.0 + nu)*(nu_u - nu))/((1.0 - 2.0*nu)*E_n*PetscSqr(R_star)*x_n*PetscSinReal(PetscSqrtReal(x_n))) *
128565876a83SMatthew G. Knepley                   (3.0*(nu_u - nu) * PetscSqrtReal(x_n) * ((2.0/(R_star*PetscSqrtReal(x_n)) + R_star*PetscSqrtReal(x_n))*PetscSinReal(R_star * PetscSqrtReal(x_n)) - 2.0*PetscCosReal(R_star * PetscSqrtReal(x_n)))
128665876a83SMatthew G. Knepley                   + 5.0 * (1.0 - nu)*(1.0 - 2.0*nu)*PetscPowRealInt(R_star, 2)*x_n*PetscSinReal(PetscSqrtReal(x_n))) * PetscExpReal(-x_n * tstar));
128765876a83SMatthew G. Knepley       }
128865876a83SMatthew G. Knepley     }
128965876a83SMatthew G. Knepley     if (PetscAbsReal(divA_n) > 1e3) PetscPrintf(PETSC_COMM_SELF, "(%g, %g, %g) divA_n: %g\n", x[0], x[1], x[2], divA_n);
129065876a83SMatthew G. Knepley     u[0] = PetscRealPart(u_inf)/R_0 * (3.0 - divA_n);
129165876a83SMatthew G. Knepley   }
129265876a83SMatthew G. Knepley   return 0;
129365876a83SMatthew G. Knepley }
129465876a83SMatthew G. Knepley 
129565876a83SMatthew G. Knepley // Pressure
129665876a83SMatthew G. Knepley static PetscErrorCode cryer_3d_p(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
129765876a83SMatthew G. Knepley {
129865876a83SMatthew G. Knepley   AppCtx        *user = (AppCtx *) ctx;
129965876a83SMatthew G. Knepley   Parameter     *param;
130065876a83SMatthew G. Knepley   PetscErrorCode ierr;
130165876a83SMatthew G. Knepley 
130265876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
130365876a83SMatthew G. Knepley   if (time <= 0.0) {
130465876a83SMatthew G. Knepley     ierr = cryer_drainage_pressure(dim, time, x, Nc, u, ctx);CHKERRQ(ierr);
130565876a83SMatthew G. Knepley   } else {
130665876a83SMatthew G. Knepley     PetscScalar alpha = param->alpha; /* -  */
130765876a83SMatthew G. Knepley     PetscScalar K_u   = param->K_u;   /* Pa */
130865876a83SMatthew G. Knepley     PetscScalar M     = param->M;     /* Pa */
130965876a83SMatthew G. Knepley     PetscScalar G     = param->mu;    /* Pa */
131065876a83SMatthew G. Knepley     PetscScalar P_0   = param->P_0;   /* Pa */
131130602db0SMatthew G. Knepley     PetscReal   R_0   = user->xmax[1];  /* m */
131265876a83SMatthew G. Knepley     PetscScalar kappa = param->k / param->mu_f;    /* m^2 / (Pa s) */
131365876a83SMatthew G. Knepley     PetscInt    N     = user->niter, n;
131465876a83SMatthew G. Knepley 
131565876a83SMatthew G. Knepley     PetscScalar K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
131665876a83SMatthew G. Knepley     PetscScalar eta   = (3.0*alpha*G) / (3.0*K_d + 4.0*G);         /* -,       Cheng (B.11) */
131765876a83SMatthew G. Knepley     PetscScalar nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
131865876a83SMatthew G. Knepley     PetscScalar nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
131965876a83SMatthew G. Knepley     PetscScalar S     = (3.0*K_u + 4.0*G) / (M*(3.0*K_d + 4.0*G)); /* Pa^{-1}, Cheng (B.14) */
132065876a83SMatthew G. Knepley     PetscScalar c     = kappa / S;                                 /* m^2 / s, Cheng (B.16) */
132165876a83SMatthew G. Knepley     PetscScalar R     = PetscSqrtReal(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
132265876a83SMatthew G. Knepley 
132365876a83SMatthew G. Knepley     PetscScalar R_star = R / R_0;
132465876a83SMatthew G. Knepley     PetscScalar t_star = PetscRealPart(c * time) / PetscSqr(R_0);
132565876a83SMatthew G. Knepley     PetscReal   A_x    = 0.0;
132665876a83SMatthew G. Knepley 
132765876a83SMatthew G. Knepley     for (n = 1; n < N+1; ++n) {
132865876a83SMatthew G. Knepley       const PetscReal x_n = user->zeroArray[n-1];
132965876a83SMatthew G. Knepley       const PetscReal E_n = PetscRealPart(PetscSqr(1 - nu)*PetscSqr(1 + nu_u)*x_n - 18.0*(1 + nu)*(nu_u - nu)*(1 - nu_u));
133065876a83SMatthew G. Knepley 
133165876a83SMatthew G. Knepley       A_x += PetscRealPart(((18.0*PetscSqr(nu_u - nu)) / (eta * E_n)) * (PetscSinReal(R_star * PetscSqrtReal(x_n)) / (R_star * PetscSinReal(PetscSqrtReal(x_n))) - 1.0) * PetscExpReal(-x_n * t_star)); /* Cheng (7.395) */
133265876a83SMatthew G. Knepley     }
133365876a83SMatthew G. Knepley     u[0] = P_0 * A_x;
133465876a83SMatthew G. Knepley   }
133565876a83SMatthew G. Knepley   return 0;
133665876a83SMatthew G. Knepley }
133765876a83SMatthew G. Knepley 
133865876a83SMatthew G. Knepley /* Boundary Kernels */
133965876a83SMatthew G. Knepley static void f0_terzaghi_bd_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
134065876a83SMatthew G. Knepley                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
134165876a83SMatthew G. Knepley                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134265876a83SMatthew G. Knepley                                     PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
134365876a83SMatthew G. Knepley {
134465876a83SMatthew G. Knepley   const PetscReal P = PetscRealPart(constants[5]);
134565876a83SMatthew G. Knepley 
134665876a83SMatthew G. Knepley   f0[0] = 0.0;
134765876a83SMatthew G. Knepley   f0[1] = P;
134865876a83SMatthew G. Knepley }
134965876a83SMatthew G. Knepley 
135045480ffeSMatthew G. Knepley #if 0
135165876a83SMatthew G. Knepley static void f0_mandel_bd_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
135265876a83SMatthew G. Knepley                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
135365876a83SMatthew G. Knepley                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135465876a83SMatthew G. Knepley                                     PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
135565876a83SMatthew G. Knepley {
135665876a83SMatthew G. Knepley   // Uniform stress distribution
135765876a83SMatthew G. Knepley   /* PetscScalar xmax =  0.5;
135865876a83SMatthew G. Knepley   PetscScalar xmin = -0.5;
135965876a83SMatthew G. Knepley   PetscScalar ymax =  0.5;
136065876a83SMatthew G. Knepley   PetscScalar ymin = -0.5;
136165876a83SMatthew G. Knepley   PetscScalar P = constants[5];
136265876a83SMatthew G. Knepley   PetscScalar aL = (xmax - xmin) / 2.0;
136365876a83SMatthew G. Knepley   PetscScalar sigma_zz = -1.0*P / aL; */
136465876a83SMatthew G. Knepley 
136565876a83SMatthew G. Knepley   // Analytical (parabolic) stress distribution
136665876a83SMatthew G. Knepley   PetscReal a1, a2, am;
136765876a83SMatthew G. Knepley   PetscReal y1, y2, ym;
136865876a83SMatthew G. Knepley 
136965876a83SMatthew G. Knepley   PetscInt NITER = 500;
137065876a83SMatthew G. Knepley   PetscReal EPS = 0.000001;
137165876a83SMatthew G. Knepley   PetscReal zeroArray[500]; /* NITER */
137265876a83SMatthew G. Knepley   PetscReal xmax =  1.0;
137365876a83SMatthew G. Knepley   PetscReal xmin =  0.0;
137465876a83SMatthew G. Knepley   PetscReal ymax =  0.1;
137565876a83SMatthew G. Knepley   PetscReal ymin =  0.0;
137665876a83SMatthew G. Knepley   PetscReal lower[2], upper[2];
137765876a83SMatthew G. Knepley 
137865876a83SMatthew G. Knepley   lower[0] = xmin - (xmax - xmin) / 2.0;
137965876a83SMatthew G. Knepley   lower[1] = ymin - (ymax - ymin) / 2.0;
138065876a83SMatthew G. Knepley   upper[0] = xmax - (xmax - xmin) / 2.0;
138165876a83SMatthew G. Knepley   upper[1] = ymax - (ymax - ymin) / 2.0;
138265876a83SMatthew G. Knepley 
138365876a83SMatthew G. Knepley   xmin = lower[0];
138465876a83SMatthew G. Knepley   ymin = lower[1];
138565876a83SMatthew G. Knepley   xmax = upper[0];
138665876a83SMatthew G. Knepley   ymax = upper[1];
138765876a83SMatthew G. Knepley 
138865876a83SMatthew G. Knepley   PetscScalar G     = constants[0];
138965876a83SMatthew G. Knepley   PetscScalar K_u   = constants[1];
139065876a83SMatthew G. Knepley   PetscScalar alpha = constants[2];
139165876a83SMatthew G. Knepley   PetscScalar M     = constants[3];
139265876a83SMatthew G. Knepley   PetscScalar kappa = constants[4];
139365876a83SMatthew G. Knepley   PetscScalar F     = constants[5];
139465876a83SMatthew G. Knepley 
139565876a83SMatthew G. Knepley   PetscScalar K_d = K_u - alpha*alpha*M;
139665876a83SMatthew G. Knepley   PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
139765876a83SMatthew G. Knepley   PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
139865876a83SMatthew G. Knepley   PetscReal   aL = (xmax - xmin) / 2.0;
139965876a83SMatthew G. Knepley   PetscReal   c = PetscRealPart(((2.0*kappa*G) * (1.0 - nu) * (nu_u - nu)) / (alpha*alpha * (1.0 - 2.0*nu) * (1.0 - nu_u)));
140065876a83SMatthew G. Knepley   PetscScalar B = (3.0 * (nu_u - nu)) / ( alpha * (1.0 - 2.0*nu) * (1.0 + nu_u));
140165876a83SMatthew G. Knepley   PetscScalar A1 = 3.0 / (B * (1.0 + nu_u));
140265876a83SMatthew G. Knepley   PetscScalar A2 = (alpha * (1.0 - 2.0*nu)) / (1.0 - nu);
140365876a83SMatthew G. Knepley 
140465876a83SMatthew G. Knepley   // Generate zero values
140565876a83SMatthew G. Knepley   for (PetscInt i=1; i < NITER+1; i++)
140665876a83SMatthew G. Knepley   {
140765876a83SMatthew G. Knepley     a1 = ((PetscReal) i - 1.0) * PETSC_PI * PETSC_PI / 4.0 + EPS;
140865876a83SMatthew G. Knepley     a2 = a1 + PETSC_PI/2;
140965876a83SMatthew G. Knepley     for (PetscInt j=0; j<NITER; j++)
141065876a83SMatthew G. Knepley     {
141165876a83SMatthew G. Knepley       y1 = PetscTanReal(a1) - PetscRealPart(A1/A2)*a1;
141265876a83SMatthew G. Knepley       y2 = PetscTanReal(a2) - PetscRealPart(A1/A2)*a2;
141365876a83SMatthew G. Knepley       am = (a1 + a2)/2.0;
141465876a83SMatthew G. Knepley       ym = PetscTanReal(am) - PetscRealPart(A1/A2)*am;
141565876a83SMatthew G. Knepley       if ((ym*y1) > 0)
141665876a83SMatthew G. Knepley       {
141765876a83SMatthew G. Knepley         a1 = am;
141865876a83SMatthew G. Knepley       } else {
141965876a83SMatthew G. Knepley         a2 = am;
142065876a83SMatthew G. Knepley       }
142165876a83SMatthew G. Knepley       if (PetscAbsReal(y2) < EPS)
142265876a83SMatthew G. Knepley       {
142365876a83SMatthew G. Knepley         am = a2;
142465876a83SMatthew G. Knepley       }
142565876a83SMatthew G. Knepley     }
142665876a83SMatthew G. Knepley     zeroArray[i-1] = am;
142765876a83SMatthew G. Knepley   }
142865876a83SMatthew G. Knepley 
142965876a83SMatthew G. Knepley   // Solution for sigma_zz
143065876a83SMatthew G. Knepley   PetscScalar A_x = 0.0;
143165876a83SMatthew G. Knepley   PetscScalar B_x = 0.0;
143265876a83SMatthew G. Knepley 
143365876a83SMatthew G. Knepley   for (PetscInt n=1; n < NITER+1; n++)
143465876a83SMatthew G. Knepley   {
143565876a83SMatthew G. Knepley     PetscReal alpha_n = zeroArray[n-1];
143665876a83SMatthew G. Knepley 
143765876a83SMatthew G. Knepley     A_x += ( PetscSinReal(alpha_n) / (alpha_n - PetscSinReal(alpha_n) * PetscCosReal(alpha_n))) * PetscCosReal( (alpha_n * x[0]) / aL) * PetscExpReal( -1.0*( (alpha_n*alpha_n*c*t)/(aL*aL)));
143865876a83SMatthew G. Knepley     B_x += ( (PetscSinReal(alpha_n) * PetscCosReal(alpha_n))/(alpha_n - PetscSinReal(alpha_n) * PetscCosReal(alpha_n))) * PetscExpReal( -1.0*( (alpha_n*alpha_n*c*t)/(aL*aL)));
143965876a83SMatthew G. Knepley   }
144065876a83SMatthew G. Knepley 
144165876a83SMatthew G. Knepley   PetscScalar sigma_zz = -1.0*(F/aL) - ((2.0*F)/aL) * (A2/A1) * A_x + ((2.0*F)/aL) * B_x;
144265876a83SMatthew G. Knepley 
144365876a83SMatthew G. Knepley   if (x[1] == ymax) {
144465876a83SMatthew G. Knepley     f0[1] += sigma_zz;
144565876a83SMatthew G. Knepley   } else if (x[1] == ymin) {
144665876a83SMatthew G. Knepley     f0[1] -= sigma_zz;
144765876a83SMatthew G. Knepley   }
144865876a83SMatthew G. Knepley }
144945480ffeSMatthew G. Knepley #endif
145065876a83SMatthew G. Knepley 
145165876a83SMatthew G. Knepley static void f0_cryer_bd_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
145265876a83SMatthew G. Knepley                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
145365876a83SMatthew G. Knepley                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
145465876a83SMatthew G. Knepley                                     PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
145565876a83SMatthew G. Knepley {
145665876a83SMatthew G. Knepley   const PetscReal P_0 = PetscRealPart(constants[5]);
14570fdc7489SMatthew Knepley   //const PetscReal R   = PetscSqrtReal(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
145865876a83SMatthew G. Knepley   PetscInt        d;
145965876a83SMatthew G. Knepley 
146065876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) f0[d] = -P_0*n[d];
146165876a83SMatthew G. Knepley   //PetscPrintf(PETSC_COMM_SELF, "R: %g P_0: %g n: (%g, %g, %g) hat n (%g, %g, %g)\n", R, P_0, n[0], n[1], n[2], x[0]/R, x[1]/R, x[2]/R);
14620fdc7489SMatthew Knepley   //for (d = 0; d < dim; ++d) if (PetscAbsReal(n[d] - x[d]/R) > 1.0) PetscPrintf(PETSC_COMM_SELF, "WTF? R: %g P_0: %g n: (%g, %g, %g) hat n (%g, %g, %g)\n", R, P_0, n[0], n[1], n[2], x[0]/R, x[1]/R, x[2]/R);
146365876a83SMatthew G. Knepley   //for (d = 0; d < dim; ++d) f0[d] = -P_0*x[d]/R;
146465876a83SMatthew G. Knepley }
146565876a83SMatthew G. Knepley 
146665876a83SMatthew G. Knepley /* Standard Kernels - Residual */
146765876a83SMatthew G. Knepley /* f0_e */
146865876a83SMatthew G. Knepley static void f0_epsilon(PetscInt dim, PetscInt Nf, PetscInt NfAux,
146965876a83SMatthew G. Knepley                        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
147065876a83SMatthew G. Knepley                        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147165876a83SMatthew G. Knepley                        PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
147265876a83SMatthew G. Knepley {
147365876a83SMatthew G. Knepley   PetscInt d;
147465876a83SMatthew G. Knepley 
147565876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
147665876a83SMatthew G. Knepley     f0[0] += u_x[d*dim+d];
147765876a83SMatthew G. Knepley   }
147865876a83SMatthew G. Knepley   f0[0] -= u[uOff[1]];
147965876a83SMatthew G. Knepley }
148065876a83SMatthew G. Knepley 
148165876a83SMatthew G. Knepley /* f0_p */
148265876a83SMatthew G. Knepley static void f0_p(PetscInt dim, PetscInt Nf, PetscInt NfAux,
148365876a83SMatthew G. Knepley                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
148465876a83SMatthew G. Knepley                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
148565876a83SMatthew G. Knepley                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
148665876a83SMatthew G. Knepley {
148765876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
148865876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
148965876a83SMatthew G. Knepley 
149065876a83SMatthew G. Knepley   f0[0] += alpha*u_t[uOff[1]];
149165876a83SMatthew G. Knepley   f0[0] += u_t[uOff[2]]/M;
149230602db0SMatthew G. Knepley   if (f0[0] != f0[0]) abort();
149365876a83SMatthew G. Knepley }
149465876a83SMatthew G. Knepley 
149565876a83SMatthew G. Knepley /* f1_u */
149665876a83SMatthew G. Knepley static void f1_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
149765876a83SMatthew G. Knepley                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
149865876a83SMatthew G. Knepley                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
149965876a83SMatthew G. Knepley                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
150065876a83SMatthew G. Knepley {
150165876a83SMatthew G. Knepley   const PetscInt  Nc     = dim;
150265876a83SMatthew G. Knepley   const PetscReal G      = PetscRealPart(constants[0]);
150365876a83SMatthew G. Knepley   const PetscReal K_u    = PetscRealPart(constants[1]);
150465876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
150565876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
150665876a83SMatthew G. Knepley   const PetscReal K_d    = K_u - alpha*alpha*M;
150765876a83SMatthew G. Knepley   const PetscReal lambda = K_d - (2.0 * G) / 3.0;
150865876a83SMatthew G. Knepley   PetscInt        c, d;
150965876a83SMatthew G. Knepley 
151065876a83SMatthew G. Knepley   for (c = 0; c < Nc; ++c)
151165876a83SMatthew G. Knepley   {
151265876a83SMatthew G. Knepley     for (d = 0; d < dim; ++d)
151365876a83SMatthew G. Knepley     {
151465876a83SMatthew G. Knepley       f1[c*dim+d] -= G*(u_x[c*dim+d] + u_x[d*dim+c]);
151565876a83SMatthew G. Knepley     }
151665876a83SMatthew G. Knepley     f1[c*dim+c] -= lambda*u[uOff[1]];
151765876a83SMatthew G. Knepley     f1[c*dim+c] += alpha*u[uOff[2]];
151865876a83SMatthew G. Knepley   }
151965876a83SMatthew G. Knepley }
152065876a83SMatthew G. Knepley 
152165876a83SMatthew G. Knepley /* f1_p */
152265876a83SMatthew G. Knepley static void f1_p(PetscInt dim, PetscInt Nf, PetscInt NfAux,
152365876a83SMatthew G. Knepley                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
152465876a83SMatthew G. Knepley                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152565876a83SMatthew G. Knepley                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
152665876a83SMatthew G. Knepley {
152765876a83SMatthew G. Knepley   const PetscReal kappa = PetscRealPart(constants[4]);
152865876a83SMatthew G. Knepley   PetscInt        d;
152965876a83SMatthew G. Knepley 
153065876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
153165876a83SMatthew G. Knepley     f1[d] += kappa*u_x[uOff_x[2]+d];
153265876a83SMatthew G. Knepley   }
153365876a83SMatthew G. Knepley }
153465876a83SMatthew G. Knepley 
153565876a83SMatthew G. Knepley /*
153665876a83SMatthew G. Knepley   \partial_df \phi_fc g_{fc,gc,df,dg} \partial_dg \phi_gc
153765876a83SMatthew G. Knepley 
153865876a83SMatthew G. Knepley   \partial_df \phi_fc \lambda \delta_{fc,df} \sum_gc \partial_dg \phi_gc \delta_{gc,dg}
153965876a83SMatthew G. Knepley   = \partial_fc \phi_fc \sum_gc \partial_gc \phi_gc
154065876a83SMatthew G. Knepley */
154165876a83SMatthew G. Knepley 
154265876a83SMatthew G. Knepley /* Standard Kernels - Jacobian */
154365876a83SMatthew G. Knepley /* g0_ee */
154465876a83SMatthew G. Knepley static void g0_ee(PetscInt dim, PetscInt Nf, PetscInt NfAux,
154565876a83SMatthew G. Knepley            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
154665876a83SMatthew G. Knepley            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154765876a83SMatthew G. Knepley            PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
154865876a83SMatthew G. Knepley {
154965876a83SMatthew G. Knepley   g0[0] = -1.0;
155065876a83SMatthew G. Knepley }
155165876a83SMatthew G. Knepley 
155265876a83SMatthew G. Knepley /* g0_pe */
155365876a83SMatthew G. Knepley static void g0_pe(PetscInt dim, PetscInt Nf, PetscInt NfAux,
155465876a83SMatthew G. Knepley            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
155565876a83SMatthew G. Knepley            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155665876a83SMatthew G. Knepley            PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
155765876a83SMatthew G. Knepley {
155865876a83SMatthew G. Knepley   const PetscReal alpha = PetscRealPart(constants[2]);
155965876a83SMatthew G. Knepley 
156065876a83SMatthew G. Knepley   g0[0] = u_tShift*alpha;
156165876a83SMatthew G. Knepley }
156265876a83SMatthew G. Knepley 
156365876a83SMatthew G. Knepley /* g0_pp */
156465876a83SMatthew G. Knepley static void g0_pp(PetscInt dim, PetscInt Nf, PetscInt NfAux,
156565876a83SMatthew G. Knepley                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
156665876a83SMatthew G. Knepley                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
156765876a83SMatthew G. Knepley                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
156865876a83SMatthew G. Knepley {
156965876a83SMatthew G. Knepley   const PetscReal M = PetscRealPart(constants[3]);
157065876a83SMatthew G. Knepley 
157165876a83SMatthew G. Knepley   g0[0] = u_tShift/M;
157265876a83SMatthew G. Knepley }
157365876a83SMatthew G. Knepley 
157465876a83SMatthew G. Knepley /* g1_eu */
157565876a83SMatthew G. Knepley static void g1_eu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
157665876a83SMatthew G. Knepley            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
157765876a83SMatthew G. Knepley            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
157865876a83SMatthew G. Knepley            PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[])
157965876a83SMatthew G. Knepley {
158065876a83SMatthew G. Knepley   PetscInt d;
158165876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) g1[d*dim+d] = 1.0; /* \frac{\partial\phi^{u_d}}{\partial x_d} */
158265876a83SMatthew G. Knepley }
158365876a83SMatthew G. Knepley 
158465876a83SMatthew G. Knepley /* g2_ue */
158565876a83SMatthew G. Knepley static void g2_ue(PetscInt dim, PetscInt Nf, PetscInt NfAux,
158665876a83SMatthew G. Knepley                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
158765876a83SMatthew G. Knepley                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
158865876a83SMatthew G. Knepley                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[])
158965876a83SMatthew G. Knepley {
159065876a83SMatthew G. Knepley   const PetscReal G      = PetscRealPart(constants[0]);
159165876a83SMatthew G. Knepley   const PetscReal K_u    = PetscRealPart(constants[1]);
159265876a83SMatthew G. Knepley   const PetscReal alpha  = PetscRealPart(constants[2]);
159365876a83SMatthew G. Knepley   const PetscReal M      = PetscRealPart(constants[3]);
159465876a83SMatthew G. Knepley   const PetscReal K_d    = K_u - alpha*alpha*M;
159565876a83SMatthew G. Knepley   const PetscReal lambda = K_d - (2.0 * G) / 3.0;
159665876a83SMatthew G. Knepley   PetscInt        d;
159765876a83SMatthew G. Knepley 
159865876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
159965876a83SMatthew G. Knepley     g2[d*dim + d] -= lambda;
160065876a83SMatthew G. Knepley   }
160165876a83SMatthew G. Knepley }
160265876a83SMatthew G. Knepley /* g2_up */
160365876a83SMatthew G. Knepley static void g2_up(PetscInt dim, PetscInt Nf, PetscInt NfAux,
160465876a83SMatthew G. Knepley                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
160565876a83SMatthew G. Knepley                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
160665876a83SMatthew G. Knepley                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[])
160765876a83SMatthew G. Knepley {
160865876a83SMatthew G. Knepley   const PetscReal alpha = PetscRealPart(constants[2]);
160965876a83SMatthew G. Knepley   PetscInt        d;
161065876a83SMatthew G. Knepley 
161165876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) {
161265876a83SMatthew G. Knepley     g2[d*dim + d] += alpha;
161365876a83SMatthew G. Knepley   }
161465876a83SMatthew G. Knepley }
161565876a83SMatthew G. Knepley 
161665876a83SMatthew G. Knepley /* g3_uu */
161765876a83SMatthew G. Knepley static void g3_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
161865876a83SMatthew G. Knepley                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
161965876a83SMatthew G. Knepley                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162065876a83SMatthew G. Knepley                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
162165876a83SMatthew G. Knepley {
162265876a83SMatthew G. Knepley   const PetscInt  Nc = dim;
162365876a83SMatthew G. Knepley   const PetscReal G  = PetscRealPart(constants[0]);
162465876a83SMatthew G. Knepley   PetscInt        c, d;
162565876a83SMatthew G. Knepley 
162665876a83SMatthew G. Knepley   for (c = 0; c < Nc; ++c) {
162765876a83SMatthew G. Knepley     for (d = 0; d < dim; ++d) {
162865876a83SMatthew G. Knepley       g3[((c*Nc + c)*dim + d)*dim + d] -= G;
162965876a83SMatthew G. Knepley       g3[((c*Nc + d)*dim + d)*dim + c] -= G;
163065876a83SMatthew G. Knepley     }
163165876a83SMatthew G. Knepley   }
163265876a83SMatthew G. Knepley }
163365876a83SMatthew G. Knepley 
163465876a83SMatthew G. Knepley /* g3_pp */
163565876a83SMatthew G. Knepley static void g3_pp(PetscInt dim, PetscInt Nf, PetscInt NfAux,
163665876a83SMatthew G. Knepley                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
163765876a83SMatthew G. Knepley                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163865876a83SMatthew G. Knepley                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
163965876a83SMatthew G. Knepley {
164065876a83SMatthew G. Knepley   const PetscReal kappa = PetscRealPart(constants[4]);
164165876a83SMatthew G. Knepley   PetscInt        d;
164265876a83SMatthew G. Knepley 
164365876a83SMatthew G. Knepley   for (d = 0; d < dim; ++d) g3[d*dim+d] += kappa;
164465876a83SMatthew G. Knepley }
164565876a83SMatthew G. Knepley 
164665876a83SMatthew G. Knepley static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
164765876a83SMatthew G. Knepley {
164865876a83SMatthew G. Knepley   PetscInt sol;
164965876a83SMatthew G. Knepley   PetscErrorCode ierr;
165065876a83SMatthew G. Knepley 
165165876a83SMatthew G. Knepley   PetscFunctionBeginUser;
165265876a83SMatthew G. Knepley   options->solType   = SOL_QUADRATIC_TRIG;
165365876a83SMatthew G. Knepley   options->niter     = 500;
165465876a83SMatthew G. Knepley   options->eps       = PETSC_SMALL;
165524b15d09SMatthew G. Knepley   options->dtInitial = -1.0;
165665876a83SMatthew G. Knepley 
165765876a83SMatthew G. Knepley   ierr = PetscOptionsBegin(comm, "", "Biot Poroelasticity Options", "DMPLEX");CHKERRQ(ierr);
165865876a83SMatthew G. Knepley   ierr = PetscOptionsInt("-niter", "Number of series term iterations in exact solutions", "ex53.c", options->niter, &options->niter, NULL);CHKERRQ(ierr);
165965876a83SMatthew G. Knepley   sol  = options->solType;
166065876a83SMatthew G. Knepley   ierr = PetscOptionsEList("-sol_type", "Type of exact solution", "ex53.c", solutionTypes, NUM_SOLUTION_TYPES, solutionTypes[options->solType], &sol, NULL);CHKERRQ(ierr);
166165876a83SMatthew G. Knepley   options->solType = (SolutionType) sol;
166265876a83SMatthew G. Knepley   ierr = PetscOptionsReal("-eps", "Precision value for root finding", "ex53.c", options->eps, &options->eps, NULL);CHKERRQ(ierr);
166324b15d09SMatthew G. Knepley   ierr = PetscOptionsReal("-dt_initial", "Override the initial timestep", "ex53.c", options->dtInitial, &options->dtInitial, NULL);CHKERRQ(ierr);
166465876a83SMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
166565876a83SMatthew G. Knepley   PetscFunctionReturn(0);
166665876a83SMatthew G. Knepley }
166765876a83SMatthew G. Knepley 
166865876a83SMatthew G. Knepley static PetscErrorCode mandelZeros(MPI_Comm comm, AppCtx *ctx, Parameter *param)
166965876a83SMatthew G. Knepley {
167065876a83SMatthew G. Knepley   //PetscBag       bag;
167165876a83SMatthew G. Knepley   PetscReal a1, a2, am;
167265876a83SMatthew G. Knepley   PetscReal y1, y2, ym;
167365876a83SMatthew G. Knepley 
167465876a83SMatthew G. Knepley   PetscFunctionBeginUser;
167565876a83SMatthew G. Knepley   //ierr = PetscBagGetData(ctx->bag, (void **) &param);CHKERRQ(ierr);
167665876a83SMatthew G. Knepley   PetscInt NITER = ctx->niter;
167765876a83SMatthew G. Knepley   PetscReal EPS = ctx->eps;
167865876a83SMatthew G. Knepley   //const PetscScalar YMAX = param->ymax;
167965876a83SMatthew G. Knepley   //const PetscScalar YMIN = param->ymin;
168065876a83SMatthew G. Knepley   PetscScalar alpha = param->alpha;
168165876a83SMatthew G. Knepley   PetscScalar K_u = param->K_u;
168265876a83SMatthew G. Knepley   PetscScalar M = param->M;
168365876a83SMatthew G. Knepley   PetscScalar G = param->mu;
168465876a83SMatthew G. Knepley   //const PetscScalar k = param->k;
168565876a83SMatthew G. Knepley   //const PetscScalar mu_f = param->mu_f;
168665876a83SMatthew G. Knepley   //const PetscScalar P_0 = param->P_0;
168765876a83SMatthew G. Knepley 
168865876a83SMatthew G. Knepley   PetscScalar K_d = K_u - alpha*alpha*M;
168965876a83SMatthew G. Knepley   PetscScalar nu = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));
169065876a83SMatthew G. Knepley   PetscScalar nu_u = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));
169165876a83SMatthew G. Knepley   //const PetscScalar kappa = k / mu_f;
169265876a83SMatthew G. Knepley 
169365876a83SMatthew G. Knepley   // Generate zero values
169465876a83SMatthew G. Knepley   for (PetscInt i=1; i < NITER+1; i++)
169565876a83SMatthew G. Knepley   {
169665876a83SMatthew G. Knepley     a1 = ((PetscReal) i - 1.0) * PETSC_PI * PETSC_PI / 4.0 + EPS;
169765876a83SMatthew G. Knepley     a2 = a1 + PETSC_PI/2;
169865876a83SMatthew G. Knepley     am = a1;
169965876a83SMatthew G. Knepley     for (PetscInt j=0; j<NITER; j++)
170065876a83SMatthew G. Knepley     {
170165876a83SMatthew G. Knepley       y1 = PetscTanReal(a1) - PetscRealPart((1.0 - nu)/(nu_u - nu))*a1;
170265876a83SMatthew G. Knepley       y2 = PetscTanReal(a2) - PetscRealPart((1.0 - nu)/(nu_u - nu))*a2;
170365876a83SMatthew G. Knepley       am = (a1 + a2)/2.0;
170465876a83SMatthew G. Knepley       ym = PetscTanReal(am) - PetscRealPart((1.0 - nu)/(nu_u - nu))*am;
170565876a83SMatthew G. Knepley       if ((ym*y1) > 0)
170665876a83SMatthew G. Knepley       {
170765876a83SMatthew G. Knepley         a1 = am;
170865876a83SMatthew G. Knepley       } else {
170965876a83SMatthew G. Knepley         a2 = am;
171065876a83SMatthew G. Knepley       }
171165876a83SMatthew G. Knepley       if (PetscAbsReal(y2) < EPS)
171265876a83SMatthew G. Knepley       {
171365876a83SMatthew G. Knepley         am = a2;
171465876a83SMatthew G. Knepley       }
171565876a83SMatthew G. Knepley     }
171665876a83SMatthew G. Knepley     ctx->zeroArray[i-1] = am;
171765876a83SMatthew G. Knepley   }
171865876a83SMatthew G. Knepley   PetscFunctionReturn(0);
171965876a83SMatthew G. Knepley }
172065876a83SMatthew G. Knepley 
172165876a83SMatthew G. Knepley static PetscReal CryerFunction(PetscReal nu_u, PetscReal nu, PetscReal x)
172265876a83SMatthew G. Knepley {
172365876a83SMatthew G. Knepley   return PetscTanReal(PetscSqrtReal(x))*(6.0*(nu_u - nu) - (1.0 - nu)*(1.0 + nu_u)*x) - (6.0*(nu_u - nu)*PetscSqrtReal(x));
172465876a83SMatthew G. Knepley }
172565876a83SMatthew G. Knepley 
172665876a83SMatthew G. Knepley static PetscErrorCode cryerZeros(MPI_Comm comm, AppCtx *ctx, Parameter *param)
172765876a83SMatthew G. Knepley {
172865876a83SMatthew G. Knepley   PetscReal   alpha = PetscRealPart(param->alpha); /* -  */
172965876a83SMatthew G. Knepley   PetscReal   K_u   = PetscRealPart(param->K_u);   /* Pa */
173065876a83SMatthew G. Knepley   PetscReal   M     = PetscRealPart(param->M);     /* Pa */
173165876a83SMatthew G. Knepley   PetscReal   G     = PetscRealPart(param->mu);    /* Pa */
173265876a83SMatthew G. Knepley   PetscInt    N     = ctx->niter, n;
173365876a83SMatthew G. Knepley 
173465876a83SMatthew G. Knepley   PetscReal   K_d   = K_u - alpha*alpha*M;                       /* Pa,      Cheng (B.5)  */
173565876a83SMatthew G. Knepley   PetscReal   nu    = (3.0*K_d - 2.0*G) / (2.0*(3.0*K_d + G));   /* -,       Cheng (B.8)  */
173665876a83SMatthew G. Knepley   PetscReal   nu_u  = (3.0*K_u - 2.0*G) / (2.0*(3.0*K_u + G));   /* -,       Cheng (B.9)  */
173765876a83SMatthew G. Knepley 
173865876a83SMatthew G. Knepley   PetscFunctionBeginUser;
173965876a83SMatthew G. Knepley   for (n = 1; n < N+1; ++n) {
174065876a83SMatthew G. Knepley     PetscReal tol = PetscPowReal(n, 1.5)*ctx->eps;
174165876a83SMatthew G. Knepley     PetscReal a1 = 0., a2 = 0., am = 0.;
174265876a83SMatthew G. Knepley     PetscReal y1, y2, ym;
174365876a83SMatthew G. Knepley     PetscInt  j, k = n-1;
174465876a83SMatthew G. Knepley 
174565876a83SMatthew G. Knepley     y1 = y2 = 1.;
174665876a83SMatthew G. Knepley     while (y1*y2 > 0) {
174765876a83SMatthew G. Knepley       ++k;
174865876a83SMatthew G. Knepley       a1 = PetscSqr(n*PETSC_PI) - k*PETSC_PI;
174965876a83SMatthew G. Knepley       a2 = PetscSqr(n*PETSC_PI) + k*PETSC_PI;
175065876a83SMatthew G. Knepley       y1 = CryerFunction(nu_u, nu, a1);
175165876a83SMatthew G. Knepley       y2 = CryerFunction(nu_u, nu, a2);
175265876a83SMatthew G. Knepley     }
175365876a83SMatthew G. Knepley     for (j = 0; j < 50000; ++j) {
175465876a83SMatthew G. Knepley       y1 = CryerFunction(nu_u, nu, a1);
175565876a83SMatthew G. Knepley       y2 = CryerFunction(nu_u, nu, a2);
175665876a83SMatthew G. Knepley       if (y1*y2 > 0) SETERRQ5(comm, PETSC_ERR_PLIB, "Invalid root finding initialization for root %D, (%g, %g)--(%g, %g)", n, a1, y1, a2, y2);
175765876a83SMatthew G. Knepley       am = (a1 + a2) / 2.0;
175865876a83SMatthew G. Knepley       ym = CryerFunction(nu_u, nu, am);
175965876a83SMatthew G. Knepley       if ((ym * y1) < 0) a2 = am;
176065876a83SMatthew G. Knepley       else               a1 = am;
176165876a83SMatthew G. Knepley       if (PetscAbsScalar(ym) < tol) break;
176265876a83SMatthew G. Knepley     }
176365876a83SMatthew G. Knepley     if (PetscAbsScalar(ym) >= tol) SETERRQ2(comm, PETSC_ERR_PLIB, "Root finding did not converge for root %D (%g)", n, PetscAbsScalar(ym));
176465876a83SMatthew G. Knepley     ctx->zeroArray[n-1] = am;
176565876a83SMatthew G. Knepley   }
176665876a83SMatthew G. Knepley   PetscFunctionReturn(0);
176765876a83SMatthew G. Knepley }
176865876a83SMatthew G. Knepley 
176965876a83SMatthew G. Knepley static PetscErrorCode SetupParameters(MPI_Comm comm, AppCtx *ctx)
177065876a83SMatthew G. Knepley {
177165876a83SMatthew G. Knepley   PetscBag       bag;
177265876a83SMatthew G. Knepley   Parameter     *p;
177365876a83SMatthew G. Knepley   PetscErrorCode ierr;
177465876a83SMatthew G. Knepley 
177565876a83SMatthew G. Knepley   PetscFunctionBeginUser;
177665876a83SMatthew G. Knepley   /* setup PETSc parameter bag */
177765876a83SMatthew G. Knepley   ierr = PetscBagGetData(ctx->bag,(void**)&p);CHKERRQ(ierr);
177865876a83SMatthew G. Knepley   ierr = PetscBagSetName(ctx->bag,"par","Poroelastic Parameters");CHKERRQ(ierr);
177965876a83SMatthew G. Knepley   bag  = ctx->bag;
178065876a83SMatthew G. Knepley   if (ctx->solType == SOL_TERZAGHI) {
178165876a83SMatthew G. Knepley     // Realistic values - Terzaghi
178265876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu,     3.0,                 "mu",    "Shear Modulus, Pa");CHKERRQ(ierr);
178365876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->K_u,    9.76,                "K_u",   "Undrained Bulk Modulus, Pa");CHKERRQ(ierr);
178465876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->alpha,  0.6,                 "alpha", "Biot Effective Stress Coefficient, -");CHKERRQ(ierr);
178565876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->M,      16.0,                "M",     "Biot Modulus, Pa");CHKERRQ(ierr);
178665876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->k,      1.5,                 "k",     "Isotropic Permeability, m**2");CHKERRQ(ierr);
178765876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu_f,   1.0,                 "mu_f",  "Fluid Dynamic Viscosity, Pa*s");CHKERRQ(ierr);
178865876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->P_0,    1.0,                 "P_0",   "Magnitude of Vertical Stress, Pa");CHKERRQ(ierr);
178965876a83SMatthew G. Knepley   } else if (ctx->solType == SOL_MANDEL) {
179065876a83SMatthew G. Knepley     // Realistic values - Mandel
179165876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu,     0.75,                "mu",    "Shear Modulus, Pa");CHKERRQ(ierr);
179265876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->K_u,    2.6941176470588233,  "K_u",   "Undrained Bulk Modulus, Pa");CHKERRQ(ierr);
179365876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->alpha,  0.6,                 "alpha", "Biot Effective Stress Coefficient, -");CHKERRQ(ierr);
179465876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->M,      4.705882352941176,   "M",     "Biot Modulus, Pa");CHKERRQ(ierr);
179565876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->k,      1.5,                 "k",     "Isotropic Permeability, m**2");CHKERRQ(ierr);
179665876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu_f,   1.0,                 "mu_f",  "Fluid Dynamic Viscosity, Pa*s");CHKERRQ(ierr);
179765876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->P_0,    1.0,                 "P_0",   "Magnitude of Vertical Stress, Pa");CHKERRQ(ierr);
179865876a83SMatthew G. Knepley   } else if (ctx->solType == SOL_CRYER) {
179965876a83SMatthew G. Knepley     // Realistic values - Mandel
180065876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu,     0.75,                "mu",    "Shear Modulus, Pa");CHKERRQ(ierr);
180165876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->K_u,    2.6941176470588233,  "K_u",   "Undrained Bulk Modulus, Pa");CHKERRQ(ierr);
180265876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->alpha,  0.6,                 "alpha", "Biot Effective Stress Coefficient, -");CHKERRQ(ierr);
180365876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->M,      4.705882352941176,   "M",     "Biot Modulus, Pa");CHKERRQ(ierr);
180465876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->k,      1.5,                 "k",     "Isotropic Permeability, m**2");CHKERRQ(ierr);
180565876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu_f,   1.0,                 "mu_f",  "Fluid Dynamic Viscosity, Pa*s");CHKERRQ(ierr);
180665876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->P_0,    1.0,                 "P_0",   "Magnitude of Vertical Stress, Pa");CHKERRQ(ierr);
180765876a83SMatthew G. Knepley   } else {
180865876a83SMatthew G. Knepley     // Nonsense values
180965876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu,     1.0,                 "mu",    "Shear Modulus, Pa");CHKERRQ(ierr);
181065876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->K_u,    1.0,                 "K_u",   "Undrained Bulk Modulus, Pa");CHKERRQ(ierr);
181165876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->alpha,  1.0,                 "alpha", "Biot Effective Stress Coefficient, -");CHKERRQ(ierr);
181265876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->M,      1.0,                 "M",     "Biot Modulus, Pa");CHKERRQ(ierr);
181365876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->k,      1.0,                 "k",     "Isotropic Permeability, m**2");CHKERRQ(ierr);
181465876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->mu_f,   1.0,                 "mu_f",  "Fluid Dynamic Viscosity, Pa*s");CHKERRQ(ierr);
181565876a83SMatthew G. Knepley     ierr = PetscBagRegisterScalar(bag, &p->P_0,    1.0,                 "P_0",   "Magnitude of Vertical Stress, Pa");CHKERRQ(ierr);
181665876a83SMatthew G. Knepley   }
181765876a83SMatthew G. Knepley   ierr = PetscBagSetFromOptions(bag);CHKERRQ(ierr);
181865876a83SMatthew G. Knepley   {
181965876a83SMatthew G. Knepley     PetscScalar K_d  = p->K_u - p->alpha*p->alpha*p->M;
182065876a83SMatthew G. Knepley     PetscScalar nu_u = (3.0*p->K_u - 2.0*p->mu) / (2.0*(3.0*p->K_u + p->mu));
182165876a83SMatthew G. Knepley     PetscScalar nu   = (3.0*K_d - 2.0*p->mu) / (2.0*(3.0*K_d + p->mu));
182265876a83SMatthew G. Knepley     PetscScalar S    = (3.0*p->K_u + 4.0*p->mu) / (p->M*(3.0*K_d + 4.0*p->mu));
182365876a83SMatthew G. Knepley     PetscReal   c    = PetscRealPart((p->k/p->mu_f) / S);
182465876a83SMatthew G. Knepley 
182565876a83SMatthew G. Knepley     PetscViewer       viewer;
182665876a83SMatthew G. Knepley     PetscViewerFormat format;
182765876a83SMatthew G. Knepley     PetscBool         flg;
182865876a83SMatthew G. Knepley 
182965876a83SMatthew G. Knepley     switch (ctx->solType) {
183065876a83SMatthew G. Knepley       case SOL_QUADRATIC_LINEAR:
183165876a83SMatthew G. Knepley       case SOL_QUADRATIC_TRIG:
183230602db0SMatthew G. Knepley       case SOL_TRIG_LINEAR: ctx->t_r = PetscSqr(ctx->xmax[0] - ctx->xmin[0])/c; break;
183330602db0SMatthew G. Knepley       case SOL_TERZAGHI:    ctx->t_r = PetscSqr(2.0*(ctx->xmax[1] - ctx->xmin[1]))/c; break;
183430602db0SMatthew G. Knepley       case SOL_MANDEL:      ctx->t_r = PetscSqr(2.0*(ctx->xmax[1] - ctx->xmin[1]))/c; break;
183530602db0SMatthew G. Knepley       case SOL_CRYER:       ctx->t_r = PetscSqr(ctx->xmax[1])/c; break;
183665876a83SMatthew G. Knepley       default: SETERRQ2(comm, PETSC_ERR_ARG_WRONG, "Invalid solution type: %s (%D)", solutionTypes[PetscMin(ctx->solType, NUM_SOLUTION_TYPES)], ctx->solType);
183765876a83SMatthew G. Knepley     }
183865876a83SMatthew G. Knepley     ierr = PetscOptionsGetViewer(comm, NULL, NULL, "-param_view", &viewer, &format, &flg);CHKERRQ(ierr);
183965876a83SMatthew G. Knepley     if (flg) {
184065876a83SMatthew G. Knepley       ierr = PetscViewerPushFormat(viewer, format);CHKERRQ(ierr);
184165876a83SMatthew G. Knepley       ierr = PetscBagView(bag, viewer);CHKERRQ(ierr);
184265876a83SMatthew G. Knepley       ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
184365876a83SMatthew G. Knepley       ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
184465876a83SMatthew G. Knepley       ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1845*1e1ea65dSPierre Jolivet       ierr = PetscPrintf(comm, "  Max displacement: %g %g\n", p->P_0*(ctx->xmax[1] - ctx->xmin[1])*(1. - 2.*nu_u)/(2.*p->mu*(1. - nu_u)), p->P_0*(ctx->xmax[1] - ctx->xmin[1])*(1. - 2.*nu)/(2.*p->mu*(1. - nu)));CHKERRQ(ierr);
1846*1e1ea65dSPierre Jolivet       ierr = PetscPrintf(comm, "  Relaxation time: %g\n", ctx->t_r);CHKERRQ(ierr);
184765876a83SMatthew G. Knepley     }
184865876a83SMatthew G. Knepley   }
184965876a83SMatthew G. Knepley   PetscFunctionReturn(0);
185065876a83SMatthew G. Knepley }
185165876a83SMatthew G. Knepley 
185265876a83SMatthew G. Knepley static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm)
185365876a83SMatthew G. Knepley {
185465876a83SMatthew G. Knepley   PetscErrorCode ierr;
185565876a83SMatthew G. Knepley 
185665876a83SMatthew G. Knepley   PetscFunctionBeginUser;
185730602db0SMatthew G. Knepley   ierr = DMCreate(comm, dm);CHKERRQ(ierr);
185830602db0SMatthew G. Knepley   ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr);
185965876a83SMatthew G. Knepley   ierr = DMSetFromOptions(*dm);CHKERRQ(ierr);
186030602db0SMatthew G. Knepley   ierr = DMSetApplicationContext(*dm, user);CHKERRQ(ierr);
186165876a83SMatthew G. Knepley   ierr = DMViewFromOptions(*dm, NULL, "-dm_view");CHKERRQ(ierr);
186230602db0SMatthew G. Knepley   ierr = DMGetBoundingBox(*dm, user->xmin, user->xmax);CHKERRQ(ierr);
186365876a83SMatthew G. Knepley   PetscFunctionReturn(0);
186465876a83SMatthew G. Knepley }
186565876a83SMatthew G. Knepley 
186665876a83SMatthew G. Knepley static PetscErrorCode SetupPrimalProblem(DM dm, AppCtx *user)
186765876a83SMatthew G. Knepley {
186865876a83SMatthew G. Knepley   PetscErrorCode (*exact[3])(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *);
186965876a83SMatthew G. Knepley   PetscErrorCode (*exact_t[3])(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *);
187045480ffeSMatthew G. Knepley   PetscDS          ds;
187145480ffeSMatthew G. Knepley   DMLabel          label;
187245480ffeSMatthew G. Knepley   PetscWeakForm    wf;
187365876a83SMatthew G. Knepley   Parameter       *param;
187465876a83SMatthew G. Knepley   PetscInt         id_mandel[2];
187565876a83SMatthew G. Knepley   PetscInt         comp[1];
187665876a83SMatthew G. Knepley   PetscInt         comp_mandel[2];
187745480ffeSMatthew G. Knepley   PetscInt         dim, id, bd, f;
187865876a83SMatthew G. Knepley   PetscErrorCode   ierr;
187965876a83SMatthew G. Knepley 
188065876a83SMatthew G. Knepley   PetscFunctionBeginUser;
188145480ffeSMatthew G. Knepley   ierr = DMGetLabel(dm, "marker", &label);CHKERRQ(ierr);
188245480ffeSMatthew G. Knepley   ierr = DMGetDS(dm, &ds);CHKERRQ(ierr);
188345480ffeSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(ds, &dim);CHKERRQ(ierr);
188465876a83SMatthew G. Knepley   ierr = PetscBagGetData(user->bag, (void **) &param);CHKERRQ(ierr);
188565876a83SMatthew G. Knepley   exact_t[0] = exact_t[1] = exact_t[2] = zero;
188665876a83SMatthew G. Knepley 
188765876a83SMatthew G. Knepley   /* Setup Problem Formulation and Boundary Conditions */
188865876a83SMatthew G. Knepley   switch (user->solType) {
188965876a83SMatthew G. Knepley   case SOL_QUADRATIC_LINEAR:
189045480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, f0_quadratic_linear_u, f1_u);CHKERRQ(ierr);
189145480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,            NULL);CHKERRQ(ierr);
189245480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_quadratic_linear_p, f1_p);CHKERRQ(ierr);
189345480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
189445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
189545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
189645480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
189745480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
189845480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe, NULL,  NULL,  NULL);CHKERRQ(ierr);
189945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp, NULL,  NULL,  g3_pp);CHKERRQ(ierr);
190065876a83SMatthew G. Knepley     exact[0]   = quadratic_u;
190165876a83SMatthew G. Knepley     exact[1]   = linear_eps;
190265876a83SMatthew G. Knepley     exact[2]   = linear_linear_p;
190365876a83SMatthew G. Knepley     exact_t[2] = linear_linear_p_t;
190465876a83SMatthew G. Knepley 
190565876a83SMatthew G. Knepley     id = 1;
190645480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall displacement", label, 1, &id, 0, 0, NULL, (void (*)(void)) exact[0], NULL, user, NULL);CHKERRQ(ierr);
190745480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall pressure",     label, 1, &id, 2, 0, NULL, (void (*)(void)) exact[2], (void (*)(void)) exact_t[2], user, NULL);CHKERRQ(ierr);
190865876a83SMatthew G. Knepley     break;
190965876a83SMatthew G. Knepley   case SOL_TRIG_LINEAR:
191045480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, f0_trig_linear_u, f1_u);CHKERRQ(ierr);
191145480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,       NULL);CHKERRQ(ierr);
191245480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_trig_linear_p, f1_p);CHKERRQ(ierr);
191345480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
191445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
191545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
191645480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
191745480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
191845480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe, NULL,  NULL,  NULL);CHKERRQ(ierr);
191945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp, NULL,  NULL,  g3_pp);CHKERRQ(ierr);
192065876a83SMatthew G. Knepley     exact[0]   = trig_u;
192165876a83SMatthew G. Knepley     exact[1]   = trig_eps;
192265876a83SMatthew G. Knepley     exact[2]   = trig_linear_p;
192365876a83SMatthew G. Knepley     exact_t[2] = trig_linear_p_t;
192465876a83SMatthew G. Knepley 
192565876a83SMatthew G. Knepley     id = 1;
192645480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall displacement", label, 1, &id, 0, 0, NULL, (void (*)(void)) exact[0], NULL, user, NULL);CHKERRQ(ierr);
192745480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall pressure",     label, 1, &id, 2, 0, NULL, (void (*)(void)) exact[2], (void (*)(void)) exact_t[2], user, NULL);CHKERRQ(ierr);
192865876a83SMatthew G. Knepley     break;
192965876a83SMatthew G. Knepley   case SOL_QUADRATIC_TRIG:
193045480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, f0_quadratic_trig_u, f1_u);CHKERRQ(ierr);
193145480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,          NULL);CHKERRQ(ierr);
193245480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_quadratic_trig_p, f1_p);CHKERRQ(ierr);
193345480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
193445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
193545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
193645480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
193745480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
193845480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe, NULL,  NULL,  NULL);CHKERRQ(ierr);
193945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp, NULL,  NULL,  g3_pp);CHKERRQ(ierr);
194065876a83SMatthew G. Knepley     exact[0]   = quadratic_u;
194165876a83SMatthew G. Knepley     exact[1]   = linear_eps;
194265876a83SMatthew G. Knepley     exact[2]   = linear_trig_p;
194365876a83SMatthew G. Knepley     exact_t[2] = linear_trig_p_t;
194465876a83SMatthew G. Knepley 
194565876a83SMatthew G. Knepley     id = 1;
194645480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall displacement", label, 1, &id, 0, 0, NULL, (void (*)(void)) exact[0], NULL, user, NULL);CHKERRQ(ierr);
194745480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "wall pressure",     label, 1, &id, 2, 0, NULL, (void (*)(void)) exact[2], (void (*)(void)) exact_t[2], user, NULL);CHKERRQ(ierr);
194865876a83SMatthew G. Knepley     break;
194965876a83SMatthew G. Knepley   case SOL_TERZAGHI:
195045480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, NULL, f1_u);CHKERRQ(ierr);
195145480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,     NULL);CHKERRQ(ierr);
195245480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_p,           f1_p);CHKERRQ(ierr);
195345480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
195445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
195545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
195645480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
195745480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
195845480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe,  NULL,  NULL,  NULL);CHKERRQ(ierr);
195945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp,  NULL,  NULL,  g3_pp);CHKERRQ(ierr);
196065876a83SMatthew G. Knepley 
196165876a83SMatthew G. Knepley     exact[0] = terzaghi_2d_u;
196265876a83SMatthew G. Knepley     exact[1] = terzaghi_2d_eps;
196365876a83SMatthew G. Knepley     exact[2] = terzaghi_2d_p;
196465876a83SMatthew G. Knepley     exact_t[0] = terzaghi_2d_u_t;
196565876a83SMatthew G. Knepley     exact_t[1] = terzaghi_2d_eps_t;
196665876a83SMatthew G. Knepley     exact_t[2] = terzaghi_2d_p_t;
196765876a83SMatthew G. Knepley 
196865876a83SMatthew G. Knepley     id = 1;
196945480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_NATURAL, "vertical stress",   label, 1, &id, 0, 0, NULL, NULL, NULL, user, &bd);CHKERRQ(ierr);
197045480ffeSMatthew G. Knepley     ierr = PetscDSGetBoundary(ds, bd, &wf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);CHKERRQ(ierr);
197106ad1575SMatthew G. Knepley     ierr = PetscWeakFormSetIndexBdResidual(wf, label, id, 0, 0, 0, f0_terzaghi_bd_u, 0, NULL);CHKERRQ(ierr);
197245480ffeSMatthew G. Knepley 
197365876a83SMatthew G. Knepley     id = 3;
197465876a83SMatthew G. Knepley     comp[0] = 1;
197545480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "fixed base",      label, 1, &id, 0, 1, comp, (void (*)(void)) zero, NULL, user, NULL);CHKERRQ(ierr);
197665876a83SMatthew G. Knepley     id = 2;
197765876a83SMatthew G. Knepley     comp[0] = 0;
197845480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "fixed side",      label, 1, &id, 0, 1, comp, (void (*)(void)) zero, NULL, user, NULL);CHKERRQ(ierr);
197965876a83SMatthew G. Knepley     id = 4;
198065876a83SMatthew G. Knepley     comp[0] = 0;
198145480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "fixed side",      label, 1, &id, 0, 1, comp, (void (*)(void)) zero, NULL, user, NULL);CHKERRQ(ierr);
198265876a83SMatthew G. Knepley     id = 1;
198345480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "drained surface", label, 1, &id, 2, 0, NULL, (void (*)(void)) terzaghi_drainage_pressure, NULL, user, NULL);CHKERRQ(ierr);
198465876a83SMatthew G. Knepley     break;
198565876a83SMatthew G. Knepley   case SOL_MANDEL:
198645480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, NULL, f1_u);CHKERRQ(ierr);
198745480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,     NULL);CHKERRQ(ierr);
198845480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_p,           f1_p);CHKERRQ(ierr);
198945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
199045480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
199145480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
199245480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
199345480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
199445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe,  NULL,  NULL,  NULL);CHKERRQ(ierr);
199545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp,  NULL,  NULL,  g3_pp);CHKERRQ(ierr);
199665876a83SMatthew G. Knepley 
199765876a83SMatthew G. Knepley     ierr = mandelZeros(PETSC_COMM_WORLD, user, param);CHKERRQ(ierr);
199865876a83SMatthew G. Knepley 
199965876a83SMatthew G. Knepley     exact[0] = mandel_2d_u;
200065876a83SMatthew G. Knepley     exact[1] = mandel_2d_eps;
200165876a83SMatthew G. Knepley     exact[2] = mandel_2d_p;
200265876a83SMatthew G. Knepley     exact_t[0] = mandel_2d_u_t;
200365876a83SMatthew G. Knepley     exact_t[1] = mandel_2d_eps_t;
200465876a83SMatthew G. Knepley     exact_t[2] = mandel_2d_p_t;
200565876a83SMatthew G. Knepley 
200665876a83SMatthew G. Knepley     id_mandel[0] = 3;
200765876a83SMatthew G. Knepley     id_mandel[1] = 1;
200865876a83SMatthew G. Knepley     //comp[0] = 1;
200965876a83SMatthew G. Knepley     comp_mandel[0] = 0;
201065876a83SMatthew G. Knepley     comp_mandel[1] = 1;
201145480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "vertical stress", label, 2, id_mandel, 0, 2, comp_mandel, (void (*)(void)) mandel_2d_u, NULL, user, NULL);CHKERRQ(ierr);
201265876a83SMatthew G. Knepley     //ierr = DMAddBoundary(dm, DM_BC_NATURAL, "vertical stress", "marker", 0, 1, comp, NULL, 2, id_mandel, user);CHKERRQ(ierr);
201365876a83SMatthew G. Knepley     //ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "fixed base", "marker", 0, 1, comp, (void (*)(void)) zero, 2, id_mandel, user);CHKERRQ(ierr);
201445480ffeSMatthew G. Knepley     //ierr = PetscDSSetBdResidual(ds, 0, f0_mandel_bd_u, NULL);CHKERRQ(ierr);
201565876a83SMatthew G. Knepley 
201665876a83SMatthew G. Knepley     id_mandel[0] = 2;
201765876a83SMatthew G. Knepley     id_mandel[1] = 4;
201845480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "drained surface", label, 2, id_mandel, 2, 0, NULL, (void (*)(void)) zero, NULL, user, NULL);CHKERRQ(ierr);
201965876a83SMatthew G. Knepley     break;
202065876a83SMatthew G. Knepley   case SOL_CRYER:
202145480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 0, NULL, f1_u);CHKERRQ(ierr);
202245480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 1, f0_epsilon,     NULL);CHKERRQ(ierr);
202345480ffeSMatthew G. Knepley     ierr = PetscDSSetResidual(ds, 2, f0_p,           f1_p);CHKERRQ(ierr);
202445480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 0, NULL,  NULL,  NULL,  g3_uu);CHKERRQ(ierr);
202545480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 1, NULL,  NULL,  g2_ue, NULL);CHKERRQ(ierr);
202645480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 0, 2, NULL,  NULL,  g2_up, NULL);CHKERRQ(ierr);
202745480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 0, NULL,  g1_eu, NULL,  NULL);CHKERRQ(ierr);
202845480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 1, 1, g0_ee, NULL,  NULL,  NULL);CHKERRQ(ierr);
202945480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 1, g0_pe,  NULL,  NULL,  NULL);CHKERRQ(ierr);
203045480ffeSMatthew G. Knepley     ierr = PetscDSSetJacobian(ds, 2, 2, g0_pp,  NULL,  NULL,  g3_pp);CHKERRQ(ierr);
203165876a83SMatthew G. Knepley 
203265876a83SMatthew G. Knepley     ierr = cryerZeros(PETSC_COMM_WORLD, user, param);CHKERRQ(ierr);
203365876a83SMatthew G. Knepley 
203465876a83SMatthew G. Knepley     exact[0] = cryer_3d_u;
203565876a83SMatthew G. Knepley     exact[1] = cryer_3d_eps;
203665876a83SMatthew G. Knepley     exact[2] = cryer_3d_p;
203765876a83SMatthew G. Knepley 
203865876a83SMatthew G. Knepley     id = 1;
203945480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_NATURAL,   "normal stress",   label, 1, &id, 0, 0, NULL, NULL,                                     NULL, user, &bd);CHKERRQ(ierr);
204045480ffeSMatthew G. Knepley     ierr = PetscDSGetBoundary(ds, bd, &wf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);CHKERRQ(ierr);
204106ad1575SMatthew G. Knepley     ierr = PetscWeakFormSetIndexBdResidual(wf, label, id, 0, 0, 0, f0_cryer_bd_u, 0, NULL);CHKERRQ(ierr);
204245480ffeSMatthew G. Knepley 
204345480ffeSMatthew G. Knepley     ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "drained surface", label, 1, &id, 2, 0, NULL, (void (*)(void)) cryer_drainage_pressure, NULL, user, NULL);CHKERRQ(ierr);
204465876a83SMatthew G. Knepley     break;
204545480ffeSMatthew G. Knepley   default: SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_WRONG, "Invalid solution type: %s (%D)", solutionTypes[PetscMin(user->solType, NUM_SOLUTION_TYPES)], user->solType);
204665876a83SMatthew G. Knepley   }
204765876a83SMatthew G. Knepley   for (f = 0; f < 3; ++f) {
204845480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolution(ds, f, exact[f], user);CHKERRQ(ierr);
204945480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolutionTimeDerivative(ds, f, exact_t[f], user);CHKERRQ(ierr);
205065876a83SMatthew G. Knepley   }
205165876a83SMatthew G. Knepley 
205265876a83SMatthew G. Knepley   /* Setup constants */
205365876a83SMatthew G. Knepley   {
205465876a83SMatthew G. Knepley     PetscScalar constants[6];
205565876a83SMatthew G. Knepley     constants[0] = param->mu;            /* shear modulus, Pa */
205665876a83SMatthew G. Knepley     constants[1] = param->K_u;           /* undrained bulk modulus, Pa */
205765876a83SMatthew G. Knepley     constants[2] = param->alpha;         /* Biot effective stress coefficient, - */
205865876a83SMatthew G. Knepley     constants[3] = param->M;             /* Biot modulus, Pa */
205965876a83SMatthew G. Knepley     constants[4] = param->k/param->mu_f; /* Darcy coefficient, m**2 / Pa*s */
206065876a83SMatthew G. Knepley     constants[5] = param->P_0;           /* Magnitude of Vertical Stress, Pa */
206145480ffeSMatthew G. Knepley     ierr = PetscDSSetConstants(ds, 6, constants);CHKERRQ(ierr);
206265876a83SMatthew G. Knepley   }
206365876a83SMatthew G. Knepley   PetscFunctionReturn(0);
206465876a83SMatthew G. Knepley }
206565876a83SMatthew G. Knepley 
20668cda7954SMatthew G. Knepley static PetscErrorCode CreateElasticityNullSpace(DM dm, PetscInt origField, PetscInt field, MatNullSpace *nullspace)
206765876a83SMatthew G. Knepley {
206865876a83SMatthew G. Knepley   PetscErrorCode ierr;
206965876a83SMatthew G. Knepley 
207065876a83SMatthew G. Knepley   PetscFunctionBegin;
20718cda7954SMatthew G. Knepley   ierr = DMPlexCreateRigidBody(dm, origField, nullspace);CHKERRQ(ierr);
207265876a83SMatthew G. Knepley   PetscFunctionReturn(0);
207365876a83SMatthew G. Knepley }
207465876a83SMatthew G. Knepley 
207530602db0SMatthew G. Knepley static PetscErrorCode SetupFE(DM dm, PetscInt Nf, PetscInt Nc[], const char *name[], PetscErrorCode (*setup)(DM, AppCtx *), void *ctx)
207665876a83SMatthew G. Knepley {
207765876a83SMatthew G. Knepley   AppCtx         *user = (AppCtx *) ctx;
207865876a83SMatthew G. Knepley   DM              cdm  = dm;
207965876a83SMatthew G. Knepley   PetscFE         fe;
208065876a83SMatthew G. Knepley   PetscQuadrature q = NULL;
208165876a83SMatthew G. Knepley   char            prefix[PETSC_MAX_PATH_LEN];
208265876a83SMatthew G. Knepley   PetscInt        dim, f;
208330602db0SMatthew G. Knepley   PetscBool       simplex;
208465876a83SMatthew G. Knepley   PetscErrorCode  ierr;
208565876a83SMatthew G. Knepley 
208665876a83SMatthew G. Knepley   PetscFunctionBegin;
208765876a83SMatthew G. Knepley   /* Create finite element */
208865876a83SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
208930602db0SMatthew G. Knepley   ierr = DMPlexIsSimplex(dm, &simplex);CHKERRQ(ierr);
209065876a83SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
209165876a83SMatthew G. Knepley     ierr = PetscSNPrintf(prefix, PETSC_MAX_PATH_LEN, "%s_", name[f]);CHKERRQ(ierr);
2092346a0eb2SMatthew Knepley     ierr = PetscFECreateDefault(PETSC_COMM_SELF, dim, Nc[f], simplex, name[f] ? prefix : NULL, -1, &fe);CHKERRQ(ierr);
209365876a83SMatthew G. Knepley     ierr = PetscObjectSetName((PetscObject) fe, name[f]);CHKERRQ(ierr);
209465876a83SMatthew G. Knepley     if (!q) {ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);}
209565876a83SMatthew G. Knepley     ierr = PetscFESetQuadrature(fe, q);CHKERRQ(ierr);
209665876a83SMatthew G. Knepley     ierr = DMSetField(dm, f, NULL, (PetscObject) fe);CHKERRQ(ierr);
209765876a83SMatthew G. Knepley     ierr = PetscFEDestroy(&fe);CHKERRQ(ierr);
209865876a83SMatthew G. Knepley   }
209965876a83SMatthew G. Knepley   ierr = DMCreateDS(dm);CHKERRQ(ierr);
210065876a83SMatthew G. Knepley   ierr = (*setup)(dm, user);CHKERRQ(ierr);
210165876a83SMatthew G. Knepley   while (cdm) {
210265876a83SMatthew G. Knepley     ierr = DMCopyDisc(dm, cdm);CHKERRQ(ierr);
210365876a83SMatthew G. Knepley     if (0) {ierr = DMSetNearNullSpaceConstructor(cdm, 0, CreateElasticityNullSpace);CHKERRQ(ierr);}
210465876a83SMatthew G. Knepley     /* TODO: Check whether the boundary of coarse meshes is marked */
210565876a83SMatthew G. Knepley     ierr = DMGetCoarseDM(cdm, &cdm);CHKERRQ(ierr);
210665876a83SMatthew G. Knepley   }
210765876a83SMatthew G. Knepley   ierr = PetscFEDestroy(&fe);CHKERRQ(ierr);
210865876a83SMatthew G. Knepley   PetscFunctionReturn(0);
210965876a83SMatthew G. Knepley }
211065876a83SMatthew G. Knepley 
211165876a83SMatthew G. Knepley static PetscErrorCode SetInitialConditions(TS ts, Vec u)
211265876a83SMatthew G. Knepley {
211365876a83SMatthew G. Knepley   DM             dm;
211465876a83SMatthew G. Knepley   PetscReal      t;
211565876a83SMatthew G. Knepley   PetscErrorCode ierr;
211665876a83SMatthew G. Knepley 
211765876a83SMatthew G. Knepley   PetscFunctionBegin;
211865876a83SMatthew G. Knepley   ierr = TSGetDM(ts, &dm);CHKERRQ(ierr);
211965876a83SMatthew G. Knepley   ierr = TSGetTime(ts, &t);CHKERRQ(ierr);
212065876a83SMatthew G. Knepley   if (t <= 0.0) {
212165876a83SMatthew G. Knepley     PetscErrorCode (*funcs[3])(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *);
212265876a83SMatthew G. Knepley     void            *ctxs[3];
212365876a83SMatthew G. Knepley     AppCtx          *ctx;
212465876a83SMatthew G. Knepley 
212565876a83SMatthew G. Knepley     ierr = DMGetApplicationContext(dm, (void **) &ctx);CHKERRQ(ierr);
212665876a83SMatthew G. Knepley     switch (ctx->solType) {
212765876a83SMatthew G. Knepley       case SOL_TERZAGHI:
212865876a83SMatthew G. Knepley         funcs[0] = terzaghi_initial_u;         ctxs[0] = ctx;
212965876a83SMatthew G. Knepley         funcs[1] = terzaghi_initial_eps;       ctxs[1] = ctx;
213065876a83SMatthew G. Knepley         funcs[2] = terzaghi_drainage_pressure; ctxs[2] = ctx;
213165876a83SMatthew G. Knepley         ierr = DMProjectFunction(dm, t, funcs, ctxs, INSERT_VALUES, u);CHKERRQ(ierr);
213265876a83SMatthew G. Knepley         break;
213365876a83SMatthew G. Knepley       case SOL_MANDEL:
213465876a83SMatthew G. Knepley         funcs[0] = mandel_initial_u;         ctxs[0] = ctx;
213565876a83SMatthew G. Knepley         funcs[1] = mandel_initial_eps;       ctxs[1] = ctx;
213665876a83SMatthew G. Knepley         funcs[2] = mandel_drainage_pressure; ctxs[2] = ctx;
213765876a83SMatthew G. Knepley         ierr = DMProjectFunction(dm, t, funcs, ctxs, INSERT_VALUES, u);CHKERRQ(ierr);
213865876a83SMatthew G. Knepley         break;
213965876a83SMatthew G. Knepley       case SOL_CRYER:
214065876a83SMatthew G. Knepley         funcs[0] = cryer_initial_u;         ctxs[0] = ctx;
214165876a83SMatthew G. Knepley         funcs[1] = cryer_initial_eps;       ctxs[1] = ctx;
214265876a83SMatthew G. Knepley         funcs[2] = cryer_drainage_pressure; ctxs[2] = ctx;
214365876a83SMatthew G. Knepley         ierr = DMProjectFunction(dm, t, funcs, ctxs, INSERT_VALUES, u);CHKERRQ(ierr);
214465876a83SMatthew G. Knepley         break;
214565876a83SMatthew G. Knepley       default:
214665876a83SMatthew G. Knepley         ierr = DMComputeExactSolution(dm, t, u, NULL);CHKERRQ(ierr);
214765876a83SMatthew G. Knepley     }
214865876a83SMatthew G. Knepley   } else {
214965876a83SMatthew G. Knepley     ierr = DMComputeExactSolution(dm, t, u, NULL);CHKERRQ(ierr);
215065876a83SMatthew G. Knepley   }
215165876a83SMatthew G. Knepley   PetscFunctionReturn(0);
215265876a83SMatthew G. Knepley }
215365876a83SMatthew G. Knepley 
215465876a83SMatthew G. Knepley /* Need to create Viewer each time because HDF5 can get corrupted */
215565876a83SMatthew G. Knepley static PetscErrorCode SolutionMonitor(TS ts, PetscInt steps, PetscReal time, Vec u, void *mctx)
215665876a83SMatthew G. Knepley {
215765876a83SMatthew G. Knepley   DM                dm;
215865876a83SMatthew G. Knepley   Vec               exact;
215965876a83SMatthew G. Knepley   PetscViewer       viewer;
216065876a83SMatthew G. Knepley   PetscViewerFormat format;
216165876a83SMatthew G. Knepley   PetscOptions      options;
216265876a83SMatthew G. Knepley   const char       *prefix;
216365876a83SMatthew G. Knepley   PetscErrorCode    ierr;
216465876a83SMatthew G. Knepley 
216565876a83SMatthew G. Knepley   PetscFunctionBegin;
216665876a83SMatthew G. Knepley   ierr = TSGetDM(ts, &dm);CHKERRQ(ierr);
216765876a83SMatthew G. Knepley   ierr = PetscObjectGetOptions((PetscObject) ts, &options);CHKERRQ(ierr);
216865876a83SMatthew G. Knepley   ierr = PetscObjectGetOptionsPrefix((PetscObject) ts, &prefix);CHKERRQ(ierr);
216965876a83SMatthew G. Knepley   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject) ts), options, prefix, "-monitor_solution", &viewer, &format, NULL);CHKERRQ(ierr);
217065876a83SMatthew G. Knepley   ierr = DMGetGlobalVector(dm, &exact);CHKERRQ(ierr);
217165876a83SMatthew G. Knepley   ierr = DMComputeExactSolution(dm, time, exact, NULL);CHKERRQ(ierr);
217265876a83SMatthew G. Knepley   ierr = DMSetOutputSequenceNumber(dm, steps, time);CHKERRQ(ierr);
217365876a83SMatthew G. Knepley   ierr = VecView(exact, viewer);CHKERRQ(ierr);
217465876a83SMatthew G. Knepley   ierr = VecView(u, viewer);CHKERRQ(ierr);
217565876a83SMatthew G. Knepley   ierr = DMRestoreGlobalVector(dm, &exact);CHKERRQ(ierr);
217665876a83SMatthew G. Knepley   {
217765876a83SMatthew G. Knepley     PetscErrorCode (**exacts)(PetscInt, PetscReal, const PetscReal x[], PetscInt, PetscScalar *u, void *ctx);
217865876a83SMatthew G. Knepley     void            **ectxs;
217965876a83SMatthew G. Knepley     PetscReal        *err;
218065876a83SMatthew G. Knepley     PetscInt          Nf, f;
218165876a83SMatthew G. Knepley 
218265876a83SMatthew G. Knepley     ierr = DMGetNumFields(dm, &Nf);CHKERRQ(ierr);
218365876a83SMatthew G. Knepley     ierr = PetscCalloc3(Nf, &exacts, Nf, &ectxs, PetscMax(1, Nf), &err);CHKERRQ(ierr);
218465876a83SMatthew G. Knepley     {
218565876a83SMatthew G. Knepley       PetscInt Nds, s;
218665876a83SMatthew G. Knepley 
218765876a83SMatthew G. Knepley       ierr = DMGetNumDS(dm, &Nds);CHKERRQ(ierr);
218865876a83SMatthew G. Knepley       for (s = 0; s < Nds; ++s) {
218965876a83SMatthew G. Knepley         PetscDS         ds;
219065876a83SMatthew G. Knepley         DMLabel         label;
219165876a83SMatthew G. Knepley         IS              fieldIS;
219265876a83SMatthew G. Knepley         const PetscInt *fields;
219365876a83SMatthew G. Knepley         PetscInt        dsNf, f;
219465876a83SMatthew G. Knepley 
219565876a83SMatthew G. Knepley         ierr = DMGetRegionNumDS(dm, s, &label, &fieldIS, &ds);CHKERRQ(ierr);
219665876a83SMatthew G. Knepley         ierr = PetscDSGetNumFields(ds, &dsNf);CHKERRQ(ierr);
219765876a83SMatthew G. Knepley         ierr = ISGetIndices(fieldIS, &fields);CHKERRQ(ierr);
219865876a83SMatthew G. Knepley         for (f = 0; f < dsNf; ++f) {
219965876a83SMatthew G. Knepley           const PetscInt field = fields[f];
220065876a83SMatthew G. Knepley           ierr = PetscDSGetExactSolution(ds, field, &exacts[field], &ectxs[field]);CHKERRQ(ierr);
220165876a83SMatthew G. Knepley         }
220265876a83SMatthew G. Knepley         ierr = ISRestoreIndices(fieldIS, &fields);CHKERRQ(ierr);
220365876a83SMatthew G. Knepley       }
220465876a83SMatthew G. Knepley     }
220565876a83SMatthew G. Knepley     ierr = DMComputeL2FieldDiff(dm, time, exacts, ectxs, u, err);CHKERRQ(ierr);
220665876a83SMatthew G. Knepley     ierr = PetscPrintf(PetscObjectComm((PetscObject) ts), "Time: %g L_2 Error: [", time);CHKERRQ(ierr);
220765876a83SMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
220865876a83SMatthew G. Knepley       if (f) {ierr = PetscPrintf(PetscObjectComm((PetscObject) ts), ", ");CHKERRQ(ierr);}
220965876a83SMatthew G. Knepley       ierr = PetscPrintf(PetscObjectComm((PetscObject) ts), "%g", (double) err[f]);CHKERRQ(ierr);
221065876a83SMatthew G. Knepley     }
221165876a83SMatthew G. Knepley     ierr = PetscPrintf(PetscObjectComm((PetscObject) ts), "]\n");CHKERRQ(ierr);
221265876a83SMatthew G. Knepley     ierr = PetscFree3(exacts, ectxs, err);CHKERRQ(ierr);
221365876a83SMatthew G. Knepley   }
221465876a83SMatthew G. Knepley   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
221565876a83SMatthew G. Knepley   PetscFunctionReturn(0);
221665876a83SMatthew G. Knepley }
221765876a83SMatthew G. Knepley 
221865876a83SMatthew G. Knepley static PetscErrorCode SetupMonitor(TS ts, AppCtx *ctx)
221965876a83SMatthew G. Knepley {
222065876a83SMatthew G. Knepley   PetscViewer       viewer;
222165876a83SMatthew G. Knepley   PetscViewerFormat format;
222265876a83SMatthew G. Knepley   PetscOptions      options;
222365876a83SMatthew G. Knepley   const char       *prefix;
222465876a83SMatthew G. Knepley   PetscBool         flg;
222565876a83SMatthew G. Knepley   PetscErrorCode    ierr;
222665876a83SMatthew G. Knepley 
222765876a83SMatthew G. Knepley   PetscFunctionBegin;
222865876a83SMatthew G. Knepley   ierr = PetscObjectGetOptions((PetscObject) ts, &options);CHKERRQ(ierr);
222965876a83SMatthew G. Knepley   ierr = PetscObjectGetOptionsPrefix((PetscObject) ts, &prefix);CHKERRQ(ierr);
223065876a83SMatthew G. Knepley   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject) ts), options, prefix, "-monitor_solution", &viewer, &format, &flg);CHKERRQ(ierr);
223165876a83SMatthew G. Knepley   if (flg) {ierr = TSMonitorSet(ts, SolutionMonitor, ctx, NULL);CHKERRQ(ierr);}
223265876a83SMatthew G. Knepley   ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
223365876a83SMatthew G. Knepley   PetscFunctionReturn(0);
223465876a83SMatthew G. Knepley }
223565876a83SMatthew G. Knepley 
223665876a83SMatthew G. Knepley static PetscErrorCode TSAdaptChoose_Terzaghi(TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
223765876a83SMatthew G. Knepley {
223865876a83SMatthew G. Knepley   static PetscReal dtTarget = -1.0;
223965876a83SMatthew G. Knepley   PetscReal        dtInitial;
224065876a83SMatthew G. Knepley   DM               dm;
224165876a83SMatthew G. Knepley   AppCtx          *ctx;
224265876a83SMatthew G. Knepley   PetscInt         step;
224365876a83SMatthew G. Knepley   PetscErrorCode   ierr;
224465876a83SMatthew G. Knepley 
224565876a83SMatthew G. Knepley   PetscFunctionBegin;
224665876a83SMatthew G. Knepley   ierr = TSGetDM(ts, &dm);CHKERRQ(ierr);
224765876a83SMatthew G. Knepley   ierr = DMGetApplicationContext(dm, (void **) &ctx);CHKERRQ(ierr);
224865876a83SMatthew G. Knepley   ierr = TSGetStepNumber(ts, &step);CHKERRQ(ierr);
224924b15d09SMatthew G. Knepley   dtInitial = ctx->dtInitial < 0.0 ? 1.0e-4*ctx->t_r : ctx->dtInitial;
225065876a83SMatthew G. Knepley   if (!step) {
225165876a83SMatthew G. Knepley     if (PetscAbsReal(dtInitial - h) > PETSC_SMALL) {
225265876a83SMatthew G. Knepley       *accept  = PETSC_FALSE;
225365876a83SMatthew G. Knepley       *next_h  = dtInitial;
225465876a83SMatthew G. Knepley       dtTarget = h;
225565876a83SMatthew G. Knepley     } else {
225665876a83SMatthew G. Knepley       *accept  = PETSC_TRUE;
225765876a83SMatthew G. Knepley       *next_h  = dtTarget < 0.0 ? dtInitial : dtTarget;
225865876a83SMatthew G. Knepley       dtTarget = -1.0;
225965876a83SMatthew G. Knepley     }
226065876a83SMatthew G. Knepley   } else {
226165876a83SMatthew G. Knepley     *accept = PETSC_TRUE;
226265876a83SMatthew G. Knepley     *next_h = h;
226365876a83SMatthew G. Knepley   }
226465876a83SMatthew G. Knepley   *next_sc = 0;  /* Reuse the same order scheme */
226565876a83SMatthew G. Knepley   *wlte    = -1; /* Weighted local truncation error was not evaluated */
226665876a83SMatthew G. Knepley   *wltea   = -1; /* Weighted absolute local truncation error was not evaluated */
226765876a83SMatthew G. Knepley   *wlter   = -1; /* Weighted relative local truncation error was not evaluated */
226865876a83SMatthew G. Knepley   PetscFunctionReturn(0);
226965876a83SMatthew G. Knepley }
227065876a83SMatthew G. Knepley 
227165876a83SMatthew G. Knepley int main(int argc, char **argv)
227265876a83SMatthew G. Knepley {
227365876a83SMatthew G. Knepley   AppCtx         ctx;       /* User-defined work context */
227465876a83SMatthew G. Knepley   DM             dm;        /* Problem specification */
227565876a83SMatthew G. Knepley   TS             ts;        /* Time Series / Nonlinear solver */
227665876a83SMatthew G. Knepley   Vec            u;         /* Solutions */
227765876a83SMatthew G. Knepley   const char    *name[3] = {"displacement", "tracestrain", "pressure"};
227865876a83SMatthew G. Knepley   PetscReal      t;
227930602db0SMatthew G. Knepley   PetscInt       dim, Nc[3];
228065876a83SMatthew G. Knepley   PetscErrorCode ierr;
228165876a83SMatthew G. Knepley 
228265876a83SMatthew G. Knepley   ierr = PetscInitialize(&argc, &argv, NULL, help);if (ierr) return ierr;
228365876a83SMatthew G. Knepley   ierr = ProcessOptions(PETSC_COMM_WORLD, &ctx);CHKERRQ(ierr);
228465876a83SMatthew G. Knepley   ierr = PetscBagCreate(PETSC_COMM_SELF, sizeof(Parameter), &ctx.bag);CHKERRQ(ierr);
228565876a83SMatthew G. Knepley   ierr = PetscMalloc1(ctx.niter, &ctx.zeroArray);CHKERRQ(ierr);
228630602db0SMatthew G. Knepley   ierr = CreateMesh(PETSC_COMM_WORLD, &ctx, &dm);CHKERRQ(ierr);
228765876a83SMatthew G. Knepley   ierr = SetupParameters(PETSC_COMM_WORLD, &ctx);CHKERRQ(ierr);
228865876a83SMatthew G. Knepley   /* Primal System */
228965876a83SMatthew G. Knepley   ierr = TSCreate(PETSC_COMM_WORLD, &ts);CHKERRQ(ierr);
229065876a83SMatthew G. Knepley   ierr = DMSetApplicationContext(dm, &ctx);CHKERRQ(ierr);
229165876a83SMatthew G. Knepley   ierr = TSSetDM(ts, dm);CHKERRQ(ierr);
229265876a83SMatthew G. Knepley 
229330602db0SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
229430602db0SMatthew G. Knepley   Nc[0] = dim;
229565876a83SMatthew G. Knepley   Nc[1] = 1;
229665876a83SMatthew G. Knepley   Nc[2] = 1;
229765876a83SMatthew G. Knepley 
229830602db0SMatthew G. Knepley   ierr = SetupFE(dm, 3, Nc, name, SetupPrimalProblem, &ctx);CHKERRQ(ierr);
229965876a83SMatthew G. Knepley   ierr = DMCreateGlobalVector(dm, &u);CHKERRQ(ierr);
230065876a83SMatthew G. Knepley   ierr = DMTSSetBoundaryLocal(dm, DMPlexTSComputeBoundary, &ctx);CHKERRQ(ierr);
230165876a83SMatthew G. Knepley   ierr = DMTSSetIFunctionLocal(dm, DMPlexTSComputeIFunctionFEM, &ctx);CHKERRQ(ierr);
230265876a83SMatthew G. Knepley   ierr = DMTSSetIJacobianLocal(dm, DMPlexTSComputeIJacobianFEM, &ctx);CHKERRQ(ierr);
230365876a83SMatthew G. Knepley   ierr = TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);CHKERRQ(ierr);
230465876a83SMatthew G. Knepley   ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
230565876a83SMatthew G. Knepley   ierr = TSSetComputeInitialCondition(ts, SetInitialConditions);CHKERRQ(ierr);
230665876a83SMatthew G. Knepley   ierr = SetupMonitor(ts, &ctx);CHKERRQ(ierr);
230765876a83SMatthew G. Knepley 
230865876a83SMatthew G. Knepley   if (ctx.solType != SOL_QUADRATIC_TRIG) {
230965876a83SMatthew G. Knepley     TSAdapt adapt;
231065876a83SMatthew G. Knepley 
231165876a83SMatthew G. Knepley     ierr = TSGetAdapt(ts, &adapt);CHKERRQ(ierr);
231265876a83SMatthew G. Knepley     adapt->ops->choose = TSAdaptChoose_Terzaghi;
231365876a83SMatthew G. Knepley   }
231465876a83SMatthew G. Knepley   if (ctx.solType == SOL_CRYER) {
231565876a83SMatthew G. Knepley     Mat          J;
231665876a83SMatthew G. Knepley     MatNullSpace sp;
231765876a83SMatthew G. Knepley 
231865876a83SMatthew G. Knepley     ierr = TSSetUp(ts);CHKERRQ(ierr);
231965876a83SMatthew G. Knepley     ierr = TSGetIJacobian(ts, &J, NULL, NULL, NULL);CHKERRQ(ierr);
232065876a83SMatthew G. Knepley     ierr = DMPlexCreateRigidBody(dm, 0, &sp);CHKERRQ(ierr);
232165876a83SMatthew G. Knepley     ierr = MatSetNullSpace(J, sp);CHKERRQ(ierr);
232265876a83SMatthew G. Knepley     ierr = MatNullSpaceDestroy(&sp);CHKERRQ(ierr);
232365876a83SMatthew G. Knepley   }
232465876a83SMatthew G. Knepley   ierr = TSGetTime(ts, &t);CHKERRQ(ierr);
232565876a83SMatthew G. Knepley   ierr = DMSetOutputSequenceNumber(dm, 0, t);CHKERRQ(ierr);
232665876a83SMatthew G. Knepley   ierr = DMTSCheckFromOptions(ts, u);CHKERRQ(ierr);
232765876a83SMatthew G. Knepley   ierr = SetInitialConditions(ts, u);CHKERRQ(ierr);
232865876a83SMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) u, "solution");CHKERRQ(ierr);
232965876a83SMatthew G. Knepley   ierr = TSSolve(ts, u);CHKERRQ(ierr);
233065876a83SMatthew G. Knepley   ierr = DMTSCheckFromOptions(ts, u);CHKERRQ(ierr);
233165876a83SMatthew G. Knepley   ierr = TSGetSolution(ts, &u);CHKERRQ(ierr);
233265876a83SMatthew G. Knepley   ierr = VecViewFromOptions(u, NULL, "-sol_vec_view");CHKERRQ(ierr);
233365876a83SMatthew G. Knepley 
233465876a83SMatthew G. Knepley   /* Cleanup */
233565876a83SMatthew G. Knepley   ierr = VecDestroy(&u);CHKERRQ(ierr);
233665876a83SMatthew G. Knepley   ierr = TSDestroy(&ts);CHKERRQ(ierr);
233765876a83SMatthew G. Knepley   ierr = DMDestroy(&dm);CHKERRQ(ierr);
233865876a83SMatthew G. Knepley   ierr = PetscBagDestroy(&ctx.bag);CHKERRQ(ierr);
233965876a83SMatthew G. Knepley   ierr = PetscFree(ctx.zeroArray);CHKERRQ(ierr);
234065876a83SMatthew G. Knepley   ierr = PetscFinalize();
234165876a83SMatthew G. Knepley   return ierr;
234265876a83SMatthew G. Knepley }
234365876a83SMatthew G. Knepley 
234465876a83SMatthew G. Knepley /*TEST
234565876a83SMatthew G. Knepley 
234665876a83SMatthew G. Knepley   test:
234765876a83SMatthew G. Knepley     suffix: 2d_quad_linear
234865876a83SMatthew G. Knepley     requires: triangle
234965876a83SMatthew G. Knepley     args: -sol_type quadratic_linear -dm_refine 2 \
235065876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
235165876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 5 -ts_monitor_extreme
235265876a83SMatthew G. Knepley 
235365876a83SMatthew G. Knepley   test:
235465876a83SMatthew G. Knepley     suffix: 3d_quad_linear
235565876a83SMatthew G. Knepley     requires: ctetgen
235630602db0SMatthew G. Knepley     args: -dm_plex_dim 3 -sol_type quadratic_linear -dm_refine 1 \
235765876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
235865876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 5 -ts_monitor_extreme
235965876a83SMatthew G. Knepley 
236065876a83SMatthew G. Knepley   test:
236165876a83SMatthew G. Knepley     suffix: 2d_trig_linear
236265876a83SMatthew G. Knepley     requires: triangle
236365876a83SMatthew G. Knepley     args: -sol_type trig_linear -dm_refine 1 \
236465876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
236565876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 5 -ts_dt 0.00001 -ts_monitor_extreme
236665876a83SMatthew G. Knepley 
236765876a83SMatthew G. Knepley   test:
236865876a83SMatthew G. Knepley     # -dm_refine 2 -convest_num_refine 3 get L_2 convergence rate: [1.9, 2.1, 1.8]
236965876a83SMatthew G. Knepley     suffix: 2d_trig_linear_sconv
237065876a83SMatthew G. Knepley     requires: triangle
237165876a83SMatthew G. Knepley     args: -sol_type trig_linear -dm_refine 1 \
237265876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
237365876a83SMatthew G. Knepley       -convest_num_refine 1 -ts_convergence_estimate -ts_convergence_temporal 0 -ts_max_steps 1 -ts_dt 0.00001 -pc_type lu
237465876a83SMatthew G. Knepley 
237565876a83SMatthew G. Knepley   test:
237665876a83SMatthew G. Knepley     suffix: 3d_trig_linear
237765876a83SMatthew G. Knepley     requires: ctetgen
237830602db0SMatthew G. Knepley     args: -dm_plex_dim 3 -sol_type trig_linear -dm_refine 1 \
237965876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
238065876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 2 -ts_monitor_extreme
238165876a83SMatthew G. Knepley 
238265876a83SMatthew G. Knepley   test:
238365876a83SMatthew G. Knepley     # -dm_refine 1 -convest_num_refine 2 gets L_2 convergence rate: [2.0, 2.1, 1.9]
238465876a83SMatthew G. Knepley     suffix: 3d_trig_linear_sconv
238565876a83SMatthew G. Knepley     requires: ctetgen
238630602db0SMatthew G. Knepley     args: -dm_plex_dim 3 -sol_type trig_linear -dm_refine 1 \
238765876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
238865876a83SMatthew G. Knepley       -convest_num_refine 1 -ts_convergence_estimate -ts_convergence_temporal 0 -ts_max_steps 1 -pc_type lu
238965876a83SMatthew G. Knepley 
239065876a83SMatthew G. Knepley   test:
239165876a83SMatthew G. Knepley     suffix: 2d_quad_trig
239265876a83SMatthew G. Knepley     requires: triangle
239365876a83SMatthew G. Knepley     args: -sol_type quadratic_trig -dm_refine 2 \
239465876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
239565876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 5 -ts_monitor_extreme
239665876a83SMatthew G. Knepley 
239765876a83SMatthew G. Knepley   test:
239865876a83SMatthew G. Knepley     # Using -dm_refine 4 gets the convergence rates to [0.95, 0.97, 0.90]
239965876a83SMatthew G. Knepley     suffix: 2d_quad_trig_tconv
240065876a83SMatthew G. Knepley     requires: triangle
240165876a83SMatthew G. Knepley     args: -sol_type quadratic_trig -dm_refine 1 \
240265876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
240365876a83SMatthew G. Knepley       -convest_num_refine 3 -ts_convergence_estimate -ts_max_steps 5 -pc_type lu
240465876a83SMatthew G. Knepley 
240565876a83SMatthew G. Knepley   test:
240665876a83SMatthew G. Knepley     suffix: 3d_quad_trig
240765876a83SMatthew G. Knepley     requires: ctetgen
240830602db0SMatthew G. Knepley     args: -dm_plex_dim 3 -sol_type quadratic_trig -dm_refine 1 \
240965876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
241065876a83SMatthew G. Knepley       -dmts_check .0001 -ts_max_steps 5 -ts_monitor_extreme
241165876a83SMatthew G. Knepley 
241265876a83SMatthew G. Knepley   test:
241365876a83SMatthew G. Knepley     # Using -dm_refine 2 -convest_num_refine 3 gets the convergence rates to [1.0, 1.0, 1.0]
241465876a83SMatthew G. Knepley     suffix: 3d_quad_trig_tconv
241565876a83SMatthew G. Knepley     requires: ctetgen
241630602db0SMatthew G. Knepley     args: -dm_plex_dim 3 -sol_type quadratic_trig -dm_refine 1 \
241765876a83SMatthew G. Knepley       -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
241865876a83SMatthew G. Knepley       -convest_num_refine 1 -ts_convergence_estimate -ts_max_steps 5 -pc_type lu
241965876a83SMatthew G. Knepley 
242030602db0SMatthew G. Knepley   testset:
242130602db0SMatthew G. Knepley     args: -sol_type terzaghi -dm_plex_simplex 0 -dm_plex_box_faces 1,8 -dm_plex_box_lower 0,0 -dm_plex_box_upper 10,10 -dm_plex_separate_marker \
242230602db0SMatthew G. Knepley           -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 -niter 16000 \
242330602db0SMatthew G. Knepley           -pc_type lu
242430602db0SMatthew G. Knepley 
242565876a83SMatthew G. Knepley     test:
242665876a83SMatthew G. Knepley       suffix: 2d_terzaghi
242730602db0SMatthew G. Knepley       requires: double
242830602db0SMatthew G. Knepley       args: -ts_dt 0.0028666667 -ts_max_steps 2 -ts_monitor -dmts_check .0001
242965876a83SMatthew G. Knepley 
243065876a83SMatthew G. Knepley     test:
243165876a83SMatthew G. Knepley       # -dm_plex_box_faces 1,64 -ts_max_steps 4 -convest_num_refine 3 gives L_2 convergence rate: [1.1, 1.1, 1.1]
243265876a83SMatthew G. Knepley       suffix: 2d_terzaghi_tconv
243330602db0SMatthew G. Knepley       args: -ts_dt 0.023 -ts_max_steps 2 -ts_convergence_estimate -convest_num_refine 1
243465876a83SMatthew G. Knepley 
243565876a83SMatthew G. Knepley     test:
243624b15d09SMatthew G. Knepley       # -dm_plex_box_faces 1,16 -convest_num_refine 4 gives L_2 convergence rate: [1.7, 1.2, 1.1]
243730602db0SMatthew G. Knepley       # if we add -displacement_petscspace_degree 3 -tracestrain_petscspace_degree 2 -pressure_petscspace_degree 2, we get [2.1, 1.6, 1.5]
243824b15d09SMatthew G. Knepley       suffix: 2d_terzaghi_sconv
243930602db0SMatthew G. Knepley       args: -ts_dt 1e-5 -dt_initial 1e-5 -ts_max_steps 2 -ts_convergence_estimate -ts_convergence_temporal 0 -convest_num_refine 1
244030602db0SMatthew G. Knepley 
244130602db0SMatthew G. Knepley   testset:
244230602db0SMatthew G. Knepley     args: -sol_type mandel -dm_plex_simplex 0 -dm_plex_box_lower -0.5,-0.125 -dm_plex_box_upper 0.5,0.125 -dm_plex_separate_marker -dm_refine 1 \
244330602db0SMatthew G. Knepley           -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1 \
244430602db0SMatthew G. Knepley           -pc_type lu
244524b15d09SMatthew G. Knepley 
244624b15d09SMatthew G. Knepley     test:
244765876a83SMatthew G. Knepley       suffix: 2d_mandel
244830602db0SMatthew G. Knepley       requires: double
244930602db0SMatthew G. Knepley       args: -ts_dt 0.0028666667 -ts_max_steps 2 -ts_monitor -dmts_check .0001
245065876a83SMatthew G. Knepley 
245165876a83SMatthew G. Knepley     test:
245265876a83SMatthew G. Knepley       # -dm_refine 5 -ts_max_steps 4 -convest_num_refine 3 gives L_2 convergence rate: [0.26, -0.0058, 0.26]
245365876a83SMatthew G. Knepley       suffix: 2d_mandel_tconv
245430602db0SMatthew G. Knepley       args: -ts_dt 0.023 -ts_max_steps 2 -ts_convergence_estimate -convest_num_refine 1
245530602db0SMatthew G. Knepley 
245630602db0SMatthew G. Knepley   testset:
245730602db0SMatthew G. Knepley     requires: ctetgen !complex
245830602db0SMatthew G. Knepley     args: -sol_type cryer -dm_plex_dim 3 -dm_plex_shape ball \
245930602db0SMatthew G. Knepley           -displacement_petscspace_degree 2 -tracestrain_petscspace_degree 1 -pressure_petscspace_degree 1
246065876a83SMatthew G. Knepley 
246165876a83SMatthew G. Knepley     test:
246265876a83SMatthew G. Knepley       suffix: 3d_cryer
246330602db0SMatthew G. Knepley       args: -ts_dt 0.0028666667 -ts_max_time 0.014333 -ts_max_steps 2 -dmts_check .0001 \
246430602db0SMatthew G. Knepley             -pc_type svd
246565876a83SMatthew G. Knepley 
246665876a83SMatthew G. Knepley     test:
246765876a83SMatthew G. Knepley       # Displacement and Pressure converge. The analytic expression for trace strain is inaccurate at the origin
246865876a83SMatthew G. Knepley       # -bd_dm_refine 3 -ref_limit 0.00666667 -ts_max_steps 5 -convest_num_refine 2 gives L_2 convergence rate: [0.47, -0.43, 1.5]
246965876a83SMatthew G. Knepley       suffix: 3d_cryer_tconv
247030602db0SMatthew G. Knepley       args: -bd_dm_refine 1 -dm_refine_volume_limit_pre 0.00666667 \
247130602db0SMatthew G. Knepley             -ts_dt 0.023 -ts_max_time 0.092 -ts_max_steps 2 -ts_convergence_estimate -convest_num_refine 1 \
247230602db0SMatthew G. Knepley             -pc_type lu -pc_factor_shift_type nonzero
247365876a83SMatthew G. Knepley 
247465876a83SMatthew G. Knepley TEST*/
2475