From 9a23bc4b1a597b34abfd8bc8ee3c4b269d990033 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 9 Jul 2013 21:28:29 +0000 Subject: [PATCH] Further tweaks by Denis Davydov and add a test. git-svn-id: https://svn.dealii.org/trunk@29958 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/tensor.h | 16 ++++--- tests/base/tensor_25.cc | 64 +++++++++++++++++++++++++++ tests/base/tensor_25/cmp/generic | 5 +++ 3 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 tests/base/tensor_25.cc create mode 100644 tests/base/tensor_25/cmp/generic 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 -- 2.39.5