Skip to content

Commit ec1390f

Browse files
Use subpackages for non-ODEs
Preparing for the DifferentialEquations.jl split SciML/DifferentialEquations.jl#1086
1 parent 352d206 commit ec1390f

File tree

9 files changed

+78
-77
lines changed

9 files changed

+78
-77
lines changed

docs/src/examples/diffusion_implicit_heat_equation.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ First, we'll use / import some packages:
1616
import Plots
1717
import LinearAlgebra
1818
import DiffEqBase
19-
import OrdinaryDiffEq as ODE
20-
import OrdinaryDiffEq: SplitODEProblem, solve, IMEXEuler
19+
import OrdinaryDiffEqBDF as BDF
2120
import SciMLBase, SciMLOperators
2221
```
2322

@@ -179,14 +178,14 @@ params = (; n)
179178
180179
tspan = (FT(0), N_t * FT(Δt))
181180
182-
prob = SplitODEProblem(SciMLOperators.MatrixOperator(D),
181+
prob = SciMLBase.SplitODEProblem(SciMLOperators.MatrixOperator(D),
183182
rhs!,
184183
T,
185184
tspan,
186185
params)
187-
alg = IMEXEuler()
186+
alg = BDF.IMEXEuler()
188187
println("Solving...")
189-
sol = solve(prob,
188+
sol = SciMLBase.solve(prob,
190189
alg,
191190
dt = Δt,
192191
saveat = range(FT(0), N_t * FT(Δt), length = 5),

docs/src/examples/kepler_problem.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Both Runge-Kutta-Nyström and Runge-Kutta integrator do not conserve energy nor
9393
In this example, we know that energy and angular momentum should be conserved. We can achieve this through manifold projection. As the name implies, it is a procedure to project the ODE solution to a manifold. Let's start with a base case, where manifold projection isn't being used.
9494

9595
```@example kepler
96-
import DiffEqCallbacks
96+
import DiffEqCallbacks as CB
9797
9898
function plot_orbit2(sol)
9999
Plots.plot(sol, vars = (1, 2), lab = "Orbit", title = "Kepler Problem Solution")
@@ -127,7 +127,7 @@ function first_integrals_manifold(residual, u, p, t)
127127
residual[3:4] .= initial_first_integrals[2] - L(u[1:2], u[3:4])
128128
end
129129
130-
cb = DiffEqCallbacks.ManifoldProjection(first_integrals_manifold, autodiff = NLS.AutoForwardDiff())
130+
cb = CB.ManifoldProjection(first_integrals_manifold, autodiff = NLS.AutoForwardDiff())
131131
sol5 = ODE.solve(prob2, ODE.RK4(), dt = 1 // 5, adaptive = false, callback = cb)
132132
analysis_plot2(sol5, H, L)
133133
```
@@ -139,7 +139,7 @@ function energy_manifold(residual, u, p, t)
139139
residual[1:2] .= initial_first_integrals[1] - H(u[1:2], u[3:4])
140140
residual[3:4] .= 0
141141
end
142-
energy_cb = DiffEqCallbacks.ManifoldProjection(energy_manifold, autodiff = NLS.AutoForwardDiff())
142+
energy_cb = CB.ManifoldProjection(energy_manifold, autodiff = NLS.AutoForwardDiff())
143143
sol6 = ODE.solve(prob2, ODE.RK4(), dt = 1 // 5, adaptive = false, callback = energy_cb)
144144
analysis_plot2(sol6, H, L)
145145
```
@@ -151,7 +151,7 @@ function angular_manifold(residual, u, p, t)
151151
residual[1:2] .= initial_first_integrals[2] - L(u[1:2], u[3:4])
152152
residual[3:4] .= 0
153153
end
154-
angular_cb = DiffEqCallbacks.ManifoldProjection(angular_manifold, autodiff = NLS.AutoForwardDiff())
154+
angular_cb = CB.ManifoldProjection(angular_manifold, autodiff = NLS.AutoForwardDiff())
155155
sol7 = ODE.solve(prob2, ODE.RK4(), dt = 1 // 5, adaptive = false, callback = angular_cb)
156156
analysis_plot2(sol7, H, L)
157157
```

docs/src/solvers/steady_state_solve.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ large time steps as the steady state approaches.
4141
Example usage:
4242

4343
```julia
44-
import DifferentialEquations as DE
44+
import SteadyStateDiffEq as SS, DifferentialEquations as DE
4545
import Sundials
46-
sol = DE.solve(prob, DE.SSRootfind())
47-
sol = DE.solve(prob, DE.DynamicSS(DE.Tsit5()))
48-
sol = DE.solve(prob, DE.DynamicSS(Sundials.CVODE_BDF()), dt = 1.0)
46+
sol = SS.solve(prob, SS.SSRootfind())
47+
sol = SS.solve(prob, SS.DynamicSS(DE.Tsit5()))
48+
sol = SS.solve(prob, SS.DynamicSS(Sundials.CVODE_BDF()), dt = 1.0)
4949
```

docs/src/tutorials/dde_example.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ no delays are written as in the ODE.
3636
Thus, the function for this model is given by:
3737

3838
```@example dde
39-
import DifferentialEquations as DE
39+
import DelayDiffEq as DDE, DifferentialEquations as DE
4040
function bc_model(du, u, h, p, t)
4141
p0, q0, v0, d0, p1, q1, v1, d1, d2, beta0, beta1, tau = p
4242
hist3 = h(p, t - tau)[3]
@@ -50,7 +50,7 @@ end
5050
Now we build a `DDEProblem`. The signature
5151

5252
```julia
53-
prob = DE.DDEProblem(f, u0, h, tspan, p = SciMLBase.NullParameters();
53+
prob = DDE.DDEProblem(f, u0, h, tspan, p = SciMLBase.NullParameters();
5454
constant_lags = [], dependent_lags = [], kwargs...)
5555
```
5656

@@ -88,28 +88,28 @@ p = (p0, q0, v0, d0, p1, q1, v1, d1, d2, beta0, beta1, tau)
8888
tspan = (0.0, 10.0)
8989
u0 = [1.0, 1.0, 1.0]
9090
91-
prob = DE.DDEProblem(bc_model, u0, h, tspan, p; constant_lags = lags)
91+
prob = DDE.DDEProblem(bc_model, u0, h, tspan, p; constant_lags = lags)
9292
```
9393

9494
An efficient way to solve this problem (given the constant lags) is with the
9595
MethodOfSteps solver. Through the magic that is Julia, it translates an OrdinaryDiffEq.jl
9696
ODE solver method into a method for delay differential equations, which is highly
97-
efficient due to sweet compiler magic. A good choice is the order 5 method `DE.Tsit5()`:
97+
efficient due to sweet compiler magic. A good choice is the order 5 method `DDE.Tsit5()`:
9898

9999
```@example dde
100-
alg = DE.MethodOfSteps(DE.Tsit5())
100+
alg = DDE.MethodOfSteps(DE.Tsit5())
101101
```
102102

103-
For lower tolerance solving, one can use the `DE.BS3()` algorithm to good
103+
For lower tolerance solving, one can use the `DDE.BS3()` algorithm to good
104104
effect (this combination is similar to the MATLAB `dde23`, but more efficient
105-
tableau), and for high tolerances the `DE.Vern6()` algorithm will give a 6th order
105+
tableau), and for high tolerances the `DDE.Vern6()` algorithm will give a 6th order
106106
solution.
107107

108108
To solve the problem with this algorithm, we do the same thing we'd do with other
109109
methods on the common interface:
110110

111111
```@example dde
112-
sol = DE.solve(prob, alg)
112+
sol = DDE.solve(prob, alg)
113113
```
114114

115115
Note that everything available to OrdinaryDiffEq.jl can be used here, including
@@ -189,20 +189,20 @@ You might have noticed DifferentialEquations.jl allows you to solve problems
189189
with undeclared delays, since you can interpolate `h` at any value. This is
190190
a feature, but use it with caution. Undeclared delays can increase the error
191191
in the solution. It's recommended that you use a method with a residual control,
192-
such as `MethodOfSteps(DE.RK4())` whenever there are undeclared delays. With this,
192+
such as `MethodOfSteps(DDE.RK4())` whenever there are undeclared delays. With this,
193193
you can use interpolated derivatives, solve functional differential equations
194194
by using quadrature on the interpolant, etc. However, note that residual control
195195
solves with a low level of accuracy, so the tolerances should be made very small,
196196
and the solution should not be trusted for more than 2-3 decimal places.
197197

198-
Note: `MethodOfSteps(DE.RK4())` with undeclared delays is similar to MATLAB's
198+
Note: `MethodOfSteps(DDE.RK4())` with undeclared delays is similar to MATLAB's
199199
`ddesd`. Thus, for example, the following is similar to solving the example
200200
from above with residual control:
201201

202202
```@example dde
203-
prob = DE.DDEProblem(bc_model, u0, h, tspan)
204-
alg = DE.MethodOfSteps(DE.RK4())
205-
sol = DE.solve(prob, alg)
203+
prob = DDE.DDEProblem(bc_model, u0, h, tspan)
204+
alg = DDE.MethodOfSteps(DE.RK4())
205+
sol = DDE.solve(prob, alg)
206206
```
207207

208208
Note that this method can solve problems with state-dependent delays.
@@ -220,9 +220,9 @@ We can solve the above problem with dependent delay tracking by declaring the
220220
dependent lags and solving with a `MethodOfSteps` algorithm:
221221

222222
```@example dde
223-
prob = DE.DDEProblem(bc_model, u0, h, tspan; dependent_lags = ((u, p, t) -> tau,))
224-
alg = DE.MethodOfSteps(DE.Tsit5())
225-
sol = DE.solve(prob, alg)
223+
prob = DDE.DDEProblem(bc_model, u0, h, tspan; dependent_lags = ((u, p, t) -> tau,))
224+
alg = DDE.MethodOfSteps(DE.Tsit5())
225+
sol = DDE.solve(prob, alg)
226226
```
227227

228228
Here, we treated the single lag `t-tau` as a state-dependent delay. Of course, you

docs/src/tutorials/rode_example.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ du = f(u,p,t,W)dt
1515
where ``f(u,p,t,W)=2u\sin(W)`` and ``W(t)`` is a Wiener process (Gaussian process).
1616

1717
```@example rode
18-
import DifferentialEquations as DE
18+
import StochasticDiffEq as SDE
1919
import Plots
2020
function f3(u, p, t, W)
2121
2u * sin(W)
2222
end
2323
u0 = 1.00
2424
tspan = (0.0, 5.0)
25-
prob = DE.RODEProblem(f3, u0, tspan)
26-
sol = DE.solve(prob, DE.RandomEM(); dt = 1 / 100)
25+
prob = SDE.RODEProblem(f3, u0, tspan)
26+
sol = SDE.solve(prob, SDE.RandomEM(); dt = 1 / 100)
2727
Plots.plot(sol)
2828
```
2929

@@ -38,16 +38,16 @@ As with the other problem types, there is an in-place version which is more
3838
efficient for systems. The signature is `f(du,u,p,t,W)`. For example,
3939

4040
```@example rode2
41-
import DifferentialEquations as DE
41+
import StochasticDiffEq as SDE
4242
import Plots
4343
function f(du, u, p, t, W)
4444
du[1] = 2u[1] * sin(W[1] - W[2])
4545
du[2] = -2u[2] * cos(W[1] + W[2])
4646
end
4747
u0 = [1.00; 1.00]
4848
tspan = (0.0, 5.0)
49-
prob = DE.RODEProblem(f, u0, tspan)
50-
sol = DE.solve(prob, DE.RandomEM(); dt = 1 / 100)
49+
prob = SDE.RODEProblem(f, u0, tspan)
50+
sol = SDE.solve(prob, SDE.RandomEM(); dt = 1 / 100)
5151
Plots.plot(sol)
5252
```
5353

@@ -56,15 +56,15 @@ you can use the `rand_prototype` keyword to explicitly set the size of the
5656
random process:
5757

5858
```@example rode3
59-
import DifferentialEquations as DE
59+
import StochasticDiffEq as SDE
6060
import Plots
6161
function f(du, u, p, t, W)
6262
du[1] = -2W[3] * u[1] * sin(W[1] - W[2])
6363
du[2] = -2u[2] * cos(W[1] + W[2])
6464
end
6565
u0 = [1.00; 1.00]
6666
tspan = (0.0, 5.0)
67-
prob = DE.RODEProblem(f, u0, tspan; rand_prototype = zeros(3))
68-
sol = DE.solve(prob, DE.RandomEM(); dt = 1 / 100)
67+
prob = SDE.RODEProblem(f, u0, tspan; rand_prototype = zeros(3))
68+
sol = SDE.solve(prob, SDE.RandomEM(); dt = 1 / 100)
6969
Plots.plot(sol)
7070
```

0 commit comments

Comments
 (0)