Skip to content

Commit 4aa092c

Browse files
committed
More docstrings
1 parent 9ba7977 commit 4aa092c

File tree

6 files changed

+93
-23
lines changed

6 files changed

+93
-23
lines changed

docs/src/assets/Project.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[deps]
2+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
3+
BoundaryValueDiffEq = "764a87c0-6b3e-53db-9096-fe964310641d"
4+
BoundaryValueDiffEqAscher = "7227322d-7511-4e07-9247-ad6ff830280e"
5+
BoundaryValueDiffEqCore = "56b672f2-a5fe-4263-ab2d-da677488eb3a"
6+
BoundaryValueDiffEqFIRK = "85d9eb09-370e-4000-bb32-543851f73618"
7+
BoundaryValueDiffEqMIRK = "1a22d4ce-7765-49ea-b6f2-13c8438986a6"
8+
BoundaryValueDiffEqMIRKN = "9255f1d6-53bf-473e-b6bd-23f1ff009da4"
9+
BoundaryValueDiffEqShooting = "ed55bfe0-3725-4db6-871e-a1dc9f42a757"
10+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
11+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
12+
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
13+
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
14+
LineSearch = "87fe0de2-c867-4266-b59a-2f0a94fc965b"
15+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
16+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
17+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
18+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
19+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
20+
SimpleBoundaryValueDiffEq = "be0294bd-f90f-4760-ac4e-3421ce2b2da0"
21+
22+
[compat]
23+
ADTypes = "1.9"
24+
BoundaryValueDiffEq = "5.13.0"
25+
BoundaryValueDiffEqAscher = "1.2.0"
26+
BoundaryValueDiffEqCore = "1.3.0"
27+
BoundaryValueDiffEqFIRK = "1.3.0"
28+
BoundaryValueDiffEqMIRK = "1.3.0"
29+
BoundaryValueDiffEqShooting = "1.3.0"
30+
DiffEqBase = "6.158.3"
31+
Documenter = "1"
32+
DocumenterCitations = "1"
33+
DocumenterInterLinks = "1.0.0"
34+
LineSearch = "0.1.4"
35+
LinearAlgebra = "1.10"
36+
LinearSolve = "2.36.2, 3"
37+
OrdinaryDiffEq = "6.90.1"
38+
Plots = "1"
39+
SciMLBase = "2.60.0"
40+
SimpleBoundaryValueDiffEq = "1.1.0"

docs/src/basics/error_control.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Adaptivity helps ensure the quality of the our numerical solution, and when our
44

55
When comes to solving ill-conditioned BVP, for example the singular pertubation problem where the small parameters become extremally small leading to the layers phonemona, the error control adaptivity becomes even more critical, because the minor pertubations can lead to large deviation in the solution. In such cases, adaptivity autimatically figure out where to use refined mesh and where to use coarse mesh to achieve the balance of computational efficiency and accuracy.
66

7-
BoundaryValuDiffEq.jl support error control adaptivity, and the adaptivity is default as on when using adaptive methods:
7+
BoundaryValuDiffEq.jl support error control adaptivity for collocation methods, and the adaptivity is default as defect control adaptivity when using adaptive collocation solvers:
88

99
```julia
1010
sol = solve(prob, MIRK4(), dt = 0.01, adaptive = true)
1111
```
1212

13-
Actually, BoundaryValueDiffEq.jl supports both defect and global error control adaptivity(while the defect control is the default), to specify different error control metods, we simply need to specify the `controller` keyword in `solve`:
13+
Actually, BoundaryValueDiffEq.jl supports both defect and global error control adaptivity(while the defect control is the default controller) [boisvert2013runge](@Citet), to specify different error control metods, we simply need to specify the `controller` keyword in `solve`:
1414

1515
```julia
1616
sol = solve(prob, MIRK4(), dt = 0.01, controller = GlobalErrorControl()) # Use global error control

docs/src/refs.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,14 @@ @book{ascher1995numerical
2727
URL = {https://epubs.siam.org/doi/abs/10.1137/1.9781611971231},
2828
eprint = {https://epubs.siam.org/doi/pdf/10.1137/1.9781611971231}
2929
}
30+
31+
@article{boisvert2013runge,
32+
title={A Runge-Kutta BVODE solver with global error and defect control},
33+
author={Boisvert, Jason J and Muir, Paul H and Spiteri, Raymond J},
34+
journal={ACM Transactions on Mathematical Software (TOMS)},
35+
volume={39},
36+
number={2},
37+
pages={1--22},
38+
year={2013},
39+
publisher={ACM New York, NY, USA}
40+
}

lib/BoundaryValueDiffEqCore/src/calc_errors.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract type GlobalErrorControlMethod end
2121
Defect estimation method with defect as
2222
2323
```math
24-
DE = max\frac{|S'(x) - f(x,S(x))|}{1 + |f(x,S(x))}
24+
defect = \\max\\frac{S'(x) - f(x,S(x))}{1 + |f(x,S(x))|}
2525
```
2626
2727
Defect controller, with the maximum `defect_threshold` as 0.1, when the estimating defect is greater than the `defect_threshold`, the mesh will be refined.
@@ -87,7 +87,7 @@ Higher order global error estimation method
8787
Uses a solution from order+2 method on the original mesh and calculate the error with
8888
8989
```math
90-
GE = max\frac{|u_p - u_{p+2}|}{1 + |u_p|}
90+
error = \\max\\frac{u_p - u_{p+2}}{1 + |u_p|}
9191
```
9292
"""
9393
struct HOErrorControl <: GlobalErrorControlMethod end
@@ -99,7 +99,9 @@ Richardson extrapolation global error estimation method
9999
100100
Use Richardson extrapolation to calculate the error on the doubled mesh with
101101
102-
GE = \frac{2^p}{2^p-1} * max\frac{|u_h - u_{h/2}|}{1 + |u_h|}
102+
```math
103+
error = \\frac{2^p}{2^p-1} * \\max\\frac{u_h - u_{h/2}}{1 + |u_h|}
104+
```
103105
"""
104106
struct REErrorControl <: GlobalErrorControlMethod end
105107

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,17 @@ function eval_bc_residual!(
144144
bcb!(resid[2], dub, ub, p)
145145
end
146146

147-
# NOTE: We use `last` since the `first` might not conform to the same structure. For eg,
148-
# in the case of residuals
147+
"""
148+
__resize!(x, n, M)
149+
150+
Resizes the input `x` to length `n` and returns the resized array. If `n` is less than the
151+
length of `x`, it truncates the array. If `n` is greater than the length of `x`, it appends
152+
zeros to the array.
153+
154+
!!! note
155+
156+
We use `last` since the `first` might not conform to the same structure. For example, in the case of residuals
157+
"""
149158
function __resize!(x::AbstractVector{<:AbstractArray}, n, M)
150159
N = n - length(x)
151160
N == 0 && return x

lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ end
2424
"""
2525
mesh_selector!(cache::MIRKCache, controller::DefectControl)
2626
mesh_selector!(cache::MIRKCache, controller::GlobalErrorControl)
27-
mesh_selector!(cache::MIRKCache, controller::Union{SequentialErrorControl, HybridErrorControl})
27+
mesh_selector!(cache::MIRKCache, controller::SequentialErrorControl)
28+
mesh_selector!(cache::MIRKCache, controller::HybridErrorControl)
2829
2930
Generate new mesh based on the defect or the global error.
3031
"""
@@ -35,7 +36,7 @@ Generate new mesh based on the defect or the global error.
3536
N = length(mesh)
3637

3738
safety_factor = T(1.3)
38-
ρ = T(1.0) # Set rho=1 means mesh distribution will take place everytime.
39+
ρ = T(1.0)
3940
Nsub_star = 0
4041
Nsub_star_ub = 4 * (N - 1)
4142
Nsub_star_lb = N ÷ 2
@@ -95,7 +96,7 @@ end
9596

9697
info = ReturnCode.Success
9798

98-
= [maximum(abs, d) for d in errors] # Broadcasting breaks GPU Compilation
99+
= [maximum(abs, d) for d in errors]
99100
ŝ .= (ŝ ./ abstol) .^ (T(1) / order)
100101
r₁ = maximum(ŝ)
101102
r₂ = sum(ŝ)
@@ -108,7 +109,8 @@ end
108109

109110
if r₁ ρ * r₃
110111
Nsub_star = 2 * (N - 1)
111-
if Nsub_star > cache.alg.max_num_subintervals # Need to determine the too large threshold
112+
# Need to determine the too large threshold
113+
if Nsub_star > cache.alg.max_num_subintervals
112114
info = ReturnCode.Failure
113115
meshₒ = mesh
114116
mesh_dt₀ = mesh_dt
@@ -148,7 +150,7 @@ end
148150

149151
info = ReturnCode.Success
150152

151-
= [maximum(abs, d) for d in errors] # Broadcasting breaks GPU Compilation
153+
= [maximum(abs, d) for d in errors]
152154
ŝ .= (ŝ ./ abstol) .^ (T(1) / (order + 1))
153155
r₁ = maximum(ŝ)
154156
r₂ = sum(ŝ)
@@ -161,7 +163,8 @@ end
161163

162164
if r₁ ρ * r₃
163165
Nsub_star = 2 * (N - 1)
164-
if Nsub_star > cache.alg.max_num_subintervals # Need to determine the too large threshold
166+
# Need to determine the too large threshold
167+
if Nsub_star > cache.alg.max_num_subintervals
165168
info = ReturnCode.Failure
166169
meshₒ = mesh
167170
mesh_dt₀ = mesh_dt
@@ -216,7 +219,8 @@ end
216219

217220
if r₁ ρ * r₃
218221
Nsub_star = 2 * (N - 1)
219-
if Nsub_star > cache.alg.max_num_subintervals # Need to determine the too large threshold
222+
# Need to determine the too large threshold
223+
if Nsub_star > cache.alg.max_num_subintervals
220224
info = ReturnCode.Failure
221225
meshₒ = mesh
222226
mesh_dt₀ = mesh_dt
@@ -305,8 +309,7 @@ end
305309
"""
306310
halve_sol(sol)
307311
308-
The input sol has length of `n + 1`. Divide the original solution into two equal length
309-
solution.
312+
The input sol has length of `n + 1`. Divide the original mesh and u from original solution into `2n + 1` one.
310313
"""
311314
function halve_sol(sol::AbstractVectorOfArray{T}, mesh) where {T}
312315
new_sol = copy(sol)
@@ -319,17 +322,17 @@ function halve_sol(sol::AbstractVectorOfArray{T}, mesh) where {T}
319322
@simd for i in (2n):-2:2
320323
new_sol[i] = (new_sol[i + 1] + new_sol[i - 1]) ./ T(2)
321324
end
322-
mes = deepcopy(mesh)
323-
resize!(mes, 2 * n + 1)
324-
mes[1] = mesh[1]
325-
mes[end] = mesh[end]
325+
new_mesh = deepcopy(mesh)
326+
resize!(new_mesh, 2 * n + 1)
327+
new_mesh[1] = mesh[1]
328+
new_mesh[end] = mesh[end]
326329
for i in (2n - 1):-2:1
327-
mes[i] = mes[(i + 1) ÷ 2]
330+
new_mesh[i] = new_mesh[(i + 1) ÷ 2]
328331
end
329332
for i in (2n):-2:2
330-
mes[i] = (mes[i + 1] + mes[i - 1]) / 2
333+
new_mesh[i] = (new_mesh[i + 1] + new_mesh[i - 1]) / 2
331334
end
332-
return DiffEqArray(new_sol.u, mes)
335+
return DiffEqArray(new_sol.u, new_mesh)
333336
end
334337

335338
"""
@@ -338,16 +341,21 @@ end
338341
error_estimate!(cache::MIRKCache, controller::SequentialErrorControl)
339342
error_estimate!(cache::MIRKCache, controller::HybridErrorControl)
340343
344+
## Defect Control
345+
341346
error_estimate for the defect uses the discrete solution approximation Y, plus stages of
342347
the RK method in 'k_discrete', plus some new stages in 'k_interp' to construct
343348
an interpolant.
344349
350+
## Global Error Control
345351
error_estimate for the global error use the higher order or doubled mesh to estiamte the
346352
global error according to err = max(abs(Y_high - Y_low)) / (1 + abs(Y_low))
347353
354+
## Sequential Error Control
348355
error_estimate for the sequential error first uses the defect controller, if the defect is
349356
satisfying, then use the global error controller.
350357
358+
## Hybrid Error Control
351359
error_estimate for the hybrid error control uses the linear combination of defect and global
352360
error to estimate the error norm.
353361
"""

0 commit comments

Comments
 (0)