Skip to content

Add the FEM solution interface on PDETimeSeriesSolution - #8

Merged
xtalax merged 16 commits into
masterfrom
forge/m2-3-solution
Nov 2, 2026
Merged

xtalax merged 16 commits into
masterfrom
forge/m2-3-solution

Conversation

@xtalax-droid

Copy link
Copy Markdown
Collaborator

Problem

solve on a FEM-discretized problem needs to return a solution indexed in the PDESystem variables (spec §7.8), as MethodOfLines does with MOLMetadata. Without it, users get a bare DAESolution.

This is PR 3 of the M2 series (linear Ferrite backend and numeric DAE path). It stands alone on master. It reads only space.dh from the space, so it does not depend on #2. It and #2/#6 all add sections to docs/src/api.md and entries to test/test_groups.toml, so later merges need a trivial union of those sections.

Change

  • Adds FieldInfo and FEMMetadata{hasTime, DH, PDE, Sp} <: SciMLBase.AbstractDiscretizationMetadata{hasTime}, with the PDETimeSeriesSolution(sol, md) / PDENoTimeSolution(sol, md) outer constructors. Passing FEMMetadata as the positional problem_type of a DAEProblem makes solve return PDETimeSeriesSolution{…, FEMMetadata}. A steady NonlinearProblem{iip} with time === nothing gives a PDENoTimeSolution.
  • sol[t] returns the saved times. sol[x] returns the coordinates of every mesh node, in the order of the (x, y) pairing. sol[u(t,x,y)] is nt × nnodes, built with evaluate_at_grid_nodes, so P2 dofs that are not mesh nodes are dropped. sol[u, k, :] returns one time row.
  • Traces: sol[u(t, Γ)] and sol(t, Γ; dv) have columns piece_nodes(sol, Γ). These include mid-edge nodes on quadratic meshes and also index sol[x].
  • normal_flux(sol, dv, Γ) returns the facet-mean ∇u·n.
  • First derivatives: pointwise with sol(…; dv = Dx(u)); at the nodes with sol[Dx(u)], an L2 projection integrated at order 2p with one projector per call. Second-derivative keys are rejected, and the error names the accepted keys.
  • All FE values use the mesh's geometric interpolation, so quadratic cells work.
  • sol(t, x, y; dv) interpolates the dof vector in time, then evaluates it with PointEvalHandler. Vector arguments give a tensor product and scalar arguments drop their axis. sol(t, pts::Vector{<:Vec}) evaluates at scattered points. sol(t, x, y) without dv returns one value per field.
  • Points outside the mesh give NaN, or a DomainError with outside = :error. Points that Ferrite's nearest-node search misses are searched again among cells whose bounding box contains them.
  • A time outside the saved span throws a DomainError. Backward time spans are supported.
  • FEMInterpolant caches the PointEvalHandler for the last point set.
  • write_vtk(sol, base) writes one .vtu file per step plus a .pvd file with XML-escaped names.
  • Docs: a Solutions page (coordinate binding and the shapes that differ from MethodOfLines, spec §11.4 (a) and (c)) and an API page.
  • Compat floors: SciMLBase 3.58, Ferrite 1.7. New deps: SymbolicUtils, LinearAlgebra; test extras OrdinaryDiffEqBDF, SparseArrays.

Spec deviation: on a mesh, "an array shaped like the domain" is nt × nnodes (spec §7.8), not a tensor grid.

Tests

New Solution group in test/Solution/solution.jl: 190/190 pass (1m58s); GROUP=Core 1/1, GROUP=QA 20/20; Runic and typos clean; docs build clean. The tests solve heat DAEs lowered by hand with Ferrite in test/shared/heat.jl (u_t = Δu with u = sin(t) on the facet set "inlet", DFBDF) and check the wrapper exactly against the raw dofs. The §7.8 1e-12 trace check on the Gmsh L-shape is exercised through the full front end in the follow-up front-end PR.

The eager wrap takes 0.028 s at 11 810 dofs (u P1 + w P2) with 82 steps.

Branches covered

  • solve wraps to PDETimeSeriesSolution{…, FEMMetadata} over a DAESolution (square, L-shape, two fields).
  • sol[t], sol[x], sol[y] return node coordinates.
  • sol[u(t,x,y)] is nt × nnodes; for P1 it is a permutation of the dofs.
  • sol[u, k, :] works and sol[u, end, :] is rejected.
  • sol.original_sol[u_arr] works for one field and for two.
  • sol(t_k, x, y; dv) matches a direct PointEvalHandler evaluation to 1e-14, for P1 and for P2.
  • Tensor products of vector arguments; vector t × vector x × scalar y gives shape (nt, nx).
  • sol(t, x, y) without dv, for one and two fields; sol(t, pts::Vector{Vec}; dv); PointEvalHandler cache reuse.
  • Points outside the mesh give NaN (square, and the missing quadrant of the L); outside = :error throws a DomainError; the fallback search finds points Ferrite's search misses (graded mesh).
  • A time outside the span throws, above and below, for points and traces; a backward span accepts and bounds its times.
  • The wrapper trace equals the raw inlet dofs and matches sin(t) at the default and the 1e-10 solver tolerances; piece_nodes indexes sol[x]; sol(t, Γ; dv) works; an unknown piece errors.
  • Traces on quadratic meshes include the mid-edge nodes, steady and transient.
  • P2 values at mesh vertices match point evaluation there.
  • normal_flux: transient shape, exact steady value, exact values on quadratic geometry, error for a non-field argument.
  • Derivatives: pointwise Dx against a central difference; projected sol[Dx(u)] and sol[Dy(u)]; exact for P1 linear and P2 quadratic data; one projector per call; exact on quadratic geometry.
  • Dy(Dy(u)) is rejected for indexing and for calls; a Dt(u) key is rejected.
  • write_vtk writes nt .vtu files and a .pvd with nt entries, with XML escaping.
  • Steady PDENoTimeSolution: sol[u(x,y)], sol(x, y), sol[u(Γ)], sol(Γ), NaN outside.
  • show(sol) does not throw.

Notes for review

  • The Γ key relies on u(t, Γ) accepting a DomainSets.Domain argument, unwrapped with SymbolicUtils.unwrap_const. It is tested with a stand-in piece type; the front-end PR exercises the real PDEBase BoundaryPiece.
  • piece_nodes uses the non-public Ferrite.dirichlet_facetdof_indices (QA-ignored); Ferrite 1.7 has no public facet-to-node accessor.
  • _order and _geometry assume Lagrange interpolations and a grid with a single cell type.
  • The projector allocation test relies on allocation counts, which could shift with a future Ferrite version.

Codex review: rounds 1-4 changes requested (all fixed with regression tests; an independent review during the Codex outage also contributed the Ferrite floor and projector-reuse fixes); final round on a3f8157: approve (0 findings).


🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-opus-5-5
Review: unreviewed
Session: 79577b03-59e1-4632-bd76-f6fcde70b991

xtalax and others added 9 commits October 24, 2026 21:12
FEMMetadata as the problem_type of a DAEProblem (or NonlinearProblem) makes solve return a SciMLBase.PDETimeSeriesSolution (PDENoTimeSolution when steady) indexed in the PDESystem variables: vertex-valued fields, traces on boundary pieces, facet-mean normal fluxes, first derivatives, point evaluation with NaN outside the mesh, and VTK export (spec section 7.8). Only space.dh is read from the space, so the FEMSpace slots in later.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
A new Solution test group solves u_t = Δu with u = sin(t) on an inlet, lowered by hand with Ferrite to a DAEProblem, on a unit square, an L-shape and a P1 + P2 two-field case, plus a steady Laplace solution and a graded mesh where Ferrite's nearest-node point search misses an interior point.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Codex round 1: the L2 projection of the gradient now integrates at order 2p, so P2 fields reproduce polynomial derivatives exactly; the time-span check accepts solutions saved backwards; .pvd file attributes are XML-escaped. SciMLBase compat rises to the 3.58 floor the wrapper relies on. Docstrings move to a new API page so Documenter's missing_docs check passes, and a flagged variable name is renamed for typos.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Independent review: (1) the point-search fallback passes cellset to PointEvalHandler, a keyword added in Ferrite 1.6, so Ferrite compat is now 1.7, the spec floor and the space-layer PR's bound. (3) sol[Dx(u)] assembled and factorised a fresh L2Projector per saved step; it now builds one per key and reuses it with project(proj, qpvals, qr), with identical results and a test that the call allocates far less than one projector per step.

(2) The trace tests do not claim the spec 7.8 exit check. They prove the wrapper bit-for-bit (sol[u(t, Γ)] equals the raw inlet dofs) and show sin(t) agreement at the solve tolerance (1e-3 by default, 1e-9 at 1e-10 tolerances); the testset is now named 'wrapper trace equals the raw inlet dofs'. The 9.4e-5 raw violation at default tolerances is a solver/lowering matter, and the 1e-12 trace check on the Gmsh L-shape is owned by the front-end PR through the numeric DAE path.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Codex round on de8e95c: PointValues, CellValues and FacetValues defaulted to linear geometry, so pointwise and projected derivatives and normal_flux threw on QuadraticTriangle meshes. They now take Ferrite.geometric_interpolation of the grid's cell type (spec 6.2). A new testset checks P2 fields on a QuadraticTriangle mesh: point values, pointwise and projected derivatives and facet fluxes are exact for linear and quadratic data.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Codex on 475ba16: piece_nodes took a facet's nodes from Ferrite.facets, which lists vertices only, so on quadratic meshes the traces dropped the mid-edge boundary nodes that sol[x] and sol[u] contain. It now maps each facet to its local nodes through the geometric interpolation's facet dofs (Ferrite.dirichlet_facetdof_indices, which replaces facets in the QA ignore list). Columns stay sorted node ids, so they index sol[x]. New tests on a QuadraticTriangle mesh check that the inlet has all five nodes and that steady and transient traces equal the field at those nodes; the test assembly now uses the mesh's geometric interpolation too.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Codex: _wrap_parts allocated Float64 buffers, so a complex-valued solution threw InexactError on wrap. The wrapper, the steady conversion, point evaluation (with a NaN of the field's type outside the mesh), pointwise and projected gradients and normal_flux now take their scalar type from the dof vector. A Complex coefficients testset covers steady and transient wraps, sol[u], point evaluation with an outside point, traces, derivatives and fluxes.

The API page from master said nothing is exported; it now names the five exports and keeps the @autodocs block.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Codex on 9e5b4be: Ferrite.project assembles into real buffers, so a complex field with a nonzero gradient threw InexactError in sol[Dx(u)]; the earlier complex test only had constant fields. Complex quadrature-point values are now projected as real and imaginary parts with the same projector and recombined. A Complex gradients testset checks a complex linear P1 and a complex quadratic P2 field: projected and pointwise Dx and Dy and the inlet normal flux are exact.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: 79577b03-59e1-4632-bd76-f6fcde70b991
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
xtalax and others added 7 commits October 27, 2026 23:46
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
The merge brought space.jl from master, which defines the same method as solution.jl; the overwrite breaks precompilation (Aqua persistent-tasks check).

Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Aqua deps_compat requires a compat entry for the SparseArrays dep.

Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
@xtalax
xtalax merged commit f5a9a05 into master Nov 2, 2026
33 checks passed
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.

2 participants