在 odeint 中使用 std::vector<Eigen::Vector3d> 作为状态类型
Using a std::vector<Eigen::Vector3d> as state type in odeint
我目前正在尝试使用 odeint 和 Eigen3 来集成 nBody 系统(目标是提供用于行星形成的高级例程的库,例如 MVS 的混合变量辛或钱伯斯混合变体)。在尝试不同的步进器时,我发现当使用普通步进器时,state_type std::vector<Eigen::Vector3d>
工作正常,但使用受控步进器(如burlisch_stoer
)编译失败,第一条错误消息是:
/usr/include/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp:87:40: error: cannot convert ‘boost::numeric::odeint::norm_result_type<std::vector<Eigen::Matrix<double, 3, 1> >, void>::type {aka Eigen::Matrix<double, 3, 1>}’ to ‘boost::numeric::odeint::default_error_checker<double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations>::value_type {aka double}’ in return
return algebra.norm_inf( x_err );
这是否意味着norm_result_type的推断不正确?这个规范到底有什么作用?它应该是x_err中发现的最高value_type吗?
第二个:
/usr/include/boost/numeric/odeint/algebra/range_algebra.hpp:132:89: error: call of overloaded ‘Matrix(int)’ is ambiguous
static_cast< typename norm_result_type<S>::type >( 0 ) );
我必须提供自己的代数才能以这种方式使用它吗?我宁愿不切换到std::vector<double>
或特征::VectorNd,因为将坐标分组非常有利于常微分方程右侧的可读性。
这是我使用的代码的简化示例。
#include "boost/numeric/odeint.hpp"
#include "boost/numeric/odeint/external/eigen/eigen.hpp"
#include "Eigen/Core"
using namespace boost::numeric::odeint;
typedef std::vector<Eigen::Vector3d> state_type;
struct f
{
void operator ()(const state_type& state, state_type& change, const double /*time*/)
{
};
};
int main()
{
// Using this compiles
typedef euler <state_type> stepper_euler;
// Using this does not compile
typedef bulirsch_stoer <state_type> stepper_burlisch;
state_type x;
integrate_const(
stepper_burlisch(),
f(),
x,
0.0,
1.0,
0.1
);
return 0;
}
头肩解决方案奏效了。我创建了一个从range_algebra
继承的代数:
class custom_algebra : public boost::numeric::odeint::range_algebra {
public:
template< typename S >
static double norm_inf( const S &s )
{
double norm = 0;
for (const auto& inner : s){
const double tmp = inner.maxCoeff();
if (tmp > norm)
norm = tmp;
}
return norm;
}
} ;
我认为应该可以使用range_algebra
和vector_space_algebra
创建这样的代数,但我还没有尝试过。
我担心你的状态类型不容易集成。问题是,将类似范围的状态类型(vector<>
)与类似向量空间的状态类型(Vector3d
)混合在一起。您需要range_algebra
来迭代向量。但是range_algebra
norm_inf
不适用于您的情况。
您可以做的是复制range_algebra
并保留所有for_eachX
方法,并且仅重新实现norm_inf
以适应您的状态类型。这应该不难。然后,您只需通过以下途径使用新的代数
typedef bulirsch_stoer< state_type , double , state_type , double , your_algebra > stepper_burlisch
相关文章:
- EASTL矢量<向量<int>>连续的
- 如何将Affine3d应用于Vector3d
- 需要帮助理解这个基本的 Vector3D 结构的代码
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- Vector3d 的特征矩阵给出了奇怪的错误
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- Eigen3/C++:使用 Vector3d 平铺 MatrixXd
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- ``这个''不能用this-&gt;指针变量
- 如何加入向量&lt; int&gt;到C 中的单个INT