]> https://gitweb.dealii.org/ - dealii.git/commitdiff
More conversion functions between symmetric tensor indices and the indices of an...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 24 Sep 2009 22:08:57 +0000 (22:08 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 24 Sep 2009 22:08:57 +0000 (22:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@19532 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/symmetric_tensor.h
deal.II/doc/news/changes.h
tests/base/symmetric_tensor_24.cc [new file with mode: 0644]
tests/base/symmetric_tensor_24/cmp/generic [new file with mode: 0644]

index 320ccabc8f5c20e8f5471c46adbb3dc35fbccbc8..2fbc0624067f85369ede471d8acdadba015ec4eb 100644 (file)
@@ -908,7 +908,21 @@ class SymmetricTensor
                                      */
     static
     unsigned int
-    unrolled_index (const TableIndices<rank> &indices);
+    component_to_unrolled_index (const TableIndices<rank> &indices);
+
+                                    /**
+                                     * The opposite of the previous
+                                     * function: given an index $i$
+                                     * in the unrolled form of the
+                                     * tensor, return what set of
+                                     * indices $(k,l)$ (for rank-2
+                                     * tensors) or $(k,l,m,n)$ (for
+                                     * rank-4 tensors) corresponds to
+                                     * it.
+                                     */
+    static
+    TableIndices<rank>
+    unrolled_to_component_indices (const unsigned int i);
 
                                     /**
                                      * Reset all values to zero.
@@ -1988,7 +2002,7 @@ SymmetricTensor<4,3>::norm () const
 template <>
 inline
 unsigned int
-SymmetricTensor<2,1>::unrolled_index (const TableIndices<2> &indices)
+SymmetricTensor<2,1>::component_to_unrolled_index (const TableIndices<2> &indices)
 {
   const unsigned int dim = 1;
   Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim));
@@ -2002,7 +2016,7 @@ SymmetricTensor<2,1>::unrolled_index (const TableIndices<2> &indices)
 template <>
 inline
 unsigned int
-SymmetricTensor<2,2>::unrolled_index (const TableIndices<2> &indices)
+SymmetricTensor<2,2>::component_to_unrolled_index (const TableIndices<2> &indices)
 {
   const unsigned int dim = 2;
   Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim));
@@ -2019,7 +2033,7 @@ SymmetricTensor<2,2>::unrolled_index (const TableIndices<2> &indices)
 template <>
 inline
 unsigned int
-SymmetricTensor<2,3>::unrolled_index (const TableIndices<2> &indices)
+SymmetricTensor<2,3>::component_to_unrolled_index (const TableIndices<2> &indices)
 {
   const unsigned int dim = 3;
   Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim));
@@ -2034,6 +2048,55 @@ SymmetricTensor<2,3>::unrolled_index (const TableIndices<2> &indices)
 
 
 
+template <>
+inline
+TableIndices<2>
+SymmetricTensor<2,1>::unrolled_to_component_indices (const unsigned int i)
+{
+  Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components));
+
+  return TableIndices<2>(0,0);
+}
+
+
+
+template <>
+inline
+TableIndices<2>
+SymmetricTensor<2,2>::unrolled_to_component_indices (const unsigned int i)
+{
+  Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components));
+
+  static const TableIndices<2> table[n_independent_components] =
+    { TableIndices<2> (0,0),
+      TableIndices<2> (1,1),
+      TableIndices<2> (0,1) };
+
+  return table[i];
+}
+
+
+
+template <>
+inline
+TableIndices<2>
+SymmetricTensor<2,3>::unrolled_to_component_indices (const unsigned int i)
+{
+  Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components));
+
+  static const TableIndices<2> table[n_independent_components] =
+    { TableIndices<2> (0,0),
+      TableIndices<2> (1,1),
+      TableIndices<2> (2,2),
+      TableIndices<2> (0,1),
+      TableIndices<2> (0,2),
+      TableIndices<2> (1,2) };
+
+  return table[i];
+}
+
+
+
 
 #endif // DOXYGEN
 
index 620070ca9fa48f6bcba98eb3d356141e2ecfcb96..80021ecc9bc5b9cc8005d744063cf40768accd79 100644 (file)
@@ -231,8 +231,9 @@ inconvenience this causes.
   </p>
   </li>
 
-  <li><p>New: SymmetricTensor::unrolled_index() returns the index of an element of
-  a symmetric tensor within an unrolled vector.
+  <li><p>New: SymmetricTensor::component_to_unrolled_index() and
+  SymmetricTensor::unrolled_to_component_indices() allow to convert between the
+  indices of an element of a symmetric tensor and the index within an unrolled vector.
   <br>
   (WB 2009/09/23)
   </p></li>
diff --git a/tests/base/symmetric_tensor_24.cc b/tests/base/symmetric_tensor_24.cc
new file mode 100644 (file)
index 0000000..9d7b8e9
--- /dev/null
@@ -0,0 +1,56 @@
+//----------------------------  symmetric_tensor_24.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2006, 2008, 2009 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  symmetric_tensor_24.cc  ---------------------------
+
+// check SymmetricTensor<2,dim>::component_to_unrolled_index and the
+// other way round
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <fstream>
+#include <iomanip>
+
+
+template <int dim>
+void check ()
+{
+  typedef SymmetricTensor<2,dim> S;
+  for (unsigned int i=0; i<S::n_independent_components; ++i)
+    {
+      deallog << i << "  --  "
+             << S::unrolled_to_component_indices (i)
+             << std::endl;
+      Assert (S::component_to_unrolled_index
+             (S::unrolled_to_component_indices (i))
+             ==
+             i,
+             ExcInternalError());
+    }
+}
+
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_24/output");
+  deallog << std::setprecision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  check<1> ();
+  check<2> ();
+  check<3> ();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_24/cmp/generic b/tests/base/symmetric_tensor_24/cmp/generic
new file mode 100644 (file)
index 0000000..78b208b
--- /dev/null
@@ -0,0 +1,12 @@
+JobId unknown Thu Sep 24 17:05:12 2009
+DEAL::0  --  [0,0]
+DEAL::0  --  [0,0]
+DEAL::1  --  [1,1]
+DEAL::2  --  [0,1]
+DEAL::0  --  [0,0]
+DEAL::1  --  [1,1]
+DEAL::2  --  [2,2]
+DEAL::3  --  [0,1]
+DEAL::4  --  [0,2]
+DEAL::5  --  [1,2]
+DEAL::OK

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.