FmmTree¶
ferreus_bbfmm.FmmTree(source_points, interpolation_order, kernel_params, sparse, *, extents=None, params=None, target_points=None, target_grid=None)
¶
A Fast Multipole Method (FMM) tree that organises source points into a hierarchical spatial structure to accelerate kernel summation tasks.
The tree is adaptively and refined, with optional sparse leaf pruning. It efficiently precomputes all operators (M2M and M2L) required for far-field approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_points
|
NDArray[float64]
|
Source point locations used to build the tree. Expected to be a numpy array with shape (N, D), where N is the number of points and D is the dimensionality. |
required |
interpolation_order
|
int
|
Number of Chebyshev interpolation nodes per dimension. |
required |
kernel_params
|
KernelParams
|
KernelParams that define the kernel function used for interaction computations. |
required |
sparse
|
bool
|
If |
required |
extents
|
Optional[NDArray[float64]]
|
Optional bounding box |
None
|
params
|
Optional[FmmParams]
|
Optional parameters for tuning the FMM performance. |
None
|
target_points
|
Optional[NDArray[float64]]
|
Optional target locations used to guide adaptive refinement when |
None
|
target_grid
|
Optional[TargetGrid]
|
Optional regular target grid used to guide adaptive refinement, without target coordinates. Provide either target_points or target_grid. |
None
|
set_weights(weights)
¶
Performs an upward pass of the tree to set the multipole coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values) |
required |
evaluate(weights, target_points)
¶
Performs a downward pass of the tree to set the local coefficients and then performs a leaf evaluation pass to evaluate the values at the target locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values) |
required |
target_points
|
NDArray[float64]
|
Numpy array of shape (N, D), where N is the number of target points and D is the dimensionality. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape (N, K), where N is the number of target points and K is the number of right-hand-sides evaluated. |
evaluate_with_gradients(weights, target_points)
¶
Performs a downward pass of the tree to set the local coefficients and then performs a leaf evaluation pass to evaluate the values and gradients at the target locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values) |
required |
target_points
|
NDArray[float64]
|
Numpy array of shape (N, D), where N is the number of target points and D is the dimensionality. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape (N, K), where N is the number of target points and K is the number of right-hand-sides evaluated. |
gradients |
NDArray[float64]
|
Array of evaluated gradients with shape (N, D x M), where N is the number of target points,
D is the dimensionality and M is the number of columns of values interpolated. |
set_local_coefficients()
¶
Performs a downward pass of the tree to set the local coefficients. Intended to be
used after calling set_weights and before calling
evaluate_leaves.
evaluate_leaves(weights, target_points)
¶
Performs a leaf evaluation pass to calculate the values at the target locations.
Intended to be used after set_local_coefficients,
for when repeated calls to this function are desired, such as when using 'surface following'
isosurface generation algorithms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values) |
required |
target_points
|
NDArray[float64]
|
Numpy array of shape (N, D), where N is the number of target points and D is the dimensionality. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape (N, K), where N is the number of target points and K is the number of right-hand-sides evaluated. |
evaluate_leaves_with_gradients(weights, target_points)
¶
Performs a leaf evaluation pass to calculate the values and gradients at the target locations.
Intended to be used after set_local_coefficients,
for when repeated calls to this function are desired, such as when using 'surface following'
isosurface generation algorithms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values) |
required |
target_points
|
NDArray[float64]
|
Numpy array of shape (N, D), where N is the number of target points and D is the dimensionality. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape (N, K), where N is the number of target points and K is the number of right-hand-sides evaluated. |
gradients |
NDArray[float64]
|
Array of evaluated gradients with shape (N, D x M), where N is the number of target points,
D is the dimensionality and M is the number of columns of values interpolated. |
evaluate_grid(weights, grid)
¶
Performs a downward pass of the tree to set the local coefficients and then performs a leaf evaluation pass to evaluate the values at the grid target locations.
Call set_weights before evaluating, and repeat that step whenever the weights change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values). Must match the weights used to set the multipole coefficients. |
required |
grid
|
TargetGrid
|
Regular target grid with the same dimensionality as the tree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the grid dimensionality differs from the tree or the grid is not completely covered by its leaf cells. Sparse trees may omit cells containing grid targets. |
Notes
Target coordinates are generated as needed, without storing the complete coordinate matrix.
grid_shape is given by TargetGrid.shape.
evaluate_grid_with_gradients(weights, grid)
¶
Performs a downward pass of the tree to set the local coefficients and then performs a leaf evaluation pass to evaluate the values and gradients at the grid target locations.
Call set_weights before evaluating, and repeat that step whenever the weights change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values). Must match the weights used to set the multipole coefficients. |
required |
grid
|
TargetGrid
|
Regular target grid with the same dimensionality as the tree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape |
gradients |
NDArray[float64]
|
Array of evaluated gradients with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the grid dimensionality differs from the tree or the grid is not completely covered by its leaf cells. Sparse trees may omit cells containing grid targets. Also raised if the kernel does not support gradient evaluation. |
Notes
Target coordinates are generated as needed, without storing the complete coordinate matrix.
grid_shape is given by TargetGrid.shape.
evaluate_grid_leaves(weights, grid)
¶
Performs a leaf evaluation pass to calculate the values at the grid target locations. Intended to be
used after set_local_coefficients, for when repeated calls to this function are desired,
such as when using 'surface following' isosurface generation algorithms.
Call set_weights followed by set_local_coefficients before evaluating.
If the weights change, repeat both steps before calling this method again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values). Must match the weights used to set the multipole coefficients. |
required |
grid
|
TargetGrid
|
Regular target grid with the same dimensionality as the tree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the grid dimensionality differs from the tree or the grid is not completely covered by its leaf cells. Sparse trees may omit cells containing grid targets. |
Notes
Target coordinates are generated as needed, without storing the complete coordinate matrix.
grid_shape is given by TargetGrid.shape.
evaluate_grid_leaves_with_gradients(weights, grid)
¶
Performs a leaf evaluation pass to calculate the values and gradients at the grid target locations. Intended to be
used after set_local_coefficients, for when repeated calls to this function are desired,
such as when using 'surface following' isosurface generation algorithms.
Call set_weights followed by set_local_coefficients before evaluating.
If the weights change, repeat both steps before calling this method again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
NDArray[float64]
|
Numpy array of shape (N, K), where N is the number of source points and K is the number of right-hand sides to evaluate, containing source point weights (values). Must match the weights used to set the multipole coefficients. |
required |
grid
|
TargetGrid
|
Regular target grid with the same dimensionality as the tree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
NDArray[float64]
|
Array of evaluated values with shape |
gradients |
NDArray[float64]
|
Array of evaluated gradients with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the grid dimensionality differs from the tree or the grid is not completely covered by its leaf cells. Sparse trees may omit cells containing grid targets. Also raised if the kernel does not support gradient evaluation. |
Notes
Target coordinates are generated as needed, without storing the complete coordinate matrix.
grid_shape is given by TargetGrid.shape.
source_points()
¶
Source point locations used to build the tree.
Returns:
| Name | Type | Description |
|---|---|---|
source_points |
NDArray[float64]
|
Numpy array of shape (N, D), where N is the number of source points and D is the dimensionality. |