Skip to content

Commit

Permalink
make style
Browse files Browse the repository at this point in the history
  • Loading branch information
rezgarshakeri committed May 31, 2022
1 parent 05d7acf commit e56d551
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
3 changes: 2 additions & 1 deletion examples/Hdiv-mixed/include/boundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PetscErrorCode CreateBCLabel(DM dm, const char name[]);
// Add Dirichlet boundaries to DM
// ---------------------------------------------------------------------------
PetscErrorCode DMAddBoundariesDirichlet(DM dm);
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, const PetscReal coords[],
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t,
const PetscReal coords[],
PetscInt num_comp_u, PetscScalar *u, void *ctx);
#endif // boundary_h
29 changes: 15 additions & 14 deletions examples/Hdiv-mixed/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ int main(int argc, char **argv) {
// ---------------------------------------------------------------------------
{
PetscErrorCode (*p)(ProblemData *, void *);
PetscCall( PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name, &p) );
PetscCall( PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name,
&p) );
if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found",
app_ctx->problem_name);
PetscCall( (*p)(problem_data, &user) );
Expand Down Expand Up @@ -140,7 +141,7 @@ int main(int argc, char **argv) {
// ---------------------------------------------------------------------------
// -- Set up libCEED objects
PetscCall( SetupLibceed(dm, ceed, app_ctx, problem_data, U_g_size,
U_loc_size, ceed_data, rhs_ceed, &target) );
U_loc_size, ceed_data, rhs_ceed, &target) );
//CeedVectorView(rhs_ceed, "%12.8f", stdout);
// ---------------------------------------------------------------------------
// Gather RHS
Expand All @@ -167,9 +168,9 @@ int main(int argc, char **argv) {
// Operator
Mat mat;
PetscCall( MatCreateShell(comm, U_l_size, U_l_size, U_g_size, U_g_size,
user, &mat) );
user, &mat) );
PetscCall( MatShellSetOperation(mat, MATOP_MULT,
(void(*)(void))MatMult_Ceed) );
(void(*)(void))MatMult_Ceed) );
PetscCall( MatShellSetVecType(mat, vec_type) );

KSP ksp;
Expand All @@ -184,7 +185,7 @@ int main(int argc, char **argv) {
// ---------------------------------------------------------------------------
CeedScalar l2_error_u, l2_error_p;
PetscCall( ComputeError(user, U_g, target,
&l2_error_u, &l2_error_p) );
&l2_error_u, &l2_error_p) );

// ---------------------------------------------------------------------------
// Output results
Expand All @@ -198,15 +199,15 @@ int main(int argc, char **argv) {
PetscCall( KSPGetIterationNumber(ksp, &its) );
PetscCall( KSPGetResidualNorm(ksp, &rnorm) );
PetscCall( PetscPrintf(comm,
" KSP:\n"
" KSP Type : %s\n"
" KSP Convergence : %s\n"
" Total KSP Iterations : %" PetscInt_FMT "\n"
" Final rnorm : %e\n"
" L2 Error of u and p : %e, %e\n",
ksp_type, KSPConvergedReasons[reason], its,
(double)rnorm, (double)l2_error_u,
(double)l2_error_p) );
" KSP:\n"
" KSP Type : %s\n"
" KSP Convergence : %s\n"
" Total KSP Iterations : %" PetscInt_FMT "\n"
" Final rnorm : %e\n"
" L2 Error of u and p : %e, %e\n",
ksp_type, KSPConvergedReasons[reason], its,
(double)rnorm, (double)l2_error_u,
(double)l2_error_p) );

// ---------------------------------------------------------------------------
// Save solution (paraview)
Expand Down
12 changes: 7 additions & 5 deletions examples/Hdiv-mixed/src/boundary.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm) {
}
DMLabel label;
PetscCall( DMGetLabel(dm, name, &label) );
PetscCall( DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, face_ids, 0, 0, NULL,
(void(*)(void))BoundaryDirichletMMS, NULL, NULL, NULL) );

PetscCall( DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, face_ids, 0, 0,
NULL,
(void(*)(void))BoundaryDirichletMMS, NULL, NULL, NULL) );


PetscFunctionReturn(0);
}
Expand All @@ -46,7 +47,8 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm) {
// ---------------------------------------------------------------------------
// Boundary function for manufactured solution
// ---------------------------------------------------------------------------
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, const PetscReal coords[],
PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t,
const PetscReal coords[],
PetscInt num_comp_u, PetscScalar *u, void *ctx) {
PetscScalar x = coords[0];
PetscScalar y = coords[1];
Expand All @@ -62,7 +64,7 @@ PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, const PetscReal c
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);
}


PetscFunctionReturn(0);
}
24 changes: 12 additions & 12 deletions examples/Hdiv-mixed/src/cl-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx) {
PetscFunctionBeginUser;
// 1) darcy2d (Hdiv_DARCY2D is created in darcy2d.c)
PetscCall( PetscFunctionListAdd(&app_ctx->problems, "darcy2d",
Hdiv_DARCY2D) );
Hdiv_DARCY2D) );
// 2) darcy3d (Hdiv_DARCY3D is created in dacry3d.c)
PetscCall( PetscFunctionListAdd(&app_ctx->problems, "darcy3d",
Hdiv_DARCY3D) );
Hdiv_DARCY3D) );
// 3) darcy3d-prism

// 4) richard
Expand All @@ -46,24 +46,24 @@ PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx) {
PetscOptionsBegin(comm, NULL, "H(div) examples in PETSc with libCEED", NULL);

PetscCall( PetscOptionsFList("-problem", "Problem to solve", NULL,
app_ctx->problems,
app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name),
&problem_flag) );
app_ctx->problems,
app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name),
&problem_flag) );

app_ctx->degree = 1;
PetscCall( PetscOptionsInt("-degree", "Polynomial degree of finite elements",
NULL, app_ctx->degree, &app_ctx->degree, NULL) );
NULL, app_ctx->degree, &app_ctx->degree, NULL) );

app_ctx->q_extra = 0;
PetscCall( PetscOptionsInt("-q_extra", "Number of extra quadrature points",
NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL) );
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) );
"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
Expand All @@ -76,8 +76,8 @@ PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx) {
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) );
"Traction vector for constrained face", NULL,
app_ctx->bc_traction_vector[i], &max_n, &set) );

if (!set)
SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP,
Expand Down
8 changes: 5 additions & 3 deletions examples/Hdiv-mixed/src/matops.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) {

// Setup libCEED vectors
PetscCall( VecGetArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x,
&x_mem_type) );
&x_mem_type) );
PetscCall( VecGetArrayAndMemType(user->Y_loc, &y, &y_mem_type) );
CeedVectorSetArray(user->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
CeedVectorSetArray(user->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
Expand All @@ -28,7 +28,8 @@ PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) {
// Restore PETSc vectors
CeedVectorTakeArray(user->x_ceed, MemTypeP2C(x_mem_type), NULL);
CeedVectorTakeArray(user->y_ceed, MemTypeP2C(y_mem_type), NULL);
PetscCall( VecRestoreArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x) );
PetscCall( VecRestoreArrayReadAndMemType(user->X_loc,
(const PetscScalar **)&x) );
PetscCall( VecRestoreArrayAndMemType(user->Y_loc, &y) );

// Local-to-global
Expand Down Expand Up @@ -81,7 +82,8 @@ PetscErrorCode ComputeError(User user, Vec X, CeedVector target,
CEED_REQUEST_IMMEDIATE);
// Restore PETSc vector
CeedVectorTakeArray(user->x_ceed, MemTypeP2C(mem_type), NULL);
PetscCall( VecRestoreArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x) );
PetscCall( VecRestoreArrayReadAndMemType(user->X_loc,
(const PetscScalar **)&x) );
// Compute L2 error for each field
CeedInt c_start, c_end, dim, num_elem, num_qpts;
PetscCall( DMGetDimension(user->dm, &dim) );
Expand Down
16 changes: 8 additions & 8 deletions examples/Hdiv-mixed/src/setup-libceed.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height,
PetscFunctionBeginUser;

PetscCall( DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem,
&elem_size, &num_comp, &num_dof, &elem_restr_offsets) );
&elem_size, &num_comp, &num_dof, &elem_restr_offsets) );

CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp,
1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES,
Expand Down Expand Up @@ -91,15 +91,15 @@ PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm,
PetscCall( DMPlexGetHeightStratum(dm, 0, &c_start, &c_end) );
num_elem = c_end - c_start;
PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim),
&restr_indices_u) );
&restr_indices_u) );
PetscCall( PetscMalloc1(num_elem,&restr_indices_p) );
bool *orient_indices_u; // to flip the dof
PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), &orient_indices_u) );
for (p = 0, elem_offset = 0; p < num_elem; p++) {
PetscInt num_indices, *indices, faces_per_elem, dofs_per_face;
PetscCall( DMPlexGetClosureIndices(dm, section, section, p, PETSC_TRUE,
&num_indices, &indices, NULL, NULL) );
&num_indices, &indices, NULL, NULL) );

restr_indices_p[p] = indices[num_indices - 1];
PetscCall( DMPlexGetConeOrientation(dm, p, &ornt) );
// Get number of faces per element
Expand All @@ -117,7 +117,7 @@ PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm,
}
}
PetscCall( DMPlexRestoreClosureIndices(dm, section, section, p, PETSC_TRUE,
&num_indices, &indices, NULL, NULL) );
&num_indices, &indices, NULL, NULL) );
}
//if (elem_offset != num_elem*dim*PetscPowInt(P, dim))
// SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB,
Expand Down Expand Up @@ -206,10 +206,10 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx,
PetscInt value = 0;
// -- Coordinate restriction
PetscCall( CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label,
value, &ceed_data->elem_restr_x) );
value, &ceed_data->elem_restr_x) );
// -- Solution restriction
PetscCall( CreateRestrictionFromPlexOriented(ceed, dm, P,
&ceed_data->elem_restr_u, &ceed_data->elem_restr_p) );
&ceed_data->elem_restr_u, &ceed_data->elem_restr_p) );
// -- Geometric ceed_data restriction
PetscCall( DMPlexGetHeightStratum(dm, 0, &c_start, &c_end) );
num_elem = c_end - c_start;
Expand Down Expand Up @@ -357,7 +357,7 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx,
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) );
&elem_restr_x_face) );

CeedElemRestrictionGetNumElements(elem_restr_x_face, &loc_num_elem_face);
CeedElemRestrictionCreateStrided(ceed, loc_num_elem_face, num_qpts_face,
Expand Down

0 comments on commit e56d551

Please sign in to comment.