dune-pdelab  2.5-dev
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_FINITEELEMENTMAP_FINITEELEMENTMAP_HH
5 #define DUNE_PDELAB_FINITEELEMENTMAP_FINITEELEMENTMAP_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&
56  find (const EntityType& e) const = delete;
57 
75  bool fixedSize() const = delete;
79  std::size_t size(GeometryType gt) const = delete;
84  bool hasDOFs(int codim) const = delete;
90  std::size_t maxLocalSize() const = delete;
91  };
92 
94  template<class Imp>
96  public LocalFiniteElementMapInterface<LocalFiniteElementMapTraits<Imp>,
97  SimpleLocalFiniteElementMap<Imp> >
98  {
99  public:
102 
105  {}
106 
108  SimpleLocalFiniteElementMap (const Imp& imp_) : imp(imp_)
109  {}
110 
112  template<class EntityType>
113  const typename Traits::FiniteElementType& find (const EntityType& e) const
114  {
115  return imp;
116  }
117 
118  private:
119  Imp imp; // create once
120  };
121 
142  template<typename GV, typename FE, typename Imp>
145  LocalFiniteElementMapTraits<FE>,
146  Imp
147  >
148  {
149  typedef typename GV::IndexSet IndexSet;
150  static const int dim = GV::dimension;
151 
152  public:
155 
158  : gv(gv_), orient(gv_.size(0))
159  {
160  using ct = typename GV::Grid::ctype;
161  auto& refElem =
162  ReferenceElements<ct, dim>::general(FE().type());
163 
164  auto &idSet = gv.grid().globalIdSet();
165 
166  // create all variants
167  variant.resize(1 << refElem.size(dim-1));
168  for (std::size_t i=0; i<variant.size(); i++)
169  variant[i] = FE(i);
170 
171  // compute orientation for all elements
172  auto& indexSet = gv.indexSet();
173 
174  // loop once over the grid
175  for (const auto& element : elements(gv))
176  {
177  auto elemid = indexSet.index(element);
178  orient[elemid] = 0;
179 
180  std::vector<typename GV::Grid::GlobalIdSet::IdType> vid(refElem.size(dim));
181  for(std::size_t i = 0; i < vid.size(); ++i)
182  vid[i] = idSet.subId(element, i, dim);
183 
184  // loop over all edges of the element
185  for(int i = 0; i < refElem.size(dim-1); ++i) {
186  auto v0 = refElem.subEntity(i, dim-1, 0, dim);
187  auto v1 = refElem.subEntity(i, dim-1, 1, dim);
188  // if (edge orientation in refelement) != (edge orientation in indexset)
189  if((v0 > v1) != (vid[v0] > vid[v1]))
190  orient[elemid] |= 1 << i;
191  }
192  }
193  }
194 
196  template<class EntityType>
197  const typename Traits::FiniteElementType& find (const EntityType& e) const
198  {
199  return variant[orient[gv.indexSet().index(e)]];
200  }
201 
202  private:
203  GV gv;
204  std::vector<FE> variant;
205  std::vector<unsigned char> orient;
206  };
207 
210  template<typename GV, typename FE, typename Imp, std::size_t Variants>
213  LocalFiniteElementMapTraits<FE>,
214  Imp >
215  {
216  typedef FE FiniteElement;
217  typedef typename GV::IndexSet IndexSet;
218 
219  public:
222 
224  RTLocalFiniteElementMap(const GV& gv_)
225  : gv(gv_), is(gv_.indexSet()), orient(gv_.size(0))
226  {
227  // create all variants
228  for (std::size_t i = 0; i < Variants; i++)
229  {
230  variant[i] = FiniteElement(i);
231  }
232 
233  // compute orientation for all elements
234  // loop once over the grid
235  for(const auto& cell : elements(gv))
236  {
237  auto myId = is.index(cell);
238  orient[myId] = 0;
239 
240  for (const auto& intersection : intersections(gv,cell))
241  {
242  if (intersection.neighbor()
243  && is.index(intersection.outside()) > myId)
244  {
245  orient[myId] |= 1 << intersection.indexInInside();
246  }
247  }
248  }
249  }
250 
252  template<class EntityType>
253  const typename Traits::FiniteElementType& find(const EntityType& e) const
254  {
255  return variant[orient[is.index(e)]];
256  }
257 
258  private:
259  GV gv;
260  std::array<FiniteElement,Variants> variant;
261  const IndexSet& is;
262  std::vector<unsigned char> orient;
263  };
264 
266 
267  } // namespace PDELab
268 } // namespace Dune
269 
270 #endif // DUNE_PDELAB_FINITEELEMENTMAP_FINITEELEMENTMAP_HH
static const int dim
Definition: adaptivity.hh:83
implementation for finite elements requiring oriented edges
Definition: finiteelementmap.hh:143
Base class for all PDELab exceptions.
Definition: exceptions.hh:17
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:221
SimpleLocalFiniteElementMap(const Imp &imp_)
Constructor where an instance of Imp can be provided.
Definition: finiteelementmap.hh:108
T Traits
Export traits.
Definition: finiteelementmap.hh:46
collect types exported by a finite element map
Definition: finiteelementmap.hh:38
FiniteElementMap exception concerning the computation of the FiniteElementMap size.
Definition: finiteelementmap.hh:21
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:253
SimpleLocalFiniteElementMap()
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:104
simple implementation where all entities have the same finite element
Definition: finiteelementmap.hh:95
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:113
collect types exported by a finite element map
Definition: finiteelementmap.hh:27
Definition: finiteelementmap.hh:211
PDELab-specific exceptions.
LocalFiniteElementMapTraits< Imp > Traits
export type of the signature
Definition: finiteelementmap.hh:101
RTLocalFiniteElementMap(const GV &gv_)
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:224
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:197
const Entity & e
Definition: localfunctionspace.hh:111
EdgeS0LocalFiniteElementMap(const GV &gv_)
construct EdgeSLocalFiniteElementMap
Definition: finiteelementmap.hh:157
T FiniteElement
Type of finite element from local functions.
Definition: finiteelementmap.hh:33
general FiniteElementMap exception
Definition: finiteelementmap.hh:19
T FiniteElementType
Type of finite element from local functions.
Definition: finiteelementmap.hh:30
interface for a finite element map
Definition: finiteelementmap.hh:42
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:154
FiniteElementMap exception raised when trying to obtain a finite element for an unsupported GeometryT...
Definition: finiteelementmap.hh:23