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

The first mapper based on the new index sets

[[Imported from SVN: r2795]]
parent 6a1f88cb
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,9 @@
#define __DUNE_MAPPER2_HH__
#include <iostream>
#include <dune/common/exceptions.hh>
#include "dune/common/helpertemplates.hh"
/**
* @file
* @brief Mapper classes are used to attach data to a grid
......@@ -32,7 +34,106 @@ namespace Dune
*
*/
/** @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 Construct mapper from grid and one fo its index sets.
\param grid A Dune grid object.
\param indexset IndexSet object returned by grid.
*/
SingleCodimSingleGeomTypeMapper (const G& grid, const IS& indexset);
/** @brief Map entity to array index.
\param e Reference to codim cc entity, where cc is the template parameter of the function.
\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;
/** @brief Map subentity of codim 0 entity to array index.
\param e Reference to codim 0 entity.
\param i Number of codim cc subentity of e, where cc is the template parameter of the function.
\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;
/** @brief Return total number of entities in the entity set managed by the mapper.
This number can be used to allocate a vector of data elements associated with the
entities of the set. In the parallel case this number is per process (i.e. it
may be different in different processes).
\return Size of the entity set.
*/
int size () const;
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())
{}
};
/** @} */
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment