1 #ifndef DUNE_ALU2DGRIDGEOMETRY_HH
2 #define DUNE_ALU2DGRIDGEOMETRY_HH
5 #include <dune/common/misc.hh>
7 #include <dune/geometry/genericgeometry/topologytypes.hh>
17 template<
int cd,
int dim,
class Gr
idImp>
18 class ALU2dGridEntity;
19 template<
int cd,
class Gr
idImp >
20 class ALU2dGridEntityPointer;
21 template<
int mydim,
int cdim,
class Gr
idImp>
22 class ALU2dGridGeometry;
23 template<
int dim,
int dimworld, ALU2DSPACE ElementType eltype >
27 template<
int mydim,
int cdim, ALU2DSPACE ElementType eltype >
31 template<
int cdim, ALU2DSPACE ElementType eltype >
57 bool valid ()
const {
return valid_; }
65 return mapping().affine();
77 GenericGeometry :: SimplexTopology< 0 > :: type :: id :
78 GenericGeometry :: CubeTopology < 0 > :: type :: id),
82 void map2world (
const map_t &m, world_t &w )
const
84 return mapping().map2world( m, w );
87 void world2map (
const world_t &w, map_t &m )
const
89 return mapping().world2map( w, m );
92 const matrix_t &jacobianTransposed (
const map_t &m )
const
94 return mapping().jacobianTransposed( m );
97 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
99 return mapping().jacobianInverseTransposed( m );
102 ctype det (
const map_t &m )
const
104 return mapping().det( m );
108 template<
class Vector >
109 void update (
const Vector &p0 )
111 mapping_.buildMapping( p0 );
117 template<
int cdim, ALU2DSPACE ElementType eltype >
120 static const int ncorners = 2;
145 bool valid ()
const {
return valid_; }
152 return mapping().affine();
164 GenericGeometry :: SimplexTopology< 1 > :: type :: id :
165 GenericGeometry :: CubeTopology < 1 > :: type :: id),
169 void map2world (
const map_t &m, world_t &w )
const
171 return mapping().map2world( m, w );
174 void world2map (
const world_t &w, map_t &m )
const
176 return mapping().world2map( w, m );
179 const matrix_t &jacobianTransposed (
const map_t &m )
const
181 return mapping().jacobianTransposed( m );
184 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
186 return mapping().jacobianInverseTransposed( m );
189 ctype det (
const map_t &m )
const
191 return mapping().det( m );
195 template<
class Geo,
class LocalGeo >
196 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
198 assert( localGeo.corners() == ncorners );
200 FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
201 for(
int i = 0; i < ncorners; ++i )
204 coord[ i ] = geo.local( localGeo.corner( i ) );
206 for(
int j = 0; j < cdim; ++j )
207 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
209 mapping_.buildMapping( coord[ 0 ], coord[ 1 ] );
214 template<
class Vector >
215 void update (
const Vector &p0,
const Vector &p1 )
217 mapping_.buildMapping( p0, p1 );
226 static const int ncorners = 3;
251 bool valid ()
const {
return valid_; }
258 return mapping().affine();
268 return GeometryType( GenericGeometry :: SimplexTopology< 2 > :: type :: id , 2 );
271 void map2world (
const map_t &m, world_t &w )
const
273 return mapping().map2world( m, w );
276 void world2map (
const world_t &w, map_t &m )
const
278 return mapping().world2map( w, m );
281 const matrix_t &jacobianTransposed (
const map_t &m )
const
283 return mapping().jacobianTransposed( m );
286 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
288 return mapping().jacobianInverseTransposed( m );
291 ctype det (
const map_t &m )
const
293 return mapping().det( m );
297 template<
class Geo,
class LocalGeo >
298 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
300 assert( localGeo.corners() == ncorners );
302 FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
303 for(
int i = 0; i < ncorners; ++i )
306 coord[ i ] = geo.local( localGeo.corner( i ) );
308 for(
int j = 0; j < cdim; ++j )
309 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
311 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
315 template<
class HElement >
316 void update (
const HElement &item )
318 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
319 item.getVertex( 2 )->coord() );
328 static const int ncorners = 4;
353 bool valid ()
const {
return valid_; }
360 return mapping().affine();
373 void map2world (
const map_t &m, world_t &w )
const
375 return mapping().map2world( m, w );
378 void world2map (
const world_t &w, map_t &m )
const
380 return mapping().world2map( w, m );
383 const matrix_t &jacobianTransposed (
const map_t &m )
const
385 return mapping().jacobianTransposed( m );
388 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
390 return mapping().jacobianInverseTransposed( m );
393 ctype det (
const map_t &m )
const
395 return mapping().det( m );
399 template<
class Geo,
class LocalGeo >
400 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
402 assert( localGeo.corners() == ncorners );
404 FieldMatrix< alu2d_ctype, ncorners, cdim > coord;
405 for(
int i = 0; i < ncorners; ++i )
408 coord[ i ] = geo.local( localGeo.corner( i ) );
410 for(
int j = 0; j < cdim; ++j )
411 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
413 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
417 template<
class HElement >
418 void update (
const HElement &item )
420 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
421 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
444 char mapping_[ lms > bms ? lms : bms ];
452 : corners_( other.corners() ), valid_( other.valid_ )
461 bool valid ()
const {
return valid_; }
468 return (corners() == 3 ? linearMapping().affine() : bilinearMapping().affine());
479 GenericGeometry :: SimplexTopology< 2 > :: type :: id :
480 GenericGeometry :: CubeTopology < 2 > :: type :: id), 2);
483 void map2world (
const map_t &m, world_t &w )
const
486 linearMapping().map2world( m, w );
488 bilinearMapping().map2world( m, w );
491 void world2map (
const world_t &w, map_t &m )
const
494 linearMapping().world2map( w, m );
496 bilinearMapping().world2map( w, m );
499 const matrix_t &jacobianTransposed (
const map_t &m )
const
501 return (corners() == 3 ? linearMapping().jacobianTransposed( m ) : bilinearMapping().jacobianTransposed( m ));
504 const inv_t &jacobianInverseTransposed (
const map_t &m )
const
506 return (corners() == 3 ? linearMapping().jacobianInverseTransposed( m ) : bilinearMapping().jacobianInverseTransposed( m ));
509 ctype det (
const map_t &m )
const
511 return (corners() == 3 ? linearMapping().det( m ) : bilinearMapping().det( m ));
515 template<
class Geo,
class LocalGeo >
516 void updateLocal (
const Geo &geo,
const LocalGeo &localGeo )
518 const int corners = localGeo.corners();
521 FieldMatrix< alu2d_ctype, 4, cdim > coord;
522 for(
int i = 0; i < corners; ++i )
525 coord[ i ] = geo.local( localGeo.corner( i ) );
527 for(
int j = 0; j < cdim; ++j )
528 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]);
531 updateMapping( corners );
533 linearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
535 bilinearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] );
540 template<
class HElement >
541 void update (
const HElement &item )
543 const int corners = item.numvertices();
544 updateMapping( corners );
546 linearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
547 item.getVertex( 2 )->coord() );
549 bilinearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(),
550 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() );
564 LinearMapping &linearMapping ()
567 return static_cast< LinearMapping *
>( &mapping_ );
570 const BilinearMapping &bilinearMapping ()
const
573 return static_cast< const BilinearMapping *
>( &mapping_ );
576 BilinearMapping &bilinearMapping ()
579 return static_cast< BilinearMapping *
>( &mapping_ );
582 void updateMapping (
const int corners )
584 assert( (corners == 3) || (corners == 4) );
585 if( corners != corners_ )
590 new( &mapping_ ) LinearMapping;
592 new( &mapping_ ) BilinearMapping;
596 void destroyMapping ()
599 linearMapping().~LinearMapping();
600 else if( corners() == 4 )
601 bilinearMapping().~BilinearMapping();
625 template<
int mydim,
int cdim,
class Gr
idImp >
626 class ALU2dGridGeometry
627 :
public GeometryDefaultImplementation< mydim, cdim, GridImp, ALU2dGridGeometry >
632 typedef typename GridImp::template Codim<0>::Geometry Geometry;
634 typedef ALU2dGridGeometry<mydim,cdim,GridImp> GeometryImp;
636 enum { dimbary=mydim+1};
638 typedef typename ALU2dImplTraits< GridImp::dimensionworld, eltype >::HElementType HElementType ;
639 typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, eltype >::Type VertexType;
642 typedef MyALU2dGridGeometryImpl< mydim, cdim, eltype > GeometryImplType;
694 bool buildGeom(
const HElementType & item);
696 bool buildGeom(
const HElementType & item,
const int aluFace);
698 bool buildGeom(
const VertexType & item,
const int );
702 template <
class GeometryType,
class LocalGeomType >
712 void print (std::ostream& ss)
const;
726 static std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > >
738 #include "geometry_imp.cc"