From f3e4ed7d09030b0509bc9f0489058eaefcd70c0b Mon Sep 17 00:00:00 2001 From: t Date: Mon, 9 Nov 2026 19:35:51 +0000 Subject: [PATCH 1/4] Deprecate DAEProblem(pdesys, disc) in favour of discretize discretize is the documented entry point; the DAEProblem method now warns and returns the same problem. Tests use discretize, with one test for the deprecation and the steady-system rejection. Agent-Harness: Claude Code 2.1.319 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c Agent-Review: unreviewed Co-authored-by: Claude Code --- src/discretization.jl | 2 +- src/frontend.jl | 7 ++++++- test/Interface/rejections.jl | 1 - test/shared/frontend_tests/arguments.jl | 1 - test/shared/frontend_tests/end_to_end.jl | 18 ++++++++++++++++++ test/shared/frontend_tests/errors.jl | 4 ---- test/shared/frontend_tests/nonlinear.jl | 12 ++++++------ test/shared/frontend_tests/operators.jl | 4 ++-- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/discretization.jl b/src/discretization.jl index 44a2260f..adfedaac 100644 --- a/src/discretization.jl +++ b/src/discretization.jl @@ -52,7 +52,7 @@ gives a `PDENoTimeSolution`. pressure in `0 ~ Dx(u1) + Dy(u2)`; a nonlinear term in the field, as in `0 ~ v^2 - u`, counts as present), and nothing otherwise; a positive number sets that value on the algebraic rows of any system; `nothing` sets nothing. The differential rows - get the `abstol` passed to `FEMDiscretization` or `DAEProblem` if it is a number, else + get the `abstol` passed to `FEMDiscretization` or `discretize` if it is a number, else OrdinaryDiffEq's default `1e-6`; an array `abstol` passed there is used as it is. An `abstol` passed to `solve` replaces the problem's whole vector. The keyword belongs to the time-dependent (DAE) path: a steady discretization ignores `:auto` and `nothing` and diff --git a/src/frontend.jl b/src/frontend.jl index 6b2731d0..ff2a36f9 100644 --- a/src/frontend.jl +++ b/src/frontend.jl @@ -526,7 +526,12 @@ function _abstol(algebraic, ops, selfnonlinear, abstol) return (; abstol = [d ? differential : algebraic for d in ops.differential_vars]) end -SciMLBase.DAEProblem(pdesys::ModelingToolkit.PDESystem, disc::FEMDiscretization; kwargs...) = +function SciMLBase.DAEProblem(pdesys::ModelingToolkit.PDESystem, disc::FEMDiscretization; kwargs...) + Base.depwarn("`DAEProblem(pdesys, disc)` is deprecated, use `discretize(pdesys, disc)` instead", :DAEProblem) + return _daeproblem(pdesys, disc; kwargs...) +end + +_daeproblem(pdesys, disc; kwargs...) = disc.time === nothing ? throw( ArgumentError( diff --git a/test/Interface/rejections.jl b/test/Interface/rejections.jl index a2170c14..33f5e8d0 100644 --- a/test/Interface/rejections.jl +++ b/test/Interface/rejections.jl @@ -61,7 +61,6 @@ end timed = [u(t, Γ) ~ sin(t) for Γ in (left, right, bottom, top)] @test_throws "dirichlet = :eliminate needs Dirichlet data that are constant in time" lower([heat], [timed; ic]; dirichlet = :eliminate) @named steady = PDESystem([Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in (left, right, bottom, top)], [(x, y) ∈ Ω], [x, y], [u(x, y)], []) - @test_throws "the FEMDiscretization has no time variable, so it lowers to a NonlinearProblem" DAEProblem(steady, FEMDiscretization(Ω)) @named transient = PDESystem([heat], [dirichlet; ic], [(x, y) ∈ Ω, t ∈ Interval(0.0, 1.0)], [t, x, y], [u(t, x, y)], []) @test_throws "for a time-dependent problem write FEMDiscretization(Ω, t)" discretize(transient, FEMDiscretization(Ω)) @test_throws "`spaces` has keys that are not dependent variables of the system: v" lower( diff --git a/test/shared/frontend_tests/arguments.jl b/test/shared/frontend_tests/arguments.jl index 0f479920..36c3df16 100644 --- a/test/shared/frontend_tests/arguments.jl +++ b/test/shared/frontend_tests/arguments.jl @@ -66,7 +66,6 @@ const DERIVED_VALUES = (tspan = (0.0, 2.0), u0 = zeros(9), p = [1.0], differenti @testset "keyword `$k` is derived" for k in keys(DERIVED_MESSAGES) kw = NamedTuple{(k,)}((DERIVED_VALUES[k],)) @test_throws ArgumentError(DERIVED_MESSAGES[k]) discretize(pdesys, disc; kw...) - @test_throws ArgumentError(DERIVED_MESSAGES[k]) SciMLBase.DAEProblem(pdesys, disc; kw...) end @testset "derived keywords in FEMDiscretization and NonlinearProblem" begin diff --git a/test/shared/frontend_tests/end_to_end.jl b/test/shared/frontend_tests/end_to_end.jl index 9d599aad..9ed7d7f5 100644 --- a/test/shared/frontend_tests/end_to_end.jl +++ b/test/shared/frontend_tests/end_to_end.jl @@ -2,6 +2,7 @@ # solution. Each manufactured solution lies in the finite-element space and the quadrature is exact # for its data, so the nodal error is at the level of the time-integration tolerance. using Test +using Base.CoreLogging: with_logger, NullLogger using FiniteElementMethod: FiniteElementMethod, rectangle_grid using Ferrite: Triangle, Quadrilateral, Line @@ -82,6 +83,23 @@ dirichlet_all(Ω) = [u(t, Γ) ~ (1 + x + 2y) * (1 + t) for Γ in pieces(Ω)] @test sys isa ModelingToolkit.System end + @testset "DAEProblem(pdesys, disc) is deprecated in favour of discretize" begin + Ω = MeshDomain(rectangle_grid(Triangle, (2, 2))) + @named pdesys = PDESystem([heat_eq], [dirichlet_all(Ω); ic], [(x, y) ∈ Ω, t ∈ Interval(0.0, 1.0)], [t, x, y], [u(t, x, y)], []) + disc = FEMDiscretization(Ω, t; saveat = 0.25) + @test_deprecated r"discretize" SciMLBase.DAEProblem(pdesys, disc; tstops = [0.5]) + old = with_logger(NullLogger()) do + SciMLBase.DAEProblem(pdesys, disc; tstops = [0.5]) + end + new = discretize(pdesys, disc; tstops = [0.5]) + @test old isa SciMLBase.DAEProblem + @test old.u0 == new.u0 && old.du0 == new.du0 && old.tspan == new.tspan && old.kwargs == new.kwargs + @named steady = PDESystem([Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in boundarypiece.(Ω, (:left, :right, :bottom, :top))], [(x, y) ∈ Ω], [x, y], [u(x, y)], []) + with_logger(NullLogger()) do + @test_throws "the FEMDiscretization has no time variable, so it lowers to a NonlinearProblem" SciMLBase.DAEProblem(steady, FEMDiscretization(Ω)) + end + end + @testset "PDESystem without parameters" begin # Leaving out `ps` gives the system `NullParameters()`, which means no parameters. Ω = MeshDomain(rectangle_grid(Triangle, (4, 4))) diff --git a/test/shared/frontend_tests/errors.jl b/test/shared/frontend_tests/errors.jl index fe541706..3cefde9a 100644 --- a/test/shared/frontend_tests/errors.jl +++ b/test/shared/frontend_tests/errors.jl @@ -101,10 +101,6 @@ dirichlet(Ω) = [u(t, Γ) ~ 0 for Γ in sides(Ω)] @named steady = PDESystem( [Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in sides(Ω)], [(x, y) ∈ Ω], [x, y], [u(x, y)], [] ) - @test_throws ArgumentError( - "the FEMDiscretization has no time variable, so it lowers to a NonlinearProblem, not a DAEProblem; " * - "call discretize(pdesys, disc) or NonlinearProblem(pdesys, disc)" - ) DAEProblem(steady, FEMDiscretization(Ω)) @named transient = PDESystem([heat], [dirichlet(Ω); ic], [(x, y) ∈ Ω, t ∈ Interval(0.0, 1.0)], [t, x, y], [u(t, x, y)], []) @test_throws ArgumentError( "the FEMDiscretization has the time variable t, so it lowers to a DAEProblem; " * diff --git a/test/shared/frontend_tests/nonlinear.jl b/test/shared/frontend_tests/nonlinear.jl index 258f2b24..54f467bb 100644 --- a/test/shared/frontend_tests/nonlinear.jl +++ b/test/shared/frontend_tests/nonlinear.jl @@ -117,7 +117,7 @@ end @testset "Jacobian against finite differences, Dirichlet rows" begin Ω = square() eq = Dt(U) + U * Dx(U) ~ Dx((1 + U^2) * Dx(U)) + Dy(Dy(U)) - U^2 + (1 + x + 2y) - prob = DAEProblem(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) + prob = discretize(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) n = length(prob.u0) rng_u = [0.3 + 0.1 * sin(3i) for i in 1:n] rng_du = [0.2 * cos(5i) for i in 1:n] @@ -141,7 +141,7 @@ end # see Dual states; the time-dependent source exercises the load path too. Ω = square() eq = Dt(U) ~ Dx((1 + U^2) * Dx(U)) + Dy((1 + U^2) * Dy(U)) + (1 + x + 2y) - 10 * ustar * (1 + t)^2 - prob = DAEProblem(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) + prob = discretize(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) dofs = prob.problem_type.space.ch.prescribed_dofs u0 = copy(prob.u0) u0[dofs] .+= 0.5 @@ -154,7 +154,7 @@ end # Every evaluation borrows its own copy of the nonlinear operator's buffers and values objects. Ω = MeshDomain(rectangle_grid(Triangle, (16, 16))) eq = Dt(U) ~ Dx((1 + U^2) * Dx(U)) + Dy((1 + U^2) * Dy(U)) + (1 + x + 2y) - 10 * ustar * (1 + t)^2 - prob = DAEProblem(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) + prob = discretize(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) probs = [remake(prob; u0 = s * prob.u0) for s in (1.0, 1.3, 0.7)] final(q) = solve(q, EXACT_ROWS; abstol = 1.0e-8, reltol = 1.0e-8).original_sol.u[end] serial = final.(probs) @@ -167,7 +167,7 @@ end @testset "AbstractFloat states and their Duals are evaluated, nested Duals are rejected" begin Ω = square() eq = Dt(U) ~ Dx((1 + U^2) * Dx(U)) + Dy(Dy(U)) + (1 + x + 2y) - 2 * ustar * (1 + t)^2 - prob = DAEProblem(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) + prob = discretize(pdesystem([eq], [dirichlet(Ω); ic], Ω), FEMDiscretization(Ω, t)) n = length(prob.u0) Dual = FiniteElementMethod.ForwardDiff.Dual value = FiniteElementMethod.ForwardDiff.value @@ -255,7 +255,7 @@ end # The operators, the nonlinear one included, hold the values they were assembled with (spec §8.3). Ω = square() eq = Dt(U) ~ Dx((1 + k * U^2) * Dx(U)) + Dy(Dy(U)) + (1 + x + 2y) - 2k * ustar * (1 + t)^2 - prob = DAEProblem(pdesystem([eq], [dirichlet(Ω); ic], Ω; ps = [k => 1.0]), FEMDiscretization(Ω, t)) + prob = discretize(pdesystem([eq], [dirichlet(Ω); ic], Ω; ps = [k => 1.0]), FEMDiscretization(Ω, t)) sol = solve(prob, EXACT_ROWS; abstol = 1.0e-10, reltol = 1.0e-10) @test nodal_error(sol, U, uexact) <= tol @test SciMLBase.successful_retcode(solve(remake(prob; p = [k => 1.0]), EXACT_ROWS)) @@ -266,7 +266,7 @@ end @testset verbose = true "still-rejected nonlinear classes" begin Ω = square() - lower(eqs, bcs = [dirichlet(Ω); ic]) = DAEProblem(pdesystem(eqs, bcs, Ω), FEMDiscretization(Ω, t)) + lower(eqs, bcs = [dirichlet(Ω); ic]) = discretize(pdesystem(eqs, bcs, Ω), FEMDiscretization(Ω, t)) # Raised by PDEBase's strong-form analysis with the messages of spec Appendix A. @test_throws ErrorException("state-dependent mass in Differential(t, 1)(u(t, x, y))*(u(t, x, y)^2) needs residual-form DAE") lower( [(1 + U^2) * Dt(U) ~ Dx(Dx(U)) + Dy(Dy(U))] diff --git a/test/shared/frontend_tests/operators.jl b/test/shared/frontend_tests/operators.jl index 860eb14a..1b8cd833 100644 --- a/test/shared/frontend_tests/operators.jl +++ b/test/shared/frontend_tests/operators.jl @@ -47,7 +47,7 @@ end # 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) + prob = discretize(pdesys, disc) free = setdiff(1:size(ops.K, 1), ops.prescribed) res = zeros(length(prob.u0)) du = randn(length(prob.u0)) @@ -66,7 +66,7 @@ end @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) + prob = discretize(pdesys, disc) @test length(prob.u0) == length(ops.u0) - length(ops.prescribed) end From b1c365907aef305c290346425feea1f906623bdb Mon Sep 17 00:00:00 2001 From: t Date: Mon, 9 Nov 2026 19:35:51 +0000 Subject: [PATCH 2/4] Use discretize in the examples, README and docs Switches the Navier-Stokes and swirl examples, README and docs to discretize(pdesys, disc). The README Navier-Stokes block changed, so its recorded hash is updated; the problem and the showcase images are unchanged. Agent-Harness: Claude Code 2.1.319 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c Agent-Review: unreviewed Co-authored-by: Claude Code --- README.md | 2 +- docs/src/assets/ns_showcase.fnv1a | 2 +- docs/src/extension_contract.md | 4 ++-- docs/src/navier_stokes.md | 2 +- examples/axisym_swirl/axisym_swirl.jl | 2 +- examples/dfg_cylinder/dfg_cylinder.jl | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 209f88bc..1a24b1bd 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ disc = FEMDiscretization( Ω, t; spaces = Dict(u => Q2, v => Q2, p => Q1), pairing = Dict(eqs[3] => p), natural = [Γ_out], initializealg = CheckInit() ) -prob = DAEProblem(dfg, disc) +prob = discretize(dfg, disc) abstol = [differential ? 1.0e-6 : 1.0e8 for differential in prob.differential_vars] # no error control on p sol = solve(prob, DFBDF(nlsolve = NLNewton(new_W_dt_cutoff = 0), linsolve = UMFPACKFactorization()); abstol, reltol = 1.0e-6) sol(tend, 0.6, 0.2; dv = v(t, x, y)) # the cross-stream velocity in the wake diff --git a/docs/src/assets/ns_showcase.fnv1a b/docs/src/assets/ns_showcase.fnv1a index 2bef995e..b8faad28 100644 --- a/docs/src/assets/ns_showcase.fnv1a +++ b/docs/src/assets/ns_showcase.fnv1a @@ -1 +1 @@ -a3eb010d9c375841 +0d80e6fde5646fde diff --git a/docs/src/extension_contract.md b/docs/src/extension_contract.md index ff0b7ee5..a518aef4 100644 --- a/docs/src/extension_contract.md +++ b/docs/src/extension_contract.md @@ -22,8 +22,8 @@ accepts a `ModelingToolkit.PDESystem` on a `MeshDomain` and returns when it has none, `FEMDiscretization(Ω)`, for a nonlinear solver such as `NewtonRaphson`. Both carry the sparse analytic Jacobian and its prototype, so `solve(prob, alg)` needs nothing -else. `DAEProblem(pdesys, disc)` and `NonlinearProblem(pdesys, disc)` build the same problems -directly. +else. `NonlinearProblem(pdesys, disc)` builds the steady problem directly; the corresponding +`DAEProblem(pdesys, disc)` is deprecated in favour of `discretize`. ## Keywords diff --git a/docs/src/navier_stokes.md b/docs/src/navier_stokes.md index 65afd75d..20c9a8f8 100644 --- a/docs/src/navier_stokes.md +++ b/docs/src/navier_stokes.md @@ -33,7 +33,7 @@ bcs = [ Q2, Q1 = Lagrange{RefQuadrilateral, 2}(), Lagrange{RefQuadrilateral, 1}() disc = FEMDiscretization(Ω, t; spaces = Dict(u => Q2, v => Q2, p => Q1), pairing = Dict(eqs[3] => p), natural = [Γout], initializealg = CheckInit()) -prob = DAEProblem(dfg, disc) +prob = discretize(dfg, disc) abstol = [d ? 1e-7 : 1e8 for d in prob.differential_vars] # pressure and Dirichlet rows out of error control sol = solve(prob, DFBDF(linsolve = UMFPACKFactorization()); abstol, reltol = 1e-7) diff --git a/examples/axisym_swirl/axisym_swirl.jl b/examples/axisym_swirl/axisym_swirl.jl index 46a27748..e03cf791 100644 --- a/examples/axisym_swirl/axisym_swirl.jl +++ b/examples/axisym_swirl/axisym_swirl.jl @@ -81,7 +81,7 @@ function axisym_problem(grid; tend, abstol = 1.0e-8) Ω, t; spaces = Dict(ur => P2, ut => P2, uz => P2, p => P1), pairing = Dict(eqs[4] => p), ibp = Dict(eqs[i] => Weighted(r) for i in 1:3), natural = [Γaxis], initializealg = CheckInit(), abstol ) - return DAEProblem(axisym, disc) + return discretize(axisym, disc) end """ diff --git a/examples/dfg_cylinder/dfg_cylinder.jl b/examples/dfg_cylinder/dfg_cylinder.jl index 72008052..6f7feff7 100644 --- a/examples/dfg_cylinder/dfg_cylinder.jl +++ b/examples/dfg_cylinder/dfg_cylinder.jl @@ -74,7 +74,7 @@ function dfg_problem(grid; tend = 30.0, ν_ = 1.0e-3, Umax_ = 0.3, ramp = 1 - ex Ω, t; spaces = Dict(u => Q2, v => Q2, p => Q1), pairing = Dict(eqs[3] => p), natural = [Γout], initializealg = CheckInit(), kwargs... ) - return DAEProblem(dfg, disc) + return discretize(dfg, disc) end "Absolute tolerances: `abstol` on the differential variables, none (1e8) on the algebraic ones." From 82d097b4de80a7c5913028b237ed6850551340e5 Mon Sep 17 00:00:00 2001 From: t Date: Mon, 9 Nov 2026 20:49:38 +0000 Subject: [PATCH 3/4] Update axisym swirl source hashes for the discretize call examples/axisym_swirl/axisym_swirl.jl now calls discretize, which changes the recorded source hashes of the figures and the animation. The problem is identical, so the images are not regenerated. Agent-Harness: Claude Code 2.1.319 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c Agent-Review: unreviewed Co-authored-by: Claude Code --- docs/src/assets/axisym_swirl.fnv1a | 2 +- docs/src/assets/axisym_swirl_animation.fnv1a | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/assets/axisym_swirl.fnv1a b/docs/src/assets/axisym_swirl.fnv1a index bef79c90..3c5abf88 100644 --- a/docs/src/assets/axisym_swirl.fnv1a +++ b/docs/src/assets/axisym_swirl.fnv1a @@ -1 +1 @@ -e369978afda92609 +7255430df70ab8ea diff --git a/docs/src/assets/axisym_swirl_animation.fnv1a b/docs/src/assets/axisym_swirl_animation.fnv1a index 8a355a95..69c8df41 100644 --- a/docs/src/assets/axisym_swirl_animation.fnv1a +++ b/docs/src/assets/axisym_swirl_animation.fnv1a @@ -1 +1 @@ -3bb1f417d3ec6ef4 +c2f9f849078215af From 9cd1041be1d8b2fb01a5a6bc97a617123ecc84e5 Mon Sep 17 00:00:00 2001 From: t Date: Mon, 9 Nov 2026 23:56:29 +0000 Subject: [PATCH 4/4] Deprecate NonlinearProblem(pdesys, disc) in favour of discretize Same treatment as DAEProblem: the method warns and forwards to a private helper with the old body. Tests use discretize, with one test for the deprecation and the transient-system rejection. Agent-Harness: Claude Code 2.1.321 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c Agent-Review: unreviewed Co-authored-by: Claude Code --- docs/src/extension_contract.md | 4 ++-- src/discretization.jl | 4 ++-- src/frontend.jl | 9 ++++++++- test/shared/frontend_tests/arguments.jl | 1 - test/shared/frontend_tests/end_to_end.jl | 17 +++++++++++++++++ test/shared/frontend_tests/errors.jl | 4 ---- test/shared/frontend_tests/steady.jl | 1 - test/shared/frontend_tests/symbolic.jl | 2 +- 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/src/extension_contract.md b/docs/src/extension_contract.md index a518aef4..0c0213fc 100644 --- a/docs/src/extension_contract.md +++ b/docs/src/extension_contract.md @@ -22,8 +22,8 @@ accepts a `ModelingToolkit.PDESystem` on a `MeshDomain` and returns when it has none, `FEMDiscretization(Ω)`, for a nonlinear solver such as `NewtonRaphson`. Both carry the sparse analytic Jacobian and its prototype, so `solve(prob, alg)` needs nothing -else. `NonlinearProblem(pdesys, disc)` builds the steady problem directly; the corresponding -`DAEProblem(pdesys, disc)` is deprecated in favour of `discretize`. +else. `NonlinearProblem(pdesys, disc)` and `DAEProblem(pdesys, disc)` are deprecated in favour of +`discretize`. ## Keywords diff --git a/src/discretization.jl b/src/discretization.jl index adfedaac..b8cdcdf8 100644 --- a/src/discretization.jl +++ b/src/discretization.jl @@ -13,7 +13,7 @@ Finite-element discretization of a `PDESystem` whose spatial domain is the mesh (of a `Ferrite.Grid`), with time variable `t`. `discretize(pdesys, disc)` assembles the Galerkin operators with Ferrite and returns a `DAEProblem` with one array unknown per field. Without `t` the discretization is steady: the `PDESystem` must have no time variable, and -`discretize` (or `NonlinearProblem(pdesys, disc)`) returns a `NonlinearProblem` whose `solve` +`discretize` returns a `NonlinearProblem` whose `solve` gives a `PDENoTimeSolution`. - `spaces`: dependent variable (`u` or `u(t, x, y)`) `=>` `Ferrite.Interpolation`; the @@ -75,7 +75,7 @@ gives a `PDENoTimeSolution`. `sol(t, x, y)`, traces and `write_vtk`; only `sol.original_sol` and the array unknowns hold the free dofs alone. `:algebraic` is recommended. - `codegen = :mtk` is reserved and raises; remaining keywords are - passed to the `DAEProblem` (or `NonlinearProblem`), where a keyword given at the + passed to the `DAEProblem` (or the steady `NonlinearProblem`), where a keyword given at the `discretize` call wins. `iv`, `unknowns`, `du0`, `coordinate`, `name` and `parameters` are set by the discretization and rejected, as are `tspan`, `u0`, `p` and `differential_vars`, which come from the `PDESystem` and the weak form. diff --git a/src/frontend.jl b/src/frontend.jl index ff2a36f9..67410165 100644 --- a/src/frontend.jl +++ b/src/frontend.jl @@ -536,13 +536,15 @@ _daeproblem(pdesys, disc; kwargs...) = throw( ArgumentError( "the FEMDiscretization has no time variable, so it lowers to a NonlinearProblem, not a DAEProblem; " * - "call discretize(pdesys, disc) or NonlinearProblem(pdesys, disc)" + "call discretize(pdesys, disc)" ) ) : SciMLBase.discretize(pdesys, disc; kwargs...) """ NonlinearProblem(pdesys::PDESystem, disc::FEMDiscretization; kwargs...) +Deprecated: use `discretize(pdesys, disc; kwargs...)`, which returns the same problem. + Discretize the steady `pdesys` with a `disc` that has no time variable and return the `NonlinearProblem` `K u + N(u) - F = 0` of the Galerkin operators, with Dirichlet rows `u_d - g_d` as algebraic equations, the sparse analytic Jacobian `K + ∂N/∂u` and the @@ -560,6 +562,11 @@ Keywords are passed to the `NonlinearProblem` after `disc.kwargs`; the keywords `differential_vars` are rejected, as for the `DAEProblem`. """ function SciMLBase.NonlinearProblem(pdesys::ModelingToolkit.PDESystem, disc::FEMDiscretization; kwargs...) + Base.depwarn("`NonlinearProblem(pdesys, disc)` is deprecated, use `discretize(pdesys, disc)` instead", :NonlinearProblem) + return _nonlinearproblem(pdesys, disc; kwargs...) +end + +function _nonlinearproblem(pdesys, disc; kwargs...) disc.time === nothing || throw( ArgumentError( "the FEMDiscretization has the time variable $(disc.time), so it lowers to a DAEProblem; " * diff --git a/test/shared/frontend_tests/arguments.jl b/test/shared/frontend_tests/arguments.jl index 36c3df16..dfa21780 100644 --- a/test/shared/frontend_tests/arguments.jl +++ b/test/shared/frontend_tests/arguments.jl @@ -72,7 +72,6 @@ const DERIVED_VALUES = (tspan = (0.0, 2.0), u0 = zeros(9), p = [1.0], differenti @test_throws ArgumentError(DERIVED_MESSAGES.tspan) FEMDiscretization(Ω, t; tspan = (0.0, 2.0)) @test_throws ArgumentError(DERIVED_MESSAGES.p) FEMDiscretization(Ω; p = [1.0]) steady = poisson_system(Ω) - @test_throws ArgumentError(DERIVED_MESSAGES.u0) SciMLBase.NonlinearProblem(steady, FEMDiscretization(Ω); u0 = zeros(9)) @test_throws ArgumentError(DERIVED_MESSAGES.u0) discretize(steady, FEMDiscretization(Ω); u0 = zeros(9)) end diff --git a/test/shared/frontend_tests/end_to_end.jl b/test/shared/frontend_tests/end_to_end.jl index 9ed7d7f5..201fd916 100644 --- a/test/shared/frontend_tests/end_to_end.jl +++ b/test/shared/frontend_tests/end_to_end.jl @@ -100,6 +100,23 @@ dirichlet_all(Ω) = [u(t, Γ) ~ (1 + x + 2y) * (1 + t) for Γ in pieces(Ω)] end end + @testset "NonlinearProblem(pdesys, disc) is deprecated in favour of discretize" begin + Ω = MeshDomain(rectangle_grid(Triangle, (2, 2))) + @named steady = PDESystem([Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in boundarypiece.(Ω, (:left, :right, :bottom, :top))], [(x, y) ∈ Ω], [x, y], [u(x, y)], []) + disc = FEMDiscretization(Ω; abstol = 1.0e-12) + @test_deprecated r"discretize" SciMLBase.NonlinearProblem(steady, disc) + old = with_logger(NullLogger()) do + SciMLBase.NonlinearProblem(steady, disc) + end + new = discretize(steady, disc) + @test old isa SciMLBase.NonlinearProblem + @test old.u0 == new.u0 && old.kwargs == new.kwargs + @named pdesys = PDESystem([heat_eq], [dirichlet_all(Ω); ic], [(x, y) ∈ Ω, t ∈ Interval(0.0, 1.0)], [t, x, y], [u(t, x, y)], []) + with_logger(NullLogger()) do + @test_throws "the FEMDiscretization has the time variable t, so it lowers to a DAEProblem" SciMLBase.NonlinearProblem(pdesys, FEMDiscretization(Ω, t)) + end + end + @testset "PDESystem without parameters" begin # Leaving out `ps` gives the system `NullParameters()`, which means no parameters. Ω = MeshDomain(rectangle_grid(Triangle, (4, 4))) diff --git a/test/shared/frontend_tests/errors.jl b/test/shared/frontend_tests/errors.jl index 3cefde9a..43d35b84 100644 --- a/test/shared/frontend_tests/errors.jl +++ b/test/shared/frontend_tests/errors.jl @@ -102,10 +102,6 @@ dirichlet(Ω) = [u(t, Γ) ~ 0 for Γ in sides(Ω)] [Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in sides(Ω)], [(x, y) ∈ Ω], [x, y], [u(x, y)], [] ) @named transient = PDESystem([heat], [dirichlet(Ω); ic], [(x, y) ∈ Ω, t ∈ Interval(0.0, 1.0)], [t, x, y], [u(t, x, y)], []) - @test_throws ArgumentError( - "the FEMDiscretization has the time variable t, so it lowers to a DAEProblem; " * - "for a steady problem write FEMDiscretization(Ω) without a time variable" - ) SciMLBase.NonlinearProblem(transient, FEMDiscretization(Ω, t)) @test_throws ArgumentError( "the PDESystem pairs t with an interval, but the FEMDiscretization has no time variable; " * "for a time-dependent problem write FEMDiscretization(Ω, t)" diff --git a/test/shared/frontend_tests/steady.jl b/test/shared/frontend_tests/steady.jl index bb25e52d..cd492172 100644 --- a/test/shared/frontend_tests/steady.jl +++ b/test/shared/frontend_tests/steady.jl @@ -109,7 +109,6 @@ end prob = discretize(pdesys, FEMDiscretization(Ω; abstol = 1.0e-12)) @test prob isa SciMLBase.NonlinearProblem @test prob.kwargs[:abstol] == 1.0e-12 - @test SciMLBase.NonlinearProblem(pdesys, FEMDiscretization(Ω)).u0 == prob.u0 # The initial guess is zero except on the Dirichlet dofs, which hold the data. space = prob.problem_type.space pd = space.ch.prescribed_dofs diff --git a/test/shared/frontend_tests/symbolic.jl b/test/shared/frontend_tests/symbolic.jl index 61bd025a..ed7f72f9 100644 --- a/test/shared/frontend_tests/symbolic.jl +++ b/test/shared/frontend_tests/symbolic.jl @@ -60,7 +60,7 @@ const Dt, Dx, Dy = Differential(t), Differential(x), Differential(y) @named steady = PDESystem( [Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) ~ 0], [u(Γ) ~ 0 for Γ in sides], [(x, y) ∈ Ω], [x, y], [u(x, y)], [] ) - @test NonlinearProblem(steady, FEMDiscretization(Ω)).f.sys === nothing + @test discretize(steady, FEMDiscretization(Ω)).f.sys === nothing @test_throws ArgumentError( "a steady FEMDiscretization builds no symbolic System, so it has no symbolic_discretize; " * "call discretize(pdesys, disc) for its NonlinearProblem"