Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adtraits.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2008-02-14
7 
8  Copyright (C) 2008 Universite Joseph Fourier (Grenoble I)
9  Copyright (C) 2013 Feel++ Consortium
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef __ADTraits_H
31 #ifdef __GNUG__
32 #pragma interface
33 #endif
34 #define __ADTraits_H 1
35 
36 #include <complex>
37 
38 #if defined( FEELPP_USES_BOOST_INTERVAL )
39 
40 #ifndef BOOST_UBLAS_USE_INTERVAL
41 # define BOOST_UBLAS_USE_INTERVAL
42 #endif
43 
44 #include <boost/numeric/interval.hpp>
45 #endif
46 
47 namespace Feel
48 {
49 #if defined( FEELPP_USES_BOOST_INTERVAL )
50 using namespace boost::numeric;
51 using namespace boost::numeric::interval_lib;
52 
53 template<class T>
54 class my_checking_base
55  :
56 public boost::numeric::interval_lib::checking_base<T>
57 {
58 public:
59  static bool is_nan( const T& x )
60  {
61  //return std::numeric_limits<T>::has_quiet_NaN && (x != x);
62  return false;
63  }
64  static bool is_empty( const T& l, const T& u )
65  {
66  //return !(l <= u); // safety for partial orders
67  return false;
68  }
69 };
70 typedef boost::numeric::interval_lib::policies<boost::numeric::interval_lib::save_state<boost::numeric::interval_lib::rounded_transc_exact<double> >, my_checking_base<double> > interval_policy_exact_type;
71 typedef boost::numeric::interval_lib::policies<boost::numeric::interval_lib::save_state<boost::numeric::interval_lib::rounded_transc_opp<double> >, my_checking_base<double> > interval_policy_opp_type;
72 typedef boost::numeric::interval_lib::policies<boost::numeric::interval_lib::save_state<boost::numeric::interval_lib::rounded_transc_std<double> >, my_checking_base<double> > interval_policy_std_type;
73 
74 typedef boost::numeric::interval_lib::default_policies<double>::type interval_policy_default_type;
75 
76 template<class T, class P>
77 struct interval
78 {
79  typedef boost::numeric::interval<T,P> type;
80 };
81 #endif // FEELPP_USES_BOOST_INTERVAL
82 
83 template <class A, class B>
84 class SNumericalTraits
85 {
86 public:
87 };
88 
89 //Specialization
90 template <class T>
91 class SNumericalTraits<T,T>
92 {
93 public:
94  typedef T promote;
95 };
96 
97 #define NUMERICAL_TRAITS(type1,type2,type3) \
98 template <> class SNumericalTraits<type1,type2> { \
99 public: \
100  typedef type3 promote; \
101 }; \
102 template <> class SNumericalTraits<type2,type1> { \
103 public: \
104  typedef type3 promote; \
105 };
106 
107 #if defined( FEELPP_USES_BOOST_INTERVAL )
108 #define INTERVAL_TRAITS( TYPE ) \
109 typedef interval<double, interval_policy_## TYPE ##_type>::type interval_## TYPE ##_type; \
110 NUMERICAL_TRAITS(interval_## TYPE ##_type,double,interval_## TYPE ##_type) \
111 NUMERICAL_TRAITS(interval_## TYPE ##_type,float,interval_## TYPE ##_type) \
112 NUMERICAL_TRAITS(interval_## TYPE ##_type,long,interval_## TYPE ##_type) \
113 NUMERICAL_TRAITS(interval_## TYPE ##_type,int,interval_## TYPE ##_type)
114 
115 INTERVAL_TRAITS ( default );
116 INTERVAL_TRAITS ( exact );
117 INTERVAL_TRAITS ( opp );
118 INTERVAL_TRAITS ( std );
119 
120 #undef INTERVAL_TRAITS
121 #endif // FEELPP_USES_BOOST_INTERVAL
122 
123 NUMERICAL_TRAITS( double,std::complex<float>,std::complex<double> )
124 NUMERICAL_TRAITS( double,float,double )
125 NUMERICAL_TRAITS( double,long,double )
126 NUMERICAL_TRAITS( double,int,double )
127 NUMERICAL_TRAITS( float,long,float )
128 NUMERICAL_TRAITS( float,int,float )
129 
130 
131 #if defined( FEELPP_USES_BOOST_INTERVAL )
132 #define FEELPP_INTERVAL_DEBUG( TYPE ) \
133  SDebugStream& operator<<( SDebugStream& o, Feel::interval_## TYPE ##_type const& e ); \
134  SNDebugStream& operator<<( SNDebugStream& o, Feel::interval_## TYPE ##_type const& e );
135 
136 FEELPP_INTERVAL_DEBUG( default );
137 FEELPP_INTERVAL_DEBUG( std );
138 FEELPP_INTERVAL_DEBUG( opp );
139 FEELPP_INTERVAL_DEBUG( exact );
140 #undef FEELPP_INTERVAL_DEBUG
141 
142 #endif // FEELPP_USES_BOOST_INTERVAL
143 
144 }
145 namespace std
146 {
147 #if defined( FEELPP_USES_BOOST_INTERVAL )
148 template<typename T, typename P>
149 std::ostream& operator<< ( std::ostream& __os, boost::numeric::interval<T,P> const& __i )
150 {
151  __os << '[' << __i.lower() << ',' << __i.upper() << ']';
152  return __os;
153 }
154 #endif // FEELPP_USES_BOOST_INTERVAL
155 }
156 #endif /* __ADTraits_H */
157 
158 

Generated on Fri Oct 25 2013 14:24:03 for Feel++ by doxygen 1.8.4