From 3285e2d33a6ae38877a3df30d52c829dc2a57d63 Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Fri, 4 Aug 2017 16:21:23 +0200 Subject: [PATCH] Implement method 'setSize' for BDMatrix --- dune/istl/bdmatrix.hh | 18 ++++++++++++++++++ dune/istl/test/matrixtest.cc | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/dune/istl/bdmatrix.hh b/dune/istl/bdmatrix.hh index cbdee7749..f5615a026 100644 --- a/dune/istl/bdmatrix.hh +++ b/dune/istl/bdmatrix.hh @@ -74,6 +74,24 @@ namespace Dune { (*this)[i][i] = *it; } + /** \brief Resize the matrix. Invalidates the content! */ + void setSize(size_type size) + { + this->BCRSMatrix<B,A>::setSize(size, // rows + size, // columns + size); // nonzeros + + for (int i=0; i<size; i++) + this->BCRSMatrix<B,A>::setrowsize(i, 1); + + this->BCRSMatrix<B,A>::endrowsizes(); + + for (int i=0; i<size; i++) + this->BCRSMatrix<B,A>::addindex(i, i); + + this->BCRSMatrix<B,A>::endindices(); + } + //! assignment BDMatrix& operator= (const BDMatrix& other) { this->BCRSMatrix<B,A>::operator=(other); diff --git a/dune/istl/test/matrixtest.cc b/dune/istl/test/matrixtest.cc index f06c8f98c..67739a012 100644 --- a/dune/istl/test/matrixtest.cc +++ b/dune/istl/test/matrixtest.cc @@ -389,6 +389,11 @@ int main() BDMatrix<FieldMatrix<double,2,2> > bdMatrix2 = { {{1,0},{0,1}}, {{0,1},{-1,0}}}; testSuperMatrix(bdMatrix2); + // test whether resizing works + bdMatrix2.setSize(5); + bdMatrix2 = 4.0; + testSuperMatrix(bdMatrix); + // //////////////////////////////////////////////////////////////////////// // Test the BTDMatrix class -- a dynamic block-tridiagonal matrix // a) the scalar case -- GitLab