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