From fb73f9b98a8de1b88394ce66292fc0e0906d9728 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 6 Nov 2025 13:33:30 +0100 Subject: [PATCH 1/4] clang-tidy fixes for f3dwy --- externalpackages/PVODE/include/pvode/band.h | 4 +- externalpackages/PVODE/precon/band.h | 2 +- include/bout/interpolation_xz.hxx | 4 +- include/bout/options.hxx | 2 +- src/field/field2d.cxx | 4 ++ src/field/field3d.cxx | 6 ++- src/field/fieldperp.cxx | 3 ++ src/field/generated_fieldops.cxx | 3 ++ .../laplace/impls/petsc/petsc_laplace.cxx | 10 +++-- src/invert/laplace/invert_laplace.cxx | 3 +- src/mesh/boundary_factory.cxx | 1 + src/mesh/boundary_standard.cxx | 2 +- src/mesh/coordinates.cxx | 8 ++-- src/mesh/fv_ops.cxx | 2 + src/mesh/impls/bout/boutmesh.cxx | 4 +- src/mesh/interpolation/bilinear_xz.cxx | 1 + src/mesh/interpolation/hermite_spline_xz.cxx | 39 ++++++++++--------- src/mesh/interpolation/lagrange_4pt_xz.cxx | 2 + src/mesh/parallel/fci.cxx | 14 ++++--- src/mesh/parallel/fci_comm.cxx | 3 ++ src/mesh/parallel_boundary_op.cxx | 2 + src/solver/impls/euler/euler.cxx | 4 ++ src/solver/impls/pvode/pvode.cxx | 7 +++- src/sys/options.cxx | 4 +- tests/MMS/spatial/fci/fci_mms.cxx | 12 ++++-- .../test-fci-boundary/get_par_bndry.cxx | 3 ++ tests/integrated/test-fci-mpi/fci_mpi.cxx | 5 +++ 27 files changed, 106 insertions(+), 48 deletions(-) diff --git a/externalpackages/PVODE/include/pvode/band.h b/externalpackages/PVODE/include/pvode/band.h index 49a98b63d6..4f54397c92 100644 --- a/externalpackages/PVODE/include/pvode/band.h +++ b/externalpackages/PVODE/include/pvode/band.h @@ -138,7 +138,7 @@ typedef struct bandmat_type { * * ******************************************************************/ -#define PVODE_BAND_ELEM(A, i, j) ((A->data)[j][i - j + (A->smu)]) +#define PVODE_BAND_ELEM(A, i, j) (((A)->data)[j][(i) - (j) + ((A)->smu)]) /****************************************************************** * * @@ -153,7 +153,7 @@ typedef struct bandmat_type { * * ******************************************************************/ -#define PVODE_BAND_COL(A, j) (((A->data)[j]) + (A->smu)) +#define PVODE_BAND_COL(A, j) ((((A)->data)[j]) + ((A)->smu)) /****************************************************************** * * diff --git a/externalpackages/PVODE/precon/band.h b/externalpackages/PVODE/precon/band.h index 24a21b4c21..727c1dc942 100644 --- a/externalpackages/PVODE/precon/band.h +++ b/externalpackages/PVODE/precon/band.h @@ -153,7 +153,7 @@ typedef struct bandmat_type { * * ******************************************************************/ -#define PVODE_BAND_COL(A, j) (((A->data)[j]) + (A->smu)) +#define PVODE_BAND_COL(A, j) ((((A)->data)[j]) + ((A)->smu)) /****************************************************************** * * diff --git a/include/bout/interpolation_xz.hxx b/include/bout/interpolation_xz.hxx index 9a7e788e67..0d223d9ee9 100644 --- a/include/bout/interpolation_xz.hxx +++ b/include/bout/interpolation_xz.hxx @@ -166,8 +166,8 @@ protected: #if HS_USE_PETSC PetscLib* petsclib; bool isInit{false}; - Mat petscWeights; - Vec rhs, result; + Mat petscWeights{}; + Vec rhs{}, result{}; #endif public: diff --git a/include/bout/options.hxx b/include/bout/options.hxx index 5b057fc3bb..f9882b16a0 100644 --- a/include/bout/options.hxx +++ b/include/bout/options.hxx @@ -999,7 +999,7 @@ Tensor Options::as>(const Tensor& similar_t std::string toString(const Options& value); /// Save the parallel fields -void saveParallel(Options& opt, const std::string name, const Field3D& tosave); +void saveParallel(Options& opt, const std::string& name, const Field3D& tosave); /// Output a stringified \p value to a stream /// diff --git a/src/field/field2d.cxx b/src/field/field2d.cxx index 4591d228f7..0410427fce 100644 --- a/src/field/field2d.cxx +++ b/src/field/field2d.cxx @@ -25,8 +25,10 @@ * **************************************************************************/ +#include "bout/bout_types.hxx" #include "bout/build_config.hxx" +#include "bout/unused.hxx" #include #include @@ -45,6 +47,8 @@ #include #include +#include +#include #include diff --git a/src/field/field3d.cxx b/src/field/field3d.cxx index 2fc6726ebc..67e9c08cde 100644 --- a/src/field/field3d.cxx +++ b/src/field/field3d.cxx @@ -25,12 +25,16 @@ * **************************************************************************/ +#include "bout/bout_types.hxx" #include "bout/build_config.hxx" #include #include #include +#include +#include +#include #include "bout/parallel_boundary_op.hxx" #include "bout/parallel_boundary_region.hxx" @@ -989,7 +993,7 @@ template Options* Field3D::track(const Field2D&, std::string); template Options* Field3D::track(const FieldPerp&, std::string); Options* Field3D::track(const BoutReal& change, std::string operation) { - if (tracking and tracking_state) { + if ((tracking != nullptr) and (tracking_state != 0)) { const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; tracking->set(outname, change, "tracking"); (*tracking)[outname].setAttributes({ diff --git a/src/field/fieldperp.cxx b/src/field/fieldperp.cxx index c7a196a57a..12d4991641 100644 --- a/src/field/fieldperp.cxx +++ b/src/field/fieldperp.cxx @@ -23,10 +23,13 @@ * **************************************************************************/ +#include "bout/unused.hxx" #include #include #include +#include +#include #include #include diff --git a/src/field/generated_fieldops.cxx b/src/field/generated_fieldops.cxx index 5f66172302..4cf364aa8a 100644 --- a/src/field/generated_fieldops.cxx +++ b/src/field/generated_fieldops.cxx @@ -1,4 +1,6 @@ // This file is autogenerated - see gen_fieldops.py +#include "bout/assert.hxx" +#include "bout/build_defines.hxx" #include #include #include @@ -6,6 +8,7 @@ #include #include #include +#include // Provide the C++ wrapper for multiplication of Field3D and Field3D Field3D operator*(const Field3D& lhs, const Field3D& rhs) { diff --git a/src/invert/laplace/impls/petsc/petsc_laplace.cxx b/src/invert/laplace/impls/petsc/petsc_laplace.cxx index bcfe6264d7..7786b89319 100644 --- a/src/invert/laplace/impls/petsc/petsc_laplace.cxx +++ b/src/invert/laplace/impls/petsc/petsc_laplace.cxx @@ -25,11 +25,15 @@ **************************************************************************/ #include "bout/build_defines.hxx" +#include +#include #if BOUT_HAS_PETSC #include "petsc_laplace.hxx" +#include + #include #include #include @@ -380,7 +384,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0, if (localmesh->firstX()) { for (int x = 0; x < localmesh->xstart; x++) { for (int z = 0; z < localmesh->LocalNz; z++) { - PetscScalar val; // Value of element to be set in the matrix + PetscScalar val = NAN; // Value of element to be set in the matrix // If Neumann Boundary Conditions are set. if (isInnerBoundaryFlagSet(INVERT_AC_GRAD)) { // Set values corresponding to nodes adjacent in x @@ -814,7 +818,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0, // Call the actual solver { - Timer timer("petscsolve"); + Timer const timer("petscsolve"); KSPSolve(ksp, bs, xs); // Call the solver to solve the system } @@ -830,7 +834,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0, } } else { timer.reset(); - PetscErrorCode err = MatMult(MatA, bs, xs); + PetscErrorCode const err = MatMult(MatA, bs, xs); if (err != PETSC_SUCCESS) { throw BoutException("MatMult failed with {:d}", static_cast(err)); } diff --git a/src/invert/laplace/invert_laplace.cxx b/src/invert/laplace/invert_laplace.cxx index 897e7e45a9..33d590cd22 100644 --- a/src/invert/laplace/invert_laplace.cxx +++ b/src/invert/laplace/invert_laplace.cxx @@ -263,7 +263,8 @@ Field3D Laplacian::forward(const Field3D& b) { ASSERT1(localmesh == b.getMesh()); // Setting the start and end range of the y-slices - int ys = localmesh->ystart, ye = localmesh->yend; + int ys = localmesh->ystart; + int ye = localmesh->yend; if (include_yguards && localmesh->hasBndryLowerY()) { ys = 0; // Mesh contains a lower boundary } diff --git a/src/mesh/boundary_factory.cxx b/src/mesh/boundary_factory.cxx index 5934daff31..fd5bbdc70d 100644 --- a/src/mesh/boundary_factory.cxx +++ b/src/mesh/boundary_factory.cxx @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/src/mesh/boundary_standard.cxx b/src/mesh/boundary_standard.cxx index fc313689be..09832d0164 100644 --- a/src/mesh/boundary_standard.cxx +++ b/src/mesh/boundary_standard.cxx @@ -1728,7 +1728,7 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { void BoundaryNeumann::apply(Field2D & f) { BoundaryNeumann::apply(f, 0.); } - void BoundaryNeumann::apply([[maybe_unused]] Field2D & f, BoutReal t) { + void BoundaryNeumann::apply([[maybe_unused]] Field2D & f, BoutReal /*t*/) { // Set (at 2nd order / 3rd order) the value at the mid-point between // the guard cell and the grid cell to be val // N.B. First guard cells (closest to the grid) is 2nd order, while diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 24bf2de0ba..78df595b13 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -4,6 +4,7 @@ * given the contravariant metric tensor terms **************************************************************************/ +#include "bout/region.hxx" #include #include #include @@ -18,6 +19,7 @@ #include #include +#include #include "invert3x3.hxx" #include "parallel/fci.hxx" @@ -619,7 +621,7 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) maxError = std::max(std::abs(local - 1), maxError); } } - BoutReal allowedError = (*options)["allowedFluxError"].withDefault(1e-6); + BoutReal const allowedError = (*options)["allowedFluxError"].withDefault(1e-6); if (maxError < allowedError / 100) { output_info.write("\tInfo: The maximum flux conservation error is {:e}", maxError); } else if (maxError < allowedError) { @@ -1617,9 +1619,9 @@ Field3D Coordinates::Div_par(const Field3DParallel& f, CELL_LOC outloc, return Bxy * Grad_par(f / Bxy_floc, outloc, method); } - auto coords = f.getCoordinates(); + auto* coords = f.getCoordinates(); // Need to modify yup and ydown fields - Field3D Jg = coords->J / sqrt(coords->g_22.asField3DParallel()); + Field3D const Jg = coords->J / sqrt(coords->g_22.asField3DParallel()); return setName(Jg * Grad_par(f / Jg, outloc, method), "Div_par({:s})", f.name); } diff --git a/src/mesh/fv_ops.cxx b/src/mesh/fv_ops.cxx index 9b5da1a0da..a5defe8c14 100644 --- a/src/mesh/fv_ops.cxx +++ b/src/mesh/fv_ops.cxx @@ -1,3 +1,5 @@ +#include "bout/boutexception.hxx" +#include "bout/difops.hxx" #include #include #include diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index 8662d314ce..79ce3378a0 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -484,8 +484,8 @@ int BoutMesh::load() { } ASSERT0(MXG >= 0); - bool meshHasMyg = Mesh::get(MYG, "MYG") == 0; - int meshMyg; + bool const meshHasMyg = Mesh::get(MYG, "MYG") == 0; + int meshMyg = 0; if (!meshHasMyg) { MYG = 2; } else { diff --git a/src/mesh/interpolation/bilinear_xz.cxx b/src/mesh/interpolation/bilinear_xz.cxx index 4facdac34c..ba7a5fe136 100644 --- a/src/mesh/interpolation/bilinear_xz.cxx +++ b/src/mesh/interpolation/bilinear_xz.cxx @@ -20,6 +20,7 @@ * **************************************************************************/ +#include "bout/boutexception.hxx" #include "bout/globals.hxx" #include "bout/interpolation_xz.hxx" #include "bout/mesh.hxx" diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index 103680c0b8..f864314f11 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -25,7 +25,12 @@ #include "bout/globals.hxx" #include "bout/index_derivs_interface.hxx" #include "bout/interpolation_xz.hxx" +#include "bout/mask.hxx" +#include "bout/utils.hxx" +#include +#include +#include #include class IndConverter { @@ -393,7 +398,7 @@ Field3D XZHermiteSplineBase::interpolate(const Field3D& f, const auto region2 = y_offset != 0 ? fmt::format("RGN_YPAR_{:+d}", y_offset) : region; - std::unique_ptr gf; + std::unique_ptr const gf; if constexpr (monotonic) { gf = gf3daccess->communicate_asPtr(f); } @@ -529,21 +534,21 @@ Field3D XZMonotonicHermiteSplineLegacy::interpolate(const Field3D& f, localmesh->communicateXZ(fx); // communicate in y, but do not calculate parallel slices { - auto h = localmesh->sendY(fx); + auto* h = localmesh->sendY(fx); localmesh->wait(h); } Field3D fz = bout::derivatives::index::DDZ(f, CELL_DEFAULT, "DEFAULT", "RGN_ALL"); localmesh->communicateXZ(fz); // communicate in y, but do not calculate parallel slices { - auto h = localmesh->sendY(fz); + auto* h = localmesh->sendY(fz); localmesh->wait(h); } Field3D fxz = bout::derivatives::index::DDX(fz, CELL_DEFAULT, "DEFAULT"); localmesh->communicateXZ(fxz); // communicate in y, but do not calculate parallel slices { - auto h = localmesh->sendY(fxz); + auto* h = localmesh->sendY(fxz); localmesh->wait(h); } @@ -557,24 +562,24 @@ Field3D XZMonotonicHermiteSplineLegacy::interpolate(const Field3D& f, const auto icxpzp = iczp.xp(); // Interpolate f in X at Z - const BoutReal f_z = - f[ic] * h00_x[i] + f[icxp] * h01_x[i] + fx[ic] * h10_x[i] + fx[icxp] * h11_x[i]; + const BoutReal f_z = (f[ic] * h00_x[i]) + (f[icxp] * h01_x[i]) + (fx[ic] * h10_x[i]) + + (fx[icxp] * h11_x[i]); // Interpolate f in X at Z+1 - const BoutReal f_zp1 = f[iczp] * h00_x[i] + f[icxpzp] * h01_x[i] + fx[iczp] * h10_x[i] - + fx[icxpzp] * h11_x[i]; + const BoutReal f_zp1 = (f[iczp] * h00_x[i]) + (f[icxpzp] * h01_x[i]) + + (fx[iczp] * h10_x[i]) + (fx[icxpzp] * h11_x[i]); // Interpolate fz in X at Z - const BoutReal fz_z = fz[ic] * h00_x[i] + fz[icxp] * h01_x[i] + fxz[ic] * h10_x[i] - + fxz[icxp] * h11_x[i]; + const BoutReal fz_z = (fz[ic] * h00_x[i]) + (fz[icxp] * h01_x[i]) + + (fxz[ic] * h10_x[i]) + (fxz[icxp] * h11_x[i]); // Interpolate fz in X at Z+1 - const BoutReal fz_zp1 = fz[iczp] * h00_x[i] + fz[icxpzp] * h01_x[i] - + fxz[iczp] * h10_x[i] + fxz[icxpzp] * h11_x[i]; + const BoutReal fz_zp1 = (fz[iczp] * h00_x[i]) + (fz[icxpzp] * h01_x[i]) + + (fxz[iczp] * h10_x[i]) + (fxz[icxpzp] * h11_x[i]); // Interpolate in Z BoutReal result = - +f_z * h00_z[i] + f_zp1 * h01_z[i] + fz_z * h10_z[i] + fz_zp1 * h11_z[i]; + (+f_z * h00_z[i]) + (f_zp1 * h01_z[i]) + (fz_z * h10_z[i]) + (fz_zp1 * h11_z[i]); ASSERT2(std::isfinite(result) || i.x() < localmesh->xstart || i.x() > localmesh->xend); @@ -594,12 +599,8 @@ Field3D XZMonotonicHermiteSplineLegacy::interpolate(const Field3D& f, ASSERT2(std::isfinite(localmin) || i.x() < localmesh->xstart || i.x() > localmesh->xend); - if (result > localmax) { - result = localmax; - } - if (result < localmin) { - result = localmin; - } + result = std::min(result, localmax); + result = std::max(result, localmin); f_interp[iyp] = result; } diff --git a/src/mesh/interpolation/lagrange_4pt_xz.cxx b/src/mesh/interpolation/lagrange_4pt_xz.cxx index 1a1e484c07..b09fea1d08 100644 --- a/src/mesh/interpolation/lagrange_4pt_xz.cxx +++ b/src/mesh/interpolation/lagrange_4pt_xz.cxx @@ -20,10 +20,12 @@ * **************************************************************************/ +#include "bout/boutexception.hxx" #include "bout/globals.hxx" #include "bout/interpolation_xz.hxx" #include "bout/mesh.hxx" +#include #include XZLagrange4pt::XZLagrange4pt(int y_offset, Mesh* mesh) diff --git a/src/mesh/parallel/fci.cxx b/src/mesh/parallel/fci.cxx index 3f3e7b0ebf..fa747f8e25 100644 --- a/src/mesh/parallel/fci.cxx +++ b/src/mesh/parallel/fci.cxx @@ -41,6 +41,7 @@ #include "bout/assert.hxx" #include "bout/bout_types.hxx" #include "bout/boutexception.hxx" +#include "bout/build_defines.hxx" #include "bout/field2d.hxx" #include "bout/field3d.hxx" #include "bout/field_data.hxx" @@ -61,6 +62,7 @@ #include #include #include +#include namespace { using namespace std::literals; @@ -84,15 +86,15 @@ void set_parallel_metric_component(std::string name, Field3D& component, int off auto& pcom = component.ynext(offset); pcom.allocate(); pcom.setRegion(fmt::format("RGN_YPAR_{:+d}", offset)); - pcom.name = name; + pcom.name = std::move(name); BOUT_FOR(i, component.getRegion("RGN_NOBNDRY")) { pcom[i.yp(offset)] = data[i]; } } -bool load_parallel_metric_component(std::string name, Field3D& component, int offset, - bool doZero) { +bool load_parallel_metric_component(const std::string& name, Field3D& component, + int offset, bool doZero) { Mesh* mesh = component.getMesh(); Field3D tmp{mesh}; - bool doload = mesh->sourceHasVar(name); + bool const doload = mesh->sourceHasVar(name); bool isValid{false}; if (doload) { const auto pname = parallel_slice_field_name(name, offset); @@ -298,7 +300,7 @@ FCIMap::FCIMap(Mesh& mesh, [[maybe_unused]] const Coordinates::FieldMetric& dy, BoutMask to_remove(map_mesh); const int xend = map_mesh->xstart - + (map_mesh->xend - map_mesh->xstart + 1) * map_mesh->getNXPE() - 1; + + ((map_mesh->xend - map_mesh->xstart + 1) * map_mesh->getNXPE()) - 1; // Default to the maximum number of points const int defValid{map_mesh->ystart - 1 + std::abs(offset)}; // Serial loop because call to BoundaryRegionPar::addPoint @@ -371,7 +373,7 @@ FCIMap::FCIMap(Mesh& mesh, [[maybe_unused]] const Coordinates::FieldMetric& dy, ASSERT2(map_mesh->xend - map_mesh->xstart >= 2); auto boundary = (xt_prime[i] < map_mesh->xstart) ? inner_boundary : outer_boundary; if (!boundary->contains(x, y, z)) { - boundary->add_point(x, y, z, x + dx, y + offset - sgn(offset) * 0.5, + boundary->add_point(x, y, z, x + dx, y + offset - (sgn(offset) * 0.5), z + dz, // Intersection point in local index space std::abs(offset_) - 0.5, // Distance to intersection defValid, offset_); diff --git a/src/mesh/parallel/fci_comm.cxx b/src/mesh/parallel/fci_comm.cxx index c0d51d1eb9..95bfa6958e 100644 --- a/src/mesh/parallel/fci_comm.cxx +++ b/src/mesh/parallel/fci_comm.cxx @@ -24,6 +24,9 @@ **************************************************************************/ #include "fci_comm.hxx" +#include "bout/assert.hxx" +#include "bout/bout_types.hxx" +#include "bout/region.hxx" #include diff --git a/src/mesh/parallel_boundary_op.cxx b/src/mesh/parallel_boundary_op.cxx index df164ce43f..644331221e 100644 --- a/src/mesh/parallel_boundary_op.cxx +++ b/src/mesh/parallel_boundary_op.cxx @@ -1,9 +1,11 @@ #include "bout/parallel_boundary_op.hxx" +#include "bout/bout_types.hxx" #include "bout/constants.hxx" #include "bout/field_factory.hxx" #include "bout/globals.hxx" #include "bout/mesh.hxx" #include "bout/output.hxx" +#include "bout/parallel_boundary_region.hxx" BoutReal BoundaryOpPar::getValue(const BoundaryRegionParIter& bndry, BoutReal t) { switch (value_type) { diff --git a/src/solver/impls/euler/euler.cxx b/src/solver/impls/euler/euler.cxx index 709ac5ba9b..34c57bb799 100644 --- a/src/solver/impls/euler/euler.cxx +++ b/src/solver/impls/euler/euler.cxx @@ -1,6 +1,8 @@ #include "euler.hxx" +#include "bout/bout.hxx" +#include "bout/field2d.hxx" #include #include #include @@ -9,6 +11,8 @@ #include #include +#include +#include #include diff --git a/src/solver/impls/pvode/pvode.cxx b/src/solver/impls/pvode/pvode.cxx index a4af3117ad..c30567b38c 100644 --- a/src/solver/impls/pvode/pvode.cxx +++ b/src/solver/impls/pvode/pvode.cxx @@ -24,6 +24,11 @@ **************************************************************************/ #include "bout/build_defines.hxx" +#include "bout/field2d.hxx" +#include "bout/field3d.hxx" +#include +#include +#include #include "pvode.hxx" @@ -360,7 +365,7 @@ BoutReal PvodeSolver::run(BoutReal tout) { if (flag != SUCCESS) { output_error.write("ERROR CVODE step failed, flag = {:d}\n", flag); if (debug_on_failure) { - CVodeMemRec* cv_mem = (CVodeMem)cvode_mem; + CVodeMemRec const* cv_mem = (CVodeMem)cvode_mem; if (f2d.empty() and v2d.empty() and v3d.empty()) { Options debug{}; using namespace std::string_literals; diff --git a/src/sys/options.cxx b/src/sys/options.cxx index ee2326df29..37d1b898b0 100644 --- a/src/sys/options.cxx +++ b/src/sys/options.cxx @@ -1,6 +1,7 @@ #include "bout/options.hxx" #include "bout/array.hxx" +#include "bout/assert.hxx" #include "bout/bout_types.hxx" #include "bout/boutexception.hxx" #include "bout/field2d.hxx" @@ -16,6 +17,7 @@ #include "bout/unused.hxx" #include "bout/utils.hxx" +#include #include #include #include @@ -343,7 +345,7 @@ Options& Options::assign<>(Tensor val, std::string source) { return *this; } -void saveParallel(Options& opt, const std::string name, const Field3D& tosave) { +void saveParallel(Options& opt, const std::string& name, const Field3D& tosave) { ASSERT0(tosave.isAllocated()); opt[name] = tosave; for (size_t i0 = 1; i0 <= tosave.numberParallelSlices(); ++i0) { diff --git a/tests/MMS/spatial/fci/fci_mms.cxx b/tests/MMS/spatial/fci/fci_mms.cxx index 265f14ea6e..c5cee0ffc8 100644 --- a/tests/MMS/spatial/fci/fci_mms.cxx +++ b/tests/MMS/spatial/fci/fci_mms.cxx @@ -1,19 +1,23 @@ #include "bout/bout.hxx" -#include "bout/build_config.hxx" #include "bout/difops.hxx" +#include "bout/field2d.hxx" #include "bout/field3d.hxx" #include "bout/field_factory.hxx" #include "bout/options.hxx" +#include "bout/utils.hxx" +#include +#include +#include #include namespace { auto fci_op_test(const std::string& name, Options& dump, const Field3D& input, const Field3D& result) { auto* mesh = input.getMesh(); - Field3D solution{FieldFactory::get()->create3D(fmt::format("{}_solution", name), - Options::getRoot(), mesh)}; - Field3D error{result - solution}; + Field3D const solution{FieldFactory::get()->create3D(fmt::format("{}_solution", name), + Options::getRoot(), mesh)}; + Field3D const error{result - solution}; dump[fmt::format("{}_l_2", name)] = sqrt(mean(SQ(error), true, "RGN_NOBNDRY")); dump[fmt::format("{}_l_inf", name)] = max(abs(error), true, "RGN_NOBNDRY"); diff --git a/tests/integrated/test-fci-boundary/get_par_bndry.cxx b/tests/integrated/test-fci-boundary/get_par_bndry.cxx index f6154fc61e..4f0f53f65d 100644 --- a/tests/integrated/test-fci-boundary/get_par_bndry.cxx +++ b/tests/integrated/test-fci-boundary/get_par_bndry.cxx @@ -1,7 +1,10 @@ #include "bout/bout.hxx" #include "bout/field3d.hxx" #include "bout/field_factory.hxx" +#include "bout/output.hxx" #include "bout/parallel_boundary_region.hxx" +#include +#include int main(int argc, char** argv) { BoutInitialise(argc, argv); diff --git a/tests/integrated/test-fci-mpi/fci_mpi.cxx b/tests/integrated/test-fci-mpi/fci_mpi.cxx index cc4fba8ffe..e54883b843 100644 --- a/tests/integrated/test-fci-mpi/fci_mpi.cxx +++ b/tests/integrated/test-fci-mpi/fci_mpi.cxx @@ -1,6 +1,11 @@ #include "fmt/format.h" #include "bout/bout.hxx" +#include "bout/field3d.hxx" #include "bout/field_factory.hxx" +#include "bout/globals.hxx" +#include "bout/options.hxx" +#include "bout/options_io.hxx" +#include "bout/region.hxx" namespace { auto fci_mpi_test(int num, Options& dump) { From 6aed3dfd8fd8ff77cf09d23a96f59027bd544729 Mon Sep 17 00:00:00 2001 From: dschwoerer <5637662+dschwoerer@users.noreply.github.com> Date: Thu, 6 Nov 2025 12:37:39 +0000 Subject: [PATCH 2/4] Apply clang-format changes --- include/bout/boundary_iterator.hxx | 5 ++++- include/bout/field.hxx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/bout/boundary_iterator.hxx b/include/bout/boundary_iterator.hxx index bbec27519e..bd11dde9a6 100644 --- a/include/bout/boundary_iterator.hxx +++ b/include/bout/boundary_iterator.hxx @@ -42,7 +42,9 @@ public: return (f[ind()] * 3 - yprev(f)) * 0.5; } - BoutReal extrapolate_next_o2(const Field3D& f) const { return (2 * f[ind()]) - yprev(f); } + BoutReal extrapolate_next_o2(const Field3D& f) const { + return (2 * f[ind()]) - yprev(f); + } BoutReal extrapolate_next_o2(const std::function& f) const { @@ -150,6 +152,7 @@ public: const int dir; virtual ~BoundaryRegionIter = default; + protected: int z{0}; int x; diff --git a/include/bout/field.hxx b/include/bout/field.hxx index 82427f029c..bbbe0e15c9 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -542,7 +542,7 @@ class Field3DParallel; T result{emptyFrom(f)}; \ BOUT_FOR(d, result.getRegion(rgn)) { result[d] = func(f[d]); } \ if constexpr (std::is_base_of_v) { \ - for (size_t i = 0; i < f.numberParallelSlices(); ++i) { \ + for (size_t i = 0; i < f.numberParallelSlices(); ++i) { \ result.yup(i) = func(f.yup(i)); \ result.ydown(i) = func(f.ydown(i)); \ } \ From f286975e0e2aef983b4e203ae98f0fdf5f56d86e Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 6 Nov 2025 13:40:51 +0100 Subject: [PATCH 3/4] Move const in front of type --- src/invert/laplace/impls/petsc/petsc_laplace.cxx | 4 ++-- src/mesh/boundary_standard.cxx | 2 +- src/mesh/coordinates.cxx | 4 ++-- src/mesh/impls/bout/boutmesh.cxx | 2 +- src/mesh/interpolation/hermite_spline_xz.cxx | 2 +- src/mesh/parallel/fci.cxx | 2 +- src/solver/impls/pvode/pvode.cxx | 2 +- tests/MMS/spatial/fci/fci_mms.cxx | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/invert/laplace/impls/petsc/petsc_laplace.cxx b/src/invert/laplace/impls/petsc/petsc_laplace.cxx index 7786b89319..e6814e259c 100644 --- a/src/invert/laplace/impls/petsc/petsc_laplace.cxx +++ b/src/invert/laplace/impls/petsc/petsc_laplace.cxx @@ -818,7 +818,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0, // Call the actual solver { - Timer const timer("petscsolve"); + const Timer timer("petscsolve"); KSPSolve(ksp, bs, xs); // Call the solver to solve the system } @@ -834,7 +834,7 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0, } } else { timer.reset(); - PetscErrorCode const err = MatMult(MatA, bs, xs); + const PetscErrorCode err = MatMult(MatA, bs, xs); if (err != PETSC_SUCCESS) { throw BoutException("MatMult failed with {:d}", static_cast(err)); } diff --git a/src/mesh/boundary_standard.cxx b/src/mesh/boundary_standard.cxx index 09832d0164..bd854f37d4 100644 --- a/src/mesh/boundary_standard.cxx +++ b/src/mesh/boundary_standard.cxx @@ -1728,7 +1728,7 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { void BoundaryNeumann::apply(Field2D & f) { BoundaryNeumann::apply(f, 0.); } - void BoundaryNeumann::apply([[maybe_unused]] Field2D & f, BoutReal /*t*/) { + void BoundaryNeumann::apply([[maybe_unused]] Field2D & f, [[maybe_unused]] BoutReal t) { // Set (at 2nd order / 3rd order) the value at the mid-point between // the guard cell and the grid cell to be val // N.B. First guard cells (closest to the grid) is 2nd order, while diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 78df595b13..fb41e6b75c 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -621,7 +621,7 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) maxError = std::max(std::abs(local - 1), maxError); } } - BoutReal const allowedError = (*options)["allowedFluxError"].withDefault(1e-6); + const BoutReal allowedError = (*options)["allowedFluxError"].withDefault(1e-6); if (maxError < allowedError / 100) { output_info.write("\tInfo: The maximum flux conservation error is {:e}", maxError); } else if (maxError < allowedError) { @@ -1621,7 +1621,7 @@ Field3D Coordinates::Div_par(const Field3DParallel& f, CELL_LOC outloc, auto* coords = f.getCoordinates(); // Need to modify yup and ydown fields - Field3D const Jg = coords->J / sqrt(coords->g_22.asField3DParallel()); + const Field3D Jg = coords->J / sqrt(coords->g_22.asField3DParallel()); return setName(Jg * Grad_par(f / Jg, outloc, method), "Div_par({:s})", f.name); } diff --git a/src/mesh/impls/bout/boutmesh.cxx b/src/mesh/impls/bout/boutmesh.cxx index 79ce3378a0..89d407d576 100644 --- a/src/mesh/impls/bout/boutmesh.cxx +++ b/src/mesh/impls/bout/boutmesh.cxx @@ -484,7 +484,7 @@ int BoutMesh::load() { } ASSERT0(MXG >= 0); - bool const meshHasMyg = Mesh::get(MYG, "MYG") == 0; + const bool meshHasMyg = Mesh::get(MYG, "MYG") == 0; int meshMyg = 0; if (!meshHasMyg) { MYG = 2; diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index f864314f11..0be5500704 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -398,7 +398,7 @@ Field3D XZHermiteSplineBase::interpolate(const Field3D& f, const auto region2 = y_offset != 0 ? fmt::format("RGN_YPAR_{:+d}", y_offset) : region; - std::unique_ptr const gf; + const std::unique_ptr gf; if constexpr (monotonic) { gf = gf3daccess->communicate_asPtr(f); } diff --git a/src/mesh/parallel/fci.cxx b/src/mesh/parallel/fci.cxx index fa747f8e25..579b2a6266 100644 --- a/src/mesh/parallel/fci.cxx +++ b/src/mesh/parallel/fci.cxx @@ -94,7 +94,7 @@ bool load_parallel_metric_component(const std::string& name, Field3D& component, int offset, bool doZero) { Mesh* mesh = component.getMesh(); Field3D tmp{mesh}; - bool const doload = mesh->sourceHasVar(name); + const bool doload = mesh->sourceHasVar(name); bool isValid{false}; if (doload) { const auto pname = parallel_slice_field_name(name, offset); diff --git a/src/solver/impls/pvode/pvode.cxx b/src/solver/impls/pvode/pvode.cxx index c30567b38c..643e518fa8 100644 --- a/src/solver/impls/pvode/pvode.cxx +++ b/src/solver/impls/pvode/pvode.cxx @@ -365,7 +365,7 @@ BoutReal PvodeSolver::run(BoutReal tout) { if (flag != SUCCESS) { output_error.write("ERROR CVODE step failed, flag = {:d}\n", flag); if (debug_on_failure) { - CVodeMemRec const* cv_mem = (CVodeMem)cvode_mem; + const CVodeMemRec* cv_mem = (CVodeMem)cvode_mem; if (f2d.empty() and v2d.empty() and v3d.empty()) { Options debug{}; using namespace std::string_literals; diff --git a/tests/MMS/spatial/fci/fci_mms.cxx b/tests/MMS/spatial/fci/fci_mms.cxx index c5cee0ffc8..e7f5664130 100644 --- a/tests/MMS/spatial/fci/fci_mms.cxx +++ b/tests/MMS/spatial/fci/fci_mms.cxx @@ -15,9 +15,9 @@ namespace { auto fci_op_test(const std::string& name, Options& dump, const Field3D& input, const Field3D& result) { auto* mesh = input.getMesh(); - Field3D const solution{FieldFactory::get()->create3D(fmt::format("{}_solution", name), + const Field3D solution{FieldFactory::get()->create3D(fmt::format("{}_solution", name), Options::getRoot(), mesh)}; - Field3D const error{result - solution}; + const Field3D error{result - solution}; dump[fmt::format("{}_l_2", name)] = sqrt(mean(SQ(error), true, "RGN_NOBNDRY")); dump[fmt::format("{}_l_inf", name)] = max(abs(error), true, "RGN_NOBNDRY"); From 4c4190b932c248b9543543fed37753bbee31d088 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 7 Nov 2025 09:24:41 +0100 Subject: [PATCH 4/4] Fix issues from clang-tidy --- include/bout/boundary_iterator.hxx | 2 +- src/mesh/interpolation/hermite_spline_xz.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/bout/boundary_iterator.hxx b/include/bout/boundary_iterator.hxx index bd11dde9a6..746de13a68 100644 --- a/include/bout/boundary_iterator.hxx +++ b/include/bout/boundary_iterator.hxx @@ -151,7 +151,7 @@ public: #endif const int dir; - virtual ~BoundaryRegionIter = default; + virtual ~BoundaryRegionIter() = default; protected: int z{0}; diff --git a/src/mesh/interpolation/hermite_spline_xz.cxx b/src/mesh/interpolation/hermite_spline_xz.cxx index 0be5500704..b383e430ac 100644 --- a/src/mesh/interpolation/hermite_spline_xz.cxx +++ b/src/mesh/interpolation/hermite_spline_xz.cxx @@ -398,7 +398,7 @@ Field3D XZHermiteSplineBase::interpolate(const Field3D& f, const auto region2 = y_offset != 0 ? fmt::format("RGN_YPAR_{:+d}", y_offset) : region; - const std::unique_ptr gf; + std::unique_ptr gf; if constexpr (monotonic) { gf = gf3daccess->communicate_asPtr(f); }