Skip to content

Commit 0b71d58

Browse files
committed
Move field_type() to FieldData; deprecate FieldData::is3D()
1 parent 5cad79a commit 0b71d58

10 files changed

Lines changed: 32 additions & 45 deletions

File tree

include/bout/field.hxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Field;
3030
#define FIELD_H
3131

3232
#include <cmath>
33-
#include <cstdint>
3433
#include <cstdio>
3534
#include <optional>
3635
#include <string>
@@ -121,11 +120,6 @@ public:
121120
/// Get the total number of points
122121
virtual int size() const = 0;
123122

124-
/// Enum to distinguish the different kinds of Fields
125-
enum class FieldType : std::uint8_t { field3d, field2d, fieldperp };
126-
/// Is this an instance of `Field3D`, `Field2D`, or `FieldPerp`?
127-
virtual FieldType field_type() const = 0;
128-
129123
friend void swap(Field& first, Field& second) noexcept {
130124
using std::swap;
131125
swap(static_cast<FieldData&>(first), static_cast<FieldData&>(second));

include/bout/field2d.hxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ public:
250250
Field2D& operator/=(BoutReal rhs);
251251

252252
// FieldData virtual functions
253-
254-
bool is3D() const override { return false; }
255253
FieldType field_type() const override { return FieldType::field2d; }
256254

257255
#if CHECK > 0

include/bout/field3d.hxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ public:
473473
///@}
474474

475475
// FieldData virtual functions
476-
bool is3D() const override { return true; }
477476
FieldType field_type() const override { return FieldType::field3d; }
478477

479478
#if CHECK > 0

include/bout/field_data.hxx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
77
*
88
* Contact: Ben Dudson, bd512@york.ac.uk
9-
*
9+
*
1010
* This file is part of BOUT++.
1111
*
1212
* BOUT++ is free software: you can redistribute it and/or modify
@@ -33,6 +33,7 @@ class FieldData;
3333
#include "bout/bout_types.hxx"
3434
#include "bout/unused.hxx"
3535

36+
#include <cstdint>
3637
#include <map>
3738
#include <memory>
3839
#include <string>
@@ -71,13 +72,22 @@ public:
7172
/// Get variable location
7273
virtual CELL_LOC getLocation() const;
7374

75+
/// Enum to distinguish the different kinds of Fields
76+
enum class FieldType : std::uint8_t { field3d, field2d, fieldperp };
77+
/// Is this an instance of `Field3D`, `Field2D`, or `FieldPerp`?
78+
virtual FieldType field_type() const = 0;
79+
7480
// Defines interface which must be implemented
7581
/// True if variable is 3D
76-
virtual bool is3D() const = 0;
82+
[[deprecated("Use `field_type()` instead")]]
83+
bool is3D() const {
84+
return field_type() == FieldType::field3d;
85+
}
86+
7787
/// Number of BoutReals in one element
7888
virtual int elementSize() const { return 1; }
7989

80-
virtual void doneComms(){}; // Notifies that communications done
90+
virtual void doneComms() {}; // Notifies that communications done
8191

8292
// Boundary conditions
8393
void setBoundary(const std::string& name); ///< Set the boundary conditions
@@ -86,13 +96,13 @@ public:
8696
copyBoundary(const FieldData& f); ///< Copy the boundary conditions from another field
8797

8898
virtual void applyBoundary(bool UNUSED(init) = false) {}
89-
virtual void applyTDerivBoundary(){};
99+
virtual void applyTDerivBoundary() {};
90100

91-
virtual void applyParallelBoundary(){};
92-
virtual void applyParallelBoundary(BoutReal UNUSED(t)){};
93-
virtual void applyParallelBoundary(const std::string& UNUSED(condition)){};
101+
virtual void applyParallelBoundary() {};
102+
virtual void applyParallelBoundary(BoutReal UNUSED(t)) {};
103+
virtual void applyParallelBoundary(const std::string& UNUSED(condition)) {};
94104
virtual void applyParallelBoundary(const std::string& UNUSED(region),
95-
const std::string& UNUSED(condition)){};
105+
const std::string& UNUSED(condition)) {};
96106
// JMAD
97107
void addBndryFunction(FuncPtr userfunc, BndryLoc location);
98108
void addBndryGenerator(FieldGeneratorPtr gen, BndryLoc location);

include/bout/fieldperp.hxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ public:
300300
*/
301301
int getNz() const override { return nz; };
302302

303-
bool is3D() const override { return false; }
304303
FieldType field_type() const override { return FieldType::fieldperp; }
305304

306305
friend void swap(FieldPerp& first, FieldPerp& second) noexcept;

include/bout/vector2d.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
1414
*
1515
* Contact: Ben Dudson, bd512@york.ac.uk
16-
*
16+
*
1717
* This file is part of BOUT++.
1818
*
1919
* BOUT++ is free software: you can redistribute it and/or modify
@@ -142,7 +142,7 @@ public:
142142
CELL_LOC getLocation() const override;
143143

144144
// FieldData virtual functions
145-
bool is3D() const override { return false; }
145+
FieldType field_type() const override { return FieldType::field2d; }
146146
int elementSize() const override { return 3; }
147147

148148
/// Apply boundary condition to all fields

include/bout/vector3d.hxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
1010
*
1111
* Contact: Ben Dudson, bd512@york.ac.uk
12-
*
12+
*
1313
* This file is part of BOUT++.
1414
*
1515
* BOUT++ is free software: you can redistribute it and/or modify
@@ -45,10 +45,10 @@ class Vector2D;
4545
* -------
4646
*
4747
* Vector3D f;
48-
*
48+
*
4949
* a.x; // Error! a.x not allocated
5050
*
51-
*
51+
*
5252
*/
5353
class Vector3D : public FieldData {
5454
public:
@@ -70,7 +70,7 @@ public:
7070
~Vector3D() override;
7171

7272
/*!
73-
* The components of the vector. These can be
73+
* The components of the vector. These can be
7474
* either co- or contra-variant, depending on
7575
* the boolean flag "covariant"
7676
*/
@@ -92,8 +92,8 @@ public:
9292
bool covariant{true};
9393

9494
/*!
95-
* In-place conversion to covariant form.
96-
*
95+
* In-place conversion to covariant form.
96+
*
9797
* If already covariant (covariant = true) then does nothing
9898
* If contravariant, multiplies by metric tensor g_{ij}
9999
*/
@@ -104,7 +104,7 @@ public:
104104
*
105105
* If already contravariant (covariant = false) then does nothing
106106
* If covariant, multiplies by metric tensor g^{ij}
107-
*
107+
*
108108
*/
109109
void toContravariant();
110110

@@ -114,14 +114,14 @@ public:
114114
* The first time this is called, a new Vector3D object is created.
115115
* Subsequent calls return a pointer to this same object
116116
*
117-
* For convenience, a standalone function "ddt" exists, so that
117+
* For convenience, a standalone function "ddt" exists, so that
118118
*
119119
* ddt(v) is equivalent to *(v.timeDeriv())
120-
*
120+
*
121121
* This does some book-keeping to ensure that the time derivative
122122
* of the components is the same as the components of the time derivative
123123
*
124-
* ddt(v).x == ddt(v.x)
124+
* ddt(v).x == ddt(v.x)
125125
*/
126126
Vector3D* timeDeriv();
127127

@@ -172,7 +172,7 @@ public:
172172
CELL_LOC getLocation() const override;
173173

174174
// FieldData virtual functions
175-
bool is3D() const override { return true; }
175+
FieldType field_type() const override { return FieldType::field3d; }
176176
int elementSize() const override { return 3; }
177177

178178
void applyBoundary(bool init = false) override;
@@ -203,7 +203,7 @@ const Vector3D cross(const Vector3D& lhs, const Vector2D& rhs);
203203

204204
/*!
205205
* Absolute magnitude (modulus) of a vector |v|
206-
*
206+
*
207207
* sqrt( v.x^2 + v.y^2 + v.z^2 )
208208
*/
209209
const Field3D abs(const Vector3D& v, const std::string& region = "RGN_ALL");

tests/unit/field/test_field.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class FieldSubClass : public Field {
2424
FieldSubClass(Mesh* localmesh, CELL_LOC location_in, DirectionTypes directions_in)
2525
: Field(localmesh, location_in, directions_in) {}
2626

27-
bool is3D() const override { return false; }
2827
int size() const override { return 42; }
2928
FieldType field_type() const override { return FieldType::field2d; }
3029
};

tests/unit/field/test_vector2d.cxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ TEST_F(Vector2DTest, ApplyBoundaryString) {
9797
EXPECT_DOUBLE_EQ(v.x(2, 2), 0.0);
9898
}
9999

100-
TEST_F(Vector2DTest, Is3D) {
101-
Vector2D vector;
102-
103-
EXPECT_FALSE(vector.is3D());
104-
}
105-
106100
TEST_F(Vector2DTest, BoutRealSize) {
107101
Vector2D vector;
108102

tests/unit/field/test_vector3d.cxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ TEST_F(Vector3DTest, ApplyBoundaryString) {
100100
EXPECT_DOUBLE_EQ(v.x(2, 2, 1), 0.0);
101101
}
102102

103-
TEST_F(Vector3DTest, Is3D) {
104-
Vector3D vector;
105-
106-
EXPECT_TRUE(vector.is3D());
107-
}
108-
109103
TEST_F(Vector3DTest, BoutRealSize) {
110104
Vector3D vector;
111105

0 commit comments

Comments
 (0)