Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ a71cad2dd6ace5741a754e2ca7daacd4bb094e0e
2c2402ed59c91164eaff46dee0f79386b7347e9e
05b7c571544c3bcb153fce67d12b9ac48947fc2d
c8f38049359170a34c915e209276238ea66b9a1e
ec69e8838be2dde140a915e50506f8e1ce3cb534
f2bc0488a298f136294c523bc5ab4086d090059b
13 changes: 13 additions & 0 deletions include/bout/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Field;
#define FIELD_H

#include <cmath>
#include <cstdio>
#include <optional>
#include <string>

#include "bout/bout_types.hxx"
Expand Down Expand Up @@ -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<size_t> regionID) {}
virtual void setRegion([[maybe_unused]] const std::string& region_name) {}
virtual void resetRegion() {}
virtual std::optional<size_t> 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};
Expand Down
43 changes: 20 additions & 23 deletions include/bout/field2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* along with BOUT++. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "bout/utils.hxx"
class Field2D;

#pragma once
Expand All @@ -36,7 +37,8 @@ class Field2D;
#include "bout/field_data.hxx"
#include "bout/fieldperp.hxx"
#include "bout/region.hxx"
#include "bout/unused.hxx"

#include <cstddef>

#if BOUT_HAS_RAJA
#include "RAJA/RAJA.hpp" // using RAJA lib
Expand Down Expand Up @@ -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<Field2D>::size_type UNUSED(index) = 0) { return *this; }
const Field2D& yup(std::vector<Field2D>::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<Field2D>::size_type UNUSED(index) = 0) { return *this; }
const Field2D& ydown(std::vector<Field2D>::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

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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 "<Field2D>";
}

Expand Down
41 changes: 24 additions & 17 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
**************************************************************************/

#include "bout/utils.hxx"
#include <cstddef>
class Field3D;

#pragma once
Expand Down Expand Up @@ -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(
Expand All @@ -263,24 +265,24 @@ public:

/// Check if this field has yup and ydown fields
/// Return reference to yup field
Field3D& yup(std::vector<Field3D>::size_type index = 0) {
Field3D& yup(size_t index = 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've thought we would also need these to be virtual to make things properly generic? Although I guess you're mostly interested in FieldMetric and compile-time polymorphism really, and not runtime polymorphism?

We could make these virtual by returning Field&, but we probably don't actually want that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the reason. We do not want to return Field, so there is no way to make this virtual.
Compile time polymorphism is right now sufficient, as long as 3D metrics are a compile time choice.

ASSERT2(index < yup_fields.size());
return yup_fields[index];
}
/// Return const reference to yup field
const Field3D& yup(std::vector<Field3D>::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<Field3D>::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<Field3D>::size_type index = 0) const {
const Field3D& ydown(size_t index = 0) const {
ASSERT2(index < ydown_fields.size());
return ydown_fields[index];
}
Expand Down Expand Up @@ -327,11 +329,11 @@ public:
const Region<Ind3D>& getRegion(const std::string& region_name) const;
/// Use region provided by the default, and if none is set, use the provided one
const Region<Ind3D>& 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<size_t> id) { regionID = id; };
std::optional<size_t> 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<size_t> id) override { regionID = id; };
std::optional<size_t> getRegionID() const override { return regionID; };

/// Return a Region<Ind2D> reference to use to iterate over the x- and
/// y-indices of this field
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -511,6 +513,9 @@ public:

std::weak_ptr<Options> 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};
Expand All @@ -530,6 +535,8 @@ private:
/// counter for tracking, to assign unique names to the variable names
int tracking_state{0};
std::weak_ptr<Options> 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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 "<Field3D>";
}

Expand Down
14 changes: 14 additions & 0 deletions include/bout/fieldperp.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
**************************************************************************/

#include <vector>
class FieldPerp;

#ifndef BOUT_FIELDPERP_H
Expand Down Expand Up @@ -157,6 +158,19 @@ public:
return *this;
}

FieldPerp& yup(std::vector<FieldPerp>::size_type UNUSED(index) = 0) { return *this; }
const FieldPerp& yup(std::vector<FieldPerp>::size_type UNUSED(index) = 0) const {
return *this;
}

FieldPerp& ydown(std::vector<FieldPerp>::size_type UNUSED(index) = 0) { return *this; }
const FieldPerp& ydown(std::vector<FieldPerp>::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
*/
Expand Down
3 changes: 1 addition & 2 deletions src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 //////////////////
Expand Down
Loading