Function¶

class
devito.types.
Function
(*args, **kwargs)[source]¶ Bases:
devito.types.dense.DiscreteFunction
,devito.finite_differences.differentiable.Differentiable
Discretized symbol representing an array in symbolic equations.
A Function carries multidimensional data and provides operations to create finitedifferences approximations.
A Function encapsulates spacevarying data; for data that also varies in time, use TimeFunction instead.
Parameters:  name (str) – Name of the symbol.
 grid (Grid, optional) – Carries shape, dimensions, and dtype of the Function. When grid is not provided, shape and dimensions must be given. For MPI execution, a Grid is compulsory.
 space_order (int or 3tuple of ints, optional) – Discretisation order for space derivatives. Defaults to 1.
space_order
also impacts the number of points available around a generic point of interest. By default,space_order
points are available on both sides of a generic point of interest, including those nearby the grid boundary. Sometimes, fewer points suffice; in other scenarios, more points are necessary. In such cases, instead of an integer, one can pass a 3tuple(o, lp, rp)
indicating the discretization order (o
) as well as the number of points on the left (lp
) and right (rp
) sides of a generic point of interest.  shape (tuple of ints, optional) – Shape of the domain region in grid points. Only necessary if
grid
isn’t given.  dimensions (tuple of Dimension, optional) – Dimensions associated with the object. Only necessary if
grid
isn’t given.  dtype (datatype, optional) – Any object that can be interpreted as a numpy data type. Defaults
to
np.float32
.  staggered (Dimension or tuple of Dimension or Stagger, optional) – Define how the Function is staggered.
 padding (int or tuple of ints, optional) – Allocate extra grid points to maximize data access alignment. When a tuple of ints, one int per Dimension should be provided.
 initializer (callable or any object exposing the buffer interface, optional) – Data initializer. If a callable is provided, data is allocated lazily.
 allocator (MemoryAllocator, optional) – Controller for memory allocation. To be used, for example, when one wants to take advantage of the memory hierarchy in a NUMA architecture. Refer to default_allocator.__doc__ for more information.
Examples
Creation
>>> from devito import Grid, Function >>> grid = Grid(shape=(4, 4)) >>> f = Function(name='f', grid=grid) >>> f f(x, y) >>> g = Function(name='g', grid=grid, space_order=2) >>> g g(x, y)
Firstorder derivatives through centered finitedifference approximations
>>> f.dx f(x, y)/h_x + f(x + h_x, y)/h_x >>> f.dy f(x, y)/h_y + f(x, y + h_y)/h_y >>> g.dx 0.5*g(x  h_x, y)/h_x + 0.5*g(x + h_x, y)/h_x >>> (f + g).dx (f(x, y) + g(x, y))/h_x + (f(x + h_x, y) + g(x + h_x, y))/h_x
Firstorder derivatives through left/right finitedifference approximations
>>> f.dxl f(x, y)/h_x  f(x  h_x, y)/h_x >>> g.dxl 1.5*g(x, y)/h_x + 0.5*g(x  2*h_x, y)/h_x  2.0*g(x  h_x, y)/h_x >>> f.dxr f(x, y)/h_x + f(x + h_x, y)/h_x
Secondorder derivative through centered finitedifference approximation
>>> g.dx2 2.0*g(x, y)/h_x**2 + g(x  h_x, y)/h_x**2 + g(x + h_x, y)/h_x**2
Notes
The parameters must always be given as keyword arguments, since SymPy uses
*args
to (re)create the dimension arguments of the symbolic object.
avg
(p=None, dims=None)[source]¶ Generate a symbolic expression computing the average of
p
points along the spatial dimensionsdims
.Parameters:  p (int, optional) – The number of summands. Defaults to the halo size.
 dims (tuple of Dimension, optional) – The Dimensions along which the average is computed. Defaults to
self
’s spatial dimensions.

data
¶ The domain data values, as a numpy.ndarray.
Elements are stored in rowmajor format.
Notes
With this accessor you are claiming that you will modify the values you get back. If you only need to look at the values, use
data_ro()
instead.

data_domain
¶ The domain data values.
Elements are stored in rowmajor format.
Notes
Alias to
self.data
.With this accessor you are claiming that you will modify the values you get back. If you only need to look at the values, use
data_ro_domain()
instead.

data_ro_domain
¶ Readonly view of the domain data values.

data_ro_with_halo
¶ Readonly view of the domain+outhalo data values.

data_with_halo
¶ The domain+outhalo data values.
Elements are stored in rowmajor format.
Notes
With this accessor you are claiming that you will modify the values you get back. If you only need to look at the values, use
data_ro_with_halo()
instead.

dimensions
¶ Tuple of Dimensions representing the object indices.

dtype
¶ The data type of the object.

grid
¶ The Grid on which the discretization occurred.

name
¶ The name of the object.

shape
¶ Shape of the domain region. The domain constitutes the area of the data written to by an Operator.
Notes
In an MPI context, this is the local domain region shape.

shape_allocated
¶ Shape of the allocated data. It includes the domain and inhalo regions, as well as any additional padding surrounding the halo.
Notes
In an MPI context, this is the local with_halo region shape.

shape_global
¶ Global shape of the domain region. The domain constitutes the area of the data written to by an Operator.
Notes
In an MPI context, this is the global domain region shape, which is therefore identical on all MPI ranks.

shape_with_halo
¶ Shape of the domain+outhalo region. The outhalo is the region surrounding the domain that may be read by an Operator.
Notes
In an MPI context, this is the local with_halo region shape. Further, note that the outhalo of inner ranks is typically empty, while the outhalo of boundary ranks contains a number of elements depending on the rank position in the decomposed grid (corner, side, …).

space_dimensions
¶ Tuple of Dimensions defining the physical space.

space_order
¶ The space order.

sum
(p=None, dims=None)[source]¶ Generate a symbolic expression computing the sum of
p
points along the spatial dimensionsdims
.Parameters:  p (int, optional) – The number of summands. Defaults to the halo size.
 dims (tuple of Dimension, optional) – The Dimensions along which the sum is computed. Defaults to
self
’s spatial dimensions.