dune-localfunctions  2.2.1
monom.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_MONOMLOCALFINITEELEMENT_HH
5 #define DUNE_MONOMLOCALFINITEELEMENT_HH
6 
7 #include <cassert>
8 #include <cstddef>
9 #include <cstdlib>
10 #include <vector>
11 
12 #include <dune/common/deprecated.hh>
13 #include <dune/common/shared_ptr.hh>
14 #include <dune/common/static_assert.hh>
15 
16 #include <dune/geometry/type.hh>
17 
20 #include "monom/monomlocalbasis.hh"
23 
24 namespace Dune
25 {
26 
35  template<class D, class R, int d, int p, int diffOrder = p>
37  {
38  enum { static_size = MonomImp::Size<d,p>::val };
39 
40  public:
47  > Traits;
48 
51  MonomLocalFiniteElement (GeometryType::BasicType basicType) DUNE_DEPRECATED
52  : basis(), interpolation(basicType, basis), gt(basicType,d)
53  {}
54 
56  MonomLocalFiniteElement (const GeometryType &gt_)
57  : basis(), interpolation(gt_, basis), gt(gt_)
58  {}
59 
62  const typename Traits::LocalBasisType& localBasis () const
63  {
64  return basis;
65  }
66 
70  {
71  return coefficients;
72  }
73 
77  {
78  return interpolation;
79  }
80 
83  GeometryType type () const
84  {
85  return gt;
86  }
87 
88  private:
92  GeometryType gt;
93  };
94 
96 
108  template<class Geometry, class RF, std::size_t p>
110  typedef typename Geometry::ctype DF;
111  static const std::size_t dim = Geometry::mydimension;
112 
114 
115  std::vector<shared_ptr<const LocalFE> > localFEs;
116 
117  void init(const GeometryType &gt) {
118  std::size_t index = gt.id() >> 1;
119  if(localFEs.size() <= index)
120  localFEs.resize(index+1);
121  localFEs[index].reset(new LocalFE(gt));
122  }
123 
124  public:
127 
129 
133  template<class ForwardIterator>
134  MonomFiniteElementFactory(const ForwardIterator &begin,
135  const ForwardIterator &end)
136  {
137  for(ForwardIterator it = begin; it != end; ++it)
138  init(*it);
139  }
140 
142 
145  MonomFiniteElementFactory(const GeometryType &gt)
146  { init(gt); }
147 
149 
153  dune_static_assert(dim <= 3, "MonomFiniteElementFactory knows the "
154  "available geometry types only up to dimension 3");
155 
156  GeometryType gt;
157  switch(dim) {
158  case 0:
159  gt.makeVertex(); init(gt);
160  break;
161  case 1:
162  gt.makeLine(); init(gt);
163  break;
164  case 2:
165  gt.makeTriangle(); init(gt);
166  gt.makeQuadrilateral(); init(gt);
167  break;
168  case 3:
169  gt.makeTetrahedron(); init(gt);
170  gt.makePyramid(); init(gt);
171  gt.makePrism(); init(gt);
172  gt.makeHexahedron(); init(gt);
173  break;
174  default:
175  // this should never happen -- it should be caught by the static
176  // assert above.
177  std::abort();
178  };
179  }
180 
182 
192  const FiniteElement make(const Geometry& geometry) {
193  std::size_t index = geometry.type().id() >> 1;
194  assert(localFEs.size() > index && localFEs[index]);
195  return FiniteElement(*localFEs[index], geometry);
196  }
197  };
198 }
199 
200 #endif // DUNE_MONOMLOCALFINITEELEMENT_HH