1#ifndef DUNE_FEM_DOUBLE_HH
2#define DUNE_FEM_DOUBLE_HH
14#include <dune/fem/io/streams/streams.hh>
15#include <dune/fem/misc/mpimanager.hh>
16#include <dune/fem/misc/threads/threadsafevalue.hh>
17#include <dune/fem/storage/singleton.hh>
27 template<
class FloatImp >
31 template <
class FloatImp>
34 typedef FlOpSummary< FloatImp > ThisType;
37 ThreadSafeValue< unsigned long > count_;
39 FlOpSummary(
const std::string& name) : name_(name), count_( 0 ) {}
43 unsigned long totalCount = 0;
44 for(
size_t i=0; i<count_.size(); ++i )
46 std::cout << name_ <<
" thread[ " << i <<
" ]: " << count_[ i ] << std::endl;
47 totalCount += count_[ i ];
50 std :: cout <<
"Total number of floating point operations (" << name_ <<
"): "
51 << totalCount << std :: endl;
54 inline void add(
const unsigned long count,
const int thread )
56 count_[ thread ] += count ;
61 static ThisType&
instance(
const std::string& name )
68 template<
class FloatImp >
72 typedef FloatImp FloatType;
75 typedef FlOpCounter< FloatType > ThisType;
83 : count_( 0 ), thread_( MPIManager::thread() )
85 FlOpSummary< FloatImp > :: instance( FloatImp::typeName() ) ;
89 inline ~FlOpCounter ()
91 FlOpSummary< FloatImp > :: instance( FloatImp::typeName() ).add( count_, thread_ );
94 inline ThisType &operator++ ()
100 inline ThisType &operator += (
const unsigned long i )
110 static thread_local ThisType
instance;
120 template<
class FloatImp >
124 typedef FloatImp FloatType;
127 typedef FlOpCounter< FloatType > ThisType;
130 inline FlOpCounter ()
135 inline ThisType &operator++ ()
140 inline ThisType &operator += (
const unsigned long i )
148 static thread_local ThisType instance;
150 static ThisType instance;
161 static double log (
const Double& v);
163 static double sqrt(
const Double& v);
165 static double cos (
const Double& v);
167 static double sin(
const Double& v);
170 static inline double min (
const Double& v,
const double p);
172 static inline double min (
const double v,
const Double& p);
174 static inline double max (
const Double& v,
const double p);
176 static inline double max (
const double v,
const Double& p);
185 typedef Double ThisType;
187 friend Double operator+ (
const Double&,
const Double& );
188 friend Double operator+ (
const Double&,
const double );
189 friend Double operator+ (
const double,
const Double& );
190 friend Double operator+ (
const Double&,
const int );
191 friend Double operator+ (
const int,
const Double& );
192 friend Double operator+ (
const Double&,
const unsigned int );
193 friend Double operator+ (
const unsigned int,
const Double& );
195 friend Double operator- (
const Double&,
const Double& );
196 friend Double operator- (
const Double&,
const double );
197 friend Double operator- (
const double,
const Double& );
198 friend Double operator- (
const Double&,
const int );
199 friend Double operator- (
const int,
const Double& );
200 friend Double operator- (
const Double&,
const unsigned int );
201 friend Double operator- (
const unsigned int,
const Double& );
203 friend Double operator* (
const Double&,
const Double& );
204 friend Double operator* (
const Double&,
const double );
205 friend Double operator* (
const double,
const Double& );
206 friend Double operator* (
const Double&,
const int );
207 friend Double operator* (
const int,
const Double& );
208 friend Double operator* (
const Double&,
const unsigned int );
209 friend Double operator* (
const unsigned int,
const Double& );
211 friend Double operator/ (
const Double&,
const Double& );
212 friend Double operator/ (
const double,
const Double& );
213 friend Double operator/ (
const Double&,
const double );
214 friend Double operator/ (
const int,
const Double& );
215 friend Double operator/ (
const Double&,
const int );
216 friend Double operator/ (
const unsigned int,
const Double& );
217 friend Double operator/ (
const Double&,
const unsigned int );
219 friend bool operator== (
const Double&,
const Double& );
220 friend bool operator== (
const double,
const Double& );
221 friend bool operator== (
const Double&,
const double );
222 friend bool operator== (
const int,
const Double& );
223 friend bool operator== (
const Double&,
const int );
224 friend bool operator== (
const unsigned int,
const Double& );
225 friend bool operator== (
const Double&,
const unsigned int );
227 friend bool operator!= (
const Double&,
const Double& );
228 friend bool operator!= (
const double,
const Double& );
229 friend bool operator!= (
const Double&,
const double );
230 friend bool operator!= (
const int,
const Double& );
231 friend bool operator!= (
const Double&,
const int );
232 friend bool operator!= (
const unsigned int,
const Double& );
233 friend bool operator!= (
const Double&,
const unsigned int );
235 friend bool operator< (
const Double&,
const Double& );
236 friend bool operator< (
const double,
const Double& );
237 friend bool operator< (
const Double&,
const double );
238 friend bool operator< (
const int,
const Double& );
239 friend bool operator< (
const Double&,
const int );
240 friend bool operator< (
const unsigned int,
const Double& );
241 friend bool operator< (
const Double&,
const unsigned int );
243 friend bool operator<= (
const Double&,
const Double& );
244 friend bool operator<= (
const double,
const Double& );
245 friend bool operator<= (
const Double&,
const double );
246 friend bool operator<= (
const int,
const Double& );
247 friend bool operator<= (
const Double&,
const int );
248 friend bool operator<= (
const unsigned int,
const Double& );
249 friend bool operator<= (
const Double&,
const unsigned int );
251 friend bool operator> (
const Double&,
const Double& );
252 friend bool operator> (
const double,
const Double& );
253 friend bool operator> (
const Double&,
const double );
254 friend bool operator> (
const int,
const Double& );
255 friend bool operator> (
const Double&,
const int );
256 friend bool operator> (
const unsigned int,
const Double& );
257 friend bool operator> (
const Double&,
const unsigned int );
259 friend bool operator>= (
const Double&,
const Double& );
260 friend bool operator>= (
const double,
const Double& );
261 friend bool operator>= (
const Double&,
const double );
262 friend bool operator>= (
const int,
const Double& );
263 friend bool operator>= (
const Double&,
const int );
264 friend bool operator>= (
const unsigned int,
const Double& );
265 friend bool operator>= (
const Double&,
const unsigned int );
267 friend std :: ostream &operator<< ( std :: ostream&,
const Double& );
268 friend std :: istream &
operator>> ( std :: istream&, Double& );
270 template<
class Traits >
271 friend OutStreamInterface< Traits > &
272 operator<< ( OutStreamInterface< Traits > &,
const Double );
273 template<
class Traits >
274 friend InStreamInterface< Traits > &
275 operator>> ( InStreamInterface< Traits > &, Double & );
277 friend double pow (
const Double& v,
const double p);
278 friend double pow (
const Double& v,
const Double& p);
279 friend double log (
const Double& v);
280 friend double sqrt(
const Double& v);
281 friend double sin(
const Double& v);
282 friend double cos(
const Double& v);
284 friend Double abs (
const Double & );
285 friend double min(
const Double&,
const double);
286 friend double min(
const double,
const Double&);
287 friend double max(
const Double&,
const double);
288 friend double max(
const double,
const Double&);
290 friend double real(
const std::complex<Double>& );
291 friend double real(
const Double& );
292 friend double imag(
const std::complex<Double>& );
293 friend double imag(
const Double& );
295#if DUNE_FEM_COMPATIBILITY
296 friend struct XdrIO< Double >;
299 friend void field_cast (
const Double &,
double & );
302 typedef FlOpCounter< ThisType > FlOpCounterType;
308 operator double ()
const
321 inline Double (
const double value )
325 inline Double (
const ThisType &other )
326 : value_( other.value_ )
329 inline ThisType &operator= (
const ThisType other )
332 value_ = other.value_;
336 inline ThisType &operator+= (
const ThisType other )
339 value_ += other.value_;
343 inline ThisType &operator-= (
const ThisType other )
346 value_ -= other.value_;
350 inline ThisType &operator*= (
const ThisType other )
353 value_ *= other.value_;
357 inline ThisType &operator/= (
const ThisType other )
360 value_ /= other.value_;
364 Double operator- ()
const
367 return Double( -value_ );
370 static std :: string typeName ()
376 static inline void flOp ()
378 ++(FlOpCounterType :: instance());
386 static inline double min (
const Double& v,
const double p)
388 return (v.value_ > p) ? p : v.value_;
392 static inline double min (
const double v,
const Double& p)
394 return (v > p.value_) ? p.value_ : v;
398 static inline double max (
const Double& v,
const double p)
400 return (v.value_ < p) ? p : v.value_;
404 static inline double max (
const double v,
const Double& p)
406 return (v < p.value_) ? p.value_ : v;
412 inline Double operator+ (
const Double &a,
const Double &b )
415 return Double( a.value_ + b.value_ );
418 inline Double operator+ (
const double a,
const Double &b )
421 return Double( a + b.value_ );
424 inline Double operator+ (
const Double &a,
const double b )
427 return Double( a.value_ + b );
430 inline Double operator+ (
const int a,
const Double &b )
433 return Double( a + b.value_ );
436 inline Double operator+ (
const Double &a,
const int b )
439 return Double( a.value_ + b );
442 inline Double operator+ (
const unsigned int a,
const Double &b )
445 return Double( a + b.value_ );
448 inline Double operator+ (
const Double &a,
const unsigned int b )
451 return Double( a.value_ + b );
459 inline Double operator- (
const Double &a,
const Double &b )
462 return Double( a.value_ - b.value_ );
465 inline Double operator- (
const double a,
const Double &b )
468 return Double( a - b.value_ );
471 inline Double operator- (
const Double &a,
const double b )
474 return Double( a.value_ - b );
477 inline Double operator- (
const int a,
const Double &b )
480 return Double( a - b.value_ );
483 inline Double operator- (
const Double &a,
const int b )
486 return Double( a.value_ - b );
489 inline Double operator- (
const unsigned int a,
const Double &b )
492 return Double( a - b.value_ );
495 inline Double operator- (
const Double &a,
const unsigned int b )
498 return Double( a.value_ - b );
506 inline Double operator* (
const Double &a,
const Double &b )
509 return Double( a.value_ * b.value_ );
512 inline Double operator* (
const double a,
const Double &b )
515 return Double( a * b.value_ );
518 inline Double operator* (
const Double &a,
const double b )
521 return Double( a.value_ * b );
524 inline Double operator* (
const int a,
const Double &b )
527 return Double( a * b.value_ );
530 inline Double operator* (
const Double &a,
const int b )
533 return Double( a.value_ * b );
536 inline Double operator* (
const unsigned int a,
const Double &b )
539 return Double( a * b.value_ );
542 inline Double operator* (
const Double &a,
const unsigned int b )
545 return Double( a.value_ * b );
553 inline Double operator/ (
const Double &a,
const Double &b )
556 return Double( a.value_ / b.value_ );
559 inline Double operator/ (
const double a,
const Double &b )
562 return Double( a / b.value_ );
565 inline Double operator/ (
const Double &a,
const double b )
568 return Double( a.value_ / b );
571 inline Double operator/ (
const int a,
const Double &b )
574 return Double( a / b.value_ );
577 inline Double operator/ (
const Double &a,
const int b )
580 return Double( a.value_ / b );
583 inline Double operator/ (
const unsigned int a,
const Double &b )
586 return Double( a / b.value_ );
589 inline Double operator/ (
const Double &a,
const unsigned int b )
592 return Double( a.value_ / b );
600 inline bool operator== (
const Double &a,
const Double &b )
602 return (a.value_ == b.value_);
605 inline bool operator== (
const double a,
const Double &b )
607 return (a == b.value_);
610 inline bool operator== (
const Double &a,
const double b )
612 return (a.value_ == b);
615 inline bool operator== (
const int a,
const Double &b )
617 return (a == b.value_);
620 inline bool operator== (
const Double &a,
const int b )
622 return (a.value_ == b);
625 inline bool operator== (
const unsigned int a,
const Double &b )
627 return (a == b.value_);
630 inline bool operator== (
const Double &a,
const unsigned int b )
632 return (a.value_ == b);
640 inline bool operator!= (
const Double &a,
const Double &b )
642 return (a.value_ != b.value_);
645 inline bool operator!= (
const double a,
const Double &b )
647 return (a != b.value_);
650 inline bool operator!= (
const Double &a,
const double b )
652 return (a.value_ != b);
655 inline bool operator!= (
const int a,
const Double &b )
657 return (a != b.value_);
660 inline bool operator!= (
const Double &a,
const int b )
662 return (a.value_ != b);
665 inline bool operator!= (
const unsigned int a,
const Double &b )
667 return (a != b.value_);
670 inline bool operator!= (
const Double &a,
const unsigned int b )
672 return (a.value_ != b);
680 inline bool operator< (
const Double &a,
const Double &b )
682 return (a.value_ < b.value_);
685 inline bool operator< (
const double a,
const Double &b )
687 return (a < b.value_);
690 inline bool operator< (
const Double &a,
const double b )
692 return (a.value_ < b);
695 inline bool operator< (
const int a,
const Double &b )
697 return (a < b.value_);
700 inline bool operator< (
const Double &a,
const int b )
702 return (a.value_ < b);
705 inline bool operator< (
const unsigned int a,
const Double &b )
707 return (a < b.value_);
710 inline bool operator< (
const Double &a,
const unsigned int b )
712 return (a.value_ < b);
720 inline bool operator<= (
const Double &a,
const Double &b )
722 return (a.value_ <= b.value_);
725 inline bool operator<= (
const double a,
const Double &b )
727 return (a <= b.value_);
730 inline bool operator<= (
const Double &a,
const double b )
732 return (a.value_ <= b);
735 inline bool operator<= (
const int a,
const Double &b )
737 return (a <= b.value_);
740 inline bool operator<= (
const Double &a,
const int b )
742 return (a.value_ <= b);
745 inline bool operator<= (
const unsigned int a,
const Double &b )
747 return (a <= b.value_);
750 inline bool operator<= (
const Double &a,
const unsigned int b )
752 return (a.value_ <= b);
760 inline bool operator> (
const Double &a,
const Double &b )
762 return (a.value_ > b.value_);
765 inline bool operator> (
const double a,
const Double &b )
767 return (a > b.value_);
770 inline bool operator> (
const Double &a,
const double b )
772 return (a.value_ > b);
775 inline bool operator> (
const int a,
const Double &b )
777 return (a > b.value_);
780 inline bool operator> (
const Double &a,
const int b )
782 return (a.value_ > b);
785 inline bool operator> (
const unsigned int a,
const Double &b )
787 return (a > b.value_);
790 inline bool operator> (
const Double &a,
const unsigned int b )
792 return (a.value_ > b);
800 inline bool operator>= (
const Double &a,
const Double &b )
802 return (a.value_ >= b.value_);
805 inline bool operator>= (
const double a,
const Double &b )
807 return (a >= b.value_);
810 inline bool operator>= (
const Double &a,
const double b )
812 return (a.value_ >= b);
815 inline bool operator>= (
const int a,
const Double &b )
817 return (a >= b.value_);
820 inline bool operator>= (
const Double &a,
const int b )
822 return (a.value_ >= b);
825 inline bool operator>= (
const unsigned int a,
const Double &b )
827 return (a >= b.value_);
830 inline bool operator>= (
const Double &a,
const unsigned int b )
832 return (a.value_ >= b);
840 inline std :: ostream &operator<< ( std :: ostream &out,
const Double &a )
842 return out << a.value_;
845 inline std :: istream &
operator>> ( std :: istream &in, Double &a )
847 return in >> a.value_;
850 template<
class Traits >
851 inline OutStreamInterface< Traits > &
852 operator<< ( OutStreamInterface< Traits > &out,
855 return out << a.value_;
858 template<
class Traits >
859 inline InStreamInterface< Traits > &
863 return in >> a.value_;
871 inline Double abs (
const Double &a )
873 return Double( std::abs( a.value_ ) );
876 static inline double log (
const Double& v)
878 return std::log(v.value_);
881 inline double pow (
const Double& a,
const double b )
883 return std::pow(a.value_, b);
886 static inline double sqrt(
const Double& v)
888 return std::sqrt(v.value_);
891 static inline double sin (
const Double& v)
893 return std::sin(v.value_);
896 static inline double cos(
const Double& v)
898 return std::cos(v.value_);
901 inline void field_cast (
const Double &f1,
double &f2 )
906 inline double real (
const std::complex<Double>& x)
908 return x.real().value_;
911 inline double real (
const Double& x)
916 inline double imag (
const std::complex<Double>& x)
918 return x.imag().value_;
921 inline double imag (
const Double& x)
928 using Fem :: Double ;
931 struct IsNumber< Double > :
public IsNumber< double > {};
932#if DUNE_VERSION_GT(DUNE_COMMON, 2, 6)
934 struct HasNaN < Double > :
public HasNaN < double > {};
942 inline Dune::Fem::Double abs (
const Dune::Fem::Double &a )
944 return Dune::Fem::abs( a );
947 inline Dune::Fem::Double pow(
const Dune::Fem::Double &a,
const Dune::Fem::Double &b )
949 return Dune::Fem::pow( a, b );
953 inline double min (
const Dune::Fem::Double& v,
const double p)
959 inline double min (
const double v,
const Dune::Fem::Double& p)
965 inline double max (
const Dune::Fem::Double& v,
const double p)
971 inline double max (
const double v,
const Dune::Fem::Double& p)
977 inline double sqrt(
const Dune::Fem::Double& v )
979 return Dune::Fem::sqrt( v );
983 inline double real (
const complex<Dune::Fem::Double>& x)
985 return Dune::Fem::real( x );
989 inline double real (
const Dune::Fem::Double& x)
991 return Dune::Fem::real( x );
995 inline double imag (
const complex<Dune::Fem::Double>& x)
997 return Dune::Fem::imag( x );
1001 inline double imag (
const Dune::Fem::Double& x)
1003 return Dune::Fem::imag( x );
1012 struct numeric_limits<
Dune::Fem::Double >
1014 static const bool is_specialized =
true;
1016 static const int radix = numeric_limits< double > :: radix;
1017 static const int digits = numeric_limits< double > :: digits;
1018 static const int digits10 = numeric_limits< double > :: digits10;
1020 static const bool is_signed = numeric_limits< double > :: is_signed;
1021 static const bool is_integer = numeric_limits< double > :: is_integer;
1022 static const bool is_exact = numeric_limits< double > :: is_exact;
1024 inline static Dune::Fem::Double
min () throw ()
1029 inline static Dune::Fem::Double
max () throw ()
1034 inline static Dune::Fem::Double epsilon () throw ()
1036 return Dune::Fem::Double( numeric_limits< double > :: epsilon() );
1039 inline static Dune::Fem::Double round_error () throw ()
1041 return Dune::Fem::Double( numeric_limits< double > :: round_error() );
1044 inline static Dune::Fem::Double infinity () throw ()
1046 return Dune::Fem::Double( numeric_limits< double > :: infinity() );
1049 inline static Dune::Fem::Double quiet_NaN () throw ()
1051 return Dune::Fem::Double( numeric_limits< double > :: quiet_NaN() );
1054 inline static Dune::Fem::Double signaling_NaN () throw ()
1056 return Dune::Fem::Double( numeric_limits< double > :: signaling_NaN() );
1059 inline static Dune::Fem::Double denorm_min () throw ()
1061 return Dune::Fem::Double( numeric_limits< double > :: denorm_min() );
1064 static const int min_exponent = numeric_limits< double > :: min_exponent;
1065 static const int max_exponent = numeric_limits< double > :: max_exponent;
1066 static const int min_exponent10 = numeric_limits< double > :: min_exponent10;
1067 static const int max_exponent10 = numeric_limits< double > :: max_exponent10;
1069 static const bool has_infinity = numeric_limits< double > :: has_infinity;
1070 static const bool has_quiet_NaN = numeric_limits< double > :: has_quiet_NaN;
1071 static const bool has_signaling_NaN = numeric_limits< double > :: has_signaling_NaN;
1072 static const float_denorm_style has_denorm = numeric_limits< double > :: has_denorm;
1073 static const bool has_denorm_loss = numeric_limits< double > :: has_denorm_loss;
1075 static const bool is_iec559 = numeric_limits< double > :: is_iec559;
1076 static const bool is_bounded = numeric_limits< double > :: is_bounded;
1077 static const bool is_modulo = numeric_limits< double > :: is_modulo;
1079 static const bool traps = numeric_limits< double > :: traps;
1080 static const bool tinyness_before = numeric_limits< double > :: tinyness_before;
1081 static const float_round_style round_style
1082 = numeric_limits< double > :: round_style;
1087 struct is_floating_point<
Dune::Fem::Double > :
public is_floating_point< double > {};
return singleton instance of given Object type.
Definition: singleton.hh:93
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:123
Various macros to work with Dune module version numbers.
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:638
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:684
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:661
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:238
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:706
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:260
Dune namespace.
Definition: alignedallocator.hh:13
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:159
Traits for type conversions and type information.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:20