]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Further tweaks by Denis Davydov and add a test.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Jul 2013 21:28:29 +0000 (21:28 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Jul 2013 21:28:29 +0000 (21:28 +0000)
git-svn-id: https://svn.dealii.org/trunk@29958 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/tensor.h
tests/base/tensor_25.cc [new file with mode: 0644]
tests/base/tensor_25/cmp/generic [new file with mode: 0644]

index bb1e0ee70449bff0f930524bf460fbef9694b0f1..052d81aaac03614e080c140b49e48b36487f9bbf 100644 (file)
@@ -420,11 +420,13 @@ inline
 Number 
 Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> & indices) const
 {
-    const unsigned int outer_ind = indices[rank_-1];
+    const unsigned int inner_ind = indices[0];
+    Assert (inner_ind<dim, ExcIndexRange(inner_ind, 0, dim));
+    
        TableIndices<rank_-1> indices1;
        for (unsigned int i = 0; i < rank_-1;i++)
-       indices1[i] = indices[i];
-       return (subtensor[outer_ind])[indices1];        
+       indices1[i] = indices[i+1];
+       return (subtensor[inner_ind])[indices1];        
 }
 
 template <int rank_, int dim, typename Number>
@@ -432,11 +434,13 @@ inline
 Number & 
 Tensor<rank_,dim,Number>::operator[] (const TableIndices<rank_> & indices)
 {
-    const unsigned int outer_ind = indices[rank_-1];
+    const unsigned int inner_ind = indices[0];
+    Assert (inner_ind<dim, ExcIndexRange(inner_ind, 0, dim));
+    
        TableIndices<rank_-1> indices1;
        for (unsigned int i = 0; i < rank_-1;i++)
-       indices1[i] = indices[i];
-       return (subtensor[outer_ind])[indices1];        
+       indices1[i] = indices[i+1];
+       return (subtensor[inner_ind])[indices1];                
 }
 
 template <int rank_, int dim, typename Number>
diff --git a/tests/base/tensor_25.cc b/tests/base/tensor_25.cc
new file mode 100644 (file)
index 0000000..82dea93
--- /dev/null
@@ -0,0 +1,64 @@
+//----------------------------  tensor_25.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2006, 2008, 2009, 2013 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.
+//
+//----------------------------  tensor_25.cc  ---------------------------
+
+// check Tensor<2,dim>::operator[] (TableIndices)
+
+#include "../tests.h"
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <fstream>
+#include <iomanip>
+
+
+template <int dim>
+void check ()
+{
+  typedef Tensor<3,dim> T;
+  T t;
+  for (unsigned int i=0; i<T::n_independent_components; ++i)
+    t[T::unrolled_to_component_indices (i)] = (i+1)*(i+2);
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+       {
+         Assert (TableIndices<3>(i,j,k)
+                 ==
+                 T::unrolled_to_component_indices (i*dim*dim+j*dim+k),
+                 ExcInternalError());
+         Assert (T::component_to_unrolled_index(TableIndices<3>(i,j,k))
+                 ==
+                 i*dim*dim+j*dim+k,
+                 ExcInternalError());
+         Assert (t[TableIndices<3>(i,j,k)] == t[i][j][k],
+                 ExcInternalError());
+       }
+  deallog << "OK" << std::endl;
+}
+
+
+int main ()
+{
+  std::ofstream logfile("tensor_25/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/tensor_25/cmp/generic b/tests/base/tensor_25/cmp/generic
new file mode 100644 (file)
index 0000000..5f42bb2
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::OK
+DEAL::OK
+DEAL::OK
+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.