在 boost odeint 中使用 make_dense_output 编译错误 C2440
Compile error C2440 with make_dense_output in boost odeint
我在 state_type ublas::vector<std::complex<double>>
和 'dense output' 中收到以下错误,但编译时使用
只是 runge_kutta_dopri5 个步进器。
C2440 'return': 无法在 boost\numeric\odeint\stepper\controlled_runge_kutta.hpp 89
从 'std::complex' 转换为 'double'
#include <iostream>
#include <complex>
#include <boost/numeric/ublas/blas.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/assignment.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/odeint.hpp>
using namespace boost::numeric::odeint;
namespace bnu = boost::numeric::ublas;
typedef bnu::vector<std::complex< double >> state_type;
struct solver_test
{
state_type & m_a;
solver_test(state_type& a): m_a(a) { }
void operator()(const state_type &x, state_type &dxdt, double t) const
{
// dummy!
dxdt = element_prod(x, m_a);
}
};
struct observer
{
std::vector<double> & m_tm;
std::vector<state_type> & m_out;
observer(std::vector<double>& tm, std::vector<state_type> & out)
:m_tm(tm), m_out(out) { }
template< class State >
void operator()(const State &x, double t) const
{
m_tm.push_back(t);
m_out.push_back(x);
}
};
int main(int argc, char **argv)
{
std::vector<double> tm;
std::vector<state_type> out;
state_type a_vec(10);
std::fill_n(a_vec.begin(), 10, std::complex<double>(1.0, 0.5));
state_type noise(10);
std::fill_n(noise.begin(), 10, std::complex<double>(1.5, 1.5));
const double dt = 0.1;
typedef runge_kutta_dopri5<state_type> dp_stepper_type;
integrate_const(make_dense_output(1.0e-6, 1.0e-3, dp_stepper_type()),
solver_test(a_vec), noise, 0.0, 10.0, dt, observer(tm, out));
// This works
//integrate_const(dp_stepper_type(),
// solver_test(a_vec), noise, 0.0, 10.0, dt, observer(tm, out));
return 0;
}
我在 MS Visual Studio Community 2017 中使用 boost 1_64_0。
我错过了什么?
为了其他遇到此问题的人,我对 state_type
变量使用了以下解决方法。
typedef std::vector<std::complex<double>> state_type;
我在求解器(函数对象)中使用 boost::numeric::ublas
来利用矩阵运算。它并不完美,但它确实有效。
我在 state_type ublas::vector<std::complex<double>>
和 'dense output' 中收到以下错误,但编译时使用
只是 runge_kutta_dopri5 个步进器。
C2440 'return': 无法在 boost\numeric\odeint\stepper\controlled_runge_kutta.hpp 89
从 'std::complex' 转换为 'double'#include <iostream>
#include <complex>
#include <boost/numeric/ublas/blas.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/assignment.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/odeint.hpp>
using namespace boost::numeric::odeint;
namespace bnu = boost::numeric::ublas;
typedef bnu::vector<std::complex< double >> state_type;
struct solver_test
{
state_type & m_a;
solver_test(state_type& a): m_a(a) { }
void operator()(const state_type &x, state_type &dxdt, double t) const
{
// dummy!
dxdt = element_prod(x, m_a);
}
};
struct observer
{
std::vector<double> & m_tm;
std::vector<state_type> & m_out;
observer(std::vector<double>& tm, std::vector<state_type> & out)
:m_tm(tm), m_out(out) { }
template< class State >
void operator()(const State &x, double t) const
{
m_tm.push_back(t);
m_out.push_back(x);
}
};
int main(int argc, char **argv)
{
std::vector<double> tm;
std::vector<state_type> out;
state_type a_vec(10);
std::fill_n(a_vec.begin(), 10, std::complex<double>(1.0, 0.5));
state_type noise(10);
std::fill_n(noise.begin(), 10, std::complex<double>(1.5, 1.5));
const double dt = 0.1;
typedef runge_kutta_dopri5<state_type> dp_stepper_type;
integrate_const(make_dense_output(1.0e-6, 1.0e-3, dp_stepper_type()),
solver_test(a_vec), noise, 0.0, 10.0, dt, observer(tm, out));
// This works
//integrate_const(dp_stepper_type(),
// solver_test(a_vec), noise, 0.0, 10.0, dt, observer(tm, out));
return 0;
}
我在 MS Visual Studio Community 2017 中使用 boost 1_64_0。 我错过了什么?
为了其他遇到此问题的人,我对 state_type
变量使用了以下解决方法。
typedef std::vector<std::complex<double>> state_type;
我在求解器(函数对象)中使用 boost::numeric::ublas
来利用矩阵运算。它并不完美,但它确实有效。