3 #ifndef DUNE_ALU2DGRIDGEOMETRY_HH
4 #define DUNE_ALU2DGRIDGEOMETRY_HH
8 #include <dune/geometry/genericgeometry/topologytypes.hh>
18 template<
int cd,
int dim,
class Gr
idImp>
19 class ALU2dGridEntity;
20 template<
int cd,
class Gr
idImp >
21 class ALU2dGridEntityPointer;
22 template<
int mydim,
int cdim,
class Gr
idImp>
23 class ALU2dGridGeometry;
24 template<
int dim,
int dimworld, ALU2DSPACE ElementType eltype >
28 template<
int mydim,
int cdim, ALU2DSPACE ElementType eltype >
29 class MyALU2dGridGeometryImpl;
31 template <
int ncorners,
class Mapping>
54 enum { mydim = ncorners < 3 ? ncorners-1 : 2 };
139 return mapping().map2world( m, w );
145 return mapping().world2map( w, m );
151 return mapping().jacobianTransposed( m );
157 return mapping().jacobianInverseTransposed( m );
165 template<
int cdim, ALU2DSPACE ElementType eltype >
166 class MyALU2dGridGeometryImpl< 0, cdim, eltype >
171 using BaseType :: mapping_ ;
172 using BaseType :: valid_ ;
175 using BaseType :: valid ;
176 using BaseType :: invalidate ;
177 using BaseType :: corners ;
189 GenericGeometry :: SimplexTopology< 0 > :: type :: id :
190 GenericGeometry :: CubeTopology < 0 > :: type :: id),
195 template<
class Vector >
196 void update (
const Vector &p0 )
198 mapping_.buildMapping( p0 );
207 template<
int cdim, ALU2DSPACE ElementType eltype >
208 class MyALU2dGridGeometryImpl< 1, cdim, eltype >
213 using BaseType :: mapping_ ;
214 using BaseType :: valid_ ;
215 using BaseType :: volume_ ;
216 using BaseType :: corners_ ;
219 using BaseType :: valid ;
220 using BaseType :: invalidate ;
221 using BaseType :: corners ;
233 GenericGeometry :: SimplexTopology< 1 > :: type :: id :
234 GenericGeometry :: CubeTopology < 1 > :: type :: id),
239 template<
class Geo,
class LocalGeo >
240 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
242 assert( localGeo.corners() == corners_ );
244 FieldMatrix< alu2d_ctype, corners_, cdim > coord;
245 for(
int i = 0; i < corners_; ++i )
248 coord[ i ] = geo.local( localGeo.corner( i ) );
250 for(
int j = 0; j < cdim; ++j )
251 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
253 mapping_.buildMapping( coord[ 0 ], coord[ 1 ] );
254 volume_ = mapping_.det(
map_t(0.25) );
259 template<
class Vector >
260 void update (
const Vector &p0,
const Vector &p1,
const double volume )
262 mapping_.buildMapping( p0, p1 );
278 using BaseType :: mapping_ ;
279 using BaseType :: valid_ ;
280 using BaseType :: volume_ ;
281 using BaseType :: corners_ ;
282 using BaseType :: referenceElement_;
285 using BaseType :: valid ;
286 using BaseType :: invalidate ;
287 using BaseType :: corners ;
296 assert(
std::abs( referenceElement_.volume() - 0.5 ) < 1e-10 );
301 return GeometryType( GenericGeometry :: SimplexTopology< 2 > :: type :: id , 2 );
305 template<
class Geo,
class LocalGeo >
306 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
308 assert( localGeo.corners() == corners_ );
310 FieldMatrix< alu2d_ctype, corners_, cdim > coord;
311 for(
int i = 0; i < corners_; ++i )
314 coord[ i ] = geo.local( localGeo.corner( i ) );
316 for(
int j = 0; j < cdim; ++j )
317 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
319 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
321 volume_ = referenceElement_.volume() * ( localGeo.volume() / geo.volume() );
322 assert( (volume_ > 0.0) && (volume_ < referenceElement_.volume() ) );
326 template<
class HElement >
327 void update (
const HElement &item )
329 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
330 item.getVertex( 2 )->coord() );
331 volume_ = item.area();
338 return 2.0 * volume_ ;
349 using BaseType :: mapping_ ;
350 using BaseType :: valid_ ;
351 using BaseType :: volume_ ;
352 using BaseType :: corners_ ;
353 using BaseType :: referenceElement_;
356 using BaseType :: valid ;
357 using BaseType :: invalidate ;
358 using BaseType :: corners ;
365 return GeometryType( GenericGeometry :: CubeTopology< 2 > :: type :: id, 2 ) ;
369 template<
class Geo,
class LocalGeo >
370 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
372 assert( localGeo.corners() == corners_ );
374 FieldMatrix< alu2d_ctype, corners_, cdim > coord;
375 for(
int i = 0; i < corners_; ++i )
378 coord[ i ] = geo.local( localGeo.corner( i ) );
380 for(
int j = 0; j < cdim; ++j )
381 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
383 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
384 volume_ = referenceElement_.volume() * ( localGeo.volume() / geo.volume() );
385 assert( (volume_ > 0.0) && (volume_ < referenceElement_.volume() ) );
389 template<
class HElement >
390 void update (
const HElement &item )
392 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
393 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
394 volume_ = item.area();
409 using BaseType :: mapping_ ;
410 using BaseType :: volume_ ;
411 using BaseType :: valid_ ;
412 using BaseType :: referenceElement_ ;
431 using BaseType :: valid ;
432 using BaseType :: invalidate ;
435 MyALU2dGridGeometryImpl ()
437 simplexReferenceElement_( ReferenceElements<
ctype, 2 >::general( type( 3 ) ) ),
448 return (corners() == 3 ? linearMapping().affine() : bilinearMapping().affine());
459 linearMapping().map2world( simplexReferenceElement_.position( i, 2 ), coordinate );
461 bilinearMapping().map2world( referenceElement_.position( i, 2 ), coordinate );
473 GenericGeometry :: SimplexTopology< 2 > :: type :: id :
474 GenericGeometry :: CubeTopology < 2 > :: type :: id), 2);
481 linearMapping().map2world( m, w );
483 bilinearMapping().map2world( m, w );
489 linearMapping().world2map( w, m );
491 bilinearMapping().world2map( w, m );
496 return (corners() == 3 ? linearMapping().jacobianTransposed( m ) : bilinearMapping().jacobianTransposed( m ));
499 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
501 return (corners() == 3 ? linearMapping().jacobianInverseTransposed( m ) : bilinearMapping().jacobianInverseTransposed( m ));
506 return (corners() == 3 ? linearMapping().det( m ) : bilinearMapping().det( m ));
510 template<
class Geo,
class LocalGeo >
511 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
513 const int corners = localGeo.corners();
516 FieldMatrix< alu2d_ctype, 4, cdim > coord;
517 for(
int i = 0; i < corners; ++i )
520 coord[ i ] = geo.local( localGeo.corner( i ) );
522 for(
int j = 0; j < cdim; ++j )
523 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
526 updateMapping( corners );
529 linearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
530 volume_ = simplexReferenceElement_.volume() * ( localGeo.volume() / geo.volume() );
534 bilinearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
535 volume_ = referenceElement_.volume() * ( localGeo.volume() / geo.volume() );
538 assert( (volume_ > 0.0) && (volume_ < 1.0) );
542 template<
class HElement >
543 void update (
const HElement &item )
545 const int corners = item.numvertices();
546 updateMapping( corners );
548 linearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
549 item.getVertex( 2 )->coord() );
551 bilinearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
552 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
554 volume_ = item.area();
559 MyALU2dGridGeometryImpl &operator= (
const MyALU2dGridGeometryImpl &other );
561 const LinearMappingType &linearMapping ()
const
564 return static_cast< const LinearMappingType *
>( &mapping_ );
567 LinearMappingType &linearMapping ()
570 return static_cast< LinearMappingType *
>( &mapping_ );
573 const BilinearMappingType &bilinearMapping ()
const
576 return static_cast< const BilinearMappingType *
>( &mapping_ );
579 BilinearMappingType &bilinearMapping ()
582 return static_cast< BilinearMappingType *
>( &mapping_ );
585 void updateMapping (
const int corners )
587 assert( (corners == 3) || (corners == 4) );
588 if( corners != myCorners_ )
591 corners = myCorners_;
593 new( &mapping_ )LinearMappingType;
595 new( &mapping_ )BilinearMappingType;
599 void destroyMapping ()
602 linearMapping().~LinearMappingType();
603 else if( corners() == 4 )
604 bilinearMapping().~BilinearMappingType();
628 template<
int mydim,
int cdim,
class Gr
idImp >
635 typedef typename GridImp::template Codim<0>::Geometry Geometry;
639 enum { dimbary=mydim+1};
642 typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, eltype >::Type VertexType;
645 typedef MyALU2dGridGeometryImpl< mydim, cdim, eltype > GeometryImplType;
703 bool buildGeom(
const HElementType & item);
705 bool buildGeom(
const HElementType & item,
const int aluFace);
707 bool buildGeom(
const VertexType & item,
const int );
711 template <
class GeometryType,
class LocalGeomType >
721 void print (std::ostream& ss)
const;
735 static std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
751 #ifdef USE_SMP_PARALLEL
753 static std::vector< GeometryProviderType > storage( GridObjectFactoryType :: maxThreads() );
754 return storage[ GridObjectFactoryType :: threadNumber () ];
772 namespace FacadeOptions
775 template<
int mydim,
int cdim,
class Gr
idImp >
779 static const bool v =
false;
785 #include "geometry_imp.cc"