1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi: set et ts=4 sw=2 sts=2:
1
3
#ifndef DUNE_ALU2DGRID_GEOMETRYIMP_CC
2
4
#define DUNE_ALU2DGRID_GEOMETRYIMP_CC
4
#include <dune/geometry/genericgeometry/conversion.hh>
5
6
#include <dune/geometry/referenceelements.hh>
10
// implementation of methods
12
//**********************************************************************
14
// --ALU2dGridGeometry
16
//**********************************************************************
19
template< int mydim, int cdim, class GridImp >
20
inline ALU2dGridGeometry< mydim, cdim, GridImp >::ALU2dGridGeometry ()
26
//! print the GeometryInformation
27
template< int mydim, int cdim, class GridImp >
28
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::print ( std::ostream &out ) const
30
out << "ALU2dGridGeometry< " << mydim << ", " << cdim << " > = ";
32
for( int i = 0; i < corners(); ++i )
34
out << c << " (" << corner( i ) << ")";
37
out << " }" << std::endl;
41
///////////////////////////////////////////////////////////////////////
44
//! access to coordinates of corners. Index is the number of the corner
45
template <int mydim, int cdim, class GridImp>
46
inline const typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate &
47
ALU2dGridGeometry< mydim, cdim, GridImp >::operator[] ( int i ) const
49
typedef GenericGeometry::MapNumberingProvider< mydim > Numbering;
50
const unsigned int tid = type().id();
51
static GlobalCoordinate c;
52
return (c = corner( Numbering::template dune2generic< mydim >( tid, i ) ));
56
//! access to coordinates of corners. Index is the number of the corner
57
template< int mydim, int cdim, class GridImp >
58
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
59
ALU2dGridGeometry< mydim, cdim, GridImp >::corner ( int i ) const
61
const GenericReferenceElement< alu2d_ctype, mydim > &refElement
62
= GenericReferenceElements< alu2d_ctype, mydim >::general( type() );
63
return global( refElement.position( i, mydim ) );
67
//! maps a local coordinate within reference element to
68
//! global coordinate in element
69
template< int mydim, int cdim, class GridImp >
70
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
71
ALU2dGridGeometry< mydim, cdim, GridImp >::global ( const LocalCoordinate &local ) const
73
GlobalCoordinate global;
74
geoImpl_.map2world( local, global );
79
//! maps a global coordinate within the element to a
80
//! local coordinate in its reference element
81
template< int mydim, int cdim, class GridImp >
82
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::LocalCoordinate
83
ALU2dGridGeometry< mydim, cdim, GridImp >::local ( const GlobalCoordinate &global ) const
86
return LocalCoordinate( 1 );
88
LocalCoordinate local;
89
geoImpl_.world2map( global, local );
94
template< int mydim, int cdim, class GridImp >
96
ALU2dGridGeometry< mydim, cdim, GridImp >::integrationElement ( const LocalCoordinate &local ) const
98
if ( eltype == ALU2DSPACE triangle || mydim < 2 )
100
assert( geoImpl_.valid() );
101
return (mydim == 0 ? 1.0 : det_);
104
return geoImpl_.det(local);
108
template< int mydim, int cdim, class GridImp >
109
inline alu2d_ctype ALU2dGridGeometry< mydim, cdim, GridImp >::volume () const
111
assert( geoImpl_.valid() );
114
switch( GridImp::elementType )
116
case ALU2DSPACE triangle:
119
case ALU2DSPACE quadrilateral:
122
case ALU2DSPACE mixed:
123
DUNE_THROW( NotImplemented, "Geometry::volume() not implemented for ElementType mixed." );
127
return (mydim == 0 ? 1.0 : det_);
131
template< int mydim, int cdim, class GridImp >
132
inline const FieldMatrix<alu2d_ctype,mydim,cdim>&
133
ALU2dGridGeometry< mydim, cdim, GridImp>::jacobianTransposed ( const LocalCoordinate &local ) const
135
return geoImpl_.jacobianTransposed( local );
139
template< int mydim, int cdim, class GridImp >
140
inline const FieldMatrix<alu2d_ctype,cdim,mydim>&
141
ALU2dGridGeometry< mydim, cdim, GridImp >::jacobianInverseTransposed ( const LocalCoordinate &local ) const
143
return geoImpl_.jacobianInverseTransposed( local );
147
//! built Geometry for triangles
148
template< int mydim, int cdim, class GridImp >
150
ALU2dGridGeometry< mydim, cdim, GridImp >::buildGeom( const HElementType &item )
154
assert( mydim == 2 );
156
// update geometry impl
157
geoImpl_.update( item );
160
det_ = (geoImpl_.corners() == 3 ? 2 * item.area() : item.area());
167
//! built Geometry for edges
168
template <int mydim, int cdim, class GridImp>
169
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
170
buildGeom(const HElementType & item, const int aluFace)
172
assert( mydim == 1 );
174
const int nf = item.numfaces();
176
// for triangles face 1 is twisted and for quatrilaterals faces 1 and 2
177
const int twist = (nf == 3) ? (aluFace % 2) : (aluFace>>1)^(aluFace&1);
178
// std::cout << nf << " " << aluFace << " " << twist << std::endl;
179
// << " ( " item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
180
// << " , " item.getVertex( (aluFace + 2 - twist ) % nf )->coord()
181
// << " ) " << std::endl;
187
// update geometry impl
188
geoImpl_.update( item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
189
item.getVertex( (aluFace + 2 - twist ) % nf )->coord() );
192
det_ = item.sidelength( aluFace );
193
//assert( std::abs( det_ - geoImpl_.det( LocalCoordinate(0.5) ) ) < 1e-14 );
199
//! built Geometry for vertices
200
template <int mydim, int cdim, class GridImp>
201
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
202
buildGeom(const VertexType & item , const int )
204
assert( mydim == 0 );
207
// update geometry impl
208
geoImpl_.update( item.coord() );
210
// volume is already 1.0
216
template <int mydim, int cdim, class GridImp>
217
template <class GeometryType, class LocalGeometryType >
218
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
219
buildLocalGeom(const GeometryType &geo, const LocalGeometryType & localGeom)
222
geoImpl_.updateLocal( geo, localGeom );
225
LocalCoordinate local( 0.25 );
226
det_ = geoImpl_.det( local );
232
// built Geometry (faceNumber is in generic numbering)
233
template< int mydim, int cdim, class GridImp >
234
inline std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
235
ALU2dGridGeometry< mydim, cdim, GridImp >::calculateReferenceCoords ( const int corners )
237
// calculate reference coordinates of aLUGrid reference triangle
239
FieldMatrix< alu2d_ctype, 4, 2 > refCoord( 0. );
240
FieldVector< alu2d_ctype, 4 > lengths( 1. );
243
refCoord[1][0] = 1.0;
245
refCoord[corners-1][1] = 1.0;
248
lengths[0] = M_SQRT2;
253
refCoord[2][0] = 1.0;
254
refCoord[2][1] = 1.0;
256
return std::make_pair( refCoord, lengths );
259
// built Geometry (faceNumber is in generic numbering)
260
template <int mydim, int cdim, class GridImp>
261
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
262
buildLocalGeometry(const int aluFace, const int twist, const int corners)
264
assert( twist == 0 || twist == 1 );
265
assert( mydim == 1 );
267
// get coordinates of reference element
268
typedef std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > > RefCoord;
269
RefCoord refCoord( calculateReferenceCoords( corners ) );
271
geoImpl_.update( refCoord.first[ ( aluFace + 1+twist ) % corners ],
272
refCoord.first[ ( aluFace + 2-twist ) % corners ] );
274
// get length of faces
275
det_ = refCoord.second[ aluFace ];
282
template <int mydim, int cdim, class GridImp >
283
inline bool ALU2dGridGeometry<mydim, cdim,GridImp>::
284
buildGeomInFather(const Geometry & fatherGeom ,
285
const Geometry & myGeom)
288
geoImpl_.updateLocal( fatherGeom, myGeom );
290
// store volume which is a part of one
291
det_ = myGeom.volume() / fatherGeom.volume();
292
assert( (det_ > 0.0) && (det_ < 1.0) );
297
} //end namespace Dune
11
// implementation of methods
13
//**********************************************************************
15
// --ALU2dGridGeometry
17
//**********************************************************************
20
template< int mydim, int cdim, class GridImp >
21
inline ALU2dGridGeometry< mydim, cdim, GridImp >::ALU2dGridGeometry ()
26
template< int mydim, int cdim, class GridImp >
27
inline ALU2dGridGeometry< mydim, cdim, GridImp >&
28
ALU2dGridGeometry< mydim, cdim, GridImp >::operator = ( const ALU2dGridGeometry& other )
38
template< int mydim, int cdim, class GridImp >
39
inline ALU2dGridGeometry< mydim, cdim, GridImp >::ALU2dGridGeometry ( const ALU2dGridGeometry& other )
44
template< int mydim, int cdim, class GridImp >
45
inline ALU2dGridGeometry< mydim, cdim, GridImp >::~ALU2dGridGeometry ()
50
template< int mydim, int cdim, class GridImp >
51
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::getObject()
53
geoImpl_ = geoProvider().getEmptyObject();
57
template< int mydim, int cdim, class GridImp >
58
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::assign( const ALU2dGridGeometry& other )
61
geoImpl_ = other.geoImpl_ ;
63
// increase reference count
67
template< int mydim, int cdim, class GridImp >
68
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::removeObj()
70
// decrease reference count
73
// if reference count is zero free the object
76
geoProvider().freeObject( geoImpl_ );
83
template< int mydim, int cdim, class GridImp >
84
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::invalidate()
86
// if geometry is used elsewhere remove the pointer
88
if( geoImpl().stillUsed() )
98
// otherwise invalidate object
99
geoImpl().invalidate();
103
//! print the GeometryInformation
104
template< int mydim, int cdim, class GridImp >
105
inline void ALU2dGridGeometry< mydim, cdim, GridImp >::print ( std::ostream &out ) const
107
out << "ALU2dGridGeometry< " << mydim << ", " << cdim << " > = ";
109
for( int i = 0; i < corners(); ++i )
111
out << c << " (" << corner( i ) << ")";
114
out << " }" << std::endl;
118
///////////////////////////////////////////////////////////////////////
121
//! access to coordinates of corners. Index is the number of the corner
122
template< int mydim, int cdim, class GridImp >
123
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
124
ALU2dGridGeometry< mydim, cdim, GridImp >::corner ( int i ) const
126
return geoImpl().corner( i );
130
//! maps a local coordinate within reference element to
131
//! global coordinate in element
132
template< int mydim, int cdim, class GridImp >
133
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::GlobalCoordinate
134
ALU2dGridGeometry< mydim, cdim, GridImp >::global ( const LocalCoordinate &local ) const
136
GlobalCoordinate global;
137
geoImpl().map2world( local, global );
142
//! maps a global coordinate within the element to a
143
//! local coordinate in its reference element
144
template< int mydim, int cdim, class GridImp >
145
inline typename ALU2dGridGeometry< mydim, cdim, GridImp >::LocalCoordinate
146
ALU2dGridGeometry< mydim, cdim, GridImp >::local ( const GlobalCoordinate &global ) const
149
return LocalCoordinate( 1 );
151
LocalCoordinate local;
152
geoImpl().world2map( global, local );
157
template< int mydim, int cdim, class GridImp >
159
ALU2dGridGeometry< mydim, cdim, GridImp >::integrationElement ( const LocalCoordinate &local ) const
161
assert( geoImpl().valid() );
164
if( std::abs( geoImpl().det( local ) - jacobianTransposed( local
165
).determinant() ) > 1e-8 )
166
std::cout << "det = " << geoImpl().det( local ) << " inv.det " <<
167
jacobianTransposed( local ).determinant() << std::endl;
168
assert( std::abs( geoImpl().det( local ) - jacobianTransposed( local
169
).determinant() ) < 1e-8 );
171
return geoImpl().det( local );
175
template< int mydim, int cdim, class GridImp >
176
inline alu2d_ctype ALU2dGridGeometry< mydim, cdim, GridImp >::volume () const
178
assert( geoImpl().valid() );
179
return geoImpl().volume();
183
template< int mydim, int cdim, class GridImp >
184
inline const FieldMatrix<alu2d_ctype,mydim,cdim>&
185
ALU2dGridGeometry< mydim, cdim, GridImp>::jacobianTransposed ( const LocalCoordinate &local ) const
187
return geoImpl().jacobianTransposed( local );
191
template< int mydim, int cdim, class GridImp >
192
inline const FieldMatrix<alu2d_ctype,cdim,mydim>&
193
ALU2dGridGeometry< mydim, cdim, GridImp >::jacobianInverseTransposed ( const LocalCoordinate &local ) const
195
return geoImpl().jacobianInverseTransposed( local );
199
//! built Geometry for triangles
200
template< int mydim, int cdim, class GridImp >
202
ALU2dGridGeometry< mydim, cdim, GridImp >::buildGeom( const HElementType &item )
206
assert( mydim == 2 );
208
// update geometry impl
209
geoImpl().update( item );
216
//! built Geometry for edges
217
template <int mydim, int cdim, class GridImp>
218
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
219
buildGeom(const HElementType & item, const int aluFace)
221
assert( mydim == 1 );
223
const int nf = item.numfaces();
225
// for triangles face 1 is twisted and for quatrilaterals faces 1 and 2
226
const int twist = (nf == 3) ? (aluFace % 2) : (aluFace>>1)^(aluFace&1);
227
// std::cout << nf << " " << aluFace << " " << twist << std::endl;
228
// << " ( " item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
229
// << " , " item.getVertex( (aluFace + 2 - twist ) % nf )->coord()
230
// << " ) " << std::endl;
236
// update geometry impl
237
geoImpl().update( item.getVertex( (aluFace + 1 + twist ) % nf )->coord() ,
238
item.getVertex( (aluFace + 2 - twist ) % nf )->coord() ,
239
item.sidelength( aluFace )
246
//! built Geometry for vertices
247
template <int mydim, int cdim, class GridImp>
248
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
249
buildGeom(const VertexType & item , const int )
251
assert( mydim == 0 );
254
// update geometry impl
255
// volume is already 1.0
256
geoImpl().update( item.coord() );
263
template <int mydim, int cdim, class GridImp>
264
template <class GeometryType, class LocalGeometryType >
265
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
266
buildLocalGeom(const GeometryType &geo, const LocalGeometryType & localGeom)
269
geoImpl().updateLocal( geo, localGeom );
274
// built Geometry (faceNumber is in generic numbering)
275
template< int mydim, int cdim, class GridImp >
276
inline std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
277
ALU2dGridGeometry< mydim, cdim, GridImp >::calculateReferenceCoords ( const int corners )
279
// calculate reference coordinates of aLUGrid reference triangle
281
FieldMatrix< alu2d_ctype, 4, 2 > refCoord( 0. );
282
FieldVector< alu2d_ctype, 4 > lengths( 1. );
285
refCoord[1][0] = 1.0;
287
refCoord[corners-1][1] = 1.0;
290
lengths[0] = M_SQRT2;
295
refCoord[2][0] = 1.0;
296
refCoord[2][1] = 1.0;
298
return std::make_pair( refCoord, lengths );
301
// built Geometry (faceNumber is in generic numbering)
302
template <int mydim, int cdim, class GridImp>
303
inline bool ALU2dGridGeometry<mydim,cdim,GridImp>::
304
buildLocalGeometry(const int aluFace, const int twist, const int corners)
306
assert( twist == 0 || twist == 1 );
307
assert( mydim == 1 );
309
// get coordinates of reference element
310
typedef std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > > RefCoord;
311
RefCoord refCoord( calculateReferenceCoords( corners ) );
313
geoImpl().update( refCoord.first[ ( aluFace + 1+twist ) % corners ],
314
refCoord.first[ ( aluFace + 2-twist ) % corners ],
315
refCoord.second[ aluFace ]
323
template <int mydim, int cdim, class GridImp >
324
inline bool ALU2dGridGeometry<mydim, cdim,GridImp>::
325
buildGeomInFather(const Geometry & fatherGeom ,
326
const Geometry & myGeom)
329
geoImpl().updateLocal( fatherGeom, myGeom );
334
} //end namespace Dune
299
336
#endif // #ifndef DUNE_ALU2DGRID_GEOMETRYIMP_CC