How to properly define a derived unit in Boost Unit

随声附和 提交于 2019-12-11 06:54:23

问题


I am trying to create a derived_dimension in boost::units for mass flow rate for si system. I cannot find any documentation on how to do this simple task. This is what I have so far but I am getting errors during the compilation.

typedef boost::units::derived_dimension<
boost::units::mass_base_dimension, 3,
boost::units::time_base_dimension, -1
>::type mass_flow_rate_dimension;

typedef boost::units::unit<
mass_flow_rate_dimension,
boost::units::si::system
> mass_flow_rate_unit;

typedef boost::units::quantity<mass_flow_rate_unit, double> mass_flow_rate;

BOOST_UNITS_STATIC_CONSTANT(kilogram_per_seconds, mass_flow_rate);

This is how I get the error:

mass_flow_rate MFR;
quantity<mass_density> density = 1.0 * kilogram_per_cubic_meter;
quantity<si::time> Time = 1.0 * second;
quantity<volume> vol = 1.0 * cubic_meters;
MFR = density * vol / Time;

error: C2338 (is_simply_convertible::value == true)


回答1:


mass_flow_rate_dimension has the wrong dimensions. You have mass to the third instead of just mass

typedef boost::units::derived_dimension<
boost::units::mass_base_dimension, 1,
boost::units::time_base_dimension, -1
>::type mass_flow_rate_dimension;

Fixes it. That error is meant just for the case when your dimensions don't line up.



来源:https://stackoverflow.com/questions/41750974/how-to-properly-define-a-derived-unit-in-boost-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!