Skip to content

Commit

Permalink
Pressure boundary condition added.Its qfunction doesn't get called.
Browse files Browse the repository at this point in the history
  • Loading branch information
rezgarshakeri committed Jun 17, 2022
1 parent 5c51868 commit 82713b0
Show file tree
Hide file tree
Showing 26 changed files with 363 additions and 405 deletions.
4 changes: 3 additions & 1 deletion examples/Hdiv-mixed/basis/Hdiv-hex.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef Hdiv_hex_h
#define Hdiv_hex_h
// Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
// All Rights reserved. See files LICENSE and NOTICE for details.
Expand Down Expand Up @@ -159,4 +161,4 @@ static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights,
}
}


#endif // Hdiv_hex_h
4 changes: 3 additions & 1 deletion examples/Hdiv-mixed/basis/Hdiv-quad.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef Hdiv_quad_h
#define Hdiv_quad_h
// Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
// All Rights reserved. See files LICENSE and NOTICE for details.
Expand Down Expand Up @@ -84,4 +86,4 @@ static void HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights,
}
}


#endif // Hdiv_quad_h
4 changes: 2 additions & 2 deletions examples/Hdiv-mixed/include/cl-options.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef cloptions_h
#define cloptions_h

#include "../include/structs.h"
#include "structs.h"

// Process general command line options
PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx);
PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx);

#endif // cloptions_h
2 changes: 1 addition & 1 deletion examples/Hdiv-mixed/include/register-problem.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef register_problems_h
#define register_problems_h

#include "../include/structs.h"
#include "structs.h"

// Register problems to be available on the command line
PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx);
Expand Down
4 changes: 3 additions & 1 deletion examples/Hdiv-mixed/include/setup-boundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <petscdmplex.h>
#include <petscsys.h>
#include <ceed.h>
#include "../include/structs.h"
#include "structs.h"

// ---------------------------------------------------------------------------
// Create boundary label
Expand All @@ -19,4 +19,6 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm);
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t,
const PetscReal coords[],
PetscInt num_comp_u, PetscScalar *u, void *ctx);
PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data,
AppCtx app_ctx, ProblemData *problem_data, DM dm);
#endif // register_boundary_h
2 changes: 1 addition & 1 deletion examples/Hdiv-mixed/include/setup-dm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <petscdmplex.h>
#include <petscsys.h>
#include <ceed.h>
#include "../include/structs.h"
#include "structs.h"

// ---------------------------------------------------------------------------
// Set-up DM
Expand Down
2 changes: 1 addition & 1 deletion examples/Hdiv-mixed/include/setup-libceed.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef setuplibceed_h
#define setuplibceed_h

#include "../include/structs.h"
#include "structs.h"

// Convert PETSc MemType to libCEED MemType
CeedMemType MemTypeP2C(PetscMemType mtype);
Expand Down
4 changes: 2 additions & 2 deletions examples/Hdiv-mixed/include/setup-solvers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "structs.h"

PetscErrorCode SetupCommonCtx(MPI_Comm comm, DM dm, Ceed ceed,
PetscErrorCode SetupCommonCtx(DM dm, Ceed ceed,
CeedData ceed_data,
OperatorApplyContext op_apply_ctx);
PetscErrorCode SetupJacobianOperatorCtx(CeedData ceed_data,
Expand All @@ -24,7 +24,7 @@ PetscErrorCode PDESolver(CeedData ceed_data, VecType vec_type, SNES snes,
PetscErrorCode ComputeL2Error(CeedData ceed_data, Vec U, CeedVector target,
CeedScalar *l2_error_u, CeedScalar *l2_error_p,
OperatorApplyContext op_apply_ctx);
PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed,
PetscErrorCode PrintOutput(Ceed ceed,
CeedMemType mem_type_backend,
SNES snes, KSP ksp,
Vec U, CeedScalar l2_error_u,
Expand Down
18 changes: 9 additions & 9 deletions examples/Hdiv-mixed/include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
// Application context from user command line options
typedef struct AppCtx_ *AppCtx;
struct AppCtx_ {
MPI_Comm comm;
// Degree of polynomial (1 only), extra quadrature pts
PetscInt degree;
PetscInt q_extra;
// For applying traction BCs
PetscInt bc_traction_count;
PetscInt bc_traction_faces[16];
PetscScalar bc_traction_vector[16][3];
PetscInt bc_pressure_count;
PetscInt bc_pressure_faces[16];
PetscScalar bc_pressure_vector[16][3];
// Problem type arguments
PetscFunctionList problems;
char problem_name[PETSC_MAX_PATH_LEN];
Expand All @@ -23,7 +24,7 @@ struct AppCtx_ {
// libCEED data struct
typedef struct CeedData_ *CeedData;
struct CeedData_ {
CeedBasis basis_x, basis_u, basis_p;
CeedBasis basis_x, basis_u, basis_p, basis_u_face;
CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i,
elem_restr_p;
CeedQFunction qf_residual, qf_jacobian, qf_error;
Expand Down Expand Up @@ -72,13 +73,12 @@ struct OperatorApplyContext_ {

// Problem specific data
typedef struct {
CeedQFunctionUser setup_rhs, residual, jacobian, setup_error,
setup_true, setup_face_geo;
const char *setup_rhs_loc, *residual_loc, *jacobian_loc,
*setup_error_loc, *setup_true_loc, *setup_face_geo_loc;
CeedQFunctionUser force, residual, jacobian, error,
setup_true, bc_pressure;
const char *force_loc, *residual_loc, *jacobian_loc,
*error_loc, *setup_true_loc, *bc_pressure_loc;
CeedQuadMode quadrature_mode;
CeedInt elem_node, dim, q_data_size_face;
PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics);

} ProblemData;

Expand Down
18 changes: 11 additions & 7 deletions examples/Hdiv-mixed/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
//
// Build with: make
// Run with:
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4
// ./main -pc_type svd -problem darcy3d -dm_plex_dim 3 -dm_plex_box_faces 4,4,4
// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4
// ./main -pc_type svd -problem darcy3d -dm_plex_dim 3 -dm_plex_box_faces 4,4,4
// ./main -pc_type svd -problem darcy3d -dm_plex_filename /path to the mesh file
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1
// ./main -pc_type svd -problem darcy2d -dm_plex_dim 2 -dm_plex_box_faces 4,4 -bc_pressure 1,2,3,4
const char help[] = "Solve H(div)-mixed problem using PETSc and libCEED\n";

#include "main.h"
Expand Down Expand Up @@ -62,7 +64,8 @@ int main(int argc, char **argv) {

// -- Process general command line options
MPI_Comm comm = PETSC_COMM_WORLD;
PetscCall( ProcessCommandLineOptions(comm, app_ctx) );
app_ctx->comm = comm;
PetscCall( ProcessCommandLineOptions(app_ctx) );

// ---------------------------------------------------------------------------
// Choose the problem from the list of registered problems
Expand Down Expand Up @@ -107,7 +110,7 @@ int main(int argc, char **argv) {


// ---------------------------------------------------------------------------
// Create local RHS vector
// Create local Force vector
// ---------------------------------------------------------------------------
Vec F_loc;
PetscInt F_loc_size;
Expand Down Expand Up @@ -147,9 +150,10 @@ int main(int argc, char **argv) {
SNES snes;
KSP ksp;
Vec U;
op_apply_ctx->comm = comm;
PetscCall( SNESCreate(comm, &snes) );
PetscCall( SNESGetKSP(snes, &ksp) );
PetscCall( SetupCommonCtx(comm, dm, ceed, ceed_data, op_apply_ctx) );
PetscCall( SetupCommonCtx(dm, ceed, ceed_data, op_apply_ctx) );
PetscCall( PDESolver(ceed_data, vec_type, snes, ksp, F, &U, op_apply_ctx) );
//VecView(U, PETSC_VIEWER_STDOUT_WORLD);

Expand All @@ -163,7 +167,7 @@ int main(int argc, char **argv) {
// ---------------------------------------------------------------------------
// Print output results
// ---------------------------------------------------------------------------
PetscCall( PrintOutput(comm, ceed, mem_type_backend,
PetscCall( PrintOutput(ceed, mem_type_backend,
snes, ksp, U, l2_error_u, l2_error_p, app_ctx) );

// ---------------------------------------------------------------------------
Expand Down
25 changes: 12 additions & 13 deletions examples/Hdiv-mixed/problems/darcy2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
/// @file
/// Utility functions for setting up Darcy problem in 2D

#include "../include/setup-libceed.h"
#include "../include/register-problem.h"
#include "../qfunctions/darcy-rhs2d.h"
#include "../qfunctions/darcy-force2d.h"
#include "../qfunctions/darcy-mass2d.h"
#include "../qfunctions/darcy-error2d.h"
#include "../qfunctions/face-geo2d.h"
#include "../qfunctions/pressure-boundary2d.h"

// Hdiv_DARCY2D is registered in cl-option.c
PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx) {
Expand All @@ -39,16 +38,16 @@ PetscErrorCode Hdiv_DARCY2D(ProblemData *problem_data, void *ctx) {
problem_data->elem_node = 4;
problem_data->q_data_size_face = 3;
problem_data->quadrature_mode = CEED_GAUSS;
problem_data->setup_rhs = SetupDarcyRhs2D;
problem_data->setup_rhs_loc = SetupDarcyRhs2D_loc;
problem_data->residual = SetupDarcyMass2D;
problem_data->residual_loc = SetupDarcyMass2D_loc;
problem_data->jacobian = SetupJacobianDarcyMass2D;
problem_data->jacobian_loc = SetupJacobianDarcyMass2D_loc;
problem_data->setup_error = SetupDarcyError2D;
problem_data->setup_error_loc = SetupDarcyError2D_loc;
problem_data->setup_face_geo = SetupFaceGeo2D;
problem_data->setup_face_geo_loc = SetupFaceGeo2D_loc;
problem_data->force = DarcyForce2D;
problem_data->force_loc = DarcyForce2D_loc;
problem_data->residual = DarcyMass2D;
problem_data->residual_loc = DarcyMass2D_loc;
problem_data->jacobian = JacobianDarcyMass2D;
problem_data->jacobian_loc = JacobianDarcyMass2D_loc;
problem_data->error = DarcyError2D;
problem_data->error_loc = DarcyError2D_loc;
problem_data->bc_pressure = BCPressure2D;
problem_data->bc_pressure_loc = BCPressure2D_loc;

// ------------------------------------------------------
// Command line Options
Expand Down
25 changes: 12 additions & 13 deletions examples/Hdiv-mixed/problems/darcy3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
/// @file
/// Utility functions for setting up Darcy problem in 3D

#include "../include/setup-libceed.h"
#include "../include/register-problem.h"
#include "../qfunctions/darcy-rhs3d.h"
#include "../qfunctions/darcy-force3d.h"
#include "../qfunctions/darcy-mass3d.h"
#include "../qfunctions/darcy-error3d.h"
#include "../qfunctions/face-geo3d.h"
#include "../qfunctions/pressure-boundary3d.h"

// Hdiv_DARCY3D is registered in cl-option.c
PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx) {
Expand All @@ -39,16 +38,16 @@ PetscErrorCode Hdiv_DARCY3D(ProblemData *problem_data, void *ctx) {
problem_data->elem_node = 8;
problem_data->q_data_size_face = 4;
problem_data->quadrature_mode = CEED_GAUSS;
problem_data->setup_rhs = SetupDarcyRhs3D;
problem_data->setup_rhs_loc = SetupDarcyRhs3D_loc;
problem_data->residual = SetupDarcyMass3D;
problem_data->residual_loc = SetupDarcyMass3D_loc;
problem_data->jacobian = SetupJacobianDarcyMass3D;
problem_data->jacobian_loc = SetupJacobianDarcyMass3D_loc;
problem_data->setup_error = SetupDarcyError3D;
problem_data->setup_error_loc = SetupDarcyError3D_loc;
problem_data->setup_face_geo = SetupFaceGeo3D;
problem_data->setup_face_geo_loc = SetupFaceGeo3D_loc;
problem_data->force = DarcyForce3D;
problem_data->force_loc = DarcyForce3D_loc;
problem_data->residual = DarcyMass3D;
problem_data->residual_loc = DarcyMass3D_loc;
problem_data->jacobian = JacobianDarcyMass3D;
problem_data->jacobian_loc = JacobianDarcyMass3D_loc;
problem_data->error = DarcyError3D;
problem_data->error_loc = DarcyError3D_loc;
problem_data->bc_pressure = BCPressure3D;
problem_data->bc_pressure_loc = BCPressure3D_loc;
// ------------------------------------------------------
// Command line Options
// ------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions examples/Hdiv-mixed/qfunctions/darcy-error2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
// -----------------------------------------------------------------------------
// Compuet error
// -----------------------------------------------------------------------------
CEED_QFUNCTION(SetupDarcyError2D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
CEED_QFUNCTION(DarcyError2D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
// *INDENT-OFF*
// Inputs
const CeedScalar (*w) = in[0],
Expand Down
6 changes: 3 additions & 3 deletions examples/Hdiv-mixed/qfunctions/darcy-error3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ CEED_QFUNCTION_HELPER CeedScalar ComputeDetMat(const CeedScalar A[3][3]) {
// -----------------------------------------------------------------------------
// Compuet error
// -----------------------------------------------------------------------------
CEED_QFUNCTION(SetupDarcyError3D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
CEED_QFUNCTION(DarcyError3D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
// *INDENT-OFF*
// Inputs
const CeedScalar (*w) = in[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// testbed platforms, in support of the nation's exascale computing imperative.

/// @file
/// RHS of Darcy problem 2D (quad element) using PETSc
/// Force of Darcy problem 2D (quad element) using PETSc

#ifndef DARCY_RHS2D_H
#define DARCY_RHS2D_H
#ifndef DARCY_FORCE2D_H
#define DARCY_FORCE2D_H

#include <math.h>

Expand All @@ -27,24 +27,26 @@
#endif
// -----------------------------------------------------------------------------
// Strong form:
// u = -\grad(p)
// \div(u) = f
// u = -\grad(p) on \Omega
// \div(u) = f on \Omega
// p = p0 on \Gamma_D
// u.n = g on \Gamma_N
// Weak form: Find (u,p) \in VxQ (V=H(div), Q=L^2) on \Omega
// (u, v) - (p, \div(v)) = -<p, v\cdot n>
// (v, u) - (\div(v), p) = -<v, p0 n>_{\Gamma_D}
// -(q, \div(u)) = -(q, f)
// This QFunction sets up the rhs and true solution for the above problem
// This QFunction sets up the force and true solution for the above problem
// Inputs:
// x : interpolation of the physical coordinate
// w : weight of quadrature
// J : dx/dX. x physical coordinate, X reference coordinate [-1,1]^dim
//
// Output:
// rhs_u : which is 0.0 for this problem
// rhs_p : -(q, f) = -\int( q * f * w*detJ)dx
// force_u : which is 0.0 for this problem (-<v, p0 n> is in pressure-boundary qfunction)
// force_p : -(q, f) = -\int( q * f * w*detJ)dx
// -----------------------------------------------------------------------------
CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
CEED_QFUNCTION(DarcyForce2D)(void *ctx, const CeedInt Q,
const CeedScalar *const *in,
CeedScalar *const *out) {
// *INDENT-OFF*
// Inputs
const CeedScalar (*coords) = in[0],
Expand All @@ -63,8 +65,8 @@ CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q,
{dxdX[0][1][i], dxdX[1][1][i]}};
const CeedScalar detJ = J[1][1]*J[0][0] - J[1][0]*J[0][1];
// *INDENT-ON*
CeedScalar pe = sin(M_PI*x) * sin(M_PI*y);
CeedScalar ue[2] = {-M_PI*cos(M_PI*x) *sin(M_PI*y), -M_PI*sin(M_PI*x) *cos(M_PI*y)};
CeedScalar pe = sin(M_PI*x) * sin(M_PI*y) + M_PI*x*y;
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};
CeedScalar f = 2*M_PI*M_PI*sin(M_PI*x)*sin(M_PI*y);

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

#endif //End of DARCY_RHS2D_H
#endif //End of DARCY_FORCE2D_H
Loading

0 comments on commit 82713b0

Please sign in to comment.