diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 742c020e17..8f35bd9366 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -11,4 +11,5 @@ a71cad2dd6ace5741a754e2ca7daacd4bb094e0e 2c2402ed59c91164eaff46dee0f79386b7347e9e 05b7c571544c3bcb153fce67d12b9ac48947fc2d c8f38049359170a34c915e209276238ea66b9a1e +ec69e8838be2dde140a915e50506f8e1ce3cb534 f2bc0488a298f136294c523bc5ab4086d090059b diff --git a/include/bout/field.hxx b/include/bout/field.hxx index 4e41aa3632..3f7f591528 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -30,6 +30,8 @@ class Field; #define FIELD_H #include +#include +#include #include #include "bout/bout_types.hxx" @@ -125,6 +127,17 @@ public: swap(first.directions, second.directions); } + /// Dummy functions to increase portability + virtual void setRegion([[maybe_unused]] size_t regionID) {} + virtual void setRegion([[maybe_unused]] std::optional regionID) {} + virtual void setRegion([[maybe_unused]] const std::string& region_name) {} + virtual void resetRegion() {} + virtual std::optional getRegionID() const { return {}; } + virtual bool hasParallelSlices() const { return true; } + virtual void calcParallelSlices() {} + virtual void splitParallelSlices() {} + virtual void clearParallelSlices() {} + private: /// Labels for the type of coordinate system this field is defined over DirectionTypes directions{YDirectionType::Standard, ZDirectionType::Standard}; diff --git a/include/bout/field2d.hxx b/include/bout/field2d.hxx index 92658f1bbf..906af38a1d 100644 --- a/include/bout/field2d.hxx +++ b/include/bout/field2d.hxx @@ -24,6 +24,7 @@ * along with BOUT++. If not, see . * */ +#include "bout/utils.hxx" class Field2D; #pragma once @@ -36,7 +37,8 @@ class Field2D; #include "bout/field_data.hxx" #include "bout/fieldperp.hxx" #include "bout/region.hxx" -#include "bout/unused.hxx" + +#include #if BOUT_HAS_RAJA #include "RAJA/RAJA.hpp" // using RAJA lib @@ -133,21 +135,14 @@ public: return *this; } - /// Check if this field has yup and ydown fields - bool hasParallelSlices() const { return true; } - - Field2D& yup(std::vector::size_type UNUSED(index) = 0) { return *this; } - const Field2D& yup(std::vector::size_type UNUSED(index) = 0) const { - return *this; - } + Field2D& yup([[maybe_unused]] size_t index = 0) { return *this; } + const Field2D& yup([[maybe_unused]] size_t index = 0) const { return *this; } - Field2D& ydown(std::vector::size_type UNUSED(index) = 0) { return *this; } - const Field2D& ydown(std::vector::size_type UNUSED(index) = 0) const { - return *this; - } + Field2D& ydown([[maybe_unused]] size_t index = 0) { return *this; } + const Field2D& ydown([[maybe_unused]] size_t index = 0) const { return *this; } - Field2D& ynext(int UNUSED(dir)) { return *this; } - const Field2D& ynext(int UNUSED(dir)) const { return *this; } + Field2D& ynext([[maybe_unused]] int dir) { return *this; } + const Field2D& ynext([[maybe_unused]] int dir) const { return *this; } // Operators @@ -230,8 +225,10 @@ public: * DIrect access to underlying array. This version is for compatibility * with Field3D objects */ - BoutReal& operator()(int jx, int jy, int UNUSED(jz)) { return operator()(jx, jy); } - const BoutReal& operator()(int jx, int jy, int UNUSED(jz)) const { + BoutReal& operator()(int jx, int jy, [[maybe_unused]] int jz) { + return operator()(jx, jy); + } + const BoutReal& operator()(int jx, int jy, [[maybe_unused]] int jz) const { return operator()(jx, jy); } @@ -274,7 +271,7 @@ public: friend void swap(Field2D& first, Field2D& second) noexcept; - int size() const override { return nx * ny; }; + int size() const override { return nx * ny; } private: /// Internal data array. Handles allocation/freeing of memory @@ -318,12 +315,12 @@ Field2D operator-(const Field2D& f); // Non-member functions inline Field2D toFieldAligned(const Field2D& f, - const std::string& UNUSED(region) = "RGN_ALL") { + [[maybe_unused]] const std::string& region = "RGN_ALL") { return f; } inline Field2D fromFieldAligned(const Field2D& f, - const std::string& UNUSED(region) = "RGN_ALL") { + [[maybe_unused]] const std::string& region = "RGN_ALL") { return f; } @@ -334,15 +331,15 @@ inline Field2D fromFieldAligned(const Field2D& f, /// default (can be changed using the \p rgn argument void checkData(const Field2D& f, const std::string& region = "RGN_NOBNDRY"); #else -inline void checkData(const Field2D& UNUSED(f), - std::string UNUSED(region) = "RGN_NOBNDRY") {} +inline void checkData([[maybe_unused]] const Field2D& f, + [[maybe_unused]] std::string region = "RGN_NOBNDRY") {} #endif /// Force guard cells of passed field \p var to NaN #if CHECK > 2 void invalidateGuards(Field2D& var); #else -inline void invalidateGuards(Field2D& UNUSED(var)) {} +inline void invalidateGuards([[maybe_unused]] Field2D& var) {} #endif /// Average in the Z direction @@ -358,7 +355,7 @@ inline Field2D& ddt(Field2D& f) { return *(f.timeDeriv()); } /// toString template specialisation /// Defined in utils.hxx template <> -inline std::string toString<>(const Field2D& UNUSED(val)) { +inline std::string toString<>([[maybe_unused]] const Field2D& val) { return ""; } diff --git a/include/bout/field3d.hxx b/include/bout/field3d.hxx index d1be32dd84..c6e1d1191d 100644 --- a/include/bout/field3d.hxx +++ b/include/bout/field3d.hxx @@ -20,6 +20,8 @@ * **************************************************************************/ +#include "bout/utils.hxx" +#include class Field3D; #pragma once @@ -238,15 +240,15 @@ public: * Ensure that this field has separate fields * for yup and ydown. */ - void splitParallelSlices(); + void splitParallelSlices() override; /*! * Clear the parallel slices, yup and ydown */ - void clearParallelSlices(); + void clearParallelSlices() override; /// Check if this field has yup and ydown fields - bool hasParallelSlices() const { + bool hasParallelSlices() const override { #if CHECK > 2 if (yup_fields.size() != ydown_fields.size()) { throw BoutException( @@ -263,24 +265,24 @@ public: /// Check if this field has yup and ydown fields /// Return reference to yup field - Field3D& yup(std::vector::size_type index = 0) { + Field3D& yup(size_t index = 0) { ASSERT2(index < yup_fields.size()); return yup_fields[index]; } /// Return const reference to yup field - const Field3D& yup(std::vector::size_type index = 0) const { + const Field3D& yup(size_t index = 0) const { ASSERT2(index < yup_fields.size()); return yup_fields[index]; } /// Return reference to ydown field - Field3D& ydown(std::vector::size_type index = 0) { + Field3D& ydown(size_t index = 0) { ASSERT2(index < ydown_fields.size()); return ydown_fields[index]; } /// Return const reference to ydown field - const Field3D& ydown(std::vector::size_type index = 0) const { + const Field3D& ydown(size_t index = 0) const { ASSERT2(index < ydown_fields.size()); return ydown_fields[index]; } @@ -327,11 +329,11 @@ public: const Region& getRegion(const std::string& region_name) const; /// Use region provided by the default, and if none is set, use the provided one const Region& getValidRegionWithDefault(const std::string& region_name) const; - void setRegion(const std::string& region_name); - void resetRegion() { regionID.reset(); }; - void setRegion(size_t id) { regionID = id; }; - void setRegion(std::optional id) { regionID = id; }; - std::optional getRegionID() const { return regionID; }; + void setRegion(const std::string& region_name) override; + void resetRegion() override { regionID.reset(); }; + void setRegion(size_t id) override { regionID = id; }; + void setRegion(std::optional id) override { regionID = id; }; + std::optional getRegionID() const override { return regionID; }; /// Return a Region reference to use to iterate over the x- and /// y-indices of this field @@ -481,7 +483,7 @@ public: friend class Vector3D; friend class Vector2D; - Field3D& calcParallelSlices(); + void calcParallelSlices() override; void applyBoundary(bool init = false) override; void applyBoundary(BoutReal t); @@ -511,6 +513,9 @@ public: std::weak_ptr getTracking() { return tracking; }; + bool areCalcParallelSlicesAllowed() const { return _allowCalcParallelSlices; }; + void disallowCalcParallelSlices() { _allowCalcParallelSlices = false; }; + private: /// Array sizes (from fieldmesh). These are valid only if fieldmesh is not null int nx{-1}, ny{-1}, nz{-1}; @@ -530,6 +535,8 @@ private: /// counter for tracking, to assign unique names to the variable names int tracking_state{0}; std::weak_ptr tracking; + + bool _allowCalcParallelSlices{true}; // name is changed if we assign to the variable, while selfname is a // non-changing copy that is used for the variable names in the dump files std::string selfname; @@ -600,8 +607,8 @@ void checkData(const Field3D& f, const std::string& region = "RGN_NOBNDRY"); #else /// Ignored with disabled CHECK; Throw an exception if \p f is not /// allocated or if any elements are non-finite (for CHECK > 2) -inline void checkData(const Field3D& UNUSED(f), - const std::string& UNUSED(region) = "RGN_NOBNDRY"){}; +inline void checkData([[maybe_unused]] const Field3D& f, + [[maybe_unused]] const std::string& region = "RGN_NOBNDRY") {}; #endif /// Fourier filtering, removes all except one mode @@ -662,7 +669,7 @@ Field2D DC(const Field3D& f, const std::string& rgn = "RGN_ALL"); #if CHECK > 2 void invalidateGuards(Field3D& var); #else -inline void invalidateGuards(Field3D& UNUSED(var)) {} +inline void invalidateGuards([[maybe_unused]] Field3D& var) {} #endif /// Returns a reference to the time-derivative of a field \p f @@ -673,7 +680,7 @@ inline Field3D& ddt(Field3D& f) { return *(f.timeDeriv()); } /// toString template specialisation /// Defined in utils.hxx template <> -inline std::string toString<>(const Field3D& UNUSED(val)) { +inline std::string toString<>([[maybe_unused]] const Field3D& val) { return ""; } diff --git a/include/bout/fieldperp.hxx b/include/bout/fieldperp.hxx index 6995308dbe..1f70089990 100644 --- a/include/bout/fieldperp.hxx +++ b/include/bout/fieldperp.hxx @@ -23,6 +23,7 @@ * **************************************************************************/ +#include class FieldPerp; #ifndef BOUT_FIELDPERP_H @@ -157,6 +158,19 @@ public: return *this; } + FieldPerp& yup(std::vector::size_type UNUSED(index) = 0) { return *this; } + const FieldPerp& yup(std::vector::size_type UNUSED(index) = 0) const { + return *this; + } + + FieldPerp& ydown(std::vector::size_type UNUSED(index) = 0) { return *this; } + const FieldPerp& ydown(std::vector::size_type UNUSED(index) = 0) const { + return *this; + } + + FieldPerp& ynext(int UNUSED(dir)) { return *this; } + const FieldPerp& ynext(int UNUSED(dir)) const { return *this; } + /*! * Ensure that data array is allocated and unique */ diff --git a/src/field/field3d.cxx b/src/field/field3d.cxx index 2cd55b0957..fe9fdc9263 100644 --- a/src/field/field3d.cxx +++ b/src/field/field3d.cxx @@ -341,9 +341,8 @@ Field3D& Field3D::operator=(const BoutReal val) { return *this; } -Field3D& Field3D::calcParallelSlices() { +void Field3D::calcParallelSlices() { getCoordinates()->getParallelTransform().calcParallelSlices(*this); - return *this; } ///////////////////// BOUNDARY CONDITIONS //////////////////