Skip to content

Commit f30f670

Browse files
committed
Added post-processing.c to solve the projection problem for velocity
1 parent fe9f65d commit f30f670

20 files changed

+870
-154
lines changed

examples/Hdiv-mixed/conv_test.sh

Lines changed: 1 addition & 1 deletion
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]=richard2d
35+
run_flags[problem]=darcy2d
3636
run_flags[dm_plex_dim]=$dim
3737
run_flags[dm_plex_box_faces]=2,2
3838
else
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run,mesh_res,error_u,error_p
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
2+
0,2,92.07816,0.09543
3+
1,4,26.30005,0.03133
4+
2,6,11.97420,0.01464
5+
3,8,6.79226,0.00838
6+
4,10,4.36393,0.00540
131 Bytes
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef post_processing_h
2+
#define post_processing_h
3+
4+
#include <ceed.h>
5+
#include <petsc.h>
6+
7+
#include "structs.h"
8+
#include "../include/setup-libceed.h"
9+
PetscErrorCode PrintOutput(Ceed ceed, AppCtx app_ctx, PetscBool has_ts,
10+
CeedMemType mem_type_backend,
11+
TS ts, SNES snes, KSP ksp,
12+
Vec U, CeedScalar l2_error_u,
13+
CeedScalar l2_error_p);
14+
PetscErrorCode SetupProjectVelocityCtx_Hdiv(MPI_Comm comm, DM dm, Ceed ceed,
15+
CeedData ceed_data, OperatorApplyContext ctx_post_Hdiv);
16+
PetscErrorCode SetupProjectVelocityCtx_H1(MPI_Comm comm, DM dm_H1, Ceed ceed,
17+
CeedData ceed_data, OperatorApplyContext ctx_post_H1);
18+
PetscErrorCode ProjectVelocity(CeedData ceed_data,
19+
Vec U, VecType vec_type, Vec *U_H1,
20+
OperatorApplyContext ctx_post_Hdiv,
21+
OperatorApplyContext ctx_post_H1);
22+
#endif // post_processing_h

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// ---------------------------------------------------------------------------
1111
// Setup FE
1212
// ---------------------------------------------------------------------------
13-
PetscErrorCode SetupFE(MPI_Comm comm, DM dm, DM dm_u0, DM dm_p0);
14-
13+
PetscErrorCode SetupFEHdiv(MPI_Comm comm, DM dm, DM dm_u0, DM dm_p0);
14+
PetscErrorCode SetupFEH1(ProblemData problem_data,
15+
AppCtx app_ctx, DM dm_H1);
1516
#endif // setupfe_h

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, DM dm_u0,
1919
CeedElemRestriction *elem_restr_u, CeedElemRestriction *elem_restr_p,
2020
CeedElemRestriction *elem_restr_u0, CeedElemRestriction *elem_restr_p0);
2121
// Set up libCEED for a given degree
22-
PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, Ceed ceed,
23-
AppCtx app_ctx,
22+
PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1,
23+
Ceed ceed, AppCtx app_ctx,
2424
ProblemData problem_data,
2525
CeedData ceed_data);
2626
#endif // setuplibceed_h

examples/Hdiv-mixed/include/structs.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct AppCtx_ {
1919
PetscFunctionList problems;
2020
char problem_name[PETSC_MAX_PATH_LEN];
2121
CeedScalar t_final, t;
22+
PetscBool view_solution, quartic;
2223
};
2324

2425
// PETSc operator contexts
@@ -41,32 +42,33 @@ struct CeedData_ {
4142
CeedBasis basis_x, basis_u, basis_p, basis_u_face;
4243
CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i,
4344
elem_restr_p, elem_restr_p_i, elem_restr_u0,
44-
elem_restr_p0;
45+
elem_restr_p0, elem_restr_u_post;
4546
CeedQFunction qf_residual, qf_jacobian, qf_error, qf_ics_u, qf_ics_p,
46-
qf_rhs_u0, qf_rhs_p0;
47+
qf_rhs_u0, qf_rhs_p0, qf_post_rhs, qf_post_mass;
4748
CeedOperator op_residual, op_jacobian, op_error, op_ics_u, op_ics_p,
48-
op_rhs_u0, op_rhs_p0;
49+
op_rhs_u0, op_rhs_p0, op_post_rhs, op_post_mass;
4950
CeedVector x_ceed, y_ceed, x_coord, x_t_ceed, rhs_u0_ceed,
50-
u0_ceed, v0_ceed, rhs_p0_ceed, p0_ceed, q0_ceed;
51+
u0_ceed, v0_ceed, rhs_p0_ceed, p0_ceed, q0_ceed,
52+
post_rhs_ceed, u_ceed, up_ceed, vp_ceed;
5153
OperatorApplyContext ctx_residual, ctx_jacobian, ctx_error, ctx_residual_ut,
52-
ctx_initial_u0, ctx_initial_p0;
54+
ctx_initial_u0, ctx_initial_p0, ctx_post_Hdiv, ctx_post_H1;
5355
CeedInt num_elem;
5456
};
5557

5658
// Problem specific data
5759
typedef struct ProblemData_ *ProblemData;
5860
struct ProblemData_ {
5961
CeedQFunctionUser true_solution, residual, jacobian, error, ics_u, ics_p,
60-
bc_pressure, rhs_u0, rhs_p0;
62+
bc_pressure, rhs_u0, rhs_p0, post_rhs, post_mass;
6163
const char *true_solution_loc, *residual_loc, *jacobian_loc,
6264
*error_loc, *bc_pressure_loc, *ics_u_loc, *ics_p_loc, *rhs_u0_loc,
63-
*rhs_p0_loc;
65+
*rhs_p0_loc, *post_rhs_loc, *post_mass_loc;
6466
CeedQuadMode quadrature_mode;
6567
CeedInt elem_node, dim, q_data_size_face;
6668
CeedQFunctionContext true_qfunction_ctx, error_qfunction_ctx,
6769
residual_qfunction_ctx, jacobian_qfunction_ctx,
6870
rhs_u0_qfunction_ctx ;
69-
PetscBool has_ts;
71+
PetscBool has_ts, view_solution, quartic;
7072
};
7173

7274
#endif // structs_h

examples/Hdiv-mixed/main.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ int main(int argc, char **argv) {
7373
CeedData ceed_data;
7474
PetscCall( PetscCalloc1(1, &ceed_data) );
7575

76-
OperatorApplyContext ctx_residual_ut, ctx_initial_u0, ctx_initial_p0;
76+
OperatorApplyContext ctx_residual_ut, ctx_initial_u0, ctx_initial_p0,
77+
ctx_post_Hdiv, ctx_post_H1;
7778
PetscCall( PetscCalloc1(1, &ctx_residual_ut) );
7879
PetscCall( PetscCalloc1(1, &ctx_initial_u0) );
7980
PetscCall( PetscCalloc1(1, &ctx_initial_p0) );
81+
PetscCall( PetscCalloc1(1, &ctx_post_Hdiv) );
82+
PetscCall( PetscCalloc1(1, &ctx_post_H1) );
8083
ceed_data->ctx_residual_ut = ctx_residual_ut;
8184
ceed_data->ctx_initial_u0 = ctx_initial_u0;
8285
ceed_data->ctx_initial_p0 = ctx_initial_p0;
86+
ceed_data->ctx_post_Hdiv = ctx_post_Hdiv;
87+
ceed_data->ctx_post_H1 = ctx_post_H1;
8388
// ---------------------------------------------------------------------------
8489
// Process command line options
8590
// ---------------------------------------------------------------------------
@@ -106,32 +111,32 @@ int main(int argc, char **argv) {
106111
// ---------------------------------------------------------------------------
107112
// Create DM
108113
// ---------------------------------------------------------------------------
109-
DM dm, dm_u0, dm_p0;
114+
DM dm, dm_u0, dm_p0, dm_H1;
110115
PetscCall( CreateDM(comm, vec_type, &dm) );
111116
PetscCall( CreateDM(comm, vec_type, &dm_u0) );
112117
PetscCall( CreateDM(comm, vec_type, &dm_p0) );
118+
PetscCall( CreateDM(comm, vec_type, &dm_H1) );
113119
// TODO: add mesh option
114120
// perturb to have smooth random mesh
115121
//PetscCall( PerturbVerticesSmooth(dm) );
116122

117123
// ---------------------------------------------------------------------------
118124
// Setup FE
119125
// ---------------------------------------------------------------------------
120-
SetupFE(comm, dm, dm_u0, dm_p0);
121-
126+
SetupFEHdiv(comm, dm, dm_u0, dm_p0);
127+
SetupFEH1(problem_data, app_ctx, dm_H1);
122128
// ---------------------------------------------------------------------------
123129
// Create local Force vector
124130
// ---------------------------------------------------------------------------
125131
Vec U; // U=[p,u], U0=u0
126132
PetscCall( DMCreateGlobalVector(dm, &U) );
127-
PetscCall( VecZeroEntries(U) );
128133

129134
// ---------------------------------------------------------------------------
130135
// Setup libCEED
131136
// ---------------------------------------------------------------------------
132137
// -- Set up libCEED objects
133-
PetscCall( SetupLibceed(dm, dm_u0, dm_p0, ceed, app_ctx, problem_data,
134-
ceed_data) );
138+
PetscCall( SetupLibceed(dm, dm_u0, dm_p0, dm_H1, ceed, app_ctx,
139+
problem_data, ceed_data) );
135140
//CeedVectorView(force_ceed, "%12.8f", stdout);
136141
//PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
137142
// bc_pressure) );
@@ -192,11 +197,31 @@ int main(int argc, char **argv) {
192197
// ---------------------------------------------------------------------------
193198
// Save solution (paraview)
194199
// ---------------------------------------------------------------------------
195-
PetscViewer viewer;
196-
PetscCall( PetscViewerVTKOpen(comm,"solution.vtu",FILE_MODE_WRITE,&viewer) );
197-
PetscCall( VecView(U, viewer) );
198-
PetscCall( PetscViewerDestroy(&viewer) );
200+
Vec U_H1;
201+
PetscCall( DMCreateGlobalVector(dm_H1, &U_H1) );
202+
PetscCall( VecZeroEntries(U_H1) );
203+
if (app_ctx->view_solution) {
204+
PetscViewer viewer_p;
205+
PetscCall( PetscViewerVTKOpen(comm,"solution_p.vtu",FILE_MODE_WRITE,
206+
&viewer_p) );
207+
PetscCall( VecView(U, viewer_p) );
208+
PetscCall( PetscViewerDestroy(&viewer_p) );
209+
210+
SetupProjectVelocityCtx_Hdiv(comm, dm, ceed, ceed_data,
211+
ceed_data->ctx_post_Hdiv);
212+
SetupProjectVelocityCtx_H1(comm, dm_H1, ceed, ceed_data,
213+
ceed_data->ctx_post_H1);
199214

215+
ProjectVelocity(ceed_data, U, vec_type, &U_H1,
216+
ceed_data->ctx_post_Hdiv,
217+
ceed_data->ctx_post_H1);
218+
219+
PetscViewer viewer_u;
220+
PetscCall( PetscViewerVTKOpen(comm,"solution_u.vtu",FILE_MODE_WRITE,
221+
&viewer_u) );
222+
PetscCall( VecView(U_H1, viewer_u) );
223+
PetscCall( PetscViewerDestroy(&viewer_u) );
224+
}
200225
// ---------------------------------------------------------------------------
201226
// Free objects
202227
// ---------------------------------------------------------------------------
@@ -205,7 +230,12 @@ int main(int argc, char **argv) {
205230
PetscCall( DMDestroy(&dm) );
206231
PetscCall( DMDestroy(&dm_u0) );
207232
PetscCall( DMDestroy(&dm_p0) );
233+
PetscCall( DMDestroy(&dm_H1) );
208234
PetscCall( VecDestroy(&U) );
235+
PetscCall( VecDestroy(&U_H1) );
236+
PetscCall( VecDestroy(&ceed_data->ctx_residual_ut->X_loc) );
237+
PetscCall( VecDestroy(&ceed_data->ctx_residual_ut->X_t_loc) );
238+
PetscCall( VecDestroy(&ceed_data->ctx_residual_ut->Y_loc) );
209239
if (problem_data->has_ts) {
210240
PetscCall( TSDestroy(&ts) );
211241
} else {
@@ -222,6 +252,8 @@ int main(int argc, char **argv) {
222252
PetscCall( PetscFree(ctx_initial_u0) );
223253
PetscCall( PetscFree(ctx_initial_p0) );
224254
PetscCall( PetscFree(ctx_residual_ut) );
255+
PetscCall( PetscFree(ctx_post_H1) );
256+
PetscCall( PetscFree(ctx_post_Hdiv) );
225257

226258
// Free libCEED objects
227259
//CeedVectorDestroy(&bc_pressure);

examples/Hdiv-mixed/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
#include "include/setup-matops.h"
1212
#include "include/setup-solvers.h"
1313
#include "include/setup-ts.h"
14+
#include "include/post-processing.h"
1415

1516
#endif // MAIN_H

examples/Hdiv-mixed/problems/darcy2d.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "../qfunctions/darcy-true2d.h"
2222
#include "../qfunctions/darcy-system2d.h"
2323
#include "../qfunctions/darcy-error2d.h"
24+
#include "../qfunctions/post-processing2d.h"
25+
#include "../qfunctions/darcy-true-quartic2d.h"
26+
#include "../qfunctions/darcy-system-quartic2d.h"
2427
//#include "../qfunctions/pressure-boundary2d.h"
2528

2629
PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, void *ctx) {
@@ -49,7 +52,22 @@ PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, void *ctx) {
4952
problem_data->error_loc = DarcyError2D_loc;
5053
//problem_data->bc_pressure = BCPressure2D;
5154
//problem_data->bc_pressure_loc = BCPressure2D_loc;
55+
problem_data->post_rhs = PostProcessingRhs2D;
56+
problem_data->post_rhs_loc = PostProcessingRhs2D_loc;
57+
problem_data->post_mass = PostProcessingMass2D;
58+
problem_data->post_mass_loc = PostProcessingMass2D_loc;
5259
problem_data->has_ts = PETSC_FALSE;
60+
problem_data->view_solution = app_ctx->view_solution;
61+
problem_data->quartic = app_ctx->quartic;
62+
63+
if (app_ctx->quartic) {
64+
problem_data->true_solution = DarcyTrueQuartic2D;
65+
problem_data->true_solution_loc = DarcyTrueQuartic2D_loc;
66+
problem_data->residual = DarcySystemQuartic2D;
67+
problem_data->residual_loc = DarcySystemQuartic2D_loc;
68+
problem_data->jacobian = JacobianDarcySystemQuartic2D;
69+
problem_data->jacobian_loc = JacobianDarcySystemQuartic2D_loc;
70+
}
5371

5472
// ------------------------------------------------------
5573
// Command line Options

examples/Hdiv-mixed/problems/darcy3d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PetscErrorCode Hdiv_DARCY3D(Ceed ceed, ProblemData problem_data, void *ctx) {
5050
//problem_data->bc_pressure = BCPressure3D;
5151
//problem_data->bc_pressure_loc = BCPressure3D_loc;
5252
problem_data->has_ts = PETSC_FALSE;
53-
53+
problem_data->view_solution = app_ctx->view_solution;
5454
// ------------------------------------------------------
5555
// Command line Options
5656
// ------------------------------------------------------

examples/Hdiv-mixed/problems/richard2d.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "../qfunctions/richard-true2d.h"
2323
#include "../qfunctions/richard-ics2d.h"
2424
#include "../qfunctions/darcy-error2d.h"
25+
#include "../qfunctions/post-processing2d.h"
2526
//#include "../qfunctions/pressure-boundary2d.h"
2627
#include "petscsystypes.h"
2728

@@ -59,7 +60,12 @@ PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, void *ctx) {
5960
problem_data->error_loc = DarcyError2D_loc;
6061
//problem_data->bc_pressure = BCPressure2D;
6162
//problem_data->bc_pressure_loc = BCPressure2D_loc;
63+
problem_data->post_rhs = PostProcessingRhs2D;
64+
problem_data->post_rhs_loc = PostProcessingRhs2D_loc;
65+
problem_data->post_mass = PostProcessingMass2D;
66+
problem_data->post_mass_loc = PostProcessingMass2D_loc;
6267
problem_data->has_ts = PETSC_TRUE;
68+
problem_data->view_solution = app_ctx->view_solution;
6369

6470
// ------------------------------------------------------
6571
// Command line Options

0 commit comments

Comments
 (0)