Skip to content
Open
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
76 changes: 70 additions & 6 deletions docs/src/boundary_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rendering.
| Dirichlet | yes |
| Neumann | yes |
| Robin | yes |
| Periodic | no |
| Periodic | yes |
| Interface | no |
| Time-dependent | yes |

Expand All @@ -28,7 +28,7 @@ Restrictions of this release:
- Geometries are `Ferrite.Grid` meshes (1D, 2D and 3D cell shapes) wrapped as `MeshDomain(grid)`, with boundary pieces named by the grid's facet sets. 1D, 2D and 3D meshes are tested; meshes with mixed cell types are rejected.
- Coordinates are Cartesian and named by the `(x, y) ∈ Ω` pairing. Time is the first or last argument of every dependent variable, never between spatial arguments.
- Dirichlet data may depend on space, time and parameters but not on another field. Neumann and Robin conditions are written with `NormalDerivative(Γ)`, with any conormal coefficient written explicitly. Neumann and Robin data may depend on time; the Robin coefficient multiplying `u(t, Γ)` may depend only on space and parameters.
- Periodic conditions `u(t, Γa) ~ u(t, Γb)` are rejected. Interface conditions between regions have no syntax; every field lives on the whole mesh.
- Periodic conditions `u(t, Γa) ~ u(t, Γb)` pair two pieces that are translates of each other; they need `dirichlet = :algebraic` and are not returned by `operators`. Interface conditions between regions have no syntax; every field lives on the whole mesh.
- Boundary pieces must be disjoint and lie on the boundary. Boundary facets with no condition for a field get the natural zero-flux condition, with a warning when that field's equation has a flux; `natural` declares them and `boundary_check` makes the warning an error or turns it off.
- Where two Dirichlet pieces of one field meet, the condition listed last in the `PDESystem` wins.
- Every field with a time derivative needs an initial condition, linear in that one field and finite at every node.
Expand Down Expand Up @@ -140,9 +140,71 @@ Like a Neumann condition, it enters the weak form as a facet integral.

## Periodic conditions

Not supported in this release. An equation between traces on two pieces,
`u(t, Γ_left) ~ u(t, Γ_right)`, is rejected with
`periodic boundary conditions are not supported`.
An equation between the traces of one field on two pieces, `u(t, Γ_left) ~ u(t, Γ_right)` (or
`u(Γ_left) ~ u(Γ_right)` for a steady problem), makes the field take equal values on the two
pieces. The pieces must be translates of each other: the translation is the difference of their
centroids, and every node of one piece (every dof of the field, for a higher-order space) must
have a node of the other at the translated place. Otherwise `discretize` throws an `ArgumentError`
that names both pieces and the mismatch. The pairs are per field, so one field may be periodic
where another carries Dirichlet pieces, and they work with any element space, including the
Taylor–Hood pair of a Navier–Stokes system, in the time-dependent and steady paths and with
`SUPG` test spaces.

For a fully periodic box write one pair per direction. A corner node belongs to several pairs;
the nodes of all pairs of a field are collected into classes of equal nodes, and each class keeps
one master. Where a periodic piece meets a Dirichlet piece, the class contains a prescribed node
and that node is the master, so the Dirichlet value holds at the shared corner. If a class holds more than one
prescribed node (a Dirichlet piece touching both ends of a periodic pair), their data must agree. `discretize` compares them at 17 evenly spaced times of the time interval, and
time-dependent data are compared again at every evaluation by the solver; a difference beyond a relative `1e-8` is an
`ArgumentError` naming the periodic pieces, the nodes, the two values and the time.

```julia
using FiniteElementMethod, ModelingToolkit, DomainSets, OrdinaryDiffEqBDF
using Ferrite: generate_grid, Triangle, Vec
using ModelingToolkit: t_nounits as t
@variables x y u(..)
Dt, Dx, Dy = Differential(t), Differential(x), Differential(y)

Ω = MeshDomain(generate_grid(Triangle, (16, 16), Vec(0.0, 0.0), Vec(1.0, 1.0)))
left, right, bottom, top = boundarypiece.(Ω, (:left, :right, :bottom, :top))
@named pdesys = PDESystem(
[Dt(u(t, x, y)) ~ Dx(Dx(u(t, x, y))) + Dy(Dy(u(t, x, y)))],
[u(t, left) ~ u(t, right), u(t, bottom) ~ u(t, top), u(0, x, y) ~ sin(2π * (x + y))],
[(x, y) ∈ Ω, t ∈ Interval(0.0, 0.05)], [t, x, y], [u(t, x, y)], [])
prob = discretize(pdesys, FEMDiscretization(Ω, t))
```

The solution is `exp(-8π² t) sin(2π (x + y))` and converges at the optimal rate;
`test/Interface/periodic.jl` runs this case, the steady and Navier–Stokes ones.

Periodic pairs work in every problem class of this package, including nonlinear terms (the
nonlinear residual and Jacobian get the same row sums and ties inside Newton's method), SUPG test
spaces, steady and transient problems and coupled fields with different spaces:

| Problem class with a periodic pair | Status | Covered by |
|:--- |:--- |:--- |
| Scalar linear, transient, 2D, P1 and P2, triangles and quadrilaterals, fully periodic | supported | `test/Interface/periodic.jl`, heat on a periodic box |
| Periodic in one direction with Dirichlet pieces in the other | supported | `test/Interface/periodic.jl`, periodic in x |
| Scalar linear on a line, transient, Galerkin and SUPG | supported | `test/Interface/periodic.jl`, periodic line |
| Scalar linear on a hexahedral mesh, steady, fully periodic | supported | `test/Interface/periodic.jl`, periodic cube |
| Steady (`NonlinearProblem`), linear terms, Galerkin and SUPG | supported | `test/Interface/periodic.jl`, steady advection–diffusion |
| Steady, nonlinear terms | supported | `test/Interface/periodic.jl`, steady nonlinear diffusion |
| Transient (`DAEProblem`), nonlinear terms and a time-dependent source | supported | `test/Interface/periodic.jl`, viscous Burgers |
| Coupled fields, different spaces per field, per-field pairs | supported | `test/Interface/periodic.jl`, coupled P2/P1 |
| Taylor–Hood Navier–Stokes, steady and transient (index-2 DAE) | supported | `test/Interface/periodic_navier_stokes.jl` |
| Boundary integrals (Neumann, Robin) on the other, non-periodic pieces | supported | assembled as before; the periodic pieces take no boundary integral |
| Pieces that are not translates of each other | error `periodic pieces Γa and Γb of u do not match under a translation: …` | `test/Interface/periodic.jl`, rejected pairs |
| A periodic piece that also carries another condition for that field | error `… has a periodic condition on Γ and a Dirichlet condition on the same piece` | same |
| `dirichlet = :eliminate`, or `operators` | error `… does not support periodic conditions …` | same |
| A space that is not a scalar Lagrange space (edge elements need orientation signs across the map) | error `… is not a nodal Lagrange space; periodic conditions are supported for scalar Lagrange spaces only …` | same, edge-element case |

The operators keep every dof as an unknown. Each node of a class other than its master is tied
to it by an algebraic row `u_node − u_master = 0`, and the Galerkin equation of the tied node is
added to its master's, which is the condensed system `PᵀKP` of the identification. No boundary
integral is assembled on a periodic piece, since the two contributions cancel for a periodic
solution. The initial value of a tied node is its master's. A piece of a periodic pair cannot
also carry a Dirichlet, Neumann or Robin condition for that field. `dirichlet = :eliminate` and
[`operators`](@ref FiniteElementMethod.operators) do not support periodic conditions.

## Interface conditions

Expand Down Expand Up @@ -188,7 +250,9 @@ is an error that names the problem; nothing falls back to `mtkcompile`.
| A time-dependent Robin coefficient, such as `Dn(u(t, Γ)) + (1 + t) * u(t, Γ) ~ 0` | error |
| `FEMDiscretization(…; codegen = :mtk)` | error |
| A mesh with mixed cell types | error |
| A periodic condition `u(t, Γa) ~ u(t, Γb)` | error |
| A periodic condition `u(t, Γa) ~ u(t, Γb)` between pieces that are not translates of each other | error naming both pieces |
| A periodic piece that also carries a Dirichlet, Neumann or Robin condition for that field | error |
| A periodic condition with `dirichlet = :eliminate`, or in `operators` | error |
| A time argument between spatial arguments, such as `u(x, t, y)` | error |
| Two Dirichlet pieces of one field sharing nodes | the condition listed last wins |
| Boundary facets with no condition for a field | natural zero-flux condition, with one warning per `discretize` call when that field's equation has a flux; `natural` declares them, `boundary_check = :error` or `:off` |
Expand Down
5 changes: 4 additions & 1 deletion docs/src/equation_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ mesh domain, no second time derivative, no integral term, nothing in 3D and noth
| 1 | Nonlinear through state-dependent coefficients and sources: `k(u)`, `f(u)`, viscous Burgers | `k = 1+u²` rates 1.71–1.94 (report 5, red cell); `burgers_2d` two-field, rates 2.26, 2.43 (report 6) | VERIFIED |
| 1 | Convection–diffusion at moderate cell Péclet number | `convdiff2` rates 2.01, 2.00 against MethodOfLines' 4.75e-2, 2.54e-2, 1.32e-2 (rate about 1) (report 6) | VERIFIED |
| 1 | Curvilinear radial Laplacians through the product rule | `sph`, `4/r² ∂ᵣ(r² ∂ᵣu)`, rate 2.00 on four refinements (report 6) | VERIFIED |
| 1 | Periodic conditions `u(t, Γa) ~ u(t, Γb)` between translated boundary pieces, in one or both directions, scalar or coupled fields with different spaces | `test/Interface/periodic.jl`: the heat equation on a fully periodic box follows its Fourier mode at rate 2 (P1) and 3 (P2); periodic in x with Dirichlet in y; steady periodic advection–diffusion at rate 2, with Galerkin and `SUPG`; two coupled fields; `test/Interface/periodic_navier_stokes.jl`: Kovasznay flow with periodic bottom and top at rates 3 and 2, and a Q2/Q1 channel flow past a block, periodic in the cross-stream direction, that conserves mass to 1e-3 | VERIFIED; the library corpus has no periodic system solved by this package |
| 1 | Dirichlet (constant and time-dependent), Neumann, Robin | time-dependent Dirichlet in `burgers_2d` and all `funcconv`; Neumann in `pdesys`, `sph` (report 6); Robin in cases (i), (ii) and the 2D DAE prototype (reports 5, 4) | VERIFIED; Robin from reports 4–5 only |
| 1 | 1D and 2D on boxes | `Line` and `Quadrilateral` grids end to end (report 6); 2D DAE with three condition kinds (report 4); two-field P1/P2 solution interface (report 7) | VERIFIED |
| 1 | Unstructured and Gmsh meshes | pieces resolved to facet sets on an L-shaped Ferrite grid and a Gmsh import probed (reports 2, 4); the API example of [Getting started](@ref) then solves on a Gmsh L-shape | VERIFIED |
| 1 | Mixed saddle-point problems with an inf-sup-stable unequal-order pair chosen by the user: Stokes and incompressible Navier–Stokes with Taylor–Hood Q2/Q1 or P2/P1 | DFG 2D-1 cylinder through the PDESystem front end (#31; test group NavierStokes, test/NavierStokes/dfg_cylinder.jl): tolerance stated before the runs = Schäfer–Turek intervals cD ∈ [5.57, 5.59], cL ∈ [0.0104, 0.0110], Δp ∈ [0.1172, 0.1176]; 16 430 unknowns give cD 5.579436, cL 0.010583, Δp 0.117584 and agree with an independent hand-written Ferrite solver on the same mesh to 1e-7; 148 986 unknowns: relative errors −4.5e-7, −5.1e-6, −5.3e-5 (benchmark (d)); Taylor–Hood Stokes rates 3 and 2 (#28) | VERIFIED for the example's formulation: continuity paired with p explicitly, pressure pinned on a boundary piece, outflow ν∂ₙu = 0, index-2 DAE started from rest; no inf-sup check is made, the user chooses a stable pair |
| 2, accepted; unreliable with Galerkin testing, use `SUPG(τ)` | Pure advection, advection-dominated problems, inviscid hyperbolic problems | `inviscid_burgers_monotonic` exact to 1e-10 only because its solution lies in the P1 space, so it says nothing about shocks or steep fronts; `convdiff4` at cell Péclet > 1 dropped to rate 1.44 on the coarse mesh (report 6) | VERIFIED limitation |
| 3, rejected with a clean error | Periodic conditions; mixed cell types; third- and fourth-order spatial operators; `∂ₜ²` (write a first-order system); integral terms; state-dependent mass; non-conormal natural conditions | Appendix A messages; 16 library rejections all periodic, 7 of them also higher order (report 6) | VERIFIED |
| 3, rejected with a clean error | Mixed cell types; third- and fourth-order spatial operators; `∂ₜ²` (write a first-order system); integral terms; state-dependent mass; non-conormal natural conditions | Appendix A messages; the 16 library rejections of report 6 were all periodic, 7 of them also higher order, and the periodic ones are now supported (see the periodic row above) | VERIFIED |
| not evidenced | discontinuous coefficients across interfaces | nothing in any corpus or prototype | neither claimed nor rejected |

The periodic row was added when periodic conditions were implemented; the specification table lists them in the rejected class.

The "Unstructured and Gmsh meshes" row's solve on a Gmsh mesh is the API example of
[Getting started](@ref), which the test suite runs (`test/Frontend/api_example.jl`).

Expand Down
2 changes: 1 addition & 1 deletion docs/src/extension_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The checks include:
- equations: an equation count that differs from the number of dependent variables, unknown
`pairing`, `spaces` or `regions` keys, time-dependent mass or stiffness coefficients,
parameters without a numeric value, SUPG with parameters in `τ` or `b`;
- boundary conditions: periodic conditions, conditions on facet sets the mesh lacks, a
- boundary conditions: periodic pieces that are not translates of each other or that carry another condition, conditions on facet sets the mesh lacks, a
region's field with conditions outside the region, time-dependent Dirichlet data with
`dirichlet = :eliminate`.

Expand Down
3 changes: 1 addition & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on a mesh, derives the Galerkin weak form, assembles it with
!!! warning
This package is under construction. Problems with Galerkin or SUPG testing are supported,
including nonlinear terms whose state dependence is in the coefficients, sources and
natural conditions (`∇·((1 + u²)∇u)`, `u ∂ₓu`, `u²`, `∂ₙu = −u⁴`); periodic
conditions and time-dependent mass or stiffness coefficients raise an error. [Boundary conditions and limitations](@ref) lists every restriction.
natural conditions (`∇·((1 + u²)∇u)`, `u ∂ₓu`, `u²`, `∂ₙu = −u⁴`); time-dependent mass or stiffness coefficients raise an error. [Boundary conditions and limitations](@ref) lists every restriction.

[Getting started](@ref) solves a heat equation on a Gmsh mesh. A MethodOfLines user should
then read [Differences from MethodOfLines](@ref): coordinates are bound differently, boundary
Expand Down
5 changes: 3 additions & 2 deletions src/FiniteElementMethod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using DiffEqBase: BrownFullBasicInit
using DomainSets: DomainSets
using Ferrite: Ferrite, Lagrange, RefLine, RefTriangle, RefQuadrilateral, RefTetrahedron, RefHexahedron
using ForwardDiff: ForwardDiff
using LinearAlgebra: dot, mul!, norm
using LinearAlgebra: I, dot, mul!, norm
using ModelingToolkit: ModelingToolkit, @parameters, @variables, Differential, MTKParameters,
ProblemTypeCtx, System, complete, getmetadata
using NonlinearSolveFirstOrder: NewtonRaphson
Expand All @@ -22,7 +22,7 @@ using PrecompileTools: PrecompileTools
using RuntimeGeneratedFunctions: RuntimeGeneratedFunctions
using SciMLBase: SciMLBase, DAEFunction, DAEProblem
using SciMLBase.SymbolicIndexingInterface: SymbolicIndexingInterface, getp, parameter_index, variable_index
using SparseArrays: SparseMatrixCSC, nonzeros, nzrange, rowvals
using SparseArrays: SparseMatrixCSC, findnz, nonzeros, nzrange, rowvals, sparse
using SymbolicUtils: SymbolicUtils
using Symbolics: Symbolics, Equation, Num, @register_array_symbolic, substitute, unwrap

Expand All @@ -32,6 +32,7 @@ RuntimeGeneratedFunctions.init(@__MODULE__)
include("numeric_dae.jl")

include("mesh.jl")
include("periodic.jl")
include("space.jl")
include("solution.jl")
include("weakform.jl")
Expand Down
9 changes: 7 additions & 2 deletions src/discretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ gives a `PDENoTimeSolution`.
by the discretization and rejected, as are `tspan`, `u0`, `p` and `differential_vars`, which
come from the `PDESystem` and the weak form.

A periodic condition `u(t, Γa) ~ u(t, Γb)` (`u(Γa) ~ u(Γb)` without time) makes the field `u` take equal values at
the nodes of two boundary pieces that are translates of each other; pieces that are not are an error naming
them. Fully periodic domains list one pair per direction, and a node shared by several pairs is tied to one master.
See the documentation page on boundary conditions for the algebraic form.

Pieces come from `boundarypiece.(Ω, names)`; on an analytic DomainSets box write
`boundarypiece.(Ref(rect), names)`, since DomainSets types do not broadcast as scalars.

Expand Down Expand Up @@ -195,15 +200,15 @@ end
# it on the Discretization page and docs/src/boundary_conditions.md keeps a static copy;
# test/Frontend/documentation.jl keeps the two equal.
PDEBase.supported_conditions(::FEMDiscretization) = PDEBase.SupportedConditions(;
geometries = (:mesh,), dirichlet = true, neumann = true, robin = true, periodic = false,
geometries = (:mesh,), dirichlet = true, neumann = true, robin = true, periodic = true,
interface = false, time_dependent = true,
notes = """
Restrictions of this release:

- Geometries are `Ferrite.Grid` meshes (1D, 2D and 3D cell shapes) wrapped as `MeshDomain(grid)`, with boundary pieces named by the grid's facet sets. 1D, 2D and 3D meshes are tested; meshes with mixed cell types are rejected.
- Coordinates are Cartesian and named by the `(x, y) ∈ Ω` pairing. Time is the first or last argument of every dependent variable, never between spatial arguments.
- Dirichlet data may depend on space, time and parameters but not on another field. Neumann and Robin conditions are written with `NormalDerivative(Γ)`, with any conormal coefficient written explicitly. Neumann and Robin data may depend on time; the Robin coefficient multiplying `u(t, Γ)` may depend only on space and parameters.
- Periodic conditions `u(t, Γa) ~ u(t, Γb)` are rejected. Interface conditions between regions have no syntax; every field lives on the whole mesh.
- Periodic conditions `u(t, Γa) ~ u(t, Γb)` pair two pieces that are translates of each other; they need `dirichlet = :algebraic` and are not returned by `operators`. Interface conditions between regions have no syntax; every field lives on the whole mesh.
- Boundary pieces must be disjoint and lie on the boundary. Boundary facets with no condition for a field get the natural zero-flux condition, with a warning when that field's equation has a flux; `natural` declares them and `boundary_check` makes the warning an error or turns it off.
- Where two Dirichlet pieces of one field meet, the condition listed last in the `PDESystem` wins.
- Every field with a time derivative needs an initial condition, linear in that one field and finite at every node.
Expand Down
Loading
Loading