Skip to content

Commit

Permalink
Merge pull request #2222 from termi-official/do/rosenbrock-docs
Browse files Browse the repository at this point in the history
Documentation for Rosenbrock methods
  • Loading branch information
ChrisRackauckas authored May 24, 2024
2 parents 89341dc + f8f8307 commit c9a578c
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 78 deletions.
15 changes: 7 additions & 8 deletions docs/src/stiff/rosenbrock.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
## Standard Rosenbrock Methods

```@docs
ROS2
ROS3
ROS2PR
ROS3PR
Scholz47
ROS3PRL
ROS3PRL2
ROS3P
Rodas3
Rodas3P
Expand All @@ -25,7 +18,6 @@ Rodas4P
Rodas4P2
Rodas5
Rodas5P
GeneralRosenbrock
```

## Rosenbrock W-Methods
Expand All @@ -39,6 +31,13 @@ ROS34PW1b
ROS34PW2
ROS34PW3
ROS34PRw
ROS2
ROS3
ROS2S
RosenbrockW6S4OS
ROS2PR
ROS3PR
Scholz4_7
ROS3PRL
ROS3PRL2
```
1 change: 1 addition & 0 deletions src/OrdinaryDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import Preferences

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

include("doc_utils.jl")
include("misc_utils.jl")

include("algorithms.jl")
Expand Down
9 changes: 7 additions & 2 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3118,10 +3118,15 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = true,
_unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau,
factorization)
end

@doc rosenbrock_wanner_docstring(
"""
RosenbrockW6S4OS: Rosenbrock-W Method
A 4th order L-stable Rosenbrock-W method (fixed step only).
"""
""",
"RosenbrockW6S4OS",
references = """
https://doi.org/10.1016/j.cam.2009.09.017
""")
struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <:
OrdinaryDiffEqRosenbrockAlgorithm{CS, AD, FDT, ST, CJ}
linsolve::F
Expand Down
31 changes: 0 additions & 31 deletions src/algorithms/explicit_rk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@ function Base.show(io::IO, alg::OrdinaryDiffEqAlgorithm)
end
print(io, ")")
end
function explicit_rk_docstring(description::String,
name::String;
references::String = "",
extra_keyword_description = "",
extra_keyword_default = "")
if !isempty(extra_keyword_default)
extra_keyword_default = "\n" * repeat(" ", 8) * extra_keyword_default
end
start_docstring = """
```julia
$name(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!,
step_limiter! = OrdinaryDiffEq.trivial_limiter!,
thread = OrdinaryDiffEq.False(),$extra_keyword_default)
```
Explicit Runge-Kutta Method.
"""
keyword_docstring = """
### Keyword Arguments
- `stage_limiter!`: function of the form `limiter!(u, integrator, p, t)`
- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`
- `thread`: determines whether internal broadcasting on
appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`,
default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when
Julia is started with multiple threads.
"""
start_docstring * description * keyword_docstring * extra_keyword_description *
"## References\n" * references
end

@doc explicit_rk_docstring(
"The second order Heun's method. Uses embedded Euler method for adaptivity.",
Expand Down
140 changes: 140 additions & 0 deletions src/doc_utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Utility function to help generating consistent docstrings across the package.
"""
# TODO we should add a consistency check using the string $name(; $keyword_default) against the standard console output of name()
function generic_solver_docstring(description::String,
name::String,
solver_class::String,
references::String,
keyword_description::String,
keyword_default::String)
if !isempty(keyword_default)
# Chunk string and remove empty lines
kws = split(keyword_default, "\n")
keywords_split = [kw for kw in kws if !isempty(rstrip(kw))]

# Indent the keywords properly
indentation = repeat(" ", length(name)+3)
# We do not indent the first kw and no newline for the last one
if length(keyword_default) > 1
keywords_split[1] = keywords_split[1] * "\n"
for i in 2:(length(keywords_split)-1)
keywords_split[i] = indentation * keywords_split[i] * "\n"
end
keywords_split[end] = indentation * keywords_split[end]
end
# Flatten into string
keyword_default = join(keywords_split)
# Remove trailing comma
keyword_default = strip(keyword_default, [','])
end
start_docstring = !isempty(keyword_default) ? """
```julia
$name(; $keyword_default)
```
$solver_class
""" :
"""
```julia
$name()
```
$solver_class
"""

keyword_docstring = """
### Keyword Arguments
$keyword_description
"""

return start_docstring * description * keyword_docstring *
"## References\n" * references
end

function explicit_rk_docstring(description::String,
name::String;
references::String = "",
extra_keyword_description::String = "",
extra_keyword_default::String = "")
keyword_default = """
stage_limiter! = OrdinaryDiffEq.trivial_limiter!,
step_limiter! = OrdinaryDiffEq.trivial_limiter!,
""" * extra_keyword_default

keyword_default_description = """
- `stage_limiter!`: function of the form `limiter!(u, integrator, p, t)`
- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`
""" * extra_keyword_description

generic_solver_docstring(
description, name, "Explicit Runge-Kutta Method. ", references,
keyword_default_description, keyword_default
)
end

function rosenbrock_docstring(description::String,
name::String;
references::String = "",
extra_keyword_description = "",
extra_keyword_default = "",
with_step_limiter = false)
keyword_default = """
autodiff = Val{true}(),
concrete_jac = nothing,
linsolve = nothing,
precs = DEFAULT_PRECS,
""" * extra_keyword_default

keyword_default_description = """
- `autodiff`: boolean to control if the Jacobian should be computed via AD or not
- `concrete_jac`: function of the form `jac!(J, u, p, t)`
- `linsolve`: custom solver for the inner linear systems
- `precs`: custom preconditioner for the inner linear solver
""" * extra_keyword_description

if with_step_limiter
keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n"
keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n"
end

generic_solver_docstring(
description, name, "Rosenbrock Method. ", references,
keyword_default_description, keyword_default
)
end

function rosenbrock_wanner_docstring(description::String,
name::String;
references::String = "",
extra_keyword_description = "",
extra_keyword_default = "",
with_step_limiter = false)
keyword_default = """
autodiff = Val{true}(),
concrete_jac = nothing,
linsolve = nothing,
precs = DEFAULT_PRECS,
""" * extra_keyword_default

keyword_default_description = """
- `autodiff`: boolean to control if the Jacobian should be computed via AD or not
- `concrete_jac`: function of the form `jac!(J, u, p, t)`
- `linsolve`: custom solver for the inner linear systems
- `precs`: custom preconditioner for the inner linear solver
""" * extra_keyword_description

if with_step_limiter
keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n"
keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n"
end

generic_solver_docstring(
description, name, "Rosenbrock-Wanner Method. ", references,
keyword_default_description, keyword_default
)
end

# TODO other classes
Loading

0 comments on commit c9a578c

Please sign in to comment.