3#ifndef DUNE_LOCALFUNCTIONS_UTILITY_FIELD_HH
4#define DUNE_LOCALFUNCTIONS_UTILITY_FIELD_HH
6#include <dune/common/gmpfield.hh>
7#include <dune/common/fvector.hh>
8#include <dune/common/fmatrix.hh>
26 template<
class Field >
29 operator Field ()
const
35 template<
class Field >
41 template<
class Field >
42 Field operator- (
const Unity< Field > &u,
const Field &f )
47 template<
class Field >
48 Field operator* (
const Unity< Field > &u,
const Field &f )
53 template<
class Field >
54 Field operator/ (
const Unity< Field > &u,
const Field &f )
75 template<
class Field >
78 operator Field ()
const
82 static const Field epsilon()
89 template<
unsigned int precision >
90 struct Zero< GMPField< precision > >
92 typedef GMPField< precision > Field;
93 operator Field ()
const
97 static const Field epsilon()
104 template<
class Field >
105 inline bool operator == (
const Zero< Field > &,
const Field &f )
107 return ( f < Zero<Field>::epsilon() && f > -Zero<Field>::epsilon() );
110 template<
class Field >
111 inline bool operator == (
const Field &f,
const Zero< Field > &z)
116 template<
class Field >
117 inline bool operator< (
const Zero< Field > &,
const Field &f )
119 return f > Zero<Field>::epsilon();
122 template<
class Field >
123 inline bool operator< (
const Field &f,
const Zero< Field > & )
125 return f < -Zero<Field>::epsilon();
128 template<
class Field >
129 inline bool operator> (
const Zero< Field > &z,
const Field &f )
134 template<
class Field >
135 inline bool operator> (
const Field &f,
const Zero< Field > &z )
156 template<
class F2,
class F1 >
157 inline void field_cast (
const F1 &f1, F2 &f2 )
163 template<
unsigned int precision >
164 inline void field_cast (
const Dune::GMPField< precision > &f1,
double &f2 )
169 template<
unsigned int precision >
170 inline void field_cast (
const Dune::GMPField< precision > &f1,
long double &f2 )
176 template<
class F2,
class F1,
int dim >
177 inline void field_cast (
const Dune::FieldVector< F1, dim > &f1, Dune::FieldVector< F2, dim > &f2 )
179 for(
int d = 0; d < dim; ++d )
180 field_cast( f1[ d ], f2[ d ] );
182 template<
class F2,
class F1 >
183 inline void field_cast (
const Dune::FieldVector< F1, 1 > &f1, F2 &f2 )
185 field_cast( f1[ 0 ], f2 );
187 template<
class F2,
class F1 >
188 inline void field_cast (
const F1 &f1, Dune::FieldVector< F2, 1 > &f2 )
190 field_cast( f1, f2[ 0 ] );
193 template<
class F2,
class F1,
int rdim,
int cdim >
194 inline void field_cast (
const Dune::FieldMatrix< F1, rdim, cdim > &f1, Dune::FieldMatrix< F2, rdim, cdim > &f2 )
196 for(
int r = 0; r < rdim; ++r )
197 field_cast( f1[ r ], f2[ r ] );
199 template<
class F2,
class F1 >
200 inline void field_cast (
const Dune::FieldMatrix<F1,1,1> &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
202 field_cast( f1[ 0 ][ 0 ], f2[ 0 ][ 0 ] );
204 template<
class F2,
class F1 >
205 inline void field_cast (
const Dune::FieldMatrix< F1, 1,1 > &f1, F2 &f2 )
207 field_cast( f1[ 0 ][ 0 ], f2 );
209 template<
class F2,
class F1 >
210 inline void field_cast (
const F1 &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
212 field_cast( f1, f2[ 0 ][ 0 ] );
214 template<
class F2,
class F1 >
215 inline void field_cast (
const Dune::FieldVector<F1,1> &f1, Dune::FieldMatrix< F2, 1,1 > &f2 )
217 field_cast( f1[ 0 ], f2[ 0 ][ 0 ] );
219 template<
class F2,
class F1 >
220 inline void field_cast (
const Dune::FieldMatrix<F1,1,1> &f1, Dune::FieldVector< F2, 1 > &f2 )
222 field_cast( f1[ 0 ][ 0 ], f2[ 0 ] );
225 template<
class F2,
class F1 >
226 inline void field_cast (
const Dune::FieldVector< F1, 1 > &f1, Dune::FieldVector<F2, 1> &f2 )
228 field_cast( f1[ 0 ], f2[ 0 ] );
231 template<
class F2,
class V >
236 template<
class F2,
class F1,
int dim >
237 struct FieldCast< F2, Dune::FieldVector<F1,dim> >
239 typedef Dune::FieldVector<F2,dim> type;
241 template<
class F2,
class F1,
int dim1,
int dim2>
242 struct FieldCast< F2, Dune::FieldMatrix<F1,dim1,dim2> >
244 typedef Dune::FieldMatrix<F2,dim1,dim2> type;
246 template<
class F2,
class V >
247 inline typename FieldCast<F2,V>::type field_cast (
const V &f1 )
249 typename FieldCast<F2,V>::type f2;
250 field_cast( f1, f2 );
261 template <
class Field>
265 struct Precision< double >
267 static const unsigned int value = 64;
271 struct Precision< long double >
273 static const unsigned int value = 80;
277 struct Precision< float >
279 static const unsigned int value = 32;
283 template<
unsigned int precision >
284 struct Precision< GMPField< precision > >
286 static const unsigned int value = precision;
293 template <
class Field,
unsigned int sum>
300 template<
unsigned int precision,
unsigned int sum >
301 struct ComputeField< GMPField< precision >, sum >
303 typedef GMPField<precision+sum> Type;
A class representing the unit of a given Field.
Definition: field.hh:28
A class representing the zero of a given Field.
Definition: field.hh:77