]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tensor<0,dim>: Use cast instead of friend declaration to access value
authorMatthias Maier <tamiko@43-1.org>
Tue, 1 Sep 2015 23:37:21 +0000 (18:37 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 18:27:20 +0000 (13:27 -0500)
include/deal.II/base/tensor_base.h

index d8c29c411f1cd16e4e9c71132b04a45b8fae6597..29a551be5f1c2c6c60afdd15de2149536f219968 100644 (file)
@@ -267,21 +267,6 @@ private:
    * The value of this scalar object.
    */
   Number value;
-
-  template <int dim2, typename Number2, typename OtherNumber>
-  friend Tensor<0, dim2, typename ProductType<Number2, OtherNumber>::type>
-  operator*(const Tensor<0, dim2, Number2> &,
-            const Tensor<0, dim2, OtherNumber> &);
-
-  template <int dim2, typename Number2, typename OtherNumber>
-  friend Tensor<0, dim2, typename ProductType<Number2, OtherNumber>::type>
-  operator+(const Tensor<0, dim2, Number2> &,
-            const Tensor<0, dim2, OtherNumber> &);
-
-  template <int dim2, typename Number2, typename OtherNumber>
-  friend Tensor<0, dim2, typename ProductType<Number2, OtherNumber>::type>
-  operator-(const Tensor<0, dim2, Number2> &,
-            const Tensor<0, dim2, OtherNumber> &);
 };
 
 
@@ -832,7 +817,7 @@ template <int dim, typename Number>
 inline
 void Tensor<0,dim,Number>::clear ()
 {
-  value = 0;
+  value = value_type();
 }
 
 
@@ -847,45 +832,6 @@ void Tensor<0,dim,Number>::serialize(Archive &ar, const unsigned int)
 
 
 
-/**
- * Returns the product of two Tensors of rank 0.
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-Tensor<0, dim, typename ProductType<Number, OtherNumber>::type>
-operator* (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
-{
-  return p.value * q.value;
-}
-
-
-
-/**
- * Add two tensors of rank 0.
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-Tensor<0, dim, typename ProductType<Number, OtherNumber>::type>
-operator+ (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
-{
-  return p.value + q.value;
-}
-
-
-
-/**
- * Subtract two tensors of rank 0.
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-Tensor<0, dim, typename ProductType<Number, OtherNumber>::type>
-operator- (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
-{
-  return p.value - q.value;
-}
-
-
-
 #ifndef DEAL_II_WITH_CXX11
 
 template <typename T, typename U, int rank, int dim>
@@ -964,6 +910,47 @@ operator / (const Tensor<0,dim,Number> &t,
 
 
 
+/**
+ * Add two tensors of rank 0.
+ */
+template <int dim, typename Number, typename OtherNumber>
+inline
+Tensor<0, dim, typename ProductType<Number, OtherNumber>::type>
+operator+ (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
+{
+  return static_cast<Number>(p) + static_cast<OtherNumber>(q);
+}
+
+
+
+/**
+ * Subtract two tensors of rank 0.
+ */
+template <int dim, typename Number, typename OtherNumber>
+inline
+Tensor<0, dim, typename ProductType<Number, OtherNumber>::type>
+operator- (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
+{
+  return static_cast<Number>(p) - static_cast<OtherNumber>(q);
+}
+
+
+
+/**
+ * Returns the contraction of two Tensors of rank 0.
+ *
+ * @relates Tensor
+ */
+template <int dim, typename Number, typename OtherNumber>
+inline
+typename ProductType<Number, OtherNumber>::type
+operator* (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q)
+{
+  return static_cast<Number>(p) * static_cast<OtherNumber>(q);
+}
+
+
+
 /*---------------------- Inline functions: Tensor<1,dim> ---------------------*/
 
 

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.