//---------------------------------------------------------------------------
// $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
*/
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.
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.
}
}
+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>
//---------------------------------------------------------------------------
// $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
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
+#include <deal.II/base/table_indices.h>
#include <vector>
#include <cmath>
*/
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.
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
}
+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