FiniteDifferenceFunction
The FiniteDifferenceFunction encapsulates a bunch of functionality extracted from Fornberger’s Calculation of Wieghts in Finite Difference Formulas
Only applies to direct product grids, but each subgrid can be regular or irregular.
Used in a large number of other places, but relatively rarely on its own.
A convenient application is the FiniteDifferenceDerivative class in the Derivatives module.
__init__(self, *diffs, axes=0, contract=False):
Constructs an object to take finite differences derivatives of grids of data
diffs:FiniteDifference1DA set of differences to take along successive axes in the data
axes:int | Iterable[int]The axes to take the specified differences along
contract:boolWhether to reduce the shape of the returned tensor if applicable after application
apply(self, vals, axes=None, mesh_spacing=None, contract=None):
Iteratively applies the stored finite difference objects to the vals
vals:np.ndarrayThe tensor of values to take the difference on
axes:int | Iterable[int]The axis or axes to take the differences along (defaults to
self.axes):returns:np.ndarrayT h e
t e n s o r
o f
d e r i v a t i v e s
__call__(self, vals, axes=None, mesh_spacing=None):
@property
order(self):
:returns:tuple[int]t h e
o r d e r
o f
t h e
d e r i v a t i v e
r e q u e s t e d
@property
weights(self):
:returns:tuple[np.array[float]]t h e
w e i g h t s
f o r
t h e
s p e c i f i e d
s t e n c i l
@property
widths(self):
:returns:tuple[(int, int)]t h e
n u m b e r
o f
p o i n t s
i n
e a c h
d i m e n s i o n ,
l e f t
a n d
r i g h t ,
f o r
t h e
s p e c i f i e d
s t e n c i l
@classmethod
regular_difference(cls, order, mesh_spacing=None, accuracy=2, stencil=None, end_point_accuracy=2, axes=0, contract=True, **kwargs):
Constructs a FiniteDifferenceFunction appropriate for a regular grid with the given stencil
order:tuple[int]the order of the derivative
mesh_spacing:None | float | tuple[float]the spacing between grid points in the regular grid
haccuracy:None | int | tuple[int]the accuracy of the derivative that we’ll try to achieve as a power on
hstencil:None | int | tuple[int]the stencil to use for the derivative (overrides
accuracy)end_point_accuracy:None | int | tuple[int]the amount of extra accuracy to use at the edges of the grid
axes:None | int | tuple[int]the axes of the passed array for the derivative to be applied along
contract:boolwhether to eliminate any axes of size
1from the resultskwargs:Any:returns:_
@classmethod
from_grid(cls, grid, order, accuracy=2, stencil=None, end_point_accuracy=2, axes=0, contract=True, **kwargs):
Constructs a FiniteDifferenceFunction from a grid and order.
Deconstructs the grid into its subgrids and builds a different differencer for each dimension
grid:np.ndarrayThe grid to use as input data when defining the derivative
order:int or list of intsorder of the derivative to compute
stencil:int or list of intsnumber of points to use in the stencil
:returns:FiniteDifferenceFunctiond e r i v
f u n c
Examples
FiniteDifferenceFunction
The FiniteDifferenceFunction encapsulates a bunch of functionality extracted from Fornberger’s Calculation of Wieghts in Finite Difference Formulas (https://epubs.siam.org/doi/pdf/10.1137/S0036144596322507)
Only applies to direct product grids, but each subgrid can be regular or irregular
Properties and Methods
regular_difference: method
from_grid: method
__init__(self, *diffs, axes=0, contract=False):
Constructs an object to take finite differences derivatives of grids of data
diffs:FiniteDifference1DA set of differences to take along successive axes in the data
axes:int | Iterable[int]The axes to take the specified differences along
contract:boolWhether to reduce the shape of the returned tensor if applicable after application
apply(self, vals, axes=None, mesh_spacing=None, contract=None):
Iteratively applies the stored finite difference objects to the vals
vals:np.ndarrayThe tensor of values to take the difference on
axes:int | Iterable[int]The axis or axes to take the differences along (defaults to
self.axes):returns:np.ndarrayThe tensor of derivatives
__call__(self, vals, axes=None, mesh_spacing=None):
@property
order(self):
:returns:tuple[int]the order of the derivative requested
@property
weights(self):
:returns:tuple[np.array[float]]the weights for the specified stencil
@property
widths(self):
:returns:tuple[(int, int)]the number of points in each dimension, left and right, for the specified stencil
Examples
Edit Examples or
Create New Examples
Edit Template or
Create New Template
Edit Docstrings