1#ifndef DUNE_ALU3DGRIDGEOMETRY_HH
2#define DUNE_ALU3DGRIDGEOMETRY_HH
14#include "alu3dinclude.hh"
17#include <dune/alugrid/common/memory.hh>
23 template<
int cd,
int dim,
class Gr
idImp>
24 class ALU3dGridEntity;
25 template<
int cd,
class Gr
idImp >
26 class ALU3dGridEntityPointer;
27 template<
int mydim,
int coorddim,
class Gr
idImp>
28 class ALU3dGridGeometry;
29 template<
int dim,
int dimworld, ALU3dGr
idElementType,
class >
31 class BilinearSurfaceMapping;
32 class TrilinearMapping;
34 template<
class Gr
idImp >
35 class ALU3dGridIntersectionIterator;
38 class MyALUGridGeometryImplementation
41 typedef FieldVector<alu3d_ctype, cdim> CoordinateVectorType;
43 static const signed char invalid = -1;
44 static const signed char updated = 0;
45 static const signed char buildmapping = 1;
47 template <
int dim,
int corners,
class Mapping>
48 class GeometryImplBase
52 GeometryImplBase(
const GeometryImplBase& );
56 static const int corners_ = corners ;
59 typedef FieldMatrix<alu3d_ctype, corners , cdim> CoordinateMatrixType;
62 typedef typename std::conditional<
64 std::unique_ptr< CoordinateMatrixType >,
65 CoordinateMatrixType >:: type CoordinateStorageType;
68 typedef Mapping MappingType;
71 CoordinateStorageType coord_ ;
84 unsigned int refCount_;
96 template <
class CoordPtrType>
97 static inline void copy(
const CoordPtrType& p,
98 CoordinateVectorType& c)
101 alugrid_assert( cdim > 1 );
108 template <
class CoordPtrType>
109 void update(
const CoordPtrType&,
116 const CoordPtrType& )
const
118 DUNE_THROW(InvalidStateException,
"This method should not be called!");
121 template <
class CoordPtrType>
122 void update(
const CoordPtrType&,
125 const CoordPtrType& )
const
127 DUNE_THROW(InvalidStateException,
"This method should not be called!");
130 template <
class CoordPtrType>
131 void update(
const CoordPtrType&,
133 const CoordPtrType& )
const
135 DUNE_THROW(InvalidStateException,
"This method should not be called!");
138 template <
class CoordPtrType>
139 void update(
const CoordPtrType&,
140 const CoordPtrType& )
const
142 DUNE_THROW(InvalidStateException,
"This method should not be called!");
145 template <
class CoordPtrType>
146 void update(
const CoordPtrType& )
const
148 DUNE_THROW(InvalidStateException,
"This method should not be called!");
152 template <
class GeometryImp>
153 inline void updateInFather(
const GeometryImp &fatherGeom ,
154 const GeometryImp &myGeom)
157 alugrid_assert( dim == 2 );
160 for(
int i=0; i < myGeom.corners() ; ++i)
163 coord_[i] = fatherGeom.local( myGeom.corner( i ) );
166 for(
int j=0; j<cdim; ++j)
168 if ( coord_[i][j] < 1e-16) coord_[i][j] = 0.0;
176 void invalidate () { status_ = invalid ; }
179 bool valid ()
const {
return status_ != invalid ; }
182 void setVolume(
const double volume ) { volume_ = volume ; }
185 double volume()
const {
return volume_; }
189 template <
int dummy,
int dim,
190 ALU3dGridElementType eltype>
class GeometryImpl;
193 template <
int dummy,
int dim, ALU3dGr
idElementType eltype>
194 class GeometryImpl :
public GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> >
197 typedef GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> > BaseType;
199 using BaseType :: corners_ ;
200 using BaseType :: copy ;
201 using BaseType :: coord_ ;
202 using BaseType :: map_ ;
203 using BaseType :: status_ ;
205 typedef typename BaseType :: MappingType MappingType ;
207 using BaseType :: update ;
208 using BaseType :: valid ;
213 alugrid_assert ( valid() );
214 alugrid_assert ( i>=0 && i<corners_ );
218 inline MappingType& mapping()
220 alugrid_assert ( valid() );
221 if( status_ == buildmapping )
return map_;
223 map_.buildMapping( coord_[0] );
224 status_ = buildmapping ;
229 template <
class CoordPtrType>
230 inline void update(
const CoordPtrType& p0)
232 alugrid_assert ( corners_ == 1 );
233 copy( p0, coord_[0] );
240 template <
int dummy, ALU3dGr
idElementType eltype>
242 :
public GeometryImplBase< 1, 2, LinearMapping<cdim, 1> >
246 typedef GeometryImplBase< dim, dim+1, LinearMapping<cdim, dim> > BaseType;
248 using BaseType :: corners_ ;
249 using BaseType :: copy ;
250 using BaseType :: coord_ ;
251 using BaseType :: map_ ;
252 using BaseType :: status_ ;
254 typedef typename BaseType :: MappingType MappingType;
256 using BaseType :: update ;
257 using BaseType :: valid ;
260 inline const CoordinateVectorType& operator [] (
const int i)
const
262 alugrid_assert ( valid() );
263 alugrid_assert ( i>=0 && i<corners_ );
267 inline MappingType& mapping()
269 alugrid_assert ( valid() );
270 if( status_ == buildmapping )
return map_;
272 map_.buildMapping( coord_[0], coord_[1] );
273 status_ = buildmapping ;
278 template <
class CoordPtrType>
279 inline void update(
const CoordPtrType& p0,
280 const CoordPtrType& p1)
282 alugrid_assert ( corners_ == 2 );
283 copy( p0, coord_[0] );
284 copy( p1, coord_[1] );
291 class GeometryImpl<dummy, 2, tetra>
292 :
public GeometryImplBase< 2, 3, LinearMapping<cdim, 2> >
296 typedef GeometryImplBase< 2, 3, LinearMapping<cdim, 2> > BaseType;
298 using BaseType :: corners_ ;
299 using BaseType :: copy ;
300 using BaseType :: coord_ ;
301 using BaseType :: map_ ;
302 using BaseType :: status_ ;
304 typedef typename BaseType :: MappingType MappingType ;
306 using BaseType :: update ;
307 using BaseType :: valid ;
310 inline const CoordinateVectorType& operator [] (
const int i)
const
312 alugrid_assert ( valid() );
313 alugrid_assert ( i>=0 && i<corners_ );
318 template <
class CoordPtrType>
319 inline void update(
const CoordPtrType& p0,
320 const CoordPtrType& p1,
321 const CoordPtrType& p2)
323 copy(p0, coord_[0] );
324 copy(p1, coord_[1] );
325 copy(p2, coord_[2] );
330 inline MappingType& mapping()
332 alugrid_assert ( valid() );
333 if( status_ == buildmapping )
return map_;
335 map_.buildMapping( coord_[0], coord_[1], coord_[2] );
336 status_ = buildmapping ;
349 class GeometryImpl<dummy, 2, hexa>
350 :
public GeometryImplBase< 2, 4, BilinearMapping< cdim > >
354 typedef GeometryImplBase< 2, 4, BilinearMapping< cdim > > BaseType;
356 using BaseType :: corners_ ;
357 using BaseType :: copy ;
358 using BaseType :: coord_ ;
359 using BaseType :: map_ ;
360 using BaseType :: status_ ;
362 typedef typename BaseType :: MappingType MappingType ;
364 using BaseType :: update ;
365 using BaseType :: valid ;
368 inline const CoordinateVectorType& operator [] (
const int i)
const
370 alugrid_assert ( valid() );
371 alugrid_assert ( i>=0 && i<corners_ );
376 template <
class CoordPtrType>
377 inline void update(
const CoordPtrType& p0,
378 const CoordPtrType& p1,
379 const CoordPtrType& p2,
380 const CoordPtrType& p3)
382 copy(p0, coord_[0] );
383 copy(p1, coord_[1] );
384 copy(p2, coord_[2] );
385 copy(p3, coord_[3] );
390 inline MappingType& mapping()
392 alugrid_assert ( valid() );
393 if( status_ == buildmapping )
return map_;
395 map_.buildMapping( coord_[0], coord_[1], coord_[2], coord_[3] );
396 status_ = buildmapping ;
403 class GeometryImpl<dummy,3, hexa>
404 :
public GeometryImplBase< 3, 8, TrilinearMapping >
408 typedef GeometryImplBase< 3, 8, TrilinearMapping > BaseType;
410 using BaseType :: corners_ ;
411 using BaseType :: copy ;
412 using BaseType :: coord_ ;
413 using BaseType :: map_ ;
414 using BaseType :: status_ ;
416 typedef typename BaseType :: MappingType MappingType ;
417 typedef typename BaseType :: CoordinateMatrixType CoordinateMatrixType;
419 typedef alu3d_ctype CoordPtrType[cdim];
422 const alu3d_ctype* coordPtr_[ corners_ ];
424 using BaseType :: update ;
425 using BaseType :: valid ;
428 GeometryImpl() : BaseType()
431 for(
int i=0; i<corners_; ++i )
435 const alu3d_ctype* point(
const int i )
const
437 alugrid_assert ( valid() );
438 alugrid_assert ( i>=0 && i<corners_ );
439 alugrid_assert ( coordPtr_[i] );
440 return coordPtr_[ i ];
444 inline CoordinateVectorType operator [] (
const int i)
const
446 CoordinateVectorType coord ;
447 copy( point( i ), coord );
452 inline void update(
const CoordPtrType& p0,
453 const CoordPtrType& p1,
454 const CoordPtrType& p2,
455 const CoordPtrType& p3,
456 const CoordPtrType& p4,
457 const CoordPtrType& p5,
458 const CoordPtrType& p6,
459 const CoordPtrType& p7)
461 coordPtr_[0] = &p0[ 0 ];
462 coordPtr_[1] = &p1[ 0 ];
463 coordPtr_[2] = &p2[ 0 ];
464 coordPtr_[3] = &p3[ 0 ];
465 coordPtr_[4] = &p4[ 0 ];
466 coordPtr_[5] = &p5[ 0 ];
467 coordPtr_[6] = &p6[ 0 ];
468 coordPtr_[7] = &p7[ 0 ];
473 template <
class GeometryImp>
474 inline void updateInFather(
const GeometryImp &fatherGeom ,
475 const GeometryImp &myGeom)
479 coord_.reset(
new CoordinateMatrixType() );
482 CoordinateMatrixType& coord = *coord_;
484 for(
int i=0; i < myGeom.corners() ; ++i)
487 coord[i] = fatherGeom.local( myGeom.corner( i ) );
490 coordPtr_[i] = (&(coord[i][0]));
493 for(
int j=0; j<cdim; ++j)
495 if ( coord[i][j] < 1e-16) coord[i][j] = 0.0;
503 inline MappingType& mapping()
505 alugrid_assert ( valid() );
506 if( status_ == buildmapping )
return map_;
508 map_.buildMapping( point( 0 ), point( 1 ), point( 2 ), point( 3 ),
509 point( 4 ), point( 5 ), point( 6 ), point( 7 ) );
511 status_ = buildmapping;
516 void invalidate () { status_ = invalid ; }
519 bool valid ()
const {
return status_ != invalid ; }
525 class GeometryImpl<dummy,3, tetra>
526 :
public GeometryImplBase< 3, 4, LinearMapping<cdim, cdim> >
529 typedef GeometryImplBase< 3, 4, LinearMapping<cdim, cdim> > BaseType;
531 using BaseType :: corners_ ;
532 using BaseType :: copy ;
533 using BaseType :: coord_ ;
534 using BaseType :: map_ ;
535 using BaseType :: status_ ;
537 typedef typename BaseType :: MappingType MappingType ;
538 typedef typename BaseType :: CoordinateMatrixType CoordinateMatrixType;
540 typedef alu3d_ctype CoordPtrType[cdim];
543 const alu3d_ctype* coordPtr_[ corners_ ];
545 using BaseType :: update ;
546 using BaseType :: valid ;
549 GeometryImpl() : BaseType()
552 for(
int i=0; i<corners_; ++i )
556 const alu3d_ctype* point(
const int i )
const
558 alugrid_assert ( valid() );
559 alugrid_assert ( i>=0 && i<corners_ );
560 alugrid_assert ( coordPtr_[ i ] );
561 return coordPtr_[ i ];
565 inline CoordinateVectorType operator [] (
const int i)
const
567 CoordinateVectorType coord ;
568 copy( point( i ), coord );
573 inline void update(
const CoordPtrType& p0,
574 const CoordPtrType& p1,
575 const CoordPtrType& p2,
576 const CoordPtrType& p3)
578 coordPtr_[0] = &p0[ 0 ];
579 coordPtr_[1] = &p1[ 0 ];
580 coordPtr_[2] = &p2[ 0 ];
581 coordPtr_[3] = &p3[ 0 ];
586 template <
class GeometryImp>
587 inline void updateInFather(
const GeometryImp &fatherGeom ,
588 const GeometryImp & myGeom)
592 coord_.reset(
new CoordinateMatrixType());
595 CoordinateMatrixType& coord = *coord_;
597 for(
int i=0; i < myGeom.corners() ; ++i)
600 coord[i] = fatherGeom.local( myGeom.corner( i ) );
603 coordPtr_[i] = (&(coord[i][0]));
606 for(
int j=0; j<cdim; ++j)
608 if ( coord[i][j] < 1e-16) coord[i][j] = 0.0;
616 inline MappingType& mapping()
618 alugrid_assert ( valid() );
619 if( status_ == buildmapping )
return map_;
621 map_.buildMapping( point( 0 ), point( 1 ), point( 2 ), point( 3 ) );
623 status_ = buildmapping;
629 template <
int mydim,
int cdim,
class Gr
idImp>
630 class ALU3dGridGeometry :
631 public GeometryDefaultImplementation<mydim, cdim, GridImp, ALU3dGridGeometry>
633 static const ALU3dGridElementType elementType = GridImp::elementType;
635 typedef typename GridImp::MPICommunicatorType Comm;
638 typedef ALU3dImplTraits< elementType, Comm > ALU3dImplTraitsType ;
641 typedef typename ALU3dImplTraitsType::IMPLElementType IMPLElementType;
642 typedef typename ALU3dImplTraitsType::GEOFaceType GEOFaceType;
643 typedef typename ALU3dImplTraitsType::GEOEdgeType GEOEdgeType;
644 typedef typename ALU3dImplTraitsType::GEOVertexType GEOVertexType;
647 typedef typename ALU3dImplTraitsType::HFaceType HFaceType;
648 typedef typename ALU3dImplTraitsType::HEdgeType HEdgeType;
649 typedef typename ALU3dImplTraitsType::VertexType VertexType;
652 typedef ElementTopologyMapping<elementType> ElementTopo;
653 typedef FaceTopologyMapping<elementType> FaceTopo;
655 static const int corners_ = (elementType == hexa) ?
Dune::power(
int(2) , int((mydim> -1) ? mydim : 0 ) ) : mydim+1;
658 typedef typename MyALUGridGeometryImplementation<cdim> ::
659 template GeometryImpl<0, mydim, elementType > GeometryImplType;
662 typedef typename GridImp :: ctype ctype;
665 typedef FieldVector<ctype, mydim> LocalCoordinate;
668 typedef FieldVector<ctype, cdim > GlobalCoordinate;
671 typedef FieldMatrix<ctype,cdim,mydim> JacobianInverseTransposed;
677 typedef FieldMatrix<ctype,
678 GridImp::dimension == 3 ? EntityCount< elementType > :: numVerticesPerFace : 2 , cdim> FaceCoordinatesType;
685 int corners ()
const;
688 GlobalCoordinate corner (
int i)
const;
692 GlobalCoordinate global (
const LocalCoordinate& local)
const;
696 LocalCoordinate local (
const GlobalCoordinate& global)
const;
699 ctype integrationElement (
const LocalCoordinate& local)
const;
703 const JacobianInverseTransposed &jacobianInverseTransposed (
const LocalCoordinate& local)
const;
706 const JacobianTransposed& jacobianTransposed (
const LocalCoordinate& local)
const;
709 bool affine ()
const;
712 ctype volume ()
const;
718 bool buildGeom(
const IMPLElementType & item);
719 bool buildGeom(
const HFaceType & item,
int twist);
720 bool buildGeom(
const HEdgeType & item,
int twist);
721 bool buildGeom(
const VertexType & item,
int twist);
724 bool buildGeom(
const FaceCoordinatesType& coords);
727 template <
class coord_t>
728 bool buildGeom(
const coord_t& p0,
734 template <
class coord_t>
735 bool buildGeom(
const coord_t& p0,
740 template <
class coord_t>
741 bool buildGeom(
const coord_t& p0,
745 template <
class Geometry>
746 bool buildGeomInFather(
const Geometry &fatherGeom ,
const Geometry &myGeom);
750 void print (std::ostream& ss)
const;
753 void invalidate () { geoImplPtr_.invalidate(); }
756 bool valid ()
const {
return geoImpl().valid(); }
760 GeometryImplType& geoImpl()
const
766 mutable ALU3DSPACE SharedPointer< GeometryImplType > geoImplPtr_;
771#include "geometry_imp.cc"
vector space out of a tensor product of fields.
Definition: fvector.hh:95
general type of geometry implementation
Definition: geometry.hh:195
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
topology of a Cartesian grid
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75