Repository navigation
Add generic Ferrite assembly driver for per-quadrature-point kernels - #5
Merged
Merged
Conversation
xtalax-droid
force-pushed
the
forge/m1-2-kernels
branch
from
October 24, 2026 20:25
04b4683 to
cd094f9
Compare
xtalax-droid
force-pushed
the
forge/m1-3-assembly
branch
from
October 24, 2026 20:27
95aa8ea to
0072a9e
Compare
Implements spec §6.5/§6.6 for M1: one pass per operator set over the cells with a shared Ferrite.reinit!, kernels iterated as a tuple through a function barrier, facet kernels by piece with FacetIndex membership and a facet-count assertion, linear M/K/F on one sparsity pattern and nonlinear r/J in one pass. Defines KernelSpec per the M1 contract (deduplicated against PR 1 at rebase). Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-opus-5-5 Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
…tests to Assembly group Drops the duplicate src/kernelspec.jl now that src/weakform.jl defines KernelSpec with the same fields. Adds a case (i) check from seam analysis through weak_form and emit_kernels to the driver against the hand-written reference, and moves the driver tests to test/Assembly/ with an [Assembly] entry in test_groups.toml. Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-opus-5-5 Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
CI's typos check reads the identifier ue as a misspelling of use/due. Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-opus-5-5 Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
xtalax-droid
force-pushed
the
forge/m1-3-assembly
branch
from
October 26, 2026 16:18
0072a9e to
80b9c41
Compare
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 3 of 4 for milestone M1 (spec §11.1): the generic Ferrite assembly driver. Stacked on #4 (
emit_kernels, baseforge/m1-2-kernels), which is stacked on #1.What
This adds an internal, unexported driver that assembles the per-quadrature-point kernels from
emit_kernels,f(U, G, Ud, V, W, X, T, N, P), with Ferrite.AssemblyContext(dh, fields, cv, fv, pieces)holds the DofHandler, the field order (which is also the equation index), the shared CellValues and FacetValues, and a map from boundary piece to facet set. A facet set can be given as a grid facet-set name or as a set ofFacetIndex.assemble_linear(ctx, kernels, p; t, ch)returns(; M, K, F).Mcomes from the:masskernels, evaluated with a unit trial function inUd.Kcomes from the:bilinearkernels, evaluated with a unit trial function inUandG.Fis−∫source.allocate_matrix(dh[, ch]). An in-placeassemble_linear!is also provided.assemble_nonlinear(ctx, kernels, u, p; t, ch)returns(; r, J). It assembles the:nonlinearkernels and their tangents∂I/∂[U; G]in one pass. An in-placeassemble_nonlinear!is also provided.Ferrite.reinit!per cell. Kernels are iterated as a tuple behind a function barrier, so each kernel's loop is type-stable. Multi-field problems use field-major slots anddof_rangeelement blocks.FacetIndexmembership. The number of facets assembled per piece is asserted to equal the size of its set.The residual convention is
M u̇ + K u − F + r(u) = 0. Constraints and DAE lowering are not in this PR; they belong to M2. m2'sFEMSpace(#2) maps ontoAssemblyContextwithout changes to either side.Why
This covers spec §6.5 (the kernel slot-in rules:
Ferrite.reinit!,FacetIndexmembership, the facet-count assertion), §6.6 (function barrier, concrete kernel types, nonlinearrandJin one pass, shared pattern) and the traps in Appendix C. It consumes the kernels from stage f of §5.1.Tests
The tests are in a new
Assemblygroup,test/Assembly/assembly.jl, with 22 tests.analyse, thenweak_form, thenemit_kernels, then this driver.K,MandFagree with a hand-written Ferrite loop to relative error ≤ 1e-14.generate_grid(Triangle, (20, 20))with a source, a Neumann piece and a Robin piece:K,MandFagree to ≤ 1e-14, andMandKshare one pattern.sum(F)with and without the Neumann datum differs byk·h·|Γ|.±u²wreaction and per-equation Neumann data:K,M,Fandragree with hand-written blocks to ≤ 1e-14, andJagrees with central differences to ≤ 1e-9.k(u) = 1 + u²with a nonlinear Neumann facet term:ragrees with a hand-written residual at a random state to ≤ 1e-14, andJagrees with central differences to ≤ 1e-9.GROUP=Assemblypasses 22/22. Runic is clean. Codex review approved it with no findings.Branches covered: linear assembly (mass, bilinear, source; volume and facet), nonlinear residual and Jacobian, single-field and two-field, Neumann, Robin, nonlinear natural conditions, and the facet-set error paths.
Performance
On the 100×100 P1 case (i), with the real
emit_kernelskernels, compared with the hand-written loop from the prototype:For comparison, the prototype's naive driver measured 68× and its function-barrier variant 5.3×.
Reviewer notes
:massand:bilinearkernels are exactly linear in their slots.classify(Add weak_form and classify (strong-to-weak stage e) #1) guarantees this.dh.griddirectly becauseFerrite.get_gridis not public.Follow-up commit
80b9c41renames the element state vectoruetou_elem, because the Typos spell check flagged it. Codex review approved it with no findings. The branch has since been rebased onto #4's head;git range-diffshows every patch unchanged.🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-opus-5-5
Review: unreviewed
Session: d6252e53-ed42-4149-9811-233262edb2ef