Skip to content

Commit 12c0186

Browse files
Add steady state docs and MINPACK
1 parent 87d4ae9 commit 12c0186

File tree

6 files changed

+164
-12
lines changed

6 files changed

+164
-12
lines changed

docs/pages.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ pages = ["index.md",
55
"tutorials/iterator_interface.md"],
66
"Basics" => Any["basics/NonlinearProblem.md",
77
"basics/NonlinearFunctions.md",
8+
"basics/NonlinearSolution.md",
89
"basics/FAQ.md"],
910
"Solvers" => Any["solvers/NonlinearSystemSolvers.md",
10-
"solvers/BracketingSolvers.md"],
11+
"solvers/BracketingSolvers.md",
12+
"solvers/SteadyStateSolvers.md"],
1113
]

docs/src/basics/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ MATLAB 2022a achieves 1.66s. Try this code yourself: we receive 0.06 seconds, or
3535
This example is still not optimized in the Julia code and we expect an improvement in a near
3636
future version.
3737

38-
For more information on performance of SciML, see the [SciMLBenchmarks](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/)
38+
For more information on performance of SciML, see the [SciMLBenchmarks](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/).

docs/src/basics/NonlinearProblem.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,46 @@
11
# Nonlinear Problems
22

3-
## The Two Types of Nonlinear Problems
3+
## The Three Types of Nonlinear Problems
44

55
NonlinearSolve.jl tackles two related types of nonlinear systems:
66

77
1. Interval rootfinding problems. I.e., find the ``t in [t_0, t_f]`` such that `f(t) = 0`.
88
2. Systems of nonlinear equations, i.e. find the `u` such that `f(u) = 0`.
9+
3. Steady state problems, i.e. find the `u` such that `u' = f(u,t)` has reached steady state,
10+
i.e. `0 = f(u, ∞)`.
911

10-
The former is for solving scalar rootfinding problems, i.e. finding a single number, and
12+
The first is for solving scalar rootfinding problems, i.e. finding a single number, and
1113
requires that a bracketing interval is known. For a bracketing interval, one must have that
1214
the sign of `f(t_0)` is opposite the sign of `f(t_f)`, thus guaranteeing a root in the
1315
interval.
1416

15-
The latter type of nonlinear system can be multidimensional and thus no ordering nor
16-
boundaries are assumed to be known. For a system of nonlinear equations, `f` can return
17-
an array and the solver seeks to find the value of `u` for which all outputs of `f` are
18-
simultaniously zero.
19-
2017
!!! note
2118

2219
Interval rootfinding problems allow for `f` to return an array, in which case the interval
2320
rootfinding problem is interpreted as finding the first `t` such that any of the components
2421
of the array hit zero.
2522

23+
The second type of nonlinear system can be multidimensional and thus no ordering nor
24+
boundaries are assumed to be known. For a system of nonlinear equations, `f` can return
25+
an array and the solver seeks to find the value of `u` for which all outputs of `f` are
26+
simultaniously zero.
27+
28+
The last type if equivalent to a nonlinear system but with the extra interpretion of
29+
having a potentially preferred unique root. That is, when there are multiple `u` such
30+
that `f(u) = 0`, the `NonlinearProblem` does not have a preferred solution, while for the
31+
`SteadyStateProblem` the preferred solution is the `u(∞)` that would arise from solving the
32+
ODE `u' = f(u,t)`.
33+
34+
!!! warn
35+
36+
Most solvers for `SteadyStateProblem` do not guarentee the preferred solution and
37+
instead will solve for some `u` in the set of solutions. The documentation of the
38+
nonlinear solvers will note if they return the preferred solution.
2639

2740
## Problem Construction Details
2841

2942
```@docs
3043
SciMLBase.IntervalNonlinearProblem
3144
SciMLBase.NonlinearProblem
45+
SciMLBase.SteadyStateProblem
3246
```

docs/src/basics/NonlinearSolution.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Nonlinear Solutions
2+
3+
```@docs
4+
SciMLBase.NonlinearSolution
5+
```

docs/src/solvers/NonlinearSystemSolvers.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ is an implementation which is specialized for small equations. It is non-allocat
1717
static arrays and thus really well-optimized for small systems, thus usually outperforming
1818
the other methods when such types are used for `u0`. `NLSolveJL`'s
1919
`:trust_region` method can be a good choice for high stability, along with
20-
`CMINPACK`.s
20+
`DynamicSS`.
2121

2222
For a system which is very non-stiff (i.e., the condition number of the Jacobian
2323
is small, or the eigenvalues of the Jacobian are within a few orders of magnitude),
@@ -51,9 +51,48 @@ can be used directly to reduce dependencies and improve load times.
5151
very efficient and non-allocating. Thus this implmentation is well-suited for small
5252
systems of equations.
5353

54+
### SteadyStateDiffEq.jl
55+
56+
Note that these solvers do not come by default, and thus one needs to install
57+
the package before using these solvers:
58+
59+
```julia
60+
]add SteadyStateDiffEq
61+
using SteadyStateDiffEq
62+
```
63+
64+
SteadyStateDiffEq.jl uses ODE solvers to iteratively approach the steady state. It is a
65+
very stable method for solving nonlinear systems, though in many cases can be more
66+
computationally expensive than direct methods.
67+
68+
- `DynamicSS` : Uses an ODE solver to find the steady state. Automatically
69+
terminates when close to the steady state.
70+
`DynamicSS(alg;abstol=1e-8,reltol=1e-6,tspan=Inf)` requires that an
71+
ODE algorithm is given as the first argument. The absolute and
72+
relative tolerances specify the termination conditions on the
73+
derivative's closeness to zero. This internally uses the
74+
`TerminateSteadyState` callback from the Callback Library. The
75+
simulated time for which given ODE is solved can be limited by
76+
`tspan`. If `tspan` is a number, it is equivalent to passing
77+
`(zero(tspan), tspan)`.
78+
79+
Example usage:
80+
81+
```julia
82+
using NonlinearSolve, SteadyStateDiffEq, OrdinaryDiffEq
83+
sol = solve(prob,DynamicSS(Tsit5()))
84+
85+
using Sundials
86+
sol = solve(prob,DynamicSS(CVODE_BDF()),dt=1.0)
87+
```
88+
89+
!!! note
90+
91+
If you use `CVODE_BDF` you may need to give a starting `dt` via `dt=....`.*
92+
5493
### SciMLNLSolve.jl
5594

56-
This is a wrapper package for importing solvers from other packages into this interface.
95+
This is a wrapper package for importing solvers from NLsolve.jl into this interface.
5796
Note that these solvers do not come by default, and thus one needs to install
5897
the package before using these solvers:
5998

@@ -62,7 +101,6 @@ the package before using these solvers:
62101
using SciMLNLSolve
63102
```
64103

65-
- `CMINPACK()`: A wrapper for using the classic MINPACK method through [MINPACK.jl](https://github.com/sglyon/MINPACK.jl)
66104
- `NLSolveJL()`: A wrapper for [NLsolve.jl](https://github.com/JuliaNLSolvers/NLsolve.jl)
67105

68106
```julia
@@ -134,3 +172,34 @@ The choices for the linear solver are:
134172
- `:KLU`: A sparse factorization method. Requires that the user specify a
135173
Jacobian. The Jacobian must be set as a sparse matrix in the `ODEProblem`
136174
type.
175+
176+
### NonlinearSolveMINPACK
177+
178+
This is a wrapper package for importing solvers from MINPACK.jl into this interface.
179+
Note that these solvers do not come by default, and thus one needs to install
180+
the package before using these solvers:
181+
182+
```julia
183+
]add NonlinearSolveMINPACK
184+
using NonlinearSolveMINPACK
185+
```
186+
187+
- `CMINPACK()`: A wrapper for using the classic MINPACK method through [MINPACK.jl](https://github.com/sglyon/MINPACK.jl)
188+
189+
```julia
190+
CMINPACK(;show_trace::Bool=false, tracing::Bool=false, method::Symbol=:hybr,
191+
io::IO=stdout)
192+
```
193+
194+
The keyword argument `method` can take on different value depending on which method of `fsolve` you are calling. The standard choices of `method` are:
195+
196+
- `:hybr`: Modified version of Powell's algorithm. Uses MINPACK routine [`hybrd1`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/hybrd1.c)
197+
- `:lm`: Levenberg-Marquardt. Uses MINPACK routine [`lmdif1`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/lmdif1.c)
198+
- `:lmdif`: Advanced Levenberg-Marquardt (more options available with `;kwargs...`). See MINPACK routine [`lmdif`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/lmdif.c) for more information
199+
- `:hybrd`: Advacned modified version of Powell's algorithm (more options available with `;kwargs...`). See MINPACK routine [`hybrd`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/hybrd.c) for more information
200+
201+
If a Jacobian is supplied as part of the [`NonlinearFunction`](@ref nonlinearfunctions),
202+
then the following methods are allowed:
203+
204+
- `:hybr`: Advacned modified version of Powell's algorithm with user supplied Jacobian. Additional arguments are available via `;kwargs...`. See MINPACK routine [`hybrj`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/hybrj.c) for more information
205+
- `:lm`: Advanced Levenberg-Marquardt with user supplied Jacobian. Additional arguments are available via `;kwargs...`. See MINPACK routine [`lmder`](https://github.com/devernay/cminpack/blob/d1f5f5a273862ca1bbcf58394e4ac060d9e22c76/lmder.c) for more information
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Steady State Solvers
2+
3+
`solve(prob::SteadyStateProblem,alg;kwargs)`
4+
5+
Solves for the steady states in the problem defined by `prob` using the algorithm
6+
`alg`. If no algorithm is given, a default algorithm will be chosen.
7+
8+
## Recommended Methods
9+
10+
Conversion to a NonlinearProblem is generally the fastest method. However, this will not
11+
guarantee the preferred root, and thus if the preferred root is required, then it's
12+
recommended that one uses `DynamicSS`. For `DynamicSS`, in many cases an adaptive stiff
13+
solver, like a Rosenbrock or BDF method (`Rodas5` or `QNDF`), is a good way to allow for
14+
very large time steps as the steady state approaches.
15+
16+
!!! note
17+
18+
The SteadyStateDiffEq.jl methods on a `SteadyStateProblem` respect the time definition
19+
in the nonlinear definition, i.e. `u' = f(u,t)` uses the correct values for `t` as the
20+
solution evolves. A conversion of a `SteadyStateProblem` to a `NonlinearProblem`
21+
replaces this with the nonlinear system `u' = f(u,∞)`, and thus the direct
22+
`SteadyStateProblem` approach can give different answers (i.e. the correct unique
23+
fixed point) on ODEs with non-autonomous dynamics.
24+
25+
## Full List of Methods
26+
27+
### Conversion to NonlinearProblem
28+
29+
Any `SteadyStateProblem` can be trivially converted to a `NonlinearProblem` via
30+
`NonlinearProblem(prob::SteadyStateProblem)`. Using this appraoch, any of the solvers from
31+
the [Nonlinear System Solvers page](@ref nonlinearsystemsolvers) can be used.
32+
33+
### SteadyStateDiffEq.jl
34+
35+
SteadyStateDiffEq.jl uses ODE solvers to iteratively approach the steady state. It is a
36+
very stable method for solving nonlinear systems, though in many cases can be more
37+
computationally expensive than direct methods.
38+
39+
- `DynamicSS` : Uses an ODE solver to find the steady state. Automatically
40+
terminates when close to the steady state.
41+
`DynamicSS(alg;abstol=1e-8,reltol=1e-6,tspan=Inf)` requires that an
42+
ODE algorithm is given as the first argument. The absolute and
43+
relative tolerances specify the termination conditions on the
44+
derivative's closeness to zero. This internally uses the
45+
`TerminateSteadyState` callback from the Callback Library. The
46+
simulated time for which given ODE is solved can be limited by
47+
`tspan`. If `tspan` is a number, it is equivalent to passing
48+
`(zero(tspan), tspan)`.
49+
50+
Example usage:
51+
52+
```julia
53+
using NonlinearSolve, SteadyStateDiffEq, OrdinaryDiffEq
54+
sol = solve(prob,DynamicSS(Tsit5()))
55+
56+
using Sundials
57+
sol = solve(prob,DynamicSS(CVODE_BDF()),dt=1.0)
58+
```
59+
60+
!!! note
61+
62+
If you use `CVODE_BDF` you may need to give a starting `dt` via `dt=....`.*

0 commit comments

Comments
 (0)