dune-vtk  0.2
lagrangepoints.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <array>
5 
6 #include <dune/common/exceptions.hh>
7 #include <dune/geometry/type.hh>
8 #include <dune/localfunctions/lagrange/equidistantpoints.hh>
9 
10 namespace Dune
11 {
12  namespace Vtk
13  {
14  namespace Impl
15  {
16  // forward declaration
17  template <class K, unsigned int dim>
18  class LagrangePointSetBuilder;
19  }
20 
21 
23 
27  template <class K, unsigned int dim>
29  : public EmptyPointSet<K, dim>
30  {
31  using Super = EmptyPointSet<K, dim>;
32 
33  public:
34  static const unsigned int dimension = dim;
35 
36  LagrangePointSet (std::size_t order)
37  : Super(order)
38  {
39  assert(order > 0);
40  }
41 
43  void build (GeometryType gt)
44  {
45  assert(gt.dim() == dimension);
46  builder_(gt, order(), points_);
47  }
48 
50  template <class Topology>
51  bool build ()
52  {
53  build(GeometryType(Topology{}));
54  return true;
55  }
56 
59  template <class Topology>
60  static bool supports (std::size_t order)
61  {
62  return true;
63  }
64 
65  using Super::order;
66 
67  private:
68  using Super::points_;
69  Impl::LagrangePointSetBuilder<K,dim> builder_;
70  };
71 
72 
73  namespace Impl
74  {
75  // Build for lagrange point sets in different dimensions
76  // Specialized for dim=1,2,3
77  template <class K, unsigned int dim>
78  class LagrangePointSetBuilder
79  {
80  public:
81  template <class Points>
82  void operator()(GeometryType, unsigned int, Points& points) const
83  {
84  DUNE_THROW(Dune::NotImplemented,
85  "Lagrange points not yet implemented for this GeometryType.");
86  }
87  };
88 
89 
90  // Lagrange points on point geometries
91  template <class K>
92  class LagrangePointSetBuilder<K,0>
93  {
94  static constexpr int dim = 0;
95  using LP = LagrangePoint<K,dim>;
96  using Vec = typename LP::Vector;
97  using Key = LocalKey;
98 
99  public:
100  template <class Points>
101  void operator()(GeometryType gt, int /*order*/, Points& points) const;
102  };
103 
104 
105  // Lagrange points on line geometries
106  template <class K>
107  class LagrangePointSetBuilder<K,1>
108  {
109  static constexpr int dim = 1;
110  using LP = LagrangePoint<K,dim>;
111  using Vec = typename LP::Vector;
112  using Key = LocalKey;
113 
114  public:
115  template <class Points>
116  void operator()(GeometryType gt, int order, Points& points) const;
117  };
118 
119 
120  // Lagrange points on 2d geometries
121  template <class K>
122  class LagrangePointSetBuilder<K,2>
123  {
124  static constexpr int dim = 2;
125  using LP = LagrangePoint<K,dim>;
126  using Vec = typename LP::Vector;
127  using Key = LocalKey;
128 
129  friend class LagrangePointSetBuilder<K,3>;
130 
131  public:
132  template <class Points>
133  void operator()(GeometryType gt, int order, Points& points) const;
134 
135  private: // implementation details
136 
137  // Construct the point set in a triangle element.
138  // Loop from the outside to the inside
139  template <class Points>
140  void buildTriangle (std::size_t nPoints, int order, Points& points) const;
141 
142  // "Barycentric index" is a triplet of integers, each running from 0 to
143  // <Order>. It is the index of a point on the triangle in barycentric
144  // coordinates.
145  static void barycentricIndex (int index, std::array<int,3>& bindex, int order);
146 
147  // Construct the point set in the quad element
148  // 1. build equispaced points with index tuple (i,j)
149  // 2. map index tuple to DOF index and LocalKey
150  template <class Points>
151  void buildQuad(std::size_t nPoints, int order, Points& points) const;
152 
153  // Obtain the VTK DOF index of the node (i,j) in the quad element
154  // and construct a LocalKey
155  static std::pair<int,Key> calcQuadKey (int i, int j, std::array<int,2> order);
156  };
157 
158 
159  // Lagrange points on 3d geometries
160  template <class K>
161  class LagrangePointSetBuilder<K,3>
162  {
163  static constexpr int dim = 3;
164  using LP = LagrangePoint<K,dim>;
165  using Vec = typename LP::Vector;
166  using Key = LocalKey;
167 
168  public:
169  template <class Points>
170  void operator() (GeometryType gt, unsigned int order, Points& points) const;
171 
172  private: // implementation details
173 
174  // Construct the point set in the tetrahedron element
175  // 1. construct barycentric (index) coordinates
176  // 2. obtains the DOF index, LocalKey and actual coordinate from barycentric index
177  template <class Points>
178  void buildTetra (std::size_t nPoints, int order, Points& points) const;
179 
180  // "Barycentric index" is a set of 4 integers, each running from 0 to
181  // <Order>. It is the index of a point in the tetrahedron in barycentric
182  // coordinates.
183  static void barycentricIndex (std::size_t p, std::array<int,4>& bindex, int order);
184 
185  // Construct the point set in the heyhedral element
186  // 1. build equispaced points with index tuple (i,j,k)
187  // 2. map index tuple to DOF index and LocalKey
188  template <class Points>
189  void buildHex (std::size_t nPoints, int order, Points& points) const;
190 
191  // Obtain the VTK DOF index of the node (i,j,k) in the hexahedral element
192  static std::pair<int,Key> calcHexKey (int i, int j, int k, std::array<int,3> order);
193  };
194 
195  } // end namespace Impl
196  } // end namespace Vtk
197 } // end namespace Dune
198 
Definition: datacollectorinterface.hh:9
A set of lagrange points compatible with the numbering of VTK and Gmsh.
Definition: lagrangepoints.hh:30
bool build()
Fill the lagrange points for the given topology type Topology
Definition: lagrangepoints.hh:51
static bool supports(std::size_t order)
Definition: lagrangepoints.hh:60
LagrangePointSet(std::size_t order)
Definition: lagrangepoints.hh:36
void build(GeometryType gt)
Fill the lagrange points for the given geometry type.
Definition: lagrangepoints.hh:43
static const unsigned int dimension
Definition: lagrangepoints.hh:34