dune-pdelab  2.4.1
finiteelementmap.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_FINITELEMENTMAP_HH
5 #define DUNE_PDELAB_FINITELEMENTMAP_HH
6 
7 #include <dune/common/deprecated.hh>
9 
10 #include <dune/geometry/referenceelements.hh>
11 
12 namespace Dune {
13  namespace PDELab {
14 
17 
19  class FiniteElementMapError : public Exception {};
24 
26  template<class T>
28  {
30  typedef T FiniteElementType;
31 
33  typedef T FiniteElement;
34  };
35 
37  template<class T>
39 
41  template<class T, class Imp>
43  {
44  public:
46  typedef T Traits;
47 
54  template<class EntityType>
55  const typename Traits::FiniteElementType& find (const EntityType& e) const
56  {
57  return asImp().find(e);
58  }
59 
77  bool fixedSize() const
78  {
79  return asImp().fixedSize();
80  }
84  std::size_t size(GeometryType gt) const
85  {
86  return asImp().size();
87  }
95  std::size_t maxLocalSize() const
96  {
97  return asImp().maxLocalSize();
98  }
99 
100  private:
101  Imp& asImp () {return static_cast<Imp &> (*this);}
102  const Imp& asImp () const {return static_cast<const Imp &>(*this);}
103  };
104 
106  template<class Imp>
108  public LocalFiniteElementMapInterface<LocalFiniteElementMapTraits<Imp>,
109  SimpleLocalFiniteElementMap<Imp> >
110  {
111  public:
114 
117  {}
118 
120  SimpleLocalFiniteElementMap (const Imp& imp_) : imp(imp_)
121  {}
122 
124  template<class EntityType>
125  const typename Traits::FiniteElementType& find (const EntityType& e) const
126  {
127  return imp;
128  }
129 
130  private:
131  Imp imp; // create once
132  };
133 
154  template<typename GV, typename FE, typename Imp>
157  LocalFiniteElementMapTraits<FE>,
158  Imp
159  >
160  {
161  typedef typename GV::IndexSet IndexSet;
162  static const int dim = GV::dimension;
163 
164  public:
167 
170  : gv(gv_), orient(gv_.size(0))
171  {
172  typedef typename GV::Grid::ctype ct;
173  auto& refElem =
174  ReferenceElements<ct, dim>::general(FE().type());
175 
176  auto &idSet = gv.grid().globalIdSet();
177 
178  // create all variants
179  variant.resize(1 << refElem.size(dim-1));
180  for (unsigned int i=0; i<variant.size(); i++)
181  variant[i] = FE(i);
182 
183  // compute orientation for all elements
184  auto& indexSet = gv.indexSet();
185 
186  // loop once over the grid
187  for (const auto& element : elements(gv))
188  {
189  auto elemid = indexSet.index(element);
190  orient[elemid] = 0;
191 
192  std::vector<typename GV::Grid::GlobalIdSet::IdType> vid(refElem.size(dim));
193  for(unsigned int i = 0; i < vid.size(); ++i)
194  vid[i] = idSet.subId(element, i, dim);
195 
196  // loop over all edges of the element
197  for(int i = 0; i < refElem.size(dim-1); ++i) {
198  int v0 = refElem.subEntity(i, dim-1, 0, dim);
199  int v1 = refElem.subEntity(i, dim-1, 1, dim);
200  // if (edge orientation in refelement) != (edge orientation in indexset)
201  if((v0 > v1) != (vid[v0] > vid[v1]))
202  orient[elemid] |= 1 << i;
203  }
204  }
205  }
206 
208  template<class EntityType>
209  const typename Traits::FiniteElementType& find (const EntityType& e) const
210  {
211  return variant[orient[gv.indexSet().index(e)]];
212  }
213 
214  private:
215  GV gv;
216  std::vector<FE> variant;
217  std::vector<unsigned char> orient;
218  };
219 
222  template<typename GV, typename FE, typename Imp, std::size_t Variants>
225  LocalFiniteElementMapTraits<FE>,
226  Imp >
227  {
228  typedef FE FiniteElement;
229  typedef typename GV::IndexSet IndexSet;
230 
231  public:
234 
236  RTLocalFiniteElementMap(const GV& gv_)
237  : gv(gv_), is(gv_.indexSet()), orient(gv_.size(0))
238  {
239  // create all variants
240  for (std::size_t i = 0; i < Variants; i++)
241  {
242  variant[i] = FiniteElement(i);
243  }
244 
245  // compute orientation for all elements
246  // loop once over the grid
247  for(const auto& cell : elements(gv))
248  {
249  unsigned int myId = is.index(cell);
250  orient[myId] = 0;
251 
252  for (const auto& intersection : intersections(gv,cell))
253  {
254  if (intersection.neighbor()
255  && is.index(intersection.outside()) > myId)
256  {
257  orient[myId] |= 1 << intersection.indexInInside();
258  }
259  }
260  }
261  }
262 
264  template<class EntityType>
265  const typename Traits::FiniteElementType& find(const EntityType& e) const
266  {
267  return variant[orient[is.index(e)]];
268  }
269 
270  private:
271  GV gv;
272  std::array<FiniteElement,Variants> variant;
273  const IndexSet& is;
274  std::vector<unsigned char> orient;
275  };
276 
278 
279  } // namespace PDELab
280 } // namespace Dune
281 
282 #endif
EdgeS0LocalFiniteElementMap(const GV &gv_)
construct EdgeSLocalFiniteElementMap
Definition: finiteelementmap.hh:169
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:125
general FiniteElementMap exception
Definition: finiteelementmap.hh:19
bool fixedSize() const
a FiniteElementMap is fixedSize iif the size of the local functions space for each GeometryType is fi...
Definition: finiteelementmap.hh:77
SimpleLocalFiniteElementMap(const Imp &imp_)
Constructor where an instance of Imp can be provided.
Definition: finiteelementmap.hh:120
Base class for all PDELab exceptions.
Definition: exceptions.hh:17
static const int dim
Definition: adaptivity.hh:83
Definition: adaptivity.hh:27
collect types exported by a finite element map
Definition: finiteelementmap.hh:38
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:265
FiniteElementMap exception raised when trying to obtain a finite element for an unsupported GeometryT...
Definition: finiteelementmap.hh:23
simple implementation where all entities have the same finite element
Definition: finiteelementmap.hh:107
std::size_t size(GeometryType gt) const
if the FiniteElementMap is fixedSize, the size methods computes the number of DOFs for given Geometry...
Definition: finiteelementmap.hh:84
T Traits
Export traits.
Definition: finiteelementmap.hh:46
const Entity & e
Definition: localfunctionspace.hh:111
interface for a finite element map
Definition: finiteelementmap.hh:42
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:166
implementation for finite elements requiring oriented edges
Definition: finiteelementmap.hh:155
FiniteElementMap exception concerning the computation of the FiniteElementMap size.
Definition: finiteelementmap.hh:21
std::size_t maxLocalSize() const
compute an upper bound for the local number of DOFs.
Definition: finiteelementmap.hh:95
LocalFiniteElementMapTraits< Imp > Traits
export type of the signature
Definition: finiteelementmap.hh:113
collect types exported by a finite element map
Definition: finiteelementmap.hh:27
T FiniteElementType
Type of finite element from local functions.
Definition: finiteelementmap.hh:30
Definition: finiteelementmap.hh:223
PDELab-specific exceptions.
const Traits::FiniteElementType & find(const EntityType &e) const
Return local basis for the given entity.
Definition: finiteelementmap.hh:55
SimpleLocalFiniteElementMap()
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:116
T FiniteElement
Type of finite element from local functions.
Definition: finiteelementmap.hh:33
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:233
RTLocalFiniteElementMap(const GV &gv_)
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:236
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:209