Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
2830673
Support time-last dependent variables in the front end and solution w…
xtalax Oct 27, 2026
53d316a
Evaluate observed expressions with sol[expr] and sol(t, xs...; dv = e…
xtalax Oct 27, 2026
49b0436
Skip observed expressions at points outside the mesh and return float…
xtalax Oct 27, 2026
196682a
Discretize steady PDESystems to a NonlinearProblem
xtalax Oct 27, 2026
54328ba
Split a quotient over its numerator when classifying weak-form terms
xtalax Oct 27, 2026
602ce47
Test P2 on a curved second-order Gmsh mesh through the front end
xtalax Oct 27, 2026
2e4a793
Implement dirichlet = :eliminate on the numeric path
xtalax Oct 27, 2026
35c99dc
Leave fully prescribed fields out of the eliminated system
xtalax Oct 27, 2026
40e3ff5
Treat a PDESystem without parameters as having none
xtalax Oct 27, 2026
72a6ef9
Accept nonlinear terms on the numeric DAE path
xtalax Oct 27, 2026
fb605f8
Merge #28 (forge/m4-6-multifield-supg) into the nonlinear branch for …
xtalax Oct 27, 2026
76a07fe
Add the DFG cylinder mesh, force functional and Ferrite reference solver
xtalax Oct 27, 2026
9f2e557
Add the DFG 2D-1 Navier–Stokes cylinder example and its test group
xtalax Oct 27, 2026
e981ce4
Add benchmark (d): Navier–Stokes cylinder against Ferrite's ns_vs_diffeq
xtalax Oct 27, 2026
3b33d71
Make a DFG solve that stops early fail loudly
xtalax Oct 27, 2026
d0f62db
Reject derivatives of a dependent variable at fixed arguments
xtalax Oct 27, 2026
2513c03
Evaluate the nonlinear operator on Dual states and per concurrent call
xtalax Oct 27, 2026
ddb4ac1
Time one discrete problem on both sides of benchmark (d); fail on ear…
xtalax Oct 27, 2026
da356a4
Set the abstol of algebraic rows of index-2 systems in FEMDiscretization
xtalax Oct 27, 2026
5766069
Check the arguments of every dependent variable the solution looks up…
xtalax Oct 27, 2026
9b00be3
Allow ForwardDiff's Dual API in the QA public-access check
xtalax Oct 27, 2026
3e97b6a
Merge #23 (time-last) into observed expressions
xtalax Oct 27, 2026
b36fc78
Test and document observed expressions on time-last fields
xtalax Oct 27, 2026
86c3b53
Reject nonlinear states other than Float64 and Dual{Float64} up front
xtalax Oct 27, 2026
7cd2781
Merge #30 (forge/m4-8-nonlinear, Codex fixes) into the DFG branch
xtalax Oct 27, 2026
cd2fe27
Merge #28 (forge/m4-6-multifield-supg, QA fix) into the DFG branch
xtalax Oct 27, 2026
20f8e47
Write the full steady state in write_vtk; describe u0 by the problem'…
xtalax Oct 27, 2026
527bfc2
Say why the DFG example keeps CheckInit after #30
xtalax Oct 27, 2026
a6456d3
Treat a PDESystem without parameters as having none in observed expre…
xtalax Oct 27, 2026
6ea30b1
Give the force functional the integrator's final derivative
xtalax Oct 27, 2026
6182a0d
Merge #24 (steady) into nonlinear terms
xtalax Oct 27, 2026
1a1586b
Merge #25 (eliminate) into nonlinear terms
xtalax Oct 27, 2026
91e85a5
Merge #24 (steady) into algebraic_abstol
xtalax Oct 27, 2026
4992114
Reject an explicit algebraic_abstol on a steady FEMDiscretization
xtalax Oct 27, 2026
962ee72
Solve steady problems with their nonlinear terms
xtalax Oct 27, 2026
a9ffb81
Keep nonlinear terms under dirichlet = :eliminate
xtalax Oct 27, 2026
ec17480
Merge #30 (steady/eliminate nonlinear) into the DFG example
xtalax Oct 27, 2026
81a192a
Merge #31 (DFG; contains #30, #28, #24, #25) into algebraic_abstol
xtalax Oct 27, 2026
e0d9c35
Count a nonlinear term in a field as presence in the algebraic_abstol…
xtalax Oct 27, 2026
02dfb04
Say what is unsupported instead of citing milestones in error messages
xtalax Oct 27, 2026
7843a72
Make symbolic_discretize a documented contract that forwards keywords
xtalax Oct 27, 2026
a1bee54
Reject derived keywords, extra positionals and non-PDESystems in disc…
xtalax Oct 27, 2026
cad8b27
Merge #36 (milestone-free messages) into the docs branch
xtalax Oct 27, 2026
1b5d4f9
Merge #37 (reserved/derived keywords, discretize argument errors) int…
xtalax Oct 27, 2026
6f667e5
Document discretize and how FEMDiscretization meets SciMLBase's exten…
xtalax Oct 27, 2026
d5a6070
Document AbstractTestSpace and Galerkin on the always-built API page
xtalax Oct 28, 2026
9404059
Merge upstream/forge/m4-base into forge/m4-2-steady
xtalax Oct 28, 2026
c7aedad
Merge upstream/master into forge/m4-base-to-master
xtalax Oct 29, 2026
720b022
Merge forge/m4-base-to-master into forge/m4-3-timelast
xtalax Oct 29, 2026
68d3cde
Merge chain/23 into forge/m4-2-steady
xtalax Oct 29, 2026
fae054a
Merge chain/24 into forge/m4-9-nullparams
xtalax Oct 29, 2026
79d8dc9
Merge chain/27 into forge/m4-1-eliminate
xtalax Oct 29, 2026
a1e1e63
Merge chain/25 into forge/m4-8-nonlinear
xtalax Oct 29, 2026
fb0a559
Merge chain/30 into forge/m4-5-curved-p2
xtalax Oct 29, 2026
b7a8aaf
Merge chain/26 into forge/m4-4-observed
xtalax Oct 29, 2026
23f7e18
Merge chain/29 into forge/m4-6-multifield-supg
xtalax Oct 29, 2026
c02e38f
Merge chain/28 into forge/m4-7-dfg-cylinder
xtalax Oct 29, 2026
d292845
Merge chain/31 into forge/m4-10-algebraic-abstol
xtalax Oct 29, 2026
2807c66
Merge chain/32 into forge/ctr-2-symbolic
xtalax Oct 29, 2026
0026071
Merge chain/34 into forge/ctr-4-messages
xtalax Oct 29, 2026
6199c5d
Merge chain/36 into forge/ctr-3-kwargs
xtalax Oct 29, 2026
981a904
Merge chain/37 into forge/ctr-1-docs
xtalax Oct 29, 2026
9902088
Give the quarter-annulus test its box so its left and bottom conditio…
xtalax Nov 1, 2026
bb5dba7
Add facet_dofs, dof_coordinates and cell_dofs on FEMMetadata
xtalax Oct 28, 2026
de26311
Fix facet_dofs on a field absent from the facet set and cell_dofs on …
xtalax Nov 2, 2026
115925a
Add operators(pdesys, disc): the assembled operators as plain data
xtalax Oct 28, 2026
4ac0bd7
Merge upstream/master into forge/m4-base-to-master
xtalax Nov 2, 2026
dd79725
Merge forge/m4-base-to-master into chain/23
xtalax Nov 2, 2026
2321be0
Merge chain/23 into chain/24
xtalax Nov 2, 2026
0f3c84f
Merge chain/24 into chain/27
xtalax Nov 2, 2026
024d118
Merge chain/27 into chain/25
xtalax Nov 2, 2026
e78dc9b
Merge chain/25 into chain/30
xtalax Nov 2, 2026
d96a3bf
Merge chain/30 into chain/26
xtalax Nov 2, 2026
e2aaecd
Merge chain/26 into chain/29
xtalax Nov 2, 2026
b1d0d7c
Merge chain/29 into chain/28
xtalax Nov 2, 2026
6015939
Merge chain/28 into chain/31
xtalax Nov 2, 2026
7164007
Merge chain/31 into chain/32
xtalax Nov 2, 2026
d900744
Merge chain/32 into chain/34
xtalax Nov 2, 2026
db6121c
Merge chain/34 into chain/36
xtalax Nov 2, 2026
4c076a6
Merge chain/36 into chain/37
xtalax Nov 2, 2026
a3910ad
Merge chain/37 into chain/38
xtalax Nov 2, 2026
60fff68
Merge chain/23 into chain/24
xtalax Nov 2, 2026
ddb9faf
Remove the MESH_PDEBASE gate from the time-last wrapper and update th…
xtalax Nov 2, 2026
9f7ef14
Remove the MESH_PDEBASE gate from the steady wrapper and update the r…
xtalax Nov 2, 2026
74d06fc
Merge chain/24 into chain/27
xtalax Nov 2, 2026
7ccab20
Merge chain/27 into chain/25
xtalax Nov 2, 2026
98bc3da
Merge chain/25 into chain/30
xtalax Nov 2, 2026
19f339b
Remove the MESH_PDEBASE gate from the eliminate wrapper and update th…
xtalax Nov 2, 2026
a2e63b3
Merge chain/30 into chain/26
xtalax Nov 2, 2026
c08da8d
Remove the MESH_PDEBASE gate from the nonlinear wrapper and update th…
xtalax Nov 2, 2026
3c03336
Merge chain/26 into chain/29
xtalax Nov 2, 2026
be895f5
Remove the MESH_PDEBASE gate from the curved-mesh wrapper
xtalax Nov 2, 2026
6dce012
Merge chain/29 into chain/28
xtalax Nov 2, 2026
1f7f953
Remove the MESH_PDEBASE gate from the observed wrapper
xtalax Nov 2, 2026
99b2d8a
Merge chain/28 into chain/31
xtalax Nov 2, 2026
0529b71
Update the restriction notes for multi-field systems and SUPG
xtalax Nov 2, 2026
14168ff
Remove the MESH_PDEBASE gate from the DFG cylinder test
xtalax Nov 2, 2026
88c0769
Merge chain/31 into chain/32
xtalax Nov 2, 2026
76e65e7
Merge chain/32 into chain/34
xtalax Nov 2, 2026
80d8ee1
Remove the MESH_PDEBASE gate from the symbolic_discretize wrapper
xtalax Nov 2, 2026
c343b35
Merge chain/34 into chain/36
xtalax Nov 2, 2026
0d49dc1
Merge chain/36 into chain/37
xtalax Nov 2, 2026
256d66b
Remove the MESH_PDEBASE gate from the messages wrapper
xtalax Nov 2, 2026
d644eb1
Merge chain/37 into chain/38
xtalax Nov 2, 2026
2bf026c
Remove the MESH_PDEBASE gate from the arguments wrapper; point the pa…
xtalax Nov 2, 2026
4b8bf4e
Remove the MESH_PDEBASE gate from the extension contract wrapper; fix…
xtalax Nov 2, 2026
1efb650
Read the extension contract page from docs/src in its test
xtalax Nov 2, 2026
07ed65a
Choose the normal_flux facet quadrature order from the interpolations
xtalax Nov 2, 2026
0857a25
Match the documentation test and boundary-condition page to the rewor…
xtalax Nov 2, 2026
7cc5d0f
Merge chain/36 into chain/37
xtalax Nov 2, 2026
2beddf2
Merge chain/37 into chain/38
xtalax Nov 2, 2026
3d1a082
Merge upstream/master into pdecomp/facet-dofs
xtalax Nov 3, 2026
d6f5b18
Merge pdecomp/facet-dofs into pdecomp/operators-api
xtalax Nov 3, 2026
6f9a5ad
Document facet_dofs, dof_coordinates and cell_dofs
xtalax Nov 3, 2026
121a18b
Merge pdecomp/facet-dofs docs into pdecomp/operators-api
xtalax Nov 3, 2026
e4c52e1
Document operators(pdesys, disc)
xtalax Nov 3, 2026
ba4921f
Treat facet cells with no subdofhandler as lacking the field in facet…
xtalax Nov 3, 2026
31233d2
Merge pdecomp/facet-dofs into pdecomp/operators-api
xtalax Nov 3, 2026
ba0a7e0
Read the spatial dimension of dof_coordinates from a node, not Ferrit…
xtalax Nov 3, 2026
47d93e6
Merge pdecomp/facet-dofs into pdecomp/operators-api
xtalax Nov 3, 2026
e5eae84
Format with Runic
xtalax Nov 3, 2026
6c8ab46
Merge Runic formatting from facet-dofs-v2
xtalax Nov 3, 2026
dc76531
Reject cell_dofs on a single region that covers only part of the mesh
xtalax Nov 3, 2026
2ce1952
Drop unused NonlinearProblem import
xtalax Nov 3, 2026
527863f
Format with Runic
xtalax Nov 3, 2026
ebb9a92
Merge chain/27 into chain/25
xtalax Nov 3, 2026
3f09aa9
Merge chain/30 into chain/26
xtalax Nov 3, 2026
afba5a6
Merge chain/24 into chain/27
xtalax Nov 3, 2026
9b9be2e
Merge chain/26 into chain/29
xtalax Nov 3, 2026
453cc94
Merge chain/25 into chain/30
xtalax Nov 3, 2026
a90c754
Merge chain/29 into chain/28
xtalax Nov 3, 2026
5489f81
Merge chain/28 into chain/31
xtalax Nov 3, 2026
92f7c12
Merge chain/31 into chain/32
xtalax Nov 3, 2026
ab4d7c2
Merge chain/32 into chain/34
xtalax Nov 3, 2026
fc0159e
Merge chain/34 into chain/36
xtalax Nov 3, 2026
9ed7ed4
Merge chain/36 into chain/37
xtalax Nov 3, 2026
7232c66
Merge chain/37 into chain/38
xtalax Nov 3, 2026
d1ad33f
Merge upstream/master into chain/24
xtalax Nov 3, 2026
0a0e7aa
Merge upstream/master into chain/23
xtalax Nov 3, 2026
288479f
Merge upstream/master into chain/25
xtalax Nov 3, 2026
d044b57
Merge upstream/master into chain/26
xtalax Nov 3, 2026
1921407
Merge chain/24 into chain/27
xtalax Nov 3, 2026
d4a375b
Merge chain/23 into chain/29
xtalax Nov 3, 2026
6a65964
Merge chain/24 into chain/30
xtalax Nov 3, 2026
0b5e2a3
Merge upstream/master into chain/28
xtalax Nov 3, 2026
68f6c10
Merge chain/28 into chain/31
xtalax Nov 3, 2026
3e29ced
Merge chain/31 into chain/32
xtalax Nov 3, 2026
119bd6f
Merge chain/32 into chain/34
xtalax Nov 3, 2026
438d2a0
Merge chain/32 into chain/36
xtalax Nov 3, 2026
65641fa
Merge chain/32 into chain/37
xtalax Nov 3, 2026
43c9bc0
Merge chain/32 into chain/38
xtalax Nov 3, 2026
961acc5
Merge remote-tracking branch 'pr/24' into fem/all-merged
xtalax Nov 3, 2026
0f5ee70
Merge remote-tracking branch 'pr/25' into fem/all-merged
xtalax Nov 3, 2026
1e53d3c
Merge remote-tracking branch 'pr/26' into fem/all-merged
xtalax Nov 3, 2026
6b61f07
Merge remote-tracking branch 'pr/27' into fem/all-merged
xtalax Nov 3, 2026
d80ae1c
Merge remote-tracking branch 'pr/28' into fem/all-merged
xtalax Nov 3, 2026
c651d1f
Merge remote-tracking branch 'pr/29' into fem/all-merged
xtalax Nov 3, 2026
b15be02
Merge remote-tracking branch 'pr/30' into fem/all-merged
xtalax Nov 3, 2026
be28681
Merge remote-tracking branch 'pr/31' into fem/all-merged
xtalax Nov 3, 2026
a29f609
Merge remote-tracking branch 'pr/32' into fem/all-merged
xtalax Nov 3, 2026
c294ce4
Merge remote-tracking branch 'pr/34' into fem/all-merged
xtalax Nov 3, 2026
ca129ca
Merge remote-tracking branch 'pr/36' into fem/all-merged
xtalax Nov 3, 2026
c8a4aa7
Merge remote-tracking branch 'pr/37' into fem/all-merged
xtalax Nov 3, 2026
636a310
Merge remote-tracking branch 'pr/38' into fem/all-merged
xtalax Nov 3, 2026
33b6e9d
Merge remote-tracking branch 'pr/45' into fem/all-merged
xtalax Nov 3, 2026
7c72b05
Merge remote-tracking branch 'pr/43' into fem/all-merged
xtalax Nov 3, 2026
76e58e9
Merge pr/48 (operators API) into fem/all-merged
xtalax Nov 3, 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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FerriteGmsh = "1.5"
ForwardDiff = "1.4"
Gmsh = "0.3"
LinearAlgebra = "1.10"
LinearSolve = "5"
ModelingToolkit = "11"
NonlinearSolveFirstOrder = "2.10"
OrdinaryDiffEqBDF = "2.4"
Expand All @@ -56,11 +57,12 @@ julia = "1.10"
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
FerriteGmsh = "4f95f4f8-b27c-4ae5-9a39-ea55e634e36b"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
OrdinaryDiffEqBDF = "6ad6398a-0878-4a85-9266-38940aa047c8"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AllocCheck", "FerriteGmsh", "Gmsh", "OrdinaryDiffEqBDF", "Random", "SafeTestsets", "SciMLTesting", "Test"]
test = ["AllocCheck", "FerriteGmsh", "Gmsh", "LinearSolve", "OrdinaryDiffEqBDF", "Random", "SafeTestsets", "SciMLTesting", "Test"]
28 changes: 28 additions & 0 deletions benchmarks/navier_stokes/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
FerriteGmsh = "4f95f4f8-b27c-4ae5-9a39-ea55e634e36b"
FiniteElementMethod = "e08948db-0ae8-498a-9b98-73fc7f237ce3"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEqBDF = "6ad6398a-0878-4a85-9266-38940aa047c8"
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
PDEBase = "a7812802-0625-4b9e-961c-d332478797e5"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[sources]
FiniteElementMethod = {path = "../.."}
PDEBase = {rev = "forge/mesh-axis-order", url = "https://github.com/xtalax-droid/PDEBase.jl"}

[compat]
julia = "1.11"
28 changes: 28 additions & 0 deletions benchmarks/navier_stokes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Benchmark (d): Navier–Stokes flow past a cylinder

`ns_cylinder.jl` measures, in one process and after a warm-up solve on each side:

1. Wall-clock against Ferrite's `ns_vs_diffeq.jl` tutorial (`ferrite_ns_vs_diffeq.jl`, the tutorial's code with
the changes listed at its top) on the same mesh, `dfg_channel_grid(h = 0.05, length = 1.1)`, with the
tutorial's settings: ν = 1e-3, inflow ramp `min(1.5t, 1.5)` (Re = 100), T = 6, abstol 1e-4, reltol 1e-5,
output every 0.1. Both sides solve one discrete problem: the outlet treatment of the PDESystem example (∇p
tested strongly, p = 0 on the outlet), which Ferrite's side gets from `outlet = :pressure`. Ferrite runs Rodas5P
on its mass-matrix ODE; FiniteElementMethod discretizes the PDESystem of `examples/dfg_cylinder` to a
DAEProblem and runs DFBDF. The horizontal velocities are compared at t = 1 and t = T at 20 points behind the
cylinder, and the time ratio is recorded only if they agree to 1% of the largest velocity there. The tutorial as
published (do-nothing outlet) is timed too, for reference. The time steppers and their error norms differ, so
the times are comparable in magnitude, not a measure of which package is faster.
2. DFG 2D-1 (Re = 20) drag, lift and pressure difference on the full channel at the meshes of
`BENCHMARK_NS_MESHES` (`h:hc` pairs, default `0.04:0.0025,0.02:0.00333,0.01:0.00167`, up to 149 094 unknowns),
with their errors against the DFG reference values.

```sh
julia --project=benchmarks/navier_stokes -e 'using Pkg; Pkg.instantiate()'
julia --project=benchmarks/navier_stokes benchmarks/navier_stokes/ns_cylinder.jl
```

The results go to `benchmarks/results/ns_cylinder.toml` (or `BENCHMARK_RESULTS_DIR`) with the environment record of
`benchmarks/common.jl`: origin, date, commit, CPU, thread counts, Julia and package versions. Peak memory of the
default run is about 6.5 GB, from the 149 094-unknown 2D-1 solve; the run takes about 10 minutes on one thread.
The environment uses this repository's package and, until a PDEBase release has the mesh layer, PDEBase from the
`forge/mesh-axis-order` branch (`[sources]`).
256 changes: 256 additions & 0 deletions benchmarks/navier_stokes/ferrite_ns_vs_diffeq.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
# Baseline of benchmark (d), spec §11.5: Ferrite's own tutorial `docs/src/literate-tutorials/ns_vs_diffeq.jl`
# (Ferrite 1.7, MIT licence), run as published apart from three changes that do not touch the numerics: the mesh
# comes from `dfg_channel_grid` of the example (the same geometry for both sides of the comparison; the tutorial's
# own Gmsh rectangle-minus-circle with `Mesh.MeshSizeMax = 0.05` is kept as `tutorial_grid`), the VTK output loop
# is replaced by `solve` with `saveat`, the progress bar and logging are off, and the linear solver is named as
# UMFPACK: the tutorial predates LinearSolve's current sparse default, whose supernodal LU rejects the change of
# sparsity pattern between Rodas5P's W matrices that UMFPACK, the default when the tutorial was written, accepts. Everything else
# (Q2Q1 Taylor–Hood with a vector velocity, ν = 1e-3, the inflow ramp `min(1.5t, 1.5)`, Rodas5P with the Ferrite
# Dirichlet limiter, `abstol = 1e-4`, `reltol = 1e-5`, `dt = 1e-3`, the free-dof error norm) is the tutorial's.
#
# `outlet = :pressure` switches to the outlet treatment of the PDESystem example, so that the timed comparison in
# `ns_cylinder.jl` solves one discrete problem on both sides. Prints and returns `(; seconds, ndofs, steps, ...)`; `ns_cylinder.jl` calls it and writes the results file.
using Ferrite, SparseArrays, BlockArrays, LinearAlgebra
using DiffEqBase
using OrdinaryDiffEqRosenbrock: Rodas5P
using ADTypes: AutoFiniteDiff
using LinearSolve: UMFPACKFactorization

include(joinpath(@__DIR__, "..", "..", "examples", "dfg_cylinder", "mesh.jl"))

function tutorial_grid()
Gmsh.initialize()
try
gmsh.option.set_number("General.Verbosity", 2)
dim = 2
rect_tag = gmsh.model.occ.add_rectangle(0, 0, 0, 1.1, 0.41)
circle_tag = gmsh.model.occ.add_circle(0.2, 0.2, 0, 0.05)
circle_curve_tag = gmsh.model.occ.add_curve_loop([circle_tag])
circle_surf_tag = gmsh.model.occ.add_plane_surface([circle_curve_tag])
gmsh.model.occ.cut([(dim, rect_tag)], [(dim, circle_surf_tag)])
gmsh.model.occ.synchronize()
gmsh.model.model.add_physical_group(dim - 1, [6], -1, "bottom")
gmsh.model.model.add_physical_group(dim - 1, [7], -1, "inlet")
gmsh.model.model.add_physical_group(dim - 1, [8], -1, "outlet")
gmsh.model.model.add_physical_group(dim - 1, [9], -1, "top")
gmsh.model.model.add_physical_group(dim - 1, [5], -1, "cylinder")
gmsh.option.setNumber("Mesh.Algorithm", 11)
gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 20)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.05)
gmsh.model.mesh.generate(dim)
grid = FerriteGmsh.togrid()
addfacetset!(grid, "walls", union(getfacetset(grid, "bottom"), getfacetset(grid, "top")))
return grid
finally
Gmsh.finalize()
end
end

function assemble_mass_matrix(cv::MultiFieldCellValues, M::SparseMatrixCSC, dh::DofHandler)
n_basefuncs_v = getnbasefunctions(cv.v)
n_basefuncs_p = getnbasefunctions(cv.p)
n_basefuncs = n_basefuncs_v + n_basefuncs_p
v▄, p▄ = 1, 2
Mₑ = BlockedArray(zeros(n_basefuncs, n_basefuncs), [n_basefuncs_v, n_basefuncs_p], [n_basefuncs_v, n_basefuncs_p])
mass_assembler = start_assemble(M)
for cell in CellIterator(dh)
fill!(Mₑ, 0)
Ferrite.reinit!(cv, cell)
for q_point in 1:getnquadpoints(cv)
dΩ = getdetJdV(cv, q_point)
for i in 1:n_basefuncs_v
φᵢ = shape_value(cv.v, q_point, i)
for j in 1:n_basefuncs_v
φⱼ = shape_value(cv.v, q_point, j)
Mₑ[BlockIndex((v▄, v▄), (i, j))] += φᵢ ⋅ φⱼ * dΩ
end
end
end
assemble!(mass_assembler, celldofs(cell), Mₑ)
end
return M
end

function assemble_stokes_matrix(cv::MultiFieldCellValues, ν, K::SparseMatrixCSC, dh::DofHandler; outlet = :do_nothing)
n_basefuncs_v = getnbasefunctions(cv.v)
n_basefuncs_p = getnbasefunctions(cv.p)
n_basefuncs = n_basefuncs_v + n_basefuncs_p
v▄, p▄ = 1, 2
Kₑ = BlockedArray(zeros(n_basefuncs, n_basefuncs), [n_basefuncs_v, n_basefuncs_p], [n_basefuncs_v, n_basefuncs_p])
stiffness_assembler = start_assemble(K)
for cell in CellIterator(dh)
fill!(Kₑ, 0)
Ferrite.reinit!(cv, cell)
for q_point in 1:getnquadpoints(cv)
dΩ = getdetJdV(cv, q_point)
for i in 1:n_basefuncs_v
∇φᵢ = shape_gradient(cv.v, q_point, i)
for j in 1:n_basefuncs_v
∇φⱼ = shape_gradient(cv.v, q_point, j)
Kₑ[BlockIndex((v▄, v▄), (i, j))] -= ν * ∇φᵢ ⊡ ∇φⱼ * dΩ
end
end
for j in 1:n_basefuncs_p
ψ = shape_value(cv.p, q_point, j)
for i in 1:n_basefuncs_v
divφ = shape_divergence(cv.v, q_point, i)
# `outlet = :pressure` keeps ∇p strong, as the PDESystem example does (see ferrite_ns_vs_diffeq).
Kₑ[BlockIndex((v▄, p▄), (i, j))] += outlet === :pressure ?
-(shape_gradient(cv.p, q_point, j) ⋅ shape_value(cv.v, q_point, i)) * dΩ : (divφ * ψ) * dΩ
Kₑ[BlockIndex((p▄, v▄), (j, i))] += (ψ * divφ) * dΩ
end
end
end
assemble!(stiffness_assembler, celldofs(cell), Kₑ)
end
return K
end

struct RHSparams{KT, CH, DH, CV, UT}
K::KT
ch::CH
dh::DH
cv::CV
u::UT
end

function ferrite_limiter!(u, _, p, t)
update!(p.ch, t)
return apply!(u, p.ch)
end

function navierstokes_rhs_element!(dvₑ, vₑ, cv)
n_basefuncs = getnbasefunctions(cv.v)
for q_point in 1:getnquadpoints(cv)
dΩ = getdetJdV(cv, q_point)
∇v = function_gradient(cv.v, q_point, vₑ)
v = function_value(cv.v, q_point, vₑ)
for j in 1:n_basefuncs
φⱼ = shape_value(cv.v, q_point, j)
dvₑ[j] -= v ⋅ ∇v' ⋅ φⱼ * dΩ
end
end
return
end

function navierstokes!(du, u_uc, p::RHSparams, t)
(; K, ch, dh, cv, u) = p
u .= u_uc
update!(ch, t)
apply!(u, ch)
mul!(du, K, u)
v_range = dof_range(dh, :v)
n_basefuncs = getnbasefunctions(cv.v)
vₑ = zeros(n_basefuncs)
duₑ = zeros(n_basefuncs)
for cell in CellIterator(dh)
Ferrite.reinit!(cv, cell)
v_celldofs = @view celldofs(cell)[v_range]
vₑ .= @views u[v_celldofs]
fill!(duₑ, 0.0)
navierstokes_rhs_element!(duₑ, vₑ, cv)
assemble!(du, v_celldofs, duₑ)
end
return
end

function navierstokes_jac_element!(Jₑ, vₑ, cv)
n_basefuncs = getnbasefunctions(cv.v)
for q_point in 1:getnquadpoints(cv)
dΩ = getdetJdV(cv, q_point)
∇v = function_gradient(cv.v, q_point, vₑ)
v = function_value(cv.v, q_point, vₑ)
for j in 1:n_basefuncs
φⱼ = shape_value(cv.v, q_point, j)
for i in 1:n_basefuncs
φᵢ = shape_value(cv.v, q_point, i)
∇φᵢ = shape_gradient(cv.v, q_point, i)
Jₑ[j, i] -= (φᵢ ⋅ ∇v' + v ⋅ ∇φᵢ') ⋅ φⱼ * dΩ
end
end
end
return
end

function navierstokes_jac!(J, u_uc, p, t)
(; K, ch, dh, cv, u) = p
u .= u_uc
update!(ch, t)
apply!(u, ch)
nonzeros(J) .= nonzeros(K)
assembler = start_assemble(J; fillzero = false)
n_basefuncs = getnbasefunctions(cv.v)
Jₑ = zeros(n_basefuncs, n_basefuncs)
vₑ = zeros(n_basefuncs)
v_range = dof_range(dh, :v)
for cell in CellIterator(dh)
Ferrite.reinit!(cv, cell)
v_celldofs = @view celldofs(cell)[v_range]
vₑ .= @views u[v_celldofs]
fill!(Jₑ, 0.0)
navierstokes_jac_element!(Jₑ, vₑ, cv)
assemble!(assembler, v_celldofs, Jₑ)
end
return apply!(J, ch)
end

struct FreeDofErrorNorm
ch::ConstraintHandler
end
(fe_norm::FreeDofErrorNorm)(u::Union{AbstractFloat, Complex}, t) = DiffEqBase.ODE_DEFAULT_NORM(u, t)
(fe_norm::FreeDofErrorNorm)(u::AbstractArray, t) = DiffEqBase.ODE_DEFAULT_NORM(u[fe_norm.ch.free_dofs], t)

"""
ferrite_ns_vs_diffeq(grid; T = 6.0, ν = 1e-3, vmax = 1.5, Δt_save = 0.1, outlet = :do_nothing)

Ferrite's tutorial problem on `grid` (facet sets `"inlet"`, `"outlet"`, `"walls"`, `"cylinder"`): build the
operators and integrate to `T`. Returns the solution, the `DofHandler` and the setup and solve times.

`outlet = :do_nothing` is the tutorial as published: the pressure gradient integrated by parts, so the outlet
carries the traction-free condition `ν∂ₙu − p n = 0`. `outlet = :pressure` is the discrete problem of the
PDESystem example instead: `∇p` tested strongly (`ν∂ₙu = 0` at the outlet) and `p = 0` imposed on the outlet
through the constraint handler, which drops the continuity equations of the outlet pressure nodes as the
example's Dirichlet rows do.
"""
function ferrite_ns_vs_diffeq(grid; T = 6.0, ν = 1.0e-3, vmax = 1.5, Δt_save = 0.1, outlet = :do_nothing)
outlet in (:do_nothing, :pressure) || throw(ArgumentError("outlet must be :do_nothing or :pressure, got $(repr(outlet))"))
setup = @elapsed begin
dim = 2
ip_v = Lagrange{RefQuadrilateral, 2}()^dim
qr = QuadratureRule{RefQuadrilateral}(4)
ip_p = Lagrange{RefQuadrilateral, 1}()
ip_geo = Ferrite.geometric_interpolation(Ferrite.getcelltype(grid))
cellvalues = MultiFieldCellValues(qr, (v = ip_v, p = ip_p), ip_geo)
dh = DofHandler(grid)
add!(dh, :v, ip_v)
add!(dh, :p, ip_p)
close!(dh)
ch = ConstraintHandler(dh)
∂Ω_noslip = union(getfacetset(grid, "walls"), getfacetset(grid, "cylinder"))
add!(ch, Dirichlet(:v, ∂Ω_noslip, (x, t) -> Vec((0.0, 0.0)), [1, 2]))
vᵢₙ(t) = min(t * vmax, vmax)
parabolic_inflow_profile(x, t) = Vec((4 * vᵢₙ(t) * x[2] * (0.41 - x[2]) / 0.41^2, 0.0))
add!(ch, Dirichlet(:v, getfacetset(grid, "inlet"), parabolic_inflow_profile, [1, 2]))
outlet === :pressure && add!(ch, Dirichlet(:p, getfacetset(grid, "outlet"), (x, t) -> 0.0))
close!(ch)
update!(ch, 0.0)
M = assemble_mass_matrix(cellvalues, allocate_matrix(dh), dh)
K = assemble_stokes_matrix(cellvalues, ν, allocate_matrix(dh), dh; outlet)
u₀ = zeros(ndofs(dh))
apply!(u₀, ch)
jac_sparsity = sparse(K)
apply!(M, ch)
p = RHSparams(K, ch, dh, cellvalues, copy(u₀))
rhs = ODEFunction(navierstokes!, mass_matrix = M; jac = navierstokes_jac!, jac_prototype = jac_sparsity)
problem = ODEProblem(rhs, u₀, (0.0, T), p)
timestepper = Rodas5P(
autodiff = AutoFiniteDiff(), step_limiter! = ferrite_limiter!, linsolve = UMFPACKFactorization()
)
end
solve_s = @elapsed sol = solve(
problem, timestepper; initializealg = NoInit(), dt = 1.0e-3,
adaptive = true, abstol = 1.0e-4, reltol = 1.0e-5, saveat = Δt_save,
internalnorm = FreeDofErrorNorm(ch), d_discontinuities = [1.0]
)
return (; sol, dh, ch, setup_s = setup, solve_s, ndofs = ndofs(dh), steps = sol.stats.naccept + sol.stats.nreject)
end
Loading
Loading