3#ifndef DUNE_ALU2DGRIDGEOMETRY_HH
4#define DUNE_ALU2DGRIDGEOMETRY_HH
8#include <dune/geometry/genericgeometry/topologytypes.hh>
10#include <dune/grid/alugrid/2d/alu2dinclude.hh>
11#include <dune/grid/alugrid/3d/mappings.hh>
12#include <dune/grid/alugrid/common/memory.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>
32 class MyALU2dGridGeometryImplBase
36 MyALU2dGridGeometryImplBase(
const MyALU2dGridGeometryImplBase& );
40 static const int corners_ = ncorners ;
43 typedef Mapping MappingType;
45 typedef typename MappingType::ctype ctype;
47 typedef typename MappingType::map_t map_t;
48 typedef typename MappingType::world_t world_t;
50 typedef typename MappingType::matrix_t matrix_t;
51 typedef typename MappingType::inv_t inv_t;
54 enum { mydim = ncorners < 3 ? ncorners-1 : 2 };
55 typedef ReferenceElement< ctype, mydim > ReferenceElementType ;
61 const ReferenceElementType& referenceElement_ ;
67 mutable unsigned int refCount_;
72 const MappingType& mapping()
const
80 MyALU2dGridGeometryImplBase(
const GeometryType type )
82 referenceElement_( ReferenceElements< ctype, mydim >::general( type ) ),
98 void operator ++ () { ++ refCount_; }
101 void operator -- () { assert( refCount_ > 0 ); --refCount_; }
104 bool operator ! ()
const {
return refCount_ == 0; }
107 bool stillUsed ()
const {
return refCount_ > 1 ; }
110 void invalidate () { valid_ = false ; }
113 bool valid ()
const {
return valid_; }
116 double volume()
const {
return volume_; }
122 return mapping().affine();
126 int corners ()
const {
return corners_ ; }
129 world_t corner(
int i )
const
132 map2world( referenceElement_.position( i, mydim ), coordinate );
137 void map2world (
const map_t &m, world_t &w )
const
139 return mapping().map2world( m, w );
143 void world2map (
const world_t &w, map_t &m )
const
145 return mapping().world2map( w, m );
149 const matrix_t &jacobianTransposed (
const map_t &m )
const
151 return mapping().jacobianTransposed( m );
155 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
157 return mapping().jacobianInverseTransposed( m );
161 ctype det (
const map_t &m )
const {
return mapping().det( m ); }
165 template<
int cdim, ALU2DSPACE ElementType eltype >
166 class MyALU2dGridGeometryImpl< 0, cdim, eltype >
167 :
public MyALU2dGridGeometryImplBase< 1, LinearMapping< cdim, 0 > >
169 typedef MyALU2dGridGeometryImplBase< 1, LinearMapping< cdim, 0 > > BaseType;
171 using BaseType :: mapping_ ;
172 using BaseType :: valid_ ;
175 using BaseType :: valid ;
176 using BaseType :: invalidate ;
177 using BaseType :: corners ;
179 typedef typename BaseType :: ctype ctype ;
180 typedef typename BaseType :: map_t map_t ;
183 MyALU2dGridGeometryImpl () : BaseType( type() ) {}
188 (eltype == ALU2DSPACE triangle ?
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 );
203 ctype det (
const map_t &m )
const {
return 1.0; }
207 template<
int cdim, ALU2DSPACE ElementType eltype >
208 class MyALU2dGridGeometryImpl< 1, cdim, eltype >
209 :
public MyALU2dGridGeometryImplBase< 2, LinearMapping< cdim, 1 > >
211 typedef MyALU2dGridGeometryImplBase< 2, LinearMapping< cdim, 1 > > BaseType;
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 ;
223 typedef typename BaseType :: ctype ctype ;
224 typedef typename BaseType :: map_t map_t ;
227 MyALU2dGridGeometryImpl () : BaseType( type() ) {}
232 (eltype == ALU2DSPACE triangle ?
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 );
268 ctype det (
const map_t &m )
const {
return volume_; }
273 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE triangle >
274 :
public MyALU2dGridGeometryImplBase< 3, LinearMapping< cdim, 2 > >
276 typedef MyALU2dGridGeometryImplBase< 3, LinearMapping< cdim, 2 > > BaseType;
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 ;
289 typedef typename BaseType :: ctype ctype ;
290 typedef typename BaseType :: map_t map_t ;
293 MyALU2dGridGeometryImpl () : BaseType( type() )
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();
336 ctype det (
const map_t &m )
const
338 return 2.0 * volume_ ;
344 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE quadrilateral >
345 :
public MyALU2dGridGeometryImplBase< 4, BilinearMapping< cdim > >
347 typedef MyALU2dGridGeometryImplBase< 4, BilinearMapping< cdim > > BaseType;
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 ;
361 MyALU2dGridGeometryImpl () : BaseType( type() ) {}
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();
401 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE mixed >
402 :
public MyALU2dGridGeometryImplBase< 4, BilinearMapping< cdim > >
404 typedef MyALU2dGridGeometryImplBase< 4, BilinearMapping< cdim > > BaseType;
406 typedef typename BaseType :: MappingType BilinearMappingType;
407 typedef Dune :: LinearMapping< cdim, 2 > LinearMappingType;
409 using BaseType :: mapping_ ;
410 using BaseType :: volume_ ;
411 using BaseType :: valid_ ;
412 using BaseType :: referenceElement_ ;
414 typedef typename LinearMappingType::ctype ctype;
416 typedef typename LinearMappingType::map_t map_t;
417 typedef typename LinearMappingType::world_t world_t;
419 typedef typename LinearMappingType::matrix_t matrix_t;
420 typedef typename LinearMappingType::inv_t inv_t;
422 typedef typename BaseType :: ReferenceElementType ReferenceElementType;
425 const ReferenceElementType& simplexReferenceElement_ ;
431 using BaseType :: valid ;
432 using BaseType :: invalidate ;
435 MyALU2dGridGeometryImpl ()
436 : BaseType( type( 4 ) ),
437 simplexReferenceElement_( ReferenceElements< ctype, 2 >::general( type( 3 ) ) ),
441 assert(
sizeof( BilinearMappingType ) >=
sizeof( LinearMappingType ) );
448 return (corners() == 3 ? linearMapping().affine() : bilinearMapping().affine());
452 int corners ()
const {
return myCorners_; }
455 world_t corner(
int i )
const
459 linearMapping().map2world( simplexReferenceElement_.position( i, 2 ), coordinate );
461 bilinearMapping().map2world( referenceElement_.position( i, 2 ), coordinate );
466 GeometryType type ()
const {
return type( corners() ); }
473 GenericGeometry :: SimplexTopology< 2 > :: type :: id :
474 GenericGeometry :: CubeTopology < 2 > :: type :: id), 2);
478 void map2world (
const map_t &m, world_t &w )
const
481 linearMapping().map2world( m, w );
483 bilinearMapping().map2world( m, w );
486 void world2map (
const world_t &w, map_t &m )
const
489 linearMapping().world2map( w, m );
491 bilinearMapping().world2map( w, m );
494 const matrix_t &jacobianTransposed (
const map_t &m )
const
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 ));
504 ctype det (
const map_t &m )
const
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 >
632 static const ALU2DSPACE ElementType eltype = GridImp::elementType;
635 typedef typename GridImp::template Codim<0>::Geometry Geometry;
639 enum { dimbary=mydim+1};
641 typedef typename ALU2dImplTraits< GridImp::dimensionworld, eltype >::HElementType HElementType ;
642 typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, eltype >::Type VertexType;
645 typedef MyALU2dGridGeometryImpl< mydim, cdim, eltype > GeometryImplType;
670 int corners ()
const {
return geoImpl().corners(); }
690 bool affine()
const {
return geoImpl().affine(); }
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;
725 const Geometry & myGeom );
728 inline bool valid()
const {
return geoImpl().valid(); }
736 calculateReferenceCoords (
const int corners );
751#ifdef USE_SMP_PARALLEL
752 typedef ALUGridObjectFactory< GridImp > GridObjectFactoryType;
753 static std::vector< GeometryProviderType > storage( GridObjectFactoryType :: maxThreads() );
754 return storage[ GridObjectFactoryType :: threadNumber () ];
762 GeometryImplType& geoImpl()
const
769 GeometryImplType* geoImpl_;
772 namespace FacadeOptions
775 template<
int mydim,
int cdim,
class Gr
idImp >
779 static const bool v =
false;
785#include "geometry_imp.cc"
Definition: geometry.hh:631
const FieldMatrix< alu2d_ctype, mydim, cdim > & jacobianTransposed(const LocalCoordinate &local) const
jacobian transposed
GlobalCoordinate global(const LocalCoordinate &local) const
int corners() const
return the number of corners of this element. Corners are numbered 0...n-1
Definition: geometry.hh:670
const GeometryType type() const
Definition: geometry.hh:667
bool buildGeomInFather(const Geometry &fatherGeom, const Geometry &myGeom)
build geometry with local coords of child in reference element
bool buildLocalGeometry(const int faceNumber, const int twist, const int coorns)
build local geometry given local face number
void print(std::ostream &ss) const
print internal data
void removeObj()
remove pointer object
GlobalCoordinate corner(int i) const
access to coordinates of corners. Index is the number of the corner
alu2d_ctype integrationElement(const LocalCoordinate &local) const
A(l) , see grid.hh.
GlobalCoordinate & getCoordVec(int i)
return non-const reference to coord vecs
void getObject()
get a new pointer object
const FieldMatrix< alu2d_ctype, cdim, mydim > & jacobianInverseTransposed(const LocalCoordinate &local) const
jacobian inverse transposed
bool buildGeom(const HElementType &item)
Methods that not belong to the Interface, but have to be public.
ALU2dGridGeometry & operator=(const ALU2dGridGeometry &)
assigment operator
bool buildLocalGeom(const GeometryType &geo, const LocalGeomType &lg)
static GeometryProviderType & geoProvider()
return storage provider for geometry objects
Definition: geometry.hh:749
bool affine() const
return true if geometry has affine mapping
Definition: geometry.hh:690
~ALU2dGridGeometry()
destructor releasing object
ALU2dGridGeometry(const ALU2dGridGeometry &)
copy constructor copying pointer and increasing reference counter
alu2d_ctype volume() const
return volume of geometry
void assign(const ALU2dGridGeometry &other)
assign pointer
organize the memory management for entitys used by the NeighborIterator
Definition: memory.hh:21
A dense n x m matrix.
Definition: fmatrix.hh:67
vector space out of a tensor product of fields.
Definition: fvector.hh:92
Default implementation for class Geometry.
Definition: geometry.hh:322
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dune namespace.
Definition: alignment.hh:14
Traits class determining whether the Dune::Geometry facade class stores the implementation object by ...
Definition: geometry.hh:47
static const bool v
Whether to store by reference.
Definition: geometry.hh:49