DenseTensorField#
- class fields.tensors.DenseTensorField(grid: GridBase, component: FieldComponent, signature: Sequence[Literal[1, -1]] | None = None)[source]#
A dense tensor field with a defined rank and tensor signature over a structured grid.
DenseTensorField
represents a tensor-valued field defined continuously across a structured coordinate grid. Each field stores its data in a singleFieldComponent
, with tensor structure encoded in the trailing dimensions of the buffer.Tensor indices are explicitly tracked using a signature, which defines whether each index is covariant (−1) or contravariant (+1). This signature is used to apply correct transformations under coordinate operations, including gradient, divergence, index raising/lowering, and contraction.
This class extends
DenseField
with tensor semantics, automatic index handling, and support for symbolic dependence metadata.See also
DenseField
,FieldComponent
,validate_rank_signature()
Methods
__init__
(grid, component[, signature])Initialize a dense tensor field over a structured coordinate grid.
adjust_tensor_signature
(indices[, ...])Adjust the variance (covariant or contravariant) of multiple tensor indices.
as_array
()Return the underlying buffer as a NumPy array.
Return the underlying buffer as a unyt array with units.
contract_with_metric
(index[, mode, out, ...])Contract this tensor field with the metric or inverse metric tensor.
determine_op_dependence
(opname, *args, **kwargs)Infer the symbolic coordinate dependence resulting from a differential operation.
element_wise_laplacian
([out, Lterm_field, ...])Compute the element-wise Laplacian of the field.
element_wise_partial_derivatives
([out, ...])Compute the element-wise partial derivatives of the field.
from_array
(*args[, signature])Construct a
FieldComponent
from an existing array-like object.from_function
(*args[, signature])Construct a
FieldComponent
by evaluating a function on the grid.full
(*args[, signature])Create a dense field filled with a fill value.
full_like
(other, *args, **kwargs)Create a full-valued component with the same grid, axes, and element shape as another.
gradient
([basis, inverse_metric_field, out, ...])Compute the covariant or contravariant gradient of this field.
lower_index
(index[, metric_field, out, ...])Lower a single contravariant index of this tensor field.
ones
(*args[, signature])Create a dense field filled with ones.
ones_like
(other, *args, **kwargs)Create a one-filled component with the same grid, axes, and element shape as another.
raise_index
(index[, inverse_metric_field, ...])Raise a single covariant index of this tensor field.
scalar_laplacian
(*args, **kwargs)Alias for
element_wise_laplacian()
.validate_component
(index, component)Validate a single field component and its index.
validate_components
(components)Validate all components in a dictionary for consistency with the field.
vector_divergence
([Dterm_field, ...])Compute the divergence of a vector field.
zeros
(*args[, signature])Create a dense field filled with zeros.
zeros_like
(other, *args, **kwargs)Create a zero-filled component with the same grid, axes, and element shape as another.
Attributes
The spatial axes along which this field component is defined.
The internal buffer storing this field’s data.
Read-only dictionary of field components.
The coordinate system (e.g. a subclass of
OrthogonalCoordinateSystem
) which underlies this grid.The symbolic coordinate dependence object for this tensor field.
The data type of the elements stored in the buffer.
Number of trailing element-wise dimensions (e.g., vector or tensor structure).
The shape of the element-wise structure (e.g., vector or tensor components).
Total number of element-wise components.
The structured grid associated with this field.
Whether this tensor is a covector (rank-1, covariant).
Whether this tensor is a scalar (rank-0).
Whether this tensor is a vector (rank-1, contravariant).
Number of spatial axes the field is defined over.
Total number of dimensions in the field buffer.
The rank [number of indices] of the tensor.
The shape of the full data array, including spatial and element dimensions.
The tensor signature specifying variance of each index.
Total number of elements in the buffer.
Number of spatial dimensions (i.e., number of named axes).
The shape of the field over the spatial axes (grid-aligned dimensions).
Total number of spatial elements (grid cells).
Return the (p, q) signature of the tensor.
Physical units attached to the buffer data, if defined.