Skip to content

Commit 8ddac30

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

26 files changed

+372
-420
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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);

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

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

Lines changed: 1 addition & 1 deletion
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);

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: 10 additions & 10 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_pressure_faces[16];
17+
PetscScalar bc_pressure_vector[16][3];
1718
// Problem type arguments
1819
PetscFunctionList problems;
1920
char problem_name[PETSC_MAX_PATH_LEN];
@@ -23,12 +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+
CeedVector x_ceed, y_ceed, x_coord;
3233
CeedQFunctionContext pq2d_context;
3334
};
3435

@@ -72,13 +73,12 @@ struct OperatorApplyContext_ {
7273

7374
// Problem specific data
7475
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;
76+
CeedQFunctionUser force, residual, jacobian, error,
77+
setup_true, bc_pressure;
78+
const char *force_loc, *residual_loc, *jacobian_loc,
79+
*error_loc, *setup_true_loc, *bc_pressure_loc;
7980
CeedQuadMode quadrature_mode;
8081
CeedInt elem_node, dim, q_data_size_face;
81-
PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics);
8282

8383
} ProblemData;
8484

examples/Hdiv-mixed/main.c

Lines changed: 18 additions & 10 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"
@@ -62,7 +64,8 @@ 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
@@ -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: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
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
2827
PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx) {
@@ -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

examples/Hdiv-mixed/problems/darcy3d.c

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

20-
#include "../include/setup-libceed.h"
2120
#include "../include/register-problem.h"
22-
#include "../qfunctions/darcy-rhs3d.h"
21+
#include "../qfunctions/darcy-force3d.h"
2322
#include "../qfunctions/darcy-mass3d.h"
2423
#include "../qfunctions/darcy-error3d.h"
25-
#include "../qfunctions/face-geo3d.h"
24+
#include "../qfunctions/pressure-boundary3d.h"
2625

2726
// Hdiv_DARCY3D is registered in cl-option.c
2827
PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx) {
@@ -39,16 +38,16 @@ PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx) {
3938
problem_data->elem_node = 8;
4039
problem_data->q_data_size_face = 4;
4140
problem_data->quadrature_mode = CEED_GAUSS;
42-
problem_data->setup_rhs = SetupDarcyRhs3D;
43-
problem_data->setup_rhs_loc = SetupDarcyRhs3D_loc;
44-
problem_data->residual = SetupDarcyMass3D;
45-
problem_data->residual_loc = SetupDarcyMass3D_loc;
46-
problem_data->jacobian = SetupJacobianDarcyMass3D;
47-
problem_data->jacobian_loc = SetupJacobianDarcyMass3D_loc;
48-
problem_data->setup_error = SetupDarcyError3D;
49-
problem_data->setup_error_loc = SetupDarcyError3D_loc;
50-
problem_data->setup_face_geo = SetupFaceGeo3D;
51-
problem_data->setup_face_geo_loc = SetupFaceGeo3D_loc;
41+
problem_data->force = DarcyForce3D;
42+
problem_data->force_loc = DarcyForce3D_loc;
43+
problem_data->residual = DarcyMass3D;
44+
problem_data->residual_loc = DarcyMass3D_loc;
45+
problem_data->jacobian = JacobianDarcyMass3D;
46+
problem_data->jacobian_loc = JacobianDarcyMass3D_loc;
47+
problem_data->error = DarcyError3D;
48+
problem_data->error_loc = DarcyError3D_loc;
49+
problem_data->bc_pressure = BCPressure3D;
50+
problem_data->bc_pressure_loc = BCPressure3D_loc;
5251
// ------------------------------------------------------
5352
// Command line Options
5453
// ------------------------------------------------------

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
// -----------------------------------------------------------------------------
2626
// Compuet error
2727
// -----------------------------------------------------------------------------
28-
CEED_QFUNCTION(SetupDarcyError2D)(void *ctx, const CeedInt Q,
29-
const CeedScalar *const *in,
30-
CeedScalar *const *out) {
28+
CEED_QFUNCTION(DarcyError2D)(void *ctx, const CeedInt Q,
29+
const CeedScalar *const *in,
30+
CeedScalar *const *out) {
3131
// *INDENT-OFF*
3232
// Inputs
3333
const CeedScalar (*w) = in[0],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ CEED_QFUNCTION_HELPER CeedScalar ComputeDetMat(const CeedScalar A[3][3]) {
4141
// -----------------------------------------------------------------------------
4242
// Compuet error
4343
// -----------------------------------------------------------------------------
44-
CEED_QFUNCTION(SetupDarcyError3D)(void *ctx, const CeedInt Q,
45-
const CeedScalar *const *in,
46-
CeedScalar *const *out) {
44+
CEED_QFUNCTION(DarcyError3D)(void *ctx, const CeedInt Q,
45+
const CeedScalar *const *in,
46+
CeedScalar *const *out) {
4747
// *INDENT-OFF*
4848
// Inputs
4949
const CeedScalar (*w) = in[0],

0 commit comments

Comments
 (0)