Field

Interface

class FieldDeviceHandler

a device-compatible structure that represents a scalar field

Subclassed by mirheo::Field

Public Functions

real operator()(real3 x) const

Evaluate the field at a given position.

Warning

The position must be inside the subdomain enlarged with a given margin (see c Field)

Return
The scalar value at x
Parameters
  • x: The position, in local coordinates

class Field : public mirheo::FieldDeviceHandler, public mirheo::MirSimulationObject

Driver class used to create a FieldDeviceHandler.

Subclassed by mirheo::FieldFromFile, mirheo::FieldFromFunction

Public Functions

Field(const MirState *state, std::string name, real3 h, real3 margin)

Construct a Field object.

Parameters
  • state: The global state of the system
  • name: The name of the field object
  • h: the grid size
  • margin: Additional margin to store in each rank

Field(Field&&)

move constructor

const FieldDeviceHandler &handler() const

Return
The handler that can be used on the device

virtual void setup(const MPI_Comm &comm) = 0

Prepare the internal state of the Field.

Must be called before handler().

Parameters
  • comm: The cartesian communicator of the domain.

Derived classes

class FieldFromFile : public mirheo::Field

a Field that can be initialized from a file

Public Functions

FieldFromFile(const MirState *state, std::string name, std::string fieldFileName, real3 h, real3 margin)

Construct a FieldFromFile object.

The format of the file is custom. It is a single file that contains a header followed by the data grid data in binary format. The header is composed of two lines in ASCII format:

  • domain size (3 floating point numbers)
  • number of grid points (3 integers)
Parameters
  • state: The global state of the system
  • name: The name of the field object
  • fieldFileName: The input file name
  • h: the grid size
  • margin: Additional margin to store in each rank

The data is an array that contains all grid values (x is the fast running index).

FieldFromFile(FieldFromFile&&)

move constructor

void setup(const MPI_Comm &comm)

Prepare the internal state of the Field.

Must be called before handler().

Parameters
  • comm: The cartesian communicator of the domain.

class FieldFromFunction : public mirheo::Field

a Field that can be initialized from FieldFunction

Public Functions

FieldFromFunction(const MirState *state, std::string name, FieldFunction func, real3 h, real3 margin)

Construct a FieldFromFunction object.

The scalar values will be discretized and stored on the grid. This can be useful as one can have a general scalar field configured on the host (e.g. from python) but usable on the device.

Parameters
  • state: The global state of the system
  • name: The name of the field object
  • func: The scalar field function
  • h: the grid size
  • margin: Additional margin to store in each rank

FieldFromFunction(FieldFromFunction&&)

move constructor

void setup(const MPI_Comm &comm)

Prepare the internal state of the Field.

Must be called before handler().

Parameters
  • comm: The cartesian communicator of the domain.

Utilities

template <typename FieldHandler>
real3 mirheo::computeGradient(const FieldHandler &field, real3 x, real h)

compute the gradient of a scalar field using finite differences on the device

Return
The approximation of the gradient of field at x
Template Parameters
  • FieldHandler: Type of device handler describing the field. Must contain parenthesis operator
Parameters
  • field: The functor that describes the continuous scalar field
  • x: The position at which to compute the gradient
  • h: The step size used to compute the gradient