How to properly define a derived unit in Boost Uni

2019-07-22 16:57发布

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条回答
Lonely孤独者°
2楼-- · 2019-07-22 17:29

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.

查看更多
登录 后发表回答