From 72f74879a1471ff01ddb7508cc35620b65191031 Mon Sep 17 00:00:00 2001
From: Peter Bastian <peter@dune-project.org>
Date: Thu, 8 Sep 2005 15:25:25 +0000
Subject: [PATCH] contains now only base class wit documentation

[[Imported from SVN: r2806]]
---
 grid/common/mapper.hh | 190 +++++++++++++++++++++++-------------------
 1 file changed, 105 insertions(+), 85 deletions(-)

diff --git a/grid/common/mapper.hh b/grid/common/mapper.hh
index 2c5e00caf..beebfa280 100644
--- a/grid/common/mapper.hh
+++ b/grid/common/mapper.hh
@@ -9,59 +9,107 @@
 #include <dune/common/exceptions.hh>
 #include "dune/common/helpertemplates.hh"
 
-/**
- * @file
- * @brief  Mapper classes are used to attach data to a grid
+/** @file
  * @author Peter Bastian
+ * @brief Provides classes with basic mappers which are used to attch data to a grid
+ *
  */
+
+/*! @defgroup Mapper Mapper
+   \ingroup Grid
+
+
+   @section Mapper1 What is a Mapper ?
+   <!--============================-->
+
+   A mapper class is used to attach user-defined data to a subset of the grid entities
+   \f$E^\prime\subseteq E\f$.
+
+   It is assumed that the data \f$D(E^\prime)\f$ associated with
+   \f$E^\prime\f$ is stored in an array. The array can be viewed as a map
+   \f[ a : I_{E^\prime} \to D(E^\prime) \f] from the consecutive, zero-starting index set
+   \f$ I_{E^\prime} = \{0, \ldots, |E^\prime|-1\}\f$ of \f$E^\prime\f$ to the data set.
+
+   The mapper class provides a mapping \f[ m : E^\prime \to I_{E^\prime} \f] from the entity
+   set to the index set.
+
+   Access from a grid entity \f$e\in E^\prime\f$ to its associated data element \f$d_e\f$ then is
+   two step process: \f[ a(m(e)) = d_e. \f]
+
+   @section Mapper2 Different Kinds of Mappers
+   <!--====================================-->
+
+   There are different kinds of mappers depending on functionality and efficiency of
+   their implementation. The user selects an appropriate mapper depending on her/his needs.
+   All mappers conform to the same interface.
+
+   @subsection para1 Index based Mappers
+
+   An index-based mapper is allocated for a grid and can be used as as the grid is not changed
+   (i.e. refined, coarsened or load balanced). The implementation of static mappers
+   is based on index sets and is typically of \f$O(1)\f$ complexity with a very
+   small constant. Index-based mappers are only available for special kinds (but usually sufficient)
+   entity sets.
+
+   @subsection para2 Id based Mappers
+
+   An id-based mapper can also be used after the grid has been changed. For that it
+   has to be implemented on the basis of id sets. This may be relatively slow
+   because the data type used for ids is usually not an int and the non-consecutive
+   ids require more complicated search data structures (typically a map). Access is therefore
+   at least \f$O(\log |E^\prime|)\f$. On the other hand, id-based mappers can treat arbitrary
+   entity sets \f$E^\prime\f$.
+
+   @section Mapper3 Mapper Interface
+   <!--==========================-->
+
+   This interface is implemented by the class template Dune::Mapper. For a full documentation see the
+   description of this class.
+
+   The function Dune::Mapper::map delivers the index for an entity. Note that that for
+   performance reasons it is usually not checked whether the entity is really in the
+   entity set.
+
+   The function Dune::Mapper::submap delivers the index for a subentity of a codim 0 entity.
+
+   The function Dune::Mapper::size returns the size of the entity set, i.e. \f$|E^\prime|\f$
+
+   The different implementations of the mapper interface are listed below.
+
+   @section Mapper4 Overview of Different Mapper Implementations
+   <!--======================================================-->
+
+   @section Mapper5 Mappers and Mesh Changes
+   <!--==================================-->
+
+
+ */
+
+
 namespace Dune
 {
   /**
-   * @defgroup GridMapper Mapper
-   * @ingroup Grid
-   * @brief Mapper classes are used to attach data to a grid
-   *
-   */
-  /**
-   * @addtogroup GridMapper
+   * @addtogroup Mapper
    *
    * @{
    */
 
-  /** @file
-   * @author Peter Bastian
-   * @brief Provides classes with basic mappers which are used to attch data to a grid
-   *
-   */
 
-  /** @brief A mapper.
-   *
-   * In this implementation of a mapper the entity set used as domain for the map consists
-   * of the entities of a given codimension c for all entities in the given index set. The index
-   * set may only contain entities of a single geometry type, otherwise an exception is thrown. This
-   * version is usually not used directly but is used to implement versions for leafwise and levelwise
-   * entity sets.
-   *
-   * Template parameters are:
-   *
-   * \par G
-   *    A Dune grid type.
-   * \par IS
-   *    LeafIndexSet or LevelIndexSet type of the given grid.
-   * \par c
-   *    A valid codimension.
-   */
-  template <typename G, typename IS, int c>
-  class SingleCodimSingleGeomTypeMapper {
-  public:
+  /** @brief Mapper interface.
 
-    /** @brief Construct mapper from grid and one fo its index sets.
+     This class template is used as a base class for all mapper implementations.
+     It uses the Barton-Nackman trick to ensure conformity to the interface.
 
-       \param grid A Dune grid object.
-       \param indexset IndexSet object returned by grid.
+     Template parameters are:
 
-     */
-    SingleCodimSingleGeomTypeMapper (const G& grid, const IS& indexset);
+     \par G
+     A Dune grid type.
+     \par MapperImp
+     An implementation of the mapper interface.
+   */
+  template <typename G, typename MapperImp>
+  class Mapper {
+  public:
 
     /** @brief Map entity to array index.
 
@@ -69,7 +117,10 @@ namespace Dune
             \return An index in the range 0 ... Max number of entities in set - 1.
      */
     template<int cc>     // this is necessary for multiple codim mappers
-    int map (const typename G::Traits::template Codim<cc>::Entity& e) const;
+    int map (const typename G::Traits::template Codim<cc>::Entity& e) const
+    {
+      return asImp().template map<cc>(e);
+    }
 
     /** @brief Map subentity of codim 0 entity to array index.
 
@@ -78,7 +129,10 @@ namespace Dune
        \return An index in the range 0 ... Max number of entities in set - 1.
      */
     template<int cc>     // this is now the subentity's codim
-    int submap (const typename G::Traits::template Codim<0>::Entity& e, int i) const;
+    int submap (const typename G::Traits::template Codim<0>::Entity& e, int i) const
+    {
+      return asImp().template submap<cc>(e,i);
+    }
 
     /** @brief Return total number of entities in the entity set managed by the mapper.
 
@@ -88,53 +142,19 @@ namespace Dune
 
        \return Size of the entity set.
      */
-    int size () const;
+    int size () const
+    {
+      return asImp().size();
+    }
 
   private:
-    const G& g;
-    const IS& is;
-  };
-
-
-  template <typename G, typename IS, int c>
-  SingleCodimSingleGeomTypeMapper<G,IS,c>::SingleCodimSingleGeomTypeMapper (const G& grid, const IS& indexset)
-    : g(grid), is(indexset)
-  {
-    // check that grid has only a single geometry type
-    if (is.geomtypes().size() != 1)
-      DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type");
-  }
-
-  template <typename G, typename IS, int c>
-  template<int cc>
-  int SingleCodimSingleGeomTypeMapper<G,IS,c>::map (const typename G::Traits::template Codim<cc>::Entity& e) const
-  {
-    IsTrue< cc == c >::yes();
-    return is.template index<cc>(e);
-  }
-
-  template <typename G, typename IS, int c>
-  template<int cc>
-  int SingleCodimSingleGeomTypeMapper<G,IS,c>::submap (const typename G::Traits::template Codim<0>::Entity& e, int i) const
-  {
-    IsTrue< cc == c >::yes();
-    return is.template subindex<cc>(e,i);
-  }
-
-  template <typename G, typename IS, int c>
-  int SingleCodimSingleGeomTypeMapper<G,IS,c>::size () const
-  {
-    return is.size(c,is.geomtypes()[0]);
-  }
-
-
-  template <typename G, int c>
-  class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<G,typename G::LeafIndexSet,c> {
-  public:
-    LeafSingleCodimSingleGeomTypeMapper (const G& grid) : SingleCodimSingleGeomTypeMapper<G,typename G::LeafIndexSet,c>(grid,grid.leafindexset())
-    {}
+    //!  Barton-Nackman trick
+    MapperImp& asImp () {return static_cast<MapperImp &> (*this);}
+    //!  Barton-Nackman trick
+    const MapperImp& asImp () const {return static_cast<const MapperImp &>(*this);}
   };
 
   /** @} */
+
 }
 #endif
-- 
GitLab