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
2 changes: 1 addition & 1 deletion include/bout/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down
3 changes: 1 addition & 2 deletions include/bout/field2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ public:
Field2D& operator/=(BoutReal rhs);

// FieldData virtual functions

bool is3D() const override { return false; }
FieldType field_type() const override { return FieldType::field2d; }

#if CHECK > 0
void doneComms() override { bndry_xin = bndry_xout = bndry_yup = bndry_ydown = true; }
Expand Down
6 changes: 3 additions & 3 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -361,7 +361,7 @@ public:
* Direct access to the underlying data array
*
* If CHECK > 2 then bounds checking is performed
*
*
* If CHECK <= 2 then no checks are performed, to
* allow inlining and optimisation of inner loops
*/
Expand Down Expand Up @@ -473,7 +473,7 @@ public:
///@}

// FieldData virtual functions
bool is3D() const override { return true; }
FieldType field_type() const override { return FieldType::field3d; }

#if CHECK > 0
void doneComms() override { bndry_xin = bndry_xout = bndry_yup = bndry_ydown = true; }
Expand Down
26 changes: 18 additions & 8 deletions include/bout/field_data.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand All @@ -33,6 +33,7 @@ class FieldData;
#include "bout/bout_types.hxx"
#include "bout/unused.hxx"

#include <cstdint>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -71,13 +72,22 @@ public:
/// Get variable location
virtual CELL_LOC getLocation() const;

/// Enum to distinguish the different kinds of Fields
enum class FieldType : std::uint8_t { field3d, field2d, fieldperp };
/// Is this an instance of `Field3D`, `Field2D`, or `FieldPerp`?
virtual FieldType field_type() const = 0;

// Defines interface which must be implemented
/// True if variable is 3D
virtual bool is3D() const = 0;
[[deprecated("Use `field_type()` instead")]]
bool is3D() const {
return field_type() == FieldType::field3d;
}

/// Number of BoutReals in one element
virtual int elementSize() const { return 1; }

virtual void doneComms(){}; // Notifies that communications done
virtual void doneComms() {}; // Notifies that communications done

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

virtual void applyBoundary(bool UNUSED(init) = false) {}
virtual void applyTDerivBoundary(){};
virtual void applyTDerivBoundary() {};

virtual void applyParallelBoundary(){};
virtual void applyParallelBoundary(BoutReal UNUSED(t)){};
virtual void applyParallelBoundary(const std::string& UNUSED(condition)){};
virtual void applyParallelBoundary() {};
virtual void applyParallelBoundary(BoutReal UNUSED(t)) {};
virtual void applyParallelBoundary(const std::string& UNUSED(condition)) {};
virtual void applyParallelBoundary(const std::string& UNUSED(region),
const std::string& UNUSED(condition)){};
const std::string& UNUSED(condition)) {};
// JMAD
void addBndryFunction(FuncPtr userfunc, BndryLoc location);
void addBndryGenerator(FieldGeneratorPtr gen, BndryLoc location);
Expand Down
51 changes: 22 additions & 29 deletions include/bout/fieldgroup.hxx
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
#ifndef BOUT_FIELDGROUP_H
#define BOUT_FIELDGROUP_H

#include "bout/field_data.hxx"
#include <bout/field3d.hxx>

#include <bout/traits.hxx>
#include <bout/vector2d.hxx>
#include <bout/vector3d.hxx>

#include <vector>

#include <algorithm>
class Field2D;
class Field3D;
class FieldPerp;
class Field;

/// Group together fields for easier communication
///
/// Note: The FieldData class is used as a base class,
/// which is inherited by Field2D, Field3D, Vector2D and Vector3D
/// however Vector2D and Vector3D are stored by reference to their
/// components (x,y,z) as Field2D or Field3D objects.
/// Note: The `Field` class is used as a base class,
/// which is inherited by `Field2D`, `Field3D`, `FieldPerp`;
/// however `Vector2D` and `Vector3D` are stored by reference to their
/// components ``(x, y, z)`` as `Field2D` or `Field3D` objects.
class FieldGroup {
public:
FieldGroup() = default;
FieldGroup(const FieldGroup& other) = default;
FieldGroup(FieldGroup&& other) = default;
FieldGroup& operator=(const FieldGroup& other) = default;
FieldGroup& operator=(FieldGroup&& other) = default;
~FieldGroup() = default;

/// Constructor with a single FieldData \p f
FieldGroup(FieldData& f) { fvec.push_back(&f); }

/// Constructor with a single Field3D \p f
FieldGroup(Field& f) { fvec.push_back(&f); }
FieldGroup(Field3D& f) {
fvec.push_back(&f);
f3vec.push_back(&f);
Expand Down Expand Up @@ -56,7 +55,7 @@ public:
}

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

/// Add a FieldData \p f to the group.
/// Add a Field \p f to the group.
///
/// A pointer to this field will be stored internally,
/// so the lifetime of this variable should be longer
/// than the lifetime of this group.
void add(FieldData& f) { fvec.push_back(&f); }
void add(Field& f) { fvec.push_back(&f); }

// Add a 3D field \p f, which goes into both vectors.
//
Expand Down Expand Up @@ -121,12 +120,8 @@ public:
}

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

/// Iteration over all fields
using iterator = std::vector<FieldData*>::iterator;
iterator begin() { return fvec.begin(); }
iterator end() { return fvec.end(); }
auto begin() { return fvec.begin(); }
auto end() { return fvec.end(); }

/// Const iteration over all fields
using const_iterator = std::vector<FieldData*>::const_iterator;
const_iterator begin() const { return fvec.begin(); }
const_iterator end() const { return fvec.end(); }
auto begin() const { return fvec.cbegin(); }
auto end() const { return fvec.cend(); }

const std::vector<FieldData*>& get() const { return fvec; }
const std::vector<Field*>& get() const { return fvec; }

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

private:
std::vector<FieldData*> fvec; // Vector of fields
std::vector<Field3D*> f3vec; // Vector of 3D fields
std::vector<Field*> fvec; // Vector of fields
std::vector<Field3D*> f3vec; // Vector of 3D fields
};

/// Combine two FieldGroups
Expand Down
22 changes: 11 additions & 11 deletions include/bout/fieldperp.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -45,8 +45,8 @@ class Field3D; // #include "bout/field3d.hxx"

/*!
* Represents a 2D field perpendicular to the magnetic field
* at a particular index in Y, which only varies in X-Z.
*
* at a particular index in Y, which only varies in X-Z.
*
* Primarily used inside field solvers
*/
class FieldPerp : public Field {
Expand Down Expand Up @@ -205,7 +205,7 @@ public:

/*!
* Access to the underlying data array at a given x,z index
*
*
* If CHECK > 2 then bounds checking is performed, otherwise
* no checks are performed
*/
Expand Down Expand Up @@ -241,9 +241,9 @@ public:
}

/*!
* Access to the underlying data array. (X,Y,Z) indices for consistency with
* Access to the underlying data array. (X,Y,Z) indices for consistency with
* other field types
*
*
*/
BoutReal& operator()(int jx, int UNUSED(jy), int jz) { return (*this)(jx, jz); }

Expand All @@ -252,7 +252,7 @@ public:
}

/*!
* Addition, modifying in-place.
* Addition, modifying in-place.
* This loops over the entire domain, including guard/boundary cells
*/
FieldPerp& operator+=(const FieldPerp& rhs);
Expand All @@ -261,7 +261,7 @@ public:
FieldPerp& operator+=(BoutReal rhs);

/*!
* Subtraction, modifying in place.
* Subtraction, modifying in place.
* This loops over the entire domain, including guard/boundary cells
*/
FieldPerp& operator-=(const FieldPerp& rhs);
Expand All @@ -270,7 +270,7 @@ public:
FieldPerp& operator-=(BoutReal rhs);

/*!
* Multiplication, modifying in place.
* Multiplication, modifying in place.
* This loops over the entire domain, including guard/boundary cells
*/
FieldPerp& operator*=(const FieldPerp& rhs);
Expand All @@ -279,7 +279,7 @@ public:
FieldPerp& operator*=(BoutReal rhs);

/*!
* Division, modifying in place.
* Division, modifying in place.
* This loops over the entire domain, including guard/boundary cells
*/
FieldPerp& operator/=(const FieldPerp& rhs);
Expand All @@ -300,7 +300,7 @@ public:
*/
int getNz() const override { return nz; };

bool is3D() const override { return false; }
FieldType field_type() const override { return FieldType::fieldperp; }

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

Expand Down
16 changes: 6 additions & 10 deletions include/bout/mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*
* Interface for mesh classes. Contains standard variables and useful
* routines.
*
*
* Changelog
* =========
*
* 2014-12 Ben Dudson <bd512@york.ac.uk>
* * Removing coordinate system into separate
* Coordinates class
* * Adding index derivative functions from derivs.cxx
*
*
* 2010-06 Ben Dudson, Sean Farley
* * Initial version, adapted from GridData class
* * Incorporates code from topology.cpp and Communicator
Expand All @@ -20,7 +20,7 @@
* Copyright 2010-2025 BOUT++ contributors
*
* Contact: Ben Dudson, dudson2@llnl.gov
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -65,6 +65,7 @@ class Mesh;
#include <optional>
#include <set>
#include <string>
#include <vector>

class BoundaryRegion;
class BoundaryRegionPar;
Expand Down Expand Up @@ -301,11 +302,6 @@ public:
/// @param g The group of fields to communicate. Guard cells will be modified
void communicateYZ(FieldGroup& g);

/*!
* Communicate an X-Z field
*/
virtual void communicate(FieldPerp& f);

/*!
* Send a list of FieldData objects
* Packs arguments into a FieldGroup and passes
Expand Down Expand Up @@ -815,8 +811,8 @@ protected:
const std::vector<int> readInts(const std::string& name, int n);

/// Calculates the size of a message for a given x and y range
int msg_len(const std::vector<FieldData*>& var_list, int xge, int xlt, int yge,
int ylt);
int msg_len(const std::vector<Field*>& var_list, int xge, int xlt, int yge,
int ylt) const;

/// Initialise derivatives
void derivs_init(Options* options);
Expand Down
4 changes: 2 additions & 2 deletions include/bout/vector2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -142,7 +142,7 @@ public:
CELL_LOC getLocation() const override;

// FieldData virtual functions
bool is3D() const override { return false; }
FieldType field_type() const override { return FieldType::field2d; }
int elementSize() const override { return 3; }

/// Apply boundary condition to all fields
Expand Down
Loading
Loading