1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi: set et ts=4 sw=2 sts=2:
3
#ifndef DUNE_GRID_YASPGRIDGEOMETRY_HH
4
#define DUNE_GRID_YASPGRIDGEOMETRY_HH
7
* \brief The YaspGeometry class and its specializations
9
YaspGeometry realizes the concept of the geometric part of a mesh entity.
11
We have specializations for dim == dimworld (elements) and dim == 0
12
(vertices). The general version implements dim == dimworld-1 (faces)
13
and otherwise throws a GridError.
18
//! The general version can do any dimension, but constructors currently exist only for dim==dimworld-1
19
template<int mydim,int cdim, class GridImp>
20
class YaspGeometry : public AxisAlignedCubeGeometry<typename GridImp::ctype,mydim,cdim>
23
//! define type used for coordinates in grid module
24
typedef typename GridImp::ctype ctype;
26
//! default constructor
28
: AxisAlignedCubeGeometry<ctype,mydim,cdim>(FieldVector<ctype,cdim>(0),FieldVector<ctype,cdim>(0)) // anything
31
//! constructor from midpoint and extension and missing direction number
32
YaspGeometry (const FieldVector<ctype, cdim>& p, const FieldVector<ctype, cdim>& h, uint8_t& m)
33
: AxisAlignedCubeGeometry<ctype,mydim,cdim>(FieldVector<ctype,cdim>(0),FieldVector<ctype,cdim>(0)) // anything
36
DUNE_THROW(GridError, "This YaspGeometry constructor assumes cdim=mydim+1");
38
FieldVector<ctype, cdim> lower = p;
39
FieldVector<ctype, cdim> upper = p;
43
lower[m] = upper[m] = p[m];
45
std::bitset<cdim> axes((1<<cdim)-1); // all bits set
46
axes[m] = false; // except the one at 'missing'
49
static_cast< AxisAlignedCubeGeometry<ctype,mydim,cdim> & >( *this ) = AxisAlignedCubeGeometry<ctype,mydim,cdim>(lower, upper, axes);
53
YaspGeometry (const YaspGeometry& other)
54
: AxisAlignedCubeGeometry<ctype,mydim,cdim>(other)
58
void print (std::ostream& s) const
60
s << "YaspGeometry<"<<mydim<<","<<cdim<< "> ";
62
for (int i=0; i<cdim; i++)
63
s << " " << 0.5*(this->lower_[i] + this->upper_[i]);
65
for (int i=0; i<cdim; i++)
66
s << " " << (this->upper_[i] - this->lower_[i]);
67
s << " coordinates: " << this->axes_;
74
//! specialize for dim=dimworld, i.e. a volume element
75
template<int mydim, class GridImp>
76
class YaspGeometry<mydim,mydim,GridImp> : public AxisAlignedCubeGeometry<typename GridImp::ctype,mydim,mydim>
79
typedef typename GridImp::ctype ctype;
81
//! default constructor
83
: AxisAlignedCubeGeometry<ctype,mydim,mydim>(FieldVector<ctype,mydim>(0),FieldVector<ctype,mydim>(0)) // anything
86
//! constructor from midpoint and extension
87
YaspGeometry (const FieldVector<ctype, mydim>& p, const FieldVector<ctype, mydim>& h)
88
: AxisAlignedCubeGeometry<ctype,mydim,mydim>(FieldVector<ctype,mydim>(0),FieldVector<ctype,mydim>(0)) // anything
90
FieldVector<ctype, mydim> lower = p;
91
FieldVector<ctype, mydim> upper = p;
95
static_cast< AxisAlignedCubeGeometry<ctype,mydim,mydim> & >( *this ) = AxisAlignedCubeGeometry<ctype,mydim,mydim>(lower, upper);
98
//! copy constructor (skipping temporary variables)
99
YaspGeometry (const YaspGeometry& other)
100
: AxisAlignedCubeGeometry<ctype,mydim,mydim>(other)
104
void print (std::ostream& s) const
106
s << "YaspGeometry<"<<mydim<<","<<mydim<< "> ";
108
for (int i=0; i<mydim; i++)
109
s << " " << 0.5 * (this->lower_[i] + this->upper_[i]);
111
for (int i=0; i<mydim; i++)
112
s << " " << (this->upper_[i] + this->lower_[i]);
117
//! specialization for dim=0, this is a vertex
118
template<int cdim, class GridImp>
119
class YaspGeometry<0,cdim,GridImp> : public AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>
122
typedef typename GridImp::ctype ctype;
124
//! default constructor
126
: AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>(FieldVector<ctype,cdim>(0)) // anything
130
explicit YaspGeometry ( const FieldVector< ctype, cdim > &p )
131
: AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>( p )
134
YaspGeometry ( const FieldVector< ctype, cdim > &p, const FieldVector< ctype, cdim > &, uint8_t &)
135
: AxisAlignedCubeGeometry<typename GridImp::ctype,0,cdim>( p )
139
void print (std::ostream& s) const
141
s << "YaspGeometry<"<<0<<","<<cdim<< "> ";
142
s << "position " << this->lower_;
146
// operator<< for all YaspGeometrys
147
template <int mydim, int cdim, class GridImp>
149
std::ostream& operator<< (std::ostream& s, YaspGeometry<mydim,cdim,GridImp>& e)
157
#endif // DUNE_GRID_YASPGRIDGEOMETRY_HH