Skip to content

Commit 9dc2612

Browse files
authored
Update to DelaunayTriangulation 1.0 (#53)
1 parent bd7c4f5 commit 9dc2612

File tree

70 files changed

+1035
-2335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1035
-2335
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1616
[compat]
1717
ChunkSplitters = "0.1, 1.0, 2.0"
1818
CommonSolve = "0.2"
19-
DelaunayTriangulation = "0.7, 0.8"
19+
DelaunayTriangulation = "1.0"
2020
PreallocationTools = "0.4"
2121
PrecompileTools = "1.2"
2222
SciMLBase = "1, 2"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ If this package doesn't suit what you need, you may like to review some of the o
2626
As a very quick demonstration, here is how we could solve a diffusion equation with Dirichlet boundary conditions on a square domain using the standard `FVMProblem` formulation; please see the docs for more information.
2727

2828
```julia
29-
using FiniteVolumeMethod, DelaunayTriangulation, CairoMakie, DifferentialEquations
29+
using FiniteVolumeMethod, DelaunayTriangulation, CairoMakie, OrdinaryDiffEq
3030
a, b, c, d = 0.0, 2.0, 0.0, 2.0
3131
nx, ny = 50, 50
3232
tri = triangulate_rectangle(a, b, c, d, nx, ny, single_boundary=true)
3333
mesh = FVMGeometry(tri)
3434
bc = (x, y, t, u, p) -> zero(u)
3535
BCs = BoundaryConditions(mesh, bc, Dirichlet)
3636
f = (x, y) -> y 1.0 ? 50.0 : 0.0
37-
initial_condition = [f(x, y) for (x, y) in each_point(tri)]
37+
initial_condition = [f(x, y) for (x, y) in DelaunayTriangulation.each_point(tri)]
3838
D = (x, y, t, u, p) -> 1 / 9
3939
final_time = 0.5
4040
prob = FVMProblem(mesh, BCs; diffusion_function=D, initial_condition, final_time)
41-
sol = solve(prob, saveat=0.001)
41+
sol = solve(prob, Tsit5(), saveat=0.001)
4242
u = Observable(sol.u[1])
4343
fig, ax, sc = tricontourf(tri, u, levels=0:5:50, colormap=:matter)
4444
tightlimits!(ax)

docs/liveserver.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import LiveServer
66
withenv("LIVESERVER_ACTIVE" => "true") do
77
LiveServer.servedocs(;
88
launch_browser=true,
9+
foldername=joinpath(repo_root, "docs"),
10+
include_dirs=[joinpath(repo_root, "src")],
11+
skip_dirs=[joinpath(repo_root, "docs/src/tutorials"),
12+
joinpath(repo_root, "docs/src/wyos"),
13+
joinpath(repo_root, "docs/src/figures"),
14+
],
915
)
10-
end
11-
16+
end
10.4 KB
Binary file not shown.
-16.6 KB
Binary file not shown.
-3.77 KB
Loading
Loading

docs/src/interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TriangleProperties
3737

3838
# `BoundaryConditions`: Defining boundary conditions
3939

40-
Once a mesh is defined, you need to associate each part of the boundary with a set of boundary nodes. Since you have a `Triangulation`, the boundary of the mesh already meets the necessary assumptions made by this package about the boundary; these assumptions are simply that they match the specification of a boundary [here in DelaunayTriangulation.jl's docs](https://SciML.github.io/DelaunayTriangulation.jl/dev/boundary_handling/#Boundary-Specification) (for example, the boundary points connect, the boundary is positively oriented, etc.).
40+
Once a mesh is defined, you need to associate each part of the boundary with a set of boundary nodes. Since you have a `Triangulation`, the boundary of the mesh already meets the necessary assumptions made by this package about the boundary; these assumptions are simply that they match the specification of a boundary [here in DelaunayTriangulation.jl's docs](https://juliageometry.github.io/DelaunayTriangulation.jl/dev/manual/boundaries/) (for example, the boundary points connect, the boundary is positively oriented, etc.).
4141

4242
You can specify boundary conditions using `BoundaryConditions`, whose docstring is below; the fields of `BoundaryConditions` are not public API, only this wrapper is.
4343

docs/src/literate_tutorials/diffusion_equation_in_a_wedge_with_mixed_boundary_conditions.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,20 @@ tc = DisplayAs.withcontext(:displaysize => (15, 80), :limit => true); #hide
2929
# one part for each boundary condition. This is accomplished
3030
# by providing a single vector for each part of the boundary as follows
3131
# (and as described in DelaunayTriangulation.jl's documentation),
32-
# where we also `refine!` the mesh to get a better mesh.
32+
# where we also `refine!` the mesh to get a better mesh. For the arc,
33+
# we use the `CircularArc` so that the mesh knows that it is triangulating
34+
# a certain arc in that area.
3335
using DelaunayTriangulation, FiniteVolumeMethod, ElasticArrays
3436
using ReferenceTests, Bessels, FastGaussQuadrature, Cubature #src
35-
n = 50
37+
3638
α = π / 4
37-
## The bottom edge
38-
x₁ = [0.0, 1.0]
39-
y₁ = [0.0, 0.0]
40-
## The arc
41-
r₂ = fill(1, n)
42-
θ₂ = LinRange(0, α, n)
43-
x₂ = @. r₂ * cos(θ₂)
44-
y₂ = @. r₂ * sin(θ₂)
45-
## The upper edge
46-
x₃ = [cos(α), 0.0]
47-
y₃ = [sin(α), 0.0]
48-
## Now combine and create the mesh
49-
x = [x₁, x₂, x₃]
50-
y = [y₁, y₂, y₃]
51-
boundary_nodes, points = convert_boundary_points_to_indices(x, y; existing_points=ElasticMatrix{Float64}(undef, 2, 0))
39+
points = [(0.0, 0.0), (1.0, 0.0), (cos(α), sin(α))]
40+
bottom_edge = [1, 2]
41+
arc = CircularArc((1.0, 0.0), (cos(α), sin(α)), (0.0, 0.0))
42+
upper_edge = [3, 1]
43+
boundary_nodes = [bottom_edge, [arc], upper_edge]
5244
tri = triangulate(points; boundary_nodes)
53-
A = get_total_area(tri)
45+
A = get_area(tri)
5446
refine!(tri; max_area=1e-4A)
5547
mesh = FVMGeometry(tri)
5648

@@ -74,7 +66,7 @@ BCs = BoundaryConditions(mesh, (lower_bc, arc_bc, upper_bc), types)
7466
# specifying the diffusion function as a constant.
7567
f = (x, y) -> 1 - sqrt(x^2 + y^2)
7668
D = (x, y, t, u, p) -> one(u)
77-
initial_condition = [f(x, y) for (x, y) in each_point(tri)]
69+
initial_condition = [f(x, y) for (x, y) in DelaunayTriangulation.each_point(tri)]
7870
final_time = 0.1
7971
prob = FVMProblem(mesh, BCs; diffusion_function=D, initial_condition, final_time)
8072

@@ -89,12 +81,18 @@ flux = (x, y, t, α, β, γ, p) -> (-α, -β)
8981
# has the best performance for these problems.
9082
using OrdinaryDiffEq, LinearSolve
9183
sol = solve(prob, TRBDF2(linsolve=KLUFactorization()), saveat=0.01, parallel=Val(false))
84+
ind = findall(DelaunayTriangulation.each_point_index(tri)) do i #hide
85+
!DelaunayTriangulation.has_vertex(tri, i) #hide
86+
end #hide
87+
using Test #hide
88+
@test sol[ind, :] reshape(repeat(initial_condition, length(sol)), :, length(sol))[ind, :] # make sure that missing vertices don't change #hide
9289
sol |> tc #hide
9390

9491
#-
9592
using CairoMakie
9693
fig = Figure(fontsize=38)
9794
for (i, j) in zip(1:3, (1, 6, 11))
95+
local ax
9896
ax = Axis(fig[1, i], width=600, height=600,
9997
xlabel="x", ylabel="y",
10098
title="t = $(sol.t[j])",
@@ -145,7 +143,7 @@ function exact_solution(x, y, t, A, ζ, f, α) #src
145143
return s #src
146144
end #src
147145
function compare_solutions(sol, tri, α, f) #src
148-
n = DelaunayTriangulation.num_solid_vertices(tri) #src
146+
n = DelaunayTriangulation.num_points(tri) #src
149147
x = zeros(n, length(sol)) #src
150148
y = zeros(n, length(sol)) #src
151149
u = zeros(n, length(sol)) #src
@@ -162,6 +160,7 @@ end #src
162160
x, y, u = compare_solutions(sol, tri, α, f) #src
163161
fig = Figure(fontsize=64) #src
164162
for i in eachindex(sol) #src
163+
local ax
165164
ax = Axis(fig[1, i], width=600, height=600) #src
166165
tricontourf!(ax, tri, sol.u[i], levels=0:0.01:1, colormap=:matter) #src
167166
ax = Axis(fig[2, i], width=600, height=600) #src

docs/src/literate_tutorials/diffusion_equation_on_a_square_plate.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BCs = BoundaryConditions(mesh, bc, Dirichlet)
3636

3737
# We can now define the actual PDE. We start by defining the initial condition and the diffusion function.
3838
f = (x, y) -> y 1.0 ? 50.0 : 0.0
39-
initial_condition = [f(x, y) for (x, y) in each_point(tri)]
39+
initial_condition = [f(x, y) for (x, y) in DelaunayTriangulation.each_point(tri)]
4040
D = (x, y, t, u, p) -> 1 / 9
4141

4242
# We can now define the problem:
@@ -50,17 +50,19 @@ prob.flux_function
5050
# where $(\alpha, \beta, \gamma)$ defines the approximation to $u$ via $u(x, y) = \alpha x + \beta y + \gamma$ so that
5151
# $\grad u(\vb x, t) = (\alpha,\beta)^{\mkern-1.5mu\mathsf{T}}$.
5252

53-
# To now solve the problem, we simply use `solve`. When no algorithm
54-
# is provided, as long as DifferentialEquations is loaded (instead of e.g.
55-
# OrdinaryDiffEq), the algorithm is chosen automatically. Moreover, note that,
53+
# To now solve the problem, we simply use `solve`. Note that,
5654
# in the `solve` call below, multithreading is enabled by default.
57-
using DifferentialEquations
58-
sol = solve(prob, saveat=0.05)
55+
# (If you don't know what algorithm to consider, do `using DifferentialEquations` instead
56+
# and simply call `solve(prob, saveat=0.05)` so that the algorithm is chosen automatically instead
57+
# of using `Tsit5()`.)
58+
using OrdinaryDiffEq
59+
sol = solve(prob, Tsit5(), saveat=0.05)
5960
sol |> tc #hide
6061

6162
# To visualise the solution, we can use `tricontourf!` from Makie.jl.
6263
fig = Figure(fontsize=38)
6364
for (i, j) in zip(1:3, (1, 6, 11))
65+
local ax
6466
ax = Axis(fig[1, i], width=600, height=600,
6567
xlabel="x", ylabel="y",
6668
title="t = $(sol.t[j])",
@@ -88,7 +90,7 @@ function exact_solution(x, y, t) #src
8890
end #src
8991
end #src
9092
function compare_solutions(sol, tri) #src
91-
n = DelaunayTriangulation.num_solid_vertices(tri) #src
93+
n = DelaunayTriangulation.num_points(tri) #src
9294
x = zeros(n, length(sol)) #src
9395
y = zeros(n, length(sol)) #src
9496
u = zeros(n, length(sol)) #src
@@ -103,6 +105,7 @@ end #src
103105
x, y, u = compare_solutions(sol, tri) #src
104106
fig = Figure(fontsize=64) #src
105107
for i in eachindex(sol) #src
108+
local ax
106109
ax = Axis(fig[1, i], width=600, height=600) #src
107110
tricontourf!(ax, tri, sol.u[i], levels=0:5:50, colormap=:matter) #src
108111
ax = Axis(fig[2, i], width=600, height=600) #src

0 commit comments

Comments
 (0)