|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72756 - sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper
From: mario.mulansky_at_[hidden]
Date: 2011-06-26 03:37:33
Author: mariomulansky
Date: 2011-06-26 03:37:29 EDT (Sun, 26 Jun 2011)
New Revision: 72756
URL: http://svn.boost.org/trac/boost/changeset/72756
Log:
prototype implementation of state_wrapper idea and new resizing concept in ideas/state_wrapper
Added:
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp (contents, props changed)
Text files modified:
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp | 26 ++++++++++++++++++--------
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp | 16 +++++++++-------
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp | 3 ++-
3 files changed, 29 insertions(+), 16 deletions(-)
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 03:37:29 EDT (Sun, 26 Jun 2011)
@@ -4,7 +4,7 @@
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
-#include <boost/numeric/odeint/util/size_adjuster.hpp>
+#include <boost/numeric/odeint/util/resize.hpp>
template< class V >
struct state_wrapper
@@ -18,7 +18,7 @@
};
-template< typename StateType >
+template< typename StateType , class Resizer >
class explicit_euler {
public:
@@ -27,23 +27,33 @@
typedef double time_type;
typedef StateType state_type;
typedef state_wrapper< state_type > wrapped_state_type;
+ typedef Resizer resizer_type;
- explicit_euler() : m_dxdt()
- {
- m_size_adjuster.register_state( 0 , m_dxdt.m_v );
- };
+ explicit_euler() : m_dxdt() , m_resizer()
+ { }
template< class System , class StateInOut >
void do_step( System system , StateInOut &inout , const time_type &t , const time_type &dt )
{
- m_size_adjuster.adjust_size( inout );
+ m_resizer.adjust_size( *this , inout );
system( inout , m_dxdt.m_v , t );
boost::numeric::odeint::range_algebra::for_each3( inout , inout , m_dxdt.m_v , typename boost::numeric::odeint::default_operations::template scale_sum2< value_type , time_type >( 1.0 , dt ) );
}
+ template< class State >
+ bool adjust_size( const State &x )
+ {
+ if( boost::numeric::odeint::same_size( x , m_dxdt.m_v ) )
+ {
+ boost::numeric::odeint::resize( x , m_dxdt.m_v );
+ return true;
+ } else
+ return false;
+ }
+
private:
- boost::numeric::odeint::size_adjuster< state_type , 1 > m_size_adjuster;
wrapped_state_type m_dxdt;
+ resizer_type m_resizer;
};
Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/size_adjuster.hpp 2011-06-26 03:37:29 EDT (Sun, 26 Jun 2011)
@@ -0,0 +1,54 @@
+#include <boost/numeric/odeint/util/is_resizeable.hpp>
+
+
+template< class Stepper , class State >
+bool adjust_size_by_resizeability( Stepper &stepper , const State &x , boost::true_type )
+{
+ return stepper.adjust_size( x );
+}
+
+template< class Stepper , class State>
+bool adjust_size_by_resizeability( Stepper &stepper , const State &x , boost::false_type )
+{
+ return false;
+}
+
+struct always_resizer
+{
+
+ template< class Stepper , class State >
+ bool adjust_size( Stepper& stepper, const State &x )
+ {
+ return adjust_size_by_resizeability( stepper , x , typename boost::numeric::odeint::is_resizeable< State >::type() );
+ stepper.resize( x );
+ }
+
+};
+
+
+struct initially_resizer
+{
+ bool m_initialized;
+
+ initially_resizer(): m_initialized( false )
+ { }
+
+ template< class Stepper , class State >
+ bool adjust_size( Stepper& stepper, const State &x )
+ {
+ if( !m_initialized )
+ {
+ m_initialized = true;
+ return adjust_size_by_resizeability( stepper , x , typename boost::numeric::odeint::is_resizeable< State >::type() );
+ }
+ return false;
+ }
+};
+
+
+struct never_resizer
+{
+ template< class Stepper , class State >
+ void adjust_size( Stepper& stepper, const State &x )
+ { }
+};
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 03:37:29 EDT (Sun, 26 Jun 2011)
@@ -2,11 +2,12 @@
#include <gsl/gsl_vector.h>
#include "explicit_euler.hpp"
+#include "size_adjuster.hpp"
#include <boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp>
using namespace std;
-typedef gsl_vector state_type;
+typedef gsl_vector* state_type;
const double sigma = 10.0;
const double R = 28.0;
@@ -28,18 +29,19 @@
state_wrapper( )
{
- m_v->owner = 0;
- m_v->size = 0;
- m_v->stride = 0;
- m_v->data = 0;
- m_v->block = 0;
+ m_v = gsl_vector_alloc( 1 );
+ }
+
+ ~state_wrapper()
+ {
+ gsl_vector_free( m_v );
}
};
int main() {
- explicit_euler< state_type > euler;
+ explicit_euler< state_type , initially_resizer > euler;
state_type x = gsl_vector_alloc( 3 );
gsl_vector_set( x , 0 , 1.0);
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_vector.cpp 2011-06-26 03:37:29 EDT (Sun, 26 Jun 2011)
@@ -2,6 +2,7 @@
#include <vector>
#include "explicit_euler.hpp"
+#include "size_adjuster.hpp"
using namespace std;
@@ -20,7 +21,7 @@
int main()
{
- explicit_euler< state_type > euler;
+ explicit_euler< state_type , initially_resizer > euler;
state_type x(3);
x[0] = 1.0; x[1] = 1.0; x[2] = 2.0;
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