dune-geometry  2.2.0
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 
171  // BasicGeometry
172  // -------------
173 
247  template< int mydim, class Traits >
249  {
250  typedef typename Traits :: CoordTraits CoordTraits;
251 
252  static const int dimGrid = Traits :: dimGrid;
253 
255  template< int, class > friend class BasicGeometry;
256 
257  public:
258 
260  static const int mydimension = mydim;
261 
263  static const int coorddimension = Traits :: dimWorld;
264 
266  typedef typename CoordTraits :: ctype ctype;
267 
269  typedef FieldVector< ctype, mydimension > LocalCoordinate;
270 
272  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
273 
274  private:
275  dune_static_assert( (0 <= mydimension) && (mydimension <= dimGrid),
276  "Invalid geometry dimension." );
277 
278  static const int codimension = dimGrid - mydimension;
279 
280  template< bool >
281  struct Hybrid
282  {
284  };
285 
286  template< bool >
287  struct NonHybrid
288  {
291  };
292 
293  typedef typename SelectType< Traits::hybrid, Hybrid< true >, NonHybrid< false > >::Type::Mapping
294  ElementMapping;
295  typedef GenericGeometry::MappingProvider< ElementMapping, codimension > MappingProvider;
296 
297  protected:
298  typedef typename MappingProvider::Mapping Mapping;
299 
300  public:
306  typedef typename Mapping::JacobianTransposed JacobianTransposed;
312  typedef typename Mapping::JacobianInverseTransposed Jacobian;
313  // for cenvencience, Jacobian is the name of the type in the geometry interface
315 
316  public:
320  : mapping_( nullptr )
321  {}
322 
328  template< class CoordVector >
329  DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords )
330  {
331  mapping_ = MappingProvider::construct( topologyId, coords, mappingStorage_ );
332  }
333 
343  template< class CoordVector >
344  DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
345  {
346  mapping_ = MappingProvider::construct( topologyId, coords, affine, mappingStorage_ );
347  }
348 
350  template< class CoordVector >
351  BasicGeometry ( const GeometryType &type, const CoordVector &coords )
352  {
353  mapping_ = MappingProvider::construct( type.id(), coords, mappingStorage_ );
354  }
355 
369  template< int fatherdim >
371  {
372  const unsigned int codim = fatherdim - mydim;
373  mapping_ = father.mapping_->template trace< codim >( i, mappingStorage_ );
374  }
375 
377  BasicGeometry ( const BasicGeometry &other )
378  : mapping_( other.mapping_ ? other.mapping_->clone( mappingStorage_ ) : nullptr )
379  {}
380 
383  {
384  if( mapping_ )
385  mapping_->~Mapping();
386  }
387 
389  const BasicGeometry &operator= ( const BasicGeometry &other )
390  {
391  if( mapping_ )
392  mapping_->~Mapping();
393  mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr;
394  return *this;
395  }
396 
404  operator bool () const
405  {
406  return bool( mapping_ );
407  }
408 
411  {
412  return mapping_->type();
413  }
414 
416  int corners () const
417  {
418  return mapping_->numCorners();
419  }
420 
422  GlobalCoordinate corner ( const int i ) const
423  {
424  return mapping_->corner( i );
425  }
426 
429  {
430  return mapping_->global( local );
431  }
432 
435  {
436  return mapping_->local( global );
437  }
438 
441  {
442  return mapping_->center();
443  }
444 
446  bool affine () const
447  {
448  return mapping_->affine();
449  }
450 
453  {
454  return mapping_->integrationElement( local );
455  }
456 
458  ctype volume () const
459  {
460  return mapping_->volume();
461  }
462 
468  {
469  return mapping_->jacobianTransposed( local );
470  }
471 
475  {
476  return mapping_->jacobianInverseTransposed( local );
477  }
478 
479  private:
480 
482  Mapping* mapping_;
483 
489  char mappingStorage_[ MappingProvider::maxMappingSize ];
490  };
491 
492 
493 
494  // Geometry
495  // --------
496 
509  template< int mydim, int cdim, class Grid >
510  class Geometry
511  : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > >
512  {
514 
515  protected:
516  typedef typename Base::Mapping Mapping;
517 
518  public:
519 
521  {}
522 
523  template< class CoordVector >
524  DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords )
525  : Base( topologyId, coords )
526  {}
527 
528  template< class CoordVector >
529  DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
530  : Base( topologyId, coords, affine )
531  {}
532 
534  template< class Geo >
535  explicit Geometry ( const Geo &geo )
536  : Base( geo.type(), geo, geo.affine() )
537  {}
538 
540  template< class CoordVector >
541  Geometry ( const GeometryType &type, const CoordVector &coords )
542  : Base( type, coords )
543  {}
544 
546  template< int fatherdim >
548  : Base( father, i )
549  {}
550  };
551 
552 
553 
554  // LocalGeometry
555  // -------------
556 
569  template< int mydim, int cdim, class Grid >
571  : public BasicGeometry< mydim, LocalGeometryTraits< Grid > >
572  {
574 
575  protected:
576  typedef typename Base::Mapping Mapping;
577 
578  public:
579  template< class CoordVector >
580  DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords )
581  : Base( topologyId, coords )
582  {}
583 
584  template< class CoordVector >
585  DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
586  : Base( topologyId, coords, affine )
587  {}
588 
590  template< class Geo >
591  explicit LocalGeometry ( const Geo &geo )
592  : Base( geo.type(), geo, geo.affine() )
593  {}
594 
596  template< class CoordVector >
597  LocalGeometry ( const GeometryType &type, const CoordVector &coords )
598  : Base( type, coords )
599  {}
600 
602  template< int fatherdim >
604  : Base( father, i )
605  {}
606  };
607 
608  }
609 
610 }
611 
612 #endif // #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH