Skip to content

Commit 41fdbfa

Browse files
Add comprehensive docstrings for ODE algorithms
- Added detailed docstrings for CompositeAlgorithm and AutoSwitch in OrdinaryDiffEqCore - Added docstrings for all Rosenbrock methods in OrdinaryDiffEqRosenbrock - Included parameter descriptions, usage guidance, and method characteristics - Enhanced documentation for algorithm switching strategies and stiffness detection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent fc31058 commit 41fdbfa

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

lib/OrdinaryDiffEqCore/src/algorithms.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ end
9191

9292
#########################################
9393

94+
"""
95+
CompositeAlgorithm(algs, choice_function)
96+
97+
A composite algorithm that chooses between multiple ODE solvers based on a user-defined choice function.
98+
This allows for adaptive algorithm switching based on problem characteristics or performance metrics.
99+
100+
# Arguments
101+
- `algs`: Tuple or array of ODE algorithms to choose from
102+
- `choice_function`: Function that determines which algorithm to use at each step
103+
104+
The choice function receives the integrator and should return an index indicating which algorithm to use.
105+
This enables sophisticated algorithm switching strategies based on solution behavior, step size, or other criteria.
106+
"""
94107
struct CompositeAlgorithm{CS, T, F} <: OrdinaryDiffEqCompositeAlgorithm
95108
algs::T
96109
choice_function::F
@@ -149,6 +162,28 @@ mutable struct AutoSwitchCache{nAlg, sAlg, tolType, T}
149162
end
150163
end
151164

165+
"""
166+
AutoSwitch(nonstiffalg, stiffalg; kwargs...)
167+
168+
An automatic algorithm switching method that dynamically chooses between a nonstiff and stiff solver
169+
based on the problem's stiffness detection. This provides robust performance across a wide range of problems
170+
without requiring the user to know the problem's stiffness characteristics a priori.
171+
172+
# Arguments
173+
- `nonstiffalg`: Algorithm to use for nonstiff regions (default: Tsit5())
174+
- `stiffalg`: Algorithm to use for stiff regions (default: Rodas5P())
175+
176+
# Keywords
177+
- `maxstiffstep`: Maximum number of consecutive steps before switching from nonstiff to stiff (default: 10)
178+
- `maxnonstiffstep`: Maximum number of consecutive steps before switching from stiff to nonstiff (default: 3)
179+
- `nonstifftol`: Tolerance for detecting nonstiff behavior (default: 3//4)
180+
- `stifftol`: Tolerance for detecting stiff behavior (default: 9//10)
181+
- `dtfac`: Factor for step size adjustment during switches (default: 2.0)
182+
- `stiffalgfirst`: Whether to start with the stiff algorithm (default: false)
183+
- `switch_max`: Maximum number of algorithm switches allowed (default: 10)
184+
185+
The switching decision is based on step size rejections and stability estimates.
186+
"""
152187
struct AutoSwitch{nAlg, sAlg, tolType, T}
153188
nonstiffalg::nAlg
154189
stiffalg::sAlg

lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,46 @@ Rosenbrock23
138138
"Rodas5P", with_step_limiter = true)
139139
Rodas5P
140140

141+
@doc rosenbrock_docstring(
142+
"A 3/2-order L-stable Rosenbrock-W method optimized for stiff problems. Good balance of accuracy and computational efficiency.",
143+
"Rosenbrock32", with_step_limiter = true)
144+
Rosenbrock32
145+
146+
@doc rosenbrock_docstring(
147+
"A 3rd-order accurate L-stable Rosenbrock method designed for parabolic problems. Particularly effective for reaction-diffusion equations.",
148+
"ROS3P", with_step_limiter = true)
149+
ROS3P
150+
151+
@doc rosenbrock_docstring(
152+
"A 3rd-order accurate L-stable Rosenbrock method from Hairer and Wanner. Good general-purpose stiff ODE solver with moderate computational cost.",
153+
"Rodas3", with_step_limiter = true)
154+
Rodas3
155+
156+
@doc rosenbrock_docstring(
157+
"A 4th-order accurate L-stable Rosenbrock method. Well-suited for moderately stiff problems with good efficiency.",
158+
"Rodas4", with_step_limiter = true)
159+
Rodas4
160+
161+
@doc rosenbrock_docstring(
162+
"A 4th-order accurate L-stable Rosenbrock method with improved error estimation. Enhanced version of Rodas4 for better step size control.",
163+
"Rodas42", with_step_limiter = true)
164+
Rodas42
165+
166+
@doc rosenbrock_docstring(
167+
"A 4th-order accurate L-stable Rosenbrock method designed for differential-algebraic equations (DAEs). Optimized for index-1 DAE problems.",
168+
"Rodas4P", with_step_limiter = true)
169+
Rodas4P
170+
171+
@doc rosenbrock_docstring(
172+
"An improved 4th-order accurate L-stable Rosenbrock method for DAEs with enhanced stability properties.",
173+
"Rodas4P2", with_step_limiter = true)
174+
Rodas4P2
175+
176+
@doc rosenbrock_docstring(
177+
"A 5th-order accurate L-stable Rosenbrock method for differential-algebraic problems. Higher accuracy but increased computational cost.",
178+
"Rodas5", with_step_limiter = true)
179+
Rodas5
180+
141181
struct GeneralRosenbrock{CS, AD, F, ST, CJ, TabType} <:
142182
OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, Val{:forward}, ST, CJ}
143183
tableau::TabType
@@ -225,3 +265,68 @@ for Alg in [
225265
end
226266
end
227267
end
268+
269+
@doc rosenbrock_docstring(
270+
"A 2nd-order accurate L-stable Rosenbrock method. Simple and robust for moderately stiff problems with lower accuracy requirements.",
271+
"ROS2")
272+
ROS2
273+
274+
@doc rosenbrock_docstring(
275+
"A 2nd-order accurate L-stable Rosenbrock method optimized for the Prothero-Robinson test problem. Good for oscillatory stiff problems.",
276+
"ROS2PR")
277+
ROS2PR
278+
279+
@doc rosenbrock_docstring(
280+
"A 2nd-order accurate L-stable Rosenbrock method with enhanced stability properties. Variant of ROS2 with improved behavior.",
281+
"ROS2S")
282+
ROS2S
283+
284+
@doc rosenbrock_docstring(
285+
"A 3rd-order accurate L-stable Rosenbrock method from Hairer and Wanner. Well-established method for general stiff ODEs.",
286+
"ROS3")
287+
ROS3
288+
289+
@doc rosenbrock_docstring(
290+
"A 3rd-order accurate L-stable Rosenbrock method optimized for the Prothero-Robinson test problem. Good for stiff oscillatory systems.",
291+
"ROS3PR")
292+
ROS3PR
293+
294+
@doc rosenbrock_docstring(
295+
"A 4th-order accurate L-stable Rosenbrock method with optimized stability function. Enhanced performance for certain stiff problem classes.",
296+
"Scholz4_7")
297+
Scholz4_7
298+
299+
@doc rosenbrock_docstring(
300+
"A 4th-order accurate L-stable Rosenbrock method with improved embedded error estimator. Part of the ROS34PW family of methods.",
301+
"ROS34PW1a")
302+
ROS34PW1a
303+
304+
@doc rosenbrock_docstring(
305+
"A 4th-order accurate L-stable Rosenbrock method with alternative embedded error estimator. Variant in the ROS34PW family.",
306+
"ROS34PW1b")
307+
ROS34PW1b
308+
309+
@doc rosenbrock_docstring(
310+
"A 4th-order accurate L-stable Rosenbrock method with enhanced embedded error estimation. Second variant in the ROS34PW family.",
311+
"ROS34PW2")
312+
ROS34PW2
313+
314+
@doc rosenbrock_docstring(
315+
"A 4th-order accurate L-stable Rosenbrock method with optimized embedded error estimator. Third variant in the ROS34PW family.",
316+
"ROS34PW3")
317+
ROS34PW3
318+
319+
@doc rosenbrock_docstring(
320+
"A 4th-order accurate L-stable Rosenbrock method designed for improved traditional Rosenbrock-Wanner methods for stiff ODEs and DAEs.",
321+
"ROS34PRw")
322+
ROS34PRw
323+
324+
@doc rosenbrock_docstring(
325+
"A 4th-order accurate L-stable Rosenbrock method implemented by Shampine. Classical implementation of a 4th-order Rosenbrock method.",
326+
"RosShamp4")
327+
RosShamp4
328+
329+
@doc rosenbrock_docstring(
330+
"A 4th-order accurate L-stable Rosenbrock method optimized for L-stability. Enhanced stability properties from Hairer and Wanner.",
331+
"Ros4LStab")
332+
Ros4LStab

0 commit comments

Comments
 (0)