@@ -144,7 +144,8 @@ nothing # hide
144144import SparseConnectivityTracer
145145
146146prob_brusselator_2d_autosparse = NLS.NonlinearProblem(
147- NLS.NonlinearFunction(brusselator_2d_loop; sparsity = SparseConnectivityTracer.TracerSparsityDetector()),
147+ NLS.NonlinearFunction(
148+ brusselator_2d_loop; sparsity = SparseConnectivityTracer.TracerSparsityDetector()),
148149 u0, p; abstol = 1e-10, reltol = 1e-10
149150)
150151
@@ -185,7 +186,8 @@ import ADTypes
185186
186187f! = (du, u) -> brusselator_2d_loop(du, u, p)
187188du0 = similar(u0)
188- jac_sparsity = ADTypes.jacobian_sparsity(f!, du0, u0, SparseConnectivityTracer.TracerSparsityDetector())
189+ jac_sparsity = ADTypes.jacobian_sparsity(
190+ f!, du0, u0, SparseConnectivityTracer.TracerSparsityDetector())
189191```
190192
191193Notice that Julia gives a nice print out of the sparsity pattern. That's neat, and would be
@@ -206,7 +208,8 @@ Now let's see how the version with sparsity compares to the version without:
206208``` @example ill_conditioned_nlprob
207209BenchmarkTools.@btime NLS.solve(prob_brusselator_2d, NLS.NewtonRaphson());
208210BenchmarkTools.@btime NLS.solve(prob_brusselator_2d_sparse, NLS.NewtonRaphson());
209- BenchmarkTools.@btime NLS.solve(prob_brusselator_2d_sparse, NLS.NewtonRaphson(linsolve = LS.KLUFactorization()));
211+ BenchmarkTools.@btime NLS.solve(
212+ prob_brusselator_2d_sparse, NLS.NewtonRaphson(linsolve = LS.KLUFactorization()));
210213nothing # hide
211214```
212215
@@ -222,7 +225,8 @@ Krylov method. To swap the linear solver out, we use the `linsolve` command and
222225GMRES linear solver.
223226
224227``` @example ill_conditioned_nlprob
225- BenchmarkTools.@btime NLS.solve(prob_brusselator_2d, NLS.NewtonRaphson(linsolve = LS.KrylovJL_GMRES()));
228+ BenchmarkTools.@btime NLS.solve(
229+ prob_brusselator_2d, NLS.NewtonRaphson(linsolve = LS.KrylovJL_GMRES()));
226230nothing # hide
227231```
228232
@@ -254,7 +258,8 @@ import IncompleteLU
254258incompletelu (W, p = nothing ) = IncompleteLU. ilu (W, τ = 50.0 ), LinearAlgebra. I
255259
256260BenchmarkTools. @btime NLS. solve (prob_brusselator_2d_sparse,
257- NLS. NewtonRaphson (linsolve = LS. KrylovJL_GMRES (precs = incompletelu), concrete_jac = true )
261+ NLS. NewtonRaphson (
262+ linsolve = LS. KrylovJL_GMRES (precs = incompletelu), concrete_jac = true )
258263);
259264nothing # hide
260265```
@@ -279,7 +284,9 @@ which is more automatic. The setup is very similar to before:
279284import AlgebraicMultigrid
280285
281286function algebraicmultigrid(W, p = nothing)
282- return AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(convert(AbstractMatrix, W))), LinearAlgebra.I
287+ return AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(convert(
288+ AbstractMatrix, W))),
289+ LinearAlgebra.I
283290end
284291
285292BenchmarkTools.@btime NLS.solve(prob_brusselator_2d_sparse,
@@ -322,11 +329,13 @@ import DifferentiationInterface
322329import SparseConnectivityTracer
323330
324331prob_brusselator_2d_exact_tracer = NLS.NonlinearProblem(
325- NLS.NonlinearFunction(brusselator_2d_loop; sparsity = SparseConnectivityTracer.TracerSparsityDetector()),
332+ NLS.NonlinearFunction(
333+ brusselator_2d_loop; sparsity = SparseConnectivityTracer.TracerSparsityDetector()),
326334 u0, p; abstol = 1e-10, reltol = 1e-10)
327335prob_brusselator_2d_approx_di = NLS.NonlinearProblem(
328336 NLS.NonlinearFunction(brusselator_2d_loop;
329- sparsity = DifferentiationInterface.DenseSparsityDetector(ADTypes.AutoForwardDiff(); atol = 1e-4)),
337+ sparsity = DifferentiationInterface.DenseSparsityDetector(
338+ ADTypes.AutoForwardDiff(); atol = 1e-4)),
330339 u0, p; abstol = 1e-10, reltol = 1e-10)
331340
332341BenchmarkTools.@btime NLS.solve(prob_brusselator_2d_exact_tracer, NLS.NewtonRaphson());
0 commit comments