@@ -54,7 +54,7 @@ are then applied at each point in space (they are broadcast). Use `dx=dy=1/32`.
54
54
55
55
The resulting ` NonlinearProblem ` definition is:
56
56
57
- ``` @example
57
+ ``` @example ill_conditioned_nlprob
58
58
using NonlinearSolve, LinearAlgebra, SparseArrays, LinearSolve
59
59
60
60
const N = 32
@@ -130,7 +130,7 @@ in action, we can give an example `du` and `u` and call `jacobian_sparsity`
130
130
on our function with the example arguments, and it will kick out a sparse matrix
131
131
with our pattern, that we can turn into our ` jac_prototype ` .
132
132
133
- ``` @example
133
+ ``` @example ill_conditioned_nlprob
134
134
using Symbolics
135
135
du0 = copy(u0)
136
136
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
141
141
would be tedious to build by hand! Now we just pass it to the ` NonlinearFunction `
142
142
like as before:
143
143
144
- ``` @example
144
+ ``` @example ill_conditioned_nlprob
145
145
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))
146
146
```
147
147
148
148
Build the ` NonlinearProblem ` :
149
149
150
- ``` @example
150
+ ``` @example ill_conditioned_nlprob
151
151
prob_brusselator_2d_sparse = NonlinearProblem(ff, u0, p)
152
152
```
153
153
154
154
Now let's see how the version with sparsity compares to the version without:
155
155
156
- ``` @example
156
+ ``` @example ill_conditioned_nlprob
157
157
using BenchmarkTools # for @btime
158
158
@btime solve(prob_brusselator_2d, NewtonRaphson());
159
159
@btime solve(prob_brusselator_2d_sparse, NewtonRaphson());
@@ -172,7 +172,7 @@ matrices is to use a Krylov subspace method. This requires choosing a linear
172
172
solver for changing to a Krylov method. To swap the linear solver out, we use
173
173
the ` linsolve ` command and choose the GMRES linear solver.
174
174
175
- ``` @example
175
+ ``` @example ill_conditioned_nlprob
176
176
@btime solve(prob_brusselator_2d, NewtonRaphson(linsolve = KrylovJL_GMRES()));
177
177
nothing # hide
178
178
```
@@ -197,7 +197,7 @@ approximate the inverse of `W = I - gamma*J` used in the solution of the ODE.
197
197
An example of this with using [ IncompleteLU.jl] ( https://github.com/haampie/IncompleteLU.jl )
198
198
is as follows:
199
199
200
- ``` @example
200
+ ``` @example ill_conditioned_nlprob
201
201
using IncompleteLU
202
202
function incompletelu(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
203
203
if newW === nothing || newW
@@ -233,7 +233,7 @@ requires a well-tuned `τ` parameter. Another option is to use
233
233
[ AlgebraicMultigrid.jl] ( https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl )
234
234
which is more automatic. The setup is very similar to before:
235
235
236
- ``` @example
236
+ ``` @example ill_conditioned_nlprob
237
237
using AlgebraicMultigrid
238
238
function algebraicmultigrid(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
239
239
if newW === nothing || newW
@@ -252,7 +252,7 @@ nothing # hide
252
252
253
253
or with a Jacobi smoother:
254
254
255
- ``` @example
255
+ ``` @example ill_conditioned_nlprob
256
256
function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
257
257
if newW === nothing || newW
258
258
A = convert(AbstractMatrix, W)
0 commit comments