fields.mixins.base.DFieldCoreMixin.from_function#
- classmethod DFieldCoreMixin.from_function(*args, **kwargs) _SupDFieldCore [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
ofstr
) – Coordinate axes along which the field is defined.*args – Additional arguments forwarded to the buffer constructor (e.g., dtype).
result_shape (
tuple
ofint
, optional) – Shape of trailing element-wise structure (e.g., for vectors/tensors). Defaults to scalar ().buffer_class (
str
orBufferBase
, 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.