From: Martin Kronbichler Date: Wed, 9 Dec 2009 18:12:05 +0000 (+0000) Subject: Cleanup of operator = (double). X-Git-Tag: v8.0.0~6751 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93375192a9e25f446584a01f9e385d83c860b061;p=dealii.git Cleanup of operator = (double). git-svn-id: https://svn.dealii.org/trunk@20220 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index f23ffa5c90..205441ecf9 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -50,7 +50,7 @@ class BlockSparseMatrix : public BlockMatrixBase > * access to its own typedefs. */ typedef BlockMatrixBase > BaseClass; - + /** * Typedef the type of the underlying * matrix. @@ -120,10 +120,10 @@ class BlockSparseMatrix : public BlockMatrixBase > * Destructor. */ virtual ~BlockSparseMatrix (); - - - /** + + + /** * Pseudo copy operator only copying * empty objects. The sizes of the block * matrices need to be the same. @@ -131,22 +131,22 @@ class BlockSparseMatrix : public BlockMatrixBase > BlockSparseMatrix & operator = (const BlockSparseMatrix &); - /** + /** * This operator assigns a scalar to a * matrix. Since this does usually not * make much sense (should we set all - * matrix entries to this value? Only the - * nonzero entries of the sparsity + * matrix entries to this value? Only + * the nonzero entries of the sparsity * pattern?), this operation is only * allowed if the actual value to be * assigned is zero. This operator only * exists to allow for the obvious - * notation matrix=0, which sets - * all elements of the matrix to zero, - * but keep the sparsity pattern + * notation matrix=0, which + * sets all elements of the matrix to + * zero, but keep the sparsity pattern * previously used. */ - BlockSparseMatrix & + BlockSparseMatrix & operator = (const double d); /** @@ -162,7 +162,7 @@ class BlockSparseMatrix : public BlockMatrixBase > * object to have no blocks at all. */ void clear (); - + /** * Reinitialize the sparse matrix * with the given sparsity @@ -209,7 +209,7 @@ class BlockSparseMatrix : public BlockMatrixBase > * (with absolute value larger than * threshold) of all the blocks. */ - unsigned int n_actually_nonzero_elements (const double threshold = 0.0) const; + unsigned int n_actually_nonzero_elements (const double threshold = 0.0) const; /** * Matrix-vector multiplication: @@ -254,7 +254,7 @@ class BlockSparseMatrix : public BlockMatrixBase > template void vmult (Vector &dst, const Vector &src) const; - + /** * Matrix-vector multiplication: * let $dst = M^T*src$ with $M$ @@ -266,7 +266,7 @@ class BlockSparseMatrix : public BlockMatrixBase > template void Tvmult (BlockVector &dst, const BlockVector &src) const; - + /** * Matrix-vector * multiplication. Just like the @@ -301,7 +301,7 @@ class BlockSparseMatrix : public BlockMatrixBase > template void Tvmult (Vector &dst, const Vector &src) const; - + /** * Apply the Jacobi * preconditioner, which @@ -396,7 +396,7 @@ class BlockSparseMatrix : public BlockMatrixBase > */ const BlockSparsityPattern & get_sparsity_pattern () const; - + /** * Determine an estimate for the * memory consumption (in bytes) @@ -406,12 +406,12 @@ class BlockSparseMatrix : public BlockMatrixBase > /** @addtogroup Exceptions * @{ */ - + /** * Exception */ DeclException0 (ExcBlockDimensionMismatch); - //@} + //@} private: /** * Pointer to the block sparsity @@ -432,6 +432,22 @@ class BlockSparseMatrix : public BlockMatrixBase > +template +inline +BlockSparseMatrix & +BlockSparseMatrix::operator = (const double d) +{ + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + + for (unsigned int r=0; rn_block_rows(); ++r) + for (unsigned int c=0; cn_block_cols(); ++c) + this->block(r,c) = d; + + return *this; +} + + + template template inline @@ -441,7 +457,7 @@ BlockSparseMatrix::vmult (BlockVector &dst, { BaseClass::vmult_block_block (dst, src); } - + template @@ -454,7 +470,7 @@ BlockSparseMatrix::vmult (BlockVector &dst, { BaseClass::vmult_block_nonblock (dst, src); } - + template @@ -467,7 +483,7 @@ BlockSparseMatrix::vmult (Vector &dst, { BaseClass::vmult_nonblock_block (dst, src); } - + template @@ -481,6 +497,7 @@ BlockSparseMatrix::vmult (Vector &dst, } + template template inline @@ -490,7 +507,7 @@ BlockSparseMatrix::Tvmult (BlockVector &dst, { BaseClass::Tvmult_block_block (dst, src); } - + template @@ -503,7 +520,7 @@ BlockSparseMatrix::Tvmult (BlockVector &dst, { BaseClass::Tvmult_block_nonblock (dst, src); } - + template @@ -516,7 +533,7 @@ BlockSparseMatrix::Tvmult (Vector &dst, { BaseClass::Tvmult_nonblock_block (dst, src); } - + template @@ -530,8 +547,10 @@ BlockSparseMatrix::Tvmult (Vector &dst, } + template template +inline void BlockSparseMatrix:: precondition_Jacobi (BlockVectorType &dst, @@ -553,8 +572,10 @@ precondition_Jacobi (BlockVectorType &dst, } + template template +inline void BlockSparseMatrix:: precondition_Jacobi (Vector &dst, diff --git a/deal.II/lac/include/lac/block_sparse_matrix.templates.h b/deal.II/lac/include/lac/block_sparse_matrix.templates.h index d6b84c64d5..078a7c1052 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.templates.h @@ -68,21 +68,6 @@ operator = (const BlockSparseMatrix &m) return *this; } - - -template -BlockSparseMatrix & -BlockSparseMatrix::operator = (const double d) -{ - Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); - - for (unsigned int r=0; rn_block_rows(); ++r) - for (unsigned int c=0; cn_block_cols(); ++c) - this->block(r,c) = d; - - return *this; -} - template diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index 1d4f113acf..ed3e2c044e 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -1365,7 +1365,7 @@ FullMatrix::operator = (const number d) Assert (d==number(0), ExcScalarAssignmentOnlyForZeroValue()); if (this->n_elements() != 0) - std::fill_n (this->val, this->n_elements(), number()); + memset (this->val, 0, this->n_elements()*sizeof(number)); return *this; } diff --git a/deal.II/lac/include/lac/petsc_block_sparse_matrix.h b/deal.II/lac/include/lac/petsc_block_sparse_matrix.h index edb9648a63..03c93e15c1 100644 --- a/deal.II/lac/include/lac/petsc_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_block_sparse_matrix.h @@ -32,7 +32,7 @@ DEAL_II_NAMESPACE_OPEN namespace PETScWrappers { - + /*! @addtogroup PETScWrappers *@{ */ @@ -66,7 +66,7 @@ namespace PETScWrappers * access to its own typedefs. */ typedef BlockMatrixBase BaseClass; - + /** * Typedef the type of the underlying * matrix. @@ -114,7 +114,7 @@ namespace PETScWrappers */ ~BlockSparseMatrix (); - /** + /** * Pseudo copy operator only copying * empty objects. The sizes of the block * matrices need to be the same. @@ -168,7 +168,7 @@ namespace PETScWrappers */ void reinit (const unsigned int n_block_rows, const unsigned int n_block_columns); - + /** * This function collects the * sizes of the sub-objects and @@ -220,7 +220,7 @@ namespace PETScWrappers */ void vmult (Vector &dst, const Vector &src) const; - + /** * Matrix-vector multiplication: * let $dst = M^T*src$ with $M$ @@ -231,7 +231,7 @@ namespace PETScWrappers */ void Tvmult (BlockVector &dst, const BlockVector &src) const; - + /** * Matrix-vector * multiplication. Just like the @@ -260,7 +260,7 @@ namespace PETScWrappers * only one block. */ void Tvmult (Vector &dst, - const Vector &src) const; + const Vector &src) const; /** * Make the clear() function in the @@ -268,11 +268,11 @@ namespace PETScWrappers * protected. */ using BlockMatrixBase::clear; - + /** @addtogroup Exceptions * @{ */ - + /** * Exception */ @@ -296,6 +296,21 @@ namespace PETScWrappers // ------------- inline and template functions ----------------- + inline + BlockSparseMatrix & + BlockSparseMatrix::operator = (const double d) + { + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + + for (unsigned int r=0; rn_block_rows(); ++r) + for (unsigned int c=0; cn_block_cols(); ++c) + this->block(r,c) = d; + + return *this; + } + + + inline void BlockSparseMatrix::vmult (BlockVector &dst, @@ -303,7 +318,7 @@ namespace PETScWrappers { BaseClass::vmult_block_block (dst, src); } - + inline @@ -313,7 +328,7 @@ namespace PETScWrappers { BaseClass::vmult_block_nonblock (dst, src); } - + inline @@ -323,7 +338,7 @@ namespace PETScWrappers { BaseClass::vmult_nonblock_block (dst, src); } - + inline @@ -342,7 +357,7 @@ namespace PETScWrappers { BaseClass::Tvmult_block_block (dst, src); } - + inline @@ -352,7 +367,7 @@ namespace PETScWrappers { BaseClass::Tvmult_block_nonblock (dst, src); } - + inline @@ -362,7 +377,7 @@ namespace PETScWrappers { BaseClass::Tvmult_nonblock_block (dst, src); } - + inline @@ -372,7 +387,7 @@ namespace PETScWrappers { BaseClass::Tvmult_nonblock_nonblock (dst, src); } - + } DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h index f4489cb5b2..8553f6f43e 100644 --- a/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h @@ -36,7 +36,7 @@ namespace PETScWrappers /*! @addtogroup PETScWrappers *@{ - */ + */ /** * Blocked sparse matrix based on the PETScWrappers::SparseMatrix class. This @@ -67,7 +67,7 @@ namespace PETScWrappers * access to its own typedefs. */ typedef BlockMatrixBase BaseClass; - + /** * Typedef the type of the underlying * matrix. @@ -115,7 +115,7 @@ namespace PETScWrappers */ ~BlockSparseMatrix (); - /** + /** * Pseudo copy operator only copying * empty objects. The sizes of the * block matrices need to be the @@ -141,7 +141,7 @@ namespace PETScWrappers * previously used. */ BlockSparseMatrix & - operator = (const PetscScalar d); + operator = (const double d); /** * Resize the matrix, by setting @@ -170,7 +170,7 @@ namespace PETScWrappers * she desires. */ void reinit (const unsigned int n_block_rows, - const unsigned int n_block_columns); + const unsigned int n_block_columns); /** * Matrix-vector multiplication: @@ -209,7 +209,7 @@ namespace PETScWrappers */ void vmult (Vector &dst, const Vector &src) const; - + /** * Matrix-vector multiplication: * let $dst = M^T*src$ with $M$ @@ -220,7 +220,7 @@ namespace PETScWrappers */ void Tvmult (BlockVector &dst, const BlockVector &src) const; - + /** * Matrix-vector * multiplication. Just like the @@ -249,7 +249,7 @@ namespace PETScWrappers * only one block. */ void Tvmult (Vector &dst, - const Vector &src) const; + const Vector &src) const; /** * This function collects the @@ -264,7 +264,7 @@ namespace PETScWrappers * the sub-objects. */ void collect_sizes (); - + /** * Return a reference to the MPI * communicator object in use with @@ -286,6 +286,21 @@ namespace PETScWrappers // ------------- inline and template functions ----------------- + inline + BlockSparseMatrix & + BlockSparseMatrix::operator = (const double d) + { + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + + for (unsigned int r=0; rn_block_rows(); ++r) + for (unsigned int c=0; cn_block_cols(); ++c) + this->block(r,c) = d; + + return *this; + } + + + inline void BlockSparseMatrix::vmult (BlockVector &dst, @@ -293,7 +308,7 @@ namespace PETScWrappers { BaseClass::vmult_block_block (dst, src); } - + inline @@ -303,7 +318,7 @@ namespace PETScWrappers { BaseClass::vmult_block_nonblock (dst, src); } - + inline @@ -313,7 +328,7 @@ namespace PETScWrappers { BaseClass::vmult_nonblock_block (dst, src); } - + inline @@ -332,7 +347,7 @@ namespace PETScWrappers { BaseClass::Tvmult_block_block (dst, src); } - + inline @@ -342,7 +357,7 @@ namespace PETScWrappers { BaseClass::Tvmult_block_nonblock (dst, src); } - + inline @@ -352,7 +367,7 @@ namespace PETScWrappers { BaseClass::Tvmult_nonblock_block (dst, src); } - + inline @@ -362,9 +377,9 @@ namespace PETScWrappers { BaseClass::Tvmult_nonblock_nonblock (dst, src); } - + } - + } diff --git a/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h b/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h index 105309562b..7dadd219e3 100644 --- a/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h @@ -645,6 +645,23 @@ namespace TrilinosWrappers // ------------- inline and template functions ----------------- + + + inline + BlockSparseMatrix & + BlockSparseMatrix::operator = (const double d) + { + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + + for (unsigned int r=0; rn_block_rows(); ++r) + for (unsigned int c=0; cn_block_cols(); ++c) + this->block(r,c) = d; + + return *this; + } + + + inline bool BlockSparseMatrix::is_compressed () const diff --git a/deal.II/lac/source/petsc_block_sparse_matrix.cc b/deal.II/lac/source/petsc_block_sparse_matrix.cc index ca306e1db7..72d2de6328 100644 --- a/deal.II/lac/source/petsc_block_sparse_matrix.cc +++ b/deal.II/lac/source/petsc_block_sparse_matrix.cc @@ -39,18 +39,6 @@ namespace PETScWrappers } - - BlockSparseMatrix & - BlockSparseMatrix::operator = (const double d) - { - for (unsigned int r=0; rn_block_rows(); ++r) - for (unsigned int c=0; cn_block_cols(); ++c) - this->block(r,c) = d; - - return *this; - } - - void BlockSparseMatrix:: reinit (const unsigned int n_block_rows, diff --git a/deal.II/lac/source/petsc_parallel_block_sparse_matrix.cc b/deal.II/lac/source/petsc_parallel_block_sparse_matrix.cc index 677f0eaeae..ff9064a522 100644 --- a/deal.II/lac/source/petsc_parallel_block_sparse_matrix.cc +++ b/deal.II/lac/source/petsc_parallel_block_sparse_matrix.cc @@ -42,18 +42,6 @@ namespace PETScWrappers } - - BlockSparseMatrix & - BlockSparseMatrix::operator = (const PetscScalar d) - { - for (unsigned int r=0; rn_block_rows(); ++r) - for (unsigned int c=0; cn_block_cols(); ++c) - this->block(r,c) = d; - - return *this; - } - - void BlockSparseMatrix:: reinit (const unsigned int n_block_rows, diff --git a/deal.II/lac/source/trilinos_block_sparse_matrix.cc b/deal.II/lac/source/trilinos_block_sparse_matrix.cc index 8b683ddb7e..3083a8389c 100644 --- a/deal.II/lac/source/trilinos_block_sparse_matrix.cc +++ b/deal.II/lac/source/trilinos_block_sparse_matrix.cc @@ -47,18 +47,6 @@ namespace TrilinosWrappers - BlockSparseMatrix & - BlockSparseMatrix::operator = (const double d) - { - for (unsigned int r=0; rn_block_rows(); ++r) - for (unsigned int c=0; cn_block_cols(); ++c) - this->block(r,c) = d; - - return *this; - } - - - void BlockSparseMatrix:: reinit (const unsigned int n_block_rows,