Skip to content

Commit d54bba8

Browse files
ErikQQYChrisRackauckas
authored andcommitted
Revamp BVP docs for new features
1 parent 573ed74 commit d54bba8

File tree

4 files changed

+128
-22
lines changed

4 files changed

+128
-22
lines changed

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ AlgebraicMultigrid = "0.5, 0.6"
4444
BSON = "0.3"
4545
BVProblemLibrary = "0.1.2"
4646
BenchmarkTools = "1"
47-
BoundaryValueDiffEq = "5.1"
47+
BoundaryValueDiffEq = "5.13"
4848
CSV = "0.10"
4949
ComponentArrays = "0.15"
5050
DAEProblemLibrary = "0.1"

docs/src/solvers/bvp_solve.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# BVP Solvers
1+
# [BVP Solvers](@id bvp_solve)
22

3-
`solve(prob::BVProblem,alg,dt=0.0;kwargs)`
3+
```julia
4+
solve(prob::BVProblem,alg,dt;kwargs)
5+
solve(prob::TwoPointBVProblem,alg,dt;kwargs)
6+
solve(prob::SecondOrderBVProblem,alg,dt;kwargs)
7+
solve(prob::SecondOrderTwoPointBVProblem,alg,dt;kwargs)
8+
```
49

5-
Solves the BVP defined by `prob` using the algorithm `alg`. All algorithms except `Shooting` methods should specify a `dt` which is the step size for the discretized mesh.
10+
Solves the BVP defined by `prob` using the algorithm `alg`. All algorithms except `Shooting` and `MultipleShooting` methods should specify a `dt` which is the step size for the discretized mesh.
611

712
## Recommended Methods
813

@@ -34,24 +39,50 @@ off via the keyword argument `adaptive = false`.
3439
Similar to `MIRK` methods, fully implicit Runge-Kutta methods construct nonlinear problems from the collocation equations of a BVP and solve such nonlinear systems to obtain numerical solutions of BVP. When solving large boundary value problems, choose a nested NonlinearSolve.jl solver by setting `nested_nlsolve=true` in FIRK solvers can achieve better performance.
3540

3641
- `LobattoIIIa2` - A 2nd stage LobattoIIIa collocation method.
37-
3842
- `LobattoIIIa3` - A 3rd stage LobattoIIIa collocation method.
3943
- `LobattoIIIa4` - A 4th stage LobattoIIIa collocation method.
4044
- `LobattoIIIa5` - A 5th stage LobattoIIIa collocation method.
45+
4146
- `LobattoIIIb2` - A 2nd stage LobattoIIIa collocation method, doesn't support defect control adaptivity.
4247
- `LobattoIIIb3` - A 3rd stage LobattoIIIa collocation method.
4348
- `LobattoIIIb4` - A 4th stage LobattoIIIa collocation method.
4449
- `LobattoIIIb5` - A 5th stage LobattoIIIa collocation method.
50+
4551
- `LobattoIIIc2` - A 2nd stage LobattoIIIa collocation method, doesn't support defect control adaptivity.
4652
- `LobattoIIIc3` - A 3rd stage LobattoIIIa collocation method.
4753
- `LobattoIIIc4` - A 4th stage LobattoIIIa collocation method.
4854
- `LobattoIIIc5` - A 5th stage LobattoIIIa collocation method.
55+
4956
- `RadauIIa1` - A 1st stage Radau collocation method, doesn't support defect control adaptivity.
5057
- `RadauIIa2` - A 2nd stage Radau collocation method.
5158
- `RadauIIa3` - A 3rd stage Radau collocation method.
5259
- `RadauIIa5` - A 5th stage Radau collocation method.
5360
- `RadauIIa7` - A 7th stage Radau collocation method.
5461

62+
#### Gauss Legendre collocation methods
63+
64+
The `Ascher` collocation methods are similar with `MIRK` and `FIRK` methods but have extension for BVDAE prblem solving, the error control is based on instead of defect control adaptivity.
65+
66+
- `Ascher1` - A 1st stage Gauss Legendre collocation method with Ascher's error control adaptivity.
67+
- `Ascher2` - A 2nd stage Gauss Legendre collocation method with Ascher's error control adaptivity.
68+
- `Ascher3` - A 3rd stage Gauss Legendre collocation method with Ascher's error control adaptivity.
69+
- `Ascher4` - A 4th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
70+
- `Ascher5` - A 5th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
71+
- `Ascher6` - A 6th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
72+
- `Ascher7` - A 7th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
73+
74+
#### MIRKN(Monotonic Implicit Runge-Kutta-Nystöm) methods
75+
76+
- `MIRKN4` - A 4th order collocation method using an implicit Runge-Kutta-Nyström tableau without defect control adaptivity.
77+
- `MIRKN6` - A 6th order collocation method using an implicit Runge-Kutta-Nyström tableau without defect control adaptivity.
78+
79+
### SimpleBoundaryValueDiffEq.jl
80+
81+
- `SimpleMIRK4` - A simplified 4th order collocation method using an implicit Runge-Kutta tableau.
82+
- `SimpleMIRK5` - A simplified 5th order collocation method using an implicit Runge-Kutta tableau.
83+
- `SimpleMIRK6` - A simplified 6th order collocation method using an implicit Runge-Kutta tableau.
84+
- `SimpleShooting` - A simplified single Shooting method.
85+
5586
### ODEInterface.jl
5687

5788
ODEInterface.jl can be used seamlessly with BoundaryValueDiffEq.jl, after we define our model using `BVProblem` or `TwoPointBVProblem`, we can directly call the solvers from ODEInterface.jl.

docs/src/tutorials/bvp_example.md

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,26 @@ function simplependulum!(du, u, p, t)
3131
end
3232
```
3333

34-
### Boundary Condition
35-
3634
There are two problem types available:
3735

38-
- A problem type for general boundary conditions `BVProblem` (including conditions that may be anywhere/ everywhere on the integration interval).
39-
- A problem type for boundaries that are specified at the beginning and the end of the integration interval `TwoPointBVProblem`
40-
41-
#### `BVProblem`
36+
- A problem type for general boundary conditions `BVProblem` (including conditions that may be anywhere/ everywhere on the integration interval, aka multi-points BVP).
37+
- A problem type for boundaries that are specified at the beginning and the end of the integration interval `TwoPointBVProblem`(aka two-points BVP)
4238

4339
The boundary conditions are specified by a function that calculates the residual in-place from the problem solution, such that the residual is $\vec{0}$ when the boundary condition is satisfied.
4440

4541
```@example bvp
4642
function bc1!(residual, u, p, t)
47-
residual[1] = u[end ÷ 2][1] + pi / 2 # the solution at the middle of the time span should be -pi/2
48-
residual[2] = u[end][1] - pi / 2 # the solution at the end of the time span should be pi/2
43+
residual[1] = u(pi/4)[1] + pi / 2 # the solution at the middle of the time span should be -pi/2
44+
residual[2] = u(pi/2)[1] - pi / 2 # the solution at the end of the time span should be pi/2
4945
end
5046
bvp1 = BVProblem(simplependulum!, bc1!, [pi / 2, pi / 2], tspan)
5147
sol1 = solve(bvp1, MIRK4(), dt = 0.05)
5248
plot(sol1)
5349
```
5450

55-
The third argument of `BVProblem` is the initial guess of the solution, which is constant in this example.
51+
The third argument of `BVProblem` or `TwoPointBVProblem` is the initial guess of the solution, which can be specified as a `Vector`, a `Function` of `t` or solution object from previous solving, in this example the initial guess is setted as a `Vector`.
5652

57-
<!-- add examples of more general initial conditions -->
58-
We need to use `MIRK4` or `Shooting` methods to solve `BVProblem`. `MIRK4` is a collocation method, whereas `Shooting` treats the problem as an IVP and varies the initial conditions until the boundary conditions are met.
59-
If you can have a good initial guess, `Shooting` method works very well.
53+
There are collocation and shooting methods for addressing boundary value problems in DifferentialEquations.jl. We need to use appropriate [available BVP solvers](@ref bvp_solve) to solve `BVProblem`. In this example, we use `MIRK4` to solve the simple pendulum example.
6054

6155
```@example bvp
6256
using OrdinaryDiffEq
@@ -70,14 +64,12 @@ sol3 = solve(bvp3, Shooting(Vern7()))
7064
```
7165

7266
The initial guess can also be supplied via a function of `t` or a previous solution type, this is especially handy for parameter analysis.
73-
We changed `u` to `sol` to emphasize the fact that in this case, the boundary condition can be written on the solution object. Thus, all the features on the solution type such as interpolations are available when using the `Shooting` method. (i.e. you can have a boundary condition saying that the maximum over the interval is `1` using an optimization function on the continuous output). Note that user has to import the IVP solver before it can be used. Any common interface ODE solver is acceptable.
67+
We changed `u` to `sol` to emphasize the fact that in this case, the boundary condition can be written on the solution object. Thus, all the features on the solution type such as interpolations are available when using both collocation nd shooting method. (i.e. you can have a boundary condition saying that the maximum over the interval is `1` using an optimization function on the continuous output).
7468

7569
```@example bvp
7670
plot(sol3)
7771
```
7872

79-
#### `TwoPointBVProblem`
80-
8173
`TwoPointBVProblem` is operationally the same as `BVProblem` but allows for the solver
8274
to specialize on the common form of being a two-point BVP, i.e. a BVP which only has
8375
boundary conditions at the start and the finish of the time interval.
@@ -99,5 +91,87 @@ plot(sol2)
9991
Note here that `bc2a!` is a boundary condition for the first time point, and `bc2b!` is a boundary condition
10092
for the final time point. `bcresid_prototype` is a prototype array which is passed in order to know the size of
10193
`resid_a` and `resid_b`. In this case, we have one residual term for the start and one for the final time point,
102-
and thus we have `bcresid_prototype = (zeros(1), zeros(1))`. If we wanted to only have boundary conditions at the
103-
final time, we could instead have done `bcresid_prototype = (zeros(0), zeros(2))`.
94+
and thus we have `bcresid_prototype = (zeros(1), zeros(1))`.
95+
96+
## Example 2: Directly Solving with Second Order BVP
97+
98+
Suppose we want to solve the second order BVP system which can be formulated as
99+
100+
```math
101+
\begin{cases}
102+
u_1''(x)= u_2(x),\\
103+
\epsilon u_2''(x)=-u_1(x)u_2'(x)- u_3(x)u_3'(x),\\
104+
\epsilon u_3''(x)=u_1'(x)u_3(x)- u_1(x) u_3 '(x)
105+
\end{cases}
106+
```
107+
108+
with initial conditions:
109+
110+
```math
111+
u_1(0) = u_1'(0)= u_1(1)=u_1'(1)=0,u_3(0)=
112+
-1, u_3(1)=1
113+
```
114+
115+
The common way of solving the second order BVP is to define intermidiate variables and transform the second order system into first order one, however, DifferentialEquations.jl allows the direct solving of second order BVP system to achieve more efficiency and higher continuity of the numerical solution.
116+
117+
```@example bvp
118+
function f!(ddu, du, u, p, t)
119+
ϵ = 0.1
120+
ddu[1] = u[2]
121+
ddu[2] = (-u[1] * du[2] - u[3] * du[3]) / ϵ
122+
ddu[3] = (du[1] * u[3] - u[1] * du[3]) / ϵ
123+
end
124+
function bc!(res, du, u, p, t)
125+
res[1] = u(0.0)[1]
126+
res[2] = u(1.0)[1]
127+
res[3] = u(0.0)[3] + 1
128+
res[4] = u(1.0)[3] - 1
129+
res[5] = du(0.0)[1]
130+
res[6] = du(1.0)[1]
131+
end
132+
u0 = [1.0, 1.0, 1.0]
133+
tspan = (0.0, 1.0)
134+
prob = SecondOrderBVProblem(f!, bc!, u0, tspan)
135+
sol = solve(prob, MIRKN4(), dt = 0.01)
136+
```
137+
138+
## Example 3: Semi-Explicit Boundary Value Differential-Algebraic Equations
139+
140+
Consider a semi-explicit boundary value differential-algebraic equation formulated as
141+
142+
```math
143+
\begin{cases}
144+
x_1'=(\epsilon+x_2-p_2(t))y+p_1'(t) \\
145+
x_2'=p_2'(t) \\
146+
x_3'=y \\
147+
0=(x_1-p_1(t))(y-e^t)
148+
\end{cases}
149+
```
150+
151+
with boundary conditions
152+
153+
```math
154+
x_1(0)=0,x_3(0)=1,x_2(1)=\sin(1)
155+
```
156+
157+
We need to choose the Ascher methods for solving BVDAEs.
158+
159+
```@example bvp
160+
function f!(du, u, p, t)
161+
e = 2.7
162+
du[1] = (1 + u[2] - sin(t)) * u[4] + cos(t)
163+
du[2] = cos(t)
164+
du[3] = u[4]
165+
du[4] = (u[1] - sin(t)) * (u[4] - e^t)
166+
end
167+
function bc!(res, u, p, t)
168+
res[1] = u[1]
169+
res[2] = u[3] - 1
170+
res[3] = u[2] - sin(1.0)
171+
end
172+
u0 = [0.0, 0.0, 0.0, 0.0]
173+
tspan = (0.0, 1.0)
174+
fun = BVPFunction(f!, bc!, mass_matrix = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 0])
175+
prob = BVProblem(fun, u0, tspan)
176+
sol = solve(prob, Ascher4(zeta = [0.0, 0.0, 1.0]), dt = 0.01)
177+
```

docs/src/types/bvp_types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
```@docs
44
SciMLBase.BVProblem
5+
SciMLBase.SecondOrderBVProblem
56
```
67

78
## Solution Type

0 commit comments

Comments
 (0)