# Sparse Jacobian with dense blocks in differentialEquations.jl or otherwise

**URL:** <https://discourse.julialang.org/t/sparse-jacobian-with-dense-blocks-in-differentialequations-jl-or-otherwise/60430>\
**Category:** Numerics\
**Tags:** question\
**Created:** [May 2, 2021, 6:51pm UTC](https://discourse.julialang.org/t/sparse-jacobian-with-dense-blocks-in-differentialequations-jl-or-otherwise/60430 "2021-05-02T18:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [May 2, 2021, 6:51pm UTC](https://discourse.julialang.org/t/sparse-jacobian-with-dense-blocks-in-differentialequations-jl-or-otherwise/60430/1 "2021-05-02T18:51:24Z")

</div>

Dear all,

I am planning to use differentialEquations.jl to solve a stiff system of ordinary differential equations in which the Jacobian is sparse with dense blocks. Such systems are well known in this community as they appear in networks with dynamics (for e.g. biology to chemistry) prescribed on the nodes of the network.

Here is what I am wondering about.

1/ Non-Linear Solver at Each Time Step

1.1/ Can the performance of the non-linear solver at each time step be monitored (equivalent of -snes\_monitor in PETSc e.g.)

1.2/ Can the setting of the non-linear solver (tolerances, Jacobians approximations) be changed

2/ Linear Solver at Each Non-Linear Step

Can the linear solver (preconditioned Krylov method) be customized and monitored?

3/ Sparsity structure of the Jacobian

The ODE has the form \dot{x} = A x + f(x) leading to a sparse Jacobian with dense blocks. Can the SplitFunction be used to specify an additive preconditioned that treats the contribution A and Jac(f(x)) separately?

Thanks, Domenico.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 2, 2021, 9:24pm UTC](https://discourse.julialang.org/t/sparse-jacobian-with-dense-blocks-in-differentialequations-jl-or-otherwise/60430/3 "2021-05-02T21:24:27Z")

</div>

> [@ziolai](#):
>
> 1.2/ Can the setting of the non-linear solver (tolerances, Jacobians approximations) be changed

Yes, the heuristics are all exposed:

> <https://github.com/SciML/OrdinaryDiffEq.jl/blob/master/src/algorithms.jl#L1754>

[https://github.com/SciML/DiffEqBase.jl/blob/master/src/nlsolve/type.jl#L65](https://github.com/SciML/DiffEqBase.jl/blob/master/src/nlsolve/type.jl#L65)

though it needs more docs.

> [@ziolai](#):
>
> Can the linear solver (preconditioned Krylov method) be customized and monitored?

Yes, you can even write your own routine.

[https://diffeq.sciml.ai/stable/features/linear\_nonlinear/](https://diffeq.sciml.ai/stable/features/linear_nonlinear/)

> [@ziolai](#):
>
> The ODE has the form \dot{x} = A x + f(x) leading to a sparse Jacobian with dense blocks. Can the SplitFunction be used to specify an additive preconditioned that treats the contribution A and Jac(f(x)) separately?

You can just do that in the linear solver.

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [May 3, 2021, 8:26am UTC](https://discourse.julialang.org/t/sparse-jacobian-with-dense-blocks-in-differentialequations-jl-or-otherwise/60430/4 "2021-05-03T08:26:13Z")

</div>

Amazing! Thx.
