File boutmesh.hxx

class BoutMesh : public Mesh
#include <boutmesh.hxx>

Implementation of Mesh (mostly) compatible with BOUT

Topology and communications compatible with BOUT conventions.

Public Functions

BoutMesh(GridDataSource *s, Options *options = nullptr)
~BoutMesh()
int load()

Read in the mesh from data sources.

comm_handle send(FieldGroup &g)

Send data between processors Does not wait for communications to complete, so wait() must be called before guard cell values are used

Example

Parameters
  • g: A group of fields to communicate

comm_handle handle = mesh->send(group); … mesh->wait(handle);

int wait(comm_handle handle)

Wait for a send operation to complete

Parameters
  • handle: The handle returned by send()

MPI_Request sendToProc(int xproc, int yproc, BoutReal *buffer, int size, int tag)

Low-level communication routine Send a buffer of data from this processor to another This must be matched by a corresponding call to receiveFromProc on the receiving processor

Parameters
  • xproc: X index of processor to send to
  • yproc: Y index of processor to send to
  • buffer: A buffer of data to send
  • size: The length of buffer
  • tag: A label, must be the same at receive

comm_handle receiveFromProc(int xproc, int yproc, BoutReal *buffer, int size, int tag)

Low-level communication routine Receive a buffer of data from another processor Must be matched by corresponding sendToProc call on the sending processor

Parameters
  • xproc: X index of sending processor
  • yproc: Y index of sending processor
  • buffer: The buffer to fill with data. Must already be allocated of length size
  • size: The length of buffer
  • tag: A label, must be the same as send

int getNXPE()

The number of processors in the X direction.

int getNYPE()

The number of processors in the Y direction.

int getXProcIndex()

This processor’s index in X direction.

int getYProcIndex()

This processor’s index in Y direction.

bool firstX()

Is this processor the first in X? i.e. is there a boundary to the left in X?

bool lastX()

Is this processor last in X? i.e. is there a boundary to the right in X?

int sendXOut(BoutReal *buffer, int size, int tag)

Send a buffer of data to processor at X index +1

Parameters
  • buffer: The data to send. Must be at least length size
  • size: The number of BoutReals to send
  • tag: A label for the communication. Must be the same at receive

int sendXIn(BoutReal *buffer, int size, int tag)

Send a buffer of data to processor at X index -1

Parameters
  • buffer: The data to send. Must be at least length size
  • size: The number of BoutReals to send
  • tag: A label for the communication. Must be the same at receive

comm_handle irecvXOut(BoutReal *buffer, int size, int tag)

Receive a buffer of data from X index +1

Parameters
  • buffer: A buffer to put the data in. Must already be allocated of length size
  • size: The number of BoutReals to receive and put in buffer
  • tag: A label for the communication. Must be the same as sent

comm_handle irecvXIn(BoutReal *buffer, int size, int tag)

Receive a buffer of data from X index -1

Parameters
  • buffer: A buffer to put the data in. Must already be allocated of length size
  • size: The number of BoutReals to receive and put in buffer
  • tag: A label for the communication. Must be the same as sent

MPI_Comm getXcomm(int jy) const

Return communicator containing all processors in X.

MPI_Comm getYcomm(int jx) const

Return communicator containing all processors in Y.

bool periodicY(int jx, BoutReal &ts) const

Is local X index jx periodic in Y?

Parameters
  • jx: The local (on this processor) index in X
  • ts: The Twist-Shift angle if periodic

bool periodicY(int jx) const

Is local X index jx periodic in Y?

Parameters
  • jx: The local (on this processor) index in X

std::pair<bool, BoutReal> hasBranchCutLower(int jx) const

Is there a branch cut at this processor’s lower boundary?

Return
pair<bool, BoutReal> - bool is true if there is a branch cut, BoutReal gives the total zShift for a 2pi poloidal circuit if there is a branch cut
Parameters
  • jx: The local (on this processor) index in X

std::pair<bool, BoutReal> hasBranchCutUpper(int jx) const

Is there a branch cut at this processor’s upper boundary?

Return
pair<bool, BoutReal> - bool is true if there is a branch cut, BoutReal gives the total zShift for a 2pi poloidal circuit if there is a branch cut
Parameters
  • jx: The local (on this processor) index in X

int ySize(int jx) const

The number of points in Y at fixed X index jx.

bool firstY() const

Is this processor first in Y? i.e. is there a boundary at lower Y?

bool lastY() const

Is this processor last in Y? i.e. is there a boundary at upper Y?

bool firstY(int xpos) const

Is this processor first in Y? i.e. is there a boundary at lower Y?

bool lastY(int xpos) const

Is this processor last in Y? i.e. is there a boundary at upper Y?

int UpXSplitIndex()

If the upper Y guard cells are split in two, return the X index where the split occurs.

int DownXSplitIndex()

If the lower Y guard cells are split in two, return the X index where the split occurs.

int sendYOutIndest(BoutReal *buffer, int size, int tag)

Send data.

int sendYOutOutdest(BoutReal *buffer, int size, int tag)
int sendYInIndest(BoutReal *buffer, int size, int tag)
int sendYInOutdest(BoutReal *buffer, int size, int tag)
comm_handle irecvYOutIndest(BoutReal *buffer, int size, int tag)

Non-blocking receive. Must be followed by a call to wait()

Parameters
  • buffer: A buffer of length size which must already be allocated
  • size: The number of BoutReals expected
  • tag: The tag number of the expected message

comm_handle irecvYOutOutdest(BoutReal *buffer, int size, int tag)

Non-blocking receive. Must be followed by a call to wait()

Parameters
  • buffer: A buffer of length size which must already be allocated
  • size: The number of BoutReals expected
  • tag: The tag number of the expected message

comm_handle irecvYInIndest(BoutReal *buffer, int size, int tag)

Non-blocking receive. Must be followed by a call to wait()

Parameters
  • buffer: A buffer of length size which must already be allocated
  • size: The number of BoutReals expected
  • tag: The tag number of the expected message

comm_handle irecvYInOutdest(BoutReal *buffer, int size, int tag)

Non-blocking receive. Must be followed by a call to wait()

Parameters
  • buffer: A buffer of length size which must already be allocated
  • size: The number of BoutReals expected
  • tag: The tag number of the expected message

const RangeIterator iterateBndryLowerY() const

Iterate over the lower Y boundary.

const RangeIterator iterateBndryUpperY() const

Iterate over the upper Y boundary.

const RangeIterator iterateBndryLowerInnerY() const
const RangeIterator iterateBndryLowerOuterY() const
const RangeIterator iterateBndryUpperInnerY() const
const RangeIterator iterateBndryUpperOuterY() const
std::vector<BoundaryRegion *> getBoundaries()

Return a vector containing all the boundary regions on this processor.

std::vector<BoundaryRegionPar *> getBoundariesPar()

Get all the parallel (Y) boundaries on this processor.

void addBoundaryPar(BoundaryRegionPar *bndry)

Add a parallel(Y) boundary to this processor.

const Field3D smoothSeparatrix(const Field3D &f)

Branch-cut special handling (experimental)

int getNx() const
int getNy() const
BoutReal GlobalX(int jx) const

Continuous X index between 0 and 1.

BoutReal GlobalY(int jy) const

Continuous Y index (0 -> 1)

BoutReal GlobalX(BoutReal jx) const

Continuous X index between 0 and 1.

BoutReal GlobalY(BoutReal jy) const

Continuous Y index (0 -> 1)

BoutReal getIxseps1() const
BoutReal getIxseps2() const
void outputVars(Datafile &file)

Add output variables to a data file These are used for post-processing

int getGlobalXIndex(int xlocal) const

Returns a global X index given a local index. Global index includes boundary cells, local index includes boundary or guard cells.

int getGlobalXIndexNoBoundaries(int xlocal) const

Returns a global X index given a local index. Global index excludes boundary cells, local index includes boundary or guard cells.

int getGlobalYIndex(int ylocal) const

Returns a global Y index given a local index. Global index includes boundary cells, local index includes boundary or guard cells.

int getGlobalYIndexNoBoundaries(int ylocal) const

Returns a global Y index given a local index. Global index excludes boundary cells, local index includes boundary or guard cells.

int getGlobalZIndex(int zlocal) const

Returns a global Z index given a local index. Global index includes boundary cells, local index includes boundary or guard cells.

int getGlobalZIndexNoBoundaries(int zlocal) const

Returns a global Z index given a local index. Global index excludes boundary cells, local index includes boundary or guard cells. Note: at the moment z-direction is always periodic, so has zero boundary cells

int XLOCAL(int xglo) const

Returns a local X index given a global index.

int YLOCAL(int yglo) const

Returns a local Y index given a global index.

Private Functions

int XGLOBAL(BoutReal xloc, BoutReal &xglo) const

Returns the global X index given a local index.

int YGLOBAL(BoutReal yloc, BoutReal &yglo) const

Returns the global Y index given a local index.

int PROC_NUM(int xind, int yind)

Returns the processor number, given X and Y processor indices.

If out of range returns -1 (no processor)

int YGLOBAL(int yloc, int yproc) const

Global Y index given local index and processor.

int YLOCAL(int yglo, int yproc) const
int YPROC(int yind)

Return the Y processor number given a global Y index.

int XPROC(int xind)

Return the X processor number given a global X index.

void default_connections()

Connection initialisation: Set processors in a simple 2D grid.

void set_connection(int ypos1, int ypos2, int xge, int xlt, bool ts = false)

Add a topology connection.

Set ypos1 and ypos2 to be neighbours in the range xge <= x < xlt. Optional argument ts sets whether to use twist-shift condition

void add_target(int ypos, int xge, int xlt)

Add a divertor target or limiter.

ypos is the y index which will become an upper target ypos+1 will become a lower target. Target created in the range xge <= x < xlt.

void topology()
void addBoundaryRegions()

Adds 2D and 3D regions for boundaries.

void free_handle(CommHandle *h)
BoutMesh::CommHandle *get_handle(int xlen, int ylen)
void clear_handles()
void post_receive(CommHandle &ch)

Create the MPI requests to receive data. Non-blocking call.

int pack_data(const std::vector<FieldData *> &var_list, int xge, int xlt, int yge, int ylt, BoutReal *buffer)

Take data from objects and put into a buffer.

int unpack_data(const std::vector<FieldData *> &var_list, int xge, int xlt, int yge, int ylt, BoutReal *buffer)

Copy data from a buffer back into the fields.

Private Members

std::string gridname
int nx
int ny
int nz

Size of the grid in the input file.

int MX
int MY
int MZ

size of the grid excluding boundary regions

int MYSUB
int MXSUB
int MZSUB

Size of the grid on this processor.

int NPES

Number of processors.

int MYPE

Rank of this processor.

int PE_YIND

Y index of this processor.

int NYPE
int NZPE
int MYPE_IN_CORE
int ixseps1
int ixseps2
int jyseps1_1
int jyseps2_1
int jyseps1_2
int jyseps2_2
int ixseps_inner
int ixseps_outer
int ixseps_upper
int ixseps_lower
int ny_inner
std::vector<BoutReal> ShiftAngle

Angle for twist-shift location.

bool TS_up_in
bool TS_up_out
bool TS_down_in
bool TS_down_out
int UDATA_INDEST
int UDATA_OUTDEST
int UDATA_XSPLIT
int DDATA_INDEST
int DDATA_OUTDEST
int DDATA_XSPLIT
int IDATA_DEST
int ODATA_DEST
bool TwistShift
bool symmetricGlobalX

Use a symmetric definition in GlobalX() function.

bool symmetricGlobalY
int zperiod
BoutReal ZMIN
BoutReal ZMAX
int MXG
int MYG
int MZG
std::vector<BoundaryRegion *> boundary
std::vector<BoundaryRegionPar *> par_boundary
bool async_send

Switch to asyncronous sends (ISend, not Send)

std::list<CommHandle *> comm_list
MPI_Comm comm_x

Communicator containing all processors in X.

MPI_Comm comm_inner

Communicators in Y. Inside both separatrices; between separatrices; and outside both separatrices

MPI_Comm comm_middle
MPI_Comm comm_outer
struct CommHandle

Communication handle Used to keep track of communications between send and receive

Public Members

MPI_Request request[6]

Array of receive requests. One for each possible neighbour; one each way in X, two each way in Y

MPI_Request sendreq[6]

Array of send requests (for non-blocking send). One for each possible neighbour; one each way in X, two each way in Y

int xbufflen

Length of the buffers used to send/receive (in BoutReals)

int ybufflen
Array<BoutReal> umsg_sendbuff

Sending buffers.

Array<BoutReal> dmsg_sendbuff
Array<BoutReal> imsg_sendbuff
Array<BoutReal> omsg_sendbuff
Array<BoutReal> umsg_recvbuff

Receiving buffers.

Array<BoutReal> dmsg_recvbuff
Array<BoutReal> imsg_recvbuff
Array<BoutReal> omsg_recvbuff
bool in_progress

Is the communication still going?

FieldGroup var_list

List of fields being communicated.