File globalfield.hxx#
-
class GlobalField#
- #include <globalfield.hxx>
This provides a method for gathering and scattering a field which takes into account the local and global indices
This is a base class which is inherited by GlobalField2D and GlobalField3D
Subclassed by GlobalField2D, GlobalField3D
Public Functions
-
GlobalField() = delete#
-
virtual ~GlobalField() = default#
-
virtual bool valid() const = 0#
Is the data valid on any processor?
-
inline bool dataIsLocal() const#
Data is on this processor.
-
inline BoutReal &operator()(int jx, int jy, int jz)#
Data access by index. This doesn’t perform any checks, so the user should first test if the data is available on this processor by calling dataIsLocal()
-
inline int xSize() const#
Size of the field in X.
-
inline int ySize() const#
Size of the field in Y.
-
inline int zSize() const#
Size of the field in Z.
Protected Functions
-
void proc_local_origin(int proc, int *x, int *y, int *z = nullptr) const#
-
void proc_origin(int proc, int *x, int *y, int *z = nullptr) const#
Return the global origin of processor proc.
-
void proc_size(int proc, int *lx, int *ly, int *lz = nullptr) const#
Return the array size of processor proc.
-
GlobalField() = delete#
-
class GlobalField2D : public GlobalField#
- #include <globalfield.hxx>
Gather and scatter a Field2D
Example
To create a GlobalField2D, pass a mesh pointer
GlobalField2D g2d(mesh);
By default data is gathered and scattered to/from processor 0. To change this, pass the processor number as a second argument:
GlobalField3D g2d(mesh, 1); // Gather onto processor 1
Gather and scatter methods operate on Field2D objects:
Field2D localdata; g2d.gather(localdata); // Gather onto one processsor
To scatter data back, use the scatter method:
localdata = g2d.scatter();
Note that both gather and scatter are collective operations, which must be performed by all processors.
To test if the data is available on a processor, use:
if(g2d.dataIsLocal()) { // g2d data on this processor }
The data in a GlobalField2D can be accessed using (x,y,z) indexing, with the index ranges given by xSize, ySize, zSize methods.
for ( int x=0; x<g2d.xSize(); x++) for ( int y=0; y<g2d.ySize(); y++) output.write(" Value at ({:d} ,{:d}) is {:e}\n" , x, y, g2d(x, y));
Public Functions
-
GlobalField2D() = delete#
Can’t be constructed without args.
-
GlobalField2D(Mesh *mesh, int proc = 0)#
Construct, giving a mesh and an optional processor
- Parameters:
mesh – [in] The mesh to gather over
proc – [in] The processor index where everything will be gathered/scattered to/from
-
~GlobalField2D() override#
Destructor.
-
inline virtual bool valid() const override#
Is the data valid and on this processor?
-
inline GlobalField2D &operator=(const Field2D &rhs)#
Assignment from a 2D field. Shorthand for a gather, and must be called on all processors The scatter assignment operator needs to be a member of Field2D.
Private Functions
-
int msg_len(int proc) const#
The length of message (in BoutReals) to be sent to or from processor
proc
- Parameters:
proc – [in] MPI processor index
-
GlobalField2D() = delete#
-
class GlobalField3D : public GlobalField#
- #include <globalfield.hxx>
Gather and scatter a Field3D to/from one processor
Example
To create a GlobalField3D, pass a mesh pointer
GlobalField3D g3d(mesh);
By default data is gathered and scattered to/from processor 0. To change this, pass the processor number as a second argument:
GlobalField3D g3d(mesh, 1); // Gather onto processor 1
Gather and scatter methods operate on Field3D objects:
Field3D localdata; g3d.gather(localdata); // Gather onto one processsor
To scatter data back, use the scatter method:
localdata = g3d.scatter();
Note that both gather and scatter are collective operations, which must be performed by all processors.
To test if the data is available on a processor, use:
if(g3d.dataIsLocal()) { // g3d data on this processor }
The data in a GlobalField3D can be accessed using (x,y,z) indexing, with the index ranges given by xSize, ySize, zSize methods.
for ( int x=0; x<g3d.xSize(); x++) for ( int y=0; y<g3d.ySize(); y++) for ( int z=0; z<g3d.zSize(); z++) output.write(" Value at ({:d} ,{:d} ,{:d}) is {:e}\n" , x, y, z, g3d(x, y, z));
Public Functions
-
GlobalField3D() = delete#
Can’t be constructed without args.
-
GlobalField3D(Mesh *mesh, int proc = 0)#
Construct, giving a mesh and an optional processor
- Parameters:
mesh – [in] The mesh to gather over
proc – [in] The processor index where everything will be gathered/scattered to/from
-
~GlobalField3D() override#
Destructor.
-
inline virtual bool valid() const override#
Test if the data is valid i.e. has been allocated.
-
inline GlobalField3D &operator=(const Field3D &rhs)#
Assignment from a 2D field. Shorthand for a gather, and must be called on all processors The scatter assignment operator needs to be a member of Field2D.
Private Functions
-
int msg_len(int proc) const#
The length of message (in BoutReals) to be sent to or from processor
proc
- Parameters:
proc – [in] MPI processor index
-
GlobalField3D() = delete#