From 7947644d7bd5370a64180f56e4b77fd7cfbee876 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 14 Aug 2001 09:08:25 +0000 Subject: [PATCH] Implement operator*= for vectors and block vectors. git-svn-id: https://svn.dealii.org/trunk@4878 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/block_vector.h | 20 +++++++++++++++++ deal.II/lac/include/lac/vector.h | 31 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/deal.II/lac/include/lac/block_vector.h b/deal.II/lac/include/lac/block_vector.h index cf3742122d..20c75c26cf 100644 --- a/deal.II/lac/include/lac/block_vector.h +++ b/deal.II/lac/include/lac/block_vector.h @@ -441,6 +441,16 @@ class BlockVector */ void scale (const Number factor); + /** + * Scale each element of the + * vector by a constant + * value. This operator is an + * alias to the @ref{scale} + * function, except that it + * returns a reference to itself. + */ + BlockVector & operator *= (const Number factor); + /** * U=a*V. Replacing. */ @@ -605,6 +615,16 @@ Number& BlockVector::operator() (const unsigned int i) +template +inline +BlockVector & BlockVector::operator *= (const Number factor) +{ + scale (factor); + return *this; +}; + + + template inline Vector & diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 60bd884573..7533548e7d 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -377,9 +377,18 @@ class Vector * Scale each element of the * vector by the given factor. */ -//TODO:[?] Why not have an operator *= instead of/in addition to `scale'? void scale (const Number factor); + /** + * Scale each element of the + * vector by a constant + * value. This operator is an + * alias to the @ref{scale} + * function, except that it + * returns a reference to itself. + */ + Vector & operator *= (const Number factor); + /** * Scale each element of this * vector by the corresponding @@ -560,6 +569,7 @@ Vector::Vector (const unsigned int n) : } + template inline Vector::~Vector () @@ -572,6 +582,7 @@ Vector::~Vector () } + template inline void Vector::reinit (const unsigned int n, const bool fast) @@ -597,6 +608,7 @@ void Vector::reinit (const unsigned int n, const bool fast) } + template inline void Vector::clear () @@ -606,6 +618,7 @@ void Vector::clear () } + template inline unsigned int Vector::size () const @@ -614,6 +627,7 @@ unsigned int Vector::size () const } + template inline typename Vector::iterator @@ -623,6 +637,7 @@ Vector::begin () }; + template inline typename Vector::const_iterator @@ -632,6 +647,7 @@ Vector::begin () const }; + template inline typename Vector::iterator @@ -641,6 +657,7 @@ Vector::end () }; + template inline typename Vector::const_iterator @@ -650,6 +667,7 @@ Vector::end () const }; + template inline Number Vector::operator() (const unsigned int i) const @@ -659,6 +677,7 @@ Number Vector::operator() (const unsigned int i) const } + template inline Number& Vector::operator() (const unsigned int i) @@ -669,6 +688,16 @@ Number& Vector::operator() (const unsigned int i) +template +inline +Vector & Vector::operator *= (const Number factor) +{ + scale (factor); + return *this; +}; + + + /** * Global function @p{swap} which overloads the default implementation * of the C++ standard library which uses a temporary object. The -- 2.39.5