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 single FieldComponent, 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.

as_unyt_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

axes

The spatial axes along which this field component is defined.

buffer

The internal buffer storing this field’s data.

components

Read-only dictionary of field components.

coordinate_system

The coordinate system (e.g. a subclass of OrthogonalCoordinateSystem) which underlies this grid.

dependence

The symbolic coordinate dependence object for this tensor field.

dtype

The data type of the elements stored in the buffer.

element_ndim

Number of trailing element-wise dimensions (e.g., vector or tensor structure).

element_shape

The shape of the element-wise structure (e.g., vector or tensor components).

element_size

Total number of element-wise components.

grid

The structured grid associated with this field.

is_covector

Whether this tensor is a covector (rank-1, covariant).

is_scalar

Whether this tensor is a scalar (rank-0).

is_vector

Whether this tensor is a vector (rank-1, contravariant).

naxes

Number of spatial axes the field is defined over.

ndim

Total number of dimensions in the field buffer.

rank

The rank [number of indices] of the tensor.

shape

The shape of the full data array, including spatial and element dimensions.

signature

The tensor signature specifying variance of each index.

size

Total number of elements in the buffer.

spatial_ndim

Number of spatial dimensions (i.e., number of named axes).

spatial_shape

The shape of the field over the spatial axes (grid-aligned dimensions).

spatial_size

Total number of spatial elements (grid cells).

tensor_class

Return the (p, q) signature of the tensor.

units

Physical units attached to the buffer data, if defined.