Dimension

Dimension()

Symbol defining an iteration space.

A Dimension represents a problem dimension. It is typically used to index into Functions, but it can also appear in the middle of a symbolic expression just like any other symbol.

Dimension is the root of a hierarchy of classes, which looks as follows (only the classes exposed to the level of the user API are shown)::

                               Dimension
                                   |
                      ---------------------------
                      |                         |
               DerivedDimension            DefaultDimension
                      |
           ---------------------
           |                   |
      SubDimension   ConditionalDimension

Parameters

Name Type Description Default
name str Name of the dimension. required
spacing symbol A symbol to represent the physical spacing along this Dimension. h_name

Examples

Dimensions are automatically created when a Grid is instantiated.

>>> from devito import Grid
>>> grid = Grid(shape=(4, 4))
>>> x, y = grid.dimensions
>>> type(x)
<class 'devito.types.dimension.SpaceDimension'>
>>> time = grid.time_dim
>>> type(time)
<class 'devito.types.dimension.TimeDimension'>
>>> t = grid.stepping_dim
>>> type(t)
<class 'devito.types.dimension.SteppingDimension'>

Alternatively, one can create Dimensions explicitly

>>> from devito import Dimension
>>> i = Dimension(name='i')

Or, when many “free” Dimensions are needed, with the shortcut

>>> from devito import dimensions
>>> i, j, k = dimensions('i j k')

A Dimension can be used to build a Function as well as within symbolic expressions, as both array index (“indexed notation”) and free symbol.

>>> from devito import Function
>>> f = Function(name='f', shape=(4, 4), dimensions=(i, j))
>>> f + f
2*f(i, j)
>>> f[i + 1, j] + f[i, j + 1]
f[i, j + 1] + f[i + 1, j]
>>> f*i
i*f(i, j)

Attributes

Name Description
is_AbstractSub bool(x) -> bool
is_Block bool(x) -> bool
is_Conditional bool(x) -> bool
is_Custom bool(x) -> bool
is_Default bool(x) -> bool
is_Derived bool(x) -> bool
is_Dimension bool(x) -> bool
is_Incr bool(x) -> bool
is_Modulo bool(x) -> bool
is_MultiSub bool(x) -> bool
is_NonlinearDerived bool(x) -> bool
is_Space bool(x) -> bool
is_Stencil bool(x) -> bool
is_Stepping bool(x) -> bool
is_Sub bool(x) -> bool
is_SubIterator bool(x) -> bool
is_Time bool(x) -> bool
is_Virtual bool(x) -> bool
spacing Symbol representing the physical spacing along the Dimension.
symbolic_incr The increment value while iterating over the Dimension.
symbolic_max Symbol defining the maximum point of the Dimension.
symbolic_min Symbol defining the minimum point of the Dimension.
symbolic_size Symbolic size of the Dimension.

Methods

Name Description
class_key Overrides sympy.Symbol.class_key such that Dimensions always

class_key

class_key()

Overrides sympy.Symbol.class_key such that Dimensions always preceed other symbols when printed (e.g. x + h_x, not h_x + x).

Back to top