2016-05-17 9 views
0

system of equationsodeintブーストライブラリでのdopri5の使用

こんにちは。私は0から10^16までの時間でそれらの方程式を進化させたいと思います。そして、最初の条件はx(0)= 10^8とy(0)= 0.5です。方程式が分母にxに依存するので、runge_kutta_dopri5でodeintを使うのは適応的なステップ制御のために良い選択です。事は私が実際にこれを行う方法を少し考えているので、私はC++とodeintでほとんど経験していません。私はodeintを使うことについてたくさん調べましたが、私には役に立たない例がありました。私が見たゼロxが到達したときも、私は計算を停止したい、この私は運

#include <iostream> 
#include <vector> 
#include <cmath> 
#include <boost/array.hpp> 
#include <boost/numeric/odeint.hpp> 

using namespace std; 
using namespace boost::numeric::odeint; 

const double b = 43.0e17; 

typedef boost::array< double , 2 > state_type; 

void binary(const state_type &x , state_type &dxdt , double t) 
{ 
dxdt[0] = -b*(64.0/5)*(1 + (73.0/24)*pow(x[1],2) 
    + 37.0/96)*pow(x[1],4))/pow(x[0],3)*pow(1-pow(x[1],2),7.0/2); 

dxdt[1] = -b*(304.0/96)*x[1]*(1 + (121.0/304)*pow(x[1],2)) 
/pow(x[0],4)*pow((1 - pow(x[1],2)),5.0/2); 

} 

void write_binary(const state_type &x , const double t) 
{ 
cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl; 
} 
//I dont know what this does but the examples used it 
struct streaming_observer 
{ 
std::ostream& m_out; 

streaming_observer(std::ostream &out) : m_out(out) { } 

template< class State , class Time > 
void operator()(const State &x , Time t) const 
{ 
    m_out << t; 
    for(size_t i=0 ; i<x.size() ; ++i) m_out << "\t" << x[i] ; 
    m_out << "\n"; 
} 
}; 
//This was a first try with a given stepper but i want to replace it 
int main(int argc, char **argv) 
    { 
state_type x = { 20.871e8 , 0.5 }; // initial conditions 
integrate(binary , x , 0.0 , 1000.0 , 0.1 , write_binary); 
} 

でこれまでに書いた例に基づいてhttps://stackoverflow.com/questions/33334073/stop-integration-in-odeint-with-stiff-ode

私はそれをそれ、私はこのエラーを得たの実行をコンパイルした場合

内部プログラムのエラー - アサーション(i < N)がconst Tで失敗しました& boost :: array :: operator [](boost :: array :: size_type)const [T = double; long unsigned int N = 2ul; boost :: array :: const_reference = const double &;後押し::配列:: size_type =長いunsigned int型]: /usr/include/boost/array.hpp(129を):範囲 の外に中止された(コアダンプ)

は、どのように私はこの仕事を得ることができますか?

+0

あなたの状態変数は 'state_type x = {20.871e8、0.5};に現れるようにx [0]とx [1]の2つだけです。 – CroCo

答えて

1

write_binary関数は、配列境界を上書きしてアサーションを発生させます。 x[2]は無効です。

関連する問題