Skip to content

Commit 358b251

Browse files
authored
Merge pull request #4115 from lindsayad/implement-reset-memory-for-diagonal-matrix
reset_memory -> restore_original_nonzero_pattern
2 parents 047a4c2 + 3b194d9 commit 358b251

6 files changed

Lines changed: 22 additions & 6 deletions

File tree

examples/miscellaneous/miscellaneous_ex17/miscellaneous_ex17.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ int main (int argc, char ** argv)
160160
// MatResetHash added in PETSc version 3.23
161161
#if !PETSC_VERSION_LESS_THAN(3, 23, 0)
162162
// reset the memory
163-
// sys_matrix.reset_memory(); # See https://gitlab.com/petsc/petsc/-/merge_requests/8063
164-
pre_matrix.reset_memory();
163+
// sys_matrix.restore_original_nonzero_pattern(); # See https://gitlab.com/petsc/petsc/-/merge_requests/8063
164+
pre_matrix.restore_original_nonzero_pattern();
165165
// zero
166166
sys_matrix.zero();
167167
pre_matrix.zero();

include/numerics/diagonal_matrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class DiagonalMatrix : public SparseMatrix<T>
176176

177177
const NumericVector<T> & diagonal() const;
178178

179+
virtual void restore_original_nonzero_pattern() override;
180+
179181
protected:
180182
/// Underlying diagonal matrix storage
181183
std::unique_ptr<NumericVector<T>> _diagonal;

include/numerics/petsc_matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class PetscMatrix final : public PetscMatrixBase<T>
291291

292292
virtual bool supports_hash_table() const override;
293293

294-
virtual void reset_memory() override;
294+
virtual void restore_original_nonzero_pattern() override;
295295

296296
protected:
297297
/**

include/numerics/sparse_matrix.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,12 @@ class SparseMatrix : public ReferenceCountedObject<SparseMatrix<T>>,
606606
/**
607607
* Reset the memory storage of the matrix. Unlike \p clear(), this does not destroy the matrix but
608608
* rather will reset the matrix to use the original preallocation or when using hash table matrix
609-
* assembly (see \p use_hash_table()) will reset (clear) the hash table used for assembly
609+
* assembly (see \p use_hash_table()) will reset (clear) the hash table used for assembly. In the
610+
* words of the \p MatResetPreallocation documentation in PETSc, 'current values in the matrix are
611+
* lost in this call', so a user can expect to have back their original sparsity pattern in a
612+
* zeroed state
610613
*/
611-
virtual void reset_memory() { libmesh_not_implemented(); }
614+
virtual void restore_original_nonzero_pattern() { libmesh_not_implemented(); }
612615

613616
protected:
614617
/**

src/numerics/diagonal_matrix.C

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,12 @@ DiagonalMatrix<T>::diagonal() const
331331
return *_diagonal;
332332
}
333333

334+
template <typename T>
335+
void
336+
DiagonalMatrix<T>::restore_original_nonzero_pattern()
337+
{
338+
_diagonal->zero();
339+
}
340+
334341
template class LIBMESH_EXPORT DiagonalMatrix<Number>;
335342
}

src/numerics/petsc_matrix.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ void PetscMatrix<T>::update_preallocation_and_zero ()
382382
template <typename T>
383383
void PetscMatrix<T>::reset_preallocation()
384384
{
385+
semiparallel_only();
386+
385387
#if !PETSC_VERSION_LESS_THAN(3,9,0)
386388
libmesh_assert (this->initialized());
387389

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

12871289
template <typename T>
12881290
void
1289-
PetscMatrix<T>::reset_memory()
1291+
PetscMatrix<T>::restore_original_nonzero_pattern()
12901292
{
1293+
semiparallel_only();
1294+
12911295
if (this->_use_hash_table)
12921296
#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
12931297
// This performs MatReset plus re-establishes the hash table

0 commit comments

Comments
 (0)