]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Patch by Denis Davydov: Provide functions to unroll and re-roll indices of Tensor...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 2 Jul 2013 19:10:38 +0000 (19:10 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 2 Jul 2013 19:10:38 +0000 (19:10 +0000)
git-svn-id: https://svn.dealii.org/trunk@29917 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/tensor.h
deal.II/include/deal.II/base/tensor_base.h

index a7526a6ac39a1f2f861a934a6c30857cb0f48fe9..1049ce5462006d1f5d5c46fe614b73532d694973 100644 (file)
@@ -147,6 +147,13 @@ this function.
 
 <ol>
 
+<li> New: There are now functions Tensor::component_to_unrolled_index()
+and Tensor::unrolled_to_component_indices() in the same way as they
+already exist for the SymmetricTensor class.
+<br>
+(Denis Davydov, 2013/07/02)
+</li>
+
 <li> New: There is now a read-write version of TableIndices::operator[].
 <br>
 (Denis Davydov, 2013/07/02)
index c151cb197fca3174647e9bff510e2873fb3b44a8..dc5dd68407e6deba77193b14ad412d23491f2718 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -71,6 +71,14 @@ public:
    */
   static const unsigned int rank      = rank_;
 
+  /**
+   * Number of independent components of a
+   * tensor of current rank. This is dim times the
+   * number of independent components of each sub-tensor.
+   */
+  static const unsigned int
+  n_independent_components = Tensor<rank_-1,dim>::n_independent_components * dim;
+
   /**
    * Type of stored objects. This
    * is a tensor of lower rank.
@@ -242,6 +250,24 @@ public:
   template <typename Number2>
   void unroll (Vector<Number2> &result) const;
 
+  /**
+   * Returns an unrolled index in
+   * the range [0,dim^rank-1] for the element of the tensor indexed by
+   * the argument to the function.
+   */
+  static
+  unsigned int
+  component_to_unrolled_index(const TableIndices<rank_> &indices);
+
+  /**
+   * Opposite of  component_to_unrolled_index: For an index in the
+   * range [0,dim^rank-1], return which set of indices it would
+   * correspond to.
+   */
+  static
+  TableIndices<rank_> unrolled_to_component_indices(const unsigned int i);
+
+
 
   /**
    * Reset all values to zero.
@@ -574,6 +600,40 @@ Tensor<rank_, dim, Number>::unroll_recursion (Vector<Number2> &result,
     }
 }
 
+template <int rank_, int dim, typename Number>
+inline
+unsigned int
+Tensor<rank_, dim, Number>::component_to_unrolled_index(const TableIndices<rank_> &indices)
+{
+   TableIndices<rank_-1> indices1;
+   for (unsigned int i = 0; i < rank_-1;i++)
+        indices1[i] = indices[i];
+
+   Assert (indices[rank_-1] < dim,
+          ExcIndexRange (indices[rank_-1], 0, dim));
+   return ( Tensor<rank_-1,dim,Number>::component_to_unrolled_index(indices1) * dim + indices[rank_-1]);
+
+}
+
+template <int rank_, int dim, typename Number>
+inline
+TableIndices<rank_>
+Tensor<rank_, dim, Number>::unrolled_to_component_indices(const unsigned int i)
+{
+  TableIndices<rank_-1> indices1;
+  TableIndices<rank_>   indices;
+
+  indices[rank_-1] = (i % dim);
+  const unsigned int i1 = i / dim;
+
+  indices1 = Tensor<rank_-1,dim,Number>::unrolled_to_component_indices(i1);
+
+  for (unsigned int i = 0; i < rank-1;i++)
+    indices[i] = indices1[i];
+
+  return indices;
+}
+
 
 
 template <int rank_, int dim, typename Number>
index 6574ddc6f2fc0a932b7b04e5abe408b047ac657b..6a56daa4dd17986cbaf5c12397f7d671abf0ba8a 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -21,6 +21,7 @@
 
 #include <deal.II/base/config.h>
 #include <deal.II/base/exceptions.h>
+#include <deal.II/base/table_indices.h>
 #include <vector>
 
 #include <cmath>
@@ -348,6 +349,13 @@ public:
    */
   static const unsigned int rank      = 1;
 
+  /**
+   * Number of independent components of a
+   * tensor of rank 1.
+   */
+  static const unsigned int
+  n_independent_components = dim;
+
   /**
    * Type of stored objects. This
    * is a Number for a rank 1 tensor.
@@ -568,6 +576,31 @@ public:
   template <typename Number2>
   void unroll (Vector<Number2> &result) const;
 
+  /**
+   * Returns an unrolled index in
+   * the range [0,dim-1] for the element of the tensor indexed by
+   * the argument to the function.
+   *
+   * Given that this is a rank-1 object, the returned value
+   * is simply the value of the only index stored by the argument.
+   */
+  static
+  unsigned int
+  component_to_unrolled_index(const TableIndices<1> &indices);
+
+  /**
+   * Opposite of  component_to_unrolled_index: For an index in the
+   * range [0,dim-1], return which set of indices it would
+   * correspond to.
+   *
+   * Given that this is a rank-1 object, the returned set of indices
+   * consists of only a single element with value equal to the argument
+   * to this function.
+   */
+  static
+  TableIndices<1> unrolled_to_component_indices(const unsigned int i);
+
+
   /**
    * Determine an estimate for
    * the memory consumption (in
@@ -1187,6 +1220,23 @@ Tensor<1,dim,Number>::unroll_recursion (Vector<Number2> &result,
 }
 
 
+template <int dim, typename Number>
+inline
+unsigned int
+Tensor<1, dim, Number>::component_to_unrolled_index (const TableIndices<1> &indices)
+{
+  return indices[0];
+}
+
+template <int dim, typename Number>
+inline
+TableIndices<1>
+Tensor<1, dim, Number>::unrolled_to_component_indices (const unsigned int i)
+{
+  return TableIndices<1>(i);
+}
+
+
 
 template <int dim, typename Number>
 inline

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.