Skip to content

Commit

Permalink
Make file comments and PetscFunctionBegin/Return spacing consistent (C…
Browse files Browse the repository at this point in the history
  • Loading branch information
zatkins-dev authored Dec 2, 2023
1 parent 179e596 commit 98285ab
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 45 deletions.
6 changes: 0 additions & 6 deletions examples/petsc/bpsraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static PetscErrorCode CreateRestriction(Ceed ceed, const CeedInt mesh_elem[3], C
// Setup CEED restriction
CeedElemRestrictionCreate(ceed, num_elem, P * P * P, num_comp, 1, m_nodes[0] * m_nodes[1] * m_nodes[2] * num_comp, CEED_MEM_HOST, CEED_OWN_POINTER,
idx, elem_restr);

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand Down Expand Up @@ -228,7 +227,6 @@ static PetscErrorCode MatMult_Mass(Mat A, Vec X, Vec Y) {
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &op_apply_ctx));

// Global-to-local
Expand Down Expand Up @@ -266,7 +264,6 @@ static PetscErrorCode MatMult_Diff(Mat A, Vec X, Vec Y) {
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &op_apply_ctx));

// Global-to-local
Expand Down Expand Up @@ -294,7 +291,6 @@ static PetscErrorCode MatMult_Diff(Mat A, Vec X, Vec Y) {
PetscCall(VecScatterEnd(op_apply_ctx->g_to_g_D, X, Y, INSERT_VALUES, SCATTER_FORWARD));
PetscCall(VecScatterBegin(op_apply_ctx->l_to_g_0, op_apply_ctx->Y_loc, Y, ADD_VALUES, SCATTER_FORWARD));
PetscCall(VecScatterEnd(op_apply_ctx->l_to_g_0, op_apply_ctx->Y_loc, Y, ADD_VALUES, SCATTER_FORWARD));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -306,7 +302,6 @@ static PetscErrorCode ComputeErrorMax(OperatorApplyContext op_apply_ctx, CeedOpe
CeedSize length;

PetscFunctionBeginUser;

CeedVectorGetLength(target, &length);
CeedVectorCreate(op_apply_ctx->ceed, length, &collocated_error);

Expand Down Expand Up @@ -337,7 +332,6 @@ static PetscErrorCode ComputeErrorMax(OperatorApplyContext op_apply_ctx, CeedOpe

// Cleanup
CeedVectorDestroy(&collocated_error);

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand Down
3 changes: 0 additions & 3 deletions examples/petsc/dmswarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ PetscScalar EvalU_Sphere(PetscInt dim, const PetscScalar x[]) {

PetscErrorCode EvalU_Poly_proj(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt num_comp, PetscScalar *u, void *ctx) {
PetscFunctionBeginUser;

const PetscScalar f_x = EvalU_Poly(dim, x);

for (PetscInt c = 0; c < num_comp; c++) u[c] = (c + 1.0) * f_x;
Expand All @@ -310,7 +309,6 @@ PetscErrorCode EvalU_Poly_proj(PetscInt dim, PetscReal t, const PetscReal x[], P

PetscErrorCode EvalU_Tanh_proj(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt num_comp, PetscScalar *u, void *ctx) {
PetscFunctionBeginUser;

const PetscScalar f_x = EvalU_Tanh(dim, x);

for (PetscInt c = 0; c < num_comp; c++) u[c] = (c + 1.0) * f_x;
Expand All @@ -319,7 +317,6 @@ PetscErrorCode EvalU_Tanh_proj(PetscInt dim, PetscReal t, const PetscReal x[], P

PetscErrorCode EvalU_Sphere_proj(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt num_comp, PetscScalar *u, void *ctx) {
PetscFunctionBeginUser;

const PetscScalar f_x = EvalU_Sphere(dim, x);

for (PetscInt c = 0; c < num_comp; c++) u[c] = (c + 1.0) * f_x;
Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/areaproblemdata.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Problem data for area examples

#ifndef libceed_petsc_examples_area_problem_data_h
#define libceed_petsc_examples_area_problem_data_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/bpsproblemdata.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Problem data for BPs

#ifndef libceed_petsc_examples_bps_problem_data_h
#define libceed_petsc_examples_bps_problem_data_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/libceedsetup.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Setup functions for BPs

#ifndef libceed_petsc_examples_setup_h
#define libceed_petsc_examples_setup_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/matops.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Operations for PETSc MatShell

#ifndef libceed_petsc_examples_matops_h
#define libceed_petsc_examples_matops_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/petscutils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Utility functions for using PETSc with libCEED

#ifndef libceed_petsc_examples_utils_h
#define libceed_petsc_examples_utils_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/petscversion.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Petsc version check

#ifndef libceed_petsc_examples_version_h
#define libceed_petsc_examples_version_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/sphereproblemdata.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Problem data for BPS sphere examples

#ifndef libceed_petsc_examples_sphere_problem_data_h
#define libceed_petsc_examples_sphere_problem_data_h

Expand Down
10 changes: 10 additions & 0 deletions examples/petsc/include/structs.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// 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
/// Data structures for PETSc examples

#ifndef libceed_petsc_examples_structs_h
#define libceed_petsc_examples_structs_h

Expand Down
1 change: 1 addition & 0 deletions examples/petsc/qfunctions/swarm/swarmmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of CEED: http://github.com/ceed

#ifndef SWARM_MASS_H
#define SWARM_MASS_H

Expand Down
10 changes: 7 additions & 3 deletions examples/petsc/src/libceedsetup.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// 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

#include "../include/libceedsetup.h"

#include <stdio.h>
Expand All @@ -9,7 +16,6 @@
// -----------------------------------------------------------------------------
PetscErrorCode CeedDataDestroy(CeedInt i, CeedData data) {
PetscFunctionBeginUser;

CeedVectorDestroy(&data->q_data);
CeedVectorDestroy(&data->x_ceed);
CeedVectorDestroy(&data->y_ceed);
Expand All @@ -26,7 +32,6 @@ PetscErrorCode CeedDataDestroy(CeedInt i, CeedData data) {
CeedOperatorDestroy(&data->op_restrict);
}
PetscCall(PetscFree(data));

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand Down Expand Up @@ -163,7 +168,6 @@ PetscErrorCode SetupLibceedByDegree(DM dm, Ceed ceed, CeedInt degree, CeedInt to
data->x_ceed = x_ceed;
data->y_ceed = y_ceed;
data->q_data_size = q_data_size;

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand Down
16 changes: 1 addition & 15 deletions examples/petsc/src/matops.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// -----------------------------------------------------------------------------
PetscErrorCode SetupApplyOperatorCtx(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, Vec X_loc, OperatorApplyContext op_apply_ctx) {
PetscFunctionBeginUser;

op_apply_ctx->comm = comm;
op_apply_ctx->dm = dm;
op_apply_ctx->X_loc = X_loc;
Expand All @@ -16,7 +15,6 @@ PetscErrorCode SetupApplyOperatorCtx(MPI_Comm comm, DM dm, Ceed ceed, CeedData c
op_apply_ctx->y_ceed = ceed_data->y_ceed;
op_apply_ctx->op = ceed_data->op_apply;
op_apply_ctx->ceed = ceed;

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -26,7 +24,6 @@ PetscErrorCode SetupApplyOperatorCtx(MPI_Comm comm, DM dm, Ceed ceed, CeedData c
PetscErrorCode SetupErrorOperatorCtx(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, Vec X_loc, CeedOperator op_error,
OperatorApplyContext op_error_ctx) {
PetscFunctionBeginUser;

op_error_ctx->comm = comm;
op_error_ctx->dm = dm;
op_error_ctx->X_loc = X_loc;
Expand All @@ -35,7 +32,6 @@ PetscErrorCode SetupErrorOperatorCtx(MPI_Comm comm, DM dm, Ceed ceed, CeedData c
op_error_ctx->y_ceed = ceed_data->y_ceed;
op_error_ctx->op = op_error;
op_error_ctx->ceed = ceed;

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -46,7 +42,6 @@ PetscErrorCode MatGetDiag(Mat A, Vec D) {
OperatorApplyContext op_apply_ctx;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &op_apply_ctx));

// Compute Diagonal via libCEED
Expand All @@ -62,7 +57,6 @@ PetscErrorCode MatGetDiag(Mat A, Vec D) {
PetscCall(VecC2P(op_apply_ctx->y_ceed, mem_type, op_apply_ctx->Y_loc));
PetscCall(VecZeroEntries(D));
PetscCall(DMLocalToGlobal(op_apply_ctx->dm, op_apply_ctx->Y_loc, ADD_VALUES, D));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -73,7 +67,6 @@ PetscErrorCode ApplyLocal_Ceed(Vec X, Vec Y, OperatorApplyContext op_apply_ctx)
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

// Global-to-local
PetscCall(DMGlobalToLocal(op_apply_ctx->dm, X, INSERT_VALUES, op_apply_ctx->X_loc));

Expand All @@ -91,7 +84,6 @@ PetscErrorCode ApplyLocal_Ceed(Vec X, Vec Y, OperatorApplyContext op_apply_ctx)
// Local-to-global
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(op_apply_ctx->dm, op_apply_ctx->Y_loc, ADD_VALUES, Y));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -102,12 +94,10 @@ PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y) {
OperatorApplyContext op_apply_ctx;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &op_apply_ctx));

// libCEED for local action of residual evaluator
PetscCall(ApplyLocal_Ceed(X, Y, op_apply_ctx));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -119,7 +109,6 @@ PetscErrorCode MatMult_Prolong(Mat A, Vec X, Vec Y) {
PetscMemType c_mem_type, f_mem_type;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &pr_restr_ctx));

// Global-to-local
Expand All @@ -143,7 +132,6 @@ PetscErrorCode MatMult_Prolong(Mat A, Vec X, Vec Y) {
// Local-to-global
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(pr_restr_ctx->dmf, pr_restr_ctx->loc_vec_f, ADD_VALUES, Y));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -155,7 +143,6 @@ PetscErrorCode MatMult_Restrict(Mat A, Vec X, Vec Y) {
PetscMemType c_mem_type, f_mem_type;

PetscFunctionBeginUser;

PetscCall(MatShellGetContext(A, &pr_restr_ctx));

// Global-to-local
Expand All @@ -179,7 +166,6 @@ PetscErrorCode MatMult_Restrict(Mat A, Vec X, Vec Y) {
// Local-to-global
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(pr_restr_ctx->dmc, pr_restr_ctx->loc_vec_c, ADD_VALUES, Y));

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand All @@ -188,13 +174,13 @@ PetscErrorCode MatMult_Restrict(Mat A, Vec X, Vec Y) {
// -----------------------------------------------------------------------------
PetscErrorCode ComputeL2Error(Vec X, PetscScalar *l2_error, OperatorApplyContext op_error_ctx) {
Vec E;

PetscFunctionBeginUser;
PetscCall(VecDuplicate(X, &E));
PetscCall(ApplyLocal_Ceed(X, E, op_error_ctx));
PetscScalar error_sq = 1.0;
PetscCall(VecSum(E, &error_sq));
*l2_error = sqrt(error_sq);

PetscFunctionReturn(PETSC_SUCCESS);
}

Expand Down
Loading

0 comments on commit 98285ab

Please sign in to comment.