ODEをBoost Odeintで使用するようになりました。便宜上、便利なAPIを備えた最新のC++ライブラリであるため、Armadilloで使用したいと思います。しかし、arma::vec
を状態タイプとして指定すると、統合の最初のステップでintegrate_adaptive()
が状態ベクトルのサイズを0x1
に変更することがすぐに分かります。私はここで簡単な例を投稿:ArmadilloはBoost Odeintと競合します:Odeintは統合中に状態ベクトルをゼロにサイズ変更します
#include <iostream>
#include <armadillo>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace arma;
using namespace boost::numeric::odeint;
typedef vec state_type;
class harm_osc
{
private:
mat my_A;
public:
harm_osc(double gam)
{
my_A = { {0.0, 1.0}, {-gam*gam, 0.0} };
}
harm_osc()
{
my_A = { {0.0, 1.0}, {-1.0, 0.0} };
}
void operator() (const vec& x, vec& dxdt, const double t)
{
cout << "size of x: " << size(x) << endl;
cout << "size of dxdt: " << size(dxdt) << endl;
dxdt = my_A*x;
}
};
class observer
{
private:
mat& my_states;
vec& my_times;
public:
observer(mat& states, vec& times):
my_states(states),
my_times(times)
{}
void operator() (const vec& x, double t)
{
my_states.insert_rows(my_states.n_rows, x);
my_times.insert_rows(my_times.n_rows, t);
cout << t << '\t';
for(auto elem : x)
cout << elem << '\t';
cout << endl;
}
};
typedef runge_kutta_cash_karp54<state_type> error_stepper_type;
typedef controlled_runge_kutta<error_stepper_type> controlled_stepper_type;
int main()
{
state_type x = {0.0, 1.0};
vec t;
mat x_full;
integrate_adaptive(make_controlled<error_stepper_type>(1e-5, 1e-5), harm_osc(1.0), x, 0.0, 200.0, 0.01, observer(x_full, t));
}
私はstate_type
としてarma::vec::fixed<2>
の代わりarma::vec
を指定した場合は、この簡単なデモが正常に実行されます。私の問題は、私が作業している現在のプロジェクトでは、コンパイル時の状態ベクトルのサイズがわからないため、直前に述べたテンプレートパラメータで修正できないということです。
ArmadilloをBoost Odeintで使用する方法はありますか?コンパイル時に状態ベクトルのサイズを固定しないでください。私のプロジェクトの他の部分では、私は適切にアルマジロを使うことができます。私は私のプロジェクト全体でそれを使用したいと思います。今、ODEを統合するとき、私はBoost Ublasを使用してODEシステムを定義します。