3#ifndef DUNE_ALU3DGRIDGEOMETRY_HH
4#define DUNE_ALU3DGRIDGEOMETRY_HH
13#include "alu3dinclude.hh"
16#include <dune/grid/alugrid/common/objectfactory.hh>
22 template<
int cd,
int dim,
class Gr
idImp>
23 class ALU3dGridEntity;
24 template<
int cd,
class Gr
idImp >
25 class ALU3dGridEntityPointer;
26 template<
int mydim,
int coorddim,
class Gr
idImp>
27 class ALU3dGridGeometry;
28 template< ALU3dGr
idElementType,
class >
30 class BilinearSurfaceMapping;
31 class TrilinearMapping;
33 template<
class Gr
idImp >
34 class ALU3dGridIntersectionIterator;
37 class MyALUGridGeometryImplementation
40 typedef FieldVector<alu3d_ctype, cdim> CoordinateVectorType;
42 static const signed char invalid = -1;
43 static const signed char updated = 0;
44 static const signed char buildmapping = 1;
46 template <
int dim,
int corners,
class Mapping>
47 class GeometryImplBase
51 GeometryImplBase(
const GeometryImplBase& );
55 static const int corners_ = corners ;
58 typedef FieldMatrix<alu3d_ctype, corners , cdim> CoordinateMatrixType;
60 template <
int dummy,
int dimused>
61 struct CoordTypeExtractorType
63 typedef CoordinateMatrixType Type;
67 struct CoordTypeExtractorType< dummy, 3 >
69 typedef CoordinateMatrixType* Type;
72 typedef typename CoordTypeExtractorType< 0, dim > :: Type CoordinateStorageType ;
75 typedef Mapping MappingType;
78 CoordinateStorageType coord_ ;
87 mutable unsigned int refCount_;
111 void operator ++ () { ++ refCount_; }
114 void operator -- () { assert( refCount_ > 0 ); --refCount_; }
117 bool operator ! ()
const {
return refCount_ == 0; }
120 bool stillUsed ()
const {
return refCount_ > 1 ; }
123 template <
class CoordPtrType>
124 static inline void copy(
const CoordPtrType& p,
125 CoordinateVectorType& c)
133 template <
class CoordPtrType>
134 void update(
const CoordPtrType&,
141 const CoordPtrType& )
const
143 DUNE_THROW(InvalidStateException,
"This method should not be called!");
146 template <
class CoordPtrType>
147 void update(
const CoordPtrType&,
150 const CoordPtrType& )
const
152 DUNE_THROW(InvalidStateException,
"This method should not be called!");
155 template <
class CoordPtrType>
156 void update(
const CoordPtrType&,
158 const CoordPtrType& )
const
160 DUNE_THROW(InvalidStateException,
"This method should not be called!");
164 void invalidate () { status_ = invalid ; }
167 bool valid ()
const {
return status_ != invalid ; }
170 void setVolume(
const double volume ) { volume_ = volume ; }
173 double volume()
const {
return volume_; }
177 template <
int dummy,
int dim,
178 ALU3dGridElementType eltype>
class GeometryImpl;
181 template <
int dummy,
int dim, ALU3dGr
idElementType eltype>
182 class GeometryImpl :
public GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> >
184 typedef GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> > BaseType;
186 using BaseType :: corners_ ;
187 using BaseType :: copy ;
188 using BaseType :: coord_ ;
189 using BaseType :: map_ ;
190 using BaseType :: status_ ;
192 typedef typename BaseType :: MappingType MappingType ;
194 using BaseType :: update ;
195 using BaseType :: valid ;
201 assert( i>=0 && i<corners_ );
205 inline MappingType& mapping()
208 if( status_ == buildmapping )
return map_;
210 map_.buildMapping( coord_[0] );
211 status_ = buildmapping ;
216 template <
class CoordPtrType>
217 inline void update(
const CoordPtrType& p0)
219 assert( corners_ == 1 );
220 copy( p0, coord_[0] );
227 template <
int dummy, ALU3dGr
idElementType eltype>
229 :
public GeometryImplBase< 1, 2, LinearMapping<cdim, 1> >
232 typedef GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> > BaseType;
234 using BaseType :: corners_ ;
235 using BaseType :: copy ;
236 using BaseType :: coord_ ;
237 using BaseType :: map_ ;
238 using BaseType :: status_ ;
240 typedef typename BaseType :: MappingType MappingType;
242 using BaseType :: update ;
243 using BaseType :: valid ;
246 inline const CoordinateVectorType& operator [] (
const int i)
const
249 assert( i>=0 && i<corners_ );
253 inline MappingType& mapping()
256 if( status_ == buildmapping )
return map_;
258 map_.buildMapping( coord_[0], coord_[1] );
259 status_ = buildmapping ;
264 template <
class CoordPtrType>
265 inline void update(
const CoordPtrType& p0,
266 const CoordPtrType& p1)
268 assert( corners_ == 2 );
269 copy( p0, coord_[0] );
270 copy( p1, coord_[1] );
277 class GeometryImpl<dummy, 2, tetra>
278 :
public GeometryImplBase< 2, 3, LinearMapping<cdim, 2> >
281 typedef GeometryImplBase< 2, 3, LinearMapping<cdim, 2> > BaseType;
283 using BaseType :: corners_ ;
284 using BaseType :: copy ;
285 using BaseType :: coord_ ;
286 using BaseType :: map_ ;
287 using BaseType :: status_ ;
289 typedef typename BaseType :: MappingType MappingType ;
291 using BaseType :: update ;
292 using BaseType :: valid ;
295 inline const CoordinateVectorType& operator [] (
const int i)
const
298 assert( i>=0 && i<corners_ );
303 template <
class CoordPtrType>
304 inline void update(
const CoordPtrType& p0,
305 const CoordPtrType& p1,
306 const CoordPtrType& p2)
308 copy(p0, coord_[0] );
309 copy(p1, coord_[1] );
310 copy(p2, coord_[2] );
315 inline MappingType& mapping()
318 if( status_ == buildmapping )
return map_;
320 map_.buildMapping( coord_[0], coord_[1], coord_[2] );
321 status_ = buildmapping ;
334 class GeometryImpl<dummy, 2, hexa>
335 :
public GeometryImplBase< 2, 4, BilinearSurfaceMapping >
338 typedef GeometryImplBase< 2, 4, BilinearSurfaceMapping > BaseType;
340 using BaseType :: corners_ ;
341 using BaseType :: copy ;
342 using BaseType :: coord_ ;
343 using BaseType :: map_ ;
344 using BaseType :: status_ ;
346 typedef typename BaseType :: MappingType MappingType ;
348 using BaseType :: update ;
349 using BaseType :: valid ;
352 inline const CoordinateVectorType& operator [] (
const int i)
const
355 assert( i>=0 && i<corners_ );
360 template <
class CoordPtrType>
361 inline void update(
const CoordPtrType& p0,
362 const CoordPtrType& p1,
363 const CoordPtrType& p2,
364 const CoordPtrType& p3)
366 copy(p0, coord_[0] );
367 copy(p1, coord_[1] );
368 copy(p2, coord_[2] );
369 copy(p3, coord_[3] );
374 inline MappingType& mapping()
377 if( status_ == buildmapping )
return map_;
379 map_.buildMapping( coord_[0], coord_[1], coord_[2], coord_[3] );
380 status_ = buildmapping ;
387 class GeometryImpl<dummy,3, hexa>
388 :
public GeometryImplBase< 3, 8, TrilinearMapping >
391 typedef GeometryImplBase< 3, 8, TrilinearMapping > BaseType;
393 using BaseType :: corners_ ;
394 using BaseType :: copy ;
395 using BaseType :: coord_ ;
396 using BaseType :: map_ ;
397 using BaseType :: status_ ;
399 typedef typename BaseType :: MappingType MappingType ;
400 typedef typename BaseType :: CoordinateMatrixType CoordinateMatrixType;
402 typedef alu3d_ctype CoordPtrType[cdim];
405 const alu3d_ctype* coordPtr_[ corners_ ];
407 using BaseType :: update ;
408 using BaseType :: valid ;
411 GeometryImpl() : BaseType()
414 for(
int i=0; i<corners_; ++i )
421 if( coord_ )
delete coord_;
424 const alu3d_ctype* point(
const int i )
const
427 assert( i>=0 && i<corners_ );
428 assert( coordPtr_[i] );
429 return coordPtr_[ i ];
433 inline CoordinateVectorType operator [] (
const int i)
const
435 CoordinateVectorType coord ;
436 copy( point( i ), coord );
441 inline void update(
const CoordPtrType& p0,
442 const CoordPtrType& p1,
443 const CoordPtrType& p2,
444 const CoordPtrType& p3,
445 const CoordPtrType& p4,
446 const CoordPtrType& p5,
447 const CoordPtrType& p6,
448 const CoordPtrType& p7)
450 coordPtr_[0] = &p0[ 0 ];
451 coordPtr_[1] = &p1[ 0 ];
452 coordPtr_[2] = &p2[ 0 ];
453 coordPtr_[3] = &p3[ 0 ];
454 coordPtr_[4] = &p4[ 0 ];
455 coordPtr_[5] = &p5[ 0 ];
456 coordPtr_[6] = &p6[ 0 ];
457 coordPtr_[7] = &p7[ 0 ];
462 template <
class GeometryImp>
463 inline void updateInFather(
const GeometryImp &fatherGeom ,
464 const GeometryImp &myGeom)
468 coord_ =
new CoordinateMatrixType();
471 CoordinateMatrixType& coord = *coord_;
473 for(
int i=0; i < myGeom.corners() ; ++i)
476 coord[i] = fatherGeom.local( myGeom.corner( i ) );
479 coordPtr_[i] = (&(coord[i][0]));
482 for(
int j=0; j<cdim; ++j)
484 if ( coord[i][j] < 1e-16) coord[i][j] = 0.0;
492 inline MappingType& mapping()
495 if( status_ == buildmapping )
return map_;
497 map_.buildMapping( point( 0 ), point( 1 ), point( 2 ), point( 3 ),
498 point( 4 ), point( 5 ), point( 6 ), point( 7 ) );
500 status_ = buildmapping;
505 void invalidate () { status_ = invalid ; }
508 bool valid ()
const {
return status_ != invalid ; }
514 class GeometryImpl<dummy,3, tetra>
515 :
public GeometryImplBase< 3, 4, LinearMapping<cdim, cdim> >
518 typedef GeometryImplBase< 3, 4, LinearMapping<cdim, cdim> > BaseType;
520 using BaseType :: corners_ ;
521 using BaseType :: copy ;
522 using BaseType :: coord_ ;
523 using BaseType :: map_ ;
524 using BaseType :: status_ ;
526 typedef typename BaseType :: MappingType MappingType ;
527 typedef typename BaseType :: CoordinateMatrixType CoordinateMatrixType;
529 typedef alu3d_ctype CoordPtrType[cdim];
532 const alu3d_ctype* coordPtr_[ corners_ ];
534 using BaseType :: update ;
535 using BaseType :: valid ;
538 GeometryImpl() : BaseType()
541 for(
int i=0; i<corners_; ++i )
548 if( coord_ )
delete coord_;
551 const alu3d_ctype* point(
const int i )
const
554 assert( i>=0 && i<corners_ );
555 assert( coordPtr_[ i ] );
556 return coordPtr_[ i ];
560 inline CoordinateVectorType operator [] (
const int i)
const
562 CoordinateVectorType coord ;
563 copy( point( i ), coord );
568 inline void update(
const CoordPtrType& p0,
569 const CoordPtrType& p1,
570 const CoordPtrType& p2,
571 const CoordPtrType& p3)
573 coordPtr_[0] = &p0[ 0 ];
574 coordPtr_[1] = &p1[ 0 ];
575 coordPtr_[2] = &p2[ 0 ];
576 coordPtr_[3] = &p3[ 0 ];
581 template <
class GeometryImp>
582 inline void updateInFather(
const GeometryImp &fatherGeom ,
583 const GeometryImp & myGeom)
587 coord_ =
new CoordinateMatrixType();
590 CoordinateMatrixType& coord = *coord_;
592 for(
int i=0; i < myGeom.corners() ; ++i)
595 coord[i] = fatherGeom.local( myGeom.corner( i ) );
598 coordPtr_[i] = (&(coord[i][0]));
601 for(
int j=0; j<cdim; ++j)
603 if ( coord[i][j] < 1e-16) coord[i][j] = 0.0;
611 inline MappingType& mapping()
614 if( status_ == buildmapping )
return map_;
616 map_.buildMapping( point( 0 ), point( 1 ), point( 2 ), point( 3 ) );
618 status_ = buildmapping;
624 template <
int mydim,
int cdim,
class Gr
idImp>
625 class ALU3dGridGeometry :
626 public GeometryDefaultImplementation<mydim, cdim, GridImp, ALU3dGridGeometry>
628 static const ALU3dGridElementType elementType = GridImp::elementType;
630 typedef typename GridImp::MPICommunicatorType Comm;
632 friend class ALU3dGridIntersectionIterator<GridImp>;
634 typedef typename ALU3dImplTraits< elementType, Comm >::IMPLElementType IMPLElementType;
635 typedef typename ALU3dImplTraits< elementType, Comm >::GEOFaceType GEOFaceType;
636 typedef typename ALU3dImplTraits< elementType, Comm >::GEOEdgeType GEOEdgeType;
637 typedef typename ALU3dImplTraits< elementType, Comm >::GEOVertexType GEOVertexType;
640 typedef typename ALU3dImplTraits< elementType, Comm >::HFaceType HFaceType;
641 typedef typename ALU3dImplTraits< elementType, Comm >::HEdgeType HEdgeType;
642 typedef typename ALU3dImplTraits< elementType, Comm >::VertexType VertexType;
644 typedef ElementTopologyMapping<elementType> ElementTopo;
645 typedef FaceTopologyMapping<elementType> FaceTopo;
647 enum { corners_ = (elementType == hexa) ? StaticPower<2,mydim>::power : mydim+1 };
650 typedef typename MyALUGridGeometryImplementation<cdim> ::
651 template GeometryImpl<0, mydim, elementType > GeometryImplType;
654 typedef typename GridImp :: ctype ctype;
657 typedef FieldVector<ctype, mydim> LocalCoordinate;
660 typedef FieldVector<ctype, cdim > GlobalCoordinate;
663 typedef FieldMatrix<ctype,cdim,mydim> JacobianInverseTransposed;
669 typedef FieldMatrix<ctype,
670 EntityCount< elementType > :: numVerticesPerFace , 3> FaceCoordinatesType;
677 ALU3dGridGeometry(
const ALU3dGridGeometry& );
680 ALU3dGridGeometry& operator = (
const ALU3dGridGeometry& );
683 ~ALU3dGridGeometry( );
690 int corners ()
const;
693 GlobalCoordinate corner (
int i)
const;
697 GlobalCoordinate global (
const LocalCoordinate& local)
const;
701 LocalCoordinate local (
const GlobalCoordinate& global)
const;
704 ctype integrationElement (
const LocalCoordinate& local)
const;
708 const JacobianInverseTransposed &jacobianInverseTransposed (
const LocalCoordinate& local)
const;
711 const JacobianTransposed& jacobianTransposed (
const LocalCoordinate& local)
const;
714 inline bool affine ()
const;
717 ctype volume ()
const;
723 bool buildGeom(
const IMPLElementType & item);
724 bool buildGeom(
const HFaceType & item,
int twist,
int faceNum);
725 bool buildGeom(
const HEdgeType & item,
int twist,
int);
726 bool buildGeom(
const VertexType & item,
int twist,
int);
729 bool buildGeom(
const FaceCoordinatesType& coords);
732 template <
class coord_t>
733 bool buildGeom(
const coord_t& p0,
739 template <
class coord_t>
740 bool buildGeom(
const coord_t& p0,
745 template <
class GeometryType>
746 bool buildGeomInFather(
const GeometryType &fatherGeom ,
const GeometryType & myGeom);
750 void print (std::ostream& ss)
const;
756 bool valid ()
const ;
760 void assign(
const ALU3dGridGeometry& other );
767 typedef ALUMemoryProvider< GeometryImplType > GeometryProviderType ;
770 static GeometryProviderType& geoProvider()
772#ifdef USE_SMP_PARALLEL
773 typedef ALUGridObjectFactory< GridImp > GridObjectFactoryType;
774 static std::vector< GeometryProviderType > storage( GridObjectFactoryType :: maxThreads() );
775 return storage[ GridObjectFactoryType :: threadNumber () ];
777 static GeometryProviderType storage;
783 GeometryImplType& geoImpl()
const
790 GeometryImplType* geoImpl_;
795#include "geometry_imp.cc"
vector space out of a tensor product of fields.
Definition: fvector.hh:94
general type of geometry implementation
Definition: geometry.hh:183
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
Various implementations of the power function for run-time and static arguments.