Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions src/frontend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,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)
Expand Down
6 changes: 3 additions & 3 deletions test/Integration/linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down
2 changes: 1 addition & 1 deletion test/shared/frontend_tests/errors.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/shared/frontend_tests/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, natural = [:top, :bottom])
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))
Expand Down Expand Up @@ -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; natural = [:right, :top, :bottom]))))
@test_throws "operators returns linear operators only" FiniteElementMethod.operators(
heat_system(Ω, [u(t, left) ~ 0]; eq = nonlinear), FEMDiscretization(Ω, t; natural = [:right, :top, :bottom])
)
@test occursin("constant in time", msg(() -> FiniteElementMethod.operators(heat_system(Ω, [u(t, left) ~ sin(t)]), FEMDiscretization(Ω, t; natural = [:right, :top, :bottom]))))
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; natural = [:right, :top, :bottom]))))
Expand Down
5 changes: 2 additions & 3 deletions test/shared/molcomparison_tests/mol_comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading