initialize_function

initialize_function(function, data, nbl, mapper=None, mode='constant', name=None, pad_halo=True, **kwargs)

Initialize a Function with the given data. data does not include the nbl outer/boundary layers; these are added via padding by this function.

Parameters

Name Type Description Default
function Function or list of Functions The initialised object. required
data ndarray or Function or list of ndarray/Function The data used for initialisation. required
nbl int or tuple of int or tuple of tuple of int Number of outer layers (such as absorbing layers for boundary damping). required
mapper dict Dictionary containing, for each dimension of function, a sub-dictionary containing the following keys: 1) ‘lhs’: List of additional expressions to be added to the LHS expressions list. 2) ‘rhs’: List of additional expressions to be added to the RHS expressions list. 3) ‘options’: Options pertaining to the additional equations that will be constructed. None
mode str The function initialisation mode. ‘constant’ and ‘reflect’ are accepted. 'constant'
name str The name assigned to the operator. None
pad_halo bool Whether to also pad the outer halo. True

Examples

In the following example the 'interior' of a function is set to one plus the value on the boundary.

>>> import numpy as np
>>> from devito import Grid, SubDomain, Function, initialize_function

Create the computational domain:

>>> grid = Grid(shape=(6, 6))
>>> x, y = grid.dimensions

Create the Function we wish to set along with the data to set it:

>>> f = Function(name='f', grid=grid, dtype=np.int32)
>>> data = np.full((4, 4), 2, dtype=np.int32)

Now create the additional expressions and options required to set the value of the interior region to one greater than the boundary value. Note that the equation is specified on the second (final) grid dimension so that additional equation is executed after padding is complete.

>>> lhs = f
>>> rhs = f+1
>>> options = {'subdomain': grid.subdomains['interior']}
>>> mapper = {}
>>> mapper[y] = {'lhs': lhs, 'rhs': rhs, 'options': options}

Call the initialize_function routine:

>>> initialize_function(f, data, 1, mapper=mapper)
>>> f.data
Data([[2, 2, 2, 2, 2, 2],
      [2, 3, 3, 3, 3, 2],
      [2, 3, 3, 3, 3, 2],
      [2, 3, 3, 3, 3, 2],
      [2, 3, 3, 3, 3, 2],
      [2, 2, 2, 2, 2, 2]], dtype=int32)
Back to top