]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Implement the transpose of a tensor of rank 2.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 3 Sep 2002 15:24:02 +0000 (15:24 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 3 Sep 2002 15:24:02 +0000 (15:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@6345 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/tensor.h
deal.II/doc/news/2002/c-3-4.html

index 771a26115c85fb3708a113e17a0bed482cd910a6..52ea6f6ffe4c0e5665c19adaf0b35b80ea602f73 100644 (file)
@@ -1012,6 +1012,85 @@ invert (const Tensor<2,dim> &t)
 
 
 
+/**
+ * Return the transpose of the given tensor. Since the compiler can
+ * perform the return value optimization, and since the size of the
+ * return object is known, it is acceptable to return the result by
+ * value, rather than by reference as a parameter. Note that there are
+ * specializations of this function for @p{dim==1,2,3}.
+ *
+ * @author Wolfgang Bangerth, 2002
+ */
+template <int dim>
+inline
+Tensor<2,dim>
+transpose (const Tensor<2,dim> &t) 
+{
+  Tensor<2,dim> tt = t;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i+1; j<dim; ++j)
+      {
+        const double x = tt[i][j];
+        tt[i][j] = tt[j][i];
+        tt[j][i] = x;
+      };
+  return tt;
+};
+
+
+
+/**
+ * Return the transpose of the given tensor. This is the
+ * specialization of the general template for @p{dim==1}.
+ *
+ * @author Wolfgang Bangerth, 2002
+ */
+inline
+Tensor<2,1>
+transpose (const Tensor<2,1> &t) 
+{
+  return t;
+};
+
+
+
+
+/**
+ * Return the transpose of the given tensor. This is the
+ * specialization of the general template for @p{dim==2}.
+ *
+ * @author Wolfgang Bangerth, 2002
+ */
+inline
+Tensor<2,2>
+transpose (const Tensor<2,2> &t) 
+{
+  const double x[2][2] = {{t[0][0], t[1][0]}, {t[0][1], t[1][1]}};
+  return Tensor<2,2>(x);
+};
+
+
+
+
+/**
+ * Return the transpose of the given tensor. This is the
+ * specialization of the general template for @p{dim==3}.
+ *
+ * @author Wolfgang Bangerth, 2002
+ */
+inline
+Tensor<2,3>
+transpose (const Tensor<2,3> &t) 
+{
+  const double x[3][3] = {{t[0][0], t[1][0], t[2][0]},
+                          {t[0][1], t[1][1], t[2][1]},
+                          {t[0][2], t[1][2], t[2][2]}};
+  return Tensor<2,3>(x);
+};
+
+
+
+
 /**
  * Multiplication of a tensor of general rank with a scalar double
  * from the right.
index c5a1c4f87024a2fcee08f6c61bf8db795f200dfe..5eae17f4329633589b5d4575398586453af5f988 100644 (file)
@@ -95,6 +95,13 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>base</h3>
 
 <ol>
+  <li> <p> 
+       New: There are now functions returning the transpose of <code
+       class="class">Tensor</code> objects of rank 2.
+       <br>
+       (WB 2002/08/31)
+       </p>
+
   <li> <p> 
        New: Row accessors for the <code class="class">vector2d</code>
        class now have a member function <code
@@ -211,7 +218,7 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
        (RH 2002/06/14)
        </p>
 
-  <li> <p> Fix: Bug in <code
+  <li> <p> Fixed: Bug in <code
        class="member">Triangulation<3>::load_user_flags(vector&lt;bool&gt;
        &)</code> is now fixed.
        <br>
@@ -226,7 +233,7 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
        (RH 2002/06/14)
        </p>
 
-  <li> <p> Change: <code
+  <li> <p> Changed: <code
        class="member">Triangulation<1>::n_quads</code> now returns 0,
        instead of throwing an assertion, as before. The same holds for
        similar functions like <code

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.