dune-pdelab  2.0.0
variablemonomfem.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef DUNE_PDELAB_VARIABLEMONOMFEM_HH
3 #define DUNE_PDELAB_VARIABLEMONOMFEM_HH
4 
5 #include <dune/geometry/type.hh>
6 
7 #include <dune/localfunctions/common/virtualwrappers.hh>
8 #include <dune/localfunctions/monom.hh>
9 #include <dune/common/array.hh>
10 #include <dune/common/shared_ptr.hh>
11 #include "finiteelementmap.hh"
12 
13 namespace Dune {
14  namespace PDELab {
15 
16  namespace {
17  template<class D, class R, int d, int p>
18  struct InitVariableMonomLocalFiniteElementMap
19  {
20  template<typename C>
21  static void init(C & c, GeometryType gt)
22  {
23  typedef Dune::MonomLocalFiniteElement<D,R,d,p> LFE;
24  typedef typename C::value_type ptr;
25  c[p] = ptr(new LocalFiniteElementVirtualImp<LFE>(LFE(gt)));
26 
27  InitVariableMonomLocalFiniteElementMap<D,R,d,p-1>::init(c,gt);
28  }
29  };
30  template<class D, class R, int d>
31  struct InitVariableMonomLocalFiniteElementMap<D,R,d,-1>
32  {
33  template<typename C>
34  static void init(C &, GeometryType) {}
35  };
36  }
37 
40  template<class M, class D, class R, int d, int maxP=6>
42  {
43  typedef typename FixedOrderLocalBasisTraits<
44  typename MonomLocalFiniteElement<D,R,d,0>::Traits::LocalBasisType::Traits,0>::Traits T;
46  typedef LocalFiniteElementVirtualInterface<T> FiniteElementType;
47  public:
49 
51  VariableMonomLocalFiniteElementMap (const M & m, unsigned int defaultP) :
52  gt_(Dune::GeometryType::cube,d), mapper_(m), polOrder_(mapper_.size(), defaultP), defaultP_(defaultP)
53  {
54  InitVariableMonomLocalFiniteElementMap<D,R,d,maxP>::init(finiteElements_, gt_);
55  }
56 
58  VariableMonomLocalFiniteElementMap (const M & m, Dune::GeometryType gt, unsigned int defaultP) :
59  gt_(gt), mapper_(m), polOrder_(mapper_.size(), defaultP), defaultP_(defaultP)
60  {
61  InitVariableMonomLocalFiniteElementMap<D,R,d,maxP>::init(finiteElements_, gt_);
62  }
63 
65  template<class EntityType>
66  const typename Traits::FiniteElementType& find (const EntityType& e) const
67  {
68  if (e.type() != gt_)
69  DUNE_THROW(InvalidGeometryType,"Unsupported geometry type: Support only " << gt_ << ", but got " << e.type());
70  return getFEM(getOrder(e));
71  }
72 
74  const typename Traits::FiniteElementType& getFEM (unsigned int p) const
75  {
76  return *(finiteElements_[p]);
77  }
78 
80  const typename Traits::FiniteElementType& getFEM () const
81  {
82  return *(finiteElements_[defaultP_]);
83  }
84 
85  template<class EntityType>
86  void setOrder (const EntityType& e, unsigned int p)
87  {
88  assert(p <= maxP);
89  unsigned int i = mapper_.map(e);
90  polOrder_[i] = p;
91  }
92 
93  template<class EntityType>
94  unsigned int getOrder (const EntityType& e) const
95  {
96  unsigned int i = mapper_.map(e);
97  unsigned int p = polOrder_[i];
98  assert(p <= maxP);
99  return p;
100  }
101 
102  bool fixedSize() const
103  {
104  return false;
105  }
106 
107  std::size_t size(GeometryType gt) const
108  {
109  DUNE_THROW(VariableElementSize,"VariableMonomLocalFiniteElementMap can contain elements of variable order.");
110  }
111 
112  std::size_t maxLocalSize() const
113  {
114  DUNE_THROW(VariableElementSize,"VariableMonomLocalFiniteElementMap can contain elements of variable order.");
115  }
116 
117  private:
118  const Dune::GeometryType gt_;
119  const M & mapper_;
120  std::vector<unsigned char> polOrder_;
121  unsigned int defaultP_;
122  Dune::array< Dune::shared_ptr<FiniteElementType>, maxP+1 > finiteElements_;
123  };
124 
125 
126 
127  }
128 }
129 
130 #endif //DUNE_PDELAB_VARIABLEMONOMFEM_HH
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
unsigned int getOrder(const EntityType &e) const
Definition: variablemonomfem.hh:94
const Traits::FiniteElementType & getFEM(unsigned int p) const
get local basis functions for a given polynomial order
Definition: variablemonomfem.hh:74
std::size_t maxLocalSize() const
Definition: variablemonomfem.hh:112
collect types exported by a finite element map
Definition: finiteelementmap.hh:27
VariableMonomLocalFiniteElementMap(const M &m, unsigned int defaultP)
Definition: variablemonomfem.hh:51
T FiniteElementType
Type of finite element from local functions.
Definition: finiteelementmap.hh:30
Definition: variablemonomfem.hh:41
const Traits::FiniteElementType & getFEM() const
get local basis functions for the default order
Definition: variablemonomfem.hh:80
R p(int i, D x)
Definition: qkdg.hh:62
const E & e
Definition: interpolate.hh:172
bool fixedSize() const
Definition: variablemonomfem.hh:102
const Traits::FiniteElementType & find(const EntityType &e) const
get local basis functions for entity
Definition: variablemonomfem.hh:66
VariableMonomLocalFiniteElementMap(const M &m, Dune::GeometryType gt, unsigned int defaultP)
Definition: variablemonomfem.hh:58
FiniteElementMapTraits< FiniteElementType > Traits
Definition: variablemonomfem.hh:48
void setOrder(const EntityType &e, unsigned int p)
Definition: variablemonomfem.hh:86
std::size_t size(GeometryType gt) const
Definition: variablemonomfem.hh:107