2016-11-23 1 views
3

This答えは役に立ちますが、おそらく構造体のODEモデルにさまざまな型の複数のパラメータを渡す方法を知りたいと思います。私の即時使用の場合は、std::array<double, 6>と2つのstd::vector<std::vector<double>>と2つの2つのスカラーを渡すことができます。リンクされた例では、harmonic_oscillator.cppと同様に、1つだけのパラメータが渡されます(double)。ありがとう。は、C++のodeintを引き上げるためのパラメータを渡しました

ここでは、ODEの力モデルに渡す必要があり、速度方程式内で使用する構造体の例を示します。

struct T 
{ 
    std::array<double, 6> IC; 
    double S; 
    double M; 
    std::vector<std::vector<double>> C; 
    std::vector<std::vector<double>> WT; 
}; 

答えて

1

私は、動作する構造化ソリューションを考え出しましたが、可変/メモリスコープのno-noがあるかどうかはわかりません。ここに例があります:

#include <vector> 
#include <boost/numeric/odeint.hpp> 

// define structure 
struct T 
{ 
    std::array<double, 6> IC; 
    double    S; 
}; 

// force model 
class harm_osc 
{ 
    struct T T1; 

public: 
    harm_osc(struct T G) : T1(G) {} 

    void operator() (const std::vector<double> &x , std::vector<double> &dxdt , const double /* t */) 
    { 
     dxdt[0] = x[1]; 
     dxdt[1] = -x[0] - T1.IC[0]*x[1] + T1.S; 
    } 
}; 

// print integrated state solution 
void write_solution(const std::vector<double> &x , const double t) 
{ 
    printf("%-6.2f %-6.2f %-6.2f\n", t, x[0], x[1]); 
} 

// problem setup 
int main() 
{ 

    std::vector<double> x(2); 
    x[0] = 1.0; 
    x[1] = 0.0; 

    struct T T2; 

    T2.IC = {0.15, 0.15, 0.15, 0.15, 0.15, 0.15}; 
    T2.S = 0.0; 

    harm_osc ho(T2); 
    boost::numeric::odeint::integrate(ho, x, 0.0, 10.0, 0.1, write_solution); 

} 
関連する問題