是通过BOOST.UNITS支持尺寸分析的Boost Odeint
Is boost odeint supporting dimensional analysis via Boost.Units?
我试图实现一个简单的ode来测试boost.dodeint是否支持boost.units的使用。但是,我的示例是在编译时失败。是我的代码,还是不升级。DODEINT支持BOOST.UNITS用于维数分析?
#include<boost/units/systems/si.hpp>
#include<boost/numeric/odeint.hpp>
typedef boost::units::quantity<boost::units::si::length,double> state_type;
typedef boost::units::quantity<velocity,double> dev_type;
typedef boost::units::quantity<boost::units::si::time,double> time_type;
using namespace boost::units::si;
void exponential_decay(const state_type &x, dev_type &dxdt, time_type t){
dxdt = -0.0001*x/second;
}
int main(){
state_type startValue = 10*meter;
using namespace boost::numeric::odeint;
auto steps = integrate(exponential_decay, startValue, 0.0*second,
10.0*second, 0.1*second);
return 0;
}
因此,最初未能找到一组state_type,代数和操作的工作集 @arash提供了缺失的链接。
但是,为了完整性,您需要不是需要带上重型机械(fusion_algebra.hpp
(。这些是针对更一般的情况,例如状态类型不是单个值。
在这种简单的情况下,真正需要的就是指定代数,而不是使用默认值。这涉及声明stepper_type
,例如:
using stepper_type = runge_kutta4<length_type, double, velocity_type,
time_type, vector_space_algebra>;
接下来,我们选择一种迭代算法超载,使我们能够提供该步骤:
活在coliru
#include <boost/numeric/odeint.hpp>
#include <boost/units/systems/si.hpp>
typedef boost::units::quantity<boost::units::si::length, double> length_type;
typedef boost::units::quantity<boost::units::si::velocity, double> velocity_type;
typedef boost::units::quantity<boost::units::si::time, double> time_type;
namespace si = boost::units::si;
void exponential_decay(const length_type &x, velocity_type &dxdt, time_type /*t*/) { dxdt = -0.0001 * x / si::second; }
int main() {
using stepper_type = boost::numeric::odeint::runge_kutta4<
length_type, double, velocity_type, time_type, boost::numeric::odeint::vector_space_algebra>;
length_type startValue = 10 * si::meter;
auto steps = integrate_const(
stepper_type{}, exponential_decay,
startValue, 0.0 * si::second, 10.0 * si::second,
0.1 * si::second);
std::cout << "Steps: " << steps << "n";
}
打印
Steps: 100
¹从http://www.boost.org/doc/libs/1_66_0/libs/numeric/numeric/odeint/doc/doc/doc/html/boost_numereric_ode_odeint/odeint/odeint_in_in_in_in_indet_in_detet_in_detail/state_tate_types_types_types_types_algebras_and_and_operations.htperations.htperations.htpperations and and Htperations.htpperations.htp.org/doc/libs/1_66_0/doc/html/html/boost_units/dentities.html
使用boost::fusion
解决问题。
#include <iostream>
#include <vector>
#include <boost/numeric/odeint.hpp>
#include <boost/numeric/odeint/algebra/fusion_algebra.hpp>
#include <boost/numeric/odeint/algebra/fusion_algebra_dispatcher.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/time.hpp>
#include <boost/units/systems/si/velocity.hpp>
#include <boost/units/systems/si/acceleration.hpp>
#include <boost/units/systems/si/io.hpp>
#include <boost/fusion/container.hpp>
using namespace std;
using namespace boost::numeric::odeint;
namespace fusion = boost::fusion;
namespace units = boost::units;
namespace si = boost::units::si;
typedef units::quantity< si::time , double > time_type;
typedef units::quantity< si::length , double > length_type;
typedef units::quantity< si::velocity , double > velocity_type;
typedef units::quantity< si::acceleration , double > acceleration_type;
typedef units::quantity< si::frequency , double > frequency_type;
typedef fusion::vector< length_type > state_type;
typedef fusion::vector< velocity_type > deriv_type;
void exponential_decay( const state_type &x , deriv_type &dxdt , time_type t )
{
fusion::at_c< 0 >( dxdt ) = (-0.0001/si::second)* fusion::at_c< 0 >( x );
}
void observer(const state_type &x,const time_type &t )
{
}
int main( int argc , char**argv )
{
typedef runge_kutta_dopri5< state_type , double , deriv_type , time_type > stepper_type;
state_type startValue( 1.0 * si::meter );
auto steps=integrate_adaptive(
make_dense_output( 1.0e-6 , 1.0e-6 , stepper_type()),
exponential_decay,
startValue , 0.0 * si::second , 100.0 * si::second , 0.1 * si::second , observer);
std::cout<<"steps: "<<steps<<std::endl;
return 0;
}
相关文章:
- boost odeint什么时候真正调用观测者
- 将 boost::odeint 与向量类一起使用,而无需调整向量的大小
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- 与 boost odeint 集成期间的析构函数调用
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- 编译错误 C2440,并在 boost odeint 中使用make_dense_output
- Boost ODEINT:具有自定义类和向量空间代数的受控步进器
- 是通过BOOST.UNITS支持尺寸分析的Boost Odeint
- 微分方程的解在 boost::odeint 和 scipy.integrate 中完全不同
- 犰狳与 Boost Odeint 冲突:Odeint 在集成期间将状态向量调整为零
- 将 boost odeint 与 std::map 和自定义向量空间代数一起使用时,没有可行的重载'='
- DDE using boost odeint
- 使用C Boost Odeint库的二阶微分方程
- Boost Odeint是否具有跨越式算法
- boost::odeint 在成员类中调用
- Comparison Boost.Odeint vs Scipy.integrate.odeint?
- 如何使用C++ Boost odeint 库求解这个常微分方程
- 如何在boost::odeint中控制bulirsch_stoer方法的顺序
- 使用boost:odeint的简单c++程序中的断言错误
- Boost::odeint演绎/替换失败