From 587ab5169865477b4741fcd4c1d69664eb80d09a Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 27 Sep 2001 13:11:12 +0000 Subject: [PATCH] Templatize the scalar product between vectors on the underlying types. This allows scalar products between vectors of float and double, etc. git-svn-id: https://svn.dealii.org/trunk@5110 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/vector.h | 13 +++++++++++-- deal.II/lac/include/lac/vector.templates.h | 11 ++++++----- deal.II/lac/source/vector.cc | 4 ++++ deal.II/lac/source/vector.long_double.cc | 6 ++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 7533548e7d..bc5305d9b0 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -203,9 +203,18 @@ class Vector Vector & operator= (const Vector& V); /** - * $U = U * V$: scalar product. + * Return the scalar product of + * two vectors. The return type + * is the underlying type of + * @p{this} vector, so the return + * type and the accuracy with + * which it the result is + * computed depend on the order + * of the arguments of this + * vector. */ - Number operator* (const Vector& V) const; + template + Number operator* (const Vector &V) const; /** * Return square of the $l_2$-norm. diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 3ce808a5ba..842fdf818f 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -104,14 +104,15 @@ bool Vector::all_zero () const template -Number Vector::operator * (const Vector& v) const +template +Number Vector::operator * (const Vector& v) const { Assert (dim!=0, ExcEmptyVector()); - - if (&v == this) + + if (this == reinterpret_cast*>(&v)) return norm_sqr(); - Assert (dim == v.dim, ExcDimensionMismatch(dim, v.dim)); + Assert (dim == v.size(), ExcDimensionMismatch(dim, v.size())); Number sum0 = 0, sum1 = 0, @@ -122,8 +123,8 @@ Number Vector::operator * (const Vector& v) const // allowing pipelined commands to be // executed in parallel const_iterator ptr = begin(), - vptr = v.begin(), eptr = ptr + (dim/4)*4; + typename Vector::const_iterator vptr = v.begin(); while (ptr!=eptr) { sum0 += (*ptr++ * *vptr++); diff --git a/deal.II/lac/source/vector.cc b/deal.II/lac/source/vector.cc index 2ff0e2217f..d007108eeb 100644 --- a/deal.II/lac/source/vector.cc +++ b/deal.II/lac/source/vector.cc @@ -17,9 +17,13 @@ // explicit instantiations template class Vector; template Vector& Vector::operator=(const Vector&); +template double Vector::operator*(const Vector&) const; +template double Vector::operator*(const Vector&) const; template class Vector; template Vector& Vector::operator=(const Vector&); +template float Vector::operator*(const Vector&) const; +template float Vector::operator*(const Vector&) const; // see the .h file for why these functions are disabled. // template Vector::Vector (const Vector& v); diff --git a/deal.II/lac/source/vector.long_double.cc b/deal.II/lac/source/vector.long_double.cc index 86b8d00969..e8a7d17ee3 100644 --- a/deal.II/lac/source/vector.long_double.cc +++ b/deal.II/lac/source/vector.long_double.cc @@ -16,10 +16,16 @@ // explicit instantiations template class Vector; + template Vector& Vector::operator=(const Vector&); template Vector& Vector::operator=(const Vector&); template Vector& Vector::operator=(const Vector&); template Vector& Vector::operator=(const Vector&); + +template float Vector::operator * (const Vector &) const; +template double Vector::operator * (const Vector &) const; +template long double Vector::operator * (const Vector &) const; +template long double Vector::operator * (const Vector &) const; // see the .h file for why these functions are disabled. // template Vector::Vector (const Vector& v); // template Vector::Vector (const Vector& v); -- 2.39.5