Dune Core Modules (2.9.0)

normal.hh
1#ifndef DUNE_SPGRID_NORMAL_HH
2#define DUNE_SPGRID_NORMAL_HH
3
5
6#include <dune/grid/spgrid/multiindex.hh>
7
8namespace Dune
9{
10
11 // SPNormalVector
12 // --------------
13
14 template< class ct, int dim >
15 class SPNormalVector
16 {
17 typedef SPNormalVector< ct, dim > This;
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 >
75 operator SPNormalVector< ct, dimension > () const
76 {
77 return SPNormalVector< ct, dimension >( axis(), sign() );
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 >
105 inline SPNormalVector< ct, dim > operator* ( const ct &a, const SPNormalVector< ct, dim > &b )
106 {
107 SPNormalVector< ct, dim > c( b );
108 c *= a;
109 return c;
110 }
111
112
113 template< class ct, int dim >
114 inline SPNormalVector< ct, dim > operator* ( const SPNormalVector< ct, dim > &a, const ct &b )
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 &
154 SPNormalVector< ct, dim >::operator*= ( const field_type &s )
155 {
156 p_ *= s;
157 return *this;
158 }
159
160
161 template< class ct, int dim >
162 inline typename SPNormalVector< ct, dim >::This &
163 SPNormalVector< ct, dim >::operator/= ( const field_type &s )
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 >
185 inline typename SPNormalVector< ct, dim >::field_type
186 SPNormalVector< ct, dim >::operator* ( const This &other ) const
187 {
188 return (i_ == other.i_ ? p_ * other.p_ : field_type( 0 ));
189 }
190
191
192 template< class ct, int dim >
193 inline typename SPNormalVector< ct, dim >::field_type
194 SPNormalVector< ct, dim >::operator* ( const FieldVector &other ) const
195 {
196 return p_ * other[ i_ ];
197 }
198
199
200 template< class ct, int dim >
201 inline typename SPNormalVector< ct, dim >::field_type
202 SPNormalVector< ct, dim >::one_norm () const
203 {
204 return std::abs( p_ );
205 }
206
207
208 template< class ct, int dim >
209 inline typename SPNormalVector< ct, dim >::field_type
210 SPNormalVector< ct, dim >::two_norm () const
211 {
212 return std::abs( p_ );
213 }
214
215
216 template< class ct, int dim >
217 inline typename SPNormalVector< ct, dim >::field_type
218 SPNormalVector< ct, dim >::two_norm2 () const
219 {
220 return p_ * p_;
221 }
222
223
224 template< class ct, int dim >
225 inline typename SPNormalVector< ct, dim >::field_type
226 SPNormalVector< ct, dim >::infinity_norm () const
227 {
228 return std::abs( p_ );
229 }
230
231
232
233 // Auxilliary Functions for SPNormalId
234 // -----------------------------------
235
236 template< int dim >
237 inline SPMultiIndex< dim > operator+ ( const SPMultiIndex< dim > &idA, const SPNormalId< dim > &idB )
238 {
239 SPMultiIndex< dim > idC( idA );
240 idC[ idB.axis()] += idB.sign();
241 return idC;
242 }
243
244
245 template< int dim >
246 inline SPMultiIndex< dim > operator+ ( const SPNormalId< dim > &idA, const SPMultiIndex< dim > &idB )
247 {
248 SPMultiIndex< dim > idC( idB );
249 idC[ idA.axis() ] += idA.sign();
250 return idC;
251 }
252
253
254 template< int dim >
255 inline SPMultiIndex< dim > operator- ( const SPMultiIndex< dim > &idA, const SPNormalId< dim > &idB )
256 {
257 SPMultiIndex< dim > idC( idA );
258 idC[ idB.axis() ] -= idB.sign();
259 return idC;
260 }
261
262
263 template< int dim >
264 inline SPMultiIndex< dim > operator- ( const SPNormalId< dim > &idA, const SPMultiIndex< dim > &idB )
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
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Implements a vector constructed from a given type representing a field and a compile-time given size.
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:259
Dune namespace.
Definition: alignedallocator.hh:13
int sign(const T &val)
Return the sign of the value.
Definition: math.hh:180
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)