13#ifndef PARTIALINDEXSET_HH
14#define PARTIALINDEXSET_HH
19#include <boost/mpl/range_c.hpp>
21#include <boost/fusion/algorithm.hpp>
23#include "dune/grid/common/indexidset.hh"
24#include "dune/grid/common/referenceelements.hh"
33template<
class Gr
id,
class IndexSet,
class Part>
42 template <Dune::PartitionIteratorType pitype>
52 Iterator(Iter
const& cur_, Iter
const& end_, Part
const& part_):
53 cur(cur_), end(end_), part(part_) {
79 while (cur!=end && !part.contains(*cur))
89 PartialIndexSet(GridSignals& signals, IndexSet
const& indexSet_, Part
const& part_):
90 indexSet(indexSet_), part(part_)
92 typedef typename IndexSet::template
Codim<0>::
93 template Partition<Dune::All_Partition>::Iterator CellIterator;
94 CellIterator
end = indexSet.template end<0,Dune::All_Partition>();
95 for (CellIterator ci=indexSet.template begin<0,Dune::All_Partition>(); ci!=
end; ++ci)
96 if (part.contains(*ci)) {
97 insert(ci->type(),indexSet.index(*ci));
98 boost::fusion::for_each(boost::mpl::range_c<int,1,Grid::dimension+1>(),
107 typename Map::const_iterator i = idx.find(e.type());
108 if (i==idx.end())
return -1;
109 else return i->second.first[indexSet.index(e)];
112 template<
class EntityType>
113 int index (
const EntityType& e)
const
115 return index<EntityType::codimension>(e);
124 Dune::GeometryType subentityType =
125 Dune::ReferenceElements<typename Grid::ctype,Grid::dimension>::general(e.type()).type(i,cc);
126 typename Map::const_iterator it = idx.find(subentityType);
127 if (it==idx.end())
return -1;
128 else return it->second.first[indexSet.template subIndex<cc>(e,i)];
131 const std::vector<Dune::GeometryType>&
geomTypes (
int codim)
const
133 return indexSet.geomTypes(codim);
136 int size (Dune::GeometryType type)
const
138 typename Map::const_iterator i= idx.find(type);
139 if (i==idx.end())
return 0;
140 else return i->second.second;
146 for (
typename Map::const_iterator i=idx.begin(); i!=idx.end(); ++i)
147 if (i->first.dim() == Grid::dimension-codim)
148 count += i->second.second;
152 template<
class EntityType>
155 return indexSet.contains(e) &&
index(e)>=0;
158 template<
int cd, Dune::PartitionIteratorType pitype>
161 return typename Codim<cd>::template Partition<pitype>::Iterator(indexSet.template begin<cd,pitype>(),
162 indexSet.template end<cd,pitype>(),
166 template<
int cd, Dune::PartitionIteratorType pitype>
169 return typename Codim<cd>::template Partition<pitype>::Iterator(indexSet.template end<cd,pitype>(),
170 indexSet.template end<cd,pitype>(),
175 IndexSet
const& indexSet;
183 typedef std::map<Dune::GeometryType,std::pair<std::vector<int>,
int> > Map;
186 void insert(Dune::GeometryType gt,
int index)
188 std::pair<std::vector<int>,
int>& gtIdx = idx[gt];
190 if (gtIdx.first.empty()) {
191 gtIdx.first.resize(indexSet.size(gt),-1);
195 if (gtIdx.first[
index]<0)
196 gtIdx.first[
index] = gtIdx.second++;
203 Update(Self& pis_, Cell
const& cell_): pis(pis_), cell(cell_) {}
205 template <
class Integer>
206 void operator()(Integer
const )
const
208 int const codim = Integer::value;
209 int const count = cell.template count<codim>();
212 for (
int i=0; i<
count; ++i)
213 pis.insert(Dune::ReferenceElements<typename Grid::ctype,Grid::dimension>::general(cell.type()).type(i,codim),
214 pis.indexSet.template subIndex<codim>(cell,i));
Entity * operator->() const
bool operator!=(Iterator const &i) const
bool operator==(Iterator const &i) const
Entity & operator*() const
Iterator(Iter const &cur_, Iter const &end_, Part const &part_)
Grid::template Codim< 0 >::Entity Entity
bool contains(const EntityType &e) const
int subIndex(Cell const &e, int i) const
Codim< cd >::template Partition< pitype >::Iterator end() const
PartialIndexSet(GridSignals &signals, IndexSet const &indexSet_, Part const &part_)
Codim< cd >::template Partition< pitype >::Iterator begin() const
int size(Dune::GeometryType type) const
const std::vector< Dune::GeometryType > & geomTypes(int codim) const
int index(const EntityType &e) const
int index(typename Grid::Traits::template Codim< cc >::Entity const &e) const
int size(int codim) const
Tools for transfer of data between grids.
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.