multiphenics / multiphenicsx

multiphenicsx - easy prototyping of multiphysics problems in FEniCSx
https://multiphenics.github.io/
GNU Lesser General Public License v3.0
45 stars 10 forks source link

Don't reallocate for each assembly #26

Closed ordinary-slim closed 5 months ago

ordinary-slim commented 5 months ago

The assemble_matrix functions call first create_matrix then do the proper assembly through non-exposed functions.

To avoid the overhead of reallocation for each call, I would like to add an optional argument A : typing.Optional[petsc4py.petsc.mat] = None to the assemble_matrix functions and zero it pre-assembly if given, otherwise create the matrix and proceed.

I think it is not necessary to check whether the matrix matches the bilinear form, bcs and restriction and leave this up to the user.

I can do the commit if you agree with this.

francesco-ballarin commented 5 months ago

The overload you require is already there, see https://github.com/multiphenics/multiphenicsx/blob/main/multiphenicsx/fem/petsc.py#L1213

You probably missed it because functools.singledispatch is bad at producing documentation for overloaded methods, in the sense that it only shows the documentation of the first appearance in the code, neglecting all remaining overloads. Unfortunately, apart from moving away from functools.singledispatch, there is not much we can do about this documentation issue. (I do think that dolfinx would have the same documentation issue, but please confirm)

ordinary-slim commented 5 months ago

Sorry for the misunderstanding, I was reading the code but I did not understand that was actually overloading.