Skip to content

Instantly share code, notes, and snippets.

@headmyshoulder
Created August 18, 2014 18:58
Show Gist options
  • Save headmyshoulder/4f11f000cf80e6da59d6 to your computer and use it in GitHub Desktop.
Save headmyshoulder/4f11f000cf80e6da59d6 to your computer and use it in GitHub Desktop.
Odeint and inheritance
#include <boost/numeric/odeint.hpp>
#include <iostream>
using namespace std;
using namespace boost::numeric::odeint;
using state_type = std::array< double , 2 >;
struct base
{
virtual ~base( void ) {}
// virtual void operator()( const state_type& x , state_type& dxdt , double t ) = 0;
virtual void operator()( const state_type& x , state_type& dxdt , double t )
{
cout << "base" << endl;
}
void do_something( void )
{
bulirsch_stoer< state_type > bs;
double t { 0.0 };
double dt { 0.0 };
state_type x { 1.0 , 0.0 };
bs.try_step( boost::ref( *this ) , x , t , dt );
}
void do_something2( void )
{
bulirsch_stoer_dense_out< state_type > bs;
double t { 0.0 };
double dt { 0.0 };
state_type x { 1.0 , 0.0 };
bs.initialize( x , t , dt );
auto tt = bs.do_step( boost::ref( *this ) );
}
};
struct derived : public base
{
void operator()( const state_type& x , state_type& dxdt , double t ) override
{
dxdt[0] = x[1];
dxdt[1] = -x[0];
cout << "derived" << endl;
}
};
int main( int argc , char *argv[] )
{
derived d;
d.do_something();
d.do_something2();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment