Cell approximator#

class sigmaepsilon.mesh.cellapproximator.LagrangianCellApproximator(cell_class: Any, x_source: Iterable | None = None)[source]#

An approximator for Lagrangian cells. It can be constructed directly or using a cell class from the library.

Parameters:
  • cell_class (PolyCell) – A Lagrangian cell class that provides the batteries for interpolation. The capabilities of this class determines the nature and accuracy of the interpolation/extrapolation.

  • x_source (Iterable, Optional) – The process of interpolation involves calculating the inverse of a matrix. If you plan to use an interpolator many times using the same set of source points, it is a good idea to fed the instance with these coordinates at the time of instantiation. This way the expensive part of the calculation is only done once, and subsequent evaluations are faster. Default is None.

Notes

Depending on the number of nodes of the element (hence the order of the approximation functions), the approximation may be exact interpolation or some kind of regression. For instance, if you try to extrapolate from 3 values using a 2-noded line element, the approximator is overfitted and the approximation is an ecaxt one only if all the data values fit a line perfectly.

Examples

Create an approximator using 8-noded hexahedrons.

>>> from sigmaepsilon.mesh import LagrangianCellApproximator
>>> from sigmaepsilon.mesh.cells import H8
>>> approximator = LagrangianCellApproximator(H8)

The data to feed the approximator:

>>> source_coordinates = H8.master_coordinates() / 2
>>> source_values = [1, 2, 3, 4, 5, 6, 7, 8]
>>> target_coordinates = H8.master_coordinates() * 2

The desired data at the target locations:

>>> target_values = approximator(
...     source=source_coordinates,
...     target=target_coordinates,
...     values=source_values
... )

This approximator can also be created using the class diretly:

>>> approximator = H8.Geometry.approximator()

If you want to reuse the approximator with the same set of source coordinates many times, you can feed these points to the approximator at instance creation:

>>> approximator = H8.Geometry.approximator(source_coordinates)
>>> approximator = LagrangianCellApproximator(H8, source_coordinates)

Then, only source values and target coordinates have to be provided for approximation to happen (in fact, you will get an Exception of you provide source coordinates both at creation and approximator):

>>> target_values = approximator(
...     target=target_coordinates,
...     values=source_values
... )

To approximator multidimensional data, you have to carefully organize the input values for utmost performance. The memory layout is optimal if the axis that goes along the input points is the last one:

>>> approximator = H8.Geometry.approximator()
>>> source_values = np.random.rand(10, 2, 8)
>>> approximator(
...     source=source_coordinates,
...     values=source_values,
...     target=target_coordinates[:3]
... ).shape
(10, 2, 3)

If it is not the last axis, you can use the ‘axis’ parameter:

>>> source_values = np.random.rand(8, 2, 10)
>>> approximator(
...     source=source_coordinates,
...     values=source_values,
...     target=target_coordinates[:3],
...     axis=0,
... ).shape
(3, 2, 10)
approximator_function(*, x_source: Iterable | None = None, shp_source_inverse: Iterable | None = None, values_source: Iterable | None = None, x_target: Iterable | None = None, axis: int | None = None) float | ndarray#

Returns interpolated values from a set of known points and values.