mcmgmapper.hh

Go to the documentation of this file.
00001 // $Id: mcmgmapper.hh 4860 2009-02-16 17:47:31Z sander $
00002 
00003 #ifndef DUNE_MCMGMAPPER_HH
00004 #define DUNE_MCMGMAPPER_HH
00005 
00006 #include <iostream>
00007 #include <map>
00008 #include "mapper.hh"
00009 #include "referenceelements.hh"
00010 
00017 namespace Dune
00018 {
00052   template <typename G, typename IS, template<int> class Layout>
00053   class MultipleCodimMultipleGeomTypeMapper : Mapper<G,MultipleCodimMultipleGeomTypeMapper<G,IS,Layout> > {
00054   public:
00055 
00062         MultipleCodimMultipleGeomTypeMapper (const G& grid, const IS& indexset)
00063           : g(grid), is(indexset)
00064         {
00065           update();
00066         }
00067 
00073         template<class EntityType>
00074         int map (const EntityType& e) const
00075         {
00076           return is.index(e) + offset.find(e.type())->second;
00077         }
00078 
00079   
00086         template<int cc>
00087         int map (const typename G::Traits::template Codim<0>::Entity& e, int i) const
00088         {
00089           GeometryType gt=ReferenceElements<double,G::dimension>::general(e.type()).type(i,cc);
00090           //      std::cout << "map: cc=" << cc << " gt=" << gt << " offset=" << offset.find(gt)->second << std::endl;
00091           return is.template subIndex<cc>(e,i) + offset.find(gt)->second;
00092         }
00093 
00102         int size () const
00103         {
00104           return n;
00105         }
00106  
00113         template<class EntityType>
00114         bool contains (const EntityType& e, int& result) const
00115         {
00116           if(!is.contains(e) || !layout.contains(e.type()))
00117       {
00118           result = 0;
00119           return false;
00120       }
00121           result = map(e);
00122           return true;
00123         }
00124 
00132         template<int cc> // this is now the subentity's codim
00133         bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i, int& result) const
00134         {
00135           result = this->template map<cc>(e,i);
00136           return true;
00137         }
00138  
00139   
00142         void update ()
00143         {
00144           n=0; // zero data elements
00145           for (int c=0; c<=G::dimension; c++)
00146                 offset.clear(); // clear all maps
00147         
00148           // Compute offsets for the different geometry types.
00149           // Note that mapper becomes invalid when the grid is modified.
00150           for (int c=0; c<=G::dimension; c++)
00151                 for (size_t i=0; i<is.geomTypes(c).size(); i++)
00152                   if (layout.contains(is.geomTypes(c)[i]))
00153                         {
00154                           //                      std::cout << "offset " << c << " " << is.geomTypes(c)[i] << " is " << n << std::endl;
00155               offset[is.geomTypes(c)[i]] = n;
00156               n += is.size(is.geomTypes(c)[i]);
00157                         }
00158         }
00159  
00160   private:
00161         int n; // number of data elements required
00162         const G& g;
00163         const IS& is;
00164         std::map<GeometryType,int> offset; // provide a map with all geometry types
00165         static Layout<G::dimension> layout; // get layout object
00166   };
00167 
00168   // C++ requires definition of static data members outside the class
00169   template <typename G, typename IS, template<int> class Layout>
00170   Layout<G::dimension> MultipleCodimMultipleGeomTypeMapper<G, IS, Layout>::layout;
00171 
00193   template <typename G, template<int> class Layout>
00194   class LeafMultipleCodimMultipleGeomTypeMapper 
00195         : public MultipleCodimMultipleGeomTypeMapper<G,typename G::Traits::LeafIndexSet,Layout> 
00196   {
00197   public:
00201         LeafMultipleCodimMultipleGeomTypeMapper (const G& grid) 
00202           : MultipleCodimMultipleGeomTypeMapper<G,typename G::Traits::LeafIndexSet,Layout>(grid,grid.leafIndexSet())
00203         {}
00204   };
00205 
00228   template <typename G, template<int> class Layout>
00229   class LevelMultipleCodimMultipleGeomTypeMapper 
00230         : public MultipleCodimMultipleGeomTypeMapper<G,typename G::Traits::LevelIndexSet,Layout> {
00231   public:
00236         LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level) 
00237           : MultipleCodimMultipleGeomTypeMapper<G,typename G::Traits::LevelIndexSet,Layout>(grid,grid.levelIndexSet(level))
00238         {}
00239   };
00240 
00242 }
00243 #endif

Generated on Thu Apr 2 10:40:43 2009 for dune-grid by  doxygen 1.5.6