Permalink
Browse files

introducing unit helper

  • Loading branch information...
headmyshoulder committed May 13, 2012
1 parent c0d4e5e commit 61b8f1a3077f140932cc0de82c8e325593d97913
Showing with 316 additions and 400 deletions.
  1. +12 −85 boost/numeric/odeint/algebra/default_operations.hpp
  2. +5 −5 boost/numeric/odeint/integrate/detail/integrate_n_steps.hpp
  3. +0 −35 boost/numeric/odeint/integrate/detail/units_helper.hpp
  4. +1 −1 boost/numeric/odeint/stepper/controlled_runge_kutta.hpp
  5. +123 −0 boost/numeric/odeint/util/unit_helper.hpp
  6. +12 −12 doc/boost_sandbox_numeric_odeint/concepts/controlled_stepper.html
  7. +15 −15 doc/boost_sandbox_numeric_odeint/concepts/dense_output_stepper.html
  8. +12 −12 doc/boost_sandbox_numeric_odeint/concepts/error_stepper.html
  9. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/implicit_system.html
  10. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/observer.html
  11. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/simple_symplectic_system.html
  12. +15 −15 doc/boost_sandbox_numeric_odeint/concepts/state_algebra_operations.html
  13. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/state_wrapper.html
  14. +15 −15 doc/boost_sandbox_numeric_odeint/concepts/stepper.html
  15. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/symplectic_system.html
  16. +9 −9 doc/boost_sandbox_numeric_odeint/concepts/system.html
  17. +0 −7 doc/boost_sandbox_numeric_odeint/getting_started/short_example.html
  18. +1 −2 doc/boost_sandbox_numeric_odeint/getting_started/usage__compilation__headers.html
  19. +0 −6 doc/boost_sandbox_numeric_odeint/odeint_in_detail/generation_functions.html
  20. +15 −15 doc/boost_sandbox_numeric_odeint/odeint_in_detail/integrate_functions.html
  21. +11 −22 doc/boost_sandbox_numeric_odeint/odeint_in_detail/state_types__algebras_and_operations.html
  22. +0 −18 doc/boost_sandbox_numeric_odeint/odeint_in_detail/steppers.html
  23. +1 −2 doc/boost_sandbox_numeric_odeint/odeint_in_detail/using_boost__range.html
  24. +10 −2 doc/boost_sandbox_numeric_odeint/odeint_in_detail/using_boost__ref.html
  25. +1 −9 doc/boost_sandbox_numeric_odeint/tutorial/chaotic_systems_and_lyapunov_exponents.html
  26. +0 −9 doc/boost_sandbox_numeric_odeint/tutorial/harmonic_oscillator.html
  27. +0 −6 doc/boost_sandbox_numeric_odeint/tutorial/solar_system.html
  28. +0 −20 doc/boost_sandbox_numeric_odeint/tutorial/special_topics.html
  29. +0 −4 doc/boost_sandbox_numeric_odeint/tutorial/stiff_systems.html
  30. +1 −15 doc/boost_sandbox_numeric_odeint/tutorial/using_cuda_and_thrust.html
  31. +2 −6 doc/index.html
  32. +1 −0 libs/numeric/odeint/doc/odeint.qbk
  33. +8 −7 libs/numeric/odeint/examples/thrust/Makefile
  34. +1 −1 libs/numeric/odeint/examples/thrust/lorenz_parameters.cu
@@ -22,77 +22,13 @@
#include <cmath> // for std::max
#include <boost/array.hpp>
-#ifndef __CUDACC__
-#include <boost/utility.hpp>
-#include <boost/units/quantity.hpp>
-#endif
+#include <boost/numeric/odeint/util/unit_helper.hpp>
+
namespace boost {
namespace numeric {
namespace odeint {
-/*
- * Conversion of boost::units for use in standard_operations::rel_error and standard_operations::maximum
- */
-namespace detail {
-
-template<class T>
-struct get_value_impl
-{
- static T value(const T &t)
- {
- return t;
- }
- typedef T result_type;
-};
-
-#ifndef __CUDACC__
-template<class Unit , class T>
-struct get_value_impl<boost::units::quantity<Unit , T> >
-{
- static T value(const boost::units::quantity<Unit , T> &t)
- {
- return t.value();
- }
- typedef T result_type;
-};
-#endif
-
-template<class T>
-typename get_value_impl<T>::result_type get_value(const T &t)
-{
- return get_value_impl<T>::value(t);
-}
-
-template<class T , class V>
-struct set_value_impl
-{
- static void set_value(T &t , const V &v)
- {
- t = v;
- }
-};
-
-#ifndef __CUDACC__
-template<class Unit , class T , class V>
-struct set_value_impl<boost::units::quantity<Unit , T> , V>
-{
- static void set_value(boost::units::quantity<Unit , T> &t , const V &v)
- {
- t = boost::units::quantity<Unit , T>::from_value(v);
- }
-};
-#endif
-
-template<class T , class V>
-
-void set_value(T &t , const V &v)
-{
- return set_value_impl<T , V>::set_value(t , v);
-}
-
-}
-
/*
@@ -507,9 +443,7 @@ struct default_operations
void operator()( T3 &t3 , const T1 &t1 , const T2 &t2 ) const
{
using std::abs;
- using detail::get_value;
- using detail::set_value;
- set_value( t3 , abs( get_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_value( t1 ) ) + m_a_dxdt * abs( get_value( t2 ) ) ) ) );
+ set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );
}
typedef void result_type;
@@ -540,10 +474,8 @@ struct default_operations
{
using std::abs;
using std::max;
- using detail::get_value;
- using detail::set_value;
- Fac1 x1 = abs( get_value( t1 ) ) , x2 = abs( get_value( t2 ) );
- set_value( t3 , abs( get_value( t3 ) ) / ( m_eps_abs + m_eps_rel * max( x1 , x2 ) ) );
+ Fac1 x1 = abs( get_unit_value( t1 ) ) , x2 = abs( get_unit_value( t2 ) );
+ set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * max( x1 , x2 ) ) );
}
typedef void result_type;
@@ -563,8 +495,7 @@ struct default_operations
{
using std::max;
using std::abs;
- using detail::get_value;
- Value a1 = abs( get_value( t1 ) ) , a2 = abs( get_value( t2 ) );
+ Value a1 = abs( get_unit_value( t1 ) ) , a2 = abs( get_unit_value( t2 ) );
return ( a1 < a2 ) ? a2 : a1 ;
}
@@ -589,8 +520,7 @@ struct default_operations
{
using std::abs;
using std::max;
- using detail::get_value;
- Res tmp = abs( get_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max( abs( x_old ) , abs( x ) ) );
+ Res tmp = abs( get_unit_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max( abs( x_old ) , abs( x ) ) );
return max( r , tmp );
}
};
@@ -610,10 +540,9 @@ struct default_operations
{
using std::abs;
using std::max;
- using detail::get_value;
- Res tmp = abs( get_value( x_err ) ) /
- ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_value( x_old ) ) + m_a_dxdt * abs( get_value( dxdt_old ) ) ) );
+ Res tmp = abs( get_unit_value( x_err ) ) /
+ ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( x_old ) ) + m_a_dxdt * abs( get_unit_value( dxdt_old ) ) ) );
return max( r , tmp );
}
};
@@ -635,8 +564,7 @@ struct default_operations
{
using std::abs;
using std::max;
- using detail::get_value;
- Res tmp = abs( get_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max( abs( x_old ) , abs( x ) ) );
+ Res tmp = abs( get_unit_value( x_err ) ) / ( m_eps_abs + m_eps_rel * max( abs( x_old ) , abs( x ) ) );
return r + tmp * tmp;
}
};
@@ -658,10 +586,9 @@ struct default_operations
{
using std::abs;
using std::max;
- using detail::get_value;
- Res tmp = abs( get_value( x_err ) ) /
- ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_value( x_old ) ) + m_a_dxdt * abs( get_value( dxdt_old ) ) ) );
+ Res tmp = abs( get_unit_value( x_err ) ) /
+ ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( x_old ) ) + m_a_dxdt * abs( get_unit_value( dxdt_old ) ) ) );
return r + tmp * tmp;
}
};
@@ -20,7 +20,7 @@
#include <boost/numeric/odeint/util/unwrap_reference.hpp>
#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
-#include <boost/numeric/odeint/integrate/detail/units_helper.hpp>
+#include <boost/numeric/odeint/util/unit_helper.hpp>
namespace boost {
namespace numeric {
@@ -53,7 +53,7 @@ Time integrate_n_steps(
stepper.do_step( system , start_state , time , dt );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
- time = start_time + static_cast< typename detail::unit_value_type<Time>::type >( step+1 ) * dt;
+ time = start_time + static_cast< typename unit_value_type<Time>::type >( step+1 ) * dt;
}
obs( start_state , time );
@@ -80,7 +80,7 @@ Time integrate_n_steps(
null_observer() , controlled_stepper_tag() );
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
- time = start_time + static_cast< typename detail::unit_value_type<Time>::type >(step+1) * time_step;
+ time = start_time + static_cast< typename unit_value_type<Time>::type >(step+1) * time_step;
}
obs( start_state , time );
@@ -98,7 +98,7 @@ Time integrate_n_steps(
typename odeint::unwrap_reference< Observer >::type &obs = observer;
Time time = start_time;
- const Time end_time = start_time + static_cast< typename detail::unit_value_type<Time>::type >(num_of_steps) * dt;
+ const Time end_time = start_time + static_cast< typename unit_value_type<Time>::type >(num_of_steps) * dt;
stepper.initialize( start_state , time , dt );
@@ -112,7 +112,7 @@ Time integrate_n_steps(
++step;
// direct computation of the time avoids error propagation happening when using time += dt
// we need clumsy type analysis to get boost units working here
- time = start_time + static_cast< typename detail::unit_value_type<Time>::type >(step) * dt;
+ time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * dt;
}
// we have not reached the end, do another real step
@@ -1,35 +0,0 @@
-/*
- * units_helper.hpp
- *
- * Created on: Mar 19, 2012
- * Author: mario
- */
-
-#ifndef UNITS_HELPER_HPP_
-#define UNITS_HELPER_HPP_
-
-#include <boost/units/quantity.hpp>
-
-namespace boost {
-namespace numeric {
-namespace odeint {
-namespace detail {
-
-template< class T >
-struct unit_value_type {
- typedef T type;
-};
-
-
-template< class Unit , class Y >
-struct unit_value_type< boost::units::quantity<Unit , Y > > {
- typedef Y type;
-};
-
-
-}
-}
-}
-}
-
-#endif /* UNITS_HELPER_HPP_ */
@@ -80,7 +80,7 @@ class default_error_checker
{
// this overwrites x_err !
algebra.for_each3( x_err , x_old , dxdt_old ,
- typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * detail::get_value( dt ) ) );
+ typename operations_type::template rel_error< value_type >( m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt * get_unit_value( dt ) ) );
value_type res = algebra.reduce( x_err ,
typename operations_type::template maximum< value_type >() , static_cast< value_type >( 0 ) );
@@ -0,0 +1,123 @@
+/*
+ [auto_generated]
+ boost/numeric/odeint/util/unit_helper.hpp
+
+ [begin_description]
+ Get and set the the value of a unit.
+ [end_description]
+
+ Copyright 2009-2011 Karsten Ahnert
+ Copyright 2009-2011 Mario Mulansky
+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or
+ copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+
+#ifndef BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
+
+
+#ifndef __CUDACC__
+#include <boost/units/quantity.hpp>
+#endif
+
+
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+
+namespace detail {
+
+ template<class T>
+ struct get_unit_value_impl
+ {
+ static T value(const T &t)
+ {
+ return t;
+ }
+ typedef T result_type;
+ };
+
+ #ifndef __CUDACC__
+ template<class Unit , class T>
+ struct get_unit_value_impl< boost::units::quantity< Unit , T> >
+ {
+ static T value( const boost::units::quantity< Unit , T> &t )
+ {
+ return t.value();
+ }
+ typedef T result_type;
+ };
+ #endif
+
+
+
+
+
+ template<class T , class V>
+ struct set_unit_value_impl
+ {
+ static void set_value(T &t , const V &v)
+ {
+ t = v;
+ }
+ };
+
+ #ifndef __CUDACC__
+ template<class Unit , class T , class V>
+ struct set_unit_value_impl<boost::units::quantity<Unit , T> , V>
+ {
+ static void set_value(boost::units::quantity<Unit , T> &t , const V &v)
+ {
+ t = boost::units::quantity<Unit , T>::from_value(v);
+ }
+ };
+ #endif
+
+
+
+} // namespace detail
+
+template<class T>
+typename detail::get_unit_value_impl<T>::result_type get_unit_value(const T &t)
+{
+ return detail::get_unit_value_impl<T>::value(t);
+}
+
+
+template<class T , class V>
+
+void set_unit_value(T &t , const V &v)
+{
+ return detail::set_unit_value_impl<T , V>::set_value(t , v);
+}
+
+
+
+template< class T >
+struct unit_value_type
+{
+ typedef T type;
+};
+
+#ifndef __CUDACC__
+template< class Unit , class Y >
+struct unit_value_type< boost::units::quantity< Unit , Y > >
+{
+ typedef Y type;
+};
+#endif
+
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif // BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
Oops, something went wrong.

0 comments on commit 61b8f1a

Please sign in to comment.