Skip to content

Commit 1fdfefe

Browse files
committed
Make examples runnable
1 parent 94a6fbc commit 1fdfefe

File tree

7 files changed

+72
-20
lines changed

7 files changed

+72
-20
lines changed

docs/common_first_steps.jl

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
using Markdown
2-
function first_steps(name, solver)
3-
Markdown.parse("""## Installation
2+
function first_steps(name, solver; fixed_timesteps = false)
3+
sym_name = Symbol(name)
4+
sym_solver = Symbol(solver)
5+
@eval begin
6+
using $sym_name
7+
function lorenz!(du, u, p, t)
8+
du[1] = 10.0 * (u[2] - u[1])
9+
du[2] = u[1] * (28.0 - u[3]) - u[2]
10+
du[3] = u[1] * u[2] - (8 / 3) * u[3]
11+
end
12+
u0 = [1.0; 0.0; 0.0]
13+
tspan = (0.0, 100.0)
14+
prob = ODEProblem(lorenz!, u0, tspan)
15+
if !($fixed_timesteps)
16+
sol = solve(prob, ($sym_solver)())
17+
else
18+
sol = solve(prob, ($sym_solver)(), dt = 1/100)
19+
end
20+
sol_end = sol[end]
21+
end
22+
installation = """## Installation
423
To be able to access the solvers in `$name`, you must first install them use the Julia package manager:
524
625
```julia
@@ -10,20 +29,53 @@ function first_steps(name, solver)
1029
This will only install the solvers listed at the bottom of this page.
1130
If you want to explore other solvers for your problem,
1231
you will need to install some of the other libraries listed in the navigation bar on the left.
32+
"""
33+
example = if !fixed_timesteps
34+
"""
1335
14-
## Example usage
36+
## Example usage
1537
16-
```julia
17-
using $name
38+
```julia
39+
using $name
1840
19-
function lorenz!(du, u, p, t)
20-
du[1] = 10.0 * (u[2] - u[1])
21-
u[2] = u[1] * (28.0 - u[3]) - u[2]
22-
du[3] = u[1] * u[2] - (8 / 3) * u[3]
41+
function lorenz!(du, u, p, t)
42+
du[1] = 10.0 * (u[2] - u[1])
43+
du[2] = u[1] * (28.0 - u[3]) - u[2]
44+
du[3] = u[1] * u[2] - (8 / 3) * u[3]
45+
end
46+
u0 = [1.0; 0.0; 0.0]
47+
tspan = (0.0, 100.0)
48+
prob = ODEProblem(lorenz!, u0, tspan)
49+
sol = solve(prob, $solver())
50+
sol[end]
51+
```
52+
```julia
53+
$sol_end
54+
```
55+
"""
56+
else
57+
"""
58+
59+
## Example usage
60+
61+
```julia
62+
using $name
63+
64+
function lorenz!(du, u, p, t)
65+
du[1] = 10.0 * (u[2] - u[1])
66+
du[2] = u[1] * (28.0 - u[3]) - u[2]
67+
du[3] = u[1] * u[2] - (8 / 3) * u[3]
68+
end
69+
u0 = [1.0; 0.0; 0.0]
70+
tspan = (0.0, 100.0)
71+
prob = ODEProblem(lorenz!, u0, tspan)
72+
sol = solve(prob, $solver(), dt=1/100)
73+
sol[end]
74+
```
75+
```julia
76+
$sol_end
77+
```
78+
"""
2379
end
24-
u0 = [1.0; 0.0; 0.0]
25-
tspan = (0.0, 100.0)
26-
prob = ODEProblem(lorenz!, u0, tspan)
27-
sol = solve(prob, $solver())
28-
```""")
80+
Markdown.parse(installation*example)
2981
end

docs/src/explicit/LowStorageRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ are generally only recommended in situations which are RAM bound, like large-sca
1212

1313
```@eval
1414
first_steps = evalfile("./common_first_steps.jl")
15-
first_steps("OrdinaryDiffEqLowStorageRK", "CarpenterKennedy2N54")
15+
first_steps("OrdinaryDiffEqLowStorageRK", "CKLLSRK43_2")
1616
```
1717

1818
## Full list of solvers

docs/src/explicit/PRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Explicit solvers optimized for a certain number of parallel calls of the system
88

99
```@eval
1010
first_steps = evalfile("./common_first_steps.jl")
11-
first_steps("OrdinaryDiffEqPRK", "KuttaPRK2p5")
11+
first_steps("OrdinaryDiffEqPRK", "KuttaPRK2p5", fixed_timesteps = true)
1212
```
1313

1414
## Full list of solvers

docs/src/explicit/SSPRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Note that for SSPRK methods, a algorithm utility `OrdinaryDiffEqCore.ssp_coeffic
1414

1515
```@eval
1616
first_steps = evalfile("./common_first_steps.jl")
17-
first_steps("OrdinaryDiffEqSSPRK", "SSPRK22")
17+
first_steps("OrdinaryDiffEqSSPRK", "SSPRK432")
1818
```
1919

2020
## Full list of solvers

docs/src/implicit/PDIRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ which is why these are the parallel DIRK methods.
2424

2525
```@eval
2626
first_steps = evalfile("./common_first_steps.jl")
27-
first_steps("OrdinaryDiffEqPDIRK", "PDIRK44")
27+
first_steps("OrdinaryDiffEqPDIRK", "PDIRK44", fixed_timesteps = true)
2828
```
2929

3030
## Full list of solvers

docs/src/implicit/SDIRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This article is a stub.
88

99
```@eval
1010
first_steps = evalfile("./common_first_steps.jl")
11-
first_steps("OrdinaryDiffEqSDIRK", "PDIRK44")
11+
first_steps("OrdinaryDiffEqSDIRK", "KenCarp3")
1212
```
1313

1414
## Full list of solvers

docs/src/semiimplicit/ExponentialRK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ you will need to install some of the other libraries listed in the navigation ba
2323

2424
```@eval
2525
first_steps = evalfile("./common_first_steps.jl")
26-
first_steps("OrdinaryDiffEqExponentialRK", "EPIRK5s3")
26+
first_steps("OrdinaryDiffEqExponentialRK", "Exprb43", fixed_timesteps = true)
2727
```
2828

2929
## Full list of solvers

0 commit comments

Comments
 (0)