Skip to content

Commit 82713b0

Browse files
committed
Pressure boundary condition added.Its qfunction doesn't get called.
1 parent 5c51868 commit 82713b0

26 files changed

+363
-405
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: 3 additions & 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
// Create boundary label
@@ -19,4 +19,6 @@ 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+
PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data,
23+
AppCtx app_ctx, ProblemData *problem_data, DM dm);
2224
#endif // register_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: 9 additions & 9 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,7 +24,7 @@ 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;
@@ -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: 11 additions & 7 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,7 +110,7 @@ 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;
@@ -147,9 +150,10 @@ int main(int argc, char **argv) {
147150
SNES snes;
148151
KSP ksp;
149152
Vec U;
153+
op_apply_ctx->comm = comm;
150154
PetscCall( SNESCreate(comm, &snes) );
151155
PetscCall( SNESGetKSP(snes, &ksp) );
152-
PetscCall( SetupCommonCtx(comm, dm, ceed, ceed_data, op_apply_ctx) );
156+
PetscCall( SetupCommonCtx(dm, ceed, ceed_data, op_apply_ctx) );
153157
PetscCall( PDESolver(ceed_data, vec_type, snes, ksp, F, &U, op_apply_ctx) );
154158
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);
155159

@@ -163,7 +167,7 @@ int main(int argc, char **argv) {
163167
// ---------------------------------------------------------------------------
164168
// Print output results
165169
// ---------------------------------------------------------------------------
166-
PetscCall( PrintOutput(comm, ceed, mem_type_backend,
170+
PetscCall( PrintOutput(ceed, mem_type_backend,
167171
snes, ksp, U, l2_error_u, l2_error_p, app_ctx) );
168172

169173
// ---------------------------------------------------------------------------

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],

examples/Hdiv-mixed/qfunctions/darcy-rhs2d.h renamed to examples/Hdiv-mixed/qfunctions/darcy-force2d.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
// testbed platforms, in support of the nation's exascale computing imperative.
1616

1717
/// @file
18-
/// RHS of Darcy problem 2D (quad element) using PETSc
18+
/// Force of Darcy problem 2D (quad element) using PETSc
1919

20-
#ifndef DARCY_RHS2D_H
21-
#define DARCY_RHS2D_H
20+
#ifndef DARCY_FORCE2D_H
21+
#define DARCY_FORCE2D_H
2222

2323
#include <math.h>
2424

@@ -27,24 +27,26 @@
2727
#endif
2828
// -----------------------------------------------------------------------------
2929
// Strong form:
30-
// u = -\grad(p)
31-
// \div(u) = f
30+
// u = -\grad(p) on \Omega
31+
// \div(u) = f on \Omega
32+
// p = p0 on \Gamma_D
33+
// u.n = g on \Gamma_N
3234
// Weak form: Find (u,p) \in VxQ (V=H(div), Q=L^2) on \Omega
33-
// (u, v) - (p, \div(v)) = -<p, v\cdot n>
35+
// (v, u) - (\div(v), p) = -<v, p0 n>_{\Gamma_D}
3436
// -(q, \div(u)) = -(q, f)
35-
// This QFunction sets up the rhs and true solution for the above problem
37+
// This QFunction sets up the force and true solution for the above problem
3638
// Inputs:
3739
// x : interpolation of the physical coordinate
3840
// w : weight of quadrature
3941
// J : dx/dX. x physical coordinate, X reference coordinate [-1,1]^dim
4042
//
4143
// Output:
42-
// rhs_u : which is 0.0 for this problem
43-
// rhs_p : -(q, f) = -\int( q * f * w*detJ)dx
44+
// force_u : which is 0.0 for this problem (-<v, p0 n> is in pressure-boundary qfunction)
45+
// force_p : -(q, f) = -\int( q * f * w*detJ)dx
4446
// -----------------------------------------------------------------------------
45-
CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q,
46-
const CeedScalar *const *in,
47-
CeedScalar *const *out) {
47+
CEED_QFUNCTION(DarcyForce2D)(void *ctx, const CeedInt Q,
48+
const CeedScalar *const *in,
49+
CeedScalar *const *out) {
4850
// *INDENT-OFF*
4951
// Inputs
5052
const CeedScalar (*coords) = in[0],
@@ -63,8 +65,8 @@ CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q,
6365
{dxdX[0][1][i], dxdX[1][1][i]}};
6466
const CeedScalar detJ = J[1][1]*J[0][0] - J[1][0]*J[0][1];
6567
// *INDENT-ON*
66-
CeedScalar pe = sin(M_PI*x) * sin(M_PI*y);
67-
CeedScalar ue[2] = {-M_PI*cos(M_PI*x) *sin(M_PI*y), -M_PI*sin(M_PI*x) *cos(M_PI*y)};
68+
CeedScalar pe = sin(M_PI*x) * sin(M_PI*y) + M_PI*x*y;
69+
CeedScalar ue[2] = {-M_PI*cos(M_PI*x) *sin(M_PI*y) - M_PI*y, -M_PI*sin(M_PI*x) *cos(M_PI*y) - M_PI*x};
6870
CeedScalar f = 2*M_PI*M_PI*sin(M_PI*x)*sin(M_PI*y);
6971

7072
// 1st eq: component 1
@@ -82,4 +84,4 @@ CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q,
8284
}
8385
// -----------------------------------------------------------------------------
8486

85-
#endif //End of DARCY_RHS2D_H
87+
#endif //End of DARCY_FORCE2D_H

0 commit comments

Comments
 (0)