]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add accessor functions that take a whole set of indices all at once.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 8 Jul 2013 18:13:17 +0000 (18:13 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 8 Jul 2013 18:13:17 +0000 (18:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@29954 0785d39b-7218-0410-832d-ea1e28bc413d

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

index bb5a41193fa1b4407f1e30645f7edc1e67cdfe96..bb1e0ee70449bff0f930524bf460fbef9694b0f1 100644 (file)
@@ -143,6 +143,16 @@ public:
    */
   const Tensor<rank_-1,dim,Number> &operator [] (const unsigned int i) const;
 
+  /**
+   * Read access using TableIndices <tt>indices</tt>
+   */
+  Number operator [](const TableIndices<rank_> & indices) const; 
+  
+  /**
+   * Read and write access using TableIndices <tt>indices</tt>
+   */
+  Number &operator [](const TableIndices<rank_> & indices); 
+  
   /**
    *  Assignment operator.
    */
@@ -405,7 +415,29 @@ Tensor<rank_,dim,Number>::operator[] (const unsigned int i) const
   return subtensor[i];
 }
 
+template <int rank_, int dim, typename Number>
+inline
+Number 
+Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> & indices) const
+{
+    const unsigned int outer_ind = indices[rank_-1];
+       TableIndices<rank_-1> indices1;
+       for (unsigned int i = 0; i < rank_-1;i++)
+       indices1[i] = indices[i];
+       return (subtensor[outer_ind])[indices1];        
+}
 
+template <int rank_, int dim, typename Number>
+inline
+Number & 
+Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> & indices)
+{
+    const unsigned int outer_ind = indices[rank_-1];
+       TableIndices<rank_-1> indices1;
+       for (unsigned int i = 0; i < rank_-1;i++)
+       indices1[i] = indices[i];
+       return (subtensor[outer_ind])[indices1];        
+}
 
 template <int rank_, int dim, typename Number>
 inline
index 6a56daa4dd17986cbaf5c12397f7d671abf0ba8a..fe44dc18b0dec8e63b85e4ac434ed6f678c7753e 100644 (file)
@@ -434,6 +434,16 @@ public:
    * backcompatibility.
    */
   Number &operator [] (const unsigned int index);
+  
+  /**
+   * Read access using TableIndices <tt>indices</tt>
+   */
+  Number operator [](const TableIndices<1> & indices) const; 
+  
+  /**
+   * Read and write access using TableIndices <tt>indices</tt>
+   */
+  Number &operator [](const TableIndices<1> & indices); 
 
   /**
    * Assignment operator.
@@ -982,6 +992,22 @@ Number &Tensor<1,dim,Number>::operator [] (const unsigned int index)
   return values[index];
 }
 
+template <int dim, typename Number>
+inline
+Number Tensor<1,dim,Number>::operator [] (const TableIndices<1> & indices) const
+{
+  Assert (indices[0]<dim, ExcIndexRange (indices[0], 0, dim));
+  return values[indices[0]];
+}
+
+template <int dim, typename Number>
+inline
+Number &Tensor<1,dim,Number>::operator [] (const TableIndices<1> & indices) 
+{
+  Assert (indices[0]<dim, ExcIndexRange (indices[0], 0, dim));
+  return values[indices[0]];
+}
+
 
 
 template <>

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.