Derivative
Derivative()
An unevaluated Derivative, which carries metadata (Dimensions, derivative order, etc) describing how the derivative will be expanded upon evaluation.
Parameters
Name | Type | Description | Default |
---|---|---|---|
expr | expr - like | Expression for which the Derivative is produced. | required |
dims | Dimension or tuple of Dimension | Dimensions w.r.t. which to differentiate. | required |
fd_order | int, tuple of int or dict of {Dimension: int} | Coefficient discretization order. Note: this impacts the width of the resulting stencil. | 1 |
deriv_order | Derivative order. | required | |
side | Side or tuple of Side | Side of the finite difference location, centered (at x), left (at x - 1) or right (at x +1). | centered |
transpose | Transpose | Forward (matvec=direct) or transpose (matvec=transpose) mode of the finite difference. | direct |
subs | dict | Substitutions to apply to the finite-difference expression after evaluation. | required |
x0 | dict | Origin (where the finite-difference is evaluated at) for the finite-difference scheme, e.g. {x: x, y: y + h_y/2}. | required |
Examples
Creation
>>> from devito import Function, Derivative, Grid
>>> grid = Grid((10, 10))
>>> x, y = grid.dimensions
>>> u = Function(name="u", grid=grid, space_order=2)
>>> Derivative(u, x)
Derivative(u(x, y), x)
This can also be obtained via the differential shortcut
>>> u.dx
Derivative(u(x, y), x)
You can also specify the order as a keyword argument
>>> Derivative(u, x, deriv_order=2)
2)) Derivative(u(x, y), (x,
Or as a tuple
>>> Derivative(u, (x, 2))
2)) Derivative(u(x, y), (x,
Once again, this can be obtained via shortcut notation
>>> u.dx2
2)) Derivative(u(x, y), (x,
Derivative object are also callable to change default setup:
>>> u.dx2(x0=x + x.spacing)
2)) Derivative(u(x, y), (x,
will create the second derivative at x=x + x.spacing. Accepted arguments for dynamic evaluation are x0
, fd_order
and side
.
Attributes
Name | Description |
---|---|
T | Transpose of the Derivative. |
Methods
Name | Description |
---|---|
func | Reconstruct self via self.__class__(*args, **kwargs) using |
func
*args, **kwargs) func(
Reconstruct self
via self.__class__(*args, **kwargs)
using self
’s __rargs__
and __rkwargs__
if and where *args
and **kwargs
lack entries.
Examples
Given
class Foo:
__rargs__ = ('a', 'b')
__rkwargs__ = ('c',)
def __init__(self, a, b, c=4):
self.a = a
self.b = b
self.c = c
a = foo(3, 5)`
Then:
* `a._rebuild() -> x(3, 5, 4)` (i.e., copy of `a`).
* `a._rebuild(4) -> x(4, 5, 4)`
* `a._rebuild(4, 7) -> x(4, 7, 4)`
* `a._rebuild(c=5) -> x(3, 5, 5)`
* `a._rebuild(1, c=7) -> x(1, 5, 7)`