You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that NonlinearSolve.jl is required to be imported for ManifoldProjection
31
32
32
33
Let's plot the orbit and check the energy and angular momentum variation. We know that energy and angular momentum should be constant, and they are also called first integrals.
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.
6
11
7
12
## Recommended Methods
8
13
@@ -52,6 +57,30 @@ Similar to `MIRK` methods, fully implicit Runge-Kutta methods construct nonlinea
52
57
-`RadauIIa5` - A 5th stage Radau collocation method.
53
58
-`RadauIIa7` - A 7th stage Radau collocation method.
54
59
60
+
#### Gauss Legendre collocation methods
61
+
62
+
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.
63
+
64
+
-`Ascher1` - A 1st stage Gauss Legendre collocation method with Ascher's error control adaptivity.
65
+
-`Ascher2` - A 2nd stage Gauss Legendre collocation method with Ascher's error control adaptivity.
66
+
-`Ascher3` - A 3rd stage Gauss Legendre collocation method with Ascher's error control adaptivity.
67
+
-`Ascher4` - A 4th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
68
+
-`Ascher5` - A 5th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
69
+
-`Ascher6` - A 6th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
70
+
-`Ascher7` - A 7th stage Gauss Legendre collocation method with Ascher's error control adaptivity.
-`MIRKN4` - A 4th order collocation method using an implicit Runge-Kutta-Nyström tableau without defect control adaptivity.
75
+
-`MIRKN6` - A 6th order collocation method using an implicit Runge-Kutta-Nyström tableau without defect control adaptivity.
76
+
77
+
### SimpleBoundaryValueDiffEq.jl
78
+
79
+
-`SimpleMIRK4` - A simplified 4th order collocation method using an implicit Runge-Kutta tableau.
80
+
-`SimpleMIRK5` - A simplified 5th order collocation method using an implicit Runge-Kutta tableau.
81
+
-`SimpleMIRK6` - A simplified 6th order collocation method using an implicit Runge-Kutta tableau.
82
+
-`SimpleShooting` - A simplified single Shooting method.
83
+
55
84
### ODEInterface.jl
56
85
57
86
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.
Copy file name to clipboardExpand all lines: docs/src/tutorials/bvp_example.md
+94-18Lines changed: 94 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -31,32 +31,26 @@ function simplependulum!(du, u, p, t)
31
31
end
32
32
```
33
33
34
-
### Boundary Condition
35
-
36
34
There are two problem types available:
37
35
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)
42
38
43
39
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.
44
40
41
+
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.
42
+
45
43
```@example bvp
46
44
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
45
+
residual[1] = u(pi / 4)[1] + pi / 2 # the solution at the middle of the time span should be -pi/2
46
+
residual[2] = u(pi / 2)[1] - pi / 2 # the solution at the end of the time span should be pi/2
The third argument of `BVProblem` is the initial guess of the solution, which is constant in this example.
56
-
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
+
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 set as a `Vector`.
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 and 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).
74
68
75
69
```@example bvp
76
70
plot(sol3)
77
71
```
78
72
79
-
#### `TwoPointBVProblem`
80
-
81
73
`TwoPointBVProblem` is operationally the same as `BVProblem` but allows for the solver
82
74
to specialize on the common form of being a two-point BVP, i.e. a BVP which only has
83
75
boundary conditions at the start and the finish of the time interval.
@@ -99,5 +91,89 @@ plot(sol2)
99
91
Note here that `bc2a!` is a boundary condition for the first time point, and `bc2b!` is a boundary condition
100
92
for the final time point. `bcresid_prototype` is a prototype array which is passed in order to know the size of
101
93
`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
The common way of solving the second order BVP is to define intermediate 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(; jac_alg = BVPJacobianAlgorithm(AutoForwardDiff())), 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.
0 commit comments