Common

Devito

class stride.physics.common.devito.GridDevito(space_order, time_order, time_dim=None, **kwargs)[source]

Bases: Gridded

Instances of this class encapsulate the Devito grid, and interact with it by generating appropriate functions on demand.

Instances will also keep a cache of created Devito functions under the vars attribute, which can be accessed by name using dot notation.

Parameters:
  • space_order (int) – Default space order of the discretisation for functions of the grid.

  • time_order (int) – Default time order of the discretisation for functions of the grid.

  • time_dim (Time, optional) – Time dimension on which to step. or False if no time dependency.

  • grid (Grid, optional) – Existing grid, if not provided one will be created. Either a grid or space, time and slow_time need to be provided.

  • space (Space, optional) –

  • time (Time, optional) –

  • slow_time (SlowTime, optional) –

deallocate(name, collect=False)[source]

Remove internal references to data buffers, if name is cached.

Parameters:
  • name (str) – Name of the function.

  • collect (bool, optional) – Whether to garbage collect after deallocate, defaults to False.

delete(name, collect=False)[source]

Remove internal references to devito function, if name is cached.

Parameters:
  • name (str) – Name of the function.

  • collect (bool, optional) – Whether to garbage collect after deallocate, defaults to False.

func(name, cached=False)[source]

Re-instantiate devito function, if name is cached.

Parameters:
  • name (str) – Name of the function.

  • cached (bool, optional) – Whether to cache the result of the func call, defaults to False.

function(name, space_order=None, **kwargs)[source]

Create a Devito Function with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.Function

sparse_function(name, num=1, space_order=None, coordinates=None, interpolation_type='linear', **kwargs)[source]

Create a Devito SparseFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • num (int, optional) – Number of points in the function, defaults to 1.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • coordinates (ndarray, optional) – Spatial coordinates of the sparse points (num points, dimensions), only needed when interpolation is not linear.

  • interpolation_type (str, optional) – Type of interpolation to perform (linear or hicks), defaults to linear, computationally more efficient but less accurate.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.SparseTimeFunction

sparse_time_function(name, num=1, space_order=None, time_order=None, coordinates=None, interpolation_type='linear', **kwargs)[source]

Create a Devito SparseTimeFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • num (int, optional) – Number of points in the function, defaults to 1.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • time_order (int, optional) – Time order of the discretisation, defaults to the grid time order.

  • coordinates (ndarray, optional) – Spatial coordinates of the sparse points (num points, dimensions), only needed when interpolation is not linear.

  • interpolation_type (str, optional) – Type of interpolation to perform (linear or hicks), defaults to linear, computationally more efficient but less accurate.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.SparseTimeFunction

symbol(name, dtype=<class 'numpy.float32'>, **kwargs)[source]

Create a Devito Function with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • dtype (data-type, optional) – Data type for the symbol, defaults to float32.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated symobl.

Return type:

devito.Symbol

tensor_time_function(name, space_order=None, time_order=None, **kwargs)[source]

Create a Devito TensorTimeFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • time_order (int, optional) – Time order of the discretisation, defaults to the grid time order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.TimeFunction

time_function(name, space_order=None, time_order=None, **kwargs)[source]

Create a Devito TimeFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • time_order (int, optional) – Time order of the discretisation, defaults to the grid time order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.TimeFunction

undersampled_time_derivative(fun, factor, time_bounds=None, offset=None, deriv_order=1, fd_order=1)[source]
undersampled_time_function(name, factor, time_bounds=None, space_order=None, time_order=None, **kwargs)[source]

Create an undersampled version of a Devito function with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • factor (int) – Undersampling factor.

  • time_bounds (tuple, optional) – Timestep bounds in which the function is sampled, defaults to all timesteps.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • time_order (int, optional) – Time order of the discretisation, defaults to the grid time order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.Function

vector_function(name, space_order=None, **kwargs)[source]

Create a Devito VectorFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.VectorFunction

vector_time_function(name, space_order=None, time_order=None, **kwargs)[source]

Create a Devito VectorTimeFunction with parameters provided.

Parameters:
  • name (str) – Name of the function.

  • space_order (int, optional) – Space order of the discretisation, defaults to the grid space order.

  • time_order (int, optional) – Time order of the discretisation, defaults to the grid time order.

  • kwargs – Additional arguments for the Devito constructor.

Returns:

Generated function.

Return type:

devito.VectorTimeFunction

with_halo(data, value=None, time_dependent=False, is_vector=False, **kwargs)[source]

Pad ndarray with appropriate halo given the grid space order.

Parameters:
  • data (ndarray) – Array to pad

  • value (float, optional) – Value used for the filling, defaults to edge value.

  • time_dependent (bool, optional) – Whether the array should be considered time dependent, defaults to False.

  • is_vector (bool, optional) – Whether the array should be considered a vector field, defaults to False.

Returns:

Padded array.

Return type:

ndarray

class stride.physics.common.devito.OperatorDevito(*args, grid=None, name='kernel', **kwargs)[source]

Bases: object

Instances of this class encapsulate Devito operators, how to configure them and how to run them.

Parameters:
  • grid (GridDevito, optional) – Predefined GridDevito. A new one will be created unless specified.

  • name (str) – Name to give to the operator, defaults to kernel.

compile()[source]

Compile the operator.

run(**kwargs)[source]

Run the operator.

set_operator(op, **kwargs)[source]

Set up a Devito operator from a list of operations.

Parameters:
  • op (list) – List of operations to be given to the devito.Operator instance.

  • kwargs (optional) – Configuration parameters to set for Devito overriding defaults.