]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
unary - for Point and Tensor
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 27 Oct 2000 10:15:40 +0000 (10:15 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 27 Oct 2000 10:15:40 +0000 (10:15 +0000)
git-svn-id: https://svn.dealii.org/trunk@3466 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/point.h
deal.II/base/include/base/tensor.h
deal.II/base/include/base/tensor_base.h

index 09caecfb2d455f9f856814ffd6d35d96cbe53782..0a24d1465fe6431036307b8641dc7f9d108742f5 100644 (file)
@@ -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<dim>   operator - (const Point<dim> &) const;
 
+                                      /**
+                                       * The opposite vector.
+                                       */
+    Point<dim>   operator - () const;
+    
                                     /**
                                      *  Multiply by a factor. If possible, use
                                      *  @p{operator *=} instead since this does not
@@ -296,6 +306,15 @@ Point<dim> Point<dim>::operator - (const Point<dim> &p) const
 
 
 
+template <int dim>
+inline
+Point<dim> Point<dim>::operator - () const 
+{
+  return (Point<dim>(*this) -(*(Tensor<1,dim>*)this));
+};
+
+
+
 template <int dim>
 inline
 Point<dim> Point<dim>::operator * (const double factor) const 
index 207cec5af517f4bad432a1ccb302c6781a005541..98e6576fb72d90032b646485598c49ba6063a99f 100644 (file)
@@ -140,6 +140,11 @@ class Tensor
                                      */
     Tensor<rank_,dim>   operator - (const Tensor<rank_,dim> &) const;
 
+                                      /**
+                                       * Invert all entries of a tensor.
+                                       */
+    Tensor<rank_,dim>   operator - () const;
+    
                                     /**
                                      * Fill a vector with all tensor elements.
                                      *
@@ -340,6 +345,20 @@ Tensor<rank_,dim>::operator - (const Tensor<rank_,dim> &t) const
 };
 
 
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim>
+Tensor<rank_,dim>::operator - () const
+{
+  Tensor<rank_,dim> tmp;
+  
+  for (unsigned int i=0; i<dim; ++i)
+    tmp.subtensor[i] = -subtensor[i];
+
+  return tmp;
+};
+
+
 template <int rank_, int dim>
 inline
 void Tensor<rank_,dim>::clear ()
index 39d48df79056f3c5319015aef00af51c14895ee6..ef7900b752a630edd2994d07cfff74cf6a100293 100644 (file)
@@ -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 <int dim>
+inline
+Tensor<1,dim> Tensor<1,dim>::operator - () const
+{
+  Tensor<1,dim> result;
+  for (unsigned int i=0; i<dim; ++i)
+      result.values[i] = -values[i];
+  return result;
+};
+
+
+
 template <int dim>
 inline
 void Tensor<1,dim>::clear ()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.