Skip to content

Commit b490926

Browse files
committed
Same environment for ill conditioned nlprob
Signed-off-by: ErikQQY <[email protected]>
1 parent daea27f commit b490926

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
23
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
34
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
45
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
@@ -13,6 +14,7 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
1314
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1415

1516
[compat]
17+
AlgebraicMultigrid = "0.5"
1618
BenchmarkTools = "1"
1719
Documenter = "0.27"
1820
IncompleteLU = "0.2"

docs/src/tutorials/advanced.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ are then applied at each point in space (they are broadcast). Use `dx=dy=1/32`.
5454

5555
The resulting `NonlinearProblem` definition is:
5656

57-
```@example
57+
```@example ill_conditioned_nlprob
5858
using NonlinearSolve, LinearAlgebra, SparseArrays, LinearSolve
5959
6060
const N = 32
@@ -130,7 +130,7 @@ in action, we can give an example `du` and `u` and call `jacobian_sparsity`
130130
on our function with the example arguments, and it will kick out a sparse matrix
131131
with our pattern, that we can turn into our `jac_prototype`.
132132

133-
```@example
133+
```@example ill_conditioned_nlprob
134134
using Symbolics
135135
du0 = copy(u0)
136136
jac_sparsity = Symbolics.jacobian_sparsity((du, u) -> brusselator_2d_loop(du, u, p),
@@ -141,19 +141,19 @@ Notice that Julia gives a nice print out of the sparsity pattern. That's neat, a
141141
would be tedious to build by hand! Now we just pass it to the `NonlinearFunction`
142142
like as before:
143143

144-
```@example
144+
```@example ill_conditioned_nlprob
145145
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))
146146
```
147147

148148
Build the `NonlinearProblem`:
149149

150-
```@example
150+
```@example ill_conditioned_nlprob
151151
prob_brusselator_2d_sparse = NonlinearProblem(ff, u0, p)
152152
```
153153

154154
Now let's see how the version with sparsity compares to the version without:
155155

156-
```@example
156+
```@example ill_conditioned_nlprob
157157
using BenchmarkTools # for @btime
158158
@btime solve(prob_brusselator_2d, NewtonRaphson());
159159
@btime solve(prob_brusselator_2d_sparse, NewtonRaphson());
@@ -172,7 +172,7 @@ matrices is to use a Krylov subspace method. This requires choosing a linear
172172
solver for changing to a Krylov method. To swap the linear solver out, we use
173173
the `linsolve` command and choose the GMRES linear solver.
174174

175-
```@example
175+
```@example ill_conditioned_nlprob
176176
@btime solve(prob_brusselator_2d, NewtonRaphson(linsolve = KrylovJL_GMRES()));
177177
nothing # hide
178178
```
@@ -197,7 +197,7 @@ approximate the inverse of `W = I - gamma*J` used in the solution of the ODE.
197197
An example of this with using [IncompleteLU.jl](https://github.com/haampie/IncompleteLU.jl)
198198
is as follows:
199199

200-
```@example
200+
```@example ill_conditioned_nlprob
201201
using IncompleteLU
202202
function incompletelu(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
203203
if newW === nothing || newW
@@ -233,7 +233,7 @@ requires a well-tuned `τ` parameter. Another option is to use
233233
[AlgebraicMultigrid.jl](https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl)
234234
which is more automatic. The setup is very similar to before:
235235

236-
```@example
236+
```@example ill_conditioned_nlprob
237237
using AlgebraicMultigrid
238238
function algebraicmultigrid(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
239239
if newW === nothing || newW
@@ -252,7 +252,7 @@ nothing # hide
252252

253253
or with a Jacobi smoother:
254254

255-
```@example
255+
```@example ill_conditioned_nlprob
256256
function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
257257
if newW === nothing || newW
258258
A = convert(AbstractMatrix, W)

0 commit comments

Comments
 (0)