fields.mixins.base.DTensorFieldCoreMixin.from_function#

classmethod DTensorFieldCoreMixin.from_function(*args, signature: SignatureInput | None = None, **kwargs) _SupDTFieldCore[source]#

Construct a FieldComponent by evaluating a function on the grid.

This method evaluates a coordinate-dependent function func over a physical coordinate mesh generated from grid along the specified axes. It is useful for initializing field data from analytic expressions.

Parameters:
  • func (callable) – A function that takes coordinate arrays (one per axis) and returns an array of values with shape (*grid_shape, *result_shape), matching the evaluated field.

  • grid (GridBase) – The grid over which to evaluate the function.

  • axes (list of str) – Coordinate axes along which the field is defined.

  • *args – Additional arguments forwarded to the buffer constructor (e.g., dtype).

  • signature (int or list of int, optional) – The signature of the tensor field being generated. This should be a sequence of 1 and -1 with 1 marking a contravariant index and -1 a covariant index. The length must match that of rank. If not specified, signature defaults to a fully contravariant form.

  • result_shape (tuple of int, optional) – Shape of trailing element-wise structure (e.g., for vectors/tensors). Defaults to scalar ().

  • buffer_class (str or BufferBase, optional) – The buffer backend used to hold data.

  • buffer_registry (BufferRegistry, optional) – Registry used to resolve buffer class strings.

  • buffer_kwargs (dict, optional) – Extra keyword arguments passed to the buffer constructor (e.g., units).

  • **kwargs – Additional keyword arguments forwarded to the function func.

Returns:

A new field component with data populated from func.

Return type:

FieldComponent

Raises:

ValueError – If the output shape of func does not match the expected field shape.