From d59d033bdaa82569c39fba5427c85d37ca6e67fd Mon Sep 17 00:00:00 2001 From: t Date: Tue, 3 Nov 2026 23:58:39 +0000 Subject: [PATCH 1/2] Test operators() after M4 and document its rejections and full-length u0 Adds tests for the nonlinear-term ArgumentError, the full-length u0 (also under dirichlet = :eliminate, where the problem's u0 drops the prescribed dofs), and updates the operators docstring to the behaviour on master. 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 --- src/frontend.jl | 12 ++++++++---- test/shared/frontend_tests/operators.jl | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/frontend.jl b/src/frontend.jl index 1196f0c2..6ad2359b 100644 --- a/src/frontend.jl +++ b/src/frontend.jl @@ -566,13 +566,17 @@ builds its own system around them (such as a component with boundary ports). Ret - `differential_vars`: rows of `M` with a nonzero entry; - `prescribed`, `dirichlet_values`: the dofs of the `PDESystem`'s Dirichlet conditions and their values (the rows `M` and `K` would have replaced); - - `u0`: the initial dof vector, with the Dirichlet values on the prescribed dofs; + - `u0`: the initial dof vector, with the Dirichlet values on the prescribed dofs. It always has + every dof, also under `dirichlet = :eliminate`, where the `DAEProblem`'s own `u0` holds the + free dofs only; - `metadata`: the [`FEMMetadata`](@ref), for [`facet_dofs`](@ref), [`dof_coordinates`](@ref) and [`cell_dofs`](@ref). -It is the linear, time-independent case only: a nonlinear term, a time-dependent source or -time-dependent Dirichlet data has no data form and raises an `ArgumentError`. Parameters are -substituted by their values, as for the `DAEProblem`. +It is the linear, time-independent case only, and anything else raises an `ArgumentError`: a +nonlinear term ("operators returns linear operators only, but the PDESystem has nonlinear +terms"), a time-dependent source ("operators needs time-independent sources, but a source +depends on time") and time-dependent Dirichlet data ("operators needs Dirichlet data that are +constant in time"). Parameters are substituted by their values, as for the `DAEProblem`. """ function operators(pdesys::ModelingToolkit.PDESystem, disc::FEMDiscretization) parts = _lower(pdesys, disc) diff --git a/test/shared/frontend_tests/operators.jl b/test/shared/frontend_tests/operators.jl index 41332bcc..ecc2fd77 100644 --- a/test/shared/frontend_tests/operators.jl +++ b/test/shared/frontend_tests/operators.jl @@ -44,6 +44,8 @@ end @test sort(ops.prescribed) == sort([facet_dofs(md, left, u); facet_dofs(md, right, u)]) @test maximum(abs, ops.K * ones(size(ops.K, 1))) < 1.0e-12 @test ops.u0[facet_dofs(md, left, u)] ≈ fill(2.0, 4) + # u0 is the full dof vector, so it lines up with the rows of M and K. + @test length(ops.u0) == size(ops.K, 1) # Off the Dirichlet rows the operators are those of the DAEProblem. prob = DAEProblem(pdesys, disc) free = setdiff(1:size(ops.K, 1), ops.prescribed) @@ -53,6 +55,21 @@ end @test res[free] ≈ (ops.M * du + ops.K * prob.u0 - ops.F)[free] end + @testset "dirichlet = :eliminate still returns the full dof vector" begin + Ω = MeshDomain(rectangle_grid(Quadrilateral, (4, 3))) + left, right = boundarypiece.(Ω, (:left, :right)) + pdesys = heat_system(Ω, [u(t, left) ~ 2.0, u(t, right) ~ 0.0]) + disc = FEMDiscretization(Ω, t; dirichlet = :eliminate) + ops = FiniteElementMethod.operators(pdesys, disc) + # operators ignores the elimination: all dofs, with the Dirichlet values on the prescribed ones. + @test length(ops.u0) == size(ops.K, 1) == 5 * 4 + @test ops.u0[facet_dofs(ops.metadata, left, u)] ≈ fill(2.0, 4) + @test ops.u0[facet_dofs(ops.metadata, right, u)] ≈ zeros(4) + # The eliminated problem drops exactly the prescribed dofs. + prob = DAEProblem(pdesys, disc) + @test length(prob.u0) == length(ops.u0) - length(ops.prescribed) + end + @testset "facet_dofs, dof_coordinates and cell_dofs" begin Ω = MeshDomain(rectangle_grid(Triangle, (4, 3))) left, top = boundarypiece.(Ω, (:left, :top)) @@ -81,6 +98,9 @@ end msg(f) = errmsg(f) nonlinear = Dt(u(t, x, y)) ~ Dx(Dx(u(t, x, y))) + Dy(Dy(u(t, x, y))) - u(t, x, y)^3 @test occursin("nonlinear", msg(() -> FiniteElementMethod.operators(heat_system(Ω, [u(t, left) ~ 0]; eq = nonlinear), FEMDiscretization(Ω, t)))) + @test_throws "operators returns linear operators only" FiniteElementMethod.operators( + heat_system(Ω, [u(t, left) ~ 0]; eq = nonlinear), FEMDiscretization(Ω, t) + ) @test occursin("constant in time", msg(() -> FiniteElementMethod.operators(heat_system(Ω, [u(t, left) ~ sin(t)]), FEMDiscretization(Ω, t)))) sourced = Dt(u(t, x, y)) ~ Dx(Dx(u(t, x, y))) + Dy(Dy(u(t, x, y))) + t @test occursin("time-independent", msg(() -> FiniteElementMethod.operators(heat_system(Ω, [u(t, left) ~ 0]; eq = sourced), FEMDiscretization(Ω, t)))) From 9946c52ee7a20c12f9046c739786076b7bc234ec Mon Sep 17 00:00:00 2001 From: t Date: Wed, 4 Nov 2026 00:06:26 +0000 Subject: [PATCH 2/2] Fix three stale test comments Comment-only: nonlinear terms are supported, periodic conditions are rejected with a fixed message, and errors.jl describes its coverage. 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 --- test/Integration/linear.jl | 6 +++--- test/shared/frontend_tests/errors.jl | 2 +- test/shared/molcomparison_tests/mol_comparison.jl | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/Integration/linear.jl b/test/Integration/linear.jl index 5064ad85..81fc2d0a 100644 --- a/test/Integration/linear.jl +++ b/test/Integration/linear.jl @@ -235,9 +235,9 @@ end end @testset "periodic conditions are carried through weak_form untouched" begin - # Checks only that weak_form passes periodic data through with its terms unchanged. Periodic pairing is - # constraint-level (PeriodicDirichlet in M4), and rejecting periodic conditions before M4 belongs to the - # discretizer (M2/M4), so this is not coverage of the periodic BC kind. + # Checks only that weak_form passes periodic data through with its terms unchanged. Periodic conditions are not + # supported by the discretizer ("periodic boundary conditions are not supported"), which rejects them + # after weak_form, so this is not coverage of the periodic BC kind. eq = Dt(U) ~ Dx(k * Dx(U)) + Dy(k * Dy(U)) + x * y + 1 bcs = [BC("top", k * Dy(U) + α * U ~ β, TOP)] periodic = [PeriodicBC("left", "right", 1, [2.0, 0.0])] diff --git a/test/shared/frontend_tests/errors.jl b/test/shared/frontend_tests/errors.jl index 3144e6b0..59de090c 100644 --- a/test/shared/frontend_tests/errors.jl +++ b/test/shared/frontend_tests/errors.jl @@ -1,4 +1,4 @@ -# Every M2 error path of the front end. Each is raised by `discretize` (which is +# The user-facing error paths of the front end. Each is raised by `discretize` (which is # `discretize(pdesys, disc)`) before any solver runs. Documented user-facing messages are matched # exactly; errors raised inside PDEBase's analysis are matched by substring. using Test diff --git a/test/shared/molcomparison_tests/mol_comparison.jl b/test/shared/molcomparison_tests/mol_comparison.jl index 20100be4..bcc1d190 100644 --- a/test/shared/molcomparison_tests/mol_comparison.jl +++ b/test/shared/molcomparison_tests/mol_comparison.jl @@ -52,9 +52,8 @@ end const SCALAR = [(u, ustar)] # Two-field reaction–diffusion with cross-diffusion χ∇w in u's flux and linear reactions coupling -# the fields both ways. Linear because the front end rejects nonlinear terms until M3's numeric path -# lands (spec §11.1); the signs of the coupling are not symmetric, so a swapped sign shows up as a -# lost rate. Each flux term is its own divergence: MethodOfLines cannot discretize +# the fields both ways. Both couplings are linear; the signs of the +# coupling are not symmetric, so a swapped sign shows up as a lost rate. Each flux term is its own divergence: MethodOfLines cannot discretize # Dx(Dx(u) + χ * Dx(w)) (it fails building an auxiliary variable), and it cannot discretize the # cross term next to a conormal condition on u, so u is Dirichlet on every face and only w has a # Neumann face.