KASKADE 7 development version
partialindexset.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2011 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef PARTIALINDEXSET_HH
14#define PARTIALINDEXSET_HH
15
16#include <cassert>
17#include <vector>
18
19#include <boost/mpl/range_c.hpp>
20
21#include <boost/fusion/algorithm.hpp>
22
23#include "dune/grid/common/indexidset.hh"
24#include "dune/grid/common/referenceelements.hh"
25
26#include "fem/fetransfer.hh"
27
33template<class Grid, class IndexSet, class Part>
36 typedef typename Grid::Traits::template Codim<0>::Entity Cell;
37
38public:
39 template <int cd>
40 struct Codim
41 {
42 template <Dune::PartitionIteratorType pitype>
43 struct Partition
44 {
46 {
47 typedef typename IndexSet::template Codim<cd>::template Partition<pitype>::Iterator Iter;
48
49 public:
50 typedef typename Grid::template Codim<0>::Entity Entity;
51
52 Iterator(Iter const& cur_, Iter const& end_, Part const& part_):
53 cur(cur_), end(end_), part(part_) {
54 ahead();
55 }
56
58 {
59 if (cur!=end)
60 ++cur;
61 ahead();
62 return *this;
63 }
64
65 Entity& operator*() const { return *cur; }
66 Entity* operator->() const { return &*cur; }
67
68 bool operator==(Iterator const& i) const { return cur==i.cur; }
69 bool operator!=(Iterator const& i) const { return !(*this == i); }
70
71 operator typename Grid::Traits::template Codim<0>::EntityPointer() const
72 {
73 return cur;
74 }
75
76 private:
77 void ahead()
78 {
79 while (cur!=end && !part.contains(*cur))
80 ++cur;
81 }
82
83 Iter cur, end;
84 Part const& part;
85 };
86 };
87 };
88
89 PartialIndexSet(GridSignals& signals, IndexSet const& indexSet_, Part const& part_):
90 indexSet(indexSet_), part(part_)
91 {
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>(),
99 Update(*this,*ci));
100 }
101 }
102
103
104 template <int cc>
105 int index (typename Grid::Traits::template Codim<cc>::Entity const& e) const
106 {
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)];
110 }
111
112 template<class EntityType>
113 int index (const EntityType& e) const
114 {
115 return index<EntityType::codimension>(e);
116 }
117
118 template<int cc>
119 int subIndex (Cell const& e, int i) const
120 {
121 // unfortunately the following is not implemented in every grid interface...
122 // return index(*e.template entity<cc>(i));
123
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)];
129 }
130
131 const std::vector<Dune::GeometryType>& geomTypes (int codim) const
132 {
133 return indexSet.geomTypes(codim);
134 }
135
136 int size (Dune::GeometryType type) const
137 {
138 typename Map::const_iterator i= idx.find(type);
139 if (i==idx.end()) return 0;
140 else return i->second.second;
141 }
142
143 int size (int codim) const
144 {
145 int count = 0;
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;
149 return count;
150 }
151
152 template<class EntityType>
153 bool contains (const EntityType& e) const
154 {
155 return indexSet.contains(e) && index(e)>=0;
156 }
157
158 template<int cd, Dune::PartitionIteratorType pitype>
159 typename Codim<cd>::template Partition<pitype>::Iterator begin () const
160 {
161 return typename Codim<cd>::template Partition<pitype>::Iterator(indexSet.template begin<cd,pitype>(),
162 indexSet.template end<cd,pitype>(),
163 part);
164 }
165
166 template<int cd, Dune::PartitionIteratorType pitype>
167 typename Codim<cd>::template Partition<pitype>::Iterator end () const
168 {
169 return typename Codim<cd>::template Partition<pitype>::Iterator(indexSet.template end<cd,pitype>(),
170 indexSet.template end<cd,pitype>(),
171 part);
172 }
173
174private:
175 IndexSet const& indexSet;
176 Part const& part;
177
178 // For each geometry type, separate contiguous indices are
179 // maintained, which are stored according to the underlying index
180 // set. A negative value denotes entities which are not contained in
181 // the partial index set. The second part in the data type is a
182 // running counter used for generating contiguous indices.
183 typedef std::map<Dune::GeometryType,std::pair<std::vector<int>,int> > Map;
184 Map idx;
185
186 void insert(Dune::GeometryType gt, int index)
187 {
188 std::pair<std::vector<int>,int>& gtIdx = idx[gt];
189
190 if (gtIdx.first.empty()) {
191 gtIdx.first.resize(indexSet.size(gt),-1);
192 gtIdx.second = 0;
193 }
194
195 if (gtIdx.first[index]<0)
196 gtIdx.first[index] = gtIdx.second++;
197 }
198
199 // A MPL/fusion functor which inserts all the cell's subentities of
200 // given codimension into the index map.
201 struct Update
202 {
203 Update(Self& pis_, Cell const& cell_): pis(pis_), cell(cell_) {}
204
205 template <class Integer>
206 void operator()(Integer const /* codim */) const
207 {
208 int const codim = Integer::value;
209 int const count = cell.template count<codim>();
210
211
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));
215 }
216
217 private:
218 Self& pis;
219 Cell const& cell;
220 };
221};
222
223
224#endif
bool operator!=(Iterator const &i) const
bool operator==(Iterator const &i) 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.
Definition: fixdune.hh:716
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Definition: gridBasics.hh:35