Grid

Grid(self, shape, extent=None, origin=None, dimensions=None, time_dimension=None, dtype=np.float32, subdomains=None, comm=None, topology=None)

A cartesian grid that encapsulates a computational domain over which to discretize a Function.

Parameters

Name Type Description Default
shape tuple of ints Shape of the computational domain in grid points. required
extent tuple of floats Physical extent of the domain in m. unit box of extent 1m in all dimensions
origin tuple of floats Physical coordinate of the origin of the domain. 0.0 in all dimensions
dimensions tuple of SpaceDimension The dimensions of the computational domain encapsulated by this Grid. None
time_dimension devito.types.dimension.TimeDimension The dimension used to define time in a TimeFunction created from this Grid. None
dtype devito.data - type Any object that can be interpreted as a numpy data type, used as default data type to be inherited by all Functions created from this Grid. np.float32
subdomains tuple of SubDomain If no subdomains are specified, the Grid only defines the two default subdomains interior and domain. None
comm MPI communicator The set of processes over which the grid is distributed. Only relevant in case of MPI execution. None

Examples

>>> from devito import Grid, Function
>>> grid = Grid(shape=(4, 4), extent=(3.0, 3.0))
>>> f = Function(name='f', grid=grid)
>>> f.shape
(4, 4)
>>> f.dimensions
(x, y)
>>> f.dtype
<class 'numpy.float32'>

In a Function, the domain defined by a Grid is often surrounded by a “halo region”, which guarantees the correctness of stencil updates nearby the domain boundary. However, the size of the halo region does not depend on the Grid; for more information, refer to Function.__doc__.

>>> f.shape_with_halo
(6, 6)

Notes

A Grid encapsulates the topology and geometry information of the computational domain that a Function can be discretized on. As such, it defines and provides the physical coordinate information of the logical cartesian grid underlying the discretized Functions. For example, the conventions for defining the coordinate space in 2D are:

.. code-block:: python

               x
     |----------------------->
     |  origin
     |     o------------o
     |     |            |
     |     |            |
     |     |   DOMAIN   | extent[1]
 y   |     |            |
     |     |            |
     |     |  extent[0] |
     |     o------------o
     |             origin + extent
     |
     v

Attributes

Name Description
comm The MPI communicator inherited from the distributor.
dimension_map Map between SpaceDimensions and their global/local size.
distributor The Distributor used for MPI-decomposing the CartesianDiscretization.
extent Physical extent of the domain in m.
interior The interior SubDomain of the Grid.
origin Physical coordinates of the domain origin.
origin_ioffset Offset index of the local (per-process) origin from the domain origin.
origin_map Map between origin symbols and their values.
origin_offset Physical offset of the local (per-process) origin from the domain origin.
origin_symbols Symbols representing the grid origin in each SpaceDimension.
shape_local Shape of the local (per-process) physical domain.
spacing Spacing between grid points in m.
spacing_map Map between spacing symbols and their values for each SpaceDimension.
spacing_symbols Symbols representing the grid spacing in each SpaceDimension.
stepping_dim Stepping dimension associated with this Grid.
subdomains The SubDomains defined in this Grid.
time_dim Time dimension associated with this Grid.
volume_cell Volume of a single cell e.g h_xh_yh_z in 3D.

Methods

Name Description
is_distributed True if dim is a distributed Dimension for this CartesianDiscretization,

is_distributed

is_distributed(dim)

True if dim is a distributed Dimension for this CartesianDiscretization, False otherwise.

Back to top