]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
<< for tensors of arbitrary rank
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 Mar 2001 11:16:05 +0000 (11:16 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 Mar 2001 11:16:05 +0000 (11:16 +0000)
git-svn-id: https://svn.dealii.org/trunk@4098 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 5b4ea1fece7fbdc62e6c01aff8dc8c66f9e1028c..1656ed9af21c1e2a5ef410c9ce2dfa644eafbcb1 100644 (file)
@@ -397,6 +397,37 @@ DeclException1 (ExcInvalidTensorIndex,
                << "Invalid tensor index " << arg1);
 
 
+/**
+ * Output operator for tensors. Print the elements consecutively, with
+ * a space in between, two spaces between rank 1 subtensors, three
+ * between rank 2 and so on.
+ */
+template <int rank_, int dim>
+inline
+std::ostream & operator << (std::ostream &out, const Tensor<rank_,dim> &p)
+{
+  for (unsigned int i=0; i<dim-1; ++i)
+    out << p[i] << ' ';
+  out << p[dim-1];
+
+  return out;
+};
+
+
+/**
+ * Specialization for 1D.
+ */
+template <int rank_>
+inline
+std::ostream & operator << (std::ostream &out, const Tensor<rank_,1> &p)
+{
+  out << p[0];
+
+  return out;
+};
+
+
+
 /**
  * Contract a tensor of rank 1 with a tensor of rank 1. The result is
  * @p{sum_j src1[j] src2[j]}.

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.