Skip to content

Build a DiagonalTensor from an AssembledVector - #5763

Open
pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/slate-diag-vector
Open

pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/slate-diag-vector

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

AI assistance: this pull request was written with Claude Code (Claude Opus 5.5).

Summary

DiagonalTensor now also accepts an AssembledVector, and returns the diagonal matrix that has the vector on its diagonal, as numpy.diag does. The main use is a lumped mass matrix whose inverse is exact at the degrees of freedom shared by two or more cells. The row sums come from UFL, and Slate only turns them into a diagonal matrix:

m = assemble(action(inner(u, v)*dx, Function(V).assign(1)))   # row sums of M, in V*
Minv_P = DiagonalTensor(AssembledVector(m)).inv * Tensor(P_form)
 DiagonalTensor(A)
   A.rank == 2  ->  arguments of A, entries A[i, i]
+  A.rank == 1  ->  (arg, arg renumbered as the next argument), entries A[i]

Evidence

test_diagonal_tensor_from_assembled_vector_times_tensor uses continuous DQ0 x CG1 on a 2-layer extruded mesh, so one degree of freedom is shared by two cells:

assemble(D * Tensor(P))     == diag(m) @ P
assemble(D.inv * Tensor(P)) == diag(1/m) @ P
  • Before: both cases fail (AssertionError: The tensor must be rank 2.).
    After: both pass. test_assemble_tensors.py and test_optimise.py pass.

Implementation details

  • DiagonalTensor.arguments returns the argument of the vector and a copy of it with the next argument number. For a Cofunction in V*, this is a map from V to V*, as for a mass matrix.
  • _slate2gem_diagonal reads the entries from a rank-1 child directly.
  • push_diag stops at AssembledVector and Reciprocal, and no longer raises an AssertionError for them.
  • DiagonalTensor raises ValueError for invalid input, not AssertionError.
  • Inverse of a DiagonalTensor already lowers to 1/a_ii, so .inv needs no new code.

Limitations

  • A bare assembly of a DiagonalTensor built from an AssembledVector follows the same rule as AssembledVector: each cell gets the global values of the vector. Use it in a product with a tensor that is assembled cell by cell. The docstring says this.
  • Tensor(P).T * D.inv * Tensor(P) stays cell-local, as other Slate products do: it does not contain the terms that couple two cells through a shared degree of freedom.
  • Mixed spaces and BlockAssembledVector are not tested.

Merge Danger

Door: two-way

Blast Radius: small. Only new input is accepted; rank-2 behaviour is unchanged.

🤖 Generated with Claude Code

@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Dec 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pbrubeck
pbrubeck force-pushed the pbrubeck/slate-diag-vector branch from 012ddfc to 320b9a7 Compare December 2, 2026 16:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant