Skip to content

Commit 2edd92f

Browse files
committed
Merge branch 'master' of github.com:SciML/NonlinearSolve.jl into ap/nls2
2 parents 572557b + cc04a70 commit 2edd92f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
3+
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
34
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
45
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
56
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
@@ -15,6 +16,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1516

1617
[compat]
1718
AlgebraicMultigrid = "0.5, 0.6"
19+
ArrayInterface = "6, 7"
1820
BenchmarkTools = "1"
1921
Documenter = "1"
2022
IncompleteLU = "0.2"

docs/src/tutorials/advanced.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ are then applied at each point in space (they are broadcast). Use `dx=dy=1/32`.
5555
The resulting `NonlinearProblem` definition is:
5656

5757
```@example ill_conditioned_nlprob
58-
using NonlinearSolve, LinearAlgebra, SparseArrays, LinearSolve
58+
using NonlinearSolve, LinearAlgebra, SparseArrays, LinearSolve, Symbolics
5959
6060
const N = 32
6161
const xyd_brusselator = range(0, stop = 1, length = N)
@@ -275,3 +275,28 @@ nothing # hide
275275

276276
For more information on the preconditioner interface, see the
277277
[linear solver documentation](https://docs.sciml.ai/LinearSolve/stable/basics/Preconditioners/).
278+
279+
## Speed up Jacobian computation with sparsity exploitation and matrix coloring
280+
281+
To cut down the of Jacobian building overhead, we can choose to exploit the sparsity pattern and deploy matrix coloring during Jacobian construction. With NonlinearSolve.jl, we can simply use `autodiff=AutoSparseForwardDiff()` to automatically exploit the sparsity pattern of Jacobian matrices:
282+
283+
```@example ill_conditioned_nlprob
284+
@benchmark solve(prob_brusselator_2d,
285+
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu, concrete_jac = true,
286+
autodiff = AutoSparseForwardDiff()));
287+
nothing # hide
288+
```
289+
290+
To setup matrix coloring for the jacobian sparsity pattern, we can simply get the coloring vector by using [ArrayInterface.jl](https://github.com/JuliaArrays/ArrayInterface.jl) for the sparsity pattern of `jac_prototype`:
291+
292+
```@example ill_conditioned_nlprob
293+
using ArrayInterface
294+
colorvec = ArrayInterface.matrix_colors(jac_sparsity)
295+
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity), colorvec)
296+
prob_brusselator_2d_sparse = NonlinearProblem(ff, u0, p)
297+
298+
@benchmark solve(prob_brusselator_2d_sparse,
299+
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu, concrete_jac = true,
300+
autodiff = AutoSparseForwardDiff()));
301+
nothing # hide
302+
```

0 commit comments

Comments
 (0)