Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ int main (int argc, char ** argv)
// MatResetHash added in PETSc version 3.23
#if !PETSC_VERSION_LESS_THAN(3, 23, 0)
// reset the memory
// sys_matrix.reset_memory(); # See https://gitlab.com/petsc/petsc/-/merge_requests/8063
pre_matrix.reset_memory();
// sys_matrix.restore_original_nonzero_pattern(); # See https://gitlab.com/petsc/petsc/-/merge_requests/8063
pre_matrix.restore_original_nonzero_pattern();
// zero
sys_matrix.zero();
pre_matrix.zero();
Expand Down
2 changes: 2 additions & 0 deletions include/numerics/diagonal_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class DiagonalMatrix : public SparseMatrix<T>

const NumericVector<T> & diagonal() const;

virtual void restore_original_nonzero_pattern() override;

protected:
/// Underlying diagonal matrix storage
std::unique_ptr<NumericVector<T>> _diagonal;
Expand Down
2 changes: 1 addition & 1 deletion include/numerics/petsc_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class PetscMatrix final : public PetscMatrixBase<T>

virtual bool supports_hash_table() const override;

virtual void reset_memory() override;
virtual void restore_original_nonzero_pattern() override;

protected:
/**
Expand Down
7 changes: 5 additions & 2 deletions include/numerics/sparse_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,12 @@ class SparseMatrix : public ReferenceCountedObject<SparseMatrix<T>>,
/**
* Reset the memory storage of the matrix. Unlike \p clear(), this does not destroy the matrix but
* rather will reset the matrix to use the original preallocation or when using hash table matrix
* assembly (see \p use_hash_table()) will reset (clear) the hash table used for assembly
* assembly (see \p use_hash_table()) will reset (clear) the hash table used for assembly. In the
* words of the \p MatResetPreallocation documentation in PETSc, 'current values in the matrix are
* lost in this call', so a user can expect to have back their original sparsity pattern in a
* zeroed state
*/
virtual void reset_memory() { libmesh_not_implemented(); }
virtual void restore_original_nonzero_pattern() { libmesh_not_implemented(); }

protected:
/**
Expand Down
7 changes: 7 additions & 0 deletions src/numerics/diagonal_matrix.C
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,12 @@ DiagonalMatrix<T>::diagonal() const
return *_diagonal;
}

template <typename T>
void
DiagonalMatrix<T>::restore_original_nonzero_pattern()
{
_diagonal->zero();
}

template class LIBMESH_EXPORT DiagonalMatrix<Number>;
}
6 changes: 5 additions & 1 deletion src/numerics/petsc_matrix.C
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ void PetscMatrix<T>::update_preallocation_and_zero ()
template <typename T>
void PetscMatrix<T>::reset_preallocation()
{
semiparallel_only();

#if !PETSC_VERSION_LESS_THAN(3,9,0)
libmesh_assert (this->initialized());

Expand Down Expand Up @@ -1286,8 +1288,10 @@ PetscMatrix<T>::copy_from_hash ()

template <typename T>
void
PetscMatrix<T>::reset_memory()
PetscMatrix<T>::restore_original_nonzero_pattern()
{
semiparallel_only();

if (this->_use_hash_table)
#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
// This performs MatReset plus re-establishes the hash table
Expand Down