Skip to content

main train 2026-11-14: ADR unfitted refactor (C44), two-level-set cut geometry (C44), Q_p spaces and p = 5 tetrahedra (C8) - #1364

Merged
cekees merged 15 commits into
proteustoolkit:mainfrom
cekees:train/main-2026-11-15
Nov 15, 2026
Merged

cekees merged 15 commits into
proteustoolkit:mainfrom
cekees:train/main-2026-11-15

Conversation

@cekees

@cekees cekees commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Each change below was reviewed, and passed CI, as its own pull request on cekees/proteus. This branch merges them onto main at 33659c3 with one merge commit per pull request, in the order listed.

Merge with "Create a merge commit", not squash or rebase, so the commits keep their hashes and the fork's pull requests close themselves.

pull request title commits
cekees#286 ADR unfitted refactor: kernels, IFE basis, cut geometry, region weights, face terms (C44, from Darsh's proposal) 8
cekees#287 C44 phase 3: a tetrahedron cut by two P1 level sets (part A, geometry) 1
cekees#288 C8 round 4: tetrahedra at p = 5; Q_p of any order on quadrilaterals and hexahedra with an oriented dof map 3

Measured, per pull request:

  • Implement structured logging #286 moves the cut-cell code out of ADR.h and equivalent_polynomials.h into Unfitted.h and UnfittedKernels.h; ADR.h goes from 4489 to 3203 lines. On a 72-case reference (2D 42 + 12, 3D 18) rerun after every commit, pure moves are bit-identical and the kernel steps differ by at most 6e-14 relative; one conditioning-amplified solution (3D P1 sphere, contrast 1000) differs by 3.1e-13 while its Jacobian moved 1.9e-15. Peak memory: 2D P1 1154 to 463 MB, 2D P2 2179 to 1086 MB, 3D P2 5912 to 2388 MB. Calling the Jacobian before the residual now works (new test; it fails on the old code).
  • added workaround for test description bug in nosetests #287 adds proteus/cutpair.h, the geometry of a tetrahedron cut by two P1 level sets, with a test binding and 50 tests; ADR.h, equivalent_polynomials.h, cutclip.h and cutquadric.h are unchanged. The three regions sum to the tetrahedron to 1.1e-15 over 20000 random pairs, an independent oracle agrees to 7e-16, the divergence theorem holds on each region to better than 1e-14, and the face fit equals the 2D composite weights to 9e-14, 2e-12 and 2e-10 at nP = 2, 3, 4.
  • make sure any Profiling.logEvent messages get printed, regardless #288 changes FemTools and tests only. Tetrahedra at p = 5: Poisson manufactured-solution rates L2 5.92, H1 4.91. New proteus/CubeSpaces.py and three FemTools classes for Q_p of any order on quadrilaterals and hexahedra, matching the oracle tables to between 1e-14 and 5e-13; Poisson L2 rates 2.00, 2.98, 3.99, 4.94, 6.01 (quadrilaterals, Q1 to Q5) and 2.00, 2.90, 3.98, 4.90 (hexahedra, Q1 to Q4); two ranks equal serial. Limits: affine elements, Lagrange on cubes only, strong Dirichlet only.

#286 and #287 both touch setup.py (one entry each) and merge cleanly. This is separate from #1363 (a guard test only) and from #1362 (1.9.x); none of the three depends on another. 2.0 only: none of this goes into 1.9.x.

Diff against main: 27 files changed, 5857 insertions(+), 3338 deletions(-).

🤖 Generated with Claude Code

cekees and others added 15 commits November 14, 2026 08:45
…t (C44 unfitted refactor, step 1)

New proteus/UnfittedKernels.h (only <cmath>; knows no mesh, cut cell or proteus type): jumpPenalty,
symmetricConsistency and load, each adding one quadrature point's local residual and row-major Jacobian
block; either output may be null; macro PROTEUS_UNFITTED_HD (default inline). Beyond the proposal's
signatures the kernels take test and trial arrays separately (Petrov-Galerkin tests with the ordinary hats,
and ADR has PG in 2D); the Galerkin overloads set trial = test.

ADR.h: the four cADR helpers updateEmbeddedBoundaryTerms / ...TermsDn / ...RobinTerms /
updateImmersedBoundaryTerms (20 arguments, 5 used) are replaced by nitscheDirichlet (symmetricConsistency +
jumpPenalty), robinTerm (jumpPenalty) and fluxJumpValue + unfitted::load. The Gamma_s and Gamma_f terms are
now added to the element residual / Jacobian at the quadrature point, no longer in the i/j loops; the ~20
accumulator locals (r_s_a, dham_s_b, f_f, ...) are gone. The planar and the curved (Dn_s) Nitsche forms share
one function: the Dirac measure carrying the normal is the argument m = D_s * n_out.

Standalone test test/unfitted/unfitted_kernels_test.cpp (compiled and run by test_unfitted_kernels.py with
the system C++ compiler, -Wall -Wextra -Werror; no proteus build): Jacobian = finite difference of the
residual for 3, 4, 6, 10 DOFs, Galerkin and Petrov-Galerkin; the penalty block is symmetric positive
semidefinite; the load is -w g v.

Measured against the reference built on main 33659c3 (72 cases: 42 two-phase P1/P2 with and without SCIFEM,
12 three-phase 2D, 18 3D from C44; residual and Jacobian at the solution and at a perturbed state, plus the
solution; baseline reruns byte-identical): 33 cases bit-identical, 39 differ by round-off, the largest
relative differences over all cases: solution 6.0e-15 (2D test 2.1 P2), Jacobian 4.7e-16, residual at the
perturbed state 3.6e-15, residual at the solution (round-off, measured against |r_pert|) 3.0e-15; the squared
L2 error against the exact solution moves by up to 8.3e-13 relative (3D P2 curved sphere, where the error
is 3e-6 and the solution moved by 2e-15). Nothing over the 1e-13 budget. ADR.h 4489 -> 4300 lines.
Tests (macOS arm64, local): test_equivalent_polynomials(+moments), test/IFEM, test/ADR3D, test/ADR_SGS,
test/CLSVOF, MCorr and VOF tests: 303 passed before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The geometry of the 3D "triply cut" element, the counterpart of the 2D
equivalent_polynomials::composite fits. New header proteus/cutpair.h, a
test binding proteus/cutpair.cpp (module proteus.cutpair) and
test/ADR3D/test_cutpair.py. No kernel reads it yet: ADR.h, ADR.py,
equivalent_polynomials.h, cutclip.h and cutquadric.h are unchanged.

cutclip.h already clips a tet by several half-spaces and integrates the
pieces, so nothing is rewritten: cutpair calls cutclip for the clipping
and the moments and cutquadric for the Gram solve, and adds

  regions()      A = {phi_s>0, phi_f<0}, B = {phi_s>0, phi_f>0},
                 S = {phi_s<0} as tetrahedra; Gamma_s split by the fluid
                 that borders it; Gamma_f split into its part in the
                 fluid and its part in the solid
  tripleLine()   Gamma_s cap Gamma_f cap K: end points, the face of K
                 each end lies on, length, tangent; lineMoments()
  PairFit        degree-k fits of A and B, of the four surface pieces
                 and of the line, with the physical measure and the
                 physical normals/tangent on an affine element; the
                 volumes and the 2D kernel's "interface buried in the
                 solid" rule (demoted)
  FacePair       a triangular face cut by two lines: region moments and
                 fits in the face parameters, the face triple point

Measured (macOS arm64, clang, -O2; python 3.13):

  partition A+B+S = K, split surfaces = unsplit surface, monomials to
    degree 4, 20000 random pairs (15157 cut by both, 9836 with a triple
    line): 1.1e-15 (volume), 7.8e-16 (surface)
  against an independent oracle (vertex enumeration from plane triples,
    scipy Delaunay, own Gauss rule; no cutclip), 400 pairs, degree 4:
    7.2e-16 (volume moments), 6.7e-16 (surface moments)
  against a brute-force grid (160^3 cells, one random point per cell),
    3 cases: within 2e-4
  July P1 reference p1_two_level_sets_tet.py, 8 cases x (A, B, S):
    2.5e-16
  fits, 300 pairs per degree, random affine elements:
    k   region moments <= k   at k+1    Dirac (physical)  line (physical)
    1   3.1e-16               1.8e-03   4.4e-15           2.4e-15
    2   2.8e-16               3.4e-04   4.9e-15           6.7e-15
    3   3.5e-16               5.7e-05   2.3e-14           2.2e-14
    4   9.7e-16               1.3e-05   1.3e-13           1.5e-13
    largest |fit| at the quadrature points: 2.3
  divergence theorem on A, B and S (clipped tet faces + split surfaces
    with their normals = derivative moments), degree 4: below 1e-14
  triple line: ends on both planes and on the reported faces to 1e-13,
    equal to the oracle's vertices (1e-11) and to the triple point of
    each face's own two cut lines (1e-12); exactly the two faces with a
    triple point are the reported ones
  face fit against the 2D kernel's composite::weights<nP>, ~1100 faces
    per degree: 8.7e-14, 1.5e-12, 1.9e-10 for nP = 2, 3, 4. The
    difference is the 2D code's tabulated inverse Gram matrix: its fit
    reproduces the face moments to 9.5e-15, 1.3e-13, 2.6e-12, the
    Cholesky solve here to 2.9e-16, 1.0e-15, 4.6e-15
  vertex permutations (24) of a physical element: volumes, physical
    areas and length equal to 1e-12
  degenerate cuts (line through a vertex, along an edge, plane on a
    face, coincident planes, uncut) and 1400 perturbations of them by
    1e-15 .. 1e-6: partition 6.1e-16, every fit finite

Tests run: test/ADR3D/test_cutpair.py (50) and test_cutclip.py (39),
89 passed, locally on darcy-class macOS arm64 with the extension built
by hand from this worktree; the setup.py entry is exercised by CI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ools routines against them, MMS rates

Round 3 stopped the CI-supported range on tetrahedra at p = 4 (tables and
MMS); triangles were at 5. This brings tetrahedra to 5. Tests and the
table generator only; no change in proteus/.

Oracle tables (test/fem_oracle): tetrahedron p = 5 for lagrange_equi,
lagrange_gll and bernstein (56 functions; values, gradients, Hessians at
59 interior points and 12 points on each face).
  * The notebook's nodes3d and the published warp-and-blend construction
    place the interior nodes of the tetrahedron differently from p = 5 on
    (round 2 measured it and chose the published one). The lagrange_gll
    table at p = 5 therefore takes its node SET from
    proteus/SimplexSpaces.py (loaded by path, numpy only); the basis on
    those nodes is still built by the generator (monomials, 50-digit
    inverse), so the two paths stay independent.
  * Every table that was in the file is bitwise unchanged (493 arrays
    compared); 32 arrays are new. File size 1045 kB -> 1958 kB.
    Regeneration takes 11 s.

Checked against the new tables (test_fem_oracle.py, test_simplex_spaces.py):
SimplexSpaces tabulation and the FemTools reference routines, values,
gradients, Hessians, on the cell and on every face, for the three
families, to 1e-12 relative; the table properties (partition of unity,
Kronecker, Bernstein non-negativity and linear precision, reproduction
of every polynomial of degree <= 5 with gradients and Hessians, node-set
symmetry). 582 passed, 1 skipped (was 540 on main for these two files).

Poisson MMS on tetrahedra, p = 5, warp-blend Lagrange (test_simplex_mms.py):
  nodes/direction   elements   dofs     L2 error    H1 error
  3                 48         1331     2.66e-03    7.13e-02
  4                 162        4096     2.56e-04    1.04e-02
  5                 384        9261     4.79e-05    2.60e-03
  6                 750        17576    1.28e-05    8.68e-04
  7                 1296       29791    4.31e-06    3.52e-04
  rates: (3,4) 5.78 / 4.75; (4,5) 5.83 / 4.83; (5,6) 5.92 / 4.91;
  (5,7) 5.94 / 4.93. CI uses (5, 6): 24 s serial for the pair.
  A polynomial of degree 5 is reproduced (L2 < 1e-11) with Lagrange and
  with Bernstein; 2 ranks give the serial errors to 1e-8 relative (node
  partition, one layer of overlap).

Tests run locally (macOS arm64, MPICH, FI_PROVIDER=tcp,
-mat_partitioning_type current): test_fem_oracle.py and
test_simplex_spaces.py in full; the p = 5 cases of test_simplex_mms.py
(9 passed).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…r.h folded in and removed (C44 unfitted refactor, step 2)

The two-sided IFE basis (coefficient solve in 2D P1/P2 and the closed-form 3D P1 tetrahedron, the unit
flux-jump lift, evaluation and gradients at the quadrature points, the VA/VB/PSI accessors, ifem_singular_error)
no longer lives inside equivalent_polynomials::Simplex behind useIfemBasis. New proteus/Unfitted.h:
unfitted::IFEBasis (built from a read-only CutFrame of the Simplex: permutation, permuted level set, inverse
Jacobian, cut point X_0, normal, inside_out, corner, edge) and unfitted::IFEFunctions (GeneralizedFunctions_mix
plus an IFEBasis, calculated and queried together: the type ADR holds per fluid-interface cell; ADR.h's GfType).
Sub-step 2a moved the code and storage and made ADR/cutclip use it; sub-step 2b folded the 277-line
ifemBasisCoefficients_wrapper.h (the small dense solves) into Unfitted.h and deleted it. Each sub-step was built
and run alone against the reference.

Simplex keeps its moment fit, permutation and the useIfemBasis behaviours that are not the basis (degenerate
edge/corner cells, the permutation root, the inside_out normal flip) and gains cut_frame() and
permuted_reference_point(). equivalent_polynomials.h 1658 -> 1000 lines; Simplex and GeneralizedFunctions_mix
keep their template signatures, so no mprans model changes: all of them (RANS2P, RANS2P2D, RANS2P_IB, RANS3PF,
RANS3PF2D, MCorr, VOF, RDLS) rebuilt unmodified. The RANS2P debug prints that read gf_p.VA() under #ifndef IFEM
still compile against zero-returning accessors on GeneralizedFunctions_mix (they read zeros before as well: that
fit never computed a basis). The IFEFunctions::calculate refuses scale = true (ADR never uses it).
cutclip.cpp (the basis test hook) uses IFEFunctions; setup.py depends updated.

Memory: no model that only needs H, 1-H, D carries basis storage any more: sizeof(GeneralizedFunctions_mix)
MCorr/VOF 2D P1 4656 -> 1296 bytes, RANS2P 2D P2 8064 -> 2048, RANS2P 3D 21320 -> 5480 (per object; ADR's
per-cell GfType is unchanged in size, it still holds the basis).

Measured against the step-1 reference (72 cases): 72/72 bit-identical (solution, residual and Jacobian at the
solution and at the perturbed state), after 2a and after 2b; against main 33659c3 the step-1 differences stand
(worst 6.0e-15). Tests (macOS arm64, local): test_equivalent_polynomials(+moments), test/IFEM (66, with the
2-rank cases), test/ADR3D (including test_ifem_p1_3d through cutclip), test/ADR_SGS, test/CLSVOF, MCorr and
VOF tests: 303 passed after 2a and after 2b (303 before).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…an oriented dof map, serial = 2 ranks

FemTools had Q1 and Q2 on cubes. This adds Q_p for any p, the counterpart
of the P_p simplex spaces of round 2, built the same way.

proteus/CubeSpaces.py (new, numpy only): the local space. Tensor nodes
(GLL by default, equispaced for comparison), dofs grouped by entity
(vertices, edges, faces, interior), tabulation of values, gradients and
Hessians on the cell and on faces from a Legendre expansion of the 1D
Lagrange functions, the sub-cells of the archive view, and the
orientation tables.

proteus/FemTools.py:
  PolynomialOnCube            local function space (wraps CubeSpaces)
  CubeEntityDOFMap            dof map; inherits the subdomain and global
                              numbering of SimplexEntityDOFMap (closed
                              form in the mesh's global entity numbers,
                              no communication)
  C0_AffinePolynomialOnCube   the space; AffineMaps, as the existing Q1
                              and Q2 classes, so parallelogram and
                              parallelepiped elements only
  SimplexEntityDOFMap         two hooks (_entityIndex, _elementDofPoints)
                              and the dofs per entity read from the
                              local space; the simplex numbering is
                              unchanged (its tests pass unmodified)
  _C0_AffinePolynomialSpace   the archive view and the array tabulation,
                              moved out of C0_AffinePolynomialOnSimplex
                              so both spaces share them
  PolynomialInterpolationConditions.quadrature2Node_element: the first
                              nNodes dofs are vertices (was dim+1)

Orientation. An edge's dofs count from its vertex with the smaller
global number. A face's (p-1)^2 dofs are indexed in the frame whose
origin is the vertex with the smallest global number and whose first
axis points to the neighbour with the smaller global number (one of 8
frames). The cell's interior dofs are indexed the same way (origin and
neighbours sorted by global number): the first version left them in
local order and the 2-rank test showed two ranks that list a ghost cell
differently disagreeing on the dof's point by 0.17; fixed before this
commit.

Local order. p = 1 is LinearOnCubeWithNodalBasis, p = 2 in 3D is
LagrangeOnCubeWithNodalBasis, function by function (2e-16). In 2D the
existing Q2 class lists the vertices as (0,3,2,1) and the edges as
(3,2,1,0); same space, other order. The existing classes are untouched.

Oracle tables (test/fem_oracle): Q3 and Q4 on the quadrilateral for both
node sets and Q3 on the hexahedron for GLL (hexahedron p = 4 would add
5 MB). The 525 arrays already in the file are bitwise unchanged; file
1958 kB -> 2759 kB.

Measured (macOS arm64, MPICH, FI_PROVIDER=tcp, -mat_partitioning_type
current):

  tabulation against the oracle, values / gradients / Hessians on the
  cell, and the worst of the three on the faces (relative):
    quadrilateral Q3 gll      7.3e-15  9.7e-15  6.4e-15   8.7e-15
    quadrilateral Q4 gll      2.0e-13  2.1e-13  1.1e-13   1.8e-13
    quadrilateral Q4 equi     4.6e-13  4.7e-13  9.7e-14   1.8e-13
    hexahedron    Q3 gll      6.7e-14  1.6e-13  4.3e-14   1.3e-13
  1D Lebesgue constant, equispaced / GLL: p=3 1.631 / 1.500,
    p=5 3.106 / 1.779, p=7 6.930 / 1.972 (the d-dimensional constant is
    the d-th power); condition number of the 1D table at p=7: 10.6 / 4.4

  dof map, 7x6-node quadrilateral grid (p = 1..5) and 4x4x4-node
  hexahedral grid (p = 1..4), GLL and equispaced, element vertex lists
  as generated and through a random symmetry of the cell per element
  and rank; 2 ranks, node and element partitions, one layer of overlap:
                              quad            hex
    conformity defect         1.1e-16         2.2e-16
    jump across faces         1.3e-15         8.9e-16
    interpolation of a Q_p
      polynomial (space)      2.0e-15         7.1e-15
    without the rule, p>=3:
      defect >= / jump >=     0.06 / 0.19     0.11 / 0.30
    global dofs, p=1..5       42 143 304      64 343 1000
                              525 806         2197
    the 2-rank dof points equal the serial set (1e-12), owned blocks
    tile the global range, ranks agree on shared points (1e-13)
    element edges not in their global frame: up to 164; faces: 143,
    all 8 frames seen; edges that local vertex numbers would orient
    differently from global ones: up to 21
    p = 1 equals NodalDOFMap; p = 2 on hexahedra equals
    QuadraticLagrangeCubeDOFMap (l2g and subdomain2global, serial and
    2 ranks), on quadrilaterals it has the same dof points

  Found, not fixed (partitioning, C32): the hexahedral subdomain mesh of
  rank 1 for the element partition with one layer of overlap has one
  ghost row in edgeNodesArray that is not an edge, (0, 0) with global
  number 0. Its p-1 dofs belong to no element; the test accounts for
  them (unused dofs == (p-1) * such rows) and asserts 0 everywhere else.

Tests run locally: test_cube_spaces.py (109), test_cube_dofmap.py (6),
and test_fem_oracle.py, test_simplex_spaces.py, test_simplex_dofmap.py,
test_bernstein_dirichlet.py: 755 passed, 1 skipped in total.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…cells only (C44 unfitted refactor, step 3)

New unfitted::CutGeometry (Unfitted.h) builds, once, everything the residual and the Jacobian read about the
cuts: per element the classification by the solid and the fluid-interface level sets (icase), the moment
fits of H/1-H/D (and the two-sided IFE basis on the elements Gamma_f cuts, evaluated at the interior and at
every face's quadrature points; the quadric fits of the curved solid), the composite fits and demotion of
the elements cut by both (2D), the flux-jump lift amplitude (the block that was inline in calculateResidual),
whether the element carries any fluid, and the two lists of interior faces (ghost penalty on faces of
Gamma_s-cut elements, SCIFEM on faces Gamma_f cuts), ascending, both elements active. ADR calls
prepareGeometry() first in calculateResidual and in calculateJacobian; prepare() returns at once unless
the level sets changed (recomputeIFEMGeometry), the mesh size changed or it is the first call.

What goes away from ADR.h (4302 -> 3834 lines): gf_f_cache/gf_s_cache/cf_s_cache, the six generation
and icase arrays, the six composite caches, fluxLiftAmp, ifem_boundaries/cutfem_boundaries (+ the unused
*_elements sets), elementIsActive, calculateGfF, ensureIFEMCacheSized, the lazy per-face
gf_f.calculate(..., true, ...) blocks in four places, and the set-up block that appeared twice (per-element
cut set-up, composite fit, flux lift: ~290 lines in the residual, ~100 in the Jacobian). The element and
face routines read the fits through geom.gfF/gfS/cfS(eN); an uncut element reads one of two canonical
constant fits instead of its own object.

Hidden call-order rule removed: the cut-face lists were filled only in calculateResidual (and filtered there
by which elements carry fluid), so a Jacobian assembled before the first residual silently left the ghost
penalty and SCIFEM terms out. New test/IFEM/test_cut_geometry.py: a fresh model object that has never run a
residual assembles the converged Jacobian (two-phase test 8 with SCIFEM, three-phase table 1; P1, P2).
Before this commit the same test fails 4/4 (built on the step-2 commit), after it passes 4/4. The Jacobian
also needed immersedBoundary_fluxJumpLift in its arguments (ADR.py), which only the residual passed.

Measured against the step-2 reference (72 cases: solution, residual and Jacobian at the solution and at the
perturbed state): 72/72 bit-identical; the Jacobian assembled first on a fresh model object equals the
Jacobian assembled after the residual bit for bit in all 72 (jfirst check). Peak RSS of the serial reference
solves (macOS arm64, getrusage maxrss), before -> after: 2D P1, 32768 triangles 1154 -> 483 MB; 2D P2, 32768
triangles 2179 -> 1111 MB; 3D P2, 24576 tetrahedra 5912 -> 2389 MB. (The three large cases agree with main to
3.5e-14 in the solution, the step-1 round-off.) Tests (local): test_equivalent_polynomials(+moments),
test/IFEM (66 + the 4 new), test/ADR3D, test/ADR_SGS, test/CLSVOF, MCorr and VOF tests: 303 passed before
the new test and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…erals and hexahedra, serial = 2 ranks

test/cube_mms_mpi.py and test/test_cube_mms.py, the counterparts of the
simplex pair: -div(grad u) = f on the unit square and cube through
NS_base and OneLevelTransport with C0_AffinePolynomialOnCube, strong
Dirichlet data on the whole boundary, errors integrated by the helper
with p+3 Gauss points per direction. Tests only; no change in proteus/.

Measured (macOS arm64, MPICH, superlu / superlu_dist, FI_PROVIDER=tcp,
-mat_partitioning_type current), GLL nodes, nodes per direction n:

  quadrilaterals            L2 error (rate)          H1 error (rate)
  Q1  n = 9, 17, 33   2.92e-02 7.28e-03 1.82e-03   2.00 2.00 | 1.00 1.00
  Q2  n = 5, 9, 17    6.02e-03 7.99e-04 1.01e-04   2.91 2.98 | 1.95 1.99
  Q3  n = 3, 5, 9     9.27e-03 5.40e-04 3.39e-05   4.10 3.99 | 3.14 3.01
  Q4  n = 3, 5, 9     4.88e-04 2.38e-05 7.76e-07   4.36 4.94 | 3.40 3.95
  Q5  n = 3, 5, 9     1.05e-04 1.49e-06 2.32e-08   6.14 6.01 | 5.16 5.01
  hexahedra
  Q1  n = 5, 9, 17    1.25e-01 3.13e-02 7.80e-03   2.00 2.00 | 1.07 1.02
  Q2  n = 3, 5, 9     2.89e-02 5.66e-03 7.56e-04   2.35 2.90 | 1.49 1.96
  Q3  n = 4, 5, 7     1.60e-03 5.08e-04 1.01e-04   4.00 3.98 | 3.06 3.02
  Q4  n = 4, 5, 6, 7  8.95e-05 2.25e-05 7.54e-06 3.06e-06
                      rates 4.80 4.90 4.92 (5->7) | 3.84 3.92 3.94 (5->7)

  CI asserts L2 rate p+1 and H1 rate p within 0.15 on the last pair
  shown that is cheap enough: hexahedra Q4 uses (5, 6), 10 s.

  A polynomial of degree p in each coordinate (in Q_p, not in P_p) is
  reproduced: L2 7e-16 (Q5 quadrilaterals), 1e-15 (Q4 hexahedra); H1
  1e-14, 2e-14. Equispaced nodes give the solution of the same space
  with another boundary interpolant (L2 differs by 5.6% for Q3 on 4^3
  hexahedra).

  2 ranks give the serial L2, H1 and max errors to 1e-8 relative: node
  and element partitions, 0 and 1 layers of overlap, Q3 and Q5 on
  quadrilaterals, Q3 and Q4 on hexahedra (including the element
  partition with one layer, where the subdomain mesh carries the edge
  record that is not an edge).

  Every run: the Jacobian's nonzero count equals the brute-force count
  of the element couplings of the dof map on every rank; the archive
  returns the dof vector exactly, holds p^nd quadrilateral or
  hexahedral sub-cells per element, none inverted, total volume 1 to
  1e-12; the space class is C0_AffinePolynomialOnCube_q<p>_<nodes>.

Tests run locally: test_cube_mms.py 24 passed in 48 s; test_simplex_mms.py
29 passed (unchanged by the FemTools refactor of the previous commit).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… element routines (C44 unfitted refactor, step 4)

The residual and the Jacobian element routines each selected, at every quadrature point, the region weights
and built the two-sided basis by hand: the solid's H_s/D_s/Dn_s, the per-side Dirac D_s_a/D_s_b (demoted /
composite / plain), the region weights wA/wB (demoted / composite / products), Gamma_f's Dirac D_f (composite
restricted to the fluid, zero when demoted), the three-way branch choice from gf_f.exact.edge/corner, the
branch basis va/vb with its gradients, the solution on each branch and the solution-jump and flux-jump lifts.
Two copies, ~110 lines each.

Unfitted.h: unfitted::RegionWeights::evaluate(geom, eN, k, x_ref, curved) builds all the weights and the
branch choice from the CutGeometry in one place; unfitted::BranchBasis::load/fieldA/fieldB/lift/weight holds the
basis at the current point, the field on each branch and the jump lifts (same loops and same order as
ck.valFromElementDOF/gradFromElementDOF, so the numbers are unchanged). ADR.h: both element routines call
them (the five composite-fit pointer parameters of the routines are gone, the geometry owns them), the
duplicated selection code is deleted; ADR.h 3834 -> 3675 lines.

Measured against the step-3 reference (72 cases: solution, residual and Jacobian at the solution and at the
perturbed state): 72/72 bit-identical; Jacobian-first still equals Jacobian-after-residual in 72/72. Tests
(macOS arm64, local): test_equivalent_polynomials(+moments), test/IFEM (70 with test_cut_geometry), test/ADR3D,
test/ADR_SGS, test/CLSVOF, MCorr and VOF tests: 307 passed (303 + the 4 added in step 3).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t routine for residual and Jacobian (C44 unfitted refactor, step 5a)

The ghost-penalty face loop existed twice (residual ~240 lines, Jacobian ~210): per face the quadrature-point
pairing, per point the two sides' mappings, the phase fields (branch basis on a Gamma_f-cut element, standard basis
elsewhere, the solution-jump and flux-jump lifts), the per-phase normal-derivative jumps, and a global-DOF-keyed
std::map accumulation. Now: FaceCtx (plain pointers), pairFacePoints() (one point pairing; strict with verification
for SCIFEM next, nearest for the ghost penalty), ghostPoint() (one routine for both: the local normal-derivative
arrays of both elements' basis functions, side 0 first, and for the residual the jump of the solution's normal
derivative) and unfitted::jumpPenalty over the 2 * nDOF local DOFs with c = gamma_g h_F, w = dS. The residual
scatters the local vector, the Jacobian scatters the local block by the face's CSR offsets: no std::map.
ADR.h 3675 -> 3535 lines. Same behaviour: a phase's penalty only where both elements carry that phase, the
combined penalty when neither is shared, dS of the last side. (The z components of the branch gradients, never set
in 3D by the old loop, are set; unreachable there today, since embedded + immersed is refused in 3D.)

This is a kernel replacing hand arithmetic: duplicated DOFs shared by the two elements used to be summed in the map
before the product, now the products are summed, so the numbers move by round-off. Measured against the step-4
reference (72 cases: solution, residual and Jacobian at the solution and at the perturbed state): 52 bit-identical
(no ghost penalty in play), 20 differ; largest relative differences: solution 6.1e-14 (3D P2 sphere, planar cuts:
the ghost-penalty-only cases are the ill-conditioned ones), Jacobian 7.9e-15, residual at the perturbed state
2.7e-14; the squared L2 error against the exact solution moves by up to 1.5e-12 relative (error ~3e-6). All under
the 1e-13 budget. Jacobian-first = Jacobian-after-residual in 72/72. Tests (macOS arm64, local): the same 307
passed before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d test_launchers_have_timeouts)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…iring, one weights routine and one point routine (C44 unfitted refactor, step 5b)

The SCIFEM face loop (Ji et al. 2014 eq. 3.7/3.8 consistency and adjoint terms plus the interior penalty) existed
twice (residual ~300 lines, Jacobian ~260). Now both call: pairFacePoints (strict: the verified quadrature pairing,
the same routine the ghost penalty uses non-strict), faceCutWeights (the edge Heaviside moment fit in 2D, the 2D fit
on the cut triangle in 3D, side 0's parametrization, in one place; cutFaceWeights takes plain pointers now) and
scifemPoint (the two-sided basis of both elements at the paired point, the half fluxes and branch jumps, and for the
residual the solution with the solution-jump and flux-jump lifts). The terms are unfitted::symmetricConsistency with
the branch weights switch * ImH_e * dS and switch * H_e * dS, and unfitted::jumpPenalty with the weights ImH_e * dS,
H_e * dS and the coefficients gamma/h * mua, gamma/h * mub, over the 2 * nDOF local DOFs; the Jacobian is the same
kernels with the residual's weights (everything is linear in u_dof). No std::map, no CSR-index map: the local block
is scattered by the face's CSR offsets. ADR.h 3535 -> 3222 lines.

Kernels replacing hand arithmetic, so round-off moves. Measured against the step-5a reference (72 cases: solution,
residual and Jacobian at the solution and at the perturbed state): 47 bit-identical (no SCIFEM in play), 25 differ.
Largest relative differences: Jacobian 2.5e-15, residual at the perturbed state 1.3e-14, solution 3.1e-13 in one case
(3D P1 sphere with mu_b/mu_a = 1000, whose Jacobian moved by 1.9e-15 and residual by 2.5e-15: the solution moves by
the conditioning of that system times that) and 6.1e-14 or less in all others. The one solution difference above the
1e-13 budget is reported here as the budget requires; the Jacobian and residual, which the kernels compute, are
within 1.3e-14. Jacobian-first = Jacobian-after-residual in 72/72. Tests (macOS arm64, local): the same 307 passed
before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e routine for residual and Jacobian (C44 unfitted refactor, step 5c)

The one-sided edge correction on an element cut by both level sets (2D, P1 and P2) existed twice (residual ~85
lines, Jacobian ~70): the two Gamma_f-cut faces, the edge moment-fit indicators of each branch (fluid or solid side
of Gamma_s), the face quadrature, the branch flux and the scatter. Now tripleCutEdge() does it once: per branch the
term is a one-sided consistency term, unfitted::symmetricConsistency with s = 0 (no adjoint part), weight
-tcSgn * W_branch * dS, over the element's local DOFs; with the nodal coefficients it adds the residual, without
them the Jacobian block (linear in u_dof through the flux; JA/JB are fixed data). The caller scatters the local
vector or block. The edge normal is sized 3 (it was 2 here). ADR.h 3222 -> 3203 lines.

Kernel replacing hand arithmetic: measured against the step-5b reference (72 cases: solution, residual and
Jacobian at the solution and at the perturbed state): 61 bit-identical, 11 differ (the triply-cut cases); largest
relative differences: solution 4.5e-16, Jacobian 9.5e-17, residual at the perturbed state 4.7e-16. Jacobian-first =
Jacobian-after-residual in 72/72. Tests (macOS arm64, local): the same 307 passed before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…region weights, face terms (C44, from Darsh's proposal)

From cekees/unfitted-refactor at d204083 (#286).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… A, geometry)

From cekees/c44-ph3a at 1c45bf1 (#287).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rilaterals and hexahedra with an oriented dof map

From cekees/c8-r4 at c8e7f87 (#288).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cekees
cekees merged commit 9c40a3b into proteustoolkit:main Nov 15, 2026
9 checks passed
@cekees
cekees deleted the train/main-2026-11-15 branch November 15, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant