class devito.types.Grid(shape, extent=None, origin=None, dimensions=None, time_dimension=None, dtype=<class 'numpy.float32'>, subdomains=None, comm=None, topology=None)[source]

Bases: CartesianDiscretization, ArgProvider

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

  • shape (tuple of ints) – Shape of the computational domain in grid points.

  • extent (tuple of floats, optional) – Physical extent of the domain in m; defaults to a unit box of extent 1m in all dimensions.

  • origin (tuple of floats, optional) – Physical coordinate of the origin of the domain; defaults to 0.0 in all dimensions.

  • dimensions (tuple of SpaceDimension, optional) – The dimensions of the computational domain encapsulated by this Grid.

  • time_dimension (TimeDimension, optional) – The dimension used to define time in a TimeFunction created from this Grid.

  • dtype (data-type, optional) – 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. Defaults to np.float32.

  • subdomains (tuple of SubDomain, optional) – If no subdomains are specified, the Grid only defines the two default subdomains interior and domain.

  • comm (MPI communicator, optional) – The set of processes over which the grid is distributed. Only relevant in case of MPI execution.


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


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:

    |  origin
    |     o------------o
    |     |            |
    |     |            |
    |     |   DOMAIN   | extent[1]
y   |     |            |
    |     |            |
    |     |  extent[0] |
    |     o------------o
    |             origin + extent
property comm

The MPI communicator inherited from the distributor.

property dimension_map

Map between SpaceDimensions and their global/local size.

property distributor

The Distributor used for MPI-decomposing the CartesianDiscretization.

property extent

Physical extent of the domain in m.

property interior

The interior SubDomain of the Grid.


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

property origin

Physical coordinates of the domain origin.

property origin_map

Map between origin symbols and their values.

property origin_offset

Offset of the local (per-process) origin from the domain origin.

property origin_symbols

Symbols representing the grid origin in each SpaceDimension.

property shape_local

Shape of the local (per-process) physical domain.

property spacing

Spacing between grid points in m.


Map between spacing symbols and their values for each SpaceDimension.


Symbols representing the grid spacing in each SpaceDimension.

property stepping_dim

Stepping dimension associated with this Grid.

property subdomains

The SubDomains defined in this Grid.

property time_dim

Time dimension associated with this Grid.

property volume_cell

Volume of a single cell e.g h_x*h_y*h_z in 3D.