From: bangerth Date: Mon, 8 Jul 2013 18:13:17 +0000 (+0000) Subject: Add accessor functions that take a whole set of indices all at once. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1edf94423d82f8e25c036e54c0ed8c7b0c676b88;p=dealii-svn.git Add accessor functions that take a whole set of indices all at once. git-svn-id: https://svn.dealii.org/trunk@29954 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 bb5a41193f..bb1e0ee704 100644 --- a/deal.II/include/deal.II/base/tensor.h +++ b/deal.II/include/deal.II/base/tensor.h @@ -143,6 +143,16 @@ public: */ const Tensor &operator [] (const unsigned int i) const; + /** + * Read access using TableIndices indices + */ + Number operator [](const TableIndices & indices) const; + + /** + * Read and write access using TableIndices indices + */ + Number &operator [](const TableIndices & indices); + /** * Assignment operator. */ @@ -405,7 +415,29 @@ Tensor::operator[] (const unsigned int i) const return subtensor[i]; } +template +inline +Number +Tensor::operator[] (const TableIndices & indices) const +{ + const unsigned int outer_ind = indices[rank_-1]; + TableIndices indices1; + for (unsigned int i = 0; i < rank_-1;i++) + indices1[i] = indices[i]; + return (subtensor[outer_ind])[indices1]; +} +template +inline +Number & +Tensor::operator[] (const TableIndices & indices) +{ + const unsigned int outer_ind = indices[rank_-1]; + TableIndices indices1; + for (unsigned int i = 0; i < rank_-1;i++) + indices1[i] = indices[i]; + return (subtensor[outer_ind])[indices1]; +} template inline diff --git a/deal.II/include/deal.II/base/tensor_base.h b/deal.II/include/deal.II/base/tensor_base.h index 6a56daa4dd..fe44dc18b0 100644 --- a/deal.II/include/deal.II/base/tensor_base.h +++ b/deal.II/include/deal.II/base/tensor_base.h @@ -434,6 +434,16 @@ public: * backcompatibility. */ Number &operator [] (const unsigned int index); + + /** + * Read access using TableIndices indices + */ + Number operator [](const TableIndices<1> & indices) const; + + /** + * Read and write access using TableIndices indices + */ + 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 +inline +Number Tensor<1,dim,Number>::operator [] (const TableIndices<1> & indices) const +{ + Assert (indices[0] +inline +Number &Tensor<1,dim,Number>::operator [] (const TableIndices<1> & indices) +{ + Assert (indices[0]