From 490bb2b9b68a127f415b1a67bb7a15f2b85e8110 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 29 Mar 2005 15:38:14 +0000 Subject: [PATCH] Allow sorting of table indices. git-svn-id: https://svn.dealii.org/trunk@10286 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/table.h | 44 +++++++++++++++++++++++++++++++ deal.II/doc/news/changes.html | 9 +++++++ 2 files changed, 53 insertions(+) diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index 079f4e249a..f69558eee8 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -62,6 +62,14 @@ template class Table<6,T>; * inequality. */ bool operator != (const TableIndicesBase &other) const; + + /** + * Sort the indices in ascending + * order. While this operation is not + * very useful for Table objects, it is + * used for the SymmetricTensor class. + */ + void sort (); protected: /** @@ -1886,6 +1894,42 @@ TableIndicesBase::operator != (const TableIndicesBase &other) const +template <> +inline +void +TableIndicesBase<1>::sort () +{} + + + +template <> +inline +void +TableIndicesBase<2>::sort () +{ + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); +} + + + +template <> +inline +void +TableIndicesBase<3>::sort () +{ + // bubble sort for 3 elements + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); + if (indices[2] < indices[1]) + std::swap (indices[1], indices[2]); + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); +} + + + + inline TableIndices<1>::TableIndices () { diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index f7d9090af5..182038e7ff 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -151,6 +151,15 @@ inconvenience this causes.

base

    +
  1. + New: The new function TableIndicesBase::sort allows to sort the indices + in ascending order. This is useful for cases where the order of indices + is irrelevant (for example in symmetric tables). +
    + (WB, 2005/03/29) +

    +
  2. New: There is a new class SymmetricTensor that provides storage and operations for symmetric tensors. -- 2.39.5