dune-grid 3.0-git
geometry.cc
Go to the documentation of this file.
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_ALBERTA_GEOMETRY_CC
4#define DUNE_ALBERTA_GEOMETRY_CC
5
9
10namespace Dune
11{
12
13 // AlbertaGridGeometry
14 // -------------------
15
16 // print the GeometryInformation
17 template <int mydim, int cdim, class GridImp>
18 inline void AlbertaGridGeometry<mydim,cdim,GridImp>::print (std::ostream& ss) const
19 {
20 ss << "AlbertaGridGeometry<" << mydim << "," << cdim << "> = { \n";
21 for(int i=0; i<corners(); i++)
22 {
23 ss << " corner " << i << " = ";
24 ss << ((*this)[i]); ss << "\n";
25 }
26 ss << "} \n";
27 }
28
29
30 template< int mydim, int cdim, class GridImp >
33 {
34 GlobalCoordinate y = corner( 0 );
35 jacobianTransposed().umtv( local, y );
36 return y;
37 }
38
39
40 //local implementation for mydim < cdim
41 template< int mydim, int cdim, class GridImp >
44 {
46 jacobianInverseTransposed().mtv( global - corner( 0 ), x );
47 return x;
48 }
49
50
51 template< int mydim, int cdim, class GridImp >
54 {
55 if( !builtJT_ )
56 {
57 const FieldVector< ctype, coorddimension > &origin = coord_[ 0 ];
58 for( int i = 0; i < mydimension; ++i )
59 {
60 jT_[ i ] = coord_[ i+1 ];
61 jT_[ i ] -= origin;
62 }
63 builtJT_ = true;
64 }
65 return jT_;
66 }
67
68
69 template< int mydim, int cdim, class GridImp >
72 {
73 if( !builtJTInv_ )
74 {
75 elDet_ = std::abs( Alberta::invert( jacobianTransposed(), jTInv_ ) );
76 assert( elDet_ > 1.0e-25 );
77 calcedDet_ = true;
78 builtJTInv_ = true;
79 }
80 return jTInv_;
81 }
82
83
84 // built Geometry
85 template< int mydim, int cdim, class GridImp >
86 template< class CoordReader >
88 ::build ( const CoordReader &coordReader )
89 {
90 builtJT_ = false;
91 builtJTInv_ = false;
92
93 // copy corners
94 for( int i = 0; i < numCorners; ++i )
95 coordReader.coordinate( i, coord_[ i ] );
96
97 // calculate centroid
98 centroid_ = coord_[ 0 ];
99 for( int i = 1; i < numCorners; ++i )
100 centroid_ += coord_[ i ];
101 centroid_ *= 1.0 / numCorners;
102
103 elDet_ = (coordReader.hasDeterminant() ? coordReader.determinant() : elDeterminant());
104 assert( std::abs( elDet_ ) > 0.0 );
105 calcedDet_ = true;
106 }
107
108
109#if !DUNE_ALBERTA_CACHE_COORDINATES
110 template< int dim, int cdim >
112 AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >::global ( const LocalCoordinate &local ) const
113 {
114 GlobalCoordinate y = corner( 0 );
115 jacobianTransposed().umtv( local, y );
116 return y;
117 }
118
119
120 //local implementation for mydim < cdim
121 template< int dim, int cdim >
122 inline typename AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >::LocalCoordinate
123 AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >::local ( const GlobalCoordinate &global ) const
124 {
125 LocalCoordinate x;
126 jacobianInverseTransposed().mtv( global - corner( 0 ), x );
127 return x;
128 }
129#endif // #if !DUNE_ALBERTA_CACHE_COORDINATES
130
131
132
133 // AlbertaGridLocalGeometryProvider
134 // --------------------------------
135
136 template< class Grid >
137 void AlbertaGridLocalGeometryProvider< Grid >::buildGeometryInFather ()
138 {
139 for( int child = 0; child < numChildren; ++child )
140 {
141 for( int orientation = 0; orientation < 2; ++orientation )
142 {
143 const GeoInFatherCoordReader coordReader( child, orientation );
144 geometryInFather_[ child ][ orientation ] = new LocalElementGeometry( coordReader );
145 }
146 }
147 }
148
149
150 template< class Grid >
151 void AlbertaGridLocalGeometryProvider< Grid >::buildFaceGeometry ()
152 {
153 for( int face = 0; face < numFaces; ++face )
154 {
155 for( int twist = minFaceTwist; twist <= maxFaceTwist; ++twist )
156 {
157 const FaceCoordReader coordReader( face, twist );
158 faceGeometry_[ face ][ twist - minFaceTwist ] = new LocalFaceGeometry( coordReader );
159 }
160 }
161 }
162
163
164
165 // AlbertaGridLocalGeometryProvider::GeoInFatherCoordReader
166 // --------------------------------------------------------
167
168 template< class Grid >
170 {
172
173 typedef FieldVector< ctype, dimension > Coordinate;
174
175 private:
177
178 public:
179 GeoInFatherCoordReader ( int child, int orientation )
180 : child_( child ),
181 orientation_( orientation )
182 {}
183
184 void coordinate ( int i, Coordinate &x ) const
185 {
186 const typename GeoInFather::LocalVector &coord
187 = GeoInFather::coordinate( child_, orientation_, i );
188 for( int j = 0; j < dimension; ++j )
189 x[ j ] = coord[ j ];
190 }
191
192 bool hasDeterminant () const
193 {
194 return false;
195 }
196
198 {
199 return ctype( 0 );
200 }
201
202 private:
203 const int child_;
204 const int orientation_;
205 };
206
207
208
209 // AlbertaGridLocalGeometryProvider::FaceCoordReader
210 // -------------------------------------------------
211
212 template< class Grid >
214 {
216
217 typedef FieldVector< ctype, dimension > Coordinate;
218
219 FaceCoordReader ( const int face, const int twist = 0 )
220 : face_( face ),
221 twist_( twist )
222 {}
223
224 void coordinate ( const int i, Coordinate &x ) const
225 {
226 const int ti = Alberta::applyInverseTwist< dimension-1 >( twist_, i );
227 const int j = mapVertices< 1 >( face_, ti );
228 refCorner( j, x );
229 }
230
231 bool hasDeterminant () const
232 {
233 return false;
234 }
235
237 {
238 return ctype( 0 );
239 }
240
241 private:
242 static void refCorner ( const int i, Coordinate &x )
243 {
244 x = ctype( 0 );
245 if( i > 0 )
246 x[ i-1 ] = ctype( 1 );
247 }
248
249 int face_;
250 int twist_;
251 };
252
253} // namespace Dune
254
255#endif // #ifndef DUNE_ALBERTA_GEOMETRY_CC
provides a wrapper for ALBERTA's refinement patches and the corners for geometryInFather
Include standard header files.
Definition agrid.hh:60
int applyInverseTwist(int twist, int i)
Definition misc.hh:631
ALBERTA REAL Real
Definition misc.hh:45
static K invert(const FieldMatrix< K, 0, m > &matrix, FieldMatrix< K, m, 0 > &inverse)
Definition algebra.hh:77
FieldVector< ctype, dimension > Coordinate
Definition geometry.cc:173
void coordinate(int i, Coordinate &x) const
Definition geometry.cc:184
GeoInFatherCoordReader(int child, int orientation)
Definition geometry.cc:179
bool hasDeterminant() const
Definition geometry.cc:192
ctype determinant() const
Definition geometry.cc:197
FaceCoordReader(const int face, const int twist=0)
Definition geometry.cc:219
void coordinate(const int i, Coordinate &x) const
Definition geometry.cc:224
ctype determinant() const
Definition geometry.cc:236
FieldVector< ctype, dimension > Coordinate
Definition geometry.cc:217
bool hasDeterminant() const
Definition geometry.cc:231
Alberta::Real ctype
Definition geometry.cc:215
geometry implementation for AlbertaGrid
Definition albertagrid/geometry.hh:106
const JacobianTransposed & jacobianTransposed() const
transposed of the geometry mapping's Jacobian
Definition geometry.cc:53
LocalCoordinate local(const GlobalCoordinate &global) const
map a point from the geometry to the reference element
Definition geometry.cc:43
const JacobianInverseTransposed & jacobianInverseTransposed() const
transposed inverse of the geometry mapping's Jacobian
Definition geometry.cc:71
FieldVector< ctype, mydimension > LocalCoordinate
Definition albertagrid/geometry.hh:124
FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed
Definition albertagrid/geometry.hh:128
void print(std::ostream &out) const
Definition geometry.cc:18
GlobalCoordinate global(const LocalCoordinate &local) const
map a point from the refence element to the geometry
Definition geometry.cc:32
FieldVector< ctype, coorddimension > GlobalCoordinate
Definition albertagrid/geometry.hh:125
FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed
Definition albertagrid/geometry.hh:127
Definition albertagrid/geometry.hh:287
Definition albertagrid/geometry.hh:474
Grid::ctype ctype
Definition albertagrid/geometry.hh:478
static const int dimension
Definition albertagrid/geometry.hh:480
Definition refinement.hh:290
Grid abstract base class.
Definition common/grid.hh:373