Skip to content
Snippets Groups Projects
Commit edf6f173 authored by Peter Bastian's avatar Peter Bastian
Browse files

changed interface of mapper. Renamed submap to map and use overloading.

Added an overloaded contains method that allows to check if the mapper provides
an index for an entity. This is mainly for the id set based mappers.

[[Imported from SVN: r2988]]
parent ce7cf5ed
Branches
Tags
No related merge requests found
......@@ -70,7 +70,7 @@
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 functions Dune::Mapper::map delivers the index for a (sub-)entity
The function Dune::Mapper::size returns the size of the entity set, i.e. \f$|E^\prime|\f$
......@@ -116,7 +116,7 @@ namespace Dune
\param e Reference to codim cc entity. The codim is extracted from the entity.
\return An index in the range 0 ... Max number of entities in set - 1.
*/
template<class EntityType> // this is necessary for multiple codim mappers
template<class EntityType>
int map (const EntityType& e) const
{
return asImp().map(e);
......@@ -129,9 +129,9 @@ 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 map (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
return asImp().template submap<cc>(e,i);
return asImp().template map<cc>(e,i);
}
/** @brief Return total number of entities in the entity set managed by the mapper.
......@@ -147,6 +147,23 @@ namespace Dune
return asImp().size();
}
/** @brief Returns true if the entity is contained in the index set
*/
template<class EntityType>
bool contains (const EntityType& e) const
{
return asImp().contains(e);
}
/** @brief Returns true if the entity is contained in the index set
*/
template<int cc> // this is now the subentity's codim
bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
return asImp().template contains<cc>(e,i);
}
private:
//! Barton-Nackman trick
MapperImp& asImp () {return static_cast<MapperImp &> (*this);}
......
......@@ -38,8 +38,9 @@ namespace Dune
* A Dune grid type.
* \par IS
* LeafIndexSet or LevelIndexSet type of the given grid.
* \par c
* A valid codimension.
* \par Layout
* A class template with a method contains, that returns true for all codims and geometry
* types that are in the map.
*/
template <typename G, typename IS, template<int> class Layout>
class MultipleCodimMultipleGeomTypeMapper : Mapper<G,MultipleCodimMultipleGeomTypeMapper<G,IS,Layout> > {
......@@ -88,7 +89,7 @@ namespace Dune
int map (const EntityType& e) const
{
enum { cc = EntityType::codimension };
return is.index(e) + offset[cc][e.geometry().type()];
return is.index(e) + offset[cc].find(e.geometry().type())->second;
}
......@@ -99,11 +100,11 @@ namespace Dune
\return An index in the range 0 ... Max number of entities in set - 1.
*/
template<int cc>
int submap (const typename G::Traits::template Codim<0>::Entity& e, int i) const
int map (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
GeometryType gt=ReferenceElements<double,G::dimension>::general(e.geometry().type()).type(i,cc);
return is.template subIndex<cc>(e,i) + offset[cc][gt];
return is.template subIndex<cc>(e,i) + offset[cc].find(gt)->second;
}
/** @brief Return total number of entities in the entity set managed by the mapper.
......@@ -119,27 +120,44 @@ namespace Dune
return n;
}
/** @brief Returns true if the entity is contained in the index set
*/
template<class EntityType>
bool contains (const EntityType& e) const
{
return true;
}
/** @brief Returns true if the entity is contained in the index set
*/
template<int cc> // this is now the subentity's codim
bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
return true;
}
private:
int n; // number of data elements required
const G& g;
const IS& is;
mutable std::map<GeometryType,int> offset[G::dimension+1]; // for each codim provide a map with all geometry types
std::map<GeometryType,int> offset[G::dimension+1]; // for each codim provide a map with all geometry types
};
/** @brief Single codim and single geometry type mapper for leaf entities.
/** @brief Multiple codim and multiple geometry type mapper for leaf entities.
This mapper uses all leaf entities of a certain codimension as its entity set. It is
assumed (and checked) that the given grid contains only entities of a single geometry type.
This mapper uses all leaf entities of a certain codimension as its entity set.
Template parameters are:
\par G
A Dune grid type.
\par c
A valid codimension.
\par Layout
A class template with a method contains, that returns true for all codims and geometry
types that are in the map.
*/
template <typename G, template<int> class Layout>
class LeafMultipleCodimMultipleGeomTypeMapper
......@@ -154,20 +172,20 @@ namespace Dune
{}
};
/** @brief Single codim and single geometry type mapper for entities of one level.
/** @brief Multiple codim and multiple geometry type mapper for entities of one level.
This mapper uses all entities of a certain codimension on a given level as its entity set. It is
assumed (and checked) that the given grid contains only entities of a single geometry type.
This mapper uses all entities of a certain codimension on a given level as its entity set.
Template parameters are:
\par G
A Dune grid type.
\par c
A valid codimension.
\par Layout
A class template with a method contains, that returns true for all codims and geometry
types that are in the map.
*/
template <typename G, int c, template<int> class Layout>
template <typename G, template<int> class Layout>
class LevelMultipleCodimMultipleGeomTypeMapper
: public MultipleCodimMultipleGeomTypeMapper<G,typename G::Traits::LevelIndexSet,Layout> {
public:
......
......@@ -66,7 +66,7 @@ namespace Dune
\return An index in the range 0 ... Max number of entities in set - 1.
*/
template<int cc>
int submap (const typename G::Traits::template Codim<0>::Entity& e, int i) const;
int map (const typename G::Traits::template Codim<0>::Entity& e, int i) const;
/** @brief Return total number of entities in the entity set managed by the mapper.
......@@ -78,6 +78,17 @@ namespace Dune
*/
int size () const;
/** @brief Returns true if the entity is contained in the index set
*/
template<class EntityType>
bool contains (const EntityType& e) const;
/** @brief Returns true if the entity is contained in the index set
*/
template<int cc> // this is now the subentity's codim
bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i) const;
private:
const G& g;
const IS& is;
......@@ -105,7 +116,7 @@ namespace Dune
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
int SingleCodimSingleGeomTypeMapper<G,IS,c>::map (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
IsTrue< cc == c >::yes();
return is.template subIndex<cc>(e,i);
......@@ -117,6 +128,19 @@ namespace Dune
return is.size(c,is.geomTypes(c)[0]);
}
template <typename G, typename IS, int c>
template<class EntityType>
bool SingleCodimSingleGeomTypeMapper<G,IS,c>::contains (const EntityType& e) const
{
return true;
}
template <typename G, typename IS, int c>
template<int cc>
bool SingleCodimSingleGeomTypeMapper<G,IS,c>::contains (const typename G::Traits::template Codim<0>::Entity& e, int i) const
{
return true;
}
/**
* @addtogroup Mapper
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment