dune-geometry  2.2.0
genericgeometry/referenceelements.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEELEMENTS_HH
5 #define DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEELEMENTS_HH
6 
11 #include <dune/common/array.hh>
12 #include <dune/common/fvector.hh>
13 #include <dune/common/typetraits.hh>
14 
16 
17 namespace Dune
18 {
19 
20  namespace GenericGeometry
21  {
22 
23  // ReferenceElement
24  // ----------------
25 
26  template< class Topology, class ctype >
28  {
29  static const unsigned int topologyId = Topology :: id;
30  static const unsigned int dimension = Topology :: dimension;
31 
32  static const unsigned int numCorners = Topology :: numCorners;
34 
35  typedef FieldVector< ctype, dimension > CoordinateType;
36 
37  template< unsigned int codim >
38  struct Codim
39  {
40  enum { size = Size< Topology, codim > :: value };
41  };
42 
43  template< unsigned int codim, unsigned int subcodim >
44  static unsigned int subNumbering ( unsigned int i, unsigned int j )
45  {
47  }
48 
49  template< unsigned int codim, unsigned int subcodim >
50  static unsigned int size ( unsigned int i )
51  {
53  }
54 
55  template< unsigned int codim >
56  static const FieldVector< ctype, dimension > &
57  baryCenter ( unsigned int i )
58  {
59  integral_constant< int, codim > codimVariable;
60  return instance().baryCenters_[ codimVariable ][ i ];
61  }
62 
63  static const CoordinateType &corner ( unsigned int i )
64  {
65  assert( i < numCorners );
66  return instance().corners_[ i ];
67  }
68 
69  static bool checkInside ( const CoordinateType &x )
70  {
72  }
73 
74  static const CoordinateType &
75  integrationOuterNormal ( unsigned int i )
76  {
77  assert( i < numNormals );
78  return instance().normals_[ i ];
79  }
80 
81  static ctype volume ()
82  {
83  return ReferenceDomain< Topology > :: template volume< ctype >();
84  }
85 
86  static const ReferenceElement &instance ()
87  {
88  static ReferenceElement inst;
89  return inst;
90  }
91 
92  private:
93  template< int codim >
94  class BaryCenterArray;
95 
97  {
98  for( unsigned int i = 0; i < numCorners; ++i )
99  ReferenceDomain< Topology > :: corner( i, corners_[ i ] );
100  for( unsigned int i = 0; i < numNormals; ++i )
102  }
103 
104  Dune::array< CoordinateType, numCorners > corners_;
105  CodimTable< BaryCenterArray, dimension > baryCenters_;
106  Dune::array< CoordinateType, numNormals > normals_;
107  };
108 
109 
110 
111  template< class Topology, class ctype >
112  template< int codim >
114  {
116 
117  typedef FieldVector< ctype, dimension > CoordinateType;
118 
119  template< int i >
120  struct Builder;
121 
122  CoordinateType baryCenters_[ Size ];
123 
124  public:
126  {
127  ForLoop< Builder, 0, Size-1 > :: apply( baryCenters_ );
128  }
129 
130  const CoordinateType &operator[] ( unsigned int i ) const
131  {
132  assert( i < Size );
133  return baryCenters_[ i ];
134  }
135 
136  static unsigned int size ()
137  {
138  return Size;
139  }
140  };
141 
142  template< class Topology, class ctype >
143  template< int codim >
144  template< int i >
145  struct ReferenceElement< Topology, ctype > :: BaryCenterArray< codim > :: Builder
146  {
147  static void apply ( CoordinateType (&baryCenters)[ Size ] )
148  {
149  typedef SubTopologyNumbering< Topology, codim, dimension - codim > Numbering;
150  typedef SubTopologySize< Topology, codim, dimension - codim > Size;
151 
152  CoordinateType &x = baryCenters[ i ];
153  x = 0;
154  const unsigned int numCorners = Size :: size( i );
155  for( unsigned int k = 0; k < numCorners; ++k )
156  {
157  unsigned int j = Numbering :: number( i, k );
158 
159  CoordinateType y;
161  x += y;
162  }
163  x *= ctype( 1 ) / ctype( numCorners );
164  }
165  };
166 
167  }
168 
169 }
170 
171 #endif // DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEELEMENTS_HH