Lifter¤
tatva.lifter.Lifter
¤
Create a lifter that maps between reduced and full vectors.
Parameters:
-
(size¤int) –Total number of dofs in the full vector.
-
(*constraints¤Constraint, default:()) –Extra constraints (e.g., periodic maps).
Examples::
lifter = Lifter(
6,
Fixed(jnp.array([0, 5]), 0.0),
Periodic(dofs=jnp.array([2]), master_dofs=jnp.array([1])),
)
u_reduced = jnp.array([10.0, 20.0, 30.0])
u_full = lifter.lift_from_zeros(u_reduced)
# u_full -> [0., 10., 10., 20., 30., 0.]
u_reduced_back = lifter.reduce(u_full)
Methods:
-
tree_flatten– -
tree_unflatten– -
add–Return a new lifter with
conditionappended to constraints. -
lift–Lift reduced displacement vector to full size.
-
lift_from_zeros–Lift reduced vector to a full vector starting from zeros.
-
reduce–Extract the reduced vector by selecting free dofs from
u_full. -
reduce_adjoint–Extract the reduced dual (residual/gradient) vector from
r_full. -
with_values–Update the internal runtime values mapping with the given updates.
-
adapt_sparsity–Augment and reduce the sparsity pattern to account for all constraints. From
-
augment_sparsity–Augment the sparsity pattern to account for all constraints.
-
reduce_sparsity–Reduce the sparsity pattern to the free DOF layout.
-
adapt_layout–MPI only. Augment the local layout to account for all constraints.
Attributes:
-
free_dofs(Array) –Array of free dofs as integer indices (not constrained).
-
constrained_dofs(Array) –Array of constrained dofs as integer indices.
-
size(int) –Total number of dofs in the full vector.
-
size_reduced(int) –Number of dofs in the reduced vector (free dofs only).
-
constraints(tuple[Constraint, ...]) –Tuple of constraints, which are applied in order during lifting. Constraints must
-
at(RuntimeValueIndexer) –Return a ValueIndexer for setting runtime values by key.
free_dofs
instance-attribute
¤
Array of free dofs as integer indices (not constrained).
constrained_dofs
instance-attribute
¤
Array of constrained dofs as integer indices.
size_reduced
instance-attribute
¤
Number of dofs in the reduced vector (free dofs only).
constraints
class-attribute
instance-attribute
¤
Tuple of constraints, which are applied in order during lifting. Constraints must specify which dofs they apply to, and can optionally specify runtime values that are provided to the lifter at runtime. These constraints are bound to the lifter instance, which allows them to access the lifter's runtime values when applying the lift.
tree_unflatten
classmethod
¤
add
¤
Return a new lifter with condition appended to constraints.
lift
¤
Lift reduced displacement vector to full size.
Parameters:
-
(u_reduced¤Array) –Vector on free dofs (length
size_reduced). -
(u_full¤Array) –Base full vector to modify; typically previous solution.
Returns:
-
Array–Full vector with free dofs set to
u_reducedand constraints -
Array–applied (Dirichlet, periodic, etc.).
lift_from_zeros
¤
Lift reduced vector to a full vector starting from zeros.
reduce
¤
Extract the reduced vector by selecting free dofs from u_full.
reduce_adjoint
¤
Extract the reduced dual (residual/gradient) vector from r_full.
This applies the adjoint of each constraint in reverse order to ensure that contributions from constrained dofs are correctly mapped back to the reduced space (e.g., summing residuals for periodic dofs).
Parameters:
-
(r_full¤Array) –Full dual vector (e.g., residual or gradient).
Returns:
-
Array–Reduced dual vector on free dofs.
with_values
¤
Update the internal runtime values mapping with the given updates.
adapt_sparsity
¤
Augment and reduce the sparsity pattern to account for all constraints. From the built-in constraints, only Periodic and PeriodicMPI have non-trivial implementations of this method, which add entries to the sparsity pattern to account for the coupling between master and slave dofs. Returns the reduced sparsity pattern for the free DOFs.
Parameters:
-
(sparsity¤csr_matrix) –Sparsity pattern in SciPy CSR format.
Returns:
-
csr_matrix–Augmented and reduced sparsity pattern in SciPy CSR format.
augment_sparsity
¤
Augment the sparsity pattern to account for all constraints.
Parameters:
-
(sparsity¤csr_matrix) –Sparsity pattern in SciPy CSR format.
Returns:
-
csr_matrix–Augmented sparsity pattern in SciPy CSR format.
reduce_sparsity
¤
Reduce the sparsity pattern to the free DOF layout.
Parameters:
-
(sparsity¤csr_matrix) –Full sparsity pattern in SciPy CSR format.
Returns:
-
csr_matrix–Reduced sparsity pattern in SciPy CSR format.
adapt_layout
¤
MPI only. Augment the local layout to account for all constraints.
This may add extra ghost dofs to the local array to account for periodic constraints, for example.
Parameters:
-
(layout¤_LocalLayout) –Local layout to augment.
Returns:
-
tuple[_LocalLayout, Lifter]–A tuple of (augmented_reduced_layout, augmented_lifter).
tatva.lifter.lifted
¤
lifted(
fn: Callable[P, Array] | None = None,
*,
argnums: tuple[int, ...] | int = 0,
output: Literal["primal", "dual"] | None = None,
) -> Callable
Lift a function that operates on reduced vectors to one that operates on full vectors.
This is a decorator that can be used to lift a function that takes reduced vectors as input and/or output to one that takes full vectors. The lifter instance is passed as the first argument to the lifted function, and the specified arguments are lifted from reduced to full vectors before being passed to the original function.
Parameters:
-
(fn¤Callable[P, Array] | None, default:None) –Function to lift; must take reduced vectors as input and/or output.
-
(argnums¤tuple[int, ...] | int, default:0) –Indices of arguments to lift from reduced to full vectors; can be an int or a tuple of ints. Default is 0 (lift the first argument).
-
(output¤Literal['primal', 'dual'] | None, default:None) –Whether to reduce the output of the original function. If "primal", the output is reduced using
Lifter.reduce. If "dual", the output is reduced usingLifter.reduce_adjoint(useful for residuals or gradients). Default is None.
Returns:
-
Callable–A new function that takes a lifter instance as the first argument, followed by the same
-
Callable–arguments as
fn, but with the specified arguments lifted from reduced to full vectors, -
Callable–and optionally with the output reduced from a full vector to a reduced vector.
tatva.lifter.Constraint
¤
Base class for conditions applied during lifting.
Subclasses define how constrained degrees of freedom (dofs) are enforced when mapping a reduced vector back to the full vector.
Methods:
-
augment_sparsity–Augment the sparsity pattern to account for this constraint.
-
apply_lift–Apply the constraint to a full vector and return the modified copy.
-
apply_transpose–Apply the transpose of the constraint to a full residual vector.
Attributes:
-
dofs(Array) –The dofs to constrain; every constraint must specify which dofs it applies to.
dofs
instance-attribute
¤
The dofs to constrain; every constraint must specify which dofs it applies to.
augment_sparsity
¤
Augment the sparsity pattern to account for this constraint.
Parameters:
-
(sparsity¤csr_matrix) –Sparsity pattern in SciPy CSR format.
Returns:
-
csr_matrix–Augmented sparsity pattern in SciPy CSR format.
apply_lift
¤
Apply the constraint to a full vector and return the modified copy.
apply_transpose
¤
Apply the transpose of the constraint to a full residual vector.
tatva.lifter.Fixed
¤
Parameters:
-
(dofs¤Array) –The dofs to constrain; these will be set to fixed values during lifting.
-
(values¤ArrayLike | RuntimeValue[ArrayLike] | None, default:None) –Fixed values to set on the constrained
dofsduring lifting; Can be
Methods:
-
augment_sparsity–Augment the sparsity pattern to account for this constraint.
-
apply_lift–Set constrained
dofstovalues. -
apply_transpose–Zero out residuals on fixed
dofs.
Attributes:
-
dofs(Array) –The dofs to constrain; these will be set to fixed values during lifting.
-
values(ArrayLike | RuntimeValue[ArrayLike]) –Values to set on the constrained
dofsduring lifting; Defaults to 0.0 if not
dofs
instance-attribute
¤
The dofs to constrain; these will be set to fixed values during lifting.
values
instance-attribute
¤
Values to set on the constrained dofs during lifting; Defaults to 0.0 if not
provided at init or runtime.
tatva.lifter.Periodic
¤
Methods:
-
augment_sparsity– -
apply_lift–Copy values from
master_dofsinto the constraineddofs. -
apply_transpose–Add residuals from constrained
dofstomaster_dofs.
Attributes:
-
dofs(Array) –The dofs to constrain; these will be set equal to the corresponding
master_dofsduring lifting. -
master_dofs(Array) –The master dofs that the constrained
dofswill be set equal to during lifting.
dofs
instance-attribute
¤
The dofs to constrain; these will be set equal to the corresponding master_dofs during lifting.
master_dofs
instance-attribute
¤
The master dofs that the constrained dofs will be set equal to during lifting.
apply_lift
¤
Copy values from master_dofs into the constrained dofs.
apply_transpose
¤
Add residuals from constrained dofs to master_dofs.
tatva.lifter.PeriodicMPI
¤
Periodicity based on nodal mapping, for use in MPI parallel computations where dofs on different processes may be constrained together.
This is a global constraint that is synchronized across all processes. It requests the
global dof indices of the slaves and masters.
You can access these with CompoundCls._g.field_name[global_node, slice, ...].
Methods:
-
augment_sparsity– -
apply_lift–Copy values from
master_dofsinto the constraineddofs. -
apply_transpose–Add residuals from constrained
dofstomaster_dofs.
Attributes:
-
dofs(Array) –The dofs to constrain; these will be set equal to the corresponding
master_dofsduring lifting. -
master_dofs(Array) –The master dofs that the constrained
dofswill be set equal to during lifting.
dofs
instance-attribute
¤
The dofs to constrain; these will be set equal to the corresponding master_dofs during lifting.
master_dofs
instance-attribute
¤
The master dofs that the constrained dofs will be set equal to during lifting.
apply_lift
¤
Copy values from master_dofs into the constrained dofs.
apply_transpose
¤
Add residuals from constrained dofs to master_dofs.
tatva.lifter.RuntimeValue
¤
Descriptor for a constraint value that must be provided at runtime.
Parameters:
-
(key¤Hashable | None, default:None) –A hashable key to identify this runtime value; used for setting values on the lifter and for error messages when the value is missing at runtime.
-
(default¤T | None, default:None) –An optional default value to use. If not provided, the lifter will raise an error if this value is not set at runtime.
Methods:
-
get_value–Get the value of this attribute from the given lifter instance.
Attributes:
tatva.lifter.LifterError
¤
Error raised when there is a problem with the lifter, e.g., missing runtime values.