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: FiniteDifference1D

    A set of differences to take along successive axes in the data

  • axes: int | Iterable[int]

    The axes to take the specified differences along

  • contract: bool

    Whether 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.ndarray

    The 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.ndarray

    The tensor of derivatives

 

__call__(self, vals, axes=None, mesh_spacing=None): 

LLM Docstring

Apply the finite-difference weights to a set of values (delegates to apply).

  • vals: np.ndarray

    the values on the grid

  • axes: Any

    the axes to difference along

  • mesh_spacing: Any

    the grid spacing(s)

  • :returns: np.ndarray

    the finite-difference derivative

 

@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

 

@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 h

  • accuracy: None | int | tuple[int]

    the accuracy of the derivative that we’ll try to achieve as a power on h

  • stencil: 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: bool

    whether to eliminate any axes of size 1 from the results

  • kwargs: Any
  • :returns: _

 

@classmethod
from_grid(cls, grid, order, accuracy=2, stencil=None, end_point_accuracy=2, axes=0, contract=True, allow_irregular=False, **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.ndarray

    The grid to use as input data when defining the derivative

  • order: int or list of ints

    order of the derivative to compute

  • stencil: int or list of ints

    number of points to use in the stencil

  • :returns: FiniteDifferenceFunction

    deriv func


Feedback

Examples

Templates

Documentation