WIAS-PDELib / VoronoiFVM.jl

Solution of nonlinear multiphysics partial differential equation systems using the Voronoi finite volume method
MIT License
213 stars 36 forks source link

Try out DifferentiationInterface for sparse autodiff? #109

Open gdalle opened 5 months ago

gdalle commented 5 months ago

Hi @j-fu! As of this morning's release, DifferentiationInterface is starting to look like a solid replacement for SparseDiffTools in the realm of sparse Jacobians and Hessians. Would you be interested in trying it out? You can check out the tutorial to get a feel for the interface.

j-fu commented 5 months ago

Thanks for pinging me - basically this is already on my bucket list. However, sparsity detection in the moment is a side track in VoronoiFVM, as the general approach is to apply AD (ForwardDiff to be exact) locally, resulting in local node and edge based Jacobi matrices (a similar approach with FEM would use element Jacobi matrices). These are assembled into the global sparse matrix via an intermediate linked list structure (see ExtendableSparse.jl).

A bit of handwaving philosophy behind this is that discretized PDEs have a repeating spatial structure. In that sense their sparsity pattern is not entirely generic (though with multispecies/multiphysics this is hard to condense into some structure) Global sparsity detection seems to kind of ignores this fact.

Sparsity detection in VoronoiFVM.jl is used for a "generic operator" (which is for weird models) and for derivatives of solution functionals (for impedance/small signal analysis).

In the moment, my main focus for the package is multithreaded assembly. How your approach to sparsity detection would work with multithreaded code ?

gdalle commented 5 months ago

A bit of handwaving philosophy behind this is that discretized PDEs have a repeating spatial structure. In that sense their sparsity pattern is not entirely generic

I see, you might be interested in the following works then, which also exploit repeated structure for differentiation:

How your approach to sparsity detection would work with multithreaded code ?

There isn't any theoretical obstacle, but I don't think performance would be great, because sparsity detection routines make lots of allocations that may hamper parallelism