headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
344 stars 101 forks source link

a patch to support modified_midpoint with Thrust operations #47

Closed slayoo closed 12 years ago

slayoo commented 12 years ago
diff --git a/boost/numeric/odeint/external/thrust/thrust_operations.hpp b/boost/numeric/odeint/external/thrust/thrust_operations.hpp
index be79f17..710657a 100644
--- a/boost/numeric/odeint/external/thrust/thrust_operations.hpp
+++ b/boost/numeric/odeint/external/thrust/thrust_operations.hpp
@@ -46,6 +46,25 @@ struct thrust_operations
         }
     };

+    template< class Fac1 = double , class Fac2 = Fac1 >
+    struct scale_sum_swap2
+    {
+        const Fac1 m_alpha1;
+        const Fac2 m_alpha2;
+
+        scale_sum_swap2( const Fac1 alpha1 , const Fac2 alpha2 )
+        : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
+
+        template< class Tuple >
+        __host__ __device__
+        void operator()( Tuple t ) const
+        {
+            typename thrust::tuple_element<0,Tuple>::type tmp = thrust::get<0>(t);
+            thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t);
+            thrust::get<1>(t) = tmp;
+        }
+    };
+
     template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 >
     struct scale_sum3
     {
headmyshoulder commented 12 years ago

Thank you, I applied your patch and commited it into the trunk. Why do you need the modified_midpoint?

slayoo commented 12 years ago

We're allowing to choose the integration method at runtime, and I've simply tried to pick a set of basic methods to be available to choose from: euler, rk4, mmid. The mmid needed this fix to compile. S.

headmyshoulder commented 12 years ago

The midpoint method is used for the bulirsch stoer stepper and it has some special features needed in bulirsch stoer. You can easily create the midpoint method from scratch by using the generic steppers, see the example in the docs: http://headmyshoulder.github.com/odeint-v2/doc/boost_numeric_odeint/odeint_in_detail/steppers.html#boost_numeric_odeint.odeint_in_detail.steppers.writing_own_runge_kutta_steppers

headmyshoulder commented 12 years ago

Done