dune-geometry  2.3.1
geometry.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH
5 #define DUNE_GENERICGEOMETRY_GEOMETRY_HH
6 
7 #warning This header and the code it contains is deprecated. If you need functionality \
8  similar to BasicGeometry, please use the MultiLinearGeometry class.
9 
10 #include <dune/common/typetraits.hh>
11 #include <dune/common/nullptr.hh>
12 
15 
16 namespace Dune
17 {
18 
19  namespace GenericGeometry
20  {
21 
172  // BasicGeometry
173  // -------------
174 
251  template< int mydim, class Traits >
253  {
254  typedef typename Traits :: CoordTraits CoordTraits;
255 
257  template< int, class > friend class BasicGeometry;
258 
259  public:
260 
262  static const int mydimension = mydim;
263 
265  static const int coorddimension = Traits :: dimWorld;
266 
268  typedef typename CoordTraits :: ctype ctype;
269 
271  typedef FieldVector< ctype, mydimension > LocalCoordinate;
272 
274  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
275 
276  private:
277  dune_static_assert( (0 <= mydimension), "Geometry dimension must be nonnegative." );
278 
279  template< bool >
280  struct Hybrid
281  {
283  };
284 
285  template< bool >
286  struct NonHybrid
287  {
288  static const int topologyId = Traits::template hasSingleGeometryType< mydimension >::topologyId;
291  };
292 
293  static const bool hybrid = !Traits::template hasSingleGeometryType< mydimension >::v;
294 
295  protected:
296  typedef typename conditional< hybrid, Hybrid< true >, NonHybrid< false > >::type::MappingFactory MappingFactory;
297  typedef typename MappingFactory::Mapping Mapping;
298 
299  public:
305  typedef typename Mapping::JacobianTransposed JacobianTransposed;
311  typedef typename Mapping::JacobianInverseTransposed Jacobian;
312  // for cenvencience, Jacobian is the name of the type in the geometry interface
314 
315  public:
319  : mapping_( nullptr )
320  {}
321 
323  template< class CoordVector >
324  BasicGeometry ( const GeometryType &type, const CoordVector &coords )
325  {
326  assert(type.dim() == mydim);
327  mapping_ = MappingFactory::construct( type.id(), coords, mappingStorage_ );
328  }
329 
333  template< class CoordVector >
334  BasicGeometry ( const CoordVector &coords )
335  {
337  type.makeFromVertices( mydim, coords.size() );
338  mapping_ = MappingFactory::construct( type.id(), coords, mappingStorage_ );
339  }
340 
354  template< int fatherdim >
356  {
357  const unsigned int codim = fatherdim - mydim;
358  mapping_ = father.mapping_->template trace< codim >( i, mappingStorage_ );
359  }
360 
362  BasicGeometry ( const BasicGeometry &other )
363  : mapping_( other.mapping_ ? other.mapping_->clone( mappingStorage_ ) : nullptr )
364  {}
365 
368  {
369  if( mapping_ )
370  mapping_->~Mapping();
371  }
372 
374  const BasicGeometry &operator= ( const BasicGeometry &other )
375  {
376  if( mapping_ )
377  mapping_->~Mapping();
378  mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr;
379  return *this;
380  }
381 
389  operator bool () const
390  {
391  return bool( mapping_ );
392  }
393 
396  {
397  return mapping_->type();
398  }
399 
401  int corners () const
402  {
403  return mapping_->numCorners();
404  }
405 
407  GlobalCoordinate corner ( const int i ) const
408  {
409  return mapping_->corner( i );
410  }
411 
414  {
415  return mapping_->global( local );
416  }
417 
420  {
421  return mapping_->local( global );
422  }
423 
426  {
427  return mapping_->center();
428  }
429 
431  bool affine () const
432  {
433  return mapping_->affine();
434  }
435 
438  {
439  return mapping_->integrationElement( local );
440  }
441 
443  ctype volume () const
444  {
445  return mapping_->volume();
446  }
447 
453  {
454  return mapping_->jacobianTransposed( local );
455  }
456 
460  {
461  return mapping_->jacobianInverseTransposed( local );
462  }
463 
464  private:
465 
467  Mapping* mapping_;
468 
474  char mappingStorage_[ MappingFactory::maxMappingSize ] __attribute__((aligned(sizeof(double))));
475  };
476 
477 
478 
479  // Geometry
480  // --------
481 
494  template< int mydim, int cdim, class Grid >
495  class Geometry
496  : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > >
497  {
499 
500  protected:
501  typedef typename Base::Mapping Mapping;
502 
503  public:
504 
506  {}
507 
509  template< class Geo >
510  explicit Geometry ( const Geo &geo )
511  : Base( geo.type(), geo, geo.affine() )
512  {}
513 
515  template< class CoordVector >
516  Geometry ( const GeometryType &type, const CoordVector &coords )
517  : Base( type, coords )
518  {}
519 
521  template< int fatherdim >
523  : Base( father, i )
524  {}
525  };
526 
527 
528 
529  // LocalGeometry
530  // -------------
531 
544  template< int mydim, int cdim, class Grid >
546  : public BasicGeometry< mydim, LocalGeometryTraits< Grid > >
547  {
549 
550  protected:
551  typedef typename Base::Mapping Mapping;
552 
553  public:
555  template< class Geo >
556  explicit LocalGeometry ( const Geo &geo )
557  : Base( geo.type(), geo, geo.affine() )
558  {}
559 
561  template< class CoordVector >
562  LocalGeometry ( const GeometryType &type, const CoordVector &coords )
563  : Base( type, coords )
564  {}
565 
567  template< int fatherdim >
569  : Base( father, i )
570  {}
571  };
572 
573  }
574 
575 }
576 
577 #endif // #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH
BasicGeometry(const CoordVector &coords)
Constructor using a vector of corner coordinates and the dimension.
Definition: geometry.hh:334
FieldVector< ctype, coorddimension > GlobalCoordinate
Type used for world coordinates.
Definition: geometry.hh:274
generic implementation of a DUNE (global) geometry
Definition: geometry.hh:495
BasicGeometry(const BasicGeometry &other)
Copy constructor.
Definition: geometry.hh:362
Geometry()
Definition: geometry.hh:505
~BasicGeometry()
Destructor.
Definition: geometry.hh:367
Mapping::JacobianInverseTransposed Jacobian
Type used for Jacobian matrices.
Definition: geometry.hh:311
ctype volume() const
Return the volume of the element.
Definition: geometry.hh:443
conditional< hybrid, Hybrid< true >, NonHybrid< false > >::type::MappingFactory MappingFactory
Definition: geometry.hh:296
conditional< isPrism, Prism< true >, Pyramid< false > >::type::type type
Definition: topologytypes.hh:295
Base::Mapping Mapping
Definition: geometry.hh:501
const JacobianTransposed & jacobianTransposed(const LocalCoordinate &local) const
Compute the transpose of the Jacobian matrix of the transformation from the reference element into th...
Definition: geometry.hh:452
GeometryType type() const
Return the topological type of this geometry.
Definition: geometry.hh:395
Mapping::JacobianTransposed JacobianTransposed
Type used for Jacobian matrices.
Definition: geometry.hh:305
FieldVector< ctype, mydimension > LocalCoordinate
Type used for parameter coordinates.
Definition: geometry.hh:271
LocalGeometry(const Geo &geo)
Copy constructor from another geometry.
Definition: geometry.hh:556
MappingFactory::Mapping Mapping
Definition: geometry.hh:297
BasicGeometry()
Default constructor.
Definition: geometry.hh:318
generic implementation of a DUNE (local) geometry
Definition: geometry.hh:545
GlobalCoordinate center() const
return center of element
Definition: geometry.hh:425
Base::Mapping Mapping
Definition: geometry.hh:551
void makeFromVertices(unsigned int dim, unsigned int vertices)
Construct the correct geometry type given the dimension and the number of vertices.
Definition: type.hh:218
Geometry(const GeometryType &type, const CoordVector &coords)
Constructor with a GeometryType and a set of coordinates.
Definition: geometry.hh:516
unsigned int id() const
Return the topology id the type.
Definition: type.hh:327
GlobalCoordinate corner(const int i) const
Return the world coordinates of the i-th corner.
Definition: geometry.hh:407
Geometry(const Geo &geo)
Copy constructor from another geometry.
Definition: geometry.hh:510
LocalGeometry(const Geometry< fatherdim, cdim, Grid > &father, int i)
Definition: geometry.hh:568
Definition: mappingprovider.hh:23
const BasicGeometry & operator=(const BasicGeometry &other)
Assignment from other BasicGeometry.
Definition: geometry.hh:374
BasicGeometry(const BasicGeometry< fatherdim, Traits > &father, int i)
obtain a geometry for a subentity
Definition: geometry.hh:355
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:322
ctype integrationElement(const LocalCoordinate &local) const
Return the factor $|det F|$ that appears in the integral transformation formula.
Definition: geometry.hh:437
interface for a mapping
Definition: mapping.hh:30
Jacobian JacobianInverseTransposed
Definition: geometry.hh:313
BasicGeometry(const GeometryType &type, const CoordVector &coords)
Constructor using a GeometryType and a list of corner coordinates.
Definition: geometry.hh:324
LocalGeometry(const GeometryType &type, const CoordVector &coords)
Constructor with a GeometryType and a set of coordinates.
Definition: geometry.hh:562
ct ctype
Definition: geometrytraits.hh:21
generic implementation of DUNE geometries
Definition: geometry.hh:252
static const int coorddimension
The dimension of the world space of this geometry.
Definition: geometry.hh:265
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:24
GlobalCoordinate global(const LocalCoordinate &local) const
Map local to global coordinates.
Definition: geometry.hh:413
const JacobianInverseTransposed & jacobianInverseTransposed(const LocalCoordinate &local) const
Compute the transpose of the inverse Jacobian matrix of the transformation from the reference element...
Definition: geometry.hh:459
int corners() const
Return the number of corners.
Definition: geometry.hh:401
LocalCoordinate local(const GlobalCoordinate &global) const
Map global to local coordinates.
Definition: geometry.hh:419
Definition: mappingprovider.hh:53
CoordTraits::ctype ctype
Type used for coordinate components.
Definition: geometry.hh:268
static const int mydimension
The dimension of the parameter space of this geometry.
Definition: geometry.hh:262
bool affine() const
Return true if this is an affine geometry.
Definition: geometry.hh:431
Geometry(const Geometry< fatherdim, cdim, Grid > &father, int i)
Definition: geometry.hh:522
Definition: topologytypes.hh:271