DUNE-FUNCTIONS (unstable)

refinedlagrangebasis.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
5 
6 #include <type_traits>
7 
8 #include <dune/common/exceptions.hh>
9 #include <dune/common/math.hh>
10 
11 #include <dune/localfunctions/refined.hh>
12 
13 #include <dune/functions/functionspacebases/defaultglobalbasis.hh>
14 #include <dune/functions/functionspacebases/leafprebasismappermixin.hh>
15 #include <dune/functions/functionspacebases/nodes.hh>
16 
17 #include <dune/geometry/type.hh>
18 
19 #include <dune/grid/common/mcmgmapper.hh>
20 
21 
22 namespace Dune {
23 namespace Functions {
24 
25 template<typename GV, int k, typename R>
26 class RefinedLagrangeNode;
27 
39 template <typename GV, int k, typename R = double>
41  public LeafPreBasisMapperMixin< GV >
42 {
44 
45  static const int dim = GV::dimension;
46 
47  // refined basis only implemented for P0 and P1
48  static_assert(k == 0 || k == 1);
49 
50  // the layout is defined in terms of a MCMGLayout specialized for k == 0 or 1
51  static MCMGLayout dofLayout()
52  {
53  if constexpr(k == 0)
54  // a refined P0 basis assigns each element 2^dim DOFs
55  return [](GeometryType gt, int) -> size_t {
56  return (gt.dim() == dim) ? (1 << dim) : 0;
57  };
58  else if constexpr(k == 1)
59  // a refined P1 basis has the same layout as a P2 basis
60  return [](GeometryType gt, int) -> size_t {
61  return Dune::binomial(int(k),int(gt.dim()));
62  };
63  else
64  DUNE_THROW(Dune::NotImplemented,
65  "Refined basis not implemented for higher-order Lagrange (k>=2) elements.");
66  }
67 
68 public:
69 
71  using GridView = GV;
72 
74  using Node = RefinedLagrangeNode<GV, k, R>;
75 
83  : Base(gv, dofLayout())
84  {
85  for (auto gt : gv.indexSet().types(0)) {
86  if (!gt.isSimplex())
87  DUNE_THROW(Dune::NotImplemented,
88  "Refined Lagrange basis only implemented for simplex grids.");
89  }
90  }
91 
93  Node makeNode () const
94  {
95  return Node{};
96  }
97 
105  static constexpr unsigned int order()
106  {
107  return k;
108  }
109 };
110 
111 
112 
113 template <typename GV, int k, typename R>
114 class RefinedLagrangeNode
115  : public LeafBasisNode
116 {
117  static constexpr int dim = GV::dimension;
118 
119  // refined basis only implemented for P0 and P1
120  static_assert(k == 0 || k == 1);
121 
122 public:
124  using Element = typename GV::template Codim<0>::Entity;
125 
127  using FiniteElement = std::conditional_t<(k==0),
128  Dune::RefinedP0LocalFiniteElement<typename GV::ctype,R,dim>,
129  Dune::RefinedP1LocalFiniteElement<typename GV::ctype,R,dim>>;
130 
140  RefinedLagrangeNode ()
141  : finiteElement_{}
142  , element_(nullptr)
143  {}
144 
149  const Element& element () const
150  {
151  return *element_;
152  }
153 
160  const FiniteElement& finiteElement () const
161  {
162  return finiteElement_;
163  }
164 
166  void bind (const Element& e)
167  {
168  element_ = &e;
169  this->setSize(finiteElement_.size());
170  }
171 
176  static constexpr unsigned int order()
177  {
178  return k;
179  }
180 
181 protected:
182  const FiniteElement finiteElement_;
183  const Element* element_;
184 };
185 
186 
187 
188 namespace BasisFactory {
189 
197 template <int k, typename R=double>
199 {
200  return [](const auto& gridView) {
201  return RefinedLagrangePreBasis<std::decay_t<decltype(gridView)>, k, R>(gridView);
202  };
203 }
204 
205 } // end namespace BasisFactory
206 
207 
221 template <typename GV, int k, typename R=double>
223 
224 } // end namespace Functions
225 } // end namespace Dune
226 
227 
228 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
A generic MixIn class for PreBasis with flat indices computed from a mapper.
Definition: leafprebasismappermixin.hh:58
GV GridView
Type of the associated GridView.
Definition: leafprebasismappermixin.hh:64
A pre-basis for a refined Lagrange bases.
Definition: refinedlagrangebasis.hh:42
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements.
Definition: refinedlagrangebasis.hh:105
Node makeNode() const
Create tree node.
Definition: refinedlagrangebasis.hh:93
RefinedLagrangeNode< GV, k, R > Node
Type of the refined Lagrange tree node.
Definition: refinedlagrangebasis.hh:74
RefinedLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: refinedlagrangebasis.hh:82
auto refinedLagrange()
Create a pre-basis factory that can create a RefinedLagrange pre-basis.
Definition: refinedlagrangebasis.hh:198
Definition: polynomial.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)