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 
93  namespace Impl {
94 
95  template<int dim>
96  struct inject_dimension
97  {
98  static constexpr int dimension = dim;
99  };
100 
101  template<>
102  struct inject_dimension<-1>
103  {
104  DUNE_DEPRECATED_MSG("Your FEM implementation does not export the dimension. This will cause compilation errors after PDELab 2.6.") inject_dimension() {};
105  };
106 
107  }
108 
110  template<class Imp, int dim_ = -1>
112  public LocalFiniteElementMapInterface<LocalFiniteElementMapTraits<Imp>,
113  SimpleLocalFiniteElementMap<Imp> >,
114  public Impl::inject_dimension<dim_>
115  {
116  public:
119 
122  {}
123 
125  SimpleLocalFiniteElementMap (const Imp& imp_) : imp(imp_)
126  {}
127 
129  template<class EntityType>
130  const typename Traits::FiniteElementType& find (const EntityType& e) const
131  {
132  return imp;
133  }
134 
135  private:
136  Imp imp; // create once
137  };
138 
159  template<typename GV, typename FE, typename Imp>
162  LocalFiniteElementMapTraits<FE>,
163  Imp
164  >
165  {
166  typedef typename GV::IndexSet IndexSet;
167  static const int dim = GV::dimension;
168 
169  public:
172 
174  static constexpr int dimension = GV::dimension;
175 
178  : gv(gv_), orient(gv_.size(0))
179  {
180  using ct = typename GV::Grid::ctype;
181  auto& refElem =
182  ReferenceElements<ct, dim>::general(FE().type());
183 
184  auto &idSet = gv.grid().globalIdSet();
185 
186  // create all variants
187  variant.resize(1 << refElem.size(dim-1));
188  for (std::size_t i=0; i<variant.size(); i++)
189  variant[i] = FE(i);
190 
191  // compute orientation for all elements
192  auto& indexSet = gv.indexSet();
193 
194  // loop once over the grid
195  for (const auto& element : elements(gv))
196  {
197  auto elemid = indexSet.index(element);
198  orient[elemid] = 0;
199 
200  std::vector<typename GV::Grid::GlobalIdSet::IdType> vid(refElem.size(dim));
201  for(std::size_t i = 0; i < vid.size(); ++i)
202  vid[i] = idSet.subId(element, i, dim);
203 
204  // loop over all edges of the element
205  for(int i = 0; i < refElem.size(dim-1); ++i) {
206  auto v0 = refElem.subEntity(i, dim-1, 0, dim);
207  auto v1 = refElem.subEntity(i, dim-1, 1, dim);
208  // if (edge orientation in refelement) != (edge orientation in indexset)
209  if((v0 > v1) != (vid[v0] > vid[v1]))
210  orient[elemid] |= 1 << i;
211  }
212  }
213  }
214 
216  template<class EntityType>
217  const typename Traits::FiniteElementType& find (const EntityType& e) const
218  {
219  return variant[orient[gv.indexSet().index(e)]];
220  }
221 
222  private:
223  GV gv;
224  std::vector<FE> variant;
225  std::vector<unsigned char> orient;
226  };
227 
230  template<typename GV, typename FE, typename Imp, std::size_t Variants>
233  LocalFiniteElementMapTraits<FE>,
234  Imp >
235  {
236  typedef FE FiniteElement;
237  typedef typename GV::IndexSet IndexSet;
238 
239  public:
242 
244  static constexpr int dimension = GV::dimension;
245 
247  RTLocalFiniteElementMap(const GV& gv_)
248  : gv(gv_), is(gv_.indexSet()), orient(gv_.size(0))
249  {
250  // create all variants
251  for (std::size_t i = 0; i < Variants; i++)
252  {
253  variant[i] = FiniteElement(i);
254  }
255 
256  // compute orientation for all elements
257  // loop once over the grid
258  for(const auto& cell : elements(gv))
259  {
260  auto myId = is.index(cell);
261  orient[myId] = 0;
262 
263  for (const auto& intersection : intersections(gv,cell))
264  {
265  if (intersection.neighbor()
266  && is.index(intersection.outside()) > myId)
267  {
268  orient[myId] |= 1 << intersection.indexInInside();
269  }
270  }
271  }
272  }
273 
275  template<class EntityType>
276  const typename Traits::FiniteElementType& find(const EntityType& e) const
277  {
278  return variant[orient[is.index(e)]];
279  }
280 
281  private:
282  GV gv;
283  std::array<FiniteElement,Variants> variant;
284  const IndexSet& is;
285  std::vector<unsigned char> orient;
286  };
287 
289 
290  } // namespace PDELab
291 } // namespace Dune
292 
293 #endif // DUNE_PDELAB_FINITEELEMENTMAP_FINITEELEMENTMAP_HH
static const int dim
Definition: adaptivity.hh:84
const Entity & e
Definition: localfunctionspace.hh:120
Definition: finiteelementmap.hh:231
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:130
FiniteElementMap exception raised when trying to obtain a finite element for an unsupported GeometryT...
Definition: finiteelementmap.hh:23
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:241
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:276
SimpleLocalFiniteElementMap(const Imp &imp_)
Constructor where an instance of Imp can be provided.
Definition: finiteelementmap.hh:125
implementation for finite elements requiring oriented edges
Definition: finiteelementmap.hh:160
T FiniteElementType
Type of finite element from local functions.
Definition: finiteelementmap.hh:30
T Traits
Export traits.
Definition: finiteelementmap.hh:46
RTLocalFiniteElementMap(const GV &gv_)
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:247
EdgeS0LocalFiniteElementMap(const GV &gv_)
construct EdgeSLocalFiniteElementMap
Definition: finiteelementmap.hh:177
SimpleLocalFiniteElementMap()
Use when Imp has a standard constructor.
Definition: finiteelementmap.hh:121
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
PDELab-specific exceptions.
LocalFiniteElementMapTraits< FE > Traits
export type of the signature
Definition: finiteelementmap.hh:171
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: finiteelementmap.hh:217
LocalFiniteElementMapTraits< Imp > Traits
export type of the signature
Definition: finiteelementmap.hh:118
collect types exported by a finite element map
Definition: finiteelementmap.hh:27
Base class for all PDELab exceptions.
Definition: exceptions.hh:17
general FiniteElementMap exception
Definition: finiteelementmap.hh:19
T FiniteElement
Type of finite element from local functions.
Definition: finiteelementmap.hh:33
simple implementation where all entities have the same finite element
Definition: finiteelementmap.hh:111
interface for a finite element map
Definition: finiteelementmap.hh:42