dune-pdelab  2.7-git
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 
74  static constexpr int dimension = -1;
78  static constexpr bool fixedSize() = delete;
82  static constexpr std::size_t size(GeometryType gt) = delete;
87  static constexpr bool hasDOFs(int codim) = delete;
93  static constexpr std::size_t maxLocalSize() = delete;
94  };
95 
97  template<class Imp, int dim_>
99  public LocalFiniteElementMapInterface<LocalFiniteElementMapTraits<Imp>,
100  SimpleLocalFiniteElementMap<Imp,dim_> >
101  {
102  public:
105 
108  {}
109 
111  SimpleLocalFiniteElementMap (const Imp& imp_) : imp(imp_)
112  {}
113 
115  template<class EntityType>
116  const typename Traits::FiniteElementType& find (const EntityType& e) const
117  {
118  return imp;
119  }
120 
121  static constexpr int dimension = dim_;
122 
123  private:
124  Imp imp; // create once
125  };
126 
147  template<typename GV, typename FE, typename Imp>
150  LocalFiniteElementMapTraits<FE>,
151  Imp
152  >
153  {
154  typedef typename GV::IndexSet IndexSet;
155  static const int dim = GV::dimension;
156 
157  public:
160 
162  static constexpr int dimension = GV::dimension;
163 
166  : gv(gv_), orient(gv_.size(0))
167  {
168  using ct = typename GV::Grid::ctype;
169  auto& refElem =
170  ReferenceElements<ct, dim>::general(FE().type());
171 
172  auto &idSet = gv.grid().globalIdSet();
173 
174  // create all variants
175  variant.resize(1 << refElem.size(dim-1));
176  for (std::size_t i=0; i<variant.size(); i++)
177  variant[i] = FE(i);
178 
179  // compute orientation for all elements
180  auto& indexSet = gv.indexSet();
181 
182  // loop once over the grid
183  for (const auto& element : elements(gv))
184  {
185  auto elemid = indexSet.index(element);
186  orient[elemid] = 0;
187 
188  std::vector<typename GV::Grid::GlobalIdSet::IdType> vid(refElem.size(dim));
189  for(std::size_t i = 0; i < vid.size(); ++i)
190  vid[i] = idSet.subId(element, i, dim);
191 
192  // loop over all edges of the element
193  for(int i = 0; i < refElem.size(dim-1); ++i) {
194  auto v0 = refElem.subEntity(i, dim-1, 0, dim);
195  auto v1 = refElem.subEntity(i, dim-1, 1, dim);
196  // if (edge orientation in refelement) != (edge orientation in indexset)
197  if((v0 > v1) != (vid[v0] > vid[v1]))
198  orient[elemid] |= 1 << i;
199  }
200  }
201  }
202 
204  template<class EntityType>
205  const typename Traits::FiniteElementType& find (const EntityType& e) const
206  {
207  return variant[orient[gv.indexSet().index(e)]];
208  }
209 
210  private:
211  GV gv;
212  std::vector<FE> variant;
213  std::vector<unsigned char> orient;
214  };
215 
218  template<typename GV, typename FE, typename Imp, std::size_t Variants>
221  LocalFiniteElementMapTraits<FE>,
222  Imp >
223  {
224  typedef FE FiniteElement;
225  typedef typename GV::IndexSet IndexSet;
226 
227  public:
230 
232  static constexpr int dimension = GV::dimension;
233 
235  RTLocalFiniteElementMap(const GV& gv_)
236  : gv(gv_), is(gv_.indexSet()), orient(gv_.size(0))
237  {
238  // create all variants
239  for (std::size_t i = 0; i < Variants; i++)
240  {
241  variant[i] = FiniteElement(i);
242  }
243 
244  // compute orientation for all elements
245  // loop once over the grid
246  for(const auto& cell : elements(gv))
247  {
248  auto myId = is.index(cell);
249  orient[myId] = 0;
250 
251  for (const auto& intersection : intersections(gv,cell))
252  {
253  if (intersection.neighbor()
254  && is.index(intersection.outside()) > myId)
255  {
256  orient[myId] |= 1 << intersection.indexInInside();
257  }
258  }
259  }
260  }
261 
263  template<class EntityType>
264  const typename Traits::FiniteElementType& find(const EntityType& e) const
265  {
266  return variant[orient[is.index(e)]];
267  }
268 
269  private:
270  GV gv;
271  std::array<FiniteElement,Variants> variant;
272  const IndexSet& is;
273  std::vector<unsigned char> orient;
274  };
275 
277 
278  } // namespace PDELab
279 } // namespace Dune
280 
281 #endif // DUNE_PDELAB_FINITEELEMENTMAP_FINITEELEMENTMAP_HH
PDELab-specific exceptions.
const Entity & e
Definition: localfunctionspace.hh:121
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Base class for all PDELab exceptions.
Definition: exceptions.hh:19
general FiniteElementMap exception
Definition: finiteelementmap.hh:19
FiniteElementMap exception concerning the computation of the FiniteElementMap size.
Definition: finiteelementmap.hh:21
FiniteElementMap exception raised when trying to obtain a finite element for an unsupported GeometryT...
Definition: finiteelementmap.hh:23
collect types exported by a finite element map
Definition: finiteelementmap.hh:28
T FiniteElement
Type of finite element from local functions.
Definition: finiteelementmap.hh:33
T FiniteElementType
Type of finite element from local functions.
Definition: finiteelementmap.hh:30
collect types exported by a finite element map
Definition: finiteelementmap.hh:38
interface for a finite element map
Definition: finiteelementmap.hh:43
static constexpr bool hasDOFs(int codim)=delete
return if FiniteElementMap has degrees of freedom for given codimension
static constexpr bool fixedSize()=delete
a FiniteElementMap is fixedSize iif the size of the local functions space for each GeometryType is fi...
static constexpr std::size_t maxLocalSize()=delete
compute an upper bound for the local number of DOFs.
T Traits
Export traits.
Definition: finiteelementmap.hh:46
static constexpr int dimension
dimension of the domain this FEM is defined on.
Definition: finiteelementmap.hh:74
static constexpr std::size_t size(GeometryType gt)=delete
if the FiniteElementMap is fixedSize, the size methods computes the number of DOFs for given Geometry...
const Traits::FiniteElementType & find(const EntityType &e) const =delete
Return local basis for the given entity.
simple implementation where all entities have the same finite element
Definition: finiteelementmap.hh:101
SimpleLocalFiniteElementMap(const Imp &imp_)
Constructor where an instance of Imp can be provided.
Definition: finiteelementmap.hh:111
LocalFiniteElementMapTraits< Imp > Traits
export type of the signature
Definition: finiteelementmap.hh:104
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:116
static constexpr int dimension
Definition: finiteelementmap.hh:121
SimpleLocalFiniteElementMap()
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:107
implementation for finite elements requiring oriented edges
Definition: finiteelementmap.hh:153
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:205
EdgeS0LocalFiniteElementMap(const GV &gv_)
construct EdgeSLocalFiniteElementMap
Definition: finiteelementmap.hh:165
static constexpr int dimension
The dimension of the finite elements returned by this map.
Definition: finiteelementmap.hh:162
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:159
Definition: finiteelementmap.hh:223
static constexpr int dimension
The dimension of the finite elements returned by this map.
Definition: finiteelementmap.hh:232
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:264
RTLocalFiniteElementMap(const GV &gv_)
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:235
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:229