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 fieldrank_or_grid (
int|PatchGrid) – Dimensionality of the index space \(I\), or a patch grid defining the index spacetensor_shape (
tuple[int,...]) – Shape of the field’s tensorsdtype (
str|type|dtype|PsType|DynamicType) – Data type of the field’s tensor entrieslayout (
str|MemoryLayout) – Memory layout of the field’s memory buffers at runtimeghost_layers (int)
- property layout: MemoryLayout#
Memory layout of runtime buffers
- property dtype: PsNumericType | DynamicType#
Data type of tensor entries
- get_buffer_spec()#
Return the buffer specification defining the field’s memory properties
- Return type:
- get_iteration_limits()#
Return the iteration limits for kernels operating on this field
- Return type:
- create_ndarray(array_module, spatial_shape, *, dtype=None, **kwargs)#
Create an
array_module.ndarraybacking this field, with the giveninner_shape.If this field is defined on a
PatchGrid,spatial_shapemust 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 spacedtype (
Optional[dtype]) – Data type of the field entries; ifNone, infer from the field typekwargs – Keyword arguments forwarded to the array module’s array creation routine (ususally
.zeros()).