Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
edb4d14
Add the Interface test group: narrated end-to-end cases through the p…
xtalax Nov 3, 2026
3977f6b
Add advection-diffusion, reaction-diffusion, variable-coefficient and…
xtalax Nov 3, 2026
28e3470
Add theme B rows to the Interface README case table
xtalax Nov 3, 2026
0dcf569
Add 3D heat, element order and solver choice interface tests
xtalax Nov 3, 2026
ada3c35
Interface README: rows for heat_3d, element_order and solver_choices
xtalax Nov 3, 2026
70c094e
Add Interface cases: coupled systems, first-order wave, mesh domains,…
xtalax Nov 3, 2026
a218e6b
Add the coupled, wave, mesh, curved and parameter cases to the Interf…
xtalax Nov 3, 2026
a8795e9
Merge test/interface-e2e-a into test/interface-e2e
xtalax Nov 3, 2026
00caa6a
Merge test/interface-e2e-b into test/interface-e2e
xtalax Nov 3, 2026
6138ff7
Merge test/interface-e2e-c into test/interface-e2e
xtalax Nov 3, 2026
91f01f8
Distinguish the 1D and 2D advection-diffusion rows in the Interface R…
Nov 3, 2026
f205d90
Merge upstream/master into test/interface-e2e
Nov 3, 2026
e17e6cd
Update the Interface rejections and reaction-diffusion cases for M4
Nov 3, 2026
b1f9afc
Add the M4 cases to the Interface test group
Nov 3, 2026
553a62a
Merge upstream/master into test/interface-e2e
Nov 3, 2026
7054ae6
Rename the manufactured-solution variables flagged by the spell check
Nov 4, 2026
22bd8e7
Merge upstream/master into test/interface-e2e
Nov 5, 2026
69495f5
Raise the OrdinaryDiffEqBDF test floor to 2.4.1
Nov 5, 2026
154b2df
Merge upstream/master into test/interface-e2e
Nov 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LinearAlgebra = "1.10"
ModelingToolkit = "11.34"
LinearSolve = "5"
NonlinearSolveFirstOrder = "2.10"
OrdinaryDiffEqBDF = "2.4"
OrdinaryDiffEqBDF = "2.4.1"
OrdinaryDiffEqNonlinearSolve = "2.9.4"
PDEBase = "0.1.40"
PrecompileTools = "1.2.1"
Expand Down
112 changes: 112 additions & 0 deletions test/Interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Interface tests

End-to-end tests written the way a user writes a script, in the style of MethodOfLines.jl's interface
tests: build a `PDESystem`, choose a `FEMDiscretization`, `discretize`, `solve`, and compare with the exact
(manufactured) solution. They use the exported and documented API only: no internals such as
`sol.disc_data` or `FiniteElementMethod.rectangle_grid`. Meshes come from `Ferrite.generate_grid`, as in
the documentation.

Run the group with `GROUP=Interface julia --project=. -e 'using Pkg; Pkg.test()'`. Every `*.jl` file in this
directory runs in its own `@safetestset`, so each file is self-contained.

## Conventions

1. **One narrated testset per case.** The name reads as a sentence stating the result
(`"P1 elements on a line converge at rate 2 for ..."`).
2. **The comment block opens every testset** and states, in this order: `PDE`, `Domain`, `BCs` (boundary and
initial conditions), `Exact` (the manufactured solution) and `Shows` (what the case demonstrates).
A testset that loops over variants uses `$name` in its title and one comment block for all of them.
3. **Short.** A case is about 40 lines at most. If it needs more, move the repeated PDE setup into a small
function above the testset (see `heat_1d_error` in `heat_1d.jl`) or split the case.
4. **Cheap.** Meshes and time spans are small; a case takes seconds after compilation.
5. **Exact comparison.** Choose a solution inside the element space (error at solver tolerance, tolerance
`1e-7`) or compare against a smooth one with a stated tolerance, or check the convergence rate with
`observed_rate` over a refinement sequence. Compare through `sol(t, x, y; dv)` using `l2_error`.
6. **Unsupported inputs** go in `rejections.jl` with `@test_throws "message text" expr`. Do not add `@test_broken`.
7. Shared code is in `test/shared/interface_helpers.jl` (`sample_points`, `l2_error`, `observed_rate`); add to it
only what two files need.

## Adding a case

Copy the nearest testset, change the PDE, boundary conditions and exact solution, update the comment block,
and add a row to the table below. A new theme is a new file in this directory; nothing needs registering.
The mesh of a box is `MeshDomain(generate_grid(Triangle, (n, n), Vec(0.0, 0.0), Vec(1.0, 1.0)))`; its
boundary pieces are `boundarypiece.(Ω, (:left, :right, :bottom, :top))` in 2D and `(:left, :right)` in 1D.

## Cases

| File | Case | PDE | Dim | Order | Boundary conditions |
|------|------|-----|-----|-------|---------------------|
| `heat_1d.jl` | P1 convergence rate 2 | heat | 1 | P1 | constant Dirichlet |
| `heat_1d.jl` | P2 convergence rate 3 | heat | 1 | P2 | constant Dirichlet |
| `heat_2d.jl` | eigenmode decay on triangles and quadrilaterals | heat | 2 | P1, P2 | zero Dirichlet |
| `heat_2d.jl` | exact reproduction by P2 | heat | 2 | P2 | time-dependent Dirichlet |
| `heat_2d.jl` | P1 convergence rate 2 | heat | 2 | P1 | time-dependent Dirichlet |
| `neumann_robin.jl` | Neumann on three sides | heat | 2 | P2 | Dirichlet and Neumann |
| `neumann_robin.jl` | Robin with parameters `k`, `α` | heat | 2 | P2 | Dirichlet and Robin |
| `neumann_robin.jl` | Dirichlet, Neumann and Robin together | heat | 2 | P2 | all three |
| `neumann_robin.jl` | insulated box | heat | 2 | P1 | zero Neumann |
| `solution_access.jl` | `sol[u]`, `sol[x]`, `sol[y]` shapes | heat with parameter `D` | 2 | P2 | Dirichlet |
| `solution_access.jl` | `sol(t, x, y; dv)` points, grids, outside the mesh | heat | 2 | P2 | Dirichlet |
| `solution_access.jl` | derivative and trace keys | heat | 2 | P2 | Dirichlet |
| `solution_access.jl` | parameter values set the diffusivity | heat | 2 | P2 | Dirichlet |
| `heat_3d.jl` | eigenmode decay on hexahedra and tetrahedra | heat | 3 | P1, P2 | zero Dirichlet |
| `heat_3d.jl` | exact reproduction by P2 | heat | 3 | P2 | time-dependent Dirichlet |
| `heat_3d.jl` | P1 hexahedra rate 2, P2 tetrahedra rate 3 | heat | 3 | P1, P2 | zero Dirichlet |
| `element_order.jl` | line P1, P2 rates 2 and 3 | heat | 1 | P1, P2 | zero Dirichlet |
| `element_order.jl` | triangle and quadrilateral P1, P2, P3 rates 2, 3, 4 | heat | 2 | P1, P2, P3 | zero Dirichlet |
| `solver_choices.jl` | DFBDF, DABDF2, DImplicitEuler, DFBDF order 2 | heat | 1 | P2 | constant Dirichlet |
| `solver_choices.jl` | tolerances and `saveat` | heat | 1 | P2 | constant and time-dependent Dirichlet |
| `solver_choices.jl` | ODE solver refused for the DAE problem | heat | 1 | P2 | time-dependent Dirichlet |
| `advection_diffusion.jl` | exact reproduction with constant velocity | advection-diffusion with source | 1 | P2 | time-dependent Dirichlet |
| `advection_diffusion.jl` | P2 convergence rate 3 with manufactured source on a line | advection-diffusion with source | 1 | P2 | zero Dirichlet |
| `advection_diffusion.jl` | exact reproduction with velocity vector on triangles and quadrilaterals | advection-diffusion with source | 2 | P2 | time-dependent Dirichlet |
| `advection_diffusion.jl` | P2 convergence rate 3 with manufactured source on triangles | advection-diffusion with source | 2 | P2 | zero Dirichlet |
| `reaction_diffusion.jl` | linear reaction with source on triangles and quadrilaterals | reaction-diffusion | 2 | P2 | zero Dirichlet |
| `reaction_diffusion.jl` | decay reaction, P2 convergence rate 3 | reaction-diffusion | 1 | P2 | zero Dirichlet |
| `reaction_diffusion.jl` | two linearly coupled fields, exact | coupled reaction-diffusion | 1 | P2 | time-dependent Dirichlet |
| `reaction_diffusion.jl` | logistic reaction, manufactured source, rate 3 | nonlinear reaction-diffusion | 1 | P2 | zero Dirichlet |
| `variable_coefficient_diffusion.jl` | `Dx(a Dx(u))`, rate 3 | divergence-form diffusion | 1 | P2 | zero Dirichlet |
| `variable_coefficient_diffusion.jl` | `a Dxx(u)`, rate 3 | non-divergence-form diffusion | 1 | P2 | zero Dirichlet |
| `variable_coefficient_diffusion.jl` | `Dx(a Dx(u)) + Dy(a Dy(u))`, rate 3, triangles and quadrilaterals | divergence-form diffusion | 2 | P2 | zero Dirichlet |
| `variable_coefficient_diffusion.jl` | `a (Dxx(u) + Dyy(u))`, rate 3, triangles and quadrilaterals | non-divergence-form diffusion | 2 | P2 | zero Dirichlet |
| `source_terms.jl` | manufactured source, rates 2 and 3 | heat with source | 1 | P1, P2 | time-dependent Dirichlet |
| `source_terms.jl` | manufactured source, rate 3, triangles and quadrilaterals | heat with source | 2 | P2 | time-dependent Dirichlet |
| `source_terms.jl` | polynomial solution, exact | heat with source | 2 | P2 | time-dependent Dirichlet |
| `coupled_systems.jl` | bidirectionally coupled pair, exact in P2 | two coupled reaction-diffusion fields | 2 | P2 | Dirichlet |
| `coupled_systems.jl` | coupled eigenmode pair (cosh, sinh) on triangles and quadrilaterals | two coupled heat fields | 2 | P2 | zero Dirichlet |
| `coupled_systems.jl` | both fields converge at rate 2 | two coupled heat fields | 2 | P1 | time-dependent Dirichlet |
| `coupled_systems.jl` | different boundary condition kinds per field | two coupled reaction-diffusion fields | 2 | P2 | Dirichlet on u; Dirichlet and Neumann on v |
| `wave_first_order.jl` | convergence of u and v on a line | wave as a first-order system | 1 | P1, P2 | zero Dirichlet |
| `wave_first_order.jl` | wave speed `c` in `ps` | wave as a first-order system | 1 | P2 | zero Dirichlet |
| `wave_first_order.jl` | 2D standing wave | wave as a first-order system | 2 | P2 | zero Dirichlet |
| `mesh_domains.jl` | side split into two named pieces | heat | 2 | P2 | Dirichlet, Neumann and Robin on five pieces |
| `mesh_domains.jl` | L-shaped Gmsh mesh read from a file | heat with parameters `k`, `α` | 2 | P2 | Dirichlet on inlet and wall, Robin on outlet |
| `curved_geometry.jl` | optimal rates on a quarter annulus with `QuadraticTriangle` cells | heat with source | 2 | P1, P2 | Dirichlet on the arcs, Neumann |
| `parameters.jl` | `D`, `A`, `g` from `ps` for three parameter sets | heat with source | 2 | P2 | Dirichlet with parameter |
| `parameters.jl` | Neumann flux `q` from `ps` | heat | 2 | P2 | Dirichlet and Neumann with parameter |
| `parameters.jl` | `D` and reaction rate `λ` from `ps` | heat with decay | 2 | P2 | zero Dirichlet |
| `steady.jl` | steady Poisson on a line, rates 2 and 3 | Poisson, no time variable | 1 | P1, P2 | constant Dirichlet |
| `steady.jl` | steady Poisson with Dirichlet and Neumann sides, rates 2 and 3 | Poisson | 2 | P1, P2 | Dirichlet and Neumann |
| `steady.jl` | steady nonlinear diffusion `k(u) = 1 + u^2`, rate 3 | nonlinear diffusion, Newton | 2 | P2 | zero Dirichlet |
| `time_last_variables.jl` | `u(x, y, t)` and `u(t, x, y)` give the same solution, time axis last | heat | 2 | P2 | zero Dirichlet |
| `time_last_variables.jl` | time-last traces, Dirichlet and Neumann data, exact | heat with time-dependent source | 2 | P2 | Dirichlet and Neumann |
| `observed_expressions.jl` | `sol[expr]` and `sol(t, x, y; dv = expr)` | heat with parameter `D` | 2 | P2 | Dirichlet |
| `eliminate.jl` | `dirichlet = :eliminate` against `:algebraic` | heat | 2 | P2 | space-dependent Dirichlet, constant in time |
| `eliminate.jl` | `dirichlet = :eliminate` on a steady problem | Laplace | 2 | P1 | Dirichlet |
| `nonlinear.jl` | viscous Burgers `u u_x`, rate 3 | Burgers with source | 1 | P2 | zero Dirichlet |
| `nonlinear.jl` | nonlinear diffusion `k(u) = 1 + u^2`, rate 3 | nonlinear diffusion with source | 2 | P2 | zero Dirichlet |
| `multifield_spaces.jl` | P2 and P1 fields in one system, rates 3 and 2 | two coupled heat fields | 2 | P2, P1 | Dirichlet |
| `multifield_spaces.jl` | a field restricted to a region reads NaN outside it | two heat fields, one on a half | 2 | P2 | Dirichlet; natural on the region's other sides |
| `supg.jl` | Galerkin oscillates, SUPG with the optimal `τ` is nodally exact | convection-diffusion boundary layer | 1 | P1 | Dirichlet |
| `supg.jl` | constant `τ` with explicit velocity, and `τ(hK, b)` | convection-diffusion boundary layer | 1 | P1 | Dirichlet |
| `navier_stokes.jl` | Kovasznay flow, Taylor-Hood, rates 3 and 2 | steady incompressible Navier-Stokes | 2 | P2/P1 | Dirichlet velocity, Dirichlet pressure on one side |
| `metadata_and_operators.jl` | `facet_dofs`, `dof_coordinates`, `cell_dofs` | heat | 2 | P1, P2 | zero Dirichlet |
| `metadata_and_operators.jl` | `operators` gives the matrices for a hand-made steady solve | heat at its steady state | 2 | P2 | Dirichlet |
| `rejections.jl` | rejected boundary conditions, equations, options, domains, shared facets, SUPG with a nonlinear term, observed expressions, `operators` | heat and others | 1 to 2 | | |

## Not covered

The DFG cylinder (Navier-Stokes, about 149 000 unknowns) is the `NavierStokes` group. Periodic conditions, `codegen = :mtk`,
time-dependent coefficients in the mass or stiffness operator, third-order and second-order-in-time equations are
rejected, and `rejections.jl` asserts the messages.
96 changes: 96 additions & 0 deletions test/Interface/advection_diffusion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Advection-diffusion with a constant velocity through the full interface, in 1D and 2D with P2 elements,
# against manufactured solutions: a source term f is chosen so that a known u solves the equation.
# docs/src/equation_classes.md lists convection-diffusion at moderate cell Peclet number as a Tier 1 class
# (supported, VERIFIED); only pure advection and advection-dominated problems are Tier 2 (they need SUPG, see `supg.jl`),
# so every case here keeps the cell Peclet number below one.
using FiniteElementMethod, ModelingToolkit, DomainSets, OrdinaryDiffEqBDF, Test
using Ferrite: generate_grid, Line, Triangle, Quadrilateral, Vec
using ModelingToolkit: t_nounits as t
include(joinpath(@__DIR__, "..", "shared", "interface_helpers.jl"))

@variables x y u(..)
Dt, Dx, Dy = Differential(t), Differential(x), Differential(y)

line(n) = MeshDomain(generate_grid(Line, (n,), Vec(0.0), Vec(1.0)))
unit_square(celltype, n) = MeshDomain(generate_grid(celltype, (n, n), Vec(0.0, 0.0), Vec(1.0, 1.0)))

# Solves the 1D problem eq on the line Ω with Dirichlet data g(t, x) at both ends and the initial condition g(0, x).
function solve_1d(eq, Ω, g, tend)
left, right = boundarypiece.(Ω, (:left, :right))
bcs = [u(t, left) ~ g(t, 0), u(t, right) ~ g(t, 1), u(0, x) ~ g(0, x)]
@named pdesys = PDESystem([eq], bcs, [(x,) ∈ Ω, t ∈ Interval(0.0, tend)], [t, x], [u(t, x)], [])
disc = FEMDiscretization(Ω, t; spaces = Dict(u => Lagrange{RefLine, 2}()))
return solve(discretize(pdesys, disc), DFBDF(); abstol = 1.0e-10, reltol = 1.0e-10)
end

# Same in 2D on the unit square with Dirichlet data g(t, x, y) on all four sides.
function solve_2d(eq, Ω, ref, g, tend)
bcs = [[u(t, Γ) ~ g(t, x, y) for Γ in boundarypiece.(Ω, (:left, :right, :bottom, :top))]; u(0, x, y) ~ g(0, x, y)]
@named pdesys = PDESystem([eq], bcs, [(x, y) ∈ Ω, t ∈ Interval(0.0, tend)], [t, x, y], [u(t, x, y)], [])
disc = FEMDiscretization(Ω, t; spaces = Dict(u => Lagrange{ref, 2}()))
return solve(discretize(pdesys, disc), DFBDF(); abstol = 1.0e-10, reltol = 1.0e-10)
end

# PDE: u_t + c u_x = D u_xx + f, with c = 2, D = 0.5
# Domain: x in (0, 1), t in (0, 1), 4 line cells
# BCs: u = g(t, x) at both ends (time-dependent Dirichlet); IC u(0, x) = g(0, x)
# Exact: u = x^2 + 3x t + t, so f = u_t + c u_x - D u_xx = 3x + 1 + 2 (2x + 3t) - 1, which lies in the P2 space
# Shows: the advection term has the right sign and size: the P2 solution is exact to the solver tolerance.
@testset "constant-velocity advection-diffusion is reproduced exactly by P2 elements on a line" begin
c, D = 2.0, 0.5
exact(t_, x_) = x_^2 + 3x_ * t_ + t_
source = 3x + 1 + c * (2x + 3t) - D * 2
sol = solve_1d(Dt(u(t, x)) + c * Dx(u(t, x)) ~ D * Dx(Dx(u(t, x))) + source, line(4), exact, 1.0)
@test l2_error(sol, u(t, x), x_ -> exact(1.0, x_), 1.0, sample_points(40)) < 1.0e-7
end

# PDE: u_t + c u_x = D u_xx + f, with c = 5, D = 1 (cell Peclet number c h / 2D is 0.63 on the coarsest mesh and 0.16 on the finest)
# Domain: x in (0, 1), t in (0, 0.2), meshes of 4, 8 and 16 line cells
# BCs: u = 0 at both ends; IC u(0, x) = sin(pi x)
# Exact: u = exp(-t) sin(pi x), so f = (D pi^2 - 1) u + c pi exp(-t) cos(pi x)
# Shows: P2 elements converge at the optimal L2 rate 3 with a source term and a first-order term.
@testset "P2 elements on a line converge at rate 3 for advection-diffusion with a manufactured source" begin
c, D = 5.0, 1.0
source = exp(-t) * ((D * pi^2 - 1) * sin(pi * x) + c * pi * cos(pi * x))
ns = (4, 8, 16)
errors = map(ns) do n
sol = solve_1d(Dt(u(t, x)) + c * Dx(u(t, x)) ~ D * Dx(Dx(u(t, x))) + source, line(n), (t_, x_) -> exp(-t_) * sin(pi * x_), 0.2)
l2_error(sol, u(t, x), x_ -> exp(-0.2) * sin(pi * x_), 0.2, sample_points(200))
end
@test all(observed_rate(errors, 1 ./ ns) .> 2.8)
end

# PDE: u_t + c . grad u = D (u_xx + u_yy) + f, with c = (1, -2), D = 0.5
# Domain: the unit square, t in (0, 1), 4 x 4 cells
# BCs: u = g(t, x, y) on all four sides (time-dependent Dirichlet); IC u(0, x, y) = g(0, x, y)
# Exact: u = x^2 + x y + 2 y^2 + t (1 + x - y), so f = u_t + c . grad u - D Laplace u, in the P2 space
# Shows: a constant velocity vector acts in both directions, on triangles and quadrilaterals.
@testset "constant-velocity advection-diffusion is reproduced exactly by P2 elements on $name meshes" for (name, celltype, ref) in (
("triangle", Triangle, RefTriangle), ("quadrilateral", Quadrilateral, RefQuadrilateral),
)
cx, cy, D = 1.0, -2.0, 0.5
exact(t_, x_, y_) = x_^2 + x_ * y_ + 2y_^2 + t_ * (1 + x_ - y_)
u_x, u_y = 2x + y + t, x + 4y - t
source = (1 + x - y) + cx * u_x + cy * u_y - D * (2 + 4)
eq = Dt(u(t, x, y)) + cx * Dx(u(t, x, y)) + cy * Dy(u(t, x, y)) ~ D * (Dx(Dx(u(t, x, y))) + Dy(Dy(u(t, x, y)))) + source
sol = solve_2d(eq, unit_square(celltype, 4), ref, exact, 1.0)
@test l2_error(sol, u(t, x, y), (x_, y_) -> exact(1.0, x_, y_), 1.0, sample_points(20), sample_points(20)) < 1.0e-7
end

# PDE: u_t + c . grad u = D (u_xx + u_yy) + f, with c = (3, 2), D = 1
# Domain: the unit square, t in (0, 0.1), meshes of 2, 4 and 8 per side
# BCs: u = 0 on all four sides; IC u(0, x, y) = sin(pi x) sin(pi y)
# Exact: u = exp(-t) sin(pi x) sin(pi y), so f = (2 D pi^2 - 1) u + c_x pi exp(-t) cos(pi x) sin(pi y) + c_y pi exp(-t) sin(pi x) cos(pi y)
# Shows: P2 elements converge at the optimal L2 rate 3 in 2D with advection and a manufactured source.
@testset "P2 elements on triangles converge at rate 3 for 2D advection-diffusion with a manufactured source" begin
cx, cy, D = 3.0, 2.0, 1.0
s = exp(-t)
source = s * ((2D * pi^2 - 1) * sin(pi * x) * sin(pi * y) + cx * pi * cos(pi * x) * sin(pi * y) + cy * pi * sin(pi * x) * cos(pi * y))
eq = Dt(u(t, x, y)) + cx * Dx(u(t, x, y)) + cy * Dy(u(t, x, y)) ~ D * (Dx(Dx(u(t, x, y))) + Dy(Dy(u(t, x, y)))) + source
ns = (2, 4, 8)
errors = map(ns) do n
sol = solve_2d(eq, unit_square(Triangle, n), RefTriangle, (t_, x_, y_) -> exp(-t_) * sin(pi * x_) * sin(pi * y_), 0.1)
l2_error(sol, u(t, x, y), (x_, y_) -> exp(-0.1) * sin(pi * x_) * sin(pi * y_), 0.1, sample_points(40), sample_points(40))
end
@test all(observed_rate(errors, 1 ./ ns) .> 2.7)
end
Loading
Loading