dune-spgrid  2.7
normal.hh
Go to the documentation of this file.
1 #ifndef DUNE_SPGRID_NORMAL_HH
2 #define DUNE_SPGRID_NORMAL_HH
3 
4 #include <dune/common/fvector.hh>
5 
7 
8 namespace Dune
9 {
10 
11  // SPNormalVector
12  // --------------
13 
14  template< class ct, int dim >
16  {
18 
19  public:
20  static const int dimension = dim;
21 
22  typedef ct field_type;
23  typedef ct value_type;
24 
25  typedef std::size_t size_type;
26 
27  typedef Dune::FieldVector< field_type, dim > FieldVector;
28 
29  SPNormalVector ( size_type i, const field_type &p ) : i_( i ), p_( p ) {}
30 
31  operator FieldVector () const
32  {
33  FieldVector v( field_type( 0 ) );
34  v[ i_ ] = p_;
35  return v;
36  }
37 
38  This &operator*= ( const field_type &s );
39  This &operator/= ( const field_type &s );
40 
41  bool operator== ( const This &other ) const;
42  bool operator!= ( const This &other ) const;
43 
44  field_type operator* ( const This &other ) const;
45  field_type operator* ( const FieldVector &other ) const;
46 
47  field_type one_norm () const;
48  field_type two_norm () const;
49  field_type two_norm2 () const;
50  field_type infinity_norm () const;
51 
52  private:
53  size_type i_;
54  field_type p_;
55  };
56 
57 
58 
59  // SPNormalId
60  // ----------
61 
62  template< int dim >
63  class SPNormalId
64  {
65  typedef SPNormalId< dim > This;
66 
67  public:
68  static const int dimension = dim;
69 
70  SPNormalId () : face_( 2*dimension ) {}
71 
72  explicit SPNormalId ( int face ) : face_( face ) {}
73 
74  template< class ct >
76  {
78  }
79 
80  This operator- () const { return This( face_ ^ 1 ); }
81 
82  int face () const { return face_; }
83 
84  int axis () const { return (face() >> 1); }
85 
86  int sign () const { return 2*(face() & 1) - 1; }
87 
88  private:
89  int face_;
90  };
91 
92 
93 
94  // Auxilliary Functions for SPNormalVector
95  // ---------------------------------------
96 
97  template< class ct, int dim >
98  inline ct operator* ( const FieldVector< ct, dim > &a, const SPNormalVector< ct, dim > &b )
99  {
100  return b*a;
101  }
102 
103 
104  template< class ct, int dim >
106  {
108  c *= a;
109  return c;
110  }
111 
112 
113  template< class ct, int dim >
115  {
116  return b*a;
117  }
118 
119 
120  template< class ct, int dim >
121  inline bool operator== ( const FieldVector< ct, dim > &a, const SPNormalVector< ct, dim > &b )
122  {
123  return (a == static_cast< FieldVector< ct, dim > >( b ));
124  }
125 
126 
127  template< class ct, int dim >
128  inline bool operator!= ( const FieldVector< ct, dim > &a, const SPNormalVector< ct, dim > &b )
129  {
130  return (a != static_cast< FieldVector< ct, dim > >( b ));
131  }
132 
133 
134  template< class ct, int dim >
135  inline bool operator== ( const SPNormalVector< ct, dim > &a, const FieldVector< ct, dim > &b )
136  {
137  return (static_cast< FieldVector< ct, dim > >( a ) == b);
138  }
139 
140 
141  template< class ct, int dim >
142  inline bool operator!= ( const SPNormalVector< ct, dim > &a, const FieldVector< ct, dim > &b )
143  {
144  return (static_cast< FieldVector< ct, dim > >( a ) != b);
145  }
146 
147 
148 
149  // Implementation of SPNormalVector
150  // --------------------------------
151 
152  template< class ct, int dim >
153  inline typename SPNormalVector< ct, dim >::This &
155  {
156  p_ *= s;
157  return *this;
158  }
159 
160 
161  template< class ct, int dim >
162  inline typename SPNormalVector< ct, dim >::This &
164  {
165  p_ /= s;
166  return *this;
167  }
168 
169 
170  template< class ct, int dim >
171  inline bool SPNormalVector< ct, dim >::operator== ( const This &other ) const
172  {
173  return (i_ == other.i_) && (p_ == other.p_);
174  }
175 
176 
177  template< class ct, int dim >
178  inline bool SPNormalVector< ct, dim >::operator!= ( const This &other ) const
179  {
180  return (i_ != other.i_) || (p_ != other.p_);
181  }
182 
183 
184  template< class ct, int dim >
187  {
188  return (i_ == other.i_ ? p_ * other.p_ : field_type( 0 ));
189  }
190 
191 
192  template< class ct, int dim >
195  {
196  return p_ * other[ i_ ];
197  }
198 
199 
200  template< class ct, int dim >
203  {
204  return std::abs( p_ );
205  }
206 
207 
208  template< class ct, int dim >
211  {
212  return std::abs( p_ );
213  }
214 
215 
216  template< class ct, int dim >
219  {
220  return p_ * p_;
221  }
222 
223 
224  template< class ct, int dim >
227  {
228  return std::abs( p_ );
229  }
230 
231 
232 
233  // Auxilliary Functions for SPNormalId
234  // -----------------------------------
235 
236  template< int dim >
238  {
239  SPMultiIndex< dim > idC( idA );
240  idC[ idB.axis()] += idB.sign();
241  return idC;
242  }
243 
244 
245  template< int dim >
247  {
248  SPMultiIndex< dim > idC( idB );
249  idC[ idA.axis() ] += idA.sign();
250  return idC;
251  }
252 
253 
254  template< int dim >
256  {
257  SPMultiIndex< dim > idC( idA );
258  idC[ idB.axis() ] -= idB.sign();
259  return idC;
260  }
261 
262 
263  template< int dim >
265  {
266  SPMultiIndex< dim > idC( -idB );
267  idC[ idA.axis() ] += idA.sign();
268  return idC;
269  }
270 
271 
272  template< int dim >
273  inline int operator* ( const SPMultiIndex< dim > &idA, const SPNormalId< dim > &idB )
274  {
275  return idB.sign() * idA[ idB.axis() ];
276  }
277 
278  template< int dim >
279  inline int operator* ( const SPNormalId< dim > &idA, const SPMultiIndex< dim > &idB )
280  {
281  return idA.sign() * idB[ idA.axis() ];
282  }
283 
284 } // namespace Dune
285 
286 #endif // #ifndef DUNE_SPGRID_NORMAL_HH
Definition: iostream.hh:7
bool operator==(const FieldVector< ct, dim > &a, const SPNormalVector< ct, dim > &b)
Definition: normal.hh:121
SPMesh< dim > operator-(const SPMesh< dim > &mesh, const SPMultiIndex< dim > &shift)
Definition: mesh.hh:245
SPMesh< dim > operator+(const SPMesh< dim > &mesh, const SPMultiIndex< dim > &shift)
Definition: mesh.hh:236
SPMultiIndex< dim > operator*(const SPMultiIndex< dim > &a, const int &b)
Definition: multiindex.hh:258
bool operator!=(const FieldVector< ct, dim > &a, const SPNormalVector< ct, dim > &b)
Definition: normal.hh:128
multiindex
Definition: multiindex.hh:25
Definition: normal.hh:16
field_type two_norm() const
Definition: normal.hh:210
field_type one_norm() const
Definition: normal.hh:202
SPNormalVector(size_type i, const field_type &p)
Definition: normal.hh:29
Dune::FieldVector< field_type, dim > FieldVector
Definition: normal.hh:27
bool operator!=(const This &other) const
Definition: normal.hh:178
ct value_type
Definition: normal.hh:23
field_type operator*(const This &other) const
Definition: normal.hh:186
This & operator/=(const field_type &s)
Definition: normal.hh:163
ct field_type
Definition: normal.hh:22
static const int dimension
Definition: normal.hh:20
bool operator==(const This &other) const
Definition: normal.hh:171
std::size_t size_type
Definition: normal.hh:25
field_type two_norm2() const
Definition: normal.hh:218
This & operator*=(const field_type &s)
Definition: normal.hh:154
field_type infinity_norm() const
Definition: normal.hh:226
Definition: normal.hh:64
int sign() const
Definition: normal.hh:86
SPNormalId()
Definition: normal.hh:70
This operator-() const
Definition: normal.hh:80
SPNormalId(int face)
Definition: normal.hh:72
int face() const
Definition: normal.hh:82
static const int dimension
Definition: normal.hh:68
int axis() const
Definition: normal.hh:84