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