Page MenuHomec4science

mtest.cpp
No OneTemporary

File Metadata

Created
Sun, Nov 17, 03:38

mtest.cpp

#define WITH_OBSERVER_MICHA
#include <iostream>
#include <boost/range/algorithm.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
typedef double state_type;
class KeepLast{
protected:
state_type last;
double time;
public:
KeepLast(){}
KeepLast(state_type x):last(x){}
void operator()(const state_type& x, double t){last=x;time=t;};
// void resize(uint n){last.resize(n);}
state_type& getState(){return last;}
double getTime(){return time;}
void setTime(double t){time=t;}
};
// void KeepLast::operator()(const state_type& x, double t){
// for(uint i=0;i<x.size();i++){
// last[i] =x[i];
// }
// time=t;
// }
typedef runge_kutta_cash_karp54< state_type > error_stepper_type;
//typedef runge_kutta_cash_dopri5< state_type > error_stepper_type;
class Myode{
public:
void operator()(const state_type& x, state_type& dxdt, const double t){dxdt=-1-x;}
static bool done(const state_type &x){cout<<x<<endl;return x<=0.0;}
};
int main(int argc, char* argv[]){
Myode ode;
KeepLast obs;
state_type x=20.0;
auto stepper = make_controlled< error_stepper_type >( 1.0e-10 , 1.0e-6 );
// auto stepper = make_dense_output( 1.0e-6 , 1.0e-5 , runge_kutta_dopri5< state_type >());
auto iter= boost::find_if(make_adaptive_range(stepper,ode,x,0.0 , 20.0 , 0.01,obs),
Myode::done);
cout<<"integration stopped at "<<x<<" "<<obs.getState()<<" "<<obs.getTime()<<endl;
return 1;
}

Event Timeline