dune-geometry  2.2.1
geometry.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH
5 #define DUNE_GENERICGEOMETRY_GEOMETRY_HH
6 
7 #include <dune/common/typetraits.hh>
8 #include <dune/common/nullptr.hh>
9 
13 
14 namespace Dune
15 {
16 
17  namespace GenericGeometry
18  {
19 
170  // BasicGeometry
171  // -------------
172 
245  template< int mydim, class Traits >
247  {
248  typedef typename Traits :: CoordTraits CoordTraits;
249 
250  static const int dimGrid = Traits :: dimGrid;
251 
253  template< int, class > friend class BasicGeometry;
254 
255  public:
256 
258  static const int mydimension = mydim;
259 
261  static const int coorddimension = Traits :: dimWorld;
262 
264  typedef typename CoordTraits :: ctype ctype;
265 
267  typedef FieldVector< ctype, mydimension > LocalCoordinate;
268 
270  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
271 
272  private:
273  dune_static_assert( (0 <= mydimension) && (mydimension <= dimGrid),
274  "Invalid geometry dimension." );
275 
276  static const int codimension = dimGrid - mydimension;
277 
278  template< bool >
279  struct Hybrid
280  {
282  };
283 
284  template< bool >
285  struct NonHybrid
286  {
289  };
290 
291  typedef typename SelectType< Traits::hybrid, Hybrid< true >, NonHybrid< false > >::Type::Mapping
292  ElementMapping;
293  typedef GenericGeometry::MappingProvider< ElementMapping, 0 > MappingProvider;
294 
295  protected:
296  typedef typename MappingProvider::Mapping Mapping;
297 
298  public:
304  typedef typename Mapping::JacobianTransposed JacobianTransposed;
310  typedef typename Mapping::JacobianInverseTransposed Jacobian;
311  // for cenvencience, Jacobian is the name of the type in the geometry interface
313 
314  public:
318  : mapping_( nullptr )
319  {}
320 
326  template< class CoordVector >
327  DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords )
328  {
329  mapping_ = MappingProvider::construct( topologyId, coords, mappingStorage_ );
330  }
331 
341  template< class CoordVector >
342  DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
343  {
344  mapping_ = MappingProvider::construct( topologyId, coords, affine, mappingStorage_ );
345  }
346 
348  template< class CoordVector >
349  BasicGeometry ( const GeometryType &type, const CoordVector &coords )
350  {
351  mapping_ = MappingProvider::construct( type.id(), coords, mappingStorage_ );
352  }
353 
367  template< int fatherdim >
369  {
370  const unsigned int codim = fatherdim - mydim;
371  mapping_ = father.mapping_->template trace< codim >( i, mappingStorage_ );
372  }
373 
375  BasicGeometry ( const BasicGeometry &other )
376  : mapping_( other.mapping_ ? other.mapping_->clone( mappingStorage_ ) : nullptr )
377  {}
378 
381  {
382  if( mapping_ )
383  mapping_->~Mapping();
384  }
385 
387  const BasicGeometry &operator= ( const BasicGeometry &other )
388  {
389  if( mapping_ )
390  mapping_->~Mapping();
391  mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr;
392  return *this;
393  }
394 
402  operator bool () const
403  {
404  return bool( mapping_ );
405  }
406 
409  {
410  return mapping_->type();
411  }
412 
414  int corners () const
415  {
416  return mapping_->numCorners();
417  }
418 
420  GlobalCoordinate corner ( const int i ) const
421  {
422  return mapping_->corner( i );
423  }
424 
427  {
428  return mapping_->global( local );
429  }
430 
433  {
434  return mapping_->local( global );
435  }
436 
439  {
440  return mapping_->center();
441  }
442 
444  bool affine () const
445  {
446  return mapping_->affine();
447  }
448 
451  {
452  return mapping_->integrationElement( local );
453  }
454 
456  ctype volume () const
457  {
458  return mapping_->volume();
459  }
460 
466  {
467  return mapping_->jacobianTransposed( local );
468  }
469 
473  {
474  return mapping_->jacobianInverseTransposed( local );
475  }
476 
477  private:
478 
480  Mapping* mapping_;
481 
487  char mappingStorage_[ MappingProvider::maxMappingSize ];
488  };
489 
490 
491 
492  // Geometry
493  // --------
494 
507  template< int mydim, int cdim, class Grid >
508  class Geometry
509  : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > >
510  {
512 
513  protected:
514  typedef typename Base::Mapping Mapping;
515 
516  public:
517 
519  {}
520 
521  template< class CoordVector >
522  DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords )
523  : Base( topologyId, coords )
524  {}
525 
526  template< class CoordVector >
527  DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
528  : Base( topologyId, coords, affine )
529  {}
530 
532  template< class Geo >
533  explicit Geometry ( const Geo &geo )
534  : Base( geo.type(), geo, geo.affine() )
535  {}
536 
538  template< class CoordVector >
539  Geometry ( const GeometryType &type, const CoordVector &coords )
540  : Base( type, coords )
541  {}
542 
544  template< int fatherdim >
546  : Base( father, i )
547  {}
548  };
549 
550 
551 
552  // LocalGeometry
553  // -------------
554 
567  template< int mydim, int cdim, class Grid >
569  : public BasicGeometry< mydim, LocalGeometryTraits< Grid > >
570  {
572 
573  protected:
574  typedef typename Base::Mapping Mapping;
575 
576  public:
577  template< class CoordVector >
578  DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords )
579  : Base( topologyId, coords )
580  {}
581 
582  template< class CoordVector >
583  DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
584  : Base( topologyId, coords, affine )
585  {}
586 
588  template< class Geo >
589  explicit LocalGeometry ( const Geo &geo )
590  : Base( geo.type(), geo, geo.affine() )
591  {}
592 
594  template< class CoordVector >
595  LocalGeometry ( const GeometryType &type, const CoordVector &coords )
596  : Base( type, coords )
597  {}
598 
600  template< int fatherdim >
602  : Base( father, i )
603  {}
604  };
605 
606  }
607 
608 }
609 
610 #endif // #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH