optimad / bitpit

Open source library for scientific HPC
http://optimad.github.io/bitpit/
GNU Lesser General Public License v3.0
116 stars 34 forks source link

LA: properly setup the preconditioner when solving multiple linear systems #411

Closed andrea-iob closed 10 months ago

andrea-iob commented 10 months ago

From the PETSc user manual: "To solve successive linear systems that have different preconditioner matrices (i.e., the matrix elements and/or the matrix data structure change), the user must call KSPSetOperators() and KSPSolve() for each solve."

andrea-iob commented 10 months ago

It seems KSPSetUp should be called just once. I refactored the code to make sure only KSPSetOperators is called for each solve (as before, KSPSetOperators is not called if the matrix hasn't changed).

andrea-iob commented 10 months ago

Lazy allocation of matrix storage was giving me some troubles, because at the time allocation was performed the information about the estimated number of non-zero element was not available anymore. I reverted the change and only added the functions to handle value and pattern storages.