Skip to content

Commit bfbae40

Browse files
committed
Merge remote-tracking branch 'origin/par-metrics' into HEAD
2 parents cbacecc + 1a5b922 commit bfbae40

35 files changed

+514
-296
lines changed

.github/workflows/clang-tidy-review.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
uses: ZedThree/clang-tidy-review@v0.23.1
2525
id: review
2626
with:
27-
annotations: true
2827
build_dir: build
2928
apt_packages: "libfftw3-dev,libnetcdf-c++4-dev,libopenmpi-dev,petsc-dev,slepc-dev,liblapack-dev,libparpack2-dev,libsundials-dev,uuid-dev"
3029
config_file: ".clang-tidy"

include/bout/field.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,15 @@ inline void checkPositive(const T& f, const std::string& name = "field",
296296
template <typename T>
297297
inline T toFieldAligned(const T& f, const std::string& region = "RGN_ALL") {
298298
static_assert(bout::utils::is_Field_v<T>, "toFieldAligned only works on Fields");
299+
ASSERT3(f.getCoordinates() != nullptr);
299300
return f.getCoordinates()->getParallelTransform().toFieldAligned(f, region);
300301
}
301302

302303
/// Convert \p f from field-aligned space in \p region (default: whole domain)
303304
template <typename T>
304305
inline T fromFieldAligned(const T& f, const std::string& region = "RGN_ALL") {
305306
static_assert(bout::utils::is_Field_v<T>, "fromFieldAligned only works on Fields");
307+
ASSERT3(f.getCoordinates() != nullptr);
306308
return f.getCoordinates()->getParallelTransform().fromFieldAligned(f, region);
307309
}
308310

include/bout/field2d.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
*/
2727
#include "bout/utils.hxx"
28+
#include <optional>
2829
class Field2D;
2930

3031
#pragma once
@@ -251,8 +252,7 @@ public:
251252
Field2D& operator/=(BoutReal rhs);
252253

253254
// FieldData virtual functions
254-
255-
bool is3D() const override { return false; }
255+
FieldType field_type() const override { return FieldType::field2d; }
256256

257257
#if CHECK > 0
258258
void doneComms() override { bndry_xin = bndry_xout = bndry_yup = bndry_ydown = true; }

include/bout/field3d.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public:
497497
Field3D& update_subtraction_inplace(BoutReal rhs);
498498

499499
// FieldData virtual functions
500-
bool is3D() const override { return true; }
500+
FieldType field_type() const override { return FieldType::field3d; }
501501

502502
#if CHECK > 0
503503
void doneComms() override { bndry_xin = bndry_xout = bndry_yup = bndry_ydown = true; }

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/fieldgroup.hxx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
#ifndef BOUT_FIELDGROUP_H
22
#define BOUT_FIELDGROUP_H
33

4-
#include "bout/field_data.hxx"
5-
#include <bout/field3d.hxx>
6-
4+
#include <bout/traits.hxx>
75
#include <bout/vector2d.hxx>
86
#include <bout/vector3d.hxx>
97

108
#include <vector>
119

12-
#include <algorithm>
10+
class Field2D;
11+
class Field3D;
12+
class FieldPerp;
13+
class Field;
1314

1415
/// Group together fields for easier communication
1516
///
16-
/// Note: The FieldData class is used as a base class,
17-
/// which is inherited by Field2D, Field3D, Vector2D and Vector3D
18-
/// however Vector2D and Vector3D are stored by reference to their
19-
/// components (x,y,z) as Field2D or Field3D objects.
17+
/// Note: The `Field` class is used as a base class,
18+
/// which is inherited by `Field2D`, `Field3D`, `FieldPerp`;
19+
/// however `Vector2D` and `Vector3D` are stored by reference to their
20+
/// components ``(x, y, z)`` as `Field2D` or `Field3D` objects.
2021
class FieldGroup {
2122
public:
2223
FieldGroup() = default;
2324
FieldGroup(const FieldGroup& other) = default;
2425
FieldGroup(FieldGroup&& other) = default;
2526
FieldGroup& operator=(const FieldGroup& other) = default;
2627
FieldGroup& operator=(FieldGroup&& other) = default;
28+
~FieldGroup() = default;
2729

28-
/// Constructor with a single FieldData \p f
29-
FieldGroup(FieldData& f) { fvec.push_back(&f); }
30-
31-
/// Constructor with a single Field3D \p f
30+
FieldGroup(Field& f) { fvec.push_back(&f); }
3231
FieldGroup(Field3D& f) {
3332
fvec.push_back(&f);
3433
f3vec.push_back(&f);
@@ -56,7 +55,7 @@ public:
5655
}
5756

5857
/// Variadic constructor. Allows an arbitrary number of
59-
/// FieldData arguments
58+
/// Field arguments
6059
///
6160
/// The explicit keyword prevents FieldGroup being constructed with arbitrary
6261
/// types. In particular arguments to add() cannot be implicitly converted
@@ -78,12 +77,12 @@ public:
7877
return *this;
7978
}
8079

81-
/// Add a FieldData \p f to the group.
80+
/// Add a Field \p f to the group.
8281
///
8382
/// A pointer to this field will be stored internally,
8483
/// so the lifetime of this variable should be longer
8584
/// than the lifetime of this group.
86-
void add(FieldData& f) { fvec.push_back(&f); }
85+
void add(Field& f) { fvec.push_back(&f); }
8786

8887
// Add a 3D field \p f, which goes into both vectors.
8988
//
@@ -121,12 +120,8 @@ public:
121120
}
122121

123122
/// Add multiple fields to this group
124-
///
125-
/// This is a variadic template which allows Field3D objects to be
126-
/// treated as a special case. An arbitrary number of fields can be
127-
/// added.
128123
template <typename... Ts>
129-
void add(FieldData& t, Ts&... ts) {
124+
void add(Field& t, Ts&... ts) {
130125
add(t); // Add the first using functions above
131126
add(ts...); // Add the rest
132127
}
@@ -165,16 +160,14 @@ public:
165160
}
166161

167162
/// Iteration over all fields
168-
using iterator = std::vector<FieldData*>::iterator;
169-
iterator begin() { return fvec.begin(); }
170-
iterator end() { return fvec.end(); }
163+
auto begin() { return fvec.begin(); }
164+
auto end() { return fvec.end(); }
171165

172166
/// Const iteration over all fields
173-
using const_iterator = std::vector<FieldData*>::const_iterator;
174-
const_iterator begin() const { return fvec.begin(); }
175-
const_iterator end() const { return fvec.end(); }
167+
auto begin() const { return fvec.cbegin(); }
168+
auto end() const { return fvec.cend(); }
176169

177-
const std::vector<FieldData*>& get() const { return fvec; }
170+
const std::vector<Field*>& get() const { return fvec; }
178171

179172
/// Iteration over 3D fields
180173
const std::vector<Field3D*>& field3d() const { return f3vec; }
@@ -183,8 +176,8 @@ public:
183176
void makeUnique();
184177

185178
private:
186-
std::vector<FieldData*> fvec; // Vector of fields
187-
std::vector<Field3D*> f3vec; // Vector of 3D fields
179+
std::vector<Field*> fvec; // Vector of fields
180+
std::vector<Field3D*> f3vec; // Vector of 3D fields
188181
};
189182

190183
/// Combine two FieldGroups

include/bout/fieldperp.hxx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
66
*
77
* Contact: Ben Dudson, bd512@york.ac.uk
8-
*
8+
*
99
* This file is part of BOUT++.
1010
*
1111
* BOUT++ is free software: you can redistribute it and/or modify
@@ -23,6 +23,8 @@
2323
*
2424
**************************************************************************/
2525

26+
#include <cstddef>
27+
#include <optional>
2628
#include <vector>
2729
class FieldPerp;
2830

@@ -45,8 +47,8 @@ class Field3D; // #include "bout/field3d.hxx"
4547

4648
/*!
4749
* Represents a 2D field perpendicular to the magnetic field
48-
* at a particular index in Y, which only varies in X-Z.
49-
*
50+
* at a particular index in Y, which only varies in X-Z.
51+
*
5052
* Primarily used inside field solvers
5153
*/
5254
class FieldPerp : public Field {
@@ -59,7 +61,8 @@ public:
5961
FieldPerp(Mesh* fieldmesh = nullptr, CELL_LOC location_in = CELL_CENTRE,
6062
int yindex_in = -1,
6163
DirectionTypes directions_in = {YDirectionType::Standard,
62-
ZDirectionType::Standard});
64+
ZDirectionType::Standard},
65+
std::optional<size_t> regionID = {});
6366

6467
/*!
6568
* Copy constructor. After this the data
@@ -205,7 +208,7 @@ public:
205208

206209
/*!
207210
* Access to the underlying data array at a given x,z index
208-
*
211+
*
209212
* If CHECK > 2 then bounds checking is performed, otherwise
210213
* no checks are performed
211214
*/
@@ -241,9 +244,9 @@ public:
241244
}
242245

243246
/*!
244-
* Access to the underlying data array. (X,Y,Z) indices for consistency with
247+
* Access to the underlying data array. (X,Y,Z) indices for consistency with
245248
* other field types
246-
*
249+
*
247250
*/
248251
BoutReal& operator()(int jx, int UNUSED(jy), int jz) { return (*this)(jx, jz); }
249252

@@ -252,7 +255,7 @@ public:
252255
}
253256

254257
/*!
255-
* Addition, modifying in-place.
258+
* Addition, modifying in-place.
256259
* This loops over the entire domain, including guard/boundary cells
257260
*/
258261
FieldPerp& operator+=(const FieldPerp& rhs);
@@ -261,7 +264,7 @@ public:
261264
FieldPerp& operator+=(BoutReal rhs);
262265

263266
/*!
264-
* Subtraction, modifying in place.
267+
* Subtraction, modifying in place.
265268
* This loops over the entire domain, including guard/boundary cells
266269
*/
267270
FieldPerp& operator-=(const FieldPerp& rhs);
@@ -270,7 +273,7 @@ public:
270273
FieldPerp& operator-=(BoutReal rhs);
271274

272275
/*!
273-
* Multiplication, modifying in place.
276+
* Multiplication, modifying in place.
274277
* This loops over the entire domain, including guard/boundary cells
275278
*/
276279
FieldPerp& operator*=(const FieldPerp& rhs);
@@ -279,7 +282,7 @@ public:
279282
FieldPerp& operator*=(BoutReal rhs);
280283

281284
/*!
282-
* Division, modifying in place.
285+
* Division, modifying in place.
283286
* This loops over the entire domain, including guard/boundary cells
284287
*/
285288
FieldPerp& operator/=(const FieldPerp& rhs);
@@ -300,7 +303,7 @@ public:
300303
*/
301304
int getNz() const override { return nz; };
302305

303-
bool is3D() const override { return false; }
306+
FieldType field_type() const override { return FieldType::fieldperp; }
304307

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

include/bout/globalindexer.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public:
8686

8787
int localSize = size();
8888
MPI_Comm comm =
89-
std::is_same_v<T, FieldPerp> ? fieldmesh->getXcomm() : BoutComm::get();
89+
std::is_same_v<T, FieldPerp> ? fieldmesh->getXZcomm() : BoutComm::get();
9090
fieldmesh->getMpi().MPI_Scan(&localSize, &globalEnd, 1, MPI_INT, MPI_SUM, comm);
9191
globalEnd--;
9292
int counter = globalStart = globalEnd - size() + 1;

include/bout/hypre_interface.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public:
159159
explicit HypreVector(IndexerPtr<T> indConverter) : indexConverter(indConverter) {
160160
Mesh& mesh = *indConverter->getMesh();
161161
const MPI_Comm comm =
162-
std::is_same_v<T, FieldPerp> ? mesh.getXcomm() : BoutComm::get();
162+
std::is_same_v<T, FieldPerp> ? mesh.getXZcomm() : BoutComm::get();
163163

164164
HYPRE_BigInt jlower = indConverter->getGlobalStart();
165165
HYPRE_BigInt jupper = jlower + indConverter->size() - 1; // inclusive end
@@ -380,7 +380,7 @@ public:
380380
: hypre_matrix(new HYPRE_IJMatrix, MatrixDeleter{}), index_converter(indConverter) {
381381
Mesh* mesh = indConverter->getMesh();
382382
const MPI_Comm comm =
383-
std::is_same_v<T, FieldPerp> ? mesh->getXcomm() : BoutComm::get();
383+
std::is_same_v<T, FieldPerp> ? mesh->getXZcomm() : BoutComm::get();
384384
parallel_transform = &mesh->getCoordinates()->getParallelTransform();
385385

386386
ilower = indConverter->getGlobalStart();
@@ -812,7 +812,7 @@ public:
812812
"values are: gmres, bicgstab, pcg")
813813
.withDefault(HYPRE_SOLVER_TYPE::bicgstab);
814814

815-
comm = std::is_same_v<T, FieldPerp> ? mesh.getXcomm() : BoutComm::get();
815+
comm = std::is_same_v<T, FieldPerp> ? mesh.getXZcomm() : BoutComm::get();
816816

817817
auto print_level =
818818
options["hypre_print_level"]

0 commit comments

Comments
 (0)