diff --git a/Solver/linearSystemPETSc.hpp b/Solver/linearSystemPETSc.hpp index fdc8809d6ee961334271d5473a5777e10f40dc9e..0e42d65d9a6c5b292f3fea1212627232988f5a7a 100644 --- a/Solver/linearSystemPETSc.hpp +++ b/Solver/linearSystemPETSc.hpp @@ -280,8 +280,12 @@ void linearSystemPETSc<scalar>::zeroMatrix() } } if (_isAllocated && _entriesPreAllocated) { - _try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY)); - _try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY)); + PetscBool assembled; + _try(MatAssembled(_a, &assembled)); + if (!assembled) { + _try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY)); + _try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY)); + } _try(MatZeroEntries(_a)); _matrixModified = true; }