From 669d6a10580d3fa49adb6b9a4e622f2fd26d9f68 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Thu, 17 Nov 2005 09:33:59 +0000 Subject: [PATCH] allow uninitialized product git-svn-id: https://svn.dealii.org/trunk@11770 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/matrix_lib.h | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/deal.II/lac/include/lac/matrix_lib.h b/deal.II/lac/include/lac/matrix_lib.h index a3da23c287..d66b060557 100644 --- a/deal.II/lac/include/lac/matrix_lib.h +++ b/deal.II/lac/include/lac/matrix_lib.h @@ -43,6 +43,13 @@ template class ProductMatrix : public PointerMatrixBase { public: + /** + * Constructor only assigning the + * memory pool. Matricesmust be + * added by reinit() later. + */ + ProductMatrix(VectorMemory& mem); + /** * Constructor. Additionally to * the two constituting matrices, a @@ -394,6 +401,12 @@ class InverseMatrixRichardson /*@}*/ //--------------------------------------------------------------------------- +template +ProductMatrix::ProductMatrix (VectorMemory& m) + : m1(0), m2(0), mem(&m, typeid(*this).name()) +{} + + template template ProductMatrix::ProductMatrix ( @@ -414,8 +427,8 @@ ProductMatrix::reinit ( const MATRIX1& mat1, const MATRIX2& mat2) { - delete m1; - delete m2; + if (m1) delete m1; + if (m2) delete m2; m1 = new PointerMatrix(&mat1, typeid(*this).name()); m2 = new PointerMatrix(&mat2, typeid(*this).name()); } @@ -424,8 +437,8 @@ ProductMatrix::reinit ( template ProductMatrix::~ProductMatrix () { - delete m1; - delete m2; + if (m1) delete m1; + if (m2) delete m2; } @@ -433,6 +446,9 @@ template void ProductMatrix::vmult (VECTOR& dst, const VECTOR& src) const { + Assert (m1 != 0, ExcNotInitialized()); + Assert (m2 != 0, ExcNotInitialized()); + VECTOR* v = mem->alloc(); v->reinit(dst); m2->vmult (*v, src); @@ -445,6 +461,9 @@ template void ProductMatrix::vmult_add (VECTOR& dst, const VECTOR& src) const { + Assert (m1 != 0, ExcNotInitialized()); + Assert (m2 != 0, ExcNotInitialized()); + VECTOR* v = mem->alloc(); v->reinit(dst); m2->vmult (*v, src); @@ -457,6 +476,9 @@ template void ProductMatrix::Tvmult (VECTOR& dst, const VECTOR& src) const { + Assert (m1 != 0, ExcNotInitialized()); + Assert (m2 != 0, ExcNotInitialized()); + VECTOR* v = mem->alloc(); v->reinit(dst); m1->Tvmult (*v, src); @@ -469,6 +491,9 @@ template void ProductMatrix::Tvmult_add (VECTOR& dst, const VECTOR& src) const { + Assert (m1 != 0, ExcNotInitialized()); + Assert (m2 != 0, ExcNotInitialized()); + VECTOR* v = mem->alloc(); v->reinit(dst); m1->Tvmult (*v, src); -- 2.39.5