From 82713b0d2a05bb84dbf72faebe27ed0ff434538b Mon Sep 17 00:00:00 2001 From: rezgarshakeri Date: Mon, 13 Jun 2022 13:19:25 -0600 Subject: [PATCH] Pressure boundary condition added.Its qfunction doesn't get called. --- examples/Hdiv-mixed/basis/Hdiv-hex.h | 4 +- examples/Hdiv-mixed/basis/Hdiv-quad.h | 4 +- examples/Hdiv-mixed/include/cl-options.h | 4 +- .../Hdiv-mixed/include/register-problem.h | 2 +- examples/Hdiv-mixed/include/setup-boundary.h | 4 +- examples/Hdiv-mixed/include/setup-dm.h | 2 +- examples/Hdiv-mixed/include/setup-libceed.h | 2 +- examples/Hdiv-mixed/include/setup-solvers.h | 4 +- examples/Hdiv-mixed/include/structs.h | 18 +-- examples/Hdiv-mixed/main.c | 18 ++- examples/Hdiv-mixed/problems/darcy2d.c | 25 ++-- examples/Hdiv-mixed/problems/darcy3d.c | 25 ++-- .../Hdiv-mixed/qfunctions/darcy-error2d.h | 6 +- .../Hdiv-mixed/qfunctions/darcy-error3d.h | 6 +- .../{darcy-rhs2d.h => darcy-force2d.h} | 32 +++-- .../{darcy-rhs3d.h => darcy-force3d.h} | 34 ++--- examples/Hdiv-mixed/qfunctions/darcy-mass2d.h | 23 ++-- examples/Hdiv-mixed/qfunctions/darcy-mass3d.h | 23 ++-- examples/Hdiv-mixed/qfunctions/face-geo2d.h | 73 ---------- examples/Hdiv-mixed/qfunctions/face-geo3d.h | 87 ------------ .../qfunctions/pressure-boundary2d.h | 58 ++++++++ .../qfunctions/pressure-boundary3d.h | 57 ++++++++ examples/Hdiv-mixed/src/cl-options.c | 35 +---- examples/Hdiv-mixed/src/setup-boundary.c | 58 +++++++- examples/Hdiv-mixed/src/setup-libceed.c | 130 ++++++------------ examples/Hdiv-mixed/src/setup-solvers.c | 34 +++-- 26 files changed, 363 insertions(+), 405 deletions(-) rename examples/Hdiv-mixed/qfunctions/{darcy-rhs2d.h => darcy-force2d.h} (74%) rename examples/Hdiv-mixed/qfunctions/{darcy-rhs3d.h => darcy-force3d.h} (82%) delete mode 100644 examples/Hdiv-mixed/qfunctions/face-geo2d.h delete mode 100644 examples/Hdiv-mixed/qfunctions/face-geo3d.h create mode 100644 examples/Hdiv-mixed/qfunctions/pressure-boundary2d.h create mode 100644 examples/Hdiv-mixed/qfunctions/pressure-boundary3d.h diff --git a/examples/Hdiv-mixed/basis/Hdiv-hex.h b/examples/Hdiv-mixed/basis/Hdiv-hex.h index a01b1a3ef3..e14b873dfb 100644 --- a/examples/Hdiv-mixed/basis/Hdiv-hex.h +++ b/examples/Hdiv-mixed/basis/Hdiv-hex.h @@ -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. @@ -159,4 +161,4 @@ static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, } } - +#endif // Hdiv_hex_h \ No newline at end of file diff --git a/examples/Hdiv-mixed/basis/Hdiv-quad.h b/examples/Hdiv-mixed/basis/Hdiv-quad.h index da1ecc1204..41086feb80 100644 --- a/examples/Hdiv-mixed/basis/Hdiv-quad.h +++ b/examples/Hdiv-mixed/basis/Hdiv-quad.h @@ -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. @@ -84,4 +86,4 @@ static void HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, } } - +#endif // Hdiv_quad_h diff --git a/examples/Hdiv-mixed/include/cl-options.h b/examples/Hdiv-mixed/include/cl-options.h index 1bfe386fb8..c6b6cbd53f 100644 --- a/examples/Hdiv-mixed/include/cl-options.h +++ b/examples/Hdiv-mixed/include/cl-options.h @@ -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 diff --git a/examples/Hdiv-mixed/include/register-problem.h b/examples/Hdiv-mixed/include/register-problem.h index e1d89f3528..14cd87973d 100644 --- a/examples/Hdiv-mixed/include/register-problem.h +++ b/examples/Hdiv-mixed/include/register-problem.h @@ -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); diff --git a/examples/Hdiv-mixed/include/setup-boundary.h b/examples/Hdiv-mixed/include/setup-boundary.h index 7268c0fc81..59b952df04 100644 --- a/examples/Hdiv-mixed/include/setup-boundary.h +++ b/examples/Hdiv-mixed/include/setup-boundary.h @@ -5,7 +5,7 @@ #include #include #include -#include "../include/structs.h" +#include "structs.h" // --------------------------------------------------------------------------- // Create boundary label @@ -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 diff --git a/examples/Hdiv-mixed/include/setup-dm.h b/examples/Hdiv-mixed/include/setup-dm.h index 48f2a83fb2..a7cf4a4685 100644 --- a/examples/Hdiv-mixed/include/setup-dm.h +++ b/examples/Hdiv-mixed/include/setup-dm.h @@ -5,7 +5,7 @@ #include #include #include -#include "../include/structs.h" +#include "structs.h" // --------------------------------------------------------------------------- // Set-up DM diff --git a/examples/Hdiv-mixed/include/setup-libceed.h b/examples/Hdiv-mixed/include/setup-libceed.h index ad8f53d705..21f76acc86 100644 --- a/examples/Hdiv-mixed/include/setup-libceed.h +++ b/examples/Hdiv-mixed/include/setup-libceed.h @@ -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); diff --git a/examples/Hdiv-mixed/include/setup-solvers.h b/examples/Hdiv-mixed/include/setup-solvers.h index 7ad8009a07..5cace9bf2a 100644 --- a/examples/Hdiv-mixed/include/setup-solvers.h +++ b/examples/Hdiv-mixed/include/setup-solvers.h @@ -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, @@ -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, diff --git a/examples/Hdiv-mixed/include/structs.h b/examples/Hdiv-mixed/include/structs.h index 30a3019d39..be20ae4cc8 100644 --- a/examples/Hdiv-mixed/include/structs.h +++ b/examples/Hdiv-mixed/include/structs.h @@ -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]; @@ -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; @@ -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; diff --git a/examples/Hdiv-mixed/main.c b/examples/Hdiv-mixed/main.c index 4070238115..72aac1a735 100644 --- a/examples/Hdiv-mixed/main.c +++ b/examples/Hdiv-mixed/main.c @@ -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" @@ -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 @@ -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; @@ -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); @@ -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) ); // --------------------------------------------------------------------------- diff --git a/examples/Hdiv-mixed/problems/darcy2d.c b/examples/Hdiv-mixed/problems/darcy2d.c index d8aaa07a8f..84000337bd 100644 --- a/examples/Hdiv-mixed/problems/darcy2d.c +++ b/examples/Hdiv-mixed/problems/darcy2d.c @@ -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) { @@ -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 diff --git a/examples/Hdiv-mixed/problems/darcy3d.c b/examples/Hdiv-mixed/problems/darcy3d.c index ac3f9b8632..79a5d69ca3 100644 --- a/examples/Hdiv-mixed/problems/darcy3d.c +++ b/examples/Hdiv-mixed/problems/darcy3d.c @@ -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) { @@ -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 // ------------------------------------------------------ diff --git a/examples/Hdiv-mixed/qfunctions/darcy-error2d.h b/examples/Hdiv-mixed/qfunctions/darcy-error2d.h index e6e7940e03..ff116bc9e7 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-error2d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-error2d.h @@ -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], diff --git a/examples/Hdiv-mixed/qfunctions/darcy-error3d.h b/examples/Hdiv-mixed/qfunctions/darcy-error3d.h index 6ef1afeca1..e647bd8999 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-error3d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-error3d.h @@ -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], diff --git a/examples/Hdiv-mixed/qfunctions/darcy-rhs2d.h b/examples/Hdiv-mixed/qfunctions/darcy-force2d.h similarity index 74% rename from examples/Hdiv-mixed/qfunctions/darcy-rhs2d.h rename to examples/Hdiv-mixed/qfunctions/darcy-force2d.h index 5abfbb4d05..3c9885655d 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-rhs2d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-force2d.h @@ -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 @@ -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)) = - +// (v, u) - (\div(v), p) = -_{\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 (- 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], @@ -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 @@ -82,4 +84,4 @@ CEED_QFUNCTION(SetupDarcyRhs2D)(void *ctx, const CeedInt Q, } // ----------------------------------------------------------------------------- -#endif //End of DARCY_RHS2D_H +#endif //End of DARCY_FORCE2D_H diff --git a/examples/Hdiv-mixed/qfunctions/darcy-rhs3d.h b/examples/Hdiv-mixed/qfunctions/darcy-force3d.h similarity index 82% rename from examples/Hdiv-mixed/qfunctions/darcy-rhs3d.h rename to examples/Hdiv-mixed/qfunctions/darcy-force3d.h index 268aacf35e..5ad3eb4c5a 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-rhs3d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-force3d.h @@ -17,8 +17,8 @@ /// @file /// RHS of Darcy problem 3D (hex element) using PETSc -#ifndef DARCY_RHS3D_H -#define DARCY_RHS3D_H +#ifndef DARCY_FORCE3D_H +#define DARCY_FORCE3D_H #include @@ -44,24 +44,26 @@ CEED_QFUNCTION_HELPER CeedScalar ComputeDetMat(const CeedScalar A[3][3]) { // ----------------------------------------------------------------------------- // 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)) = - +// (v, u) - (\div(v), p) = -_{\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 (- is in pressure-boundary qfunction) +// force_p : -(q, f) = -\int( q * f * w*detJ)dx // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupDarcyRhs3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyForce3D)(void *ctx, const CeedInt Q, + const CeedScalar *const *in, + CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*coords) = in[0], @@ -81,10 +83,10 @@ CEED_QFUNCTION(SetupDarcyRhs3D)(void *ctx, const CeedInt Q, {dxdX[0][2][i], dxdX[1][2][i], dxdX[2][2][i]}}; const CeedScalar detJ = ComputeDetMat(J); // *INDENT-ON* - CeedScalar pe = sin(M_PI*x) * sin(M_PI*y) * sin(M_PI*z); - CeedScalar ue[3] = {-M_PI*cos(M_PI*x) *sin(M_PI*y) *sin(M_PI*z), - -M_PI*sin(M_PI*x) *cos(M_PI*y) *sin(M_PI*z), - -M_PI*sin(M_PI*x) *sin(M_PI*y) *cos(M_PI*z) + CeedScalar pe = sin(M_PI*x) * sin(M_PI*y) * sin(M_PI*z) + M_PI*x*y*z; + CeedScalar ue[3] = {-M_PI*cos(M_PI*x) *sin(M_PI*y) *sin(M_PI*z) - M_PI *y*z, + -M_PI*sin(M_PI*x) *cos(M_PI*y) *sin(M_PI*z) - M_PI *x*z, + -M_PI*sin(M_PI*x) *sin(M_PI*y) *cos(M_PI*z) - M_PI *x *y }; CeedScalar f = 3*M_PI*M_PI*sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z); @@ -106,4 +108,4 @@ CEED_QFUNCTION(SetupDarcyRhs3D)(void *ctx, const CeedInt Q, } // ----------------------------------------------------------------------------- -#endif //End of DARCY_RHS3D_H +#endif //End of DARCY_FORCE3D_H diff --git a/examples/Hdiv-mixed/qfunctions/darcy-mass2d.h b/examples/Hdiv-mixed/qfunctions/darcy-mass2d.h index 95cdc5d66d..9f9f16d8eb 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-mass2d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-mass2d.h @@ -24,10 +24,12 @@ // ----------------------------------------------------------------------------- // 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)) = - +// (v, u) - (\div(v), p) = -_{\Gamma_D} // -(q, \div(u)) = -(q, f) // This QFunction setup the mixed form of the above equation // Inputs: @@ -48,9 +50,12 @@ // Note we need to apply Piola map on the basis_u, which is J*u/detJ // So (v,u) = \int (v^T * u detJ*w) ==> \int (v^T J^T*J*u*w/detJ) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupDarcyMass2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +// ----------------------------------------------------------------------------- +// Residual evaluation for Darcy problem +// ----------------------------------------------------------------------------- +CEED_QFUNCTION(DarcyMass2D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, + CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*w) = in[0], @@ -102,9 +107,9 @@ CEED_QFUNCTION(SetupDarcyMass2D)(void *ctx, CeedInt Q, // ----------------------------------------------------------------------------- // Jacobian evaluation for Darcy problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupJacobianDarcyMass2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(JacobianDarcyMass2D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, + CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*w) = in[0], diff --git a/examples/Hdiv-mixed/qfunctions/darcy-mass3d.h b/examples/Hdiv-mixed/qfunctions/darcy-mass3d.h index bf1a27dc74..198e09dc6a 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-mass3d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-mass3d.h @@ -40,10 +40,12 @@ CEED_QFUNCTION_HELPER CeedScalar ComputeDetMat(const CeedScalar A[3][3]) { // ----------------------------------------------------------------------------- // 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)) = - +// (v, u) - (\div(v), p) = -_{\Gamma_D} // -(q, \div(u)) = -(q, f) // This QFunction setup the mixed form of the above equation // Inputs: @@ -64,9 +66,12 @@ CEED_QFUNCTION_HELPER CeedScalar ComputeDetMat(const CeedScalar A[3][3]) { // Note we need to apply Piola map on the basis_u, which is J*u/detJ // So (v,u) = \int (v^T * u detJ*w) ==> \int (v^T J^T*J*u*w/detJ) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupDarcyMass3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +// ----------------------------------------------------------------------------- +// Residual evaluation for Darcy problem +// ----------------------------------------------------------------------------- +CEED_QFUNCTION(DarcyMass3D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, + CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*w) = in[0], @@ -118,9 +123,9 @@ CEED_QFUNCTION(SetupDarcyMass3D)(void *ctx, CeedInt Q, // ----------------------------------------------------------------------------- // Jacobian evaluation for Darcy problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupJacobianDarcyMass3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(JacobianDarcyMass3D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, + CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*w) = in[0], diff --git a/examples/Hdiv-mixed/qfunctions/face-geo2d.h b/examples/Hdiv-mixed/qfunctions/face-geo2d.h deleted file mode 100644 index 930c1c5a7b..0000000000 --- a/examples/Hdiv-mixed/qfunctions/face-geo2d.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. -// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. -// -// SPDX-License-Identifier: BSD-2-Clause -// -// This file is part of CEED: http://github.com/ceed - -/// @file -/// Geometric factors (2D) using PETSc - -#ifndef face_geo_2d_h -#define face_geo_2d_h - -#include -// ***************************************************************************** -// This QFunction sets up the geometric factor required for integration when -// reference coordinates are in 1D and the physical coordinates are in 2D -// -// Reference (parent) 1D coordinates: X -// Physical (current) 2D coordinates: x -// Change of coordinate vector: -// J1 = dx_1/dX -// J2 = dx_2/dX -// -// detJb is the magnitude of (J1,J2) -// -// All quadrature data is stored in 3 field vector of quadrature data. -// -// We require the determinant of the Jacobian to properly compute integrals of -// the form: int( u v ) -// -// Stored: w detJb -// in q_data_face[0] -// -// Normal vector is given by the cross product of (J1,J2)/detJ and ẑ -// -// Stored: (J1,J2,0) x (0,0,1) / detJb -// in q_data_face[1:2] as -// (detJb^-1) * [ J2 ] -// [-J1 ] -// -// ***************************************************************************** -CEED_QFUNCTION(SetupFaceGeo2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, CeedScalar *const *out) { - // *INDENT-OFF* - // Inputs - const CeedScalar (*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0], - (*w) = in[1]; - // Outputs - CeedScalar (*q_data_face)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; - // *INDENT-ON* - - CeedPragmaSIMD - // Quadrature Point Loop - for (CeedInt i=0; i -// ***************************************************************************** -// This QFunction sets up the geometric factor required for integration when -// reference coordinates are in 1D and the physical coordinates are in 2D -// -// Reference (parent) 1D coordinates: X -// Physical (current) 2D coordinates: x -// Change of coordinate vector: -// J1 = dx_1/dX -// J2 = dx_2/dX -// -// detJb is the magnitude of (J1,J2) -// -// All quadrature data is stored in 3 field vector of quadrature data. -// -// We require the determinant of the Jacobian to properly compute integrals of -// the form: int( u v ) -// -// Stored: w detJb -// in q_data_face[0] -// -// Normal vector is given by the cross product of (J1,J2)/detJ and ẑ -// -// Stored: (J1,J2,0) x (0,0,1) / detJb -// in q_data_face[1:2] as -// (detJb^-1) * [ J2 ] -// [-J1 ] -// -// ***************************************************************************** -CEED_QFUNCTION(SetupFaceGeo3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, CeedScalar *const *out) { - // *INDENT-OFF* - // Inputs - const CeedScalar (*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0], - (*w) = in[1]; - // Outputs - CeedScalar (*q_data_face)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; - // *INDENT-OFF* - - CeedPragmaSIMD - // Quadrature Point Loop - for (CeedInt i=0; i_{\Gamma_D} +// -(q, \div(u)) = -(q, f) +// This QFunction sets up the pressure boundary conditions : -_{\Gamma_D} +// Inputs: +// w : weight of quadrature +// p0 : pressure value on the boundary +// +// Output: +// v : p0 * N * w +// Note that the Piola map of the H(div) basis and physical normal "n" got canceled +// and we need to multiply by the reference normal "N" on each face +// ----------------------------------------------------------------------------- +CEED_QFUNCTION(BCPressure2D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, CeedScalar *const *out) { + // *INDENT-OFF* + // Inputs + const CeedScalar (*w) = in[0]; + // Outputs + CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + // *INDENT-ON* + + // User context + CeedPragmaSIMD + // Quadrature Point Loop + for (CeedInt i=0; i_{\Gamma_D} +// -(q, \div(u)) = -(q, f) +// This QFunction sets up the pressure boundary conditions : -_{\Gamma_D} +// Inputs: +// w : weight of quadrature +// p0 : pressure value on the boundary +// +// Output: +// v : p0 * N * w +// Note that the Piola map of the H(div) basis and physical normal "n" got canceled +// and we need to multiply by the reference normal "N" on each face +// ----------------------------------------------------------------------------- +CEED_QFUNCTION(BCPressure3D)(void *ctx, CeedInt Q, + const CeedScalar *const *in, CeedScalar *const *out) { + // *INDENT-OFF* + // Inputs + const CeedScalar (*w) = in[0]; + // Outputs + CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + // *INDENT-OFF* + + // User context + CeedPragmaSIMD + // Quadrature Point Loop + for (CeedInt i=0; icomm, NULL, "H(div) examples in PETSc with libCEED", + NULL); PetscCall( PetscOptionsFList("-problem", "Problem to solve", NULL, app_ctx->problems, @@ -43,32 +44,10 @@ PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx) { app_ctx->q_extra = 0; PetscCall( PetscOptionsInt("-q_extra", "Number of extra quadrature points", NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL) ); - - // Neumann boundary conditions - app_ctx->bc_traction_count = 16; - PetscCall( PetscOptionsIntArray("-bc_traction", - "Face IDs to apply traction (Neumann) BC", - NULL, app_ctx->bc_traction_faces, - &app_ctx->bc_traction_count, NULL) ); - // Set vector for each traction BC - for (PetscInt i = 0; i < app_ctx->bc_traction_count; i++) { - // Traction vector - char option_name[25]; - for (PetscInt j = 0; j < 3; j++) - app_ctx->bc_traction_vector[i][j] = 0.; - - snprintf(option_name, sizeof option_name, "-bc_traction_%d", - app_ctx->bc_traction_faces[i]); - PetscInt max_n = 3; - PetscBool set = false; - PetscCall( PetscOptionsScalarArray(option_name, - "Traction vector for constrained face", NULL, - app_ctx->bc_traction_vector[i], &max_n, &set) ); - - if (!set) - SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, - "Traction vector must be set for all traction boundary conditions."); - } + app_ctx->bc_pressure_count = 16; + PetscCall( PetscOptionsIntArray("-bc_pressure", + "Face IDs to apply pressure BC", + NULL, app_ctx->bc_pressure_faces, &app_ctx->bc_pressure_count, NULL) ); PetscOptionsEnd(); diff --git a/examples/Hdiv-mixed/src/setup-boundary.c b/examples/Hdiv-mixed/src/setup-boundary.c index d5f6a31ced..0130b67242 100644 --- a/examples/Hdiv-mixed/src/setup-boundary.c +++ b/examples/Hdiv-mixed/src/setup-boundary.c @@ -41,6 +41,53 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm) { PetscFunctionReturn(0); } +// --------------------------------------------------------------------------- +// Add Neumann boundaries to DM +// --------------------------------------------------------------------------- +PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, + AppCtx app_ctx, ProblemData *problem_data, DM dm) { + PetscInt dim; + CeedQFunction qf_pressure; + CeedOperator op_pressure; + + PetscFunctionBeginUser; + + PetscCall( DMGetDimension(dm, &dim) ); + + if (app_ctx->bc_pressure_count > 0) { + DMLabel domain_label; + PetscCall(DMGetLabel(dm, "Face Sets", &domain_label)); + // Compute contribution on each boundary face + for (CeedInt i = 0; i < app_ctx->bc_pressure_count; i++) { + + CeedQFunctionCreateInterior(ceed, 1, problem_data->bc_pressure, + problem_data->bc_pressure_loc, &qf_pressure); + + CeedQFunctionAddInput(qf_pressure, "weight", 1, CEED_EVAL_WEIGHT); + CeedQFunctionAddOutput(qf_pressure, "v", dim, CEED_EVAL_INTERP); + + // -- Apply operator + CeedOperatorCreate(ceed, qf_pressure, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, + &op_pressure); + CeedOperatorSetField(op_pressure, "weight", CEED_ELEMRESTRICTION_NONE, + ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_pressure, "v", ceed_data->elem_restr_u, + ceed_data->basis_u_face, CEED_VECTOR_ACTIVE); + // -- Add to composite operator + CeedCompositeOperatorAddSub(ceed_data->op_residual, op_pressure); + printf("----------------------------------------- \n"); + printf("setup-boundary.c: Add bc_pressure operator to residual\n"); + printf("----------------------------------------- \n"); + CeedOperatorView(ceed_data->op_residual, stdout); + // -- Cleanup + CeedQFunctionDestroy(&qf_pressure); + CeedOperatorDestroy(&op_pressure); + } + } + + PetscFunctionReturn(0); +} + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif @@ -57,14 +104,13 @@ PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, PetscFunctionBeginUser; if (dim == 2) { - u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y); - u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y); + u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y) - M_PI*y; + u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y) - M_PI*x; } else { - u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y) *sin(M_PI*z); - u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y) *sin(M_PI*z); - u[2] = -M_PI*sin(M_PI*x) *sin(M_PI*y) *cos(M_PI*z); + u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y) *sin(M_PI*z) - M_PI*y*z; + u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y) *sin(M_PI*z) - M_PI*x*z; + u[2] = -M_PI*sin(M_PI*x) *sin(M_PI*y) *cos(M_PI*z) - M_PI*x*y; } - PetscFunctionReturn(0); } diff --git a/examples/Hdiv-mixed/src/setup-libceed.c b/examples/Hdiv-mixed/src/setup-libceed.c index dd7819de17..0d2d71d03a 100644 --- a/examples/Hdiv-mixed/src/setup-libceed.c +++ b/examples/Hdiv-mixed/src/setup-libceed.c @@ -1,4 +1,5 @@ #include "../include/setup-libceed.h" +#include "../include/setup-boundary.h" #include "../include/petsc-macros.h" #include "../basis/Hdiv-quad.h" #include "../basis/Hdiv-hex.h" @@ -29,6 +30,7 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data) { CeedBasisDestroy(&ceed_data->basis_x); CeedBasisDestroy(&ceed_data->basis_u); CeedBasisDestroy(&ceed_data->basis_p); + CeedBasisDestroy(&ceed_data->basis_u_face); // QFunctions CeedQFunctionDestroy(&ceed_data->qf_residual); CeedQFunctionDestroy(&ceed_data->qf_jacobian); @@ -160,8 +162,8 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, PetscInt c_start, c_end, num_elem; const PetscScalar *coordArray; CeedVector x_coord; - CeedQFunction qf_setup_rhs, qf_residual, qf_jacobian, qf_error; - CeedOperator op_setup_rhs, op_residual, op_jacobian, op_error; + CeedQFunction qf_force, qf_residual, qf_jacobian, qf_error; + CeedOperator op_force, op_residual, op_jacobian, op_error; PetscFunctionBeginUser; // --------------------------------------------------------------------------- @@ -170,7 +172,7 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, dim = problem_data->dim; num_comp_x = dim; num_comp_u = 1; // one vector dof - num_comp_p = 1; // one vector dof + num_comp_p = 1; // one scalar dof // Number of quadratures per element CeedInt num_qpts = PetscPowInt(Q, dim); // Pressure and velocity dof per element @@ -186,6 +188,10 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, L2BasisP0(dim, Q, q_ref, q_weights, interp_p, problem_data->quadrature_mode); CeedBasisCreateH1(ceed, CEED_TOPOLOGY_QUAD, num_comp_p, 1, num_qpts, interp_p, grad, q_ref,q_weights, &ceed_data->basis_p); + HdivBasisQuad(Q, q_ref, q_weights, interp_u, div, + CEED_GAUSS_LOBATTO); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, + interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); } else { HdivBasisHex(Q, q_ref, q_weights, interp_u, div, problem_data->quadrature_mode); CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, @@ -193,6 +199,9 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, L2BasisP0(dim, Q, q_ref, q_weights, interp_p, problem_data->quadrature_mode); CeedBasisCreateH1(ceed, CEED_TOPOLOGY_HEX, num_comp_p, 1, num_qpts, interp_p, grad, q_ref,q_weights, &ceed_data->basis_p); + HdivBasisHex(Q, q_ref, q_weights, interp_u, div, CEED_GAUSS_LOBATTO); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, + interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); } CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, @@ -235,31 +244,31 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, // --------------------------------------------------------------------------- CeedVectorCreate(ceed, num_elem*num_qpts*(dim+1), target); // Create the q-function that sets up the RHS and true solution - CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_rhs, - problem_data->setup_rhs_loc, &qf_setup_rhs); - CeedQFunctionAddInput(qf_setup_rhs, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_setup_rhs, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_setup_rhs, "dx", dim*dim, CEED_EVAL_GRAD); - CeedQFunctionAddOutput(qf_setup_rhs, "rhs_u", dim, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_setup_rhs, "rhs_p", 1, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_setup_rhs, "true_soln", dim+1, CEED_EVAL_NONE); + CeedQFunctionCreateInterior(ceed, 1, problem_data->force, + problem_data->force_loc, &qf_force); + CeedQFunctionAddInput(qf_force, "x", num_comp_x, CEED_EVAL_INTERP); + CeedQFunctionAddInput(qf_force, "weight", 1, CEED_EVAL_WEIGHT); + CeedQFunctionAddInput(qf_force, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddOutput(qf_force, "rhs_u", dim, CEED_EVAL_INTERP); + CeedQFunctionAddOutput(qf_force, "rhs_p", 1, CEED_EVAL_INTERP); + CeedQFunctionAddOutput(qf_force, "true_soln", dim+1, CEED_EVAL_NONE); // Create the operator that builds the RHS and true solution - CeedOperatorCreate(ceed, qf_setup_rhs, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_setup_rhs); - CeedOperatorSetField(op_setup_rhs, "x", ceed_data->elem_restr_x, + CeedOperatorCreate(ceed, qf_force, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, + &op_force); + CeedOperatorSetField(op_force, "x", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "weight", CEED_ELEMRESTRICTION_NONE, + CeedOperatorSetField(op_force, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_rhs, "dx", ceed_data->elem_restr_x, + CeedOperatorSetField(op_force, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "rhs_u", ceed_data->elem_restr_u, + CeedOperatorSetField(op_force, "rhs_u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "rhs_p", ceed_data->elem_restr_p, + CeedOperatorSetField(op_force, "rhs_p", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "true_soln", ceed_data->elem_restr_U_i, + CeedOperatorSetField(op_force, "true_soln", ceed_data->elem_restr_U_i, CEED_BASIS_COLLOCATED, *target); // Setup RHS and true solution - CeedOperatorApply(op_setup_rhs, x_coord, force_ceed, CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(op_force, x_coord, force_ceed, CEED_REQUEST_IMMEDIATE); // --------------------------------------------------------------------------- // Persistent libCEED vectors @@ -304,7 +313,13 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ceed_data->basis_p, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_residual = qf_residual; - ceed_data->op_residual = op_residual; + CeedCompositeOperatorCreate(ceed, &ceed_data->op_residual); + CeedCompositeOperatorAddSub(ceed_data->op_residual, op_residual); + + // --------------------------------------------------------------------------- + // Add Pressure boundary condition. See setup-boundary.c + // --------------------------------------------------------------------------- + DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm); // Local jacobian evaluator // --------------------------------------------------------------------------- @@ -348,8 +363,8 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, // Setup Error Qfunction // --------------------------------------------------------------------------- // Create the q-function that sets up the error - CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_error, - problem_data->setup_error_loc, &qf_error); + CeedQFunctionCreateInterior(ceed, 1, problem_data->error, + problem_data->error_loc, &qf_error); CeedQFunctionAddInput(qf_error, "weight", 1, CEED_EVAL_WEIGHT); CeedQFunctionAddInput(qf_error, "dx", dim*dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_error, "u", dim, CEED_EVAL_INTERP); @@ -375,74 +390,9 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ceed_data->qf_error = qf_error; ceed_data->op_error = op_error; - // --------------------------------------------------------------------------- - // Dirichlet boundary conditions, if needed - // --------------------------------------------------------------------------- - //PetscCall( DMAddBoundariesDirichlet(dm) ); - // --------------------------------------------------------------------------- - // Traction boundary conditions, if needed - // --------------------------------------------------------------------------- - - // --- Setup - PetscCall( DMGetLabel(dm, "Face Sets", &domain_label) ); - - // -- Basis - CeedInt loc_num_elem_face, num_qpts_face, - q_data_size_face = problem_data->q_data_size_face; - CeedBasis basis_x_face; - height = 1; - CeedBasisCreateTensorH1Lagrange(ceed, dim - height, num_comp_x, 2, Q, - problem_data->quadrature_mode, &basis_x_face); - // ---- CEED Restriction - CeedElemRestriction elem_restr_x_face, elem_restr_qd_i_face; - num_qpts_face = CeedIntPow(Q, dim - height); - PetscCall( CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, 4, - &elem_restr_x_face) ); - - CeedElemRestrictionGetNumElements(elem_restr_x_face, &loc_num_elem_face); - CeedElemRestrictionCreateStrided(ceed, loc_num_elem_face, num_qpts_face, - q_data_size_face, - q_data_size_face*loc_num_elem_face*num_qpts_face, - CEED_STRIDES_BACKEND, &elem_restr_qd_i_face); - //printf("%d\n", loc_num_elem_face); - //CeedElemRestrictionView(elem_restr_x_face, stdout); - // ---- CEED Vector - CeedVector q_data_face; - CeedVectorCreate(ceed, q_data_size_face*loc_num_elem_face*num_qpts_face, - &q_data_face); - // -- QFunction - CeedQFunction qf_setup_face_geo; - CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_face_geo, - problem_data->setup_face_geo_loc, &qf_setup_face_geo); - CeedQFunctionAddInput(qf_setup_face_geo, "dx", num_comp_x*(dim-height), - CEED_EVAL_GRAD); - CeedQFunctionAddInput(qf_setup_face_geo, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddOutput(qf_setup_face_geo, "qdata face", q_data_size_face, - CEED_EVAL_NONE); - // -- Operator - CeedOperator op_setup_face_geo; - CeedOperatorCreate(ceed, qf_setup_face_geo, CEED_QFUNCTION_NONE, - CEED_QFUNCTION_NONE, &op_setup_face_geo); - CeedOperatorSetField(op_setup_face_geo, "dx", elem_restr_x_face, - basis_x_face, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_face_geo, "weight", CEED_ELEMRESTRICTION_NONE, - basis_x_face, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_face_geo, "qdata face", elem_restr_qd_i_face, - CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - // -- Compute the quadrature data - CeedOperatorApply(op_setup_face_geo, x_coord, q_data_face, - CEED_REQUEST_IMMEDIATE); - // -- Cleanup - CeedBasisDestroy(&basis_x_face); - CeedVectorDestroy(&q_data_face); - CeedElemRestrictionDestroy(&elem_restr_x_face); - CeedElemRestrictionDestroy(&elem_restr_qd_i_face); - CeedQFunctionDestroy(&qf_setup_face_geo); - CeedOperatorDestroy(&op_setup_face_geo); - - CeedQFunctionDestroy(&qf_setup_rhs); - CeedOperatorDestroy(&op_setup_rhs); + CeedQFunctionDestroy(&qf_force); + CeedOperatorDestroy(&op_force); CeedVectorDestroy(&x_coord); PetscFunctionReturn(0); diff --git a/examples/Hdiv-mixed/src/setup-solvers.c b/examples/Hdiv-mixed/src/setup-solvers.c index d72b6f6f26..ea7f4335c3 100644 --- a/examples/Hdiv-mixed/src/setup-solvers.c +++ b/examples/Hdiv-mixed/src/setup-solvers.c @@ -5,12 +5,11 @@ // ----------------------------------------------------------------------------- // Setup operator context data // ----------------------------------------------------------------------------- -PetscErrorCode SetupCommonCtx(MPI_Comm comm, DM dm, Ceed ceed, +PetscErrorCode SetupCommonCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext op_apply_ctx) { PetscFunctionBeginUser; - op_apply_ctx->comm = comm; op_apply_ctx->dm = dm; PetscCall( DMCreateLocalVector(dm, &op_apply_ctx->X_loc) ); PetscCall( VecDuplicate(op_apply_ctx->X_loc, &op_apply_ctx->Y_loc) ); @@ -73,10 +72,9 @@ PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx) { PetscFunctionBeginUser; // Use computed BCs - //PetscCall( VecZeroEntries(op_apply_ctx->X_loc) ); - //PetscCall( DMPlexInsertBoundaryValues(op_apply_ctx->dm, PETSC_TRUE, - // op_apply_ctx->X_loc, - // 1.0, NULL, NULL, NULL) ); + PetscCall( DMPlexInsertBoundaryValues(op_apply_ctx->dm, PETSC_TRUE, + op_apply_ctx->X_loc, + 1.0, NULL, NULL, NULL) ); // libCEED for local action of residual evaluator PetscCall( ApplyLocalCeedOp(X, Y, op_apply_ctx) ); @@ -140,9 +138,17 @@ PetscErrorCode PDESolver(CeedData ceed_data, VecType vec_type, SNES snes, // Set SNES residual evaluation function SetupResidualOperatorCtx(ceed_data, op_apply_ctx); + printf("----------------------------------------- \n"); + printf("setup-solver.c: Set SNES residual\n"); + printf("----------------------------------------- \n"); + CeedOperatorView(op_apply_ctx->op_apply, stdout); PetscCall( SNESSetFunction(snes, R, SNESFormResidual, op_apply_ctx) ); // -- SNES Jacobian SetupJacobianOperatorCtx(ceed_data, op_apply_ctx); + printf("----------------------------------------- \n"); + printf("setup-solver.c: Set SNES jacobian\n"); + printf("----------------------------------------- \n"); + CeedOperatorView(op_apply_ctx->op_apply, stdout); PetscCall( SNESSetJacobian(snes, mat_jacobian, mat_jacobian, SNESFormJacobian, op_apply_ctx) ); @@ -254,7 +260,7 @@ PetscErrorCode ComputeL2Error(CeedData ceed_data, Vec X, CeedVector target, // ----------------------------------------------------------------------------- // This function print the output // ----------------------------------------------------------------------------- -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, @@ -267,8 +273,8 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, char hostname[PETSC_MAX_PATH_LEN]; PetscCall( PetscGetHostName(hostname, sizeof hostname) ); PetscInt comm_size; - PetscCall( MPI_Comm_size(comm, &comm_size) ); - PetscCall( PetscPrintf(comm, + PetscCall( MPI_Comm_size(app_ctx->comm, &comm_size) ); + PetscCall( PetscPrintf(app_ctx->comm, "\n-- Mixed H(div) Example - libCEED + PETSc --\n" " MPI:\n" " Hostname : %s\n" @@ -280,7 +286,7 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, VecType vecType; PetscCall( VecGetType(U, &vecType) ); - PetscCall( PetscPrintf(comm, + PetscCall( PetscPrintf(app_ctx->comm, " PETSc:\n" " PETSc Vec Type : %s\n", vecType) ); @@ -288,7 +294,7 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, PetscInt U_l_size, U_g_size; PetscCall( VecGetSize(U, &U_g_size) ); PetscCall( VecGetLocalSize(U, &U_l_size) ); - PetscCall( PetscPrintf(comm, + PetscCall( PetscPrintf(app_ctx->comm, " Problem:\n" " Problem Name : %s\n" " Global nodes (u + p) : %" PetscInt_FMT "\n" @@ -305,7 +311,7 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, PetscCall( SNESGetType(snes, &snes_type) ); PetscCall( SNESGetConvergedReason(snes, &snes_reason) ); PetscCall( SNESGetFunctionNorm(snes, &snes_rnorm) ); - PetscCall( PetscPrintf(comm, + PetscCall( PetscPrintf(app_ctx->comm, " SNES:\n" " SNES Type : %s\n" " SNES Convergence : %s\n" @@ -328,7 +334,7 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, PetscCall( KSPGetConvergedReason(ksp, &ksp_reason) ); PetscCall( KSPGetIterationNumber(ksp, &ksp_its) ); PetscCall( KSPGetResidualNorm(ksp, &ksp_rnorm) ); - PetscCall( PetscPrintf(comm, + PetscCall( PetscPrintf(app_ctx->comm, " KSP:\n" " KSP Type : %s\n" " PC Type : %s\n" @@ -338,7 +344,7 @@ PetscErrorCode PrintOutput(MPI_Comm comm, Ceed ceed, ksp_type, pc_type, KSPConvergedReasons[ksp_reason], ksp_its, (double)ksp_rnorm ) ); - PetscCall( PetscPrintf(comm, + PetscCall( PetscPrintf(app_ctx->comm, " L2 Error (MMS):\n" " L2 error of u and p : %e, %e\n", (double)l2_error_u,