From: Wolfgang Bangerth Date: Tue, 9 Jul 2013 21:28:29 +0000 (+0000) Subject: Further tweaks by Denis Davydov and add a test. X-Git-Tag: v8.0.0~162 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90eba6509a5ddf40fa0cd0c417e5c5bbcda2e1a3;p=dealii.git Further tweaks by Denis Davydov and add a test. git-svn-id: https://svn.dealii.org/trunk@29958 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/tensor.h b/deal.II/include/deal.II/base/tensor.h index bb1e0ee704..052d81aaac 100644 --- a/deal.II/include/deal.II/base/tensor.h +++ b/deal.II/include/deal.II/base/tensor.h @@ -420,11 +420,13 @@ inline Number Tensor::operator[] (const TableIndices & indices) const { - const unsigned int outer_ind = indices[rank_-1]; + const unsigned int inner_ind = indices[0]; + Assert (inner_ind 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 @@ -432,11 +434,13 @@ inline Number & Tensor::operator[] (const TableIndices & indices) { - const unsigned int outer_ind = indices[rank_-1]; + const unsigned int inner_ind = indices[0]; + Assert (inner_ind 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 diff --git a/tests/base/tensor_25.cc b/tests/base/tensor_25.cc new file mode 100644 index 0000000000..82dea93c51 --- /dev/null +++ b/tests/base/tensor_25.cc @@ -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 +#include +#include +#include +#include + + +template +void check () +{ + typedef Tensor<3,dim> T; + T t; + for (unsigned int i=0; i(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 index 0000000000..5f42bb230f --- /dev/null +++ b/tests/base/tensor_25/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::OK +DEAL::OK +DEAL::OK +DEAL::OK