Field

Interface

class ScalarFieldDeviceHandler

a device-compatible structure that represents a scalar field

Subclassed by mirheo::ScalarField

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 ScalarField)

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

class ScalarField : public mirheo::ScalarFieldDeviceHandler, public mirheo::MirSimulationObject

Driver class used to create a ScalarFieldDeviceHandler.

Subclassed by mirheo::ScalarFieldFromFile, mirheo::ScalarFieldFromFunction

Public Functions

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

Construct a ScalarField 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

ScalarField(ScalarField&&)

move constructor

const ScalarFieldDeviceHandler &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 ScalarField.

Must be called before handler().

Parameters
  • comm: The cartesian communicator of the domain.

Derived classes

class ScalarFieldFromFile : public mirheo::ScalarField

a ScalarField that can be initialized from a file

Public Functions

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

Construct a ScalarFieldFromFile 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).

ScalarFieldFromFile(ScalarFieldFromFile&&)

move constructor

void setup(const MPI_Comm &comm)

Prepare the internal state of the ScalarField.

Must be called before handler().

Parameters
  • comm: The cartesian communicator of the domain.

class ScalarFieldFromFunction : public mirheo::ScalarField

a ScalarField that can be initialized from a ScalarFieldFunction

Public Functions

ScalarFieldFromFunction(const MirState *state, std::string name, ScalarFieldFunction func, real3 h, real3 margin)

Construct a ScalarFieldFromFunction 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

ScalarFieldFromFunction(ScalarFieldFromFunction&&)

move constructor

void setup(const MPI_Comm &comm)

Prepare the internal state of the ScalarField.

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