Skip to content

Commit 13a906e

Browse files
committed
Richards problem converged, and checked with MMS
1 parent 607ca9f commit 13a906e

18 files changed

+314
-248
lines changed

examples/Hdiv-mixed/conv_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare -A run_flags
3232
run_flags[pc_type]=svd
3333
if [[ $dim -eq 2 ]];
3434
then
35-
run_flags[problem]=darcy2d
35+
run_flags[problem]=richard2d
3636
run_flags[dm_plex_dim]=$dim
3737
run_flags[dm_plex_box_faces]=2,2
3838
else
@@ -43,8 +43,8 @@ declare -A run_flags
4343

4444
declare -A test_flags
4545
test_flags[res_start]=2
46-
test_flags[res_stride]=1
47-
test_flags[res_end]=12
46+
test_flags[res_stride]=2
47+
test_flags[res_end]=10
4848

4949
file_name=conv_test_result.csv
5050

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
run,mesh_res,error_u,error_p
2-
0,2,9.13818,0.09469
3-
1,3,4.60103,0.05186
4-
2,4,2.75883,0.03199
5-
3,5,1.81813,0.02132
6-
4,6,1.27780,0.01505
7-
5,7,0.93759,0.01108
8-
6,8,0.71073,0.00842
9-
7,9,0.55232,0.00655
10-
8,10,0.43767,0.00520
11-
9,11,0.35229,0.00418
12-
10,12,0.28723,0.00340
2+
0,2,8.22730,0.00852
3+
1,4,2.50219,0.00291
4+
2,6,1.60805,0.00181
5+
3,8,1.02228,0.00114
6+
4,10,0.70467,0.00078
-1.28 KB
Loading

examples/Hdiv-mixed/include/setup-solvers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ PetscErrorCode PDESolver(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data,
1919
VecType vec_type, SNES snes, KSP ksp, Vec *U);
2020
PetscErrorCode ComputeL2Error(DM dm, Ceed ceed, CeedData ceed_data, Vec U,
2121
CeedScalar *l2_error_u, CeedScalar *l2_error_p);
22-
PetscErrorCode PrintOutput(Ceed ceed,
22+
PetscErrorCode PrintOutput(Ceed ceed, AppCtx app_ctx, PetscBool has_ts,
2323
CeedMemType mem_type_backend,
24-
SNES snes, KSP ksp,
24+
TS ts, SNES snes, KSP ksp,
2525
Vec U, CeedScalar l2_error_u,
26-
CeedScalar l2_error_p, AppCtx app_ctx);
26+
CeedScalar l2_error_p);
2727

2828
#endif // setup_solvers_h

examples/Hdiv-mixed/include/setup-ts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm, Ceed ceed,
2020
PetscErrorCode TSFormIResidual(TS ts, PetscReal time, Vec X, Vec X_t, Vec Y,
2121
void *ctx_residual_ut);
2222
PetscErrorCode TSSolveRichard(DM dm, CeedData ceed_data, AppCtx app_ctx,
23-
Vec *U, PetscScalar *f_time, TS *ts);
23+
Vec *U, TS *ts);
2424

2525
#endif // setup_ts_h

examples/Hdiv-mixed/include/structs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ struct AppCtx_ {
1818
// Problem type arguments
1919
PetscFunctionList problems;
2020
char problem_name[PETSC_MAX_PATH_LEN];
21-
CeedContextFieldLabel solution_time_label;
22-
CeedScalar t_final;
21+
CeedScalar t_final, t;
2322
};
2423

2524
// PETSc operator contexts
@@ -31,8 +30,9 @@ struct OperatorApplyContext_ {
3130
CeedOperator op_apply;
3231
DM dm;
3332
Ceed ceed;
34-
CeedScalar t;
35-
CeedContextFieldLabel solution_time_label, final_time_label;
33+
CeedScalar t, dt;
34+
CeedContextFieldLabel solution_time_label, final_time_label,
35+
timestep_label; ;
3636
};
3737

3838
// libCEED data struct

examples/Hdiv-mixed/main.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ int main(int argc, char **argv) {
136136
//PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
137137
// bc_pressure) );
138138

139-
140139
// ---------------------------------------------------------------------------
141140
// Setup TSSolve for Richard problem
142141
// ---------------------------------------------------------------------------
142+
TS ts;
143143
if (problem_data->has_ts) {
144144
// ---------------------------------------------------------------------------
145145
// Create global initial conditions
@@ -154,46 +154,49 @@ int main(int argc, char **argv) {
154154
ceed_data->ctx_initial_u0,
155155
ceed_data->ctx_initial_p0,
156156
ceed_data->ctx_residual_ut);
157-
VecView(U, PETSC_VIEWER_STDOUT_WORLD);
157+
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);
158+
// Solve Richards problem
159+
PetscCall( VecZeroEntries(ceed_data->ctx_residual_ut->X_loc) );
160+
PetscCall( VecZeroEntries(ceed_data->ctx_residual_ut->X_t_loc) );
161+
PetscCall( TSSolveRichard(dm, ceed_data, app_ctx,
162+
&U, &ts) );
163+
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);
158164
}
159165

166+
SNES snes;
167+
KSP ksp;
160168
if (!problem_data->has_ts) {
161169
// ---------------------------------------------------------------------------
162-
// Solve PDE
170+
// Setup SNES for Darcy problem
163171
// ---------------------------------------------------------------------------
164172
// Create SNES
165-
SNES snes;
166-
KSP ksp;
167173
PetscCall( SNESCreate(comm, &snes) );
168174
PetscCall( SNESGetKSP(snes, &ksp) );
169175
PetscCall( PDESolver(comm, dm, ceed, ceed_data, vec_type, snes, ksp, &U) );
170176
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);
177+
}
171178

172-
// ---------------------------------------------------------------------------
173-
// Compute L2 error of mms problem
174-
// ---------------------------------------------------------------------------
175-
CeedScalar l2_error_u, l2_error_p;
176-
PetscCall( ComputeL2Error(dm, ceed,ceed_data, U, &l2_error_u,
177-
&l2_error_p) );
178-
179-
// ---------------------------------------------------------------------------
180-
// Print output results
181-
// ---------------------------------------------------------------------------
182-
PetscCall( PrintOutput(ceed, mem_type_backend,
183-
snes, ksp, U, l2_error_u, l2_error_p, app_ctx) );
184-
185-
// ---------------------------------------------------------------------------
186-
// Save solution (paraview)
187-
// ---------------------------------------------------------------------------
188-
PetscViewer viewer;
179+
// ---------------------------------------------------------------------------
180+
// Compute L2 error of mms problem
181+
// ---------------------------------------------------------------------------
182+
CeedScalar l2_error_u, l2_error_p;
183+
PetscCall( ComputeL2Error(dm, ceed, ceed_data, U, &l2_error_u,
184+
&l2_error_p) );
189185

190-
PetscCall( PetscViewerVTKOpen(comm,"solution.vtu",FILE_MODE_WRITE,&viewer) );
191-
PetscCall( VecView(U, viewer) );
192-
PetscCall( PetscViewerDestroy(&viewer) );
186+
// ---------------------------------------------------------------------------
187+
// Print output results
188+
// ---------------------------------------------------------------------------
189+
PetscCall( PrintOutput(ceed, app_ctx, problem_data->has_ts, mem_type_backend,
190+
ts, snes, ksp, U, l2_error_u, l2_error_p) );
193191

194-
PetscCall( SNESDestroy(&snes) );
192+
// ---------------------------------------------------------------------------
193+
// Save solution (paraview)
194+
// ---------------------------------------------------------------------------
195+
PetscViewer viewer;
196+
PetscCall( PetscViewerVTKOpen(comm,"solution.vtu",FILE_MODE_WRITE,&viewer) );
197+
PetscCall( VecView(U, viewer) );
198+
PetscCall( PetscViewerDestroy(&viewer) );
195199

196-
}
197200
// ---------------------------------------------------------------------------
198201
// Free objects
199202
// ---------------------------------------------------------------------------
@@ -203,6 +206,11 @@ int main(int argc, char **argv) {
203206
PetscCall( DMDestroy(&dm_u0) );
204207
PetscCall( DMDestroy(&dm_p0) );
205208
PetscCall( VecDestroy(&U) );
209+
if (problem_data->has_ts) {
210+
PetscCall( TSDestroy(&ts) );
211+
} else {
212+
PetscCall( SNESDestroy(&snes) );
213+
}
206214
PetscCall( CeedDataDestroy(ceed_data, problem_data) );
207215

208216
// -- Function list

examples/Hdiv-mixed/problems/darcy2d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, void *ctx) {
5454
// ------------------------------------------------------
5555
// Command line Options
5656
// ------------------------------------------------------
57-
CeedScalar kappa = 1., rho_a0 = 998.2, g = 9.8, alpha_a = 1., b_a = 10.;
57+
CeedScalar kappa = 10., rho_a0 = 998.2, g = 9.8, alpha_a = 1., b_a = 10.;
5858
PetscOptionsBegin(app_ctx->comm, NULL, "Options for Hdiv-mixed problem", NULL);
5959
PetscCall( PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL,
6060
kappa, &kappa, NULL));

examples/Hdiv-mixed/problems/richard2d.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "../qfunctions/richard-system2d.h"
2222
#include "../qfunctions/richard-true2d.h"
2323
#include "../qfunctions/richard-ics2d.h"
24+
#include "../qfunctions/darcy-error2d.h"
2425
//#include "../qfunctions/pressure-boundary2d.h"
2526
#include "petscsystypes.h"
2627

@@ -50,14 +51,12 @@ PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, void *ctx) {
5051
problem_data->rhs_p0_loc = RichardRhsP02D_loc;
5152
problem_data->ics_p = RichardICsP2D;
5253
problem_data->ics_p_loc = RichardICsP2D_loc;
53-
//problem_data->ics_p = RichardICsP2D;
54-
//problem_data->ics_p_loc = RichardICsP2D_loc;
55-
//problem_data->residual = RichardSystem2D;
56-
//problem_data->residual_loc = RichardSystem2D_loc;
54+
problem_data->residual = RichardSystem2D;
55+
problem_data->residual_loc = RichardSystem2D_loc;
5756
//problem_data->jacobian = JacobianRichardSystem2D;
5857
//problem_data->jacobian_loc = JacobianRichardSystem2D_loc;
59-
//problem_data->error = DarcyError2D;
60-
//problem_data->error_loc = DarcyError2D_loc;
58+
problem_data->error = DarcyError2D;
59+
problem_data->error_loc = DarcyError2D_loc;
6160
//problem_data->bc_pressure = BCPressure2D;
6261
//problem_data->bc_pressure_loc = BCPressure2D_loc;
6362
problem_data->has_ts = PETSC_TRUE;
@@ -81,7 +80,7 @@ PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, void *ctx) {
8180
rho_a0, &rho_a0, NULL));
8281
PetscCall( PetscOptionsScalar("-beta", "Water compressibility", NULL,
8382
beta, &beta, NULL));
84-
app_ctx->t_final = 5.;
83+
app_ctx->t_final = 0.5;
8584
PetscCall( PetscOptionsScalar("-t_final", "End time", NULL,
8685
app_ctx->t_final, &app_ctx->t_final, NULL));
8786
PetscOptionsEnd();
@@ -105,10 +104,15 @@ PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, void *ctx) {
105104
offsetof(struct RICHARDContext_, t), 1, "current solver time");
106105
CeedQFunctionContextRegisterDouble(richard_context, "final_time",
107106
offsetof(struct RICHARDContext_, t_final), 1, "final time");
107+
CeedQFunctionContextRegisterDouble(richard_context, "time_step",
108+
offsetof(struct RICHARDContext_, dt), 1, "time step");
108109
problem_data->true_qfunction_ctx = richard_context;
109110
CeedQFunctionContextReferenceCopy(richard_context,
110111
&problem_data->rhs_u0_qfunction_ctx);
111-
112+
CeedQFunctionContextReferenceCopy(richard_context,
113+
&problem_data->residual_qfunction_ctx);
114+
CeedQFunctionContextReferenceCopy(richard_context,
115+
&problem_data->error_qfunction_ctx);
112116
PetscCall( PetscFree(richard_ctx) );
113117

114118
PetscFunctionReturn(0);

examples/Hdiv-mixed/qfunctions/darcy-system2d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ CEED_QFUNCTION(JacobianDarcySystem2D)(void *ctx, CeedInt Q,
172172

173173
// *INDENT-ON*
174174
DARCYContext context = (DARCYContext)ctx;
175-
const CeedScalar kappa = context->kappa;
175+
const CeedScalar kappa = context->kappa;
176176
const CeedScalar rho_a0 = context->rho_a0;
177177
const CeedScalar g = context->g;
178178
const CeedScalar alpha_a = context->alpha_a;

examples/Hdiv-mixed/qfunctions/darcy-true2d.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,20 @@ CEED_QFUNCTION(DarcyTrue2D)(void *ctx, const CeedInt Q,
7777
CeedScalar x = coords[i+0*Q], y = coords[i+1*Q];
7878
CeedScalar psi = sin(PI_DOUBLE*x)*sin(PI_DOUBLE*y);
7979
CeedScalar psi_x = PI_DOUBLE*cos(PI_DOUBLE*x)*sin(PI_DOUBLE*y);
80+
CeedScalar psi_xx = -PI_DOUBLE*PI_DOUBLE*psi;
8081
CeedScalar psi_y = PI_DOUBLE*sin(PI_DOUBLE*x)*cos(PI_DOUBLE*y);
81-
82+
CeedScalar psi_yy = -PI_DOUBLE*PI_DOUBLE*psi;
8283
// k_r = b_a + alpha_a * (1 - x*y)
8384
CeedScalar k_r = b_a + alpha_a*(1-x*y);
85+
CeedScalar k_rx = -alpha_a*y;
86+
CeedScalar k_ry = -alpha_a*x;
8487
// rho = rho_a/rho_a0
8588
CeedScalar rho = 1.;
8689
// u = -rho*k_r*K *[grad(\psi) - rho*g_u]
87-
CeedScalar u[2] = {-rho*k_r*kappa*psi_x, -rho*k_r*kappa*(psi_y-1)};
88-
CeedScalar div_u = -rho*kappa*(-alpha_a*y*psi_x - k_r*PI_DOUBLE*PI_DOUBLE*psi
89-
-alpha_a*x*psi_y - k_r*PI_DOUBLE*PI_DOUBLE*psi);
90-
90+
CeedScalar u[2] = {-rho*kappa*k_r*psi_x,
91+
-rho*kappa*k_r*(psi_y-1)};
92+
CeedScalar div_u = -rho*kappa*(k_rx*psi_x + k_r*psi_xx +
93+
k_ry*(psi_y-1) + k_r*psi_yy);
9194
// True Force: f = \div(u)
9295
true_force[i+0*Q] = div_u;
9396
// True Solution

examples/Hdiv-mixed/qfunctions/darcy-true3d.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ CEED_QFUNCTION(DarcyTrue3D)(void *ctx, const CeedInt Q,
7777
CeedScalar x = coords[i+0*Q], y = coords[i+1*Q], z = coords[i+2*Q];
7878
CeedScalar psi = sin(PI_DOUBLE*x) * sin(PI_DOUBLE*y) * sin(PI_DOUBLE*z);
7979
CeedScalar psi_x = PI_DOUBLE*cos(PI_DOUBLE*x) *sin(PI_DOUBLE*y) *sin(PI_DOUBLE*z);
80+
CeedScalar psi_xx = -PI_DOUBLE*PI_DOUBLE*psi;
8081
CeedScalar psi_y = PI_DOUBLE*sin(PI_DOUBLE*x) *cos(PI_DOUBLE*y) *sin(PI_DOUBLE*z);
82+
CeedScalar psi_yy = -PI_DOUBLE*PI_DOUBLE*psi;
8183
CeedScalar psi_z = PI_DOUBLE*sin(PI_DOUBLE*x) *sin(PI_DOUBLE*y) *cos(PI_DOUBLE*z);
84+
CeedScalar psi_zz = -PI_DOUBLE*PI_DOUBLE*psi;
8285

8386
// k_r = b_a + alpha_a * (psi - x2)
8487
CeedScalar k_r = b_a + alpha_a*(1-x*y*z);
88+
CeedScalar k_rx = -alpha_a*y*z;
89+
CeedScalar k_ry = -alpha_a*x*z;
90+
CeedScalar k_rz = -alpha_a*x*y;
8591
// rho = rho_a/rho_a0
8692
CeedScalar rho = 1.;
8793
// u = -rho*k_r*K *[grad(\psi) - rho*g_u]
88-
CeedScalar u[3] = {-rho*k_r*kappa*psi_x,
89-
-rho*k_r*kappa*psi_y,
90-
-rho*k_r*kappa*(psi_z-1)};
91-
CeedScalar div_u = -rho*kappa*(-alpha_a*y*z*psi_x - k_r*PI_DOUBLE*PI_DOUBLE*psi
92-
-alpha_a*x*z*psi_y - k_r*PI_DOUBLE*PI_DOUBLE*psi
93-
-alpha_a*x*y*psi_z - k_r*PI_DOUBLE*PI_DOUBLE*psi);
94+
CeedScalar u[3] = {-rho*kappa*k_r*psi_x,
95+
-rho*kappa*k_r*psi_y,
96+
-rho*kappa*k_r*(psi_z-1)};
97+
CeedScalar div_u = -rho*kappa*(k_rx*psi_x + k_r*psi_xx +
98+
k_ry*psi_y + k_r*psi_yy +
99+
k_rz*(psi_z-1) + k_r*psi_zz);
94100

95101
// True Force: f = \div(u)
96102
true_force[i+0*Q] = div_u;

examples/Hdiv-mixed/qfunctions/richard-ics2d.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct RICHARDContext_ {
6666
CeedScalar rho_a0;
6767
CeedScalar alpha_a, b_a;
6868
CeedScalar beta, p0;
69-
CeedScalar t, t_final;
69+
CeedScalar t, t_final, dt;
7070
CeedScalar gamma;
7171
};
7272
#endif
@@ -105,8 +105,9 @@ CEED_QFUNCTION(RichardRhsU02D)(void *ctx, const CeedInt Q,
105105
CeedScalar k_r = b_a + alpha_a*(1-x*y);
106106
// rho = rho_a/rho_a0
107107
CeedScalar rho = 1.;
108-
// ue = -rho*k_r*K *[grad(\psi) - rho*g_u]
109-
CeedScalar ue[2] = {-rho*k_r*kappa*psi1_x, -rho*k_r*kappa*(psi1_y-1)};
108+
// ue = -rho*k_r*K *[grad(\psi)]
109+
CeedScalar ue[2] = {-rho*k_r*kappa*psi1_x,
110+
-rho*k_r*kappa*psi1_y};
110111
CeedScalar rhs1[2];
111112
// rhs = (v, ue) = J^T*ue*w
112113
AlphaMatTransposeVecMult2x2(w[i], J, ue, rhs1);
@@ -184,10 +185,10 @@ CEED_QFUNCTION(RichardRhsP02D)(void *ctx, const CeedInt Q,
184185
{dxdX[0][1][i], dxdX[1][1][i]}};
185186
const CeedScalar det_J = MatDet2x2(J);
186187
// psi = exp(-gamma*t)*sin(pi*x)*sin(pi*y)
187-
CeedScalar psi_e = sin(PI_DOUBLE*x)*sin(PI_DOUBLE*y);
188+
CeedScalar psi1 = sin(PI_DOUBLE*x)*sin(PI_DOUBLE*y);
188189

189190
// rhs = (q, pe) = pe*w*det_J
190-
rhs_p0[i] = psi_e*w[i]*det_J;
191+
rhs_p0[i] = psi1*w[i]*det_J;
191192
} // End of Quadrature Point Loop
192193
return 0;
193194
}

0 commit comments

Comments
 (0)