From ba3d9127f531a41fc059c61aa824cca752b70ea0 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Fri, 25 Nov 2005 10:39:42 +0000 Subject: [PATCH] allow unitialized ProductSparseMatrix git-svn-id: https://svn.dealii.org/trunk@11790 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/matrix_lib.h | 16 ++++++++++ deal.II/lac/source/matrix_lib.cc | 48 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/deal.II/lac/include/lac/matrix_lib.h b/deal.II/lac/include/lac/matrix_lib.h index 443cd07c26..4b6c2dbb2f 100644 --- a/deal.II/lac/include/lac/matrix_lib.h +++ b/deal.II/lac/include/lac/matrix_lib.h @@ -181,6 +181,22 @@ class ProductSparseMatrix : public PointerMatrixBase > const MatrixType& m2, VectorMemory& mem); + /** + * Constructor leaving an + * unitialized + * matrix. initialize() must be + * called, before the matrix can + * be used. + */ + ProductSparseMatrix(); + + void initialize(const MatrixType& m1, + const MatrixType& m2, + VectorMemory& mem); + + // Doc in PointerMatrixBase + void clear(); + /** * Matrix-vector product w = * m1 * m2 * v. diff --git a/deal.II/lac/source/matrix_lib.cc b/deal.II/lac/source/matrix_lib.cc index 0f4ee74df0..57c1ebbaeb 100644 --- a/deal.II/lac/source/matrix_lib.cc +++ b/deal.II/lac/source/matrix_lib.cc @@ -35,10 +35,46 @@ ProductSparseMatrix::ProductSparseMatrix( } +template +ProductSparseMatrix::ProductSparseMatrix() + : + m1(0, typeid(*this).name()), + m2(0, typeid(*this).name()), + mem(0, typeid(*this).name()) +{} + + +template +void +ProductSparseMatrix::initialize( + const MatrixType& mat1, + const MatrixType& mat2, + VectorMemory& memory) +{ + Assert(mat1.n() == mat2.m(), ExcDimensionMismatch(mat1.n(),mat2.m())); + mem = &memory; + m1 = &mat1; + m2 = &mat2; +} + + +template +void +ProductSparseMatrix::clear() +{ + m1 = 0; + m2 = 0; +} + + template void ProductSparseMatrix::vmult (VectorType& dst, const VectorType& src) const { + Assert(mem != 0, ExcNotInitialized()); + Assert(m1 != 0, ExcNotInitialized()); + Assert(m2 != 0, ExcNotInitialized()); + VectorType* v = mem->alloc(); v->reinit(m1->n()); m2->vmult (*v, src); @@ -51,6 +87,10 @@ template void ProductSparseMatrix::vmult_add (VectorType& dst, const VectorType& src) const { + Assert(mem != 0, ExcNotInitialized()); + Assert(m1 != 0, ExcNotInitialized()); + Assert(m2 != 0, ExcNotInitialized()); + VectorType* v = mem->alloc(); v->reinit(m1->n()); m2->vmult (*v, src); @@ -63,6 +103,10 @@ template void ProductSparseMatrix::Tvmult (VectorType& dst, const VectorType& src) const { + Assert(mem != 0, ExcNotInitialized()); + Assert(m1 != 0, ExcNotInitialized()); + Assert(m2 != 0, ExcNotInitialized()); + VectorType* v = mem->alloc(); v->reinit(m1->n()); m1->Tvmult (*v, src); @@ -75,6 +119,10 @@ template void ProductSparseMatrix::Tvmult_add (VectorType& dst, const VectorType& src) const { + Assert(mem != 0, ExcNotInitialized()); + Assert(m1 != 0, ExcNotInitialized()); + Assert(m2 != 0, ExcNotInitialized()); + VectorType* v = mem->alloc(); v->reinit(m1->n()); m1->Tvmult (*v, src); -- 2.39.5