Skip to content

Commit f8f8307

Browse files
Update Rosenbrock method docs.
1 parent aa44608 commit f8f8307

File tree

6 files changed

+501
-78
lines changed

6 files changed

+501
-78
lines changed

docs/src/stiff/rosenbrock.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
## Standard Rosenbrock Methods
44

55
```@docs
6-
ROS2
7-
ROS3
8-
ROS2PR
9-
ROS3PR
10-
Scholz47
11-
ROS3PRL
12-
ROS3PRL2
136
ROS3P
147
Rodas3
158
Rodas3P
@@ -25,7 +18,6 @@ Rodas4P
2518
Rodas4P2
2619
Rodas5
2720
Rodas5P
28-
GeneralRosenbrock
2921
```
3022

3123
## Rosenbrock W-Methods
@@ -39,6 +31,13 @@ ROS34PW1b
3931
ROS34PW2
4032
ROS34PW3
4133
ROS34PRw
34+
ROS2
35+
ROS3
4236
ROS2S
4337
RosenbrockW6S4OS
38+
ROS2PR
39+
ROS3PR
40+
Scholz4_7
41+
ROS3PRL
42+
ROS3PRL2
4443
```

src/OrdinaryDiffEq.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import Preferences
128128

129129
DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothing
130130

131+
include("doc_utils.jl")
131132
include("misc_utils.jl")
132133

133134
include("algorithms.jl")

src/algorithms.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,10 +3118,15 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = true,
31183118
_unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau,
31193119
factorization)
31203120
end
3121+
3122+
@doc rosenbrock_wanner_docstring(
31213123
"""
3122-
RosenbrockW6S4OS: Rosenbrock-W Method
31233124
A 4th order L-stable Rosenbrock-W method (fixed step only).
3124-
"""
3125+
""",
3126+
"RosenbrockW6S4OS",
3127+
references = """
3128+
https://doi.org/10.1016/j.cam.2009.09.017
3129+
""")
31253130
struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <:
31263131
OrdinaryDiffEqRosenbrockAlgorithm{CS, AD, FDT, ST, CJ}
31273132
linsolve::F

src/algorithms/explicit_rk.jl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ function Base.show(io::IO, alg::OrdinaryDiffEqAlgorithm)
55
end
66
print(io, ")")
77
end
8-
function explicit_rk_docstring(description::String,
9-
name::String;
10-
references::String = "",
11-
extra_keyword_description = "",
12-
extra_keyword_default = "")
13-
if !isempty(extra_keyword_default)
14-
extra_keyword_default = "\n" * repeat(" ", 8) * extra_keyword_default
15-
end
16-
start_docstring = """
17-
```julia
18-
$name(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!,
19-
step_limiter! = OrdinaryDiffEq.trivial_limiter!,
20-
thread = OrdinaryDiffEq.False(),$extra_keyword_default)
21-
```
22-
23-
Explicit Runge-Kutta Method.
24-
"""
25-
keyword_docstring = """
26-
27-
### Keyword Arguments
28-
29-
- `stage_limiter!`: function of the form `limiter!(u, integrator, p, t)`
30-
- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`
31-
- `thread`: determines whether internal broadcasting on
32-
appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`,
33-
default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when
34-
Julia is started with multiple threads.
35-
"""
36-
start_docstring * description * keyword_docstring * extra_keyword_description *
37-
"## References\n" * references
38-
end
398

409
@doc explicit_rk_docstring(
4110
"The second order Heun's method. Uses embedded Euler method for adaptivity.",

src/doc_utils.jl

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""
2+
Utility function to help generating consistent docstrings across the package.
3+
"""
4+
# TODO we should add a consistency check using the string $name(; $keyword_default) against the standard console output of name()
5+
function generic_solver_docstring(description::String,
6+
name::String,
7+
solver_class::String,
8+
references::String,
9+
keyword_description::String,
10+
keyword_default::String)
11+
if !isempty(keyword_default)
12+
# Chunk string and remove empty lines
13+
kws = split(keyword_default, "\n")
14+
keywords_split = [kw for kw in kws if !isempty(rstrip(kw))]
15+
16+
# Indent the keywords properly
17+
indentation = repeat(" ", length(name)+3)
18+
# We do not indent the first kw and no newline for the last one
19+
if length(keyword_default) > 1
20+
keywords_split[1] = keywords_split[1] * "\n"
21+
for i in 2:(length(keywords_split)-1)
22+
keywords_split[i] = indentation * keywords_split[i] * "\n"
23+
end
24+
keywords_split[end] = indentation * keywords_split[end]
25+
end
26+
# Flatten into string
27+
keyword_default = join(keywords_split)
28+
# Remove trailing comma
29+
keyword_default = strip(keyword_default, [','])
30+
end
31+
start_docstring = !isempty(keyword_default) ? """
32+
```julia
33+
$name(; $keyword_default)
34+
```
35+
36+
$solver_class
37+
""" :
38+
"""
39+
```julia
40+
$name()
41+
```
42+
43+
$solver_class
44+
"""
45+
46+
keyword_docstring = """
47+
48+
### Keyword Arguments
49+
50+
$keyword_description
51+
"""
52+
53+
return start_docstring * description * keyword_docstring *
54+
"## References\n" * references
55+
end
56+
57+
function explicit_rk_docstring(description::String,
58+
name::String;
59+
references::String = "",
60+
extra_keyword_description::String = "",
61+
extra_keyword_default::String = "")
62+
keyword_default = """
63+
stage_limiter! = OrdinaryDiffEq.trivial_limiter!,
64+
step_limiter! = OrdinaryDiffEq.trivial_limiter!,
65+
""" * extra_keyword_default
66+
67+
keyword_default_description = """
68+
- `stage_limiter!`: function of the form `limiter!(u, integrator, p, t)`
69+
- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`
70+
""" * extra_keyword_description
71+
72+
generic_solver_docstring(
73+
description, name, "Explicit Runge-Kutta Method. ", references,
74+
keyword_default_description, keyword_default
75+
)
76+
end
77+
78+
function rosenbrock_docstring(description::String,
79+
name::String;
80+
references::String = "",
81+
extra_keyword_description = "",
82+
extra_keyword_default = "",
83+
with_step_limiter = false)
84+
keyword_default = """
85+
autodiff = Val{true}(),
86+
concrete_jac = nothing,
87+
linsolve = nothing,
88+
precs = DEFAULT_PRECS,
89+
""" * extra_keyword_default
90+
91+
keyword_default_description = """
92+
- `autodiff`: boolean to control if the Jacobian should be computed via AD or not
93+
- `concrete_jac`: function of the form `jac!(J, u, p, t)`
94+
- `linsolve`: custom solver for the inner linear systems
95+
- `precs`: custom preconditioner for the inner linear solver
96+
""" * extra_keyword_description
97+
98+
if with_step_limiter
99+
keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n"
100+
keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n"
101+
end
102+
103+
generic_solver_docstring(
104+
description, name, "Rosenbrock Method. ", references,
105+
keyword_default_description, keyword_default
106+
)
107+
end
108+
109+
function rosenbrock_wanner_docstring(description::String,
110+
name::String;
111+
references::String = "",
112+
extra_keyword_description = "",
113+
extra_keyword_default = "",
114+
with_step_limiter = false)
115+
keyword_default = """
116+
autodiff = Val{true}(),
117+
concrete_jac = nothing,
118+
linsolve = nothing,
119+
precs = DEFAULT_PRECS,
120+
""" * extra_keyword_default
121+
122+
keyword_default_description = """
123+
- `autodiff`: boolean to control if the Jacobian should be computed via AD or not
124+
- `concrete_jac`: function of the form `jac!(J, u, p, t)`
125+
- `linsolve`: custom solver for the inner linear systems
126+
- `precs`: custom preconditioner for the inner linear solver
127+
""" * extra_keyword_description
128+
129+
if with_step_limiter
130+
keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n"
131+
keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n"
132+
end
133+
134+
generic_solver_docstring(
135+
description, name, "Rosenbrock-Wanner Method. ", references,
136+
keyword_default_description, keyword_default
137+
)
138+
end
139+
140+
# TODO other classes

0 commit comments

Comments
 (0)