Compound¤
tatva.compound.Compound
¤
A compound array/state.
A helper class to create a compound state with multiple fields. It simplifies packing and unpacking into and from a flat array. Useful to manage fields while working with a flat array for the solver.
Parameters:
-
(arr¤Array | None, default:None) –The flat data array. If None, initializes to zeros.
Examples:
Create a compound state with fields::
class MyState(Compound):
u = field(shape=(N, 3))
phi = field(shape=(N,), default_factory=lambda: jnp.ones(N))
state = MyState()
Use state.arr to access the flat array, and state.u, state.phi to access the
individual fields.
You can use iterator unpacking to directly unpack the fields from the state::
u, phi = MyState(arr)
Methods:
-
tree_flatten– -
tree_unflatten– -
get_layout–MPI only. Get the local layout information for this compound state. Requires
-
at–Helper for functional updates to fields. Usage: `new_state =
-
flatten–Return the flat array representation of the state. Same as
state.arr.
Attributes:
get_layout
classmethod
¤
MPI only. Get the local layout information for this compound state. Requires that the class has been initialized with MPI context (mesh, partition_info, comm).
tatva.compound.field
¤
Classes:
-
FieldSize– -
Field–A descriptor to define fields in the State class.
-
FieldStackedView–A descriptor to define fields that are sub-fields of a stacked field in the State class.
Functions:
-
field–
Attributes:
Field
¤
Field(
shape: tuple[int, ...],
default_factory: Callable | None = None,
field_type: _FieldType | FieldType = FieldType.LOCAL,
*,
_slice: slice | None = None,
)
A descriptor to define fields in the State class.
Methods:
-
indices–
Attributes:
-
default_factory(Callable | None) – -
field_type(_FieldType | FieldType) – -
shape(tuple[int, ...]) – -
size(int) –
FieldStackedView
¤
FieldStackedView(
shape: tuple[int, ...],
default_factory: Callable | None,
parent_field: _FieldBase,
parent_slice: tuple[slice, ...],
field_type: _FieldType | FieldType = FieldType.LOCAL,
)
A descriptor to define fields that are sub-fields of a stacked field in the State class.
Methods:
-
indices–
Attributes:
-
default_factory– -
field_type– -
shape(tuple[int, ...]) – -
size(int) –
field
¤
field(
shape: tuple[int, ...],
default_factory: Callable | None = None,
field_type: FieldType | _FieldType = FieldType.LOCAL,
) -> Field
tatva.compound.stack_fields
¤
Class decorator to stack compatible fields into a shared contiguous layout.