]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Restructure declarations in tensor_base.h and tensor.h
authorMatthias Maier <tamiko@43-1.org>
Wed, 2 Sep 2015 22:17:06 +0000 (17:17 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 18:27:20 +0000 (13:27 -0500)
Move everything that isn't necessary from tensor_base.h to tensor.h

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

index 224e3fc5fdd139369b027f3ad473a527a7a37c98..738be73325e2e3c0b06a0c1c7c3f857b2648f2b2 100644 (file)
 DEAL_II_NAMESPACE_OPEN
 
 
-
 /* ----------------- Non-member functions operating on tensors. ------------ */
 
-
+/**
+ * @name Output functions for Tensor objects
+ */
+//@{
 
 /**
  * Output operator for tensors. Print the elements consecutively, with a space
@@ -46,10 +48,13 @@ std::ostream &operator << (std::ostream &out, const Tensor<rank_,dim,Number> &p)
   return out;
 }
 
-#ifndef DOXYGEN
 
 /**
- * Specialization for 1D.
+ * Output operator for tensors and dimension 1. This is implemented
+ * specialized from the general template in order to avoid a compiler
+ * warning that the loop is empty.
+ *
+ * @relates Tensor
  */
 template <int rank_>
 inline
@@ -60,7 +65,212 @@ std::ostream &operator << (std::ostream &out, const Tensor<rank_,1> &p)
   return out;
 }
 
-#endif // DOXYGEN
+
+/**
+ * Output operator for tensors of rank 0. Since such tensors are scalars, we
+ * simply print this one value.
+ *
+ * @relates Tensor<0,dim,Number>
+ */
+template <int dim, typename Number>
+inline
+std::ostream &operator << (std::ostream &out, const Tensor<0,dim,Number> &p)
+{
+  out << static_cast<Number>(p);
+  return out;
+}
+
+
+/**
+ * Output operator for tensors of rank 1. Print the elements consecutively,
+ * with a space in between.
+ *
+ * @relates Tensor<1,dim,Number>
+ */
+template <int dim, typename Number>
+inline
+std::ostream &operator << (std::ostream &out, const Tensor<1,dim,Number> &p)
+{
+  for (unsigned int i=0; i<dim-1; ++i)
+    out << p[i] << ' ';
+  out << p[dim-1];
+
+  return out;
+}
+
+
+/**
+ * Output operator for tensors of rank 1 and dimension 1. This is implemented
+ * specialized from the general template in order to avoid a compiler warning
+ * that the loop is empty.
+ *
+ * @relates Tensor<1,dim,Number>
+ */
+inline
+std::ostream &operator << (std::ostream &out, const Tensor<1,1,double> &p)
+{
+  out << p[0];
+
+  return out;
+}
+
+
+//@}
+/**
+ * @name Vector space operations on Tensor objects:
+ */
+//@{
+
+/**
+ * Scalar multiplication of a tensor of rank 0 with a scalar from the left.
+ *
+ * @relates Tensor<0,dim,Number>
+ * @relates EnableIfScalar
+ */
+template <int dim,
+         typename Number,
+         typename OtherNumber,
+         typename = typename EnableIfScalar<OtherNumber>::type>
+inline
+Tensor<0,dim,typename ProductType<OtherNumber, Number>::type>
+operator * (const OtherNumber           factor,
+            const Tensor<0,dim,Number> &t)
+{
+  return factor * static_cast<Number>(t);
+}
+
+
+/**
+ * Scalar multiplication of a tensor of rank 0 with a scalar from the right.
+ *
+ * @relates Tensor<0,dim,Number>
+ * @relates EnableIfScalar
+ */
+template <int dim,
+         typename Number,
+         typename OtherNumber,
+         typename = typename EnableIfScalar<OtherNumber>::type>
+inline
+Tensor<0,dim,typename ProductType<Number, OtherNumber>::type>
+operator * (const Tensor<0,dim,Number> &t,
+            const OtherNumber           factor)
+{
+  return static_cast<Number>(t) * factor;
+}
+
+
+/**
+ * Division of a tensor of rank 0 with a scalar number.
+ *
+ * @relates Tensor<0,dim,Number>
+ * @relates EnableIfScalar
+ */
+template <int dim,
+         typename Number,
+         typename OtherNumber,
+         typename = typename EnableIfScalar<OtherNumber>::type>
+inline
+Tensor<0,dim,typename ProductType<Number, OtherNumber>::type>
+operator / (const Tensor<0,dim,Number> &t,
+            const OtherNumber           factor)
+{
+  return static_cast<Number>(t) / factor;
+}
+
+
+/**
+ * Add two tensors of rank 0.
+ *
+ * @relates Tensor<0,dim,Number>
+ */
+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.
+ *
+ * @relates Tensor<0,dim,Number>
+ */
+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);
+}
+
+
+//@}
+/**
+ * @name Contraction operations on Tensors
+ */
+//@{
+
+/**
+ * Returns the contraction of two Tensors of rank 0.
+ *
+ * @relates Tensor<0,dim,Number>
+ */
+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);
+}
+
+//@}
+
+
+/**
+ * Contract a tensor of rank 1 with a tensor of rank 1. The result is
+ * <tt>sum_j src1[j] src2[j]</tt>.
+ *
+ * @relates Tensor
+ */
+template <int dim, typename Number, typename OtherNumber>
+inline
+typename ProductType<Number,OtherNumber>::type
+contract (const Tensor<1,dim,Number> &src1,
+          const Tensor<1,dim,OtherNumber> &src2)
+{
+  typename ProductType<Number,OtherNumber>::type res
+    = typename ProductType<Number,OtherNumber>::type();
+  for (unsigned int i=0; i<dim; ++i)
+    res += src1[i] * src2[i];
+
+  return res;
+}
+
+
+/**
+ * Multiplication operator performing a contraction of the last index of the
+ * first argument and the first index of the second argument. This function
+ * therefore does the same as the corresponding <tt>contract</tt> function,
+ * but returns the result as a return value, rather than writing it into the
+ * reference given as the first argument to the <tt>contract</tt> function.
+ *
+ * Note that for the <tt>Tensor</tt> class, the multiplication operator only
+ * performs a contraction over a single pair of indices. This is in contrast
+ * to the multiplication operator for symmetric tensors, which does the double
+ * contraction.
+ *
+ * @relates Tensor
+ */
+template <int dim, typename Number, typename OtherNumber>
+inline
+typename ProductType<Number,OtherNumber>::type
+operator * (const Tensor<1,dim,Number> &src1,
+            const Tensor<1,dim,OtherNumber> &src2)
+{
+  return contract(src1, src2);
+}
 
 
 /**
index ada55ccbd85e3351504debb8325b7b2ca6818c15..08a1d022dd2bb764e99b611205cf02f9ddb63931 100644 (file)
@@ -633,12 +633,10 @@ private:
 };
 
 
-
 #ifndef DOXYGEN
 /*---------------------- Inline functions: Tensor<0,dim> ---------------------*/
 
 
-
 template <int dim,typename Number>
 inline
 Tensor<0,dim,Number>::Tensor ()
@@ -1258,9 +1256,7 @@ Tensor<rank_,dim,Number>::serialize(Archive &ar, const unsigned int)
 /* ----------------- Non-member functions operating on tensors. ------------- */
 
 
-
 #ifndef DEAL_II_WITH_CXX11
-
 template <typename T, typename U, int rank, int dim>
 struct ProductType<T,Tensor<rank,dim,U> >
 {
@@ -1272,171 +1268,16 @@ struct ProductType<Tensor<rank,dim,T>,U>
 {
   typedef Tensor<rank,dim,typename ProductType<T,U>::type> type;
 };
-
 #endif
 
-
-/**
- * TODO
- *
- * @relates Tensor
- * @relates EnableIfScalar
- */
-template <int dim,
-         typename Number,
-         typename OtherNumber,
-         typename = typename EnableIfScalar<OtherNumber>::type>
-inline
-Tensor<0,dim,typename ProductType<OtherNumber, Number>::type>
-operator * (const OtherNumber           factor,
-            const Tensor<0,dim,Number> &t)
-{
-  return factor * static_cast<Number>(t);
-}
-
-
-
-/**
- * TODO
- *
- * @relates Tensor
- * @relates EnableIfScalar
- */
-template <int dim,
-         typename Number,
-         typename OtherNumber,
-         typename = typename EnableIfScalar<OtherNumber>::type>
-inline
-Tensor<0,dim,typename ProductType<Number, OtherNumber>::type>
-operator * (const Tensor<0,dim,Number> &t,
-            const OtherNumber           factor)
-{
-  return static_cast<Number>(t) * factor;
-}
-
-
-
-/**
- * TODO
- *
- * @relates Tensor
- * @relates EnableIfScalar
- */
-template <int dim,
-         typename Number,
-         typename OtherNumber,
-         typename = typename EnableIfScalar<OtherNumber>::type>
-inline
-Tensor<0,dim,typename ProductType<Number, OtherNumber>::type>
-operator / (const Tensor<0,dim,Number> &t,
-            const OtherNumber           factor)
-{
-  return static_cast<Number>(t) / factor;
-}
-
-
-
-/**
- * Add two tensors of rank 0.
- *
- * @relates Tensor
- */
-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.
- *
- * @relates Tensor
- */
-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);
-}
-
-
-// TODO:
-
-
-/**
- * Output operator for tensors of rank 0. Since such tensors are scalars, we
- * simply print this one value.
- *
- * @relates Tensor<0,dim,Number>
- */
-template <int dim, typename Number>
-inline
-std::ostream &operator << (std::ostream &out, const Tensor<0,dim,Number> &p)
-{
-  out << static_cast<Number>(p);
-  return out;
-}
-
-
-
 /**
- * Output operator for tensors of rank 1. Print the elements consecutively,
- * with a space in between.
- *
- * @relates Tensor<1,dim,Number>
+ * @name Vector space operations on Tensor objects:
  */
-template <int dim, typename Number>
-inline
-std::ostream &operator << (std::ostream &out, const Tensor<1,dim,Number> &p)
-{
-  for (unsigned int i=0; i<dim-1; ++i)
-    out << p[i] << ' ';
-  out << p[dim-1];
-
-  return out;
-}
-
-
+//@{
 
 /**
- * Output operator for tensors of rank 1 and dimension 1. This is implemented
- * specialized from the general template in order to avoid a compiler warning
- * that the loop is empty.
- *
- * @relates Tensor<1,dim,Number>
- */
-inline
-std::ostream &operator << (std::ostream &out, const Tensor<1,1,double> &p)
-{
-  out << p[0];
-
-  return out;
-}
-
-
-
-/**
- * Multiplication of a tensor of rank with a scalar number from the right.
+ * Multiplication of a tensor of general rank with a scalar number from the
+ * right.
  *
  * The purpose of this operator is to enable only multiplication of a tensor
  * by a scalar number (i.e., a floating point number, a complex floating point
@@ -1477,7 +1318,6 @@ operator * (const Tensor<rank,dim,Number> &t,
 }
 
 
-
 /**
  * Multiplication of a tensor of general rank with a scalar number from the
  * left. See the discussion with the operator with switched arguments for more
@@ -1500,7 +1340,6 @@ operator * (const Number                        factor,
 }
 
 
-
 /**
  * Division of a tensor of general rank with a scalar number. See the
  * discussion on operator*() above for more information about template
@@ -1526,7 +1365,6 @@ operator / (const Tensor<rank,dim,Number> &t,
 }
 
 
-
 /**
  * Addition of two tensors of general @tparam rank.
  *
@@ -1546,7 +1384,6 @@ operator+ (const Tensor<rank,dim,Number> &p, const Tensor<rank,dim,OtherNumber>
 }
 
 
-
 /**
  * Subtraction of two tensors of general @tparam rank.
  *
@@ -1565,52 +1402,7 @@ operator- (const Tensor<rank,dim,Number> &p, const Tensor<rank,dim,OtherNumber>
   return tmp;
 }
 
-
-
-/**
- * Contract a tensor of rank 1 with a tensor of rank 1. The result is
- * <tt>sum_j src1[j] src2[j]</tt>.
- *
- * @relates Tensor
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-typename ProductType<Number,OtherNumber>::type
-contract (const Tensor<1,dim,Number> &src1,
-          const Tensor<1,dim,OtherNumber> &src2)
-{
-  typename ProductType<Number,OtherNumber>::type res
-    = typename ProductType<Number,OtherNumber>::type();
-  for (unsigned int i=0; i<dim; ++i)
-    res += src1[i] * src2[i];
-
-  return res;
-}
-
-
-/**
- * Multiplication operator performing a contraction of the last index of the
- * first argument and the first index of the second argument. This function
- * therefore does the same as the corresponding <tt>contract</tt> function,
- * but returns the result as a return value, rather than writing it into the
- * reference given as the first argument to the <tt>contract</tt> function.
- *
- * Note that for the <tt>Tensor</tt> class, the multiplication operator only
- * performs a contraction over a single pair of indices. This is in contrast
- * to the multiplication operator for symmetric tensors, which does the double
- * contraction.
- *
- * @relates Tensor
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-typename ProductType<Number,OtherNumber>::type
-operator * (const Tensor<1,dim,Number> &src1,
-            const Tensor<1,dim,OtherNumber> &src2)
-{
-  return contract(src1, src2);
-}
-
+//@}
 
 
 DEAL_II_NAMESPACE_CLOSE

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.