pystencils.grids.tensor_field.TensorField#

class pystencils.grids.tensor_field.TensorField(name, rank_or_grid, tensor_shape=(), *, dtype=DynamicType.NUMERIC_TYPE, layout=MemoryLayout.RIGHTMOST, ghost_layers=0)#

Tensor field mapping each point of a \(d\)-dimensional index space to a rank \(n\) tensor.

A tensor field is a function

\[f: I \to T^{k_1 \times \cdots \times k_n}\]

from an index space \(I \subset \mathbb{Z}^{d}\) to a tensor space over \(T\). \(T\) may be \(\mathbb{R}\) or a specific numeric data type.

Note

Degenerate tensor shapes (i.e. \(n_i = 1\) for any \(i\)) are not supported.

Accessing Values Field entries can be accessed using the [] and () operators. Spatial offsets must be given in []; they are interpreted relative to the current node. Tensor indices are passed to ().

Examples:

  • Access vector entry 1 at the current node:

f(1)
  • Access scalar entry at the eastern neighbor node:

f[1, 0]()
  • Access tensor entry (0, 0) at the north-west neighbor node:

f[-1, 1](0, 0)
Parameters:
  • name (str) – Name of the tensor field

  • rank_or_grid (int | PatchGrid) – Dimensionality of the index space \(I\), or a patch grid defining the index space

  • tensor_shape (tuple[int, ...]) – Shape of the field’s tensors

  • dtype (str | type | dtype | PsType | DynamicType) – Data type of the field’s tensor entries

  • layout (str | MemoryLayout) – Memory layout of the field’s memory buffers at runtime

  • ghost_layers (int)

property layout: MemoryLayout#

Memory layout of runtime buffers

property spatial_rank: int#

Dimensionality of the spatial index space

property tensor_shape: tuple[int, ...]#

Shape of the field’s tensors

property tensor_rank: int#

Rank of the field’s tensors

property ghost_layers: int#

Number of ghost layers of this field

property name: str#

The field’s name

property dtype: PsNumericType | DynamicType#

Data type of tensor entries

property grid: PatchGrid | None#

This field’s parent patch grid

get_buffer_spec()#

Return the buffer specification defining the field’s memory properties

Return type:

FieldBufferSpec

get_iteration_limits()#

Return the iteration limits for kernels operating on this field

Return type:

IterationLimits

create_ndarray(array_module, spatial_shape, *, dtype=None, **kwargs)#

Create an array_module.ndarray backing this field, with the given inner_shape.

If this field is defined on a PatchGrid, spatial_shape must reflect the number of nodes on that grid (i.e. number of cells, number of vertices, etc…)

Parameters:
  • array_module (ModuleType) – Reference to the array module (NumPy, CuPy, DPNP)

  • spatial_shape (tuple[int, ...]) – Shape of the field’s spatial index space

  • dtype (Optional[dtype]) – Data type of the field entries; if None, infer from the field type

  • kwargs – Keyword arguments forwarded to the array module’s array creation routine (ususally .zeros()).

view_ndarray(arr)#

Return a view into the inner region of the given ndarray backing this field

Return type:

TypeVar(TArray)

Parameters:

arr (TArray)