|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72764 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/util libs/numeric/odeint/ideas/state_wrapper
From: mario.mulansky_at_[hidden]
Date: 2011-06-26 10:03:30
Author: mariomulansky
Date: 2011-06-26 10:03:29 EDT (Sun, 26 Jun 2011)
New Revision: 72764
URL: http://svn.boost.org/trac/boost/changeset/72764
Log:
added resizing to wrapper in ideas
Added:
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp (contents, props changed)
Binary files modified:
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/Jamfile
Text files modified:
sandbox/odeint/branches/karsten/boost/numeric/odeint/util/is_resizeable.hpp | 6 ++++--
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp | 39 +++++++++++++++++++++++++++++++++++----
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp | 13 +++++++++++++
3 files changed, 52 insertions(+), 6 deletions(-)
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/is_resizeable.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/is_resizeable.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/is_resizeable.hpp 2011-06-26 10:03:29 EDT (Sun, 26 Jun 2011)
@@ -23,7 +23,8 @@
template< class Container >
struct is_resizeable
{
- struct type : public boost::false_type { };
+ //struct type : public boost::false_type { };
+ typedef boost::false_type type;
const static bool value = type::value;
};
@@ -33,7 +34,8 @@
template< class V, class A >
struct is_resizeable< std::vector< V , A > >
{
- struct type : public boost::true_type { };
+ //struct type : public boost::true_type { };
+ typedef boost::true_type type;
const static bool value = type::value;
};
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/Jamfile
==============================================================================
Binary files. No diff available.
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp 2011-06-26 10:03:29 EDT (Sun, 26 Jun 2011)
@@ -4,10 +4,40 @@
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
-#include <boost/numeric/odeint/util/resize.hpp>
+#include <boost/numeric/odeint/util/is_resizeable.hpp>
+#include <boost/type_traits/integral_constant.hpp>
+
+
+template< class V , typename resizeable = typename boost::numeric::odeint::is_resizeable< V >::type>
+struct state_wrapper;
+
+//two standard implementations, with and without resizing depending on is_resizeable< StateType >
+
+template< class V >
+struct state_wrapper< V , boost::true_type > // with resizing
+{
+ typedef typename V::value_type value_type;
+
+ V m_v;
+
+ state_wrapper() : m_v() { }
+
+ template< class StateIn >
+ bool same_size( const StateIn &x ) const
+ {
+ return ( boost::size( m_v ) == boost::size( x ) );
+ }
+
+ template< class StateIn >
+ void resize( const StateIn &x )
+ {
+ m_v.resize( x.size() );
+ }
+};
+
template< class V >
-struct state_wrapper
+struct state_wrapper< V , boost::false_type > // without resizing
{
typedef typename V::value_type value_type;
@@ -15,6 +45,7 @@
state_wrapper() : m_v() { }
+ //no resize method
};
@@ -45,9 +76,9 @@
template< class State >
bool adjust_size( const State &x )
{
- if( boost::numeric::odeint::same_size( x , m_dxdt.m_v ) )
+ if( m_dxdt.same_size( x ) )
{
- boost::numeric::odeint::resize( x , m_dxdt.m_v );
+ m_dxdt.resize( x );
return true;
} else
return false;
Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_array.cpp 2011-06-26 10:03:29 EDT (Sun, 26 Jun 2011)
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <boost/array.hpp>
+
+#include "explicit_euler.hpp"
+#include "size_adjuster.hpp"
+
+using namespace std;
+
+typedef boost::array< double , 3 > state_type;
+
+const double sigma = 10.0;
+const double R = 28.0;
+const double b = 8.0 / 3.0;
+
+void lorenz( const state_type &x , state_type &dxdt , double t )
+{
+ dxdt[0] = sigma * ( x[1] - x[0] );
+ dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
+ dxdt[2] = x[0]*x[1] - b * x[2];
+}
+
+int main()
+{
+ explicit_euler< state_type , initially_resizer > euler;
+ //you would use never_resizer for arrays, but just to show that no resizing is called
+ //even with initially_resizer I use this one here.
+
+ state_type x;
+ x[0] = 1.0; x[1] = 1.0; x[2] = 2.0;
+
+ euler.do_step( lorenz , x , 0.0 , 0.1 );
+
+ cout << x[0] << " " << x[1] << " " << x[2] << endl;
+}
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp 2011-06-26 10:03:29 EDT (Sun, 26 Jun 2011)
@@ -37,6 +37,19 @@
gsl_vector_free( m_v );
}
+ bool same_size( const gsl_vector *x )
+ {
+ return ( m_v->size == x->size );
+ }
+
+ void resize( const gsl_vector *x )
+ {
+ if( x->size == 0 ) return;
+
+ gsl_vector_free( m_v );
+ m_v = gsl_vector_alloc( x->size );
+ }
+
};
int main() {
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk