1 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEDOMAIN_HH
2 #define DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEDOMAIN_HH
4 #include <dune/common/array.hh>
5 #include <dune/common/fvector.hh>
6 #include <dune/common/typetraits.hh>
14 namespace GenericGeometry
20 template<
class Topology >
21 struct ReferenceDomain;
28 template<
class Topology >
29 class ReferenceDomainBase;
33 class ReferenceDomainBase< Point >
35 typedef Point Topology;
37 friend struct ReferenceDomain< Topology >;
38 friend class ReferenceDomainBase< Prism< Topology > >;
39 friend class ReferenceDomainBase< Pyramid< Topology > >;
41 static const unsigned int numNormals = 0;
43 template<
class ctype,
int dim >
44 static void corner (
unsigned int i, FieldVector< ctype, dim > &n )
46 assert( i < Topology::numCorners );
49 template<
class ctype,
int dim >
51 checkInside (
const FieldVector< ctype, dim > &x, ctype factor )
56 template<
class ctype,
int dim >
58 integrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
60 assert( i < numNormals );
63 template<
class ctype >
64 static ctype volume ()
71 template<
class BaseTopology >
72 class ReferenceDomainBase< Prism< BaseTopology > >
74 typedef Prism< BaseTopology > Topology;
76 friend struct ReferenceDomain< Topology >;
77 friend class ReferenceDomainBase< Prism< Topology > >;
78 friend class ReferenceDomainBase< Pyramid< Topology > >;
80 static const unsigned int numNormals = Size< Topology, 1 >::value;
82 static const unsigned int dimension = Topology::dimension;
83 static const unsigned int myindex = dimension - 1;
85 template<
class ctype,
int dim >
86 static void corner (
unsigned int i, FieldVector< ctype, dim > &x )
88 assert( i < Topology::numCorners );
89 const unsigned int j = i % BaseTopology::numCorners;
90 ReferenceDomainBase< BaseTopology >::corner( j, x );
91 if( i >= BaseTopology::numCorners )
92 x[ myindex ] = ctype( 1 );
95 template<
class ctype,
int dim >
97 checkInside (
const FieldVector< ctype, dim > &x, ctype factor )
99 const ctype xn = x[ myindex ];
100 const ctype cxn = factor - xn;
101 return (xn > -1e-12) && (cxn > -1e-12)
102 && ReferenceDomainBase< BaseTopology >::checkInside( x, factor );
105 template<
class ctype,
int dim >
107 integrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
109 typedef ReferenceDomainBase< BaseTopology > BaseReferenceDomain;
111 if( i >= BaseReferenceDomain::numNormals )
113 const unsigned int j = i - BaseReferenceDomain::numNormals;
114 n[ myindex ] = (j == 0 ? ctype( -1 ) : ctype( 1 ));
117 BaseReferenceDomain::integrationOuterNormal( i, n );
120 template<
class ctype >
121 static ctype volume ()
123 typedef ReferenceDomainBase< BaseTopology > BaseReferenceDomain;
124 return BaseReferenceDomain::template volume< ctype >();
129 template<
class BaseTopology >
130 class ReferenceDomainBase< Pyramid< BaseTopology > >
132 typedef Pyramid< BaseTopology > Topology;
134 friend struct ReferenceDomain< Topology >;
135 friend class ReferenceDomainBase< Prism< Topology > >;
136 friend class ReferenceDomainBase< Pyramid< Topology > >;
138 static const unsigned int numNormals = Size< Topology, 1 >::value;
140 static const unsigned int dimension = Topology::dimension;
141 static const unsigned int myindex = dimension - 1;
144 struct MultiDimensional
146 template<
class ctype,
int dim >
148 integrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
150 multiDimensionalIntegrationOuterNormal( i, n );
155 struct OneDimensional
157 template<
class ctype,
int dim >
159 integrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
161 n[ myindex ] = (i > 0) ? ctype( 1 ) : ctype( -1 );
165 template<
class ctype,
int dim >
166 static void corner (
unsigned int i, FieldVector< ctype, dim > &x )
168 assert( i < Topology::numCorners );
169 if( i < BaseTopology::numCorners )
170 ReferenceDomainBase< BaseTopology >::corner( i, x );
172 x[ myindex ] = ctype( 1 );
175 template<
class ctype,
int dim >
177 checkInside (
const FieldVector< ctype, dim > &x, ctype factor )
179 const ctype xn = x[ myindex ];
180 const ctype cxn = factor - xn;
181 return (xn > -1e-12) && (cxn > -1e-12)
182 && ReferenceDomainBase< BaseTopology >::checkInside( x, cxn );
185 template<
class ctype,
int dim >
187 multiDimensionalIntegrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
189 typedef ReferenceDomainBase< BaseTopology > BaseReferenceDomain;
190 typedef SubTopologyNumbering< BaseTopology, 1, dimension-2 > Numbering;
194 const unsigned int j = Numbering::number( i-1, 0 );
195 FieldVector< ctype, dim > x( ctype( 0 ) );
196 BaseReferenceDomain::corner( j, x );
198 BaseReferenceDomain::integrationOuterNormal ( i-1, n );
199 n[ myindex ] = (x * n);
202 n[ myindex ] = ctype( -1 );
205 template<
class ctype,
int dim >
207 integrationOuterNormal (
unsigned int i, FieldVector< ctype, dim > &n )
209 SelectType< (dimension > 1), MultiDimensional<true>, OneDimensional<false> > :: Type
210 ::integrationOuterNormal( i, n );
213 template<
class ctype >
214 static ctype volume ()
216 typedef ReferenceDomainBase< BaseTopology > BaseReferenceDomain;
217 const ctype baseVolume = BaseReferenceDomain::template volume< ctype >();
218 return baseVolume / ctype( (
unsigned int)(dimension) );
228 template<
class Topology >
235 = ReferenceDomainBase< Topology >::numNormals;
237 template<
class ctype >
238 static void corner (
unsigned int i, FieldVector< ctype, dimension > &x )
244 template<
class ctype >
245 static bool checkInside (
const FieldVector< ctype, dimension > &x )
250 template<
class ctype >
258 template<
class ctype >
261 return ReferenceDomainBase< Topology >::template volume< ctype >();
269 #endif // DUNE_GEOMETRY_GENERICGEOMETRY_REFERENCEDOMAIN_HH