5#ifndef DUNE_LOCALFUNCTIONS_UTILITY_FIELD_HH
6#define DUNE_LOCALFUNCTIONS_UTILITY_FIELD_HH
8#include <dune/common/gmpfield.hh>
9#include <dune/common/fvector.hh>
10#include <dune/common/fmatrix.hh>
28 template<
class Field >
31 operator Field ()
const
37 template<
class Field >
43 template<
class Field >
44 Field operator- (
const Unity< Field > &u,
const Field &f )
49 template<
class Field >
50 Field operator* (
const Unity< Field > &u,
const Field &f )
55 template<
class Field >
56 Field operator/ (
const Unity< Field > &u,
const Field &f )
77 template<
class Field >
80 operator Field ()
const
84 static const Field epsilon()
91 template<
unsigned int precision >
92 struct Zero< GMPField< precision > >
94 typedef GMPField< precision > Field;
95 operator Field ()
const
99 static const Field epsilon()
106 template<
class Field >
107 inline bool operator == (
const Zero< Field > &,
const Field &f )
109 return ( f < Zero<Field>::epsilon() && f > -Zero<Field>::epsilon() );
112 template<
class Field >
113 inline bool operator == (
const Field &f,
const Zero< Field > &z)
118 template<
class Field >
119 inline bool operator< (
const Zero< Field > &,
const Field &f )
121 return f > Zero<Field>::epsilon();
124 template<
class Field >
125 inline bool operator< (
const Field &f,
const Zero< Field > & )
127 return f < -Zero<Field>::epsilon();
130 template<
class Field >
131 inline bool operator> (
const Zero< Field > &z,
const Field &f )
136 template<
class Field >
137 inline bool operator> (
const Field &f,
const Zero< Field > &z )
158 template<
class F2,
class F1 >
159 inline void field_cast (
const F1 &f1, F2 &f2 )
165 template<
unsigned int precision >
166 inline void field_cast (
const Dune::GMPField< precision > &f1,
double &f2 )
171 template<
unsigned int precision >
172 inline void field_cast (
const Dune::GMPField< precision > &f1,
long double &f2 )
178 template<
class F2,
class F1,
int dim >
179 inline void field_cast (
const Dune::FieldVector< F1, dim > &f1, Dune::FieldVector< F2, dim > &f2 )
181 for(
int d = 0; d < dim; ++d )
182 field_cast( f1[ d ], f2[ d ] );
184 template<
class F2,
class F1 >
185 inline void field_cast (
const Dune::FieldVector< F1, 1 > &f1, F2 &f2 )
187 field_cast( f1[ 0 ], f2 );
189 template<
class F2,
class F1 >
190 inline void field_cast (
const F1 &f1, Dune::FieldVector< F2, 1 > &f2 )
192 field_cast( f1, f2[ 0 ] );
195 template<
class F2,
class F1,
int rdim,
int cdim >
196 inline void field_cast (
const Dune::FieldMatrix< F1, rdim, cdim > &f1, Dune::FieldMatrix< F2, rdim, cdim > &f2 )
198 for(
int r = 0; r < rdim; ++r )
199 field_cast( f1[ r ], f2[ r ] );
201 template<
class F2,
class F1 >
202 inline void field_cast (
const Dune::FieldMatrix<F1,1,1> &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
204 field_cast( f1[ 0 ][ 0 ], f2[ 0 ][ 0 ] );
206 template<
class F2,
class F1 >
207 inline void field_cast (
const Dune::FieldMatrix< F1, 1,1 > &f1, F2 &f2 )
209 field_cast( f1[ 0 ][ 0 ], f2 );
211 template<
class F2,
class F1 >
212 inline void field_cast (
const F1 &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
214 field_cast( f1, f2[ 0 ][ 0 ] );
216 template<
class F2,
class F1 >
217 inline void field_cast (
const Dune::FieldVector<F1,1> &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
219 field_cast( f1[ 0 ], f2[ 0 ][ 0 ] );
221 template<
class F2,
class F1 >
222 inline void field_cast (
const Dune::FieldMatrix<F1,1,1> &f1, Dune::FieldVector< F2, 1 > &f2 )
224 field_cast( f1[ 0 ][ 0 ], f2[ 0 ] );
227 template<
class F2,
class F1 >
228 inline void field_cast (
const Dune::FieldVector< F1, 1 > &f1, Dune::FieldVector<F2, 1> &f2 )
230 field_cast( f1[ 0 ], f2[ 0 ] );
233 template<
class F2,
class V >
238 template<
class F2,
class F1,
int dim >
239 struct FieldCast< F2, Dune::FieldVector<F1,dim> >
241 typedef Dune::FieldVector<F2,dim> type;
243 template<
class F2,
class F1,
int dim1,
int dim2>
244 struct FieldCast< F2, Dune::FieldMatrix<F1,dim1,dim2> >
246 typedef Dune::FieldMatrix<F2,dim1,dim2> type;
248 template<
class F2,
class V >
249 inline typename FieldCast<F2,V>::type field_cast (
const V &f1 )
251 typename FieldCast<F2,V>::type f2;
252 field_cast( f1, f2 );
263 template <
class Field>
267 struct Precision< double >
269 static const unsigned int value = 64;
273 struct Precision< long double >
275 static const unsigned int value = 80;
279 struct Precision< float >
281 static const unsigned int value = 32;
285 template<
unsigned int precision >
286 struct Precision< GMPField< precision > >
288 static const unsigned int value = precision;
295 template <
class Field,
unsigned int sum>
302 template<
unsigned int precision,
unsigned int sum >
303 struct ComputeField< GMPField< precision >, sum >
305 typedef GMPField<precision+sum> Type;
A class representing the unit of a given Field.
Definition: field.hh:30
A class representing the zero of a given Field.
Definition: field.hh:79