1#ifndef DUNE_SPGRID_CUBE_HH
2#define DUNE_SPGRID_CUBE_HH
6#include <dune/common/iostream.hh>
14 template<
class ct,
int dim >
17 typedef SPCube< ct, dim > This;
24 static const int dimension = dim;
42 SPCube (
const GlobalVector &a,
const GlobalVector &b );
48 const GlobalVector &origin ()
const;
54 const GlobalVector &width ()
const;
62 bool contains (
const GlobalVector &x )
const;
68 static This unitCube ();
71 GlobalVector origin_, width_;
79 template<
class ct,
int dim >
80 inline SPCube< ct, dim >::SPCube ()
82 for(
int i = 0; i < dimension; ++i )
83 origin_[ i ] = width_[ i ] = 0;
87 template<
class ct,
int dim >
88 inline SPCube< ct, dim >
89 ::SPCube (
const GlobalVector &a,
const GlobalVector &b )
91 for(
int i = 0; i < dimension; ++i )
93 origin_[ i ] = std::min( a[ i ], b[ i ] );
94 width_[ i ] = std::max( a[ i ], b[ i ] ) - origin_[ i ];
99 template<
class ct,
int dim >
100 inline const typename SPCube< ct, dim >::GlobalVector &
101 SPCube< ct, dim >::origin ()
const
107 template<
class ct,
int dim >
108 inline const typename SPCube< ct, dim >::GlobalVector &
109 SPCube< ct, dim >::width ()
const
115 template<
class ct,
int dim >
116 inline bool SPCube< ct, dim >::contains (
const GlobalVector &x )
const
118 bool contains =
true;
119 for(
int i = 0; i < dimension; ++i )
121 const ctype y = x[ i ] - origin()[ i ];
122 contains &= ((y >= 0) && (y <= width()[ i ]));
128 template<
class ct,
int dim >
129 inline typename SPCube< ct, dim >::This
130 SPCube< ct, dim >::unitCube ()
133 for(
int i = 0; i < dimension; ++i )
146 template<
class char_type,
class traits,
class ct,
int dim >
147 inline std::basic_ostream< char_type, traits > &
148 operator<< ( std::basic_ostream< char_type, traits > &out,
149 const SPCube< ct, dim > &
cube )
151 typedef SPCube< ct, dim > Cube;
152 typename Cube::GlobalVector a =
cube.origin();
153 typename Cube::GlobalVector b = a +
cube.width();
154 for(
int i = 0; i < Cube::dimension; ++i )
155 out << (i > 0 ?
"x[" :
"[") << a[ i ] <<
"," << b[ i ] <<
"]";
160 template<
class char_type,
class traits,
class ct,
int dim >
161 inline std::basic_istream< char_type, traits > &
162 operator>> ( std::basic_istream< char_type, traits > &in,
163 SPCube< ct, dim > &
cube )
165 typedef SPCube< ct, dim > Cube;
166 typename Cube::GlobalVector a;
167 typename Cube::GlobalVector b;
168 for(
int i = 0; i < Cube::dimension; ++i )
172 in >> match(
'[' ) >> a[ i ] >> match(
',' ) >> b[ i ] >> match(
']' );
Implements a vector constructed from a given type representing a field and a compile-time given size.
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
Dune namespace.
Definition: alignedallocator.hh:13
@ cube
use only cube elements (i.e., quadrilaterals or hexahedra)
Definition: declaration.hh:19