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
feelcore/feel.hpp
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: 2006-12-30
7 
8  Copyright (C) 2006,2007,2008,2009,2010 Université de Grenoble 1
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 # ifndef __cplusplus
30 # error You must use C++ for Feel
31 # endif
32 
33 # ifndef _FEELPP_HH_
34 # define _FEELPP_HH_
35 
36 #include <complex>
37 
38 #include <boost/mpl/multiplies.hpp>
39 #include <boost/mpl/list.hpp>
40 #include <boost/mpl/lower_bound.hpp>
41 #include <boost/mpl/transform_view.hpp>
42 #include <boost/mpl/sizeof.hpp>
43 #include <boost/mpl/int.hpp>
44 #include <boost/mpl/identity.hpp>
45 #include <boost/mpl/base.hpp>
46 #include <boost/mpl/deref.hpp>
47 #include <boost/mpl/begin_end.hpp>
48 #include <boost/mpl/comparison.hpp>
49 
50 #include <boost/tokenizer.hpp>
51 #include <boost/token_functions.hpp>
52 #include <boost/algorithm/string/split.hpp>
53 #include <boost/algorithm/string/classification.hpp>
54 
55 #include <boost/assign/list_of.hpp>
56 
57 #include <boost/math/constants/constants.hpp>
58 
59 #include <boost/lambda/lambda.hpp>
60 #include <boost/lambda/bind.hpp>
61 
62 #include <boost/mpi.hpp>
63 
64 #include <boost/program_options.hpp>
65 
66 #include <boost/cstdint.hpp>
67 
68 #include <boost/filesystem/operations.hpp>
69 #include <boost/filesystem/fstream.hpp>
70 
71 #include <boost/format.hpp>
72 #include <boost/foreach.hpp>
73 
74 #include <cmath>
75 #include <numeric>
76 #include <string>
77 #include <limits>
78 #include <iosfwd>
79 
80 #include <glog/logging.h>
81 
82 #include <feel/feelconfig.h>
83 #include <feel/feelcore/info.hpp>
86 
87 #include <feel/feelcore/flags.hpp>
89 
90 #if defined( FEELPP_HAS_TBB )
91 #include <tbb/tick_count.h>
92 #include <tbb/blocked_range.h>
93 #include <tbb/parallel_for.h>
94 #include <tbb/parallel_reduce.h>
95 #include <tbb/task_scheduler_init.h>
96 #include <tbb/mutex.h>
97 #endif // FEELPP_HAS_TBB
98 
99 
100 
101 namespace Feel
102 {
103 namespace assign = boost::assign;
104 namespace fs = boost::filesystem;
105 namespace mpl = boost::mpl;
106 namespace lambda = boost::lambda;
107 namespace po = boost::program_options;
108 namespace mpi=boost::mpi;
109 namespace constants=boost::math::constants;
110 //namespace constants = boost::math::constants;
111 //using boost::math::double_constants;
112 const double pi = constants::pi<double>();
113 const double two_pi = constants::two_pi<double>();
114 
115 namespace algorithm=boost::algorithm;
116 using google::WARNING;
117 using google::ERROR;
118 using google::INFO;
119 using google::FATAL;
120 
121 namespace detail
122 {
123 /*
124  "inline" is used for ignore_unused_variable_warning()
125  and function_requires() to make sure there is no
126  overhead with g++.
127  (ripped from boost/concept_check.hpp in order to avoid importing a huge header)
128 
129  \code
130  void f( int q )
131  {
132  // q is not used before the check
133  FEELPP_ASSERT( q ).error( "q <= 0" );
134  // q is not used after the check
135 
136  // this ensures that in -DNDEBUG there are no warnings about
137  // unused parameter
138  detail::ignore_unused_variable_warning( q );
139  }
140  \endcode
141  */
142 template <class T> inline void ignore_unused_variable_warning( const T& ) { }
143 }
144 
181 typedef double Real;
182 typedef double scalar_type;
183 typedef std::complex<double> complex_type;
184 
185 //
186 // Create type that are machine independent
187 // \warning should test here the boost version
188 //
189 // only available in boost 1.32
190 #include <boost/mpl/eval_if.hpp>
191 
195 namespace detail
196 {
197 template<int bit_size>
198 class no_int
199 {
200 private:
201  no_int();
202 };
203 
204 template< int bit_size >
205 struct integer
206 {
207  typedef mpl::list<signed char,signed short, signed int, signed long int, signed long long> builtins_;
208  typedef typename mpl::base< typename mpl::lower_bound<
209  mpl::transform_view< builtins_, mpl::multiplies< mpl::sizeof_<mpl::placeholders::_1>, mpl::int_<8> >
210  >
211  , mpl::integral_c<size_t, bit_size>
212  >::type >::type iter_;
213 
214  typedef typename mpl::end<builtins_>::type last_;
215  typedef typename mpl::eval_if<
216  boost::is_same<iter_,last_>
217  , mpl::identity< no_int<bit_size> >
218  , mpl::deref<iter_>
219  >::type type;
220 };
221 
222 template< int bit_size >
223 struct real
224 {
225  typedef mpl::list<float, double, long double> builtins_;
226  typedef typename mpl::base< typename mpl::lower_bound<
227  mpl::transform_view< builtins_, mpl::multiplies< mpl::sizeof_<mpl::placeholders::_1>, mpl::int_<8> >
228  >
229  , mpl::integral_c<size_t, bit_size>
230  >::type >::type iter_;
231 
232  typedef typename mpl::end<builtins_>::type last_;
233  typedef typename mpl::eval_if<
234  boost::is_same<iter_,last_>
235  , mpl::identity< no_int<bit_size> >
236  , mpl::deref<iter_>
237  >::type type;
238 };
239 }
240 #if 0
241 typedef detail::integer<1>::type int1_type;
242 
243 typedef detail::integer<8>::type int8_type;
244 typedef detail::integer<16>::type int16_type;
245 typedef detail::integer<32>::type int32_type;
246 typedef detail::integer<64>::type int64_type;
247 typedef detail::integer<128>::type int128_type;
248 #else
249 typedef boost::int8_t int8_type;
250 typedef boost::int16_t int16_type;
251 typedef boost::int32_t int32_type;
252 #if !defined( BOOST_NO_INT64_T )
253 typedef boost::int64_t int64_type;
254 #endif // BOOST_NO_INT64_T
255 #endif // 0
256 typedef detail::real<32>::type real32_type;
257 typedef detail::real<64>::type real64_type;
258 
259 BOOST_STATIC_ASSERT( ( boost::is_same<real32_type, float>::value ) );
260 BOOST_STATIC_ASSERT( ( boost::is_same<real64_type, double>::value ) );
261 
265 namespace detail
266 {
267 template< int bit_size >
268 struct unsigned_integer
269 {
270  //typedef mpl::list<unsigned char,unsigned short, long unsigned int, long unsigned int, long unsigned long> builtins_;
271  typedef mpl::list<unsigned char,unsigned short, unsigned int, unsigned long int, unsigned long long> builtins_;
272  typedef typename mpl::base< typename mpl::lower_bound<
273  mpl::transform_view< builtins_
274  , mpl::multiplies< mpl::sizeof_<mpl::placeholders::_1>, mpl::int_<8> >
275  >
276  , mpl::integral_c<size_t, bit_size>
277  >::type >::type iter_;
278 
279  typedef typename mpl::end<builtins_>::type last_;
280  typedef typename mpl::eval_if<
281  boost::is_same<iter_,last_>
282  , mpl::identity< no_int<bit_size> >
283  , mpl::deref<iter_>
284  >::type type;
285 };
286 }
287 #if 0
288 typedef detail::unsigned_integer<1>::type uint1_type;
289 typedef detail::unsigned_integer<8>::type uint8_type;
290 typedef detail::unsigned_integer<16>::type uint16_type;
291 typedef detail::unsigned_integer<32>::type uint32_type;
292 typedef detail::unsigned_integer<64>::type uint64_type;
293 typedef detail::unsigned_integer<128>::type uint128_type;
294 #else
295 typedef boost::uint8_t uint8_type;
296 typedef boost::uint16_t uint16_type;
297 typedef boost::uint32_t uint32_type;
298 #if !defined( BOOST_NO_INT64_T )
299 typedef boost::uint64_t uint64_type;
300 
306 typedef int64_type flag_type;
307 
308 const int64_type invalid_flag_type_value = std::numeric_limits<int32_type>::min();
309 #else
310 typedef int32_type flag_type;
311 
312 const int32_type invalid_flag_type_value = std::numeric_limits<int32_type>::min();
313 #endif // BOOST_NO_INT64_T
314 #endif
315 typedef uint16_type dim_type;
317 
319 typedef size_t size_type;
320 
321 #if defined( __APPLE__ )
322 typedef unsigned int uint;
323 #endif // __APPLE__
324 //BOOST_MPL_ASSERT_MSG( ( boost::is_same<size_type,uint32_type>::value), NOT_SAME, (size_t, long unsigned int, uint32_type, uint64_type));
329 
333 const uint8_type invalid_uint8_type_value = uint8_type( -1 );
334 
338 const uint16_type invalid_uint16_type_value = uint16_type( -1 );
339 
343 const uint32_type invalid_uint32_type_value = uint32_type( -1 );
344 
345 #if !defined( BOOST_NO_INT64_T )
346 
349 const uint64_type invalid_uint64_type_value = uint64_type( -1 );
350 #endif // BOOST_NO_INT64_T
351 
355 
356 
361 
363 
364 } // end namespace Feel
365 
366 #include <boost/program_options.hpp>
367 #include <boost/date_time/posix_time/posix_time.hpp>
368 
369 namespace Feel
370 {
371 // alias for program_options namespace
372 namespace po = boost::program_options;
373 
374 std::string
375 prefixvm( std::string const& prefix,
376  std::string const& opt,
377  std::string const& sep="." );
378 
379 
380 // alias for date_time namespaces
381 namespace posix_time = boost::posix_time;
382 namespace gregorian = boost::gregorian;
383 
384 namespace meta
385 {
386 template<typename TheArgs>
387 struct remove_all
388 {
389  typedef typename boost::remove_pointer<
390  typename boost::remove_const<
391  typename boost::remove_reference<
392  TheArgs
393  >::type
394  >::type
395  >::type type;
396 };
397 }
398 }
399 
400 #if defined( FEELPP_HAS_ARPREC)
401 # define FEELPP_HAS_MP_REAL 1
402 #include <mp/mpreal.h>
403 #include <mp/mp.h>
404 #endif /* FEELPP_HAS_ARPREC */
405 
406 
407 #if defined( FEELPP_HAS_QDLIB ) || defined( FEELPP_HAS_QD_H )
408 # define FEELPP_HAS_DD_REAL 1
409 # define FEELPP_HAS_QD_REAL 1
410 # include <qd/dd.h>
411 # include <qd/qd.h>
412 # include <qd/fpu.h>
413 
414 
416 namespace std
417 {
418 template<>
419 struct numeric_limits<dd_real>
420 {
421  static const bool is_specialized = true;
422 
423  static const int digits = 32;
424  static const int digits10 = 32;
425  static const bool is_signed = true;
426  static const bool is_integer = false;
427  static const bool is_exact = false;
428  static const int radix = __FLT_RADIX__;
429  static dd_real epsilon() throw()
430  {
431  return dd_real::_eps;
432  }
433  static dd_real round_error() throw()
434  {
435  return 0.5;
436  }
437  static dd_real min() throw()
438  {
439  return dd_real::_eps;
440  }
441 };
442 
444 template<>
445 struct numeric_limits<qd_real>
446 {
447  static const bool is_specialized = true;
448 
449  static const int digits = 64;
450  static const int digits10 = 64;
451  static const bool is_signed = true;
452  static const bool is_integer = false;
453  static const bool is_exact = false;
454  static const int radix = __FLT_RADIX__;
455  static qd_real epsilon() throw()
456  {
457  return qd_real::_eps;
458  }
459  static qd_real round_error() throw()
460  {
461  return 0.5;
462  }
463 
464  static qd_real min() throw()
465  {
466  return qd_real::_eps;
467  }
468 
469 
470 };
471 }
472 
473 #endif /* FEELPP_HAS_QD */
474 
475 #if defined( FEELPP_HAS_MPFR )
476 #include <feel/feelcore/mpfr.hpp>
477 
478 namespace Feel
479 {
483 typedef mpfr::MpfrClass mp_type;
484 
490 typedef mp_prec_t mp_precision_type;
491 
501 inline void setMpPrecision( mp_precision_type __prec )
502 {
503  mpfr_set_default_prec ( __prec );
504 }
505 
506 const mp_type mp_eps = mpfr::pow( mp_type( 2 ), -mp_type::GetDefaultPrecision()+1 );
507 
508 }
509 #endif // FEELPP_HAS_MPFR
510 
511 
512 #include <boost/shared_ptr.hpp>
513 #include <boost/detail/is_xxx.hpp>
514 
515 namespace Feel
516 {
517 namespace detail
518 {
519 BOOST_DETAIL_IS_XXX_DEF( shared_ptr, boost::shared_ptr, 1 )
520 }
521 }
522 
523 #if defined(FEELPP_HAS_OPENMP)
524 #include <omp.h>
525 
526 #define OMP_SET_NUM_THREADS(num) omp_set_num_threads(num)
527 #define OMP_GET_NUM_THREADS omp_get_num_threads()
528 #define OMP_SET_DYNAMIC(num) omp_set_dynamic(num)
529 #define OMP_SET_NESTED(num) omp_set_nested(num)
530 
531 // openmp timing
532 #define OMP_GET_WTIME omp_get_wtime()
533 #define OMP_GET_WTICK omp_get_wtick()
534 
535 #else
536 #define OMP_SET_NUM_THREADS(num)
537 #define OMP_GET_NUM_THREADS 1
538 #define OMP_SET_DYNAMIC(num)
539 #define OMP_SET_NESTED(num)
540 
541 #define OMP_GET_WTIME 0
542 #define OMP_GET_WTICK 0
543 
544 #endif /* FEELPP_HAS_OPENMP */
545 
546 #if !defined( DVLOG_IF )
547 
548 #ifndef NDEBUG
549 #define DVLOG_IF(verboselevel, condition) VLOG(verboselevel)
550 #else
551 #define DVLOG_IF(verboselevel,condition) \
552  (true || ( !VLOG_IS_ON(verboselevel) && !(condition))) ? \
553  (void) 0 : google::LogMessageVoidify() & LOG(INFO)
554 #endif // NDEBUG
555 
556 #endif // DVLOG_IF
557 
558 #endif

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