From 5d91aa20ff6553297e9046a4e983648be49beaa3 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Fri, 27 Oct 2000 10:15:40 +0000 Subject: [PATCH] unary - for Point and Tensor git-svn-id: https://svn.dealii.org/trunk@3466 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/point.h | 19 +++++++++++++++++++ deal.II/base/include/base/tensor.h | 19 +++++++++++++++++++ deal.II/base/include/base/tensor_base.h | 17 +++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/deal.II/base/include/base/point.h b/deal.II/base/include/base/point.h index 09caecfb2d..0a24d1465f 100644 --- a/deal.II/base/include/base/point.h +++ b/deal.II/base/include/base/point.h @@ -93,6 +93,11 @@ class Point : public Tensor<1,dim> */ double & operator () (const unsigned int index); +/* + * Plus and minus operators are re-implemented from Tensor<1,dim> + * to avoid additional casting. + */ + /** * Add two point vectors. If possible, use * @p{operator +=} instead since this does not @@ -107,6 +112,11 @@ class Point : public Tensor<1,dim> */ Point operator - (const Point &) const; + /** + * The opposite vector. + */ + Point operator - () const; + /** * Multiply by a factor. If possible, use * @p{operator *=} instead since this does not @@ -296,6 +306,15 @@ Point Point::operator - (const Point &p) const +template +inline +Point Point::operator - () const +{ + return (Point(*this) -(*(Tensor<1,dim>*)this)); +}; + + + template inline Point Point::operator * (const double factor) const diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 207cec5af5..98e6576fb7 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -140,6 +140,11 @@ class Tensor */ Tensor operator - (const Tensor &) const; + /** + * Invert all entries of a tensor. + */ + Tensor operator - () const; + /** * Fill a vector with all tensor elements. * @@ -340,6 +345,20 @@ Tensor::operator - (const Tensor &t) const }; +template +inline +Tensor +Tensor::operator - () const +{ + Tensor tmp; + + for (unsigned int i=0; i inline void Tensor::clear () diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 39d48df790..ef7900b752 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -191,6 +191,11 @@ class Tensor<1,dim> { */ Tensor<1,dim> operator - (const Tensor<1,dim> &) const; + /** + * Tensor with inverted entries. + */ + Tensor<1,dim> operator - () const; + /** * Reset all values to zero. */ @@ -416,6 +421,18 @@ Tensor<1,dim> Tensor<1,dim>::operator - (const Tensor<1,dim> &p) const +template +inline +Tensor<1,dim> Tensor<1,dim>::operator - () const +{ + Tensor<1,dim> result; + for (unsigned int i=0; i inline void Tensor<1,dim>::clear () -- 2.39.5