From f1d7923f873a40f22f1a30d434d4d0493c24554f Mon Sep 17 00:00:00 2001 From: hartmann Date: Tue, 24 Sep 2002 09:36:11 +0000 Subject: [PATCH] Implement the TableIndices and Table classses for N=4,5 and 6. git-svn-id: https://svn.dealii.org/trunk@6497 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/table.h | 856 ++++++++++++++++++++++++++++-- deal.II/doc/news/2002/c-3-4.html | 12 + 2 files changed, 828 insertions(+), 40 deletions(-) diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index b2f88f1f40..b6bd7c7259 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -164,6 +164,105 @@ class TableIndices<3> : public TableIndicesBase<3> }; +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a four-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the @ref{TableIndicesBase} base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<4> : public TableIndicesBase<4> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4); +}; + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a five-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the @ref{TableIndicesBase} base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<5> : public TableIndicesBase<5> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5); +}; + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a four-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the @ref{TableIndicesBase} base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<6> : public TableIndicesBase<6> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6); +}; + + /** * Have a namespace in which we declare some classes that are used to * access the elements of tables using the @p{operator[]}. These are @@ -1053,63 +1152,340 @@ class Table<3,T> : public TableBase<3,T> - -/* --------------------- Template and inline functions ---------------- */ - - -template -inline -unsigned int -TableIndicesBase::operator [] (const unsigned int i) const +/** + * A class representing a four-dimensional table of objects (not + * necessarily only numbers). + * + * For the rationale of this class, and a description of the + * interface, see the base class. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template +class Table<4,T> : public TableBase<4,T> { - return indices[i]; -}; - - + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); -inline -TableIndices<1>::TableIndices () -{ - this->indices[0] = 0; -}; + /** + * Constructor. Pass down the + * given dimensions to the base + * class. + */ + Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4); + + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + TableBaseAccessors::Accessor<4,T,true,3> + operator [] (const unsigned int i) const; + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + TableBaseAccessors::Accessor<4,T,false,3> + operator [] (const unsigned int i); + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + const T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l) const; + -inline -TableIndices<1>::TableIndices (const unsigned int index1) -{ - this->indices[0] = index1; + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l); }; -inline -TableIndices<2>::TableIndices () +/** + * A class representing a five-dimensional table of objects (not + * necessarily only numbers). + * + * For the rationale of this class, and a description of the + * interface, see the base class. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template +class Table<5,T> : public TableBase<5,T> { - this->indices[0] = this->indices[1] = 0; -}; - + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); + /** + * Constructor. Pass down the + * given dimensions to the base + * class. + */ + Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4, + const unsigned int size5); -inline -TableIndices<2>::TableIndices (const unsigned int index1, - const unsigned int index2) -{ - this->indices[0] = index1; - this->indices[1] = index2; -}; + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + TableBaseAccessors::Accessor<5,T,true,4> + operator [] (const unsigned int i) const; + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + TableBaseAccessors::Accessor<5,T,false,4> + operator [] (const unsigned int i); + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + const T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m) const; + -inline -TableIndices<3>::TableIndices () -{ - this->indices[0] = this->indices[1] = this->indices[2] = 0; + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m); }; -inline +/** + * A class representing a six-dimensional table of objects (not + * necessarily only numbers). + * + * For the rationale of this class, and a description of the + * interface, see the base class. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template +class Table<6,T> : public TableBase<6,T> +{ + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); + + /** + * Constructor. Pass down the + * given dimensions to the base + * class. + */ + Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4, + const unsigned int size5, + const unsigned int size6); + + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + TableBaseAccessors::Accessor<6,T,true,5> + operator [] (const unsigned int i) const; + + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + TableBaseAccessors::Accessor<6,T,false,5> + operator [] (const unsigned int i); + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + const T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m, + const unsigned int n) const; + + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m, + const unsigned int n); +}; + + + + + +/* --------------------- Template and inline functions ---------------- */ + + +template +inline +unsigned int +TableIndicesBase::operator [] (const unsigned int i) const +{ + return indices[i]; +}; + + + +inline +TableIndices<1>::TableIndices () +{ + this->indices[0] = 0; +}; + + + +inline +TableIndices<1>::TableIndices (const unsigned int index1) +{ + this->indices[0] = index1; +}; + + + +inline +TableIndices<2>::TableIndices () +{ + this->indices[0] = this->indices[1] = 0; +}; + + + +inline +TableIndices<2>::TableIndices (const unsigned int index1, + const unsigned int index2) +{ + this->indices[0] = index1; + this->indices[1] = index2; +}; + + + +inline +TableIndices<3>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = 0; +}; + + + +inline TableIndices<3>::TableIndices (const unsigned int index1, const unsigned int index2, const unsigned int index3) @@ -1120,6 +1496,78 @@ TableIndices<3>::TableIndices (const unsigned int index1, }; +inline +TableIndices<4>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = 0; +}; + + + +inline +TableIndices<4>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; +}; + + + +inline +TableIndices<5>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = this->indices[4] = 0; +}; + + + +inline +TableIndices<5>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; + this->indices[4] = index5; +}; + + + +inline +TableIndices<6>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] + = this->indices[3] = this->indices[4] = 0; +}; + + + +inline +TableIndices<6>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; + this->indices[4] = index5; + this->indices[5] = index6; +}; + + template TableBase::TableBase () @@ -1738,7 +2186,8 @@ Table<3,T>::operator () (const unsigned int i, ExcIndexRange (j, 0, this->table_size[1])); Assert (k < this->table_size[2], ExcIndexRange (k, 0, this->table_size[2])); - return this->val[(i*this->table_size[1]+j)*this->table_size[2] + k]; + return this->val[(i*this->table_size[1]+j) + *this->table_size[2] + k]; }; @@ -1756,8 +2205,335 @@ Table<3,T>::operator () (const unsigned int i, ExcIndexRange (j, 0, this->table_size[1])); Assert (k < this->table_size[2], ExcIndexRange (k, 0, this->table_size[2])); - return this->val[(i*this->table_size[1]+j)*this->table_size[2] + k]; + return this->val[(i*this->table_size[1]+j) + *this->table_size[2] + k]; }; + +template +Table<4,T>::Table () +{}; + + + +template +Table<4,T>::Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4) + : + TableBase<4,T> (TableIndices<4> (size1, size2, size3, size4)) +{}; + + + +template +inline +TableBaseAccessors::Accessor<4,T,true,3> +Table<4,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3]; + return (TableBaseAccessors::Accessor<4,T,true,3> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +TableBaseAccessors::Accessor<4,T,false,3> +Table<4,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3]; + return (TableBaseAccessors::Accessor<4,T,false,3> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +const T & +Table<4,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + return this->val[((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l]; +}; + + + +template +inline +T & +Table<4,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + return this->val[((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l]; +}; + + + + +template +Table<5,T>::Table () +{}; + + + +template +Table<5,T>::Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4, + const unsigned int size5) + : + TableBase<5,T> (TableIndices<5> (size1, size2, size3, size4, size5)) +{}; + + + +template +inline +TableBaseAccessors::Accessor<5,T,true,4> +Table<5,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3] * + this->table_size[4]; + return (TableBaseAccessors::Accessor<5,T,true,4> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +TableBaseAccessors::Accessor<5,T,false,4> +Table<5,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3] * + this->table_size[4]; + return (TableBaseAccessors::Accessor<5,T,false,4> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +const T & +Table<5,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + Assert (m < this->table_size[4], + ExcIndexRange (m, 0, this->table_size[4])); + return this->val[(((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l) + *this->table_size[4] + m]; +}; + + + +template +inline +T & +Table<5,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + Assert (m < this->table_size[4], + ExcIndexRange (m, 0, this->table_size[4])); + return this->val[(((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l) + *this->table_size[4] + m]; +}; + + + +template +Table<6,T>::Table () +{}; + + + +template +Table<6,T>::Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3, + const unsigned int size4, + const unsigned int size5, + const unsigned int size6) + : + TableBase<6,T> (TableIndices<6> (size1, size2, size3, size4, size5, size6)) +{}; + + + +template +inline +TableBaseAccessors::Accessor<6,T,true,5> +Table<6,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5]; + return (TableBaseAccessors::Accessor<6,T,true,5> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +TableBaseAccessors::Accessor<6,T,false,5> +Table<6,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2] * + this->table_size[3] * + this->table_size[4] * + this->table_size[5]; + return (TableBaseAccessors::Accessor<6,T,false,5> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +const T & +Table<6,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m, + const unsigned int n) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + Assert (m < this->table_size[4], + ExcIndexRange (m, 0, this->table_size[4])); + Assert (n < this->table_size[5], + ExcIndexRange (n, 0, this->table_size[5])); + return this->val[((((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l) + *this->table_size[4] + m) + *this->table_size[5] + n]; +}; + + + +template +inline +T & +Table<6,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k, + const unsigned int l, + const unsigned int m, + const unsigned int n) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + Assert (l < this->table_size[3], + ExcIndexRange (l, 0, this->table_size[3])); + Assert (m < this->table_size[4], + ExcIndexRange (m, 0, this->table_size[4])); + Assert (n < this->table_size[5], + ExcIndexRange (n, 0, this->table_size[5])); + return this->val[((((i*this->table_size[1]+j) + *this->table_size[2] + k) + *this->table_size[3] + l) + *this->table_size[4] + m) + *this->table_size[5] + n]; +}; + + + #endif diff --git a/deal.II/doc/news/2002/c-3-4.html b/deal.II/doc/news/2002/c-3-4.html index b6b2595ab4..0ca6b512d0 100644 --- a/deal.II/doc/news/2002/c-3-4.html +++ b/deal.II/doc/news/2002/c-3-4.html @@ -143,6 +143,18 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

base

    +
  1. New: The classes TableIndices<N> and Table<N,T> are now implemented also + for N=4,5 and 6. The Table<N,T> class represents an + N-dimensional array and might replace the + N-times-nested-use of the std::vector class. +
    + (RH 2002/09/24) +

    +
  2. New: The Threads::n_existing_threads function returns the present number of existing threads, allowing an -- 2.39.5