Skip to content

Commit 2a70772

Browse files
committed
Pressure boundary condition added. Need to rotate normals.
1 parent 5c51868 commit 2a70772

27 files changed

+405
-434
lines changed

examples/Hdiv-mixed/basis/Hdiv-hex.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef Hdiv_hex_h
2+
#define Hdiv_hex_h
13
// Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
24
// Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
35
// All Rights reserved. See files LICENSE and NOTICE for details.
@@ -159,4 +161,4 @@ static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights,
159161
}
160162
}
161163

162-
164+
#endif // Hdiv_hex_h

examples/Hdiv-mixed/basis/Hdiv-quad.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef Hdiv_quad_h
2+
#define Hdiv_quad_h
13
// Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
24
// Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
35
// All Rights reserved. See files LICENSE and NOTICE for details.
@@ -84,4 +86,4 @@ static void HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights,
8486
}
8587
}
8688

87-
89+
#endif // Hdiv_quad_h
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef cloptions_h
22
#define cloptions_h
33

4-
#include "../include/structs.h"
4+
#include "structs.h"
55

66
// Process general command line options
7-
PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx);
7+
PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx);
88

99
#endif // cloptions_h

examples/Hdiv-mixed/include/register-problem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#ifndef register_problems_h
22
#define register_problems_h
33

4-
#include "../include/structs.h"
4+
#include "structs.h"
55

66
// Register problems to be available on the command line
77
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
88
// -----------------------------------------------------------------------------
99
// Set up problems function prototype
1010
// -----------------------------------------------------------------------------
1111
// 1) darcy2d
12-
PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx);
12+
PetscErrorCode Hdiv_DARCY2D(ProblemData problem_data, void *ctx);
1313

1414
// 2) darcy3d
15-
PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx);
15+
PetscErrorCode Hdiv_DARCY3D(ProblemData problem_data, void *ctx);
1616

1717
// 3) darcy3dprism
1818

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef register_boundary_h
2-
#define register_boundary_h
1+
#ifndef setup_boundary_h
2+
#define setup_boundary_h
33

44
#include <petsc.h>
55
#include <petscdmplex.h>
66
#include <petscsys.h>
77
#include <ceed.h>
8-
#include "../include/structs.h"
8+
#include "structs.h"
99

1010
// ---------------------------------------------------------------------------
1111
// Create boundary label
@@ -19,4 +19,7 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm);
1919
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t,
2020
const PetscReal coords[],
2121
PetscInt num_comp_u, PetscScalar *u, void *ctx);
22-
#endif // register_boundary_h
22+
PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data,
23+
AppCtx app_ctx, ProblemData problem_data, DM dm,
24+
CeedVector bc_pressure);
25+
#endif // setup_boundary_h

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <petscdmplex.h>
66
#include <petscsys.h>
77
#include <ceed.h>
8-
#include "../include/structs.h"
8+
#include "structs.h"
99

1010
// ---------------------------------------------------------------------------
1111
// Set-up DM
1212
// ---------------------------------------------------------------------------
13-
PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data,
13+
PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData problem_data,
1414
DM *dm);
1515

1616
#endif // setupdm_h

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef setuplibceed_h
22
#define setuplibceed_h
33

4-
#include "../include/structs.h"
4+
#include "structs.h"
55

66
// Convert PETSc MemType to libCEED MemType
77
CeedMemType MemTypeP2C(PetscMemType mtype);
@@ -18,7 +18,7 @@ PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P,
1818
CeedElemRestriction *elem_restr_oriented, CeedElemRestriction *elem_restr);
1919
// Set up libCEED for a given degree
2020
PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx,
21-
ProblemData *problem_data,
21+
ProblemData problem_data,
2222
PetscInt rhs_loc_size, CeedData ceed_data,
2323
CeedVector rhs_ceed, CeedVector *target);
2424
#endif // setuplibceed_h

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "structs.h"
88

9-
PetscErrorCode SetupCommonCtx(MPI_Comm comm, DM dm, Ceed ceed,
9+
PetscErrorCode SetupCommonCtx(DM dm, Ceed ceed,
1010
CeedData ceed_data,
1111
OperatorApplyContext op_apply_ctx);
1212
PetscErrorCode SetupJacobianOperatorCtx(CeedData ceed_data,
@@ -24,7 +24,7 @@ PetscErrorCode PDESolver(CeedData ceed_data, VecType vec_type, SNES snes,
2424
PetscErrorCode ComputeL2Error(CeedData ceed_data, Vec U, CeedVector target,
2525
CeedScalar *l2_error_u, CeedScalar *l2_error_p,
2626
OperatorApplyContext op_apply_ctx);
27-
PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed,
27+
PetscErrorCode PrintOutput(Ceed ceed,
2828
CeedMemType mem_type_backend,
2929
SNES snes, KSP ksp,
3030
Vec U, CeedScalar l2_error_u,

examples/Hdiv-mixed/include/structs.h

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
// Application context from user command line options
88
typedef struct AppCtx_ *AppCtx;
99
struct AppCtx_ {
10+
MPI_Comm comm;
1011
// Degree of polynomial (1 only), extra quadrature pts
1112
PetscInt degree;
1213
PetscInt q_extra;
1314
// For applying traction BCs
14-
PetscInt bc_traction_count;
15-
PetscInt bc_traction_faces[16];
16-
PetscScalar bc_traction_vector[16][3];
15+
PetscInt bc_pressure_count;
16+
PetscInt bc_faces[16]; // face ID
17+
PetscScalar bc_pressure_value[16];
1718
// Problem type arguments
1819
PetscFunctionList problems;
1920
char problem_name[PETSC_MAX_PATH_LEN];
@@ -23,13 +24,12 @@ struct AppCtx_ {
2324
// libCEED data struct
2425
typedef struct CeedData_ *CeedData;
2526
struct CeedData_ {
26-
CeedBasis basis_x, basis_u, basis_p;
27+
CeedBasis basis_x, basis_u, basis_p, basis_u_face;
2728
CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i,
2829
elem_restr_p;
2930
CeedQFunction qf_residual, qf_jacobian, qf_error;
3031
CeedOperator op_residual, op_jacobian, op_error;
31-
CeedVector x_ceed, y_ceed;
32-
CeedQFunctionContext pq2d_context;
32+
CeedVector x_ceed, y_ceed, x_coord;
3333
};
3434

3535
// 1) darcy2d
@@ -50,13 +50,31 @@ struct DARCY3DContext_ {
5050
};
5151
#endif
5252

53-
// 4) richard
53+
// 3) richard2d
54+
#ifndef PHYSICS_RICHARD2D_STRUCT
55+
#define PHYSICS_RICHARD2D_STRUCT
56+
typedef struct RICHARD2DContext_ *RICHARD2DContext;
57+
struct RICHARD2DContext_ {
58+
CeedScalar kappa;
59+
};
60+
#endif
61+
62+
// 4) richard3d
63+
#ifndef PHYSICS_RICHARD3D_STRUCT
64+
#define PHYSICS_RICHARD3D_STRUCT
65+
typedef struct RICHARD3DContext_ *RICHARD3DContext;
66+
struct RICHARD3DContext_ {
67+
CeedScalar kappa;
68+
};
69+
#endif
5470

5571
// Struct that contains all enums and structs used for the physics of all problems
5672
typedef struct Physics_ *Physics;
5773
struct Physics_ {
5874
DARCY2DContext darcy2d_ctx;
5975
DARCY3DContext darcy3d_ctx;
76+
RICHARD2DContext richard2d_ctx;
77+
RICHARD3DContext richard3d_ctx;
6078
};
6179

6280
// PETSc operator contexts
@@ -71,15 +89,15 @@ struct OperatorApplyContext_ {
7189
};
7290

7391
// Problem specific data
74-
typedef struct {
75-
CeedQFunctionUser setup_rhs, residual, jacobian, setup_error,
76-
setup_true, setup_face_geo;
77-
const char *setup_rhs_loc, *residual_loc, *jacobian_loc,
78-
*setup_error_loc, *setup_true_loc, *setup_face_geo_loc;
92+
typedef struct ProblemData_ *ProblemData;
93+
struct ProblemData_ {
94+
CeedQFunctionUser force, residual, jacobian, error,
95+
setup_true, bc_pressure;
96+
const char *force_loc, *residual_loc, *jacobian_loc,
97+
*error_loc, *setup_true_loc, *bc_pressure_loc;
7998
CeedQuadMode quadrature_mode;
8099
CeedInt elem_node, dim, q_data_size_face;
81-
PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics);
82100

83-
} ProblemData;
101+
};
84102

85103
#endif // structs_h

examples/Hdiv-mixed/main.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
//
2424
// Build with: make
2525
// Run with:
26-
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4
27-
// ./main -pc_type svd -problem darcy3d -dm_plex_dim 3 -dm_plex_box_faces 4,4,4
28-
// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
26+
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4
27+
// ./main -pc_type svd -problem darcy3d -dm_plex_dim 3 -dm_plex_box_faces 4,4,4
28+
// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
29+
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1
30+
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1,2,3,4
2931
const char help[] = "Solve H(div)-mixed problem using PETSc and libCEED\n";
3032

3133
#include "main.h"
@@ -42,7 +44,7 @@ int main(int argc, char **argv) {
4244
AppCtx app_ctx;
4345
PetscCall( PetscCalloc1(1, &app_ctx) );
4446

45-
ProblemData *problem_data = NULL;
47+
ProblemData problem_data = NULL;
4648
PetscCall( PetscCalloc1(1, &problem_data) );
4749

4850
CeedData ceed_data;
@@ -62,13 +64,14 @@ int main(int argc, char **argv) {
6264

6365
// -- Process general command line options
6466
MPI_Comm comm = PETSC_COMM_WORLD;
65-
PetscCall( ProcessCommandLineOptions(comm, app_ctx) );
67+
app_ctx->comm = comm;
68+
PetscCall( ProcessCommandLineOptions(app_ctx) );
6669

6770
// ---------------------------------------------------------------------------
6871
// Choose the problem from the list of registered problems
6972
// ---------------------------------------------------------------------------
7073
{
71-
PetscErrorCode (*p)(ProblemData *, void *);
74+
PetscErrorCode (*p)(ProblemData, void *);
7275
PetscCall( PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name,
7376
&p) );
7477
if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found",
@@ -107,12 +110,12 @@ int main(int argc, char **argv) {
107110

108111

109112
// ---------------------------------------------------------------------------
110-
// Create local RHS vector
113+
// Create local Force vector
111114
// ---------------------------------------------------------------------------
112115
Vec F_loc;
113116
PetscInt F_loc_size;
114117
CeedScalar *f;
115-
CeedVector force_ceed, target;
118+
CeedVector force_ceed, target, bc_pressure;
116119
PetscMemType force_mem_type;
117120
PetscCall( DMCreateLocalVector(dm, &F_loc) );
118121
// Local size for libCEED
@@ -121,15 +124,18 @@ int main(int argc, char **argv) {
121124
PetscCall( VecGetArrayAndMemType(F_loc, &f, &force_mem_type) );
122125
CeedVectorCreate(ceed, F_loc_size, &force_ceed);
123126
CeedVectorSetArray(force_ceed, MemTypeP2C(force_mem_type), CEED_USE_POINTER, f);
124-
127+
CeedVectorCreate(ceed, F_loc_size, &bc_pressure);
128+
CeedVectorSetArray(bc_pressure, MemTypeP2C(force_mem_type), CEED_USE_POINTER,
129+
f);
125130
// ---------------------------------------------------------------------------
126131
// Setup libCEED - Compute local F and true solution (target)
127132
// ---------------------------------------------------------------------------
128133
// -- Set up libCEED objects
129134
PetscCall( SetupLibceed(dm, ceed, app_ctx, problem_data,
130135
F_loc_size, ceed_data, force_ceed, &target) );
131136
//CeedVectorView(force_ceed, "%12.8f", stdout);
132-
137+
PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm,
138+
bc_pressure) );
133139
// ---------------------------------------------------------------------------
134140
// Create global F
135141
// ---------------------------------------------------------------------------
@@ -147,9 +153,10 @@ int main(int argc, char **argv) {
147153
SNES snes;
148154
KSP ksp;
149155
Vec U;
156+
op_apply_ctx->comm = comm;
150157
PetscCall( SNESCreate(comm, &snes) );
151158
PetscCall( SNESGetKSP(snes, &ksp) );
152-
PetscCall( SetupCommonCtx(comm, dm, ceed, ceed_data, op_apply_ctx) );
159+
PetscCall( SetupCommonCtx(dm, ceed, ceed_data, op_apply_ctx) );
153160
PetscCall( PDESolver(ceed_data, vec_type, snes, ksp, F, &U, op_apply_ctx) );
154161
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);
155162

@@ -163,7 +170,7 @@ int main(int argc, char **argv) {
163170
// ---------------------------------------------------------------------------
164171
// Print output results
165172
// ---------------------------------------------------------------------------
166-
PetscCall( PrintOutput(comm, ceed, mem_type_backend,
173+
PetscCall( PrintOutput(ceed, mem_type_backend,
167174
snes, ksp, U, l2_error_u, l2_error_p, app_ctx) );
168175

169176
// ---------------------------------------------------------------------------
@@ -201,6 +208,7 @@ int main(int argc, char **argv) {
201208

202209
// Free libCEED objects
203210
CeedVectorDestroy(&force_ceed);
211+
CeedVectorDestroy(&bc_pressure);
204212
CeedVectorDestroy(&target);
205213
PetscCall( CeedDataDestroy(ceed_data) );
206214
CeedDestroy(&ceed);

examples/Hdiv-mixed/problems/darcy2d.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
/// @file
1818
/// Utility functions for setting up Darcy problem in 2D
1919

20-
#include "../include/setup-libceed.h"
2120
#include "../include/register-problem.h"
22-
#include "../qfunctions/darcy-rhs2d.h"
21+
#include "../qfunctions/darcy-force2d.h"
2322
#include "../qfunctions/darcy-mass2d.h"
2423
#include "../qfunctions/darcy-error2d.h"
25-
#include "../qfunctions/face-geo2d.h"
24+
#include "../qfunctions/pressure-boundary2d.h"
2625

2726
// Hdiv_DARCY2D is registered in cl-option.c
28-
PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx) {
27+
PetscErrorCode Hdiv_DARCY2D(ProblemData problem_data, void *ctx) {
2928
Physics phys = *(Physics *)ctx;
3029
MPI_Comm comm = PETSC_COMM_WORLD;
3130
PetscFunctionBeginUser;
@@ -39,16 +38,16 @@ PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx) {
3938
problem_data->elem_node = 4;
4039
problem_data->q_data_size_face = 3;
4140
problem_data->quadrature_mode = CEED_GAUSS;
42-
problem_data->setup_rhs = SetupDarcyRhs2D;
43-
problem_data->setup_rhs_loc = SetupDarcyRhs2D_loc;
44-
problem_data->residual = SetupDarcyMass2D;
45-
problem_data->residual_loc = SetupDarcyMass2D_loc;
46-
problem_data->jacobian = SetupJacobianDarcyMass2D;
47-
problem_data->jacobian_loc = SetupJacobianDarcyMass2D_loc;
48-
problem_data->setup_error = SetupDarcyError2D;
49-
problem_data->setup_error_loc = SetupDarcyError2D_loc;
50-
problem_data->setup_face_geo = SetupFaceGeo2D;
51-
problem_data->setup_face_geo_loc = SetupFaceGeo2D_loc;
41+
problem_data->force = DarcyForce2D;
42+
problem_data->force_loc = DarcyForce2D_loc;
43+
problem_data->residual = DarcyMass2D;
44+
problem_data->residual_loc = DarcyMass2D_loc;
45+
problem_data->jacobian = JacobianDarcyMass2D;
46+
problem_data->jacobian_loc = JacobianDarcyMass2D_loc;
47+
problem_data->error = DarcyError2D;
48+
problem_data->error_loc = DarcyError2D_loc;
49+
problem_data->bc_pressure = BCPressure2D;
50+
problem_data->bc_pressure_loc = BCPressure2D_loc;
5251

5352
// ------------------------------------------------------
5453
// Command line Options

0 commit comments

Comments
 (0)