Boost logo

Boost Users :

Subject: [Boost-users] boost::units - converting from one derived_dimension to another across systems (imperial to metric)
From: Matt Vinson (matt.vinson_at_[hidden])
Date: 2018-11-21 01:46:53

 degski: I do not think am making the "nauseam" mistake.  My issue is using Boost.Units correctly which I concede is difficult for me but I am reading the docs and trying to get it.
In our field of engineering, we use Kg as a force; not a mass.  (We also use pound as a force; not a mass - for your "UK's Weights and Measures Act 1963" counterpart).  That said, I should not have made the mistake of using Kg as a force in Boost.Units, it's true.  Shame on me.
My task is to convert between lineal forces: k/ft, k/in, lb/ft, lb/in, kN/m, kN/cm, kN/m, N/m, N/cm, N/m, Metric ton/m, Metric ton/cm, Metric ton/mm, Kg/m, Kg/cm, Kg/mm.  These are all force/length.

Steven Watanabe: Thank you, again.#1: I was not trying to say it's wrong; sorry.  Just that I did not see 'length' and opted for the one that did.  The unit's are correct, as you say.
#2: This is an error to start with Kg(force)/meter.  I can start with N/meter.  I've changed this variable name to newton_per_meter and the conversion factors.


namespace dimensional_analysis{

    typedef boost::units::length_base_dimension::dimension_type length_dimension;

    typedef boost::units::mass_base_dimension::dimension_type mass_dimension;

typedef boost::units::make_system<boost::units::us::inch_base_unit,boost::units::us::pound_base_unit>::type ip_system;

       namespace lineal_force {

             typedef boost::mpl::divides<boost::units::force_dimension,boost::units::length_dimension>::type lineal_force_dimension;          

             namespace imperial {


                     ////lb/in, right?

////boost::units::force_dimension =pound

////boost::units::length_dimension = in


                     typedef boost::units::unit<lineal_force_dimension,lengths::ip_system> lineal_force_unit;


              namespace si {


                     ////N/m, right?

////boost::units::force_dimension = newton

////boost::units::length_dimension = meter


                     typedef boost::units::unit<lineal_force_dimension,boost::units::si::system> lineal_force_unit;





//Imperiallb/in to SI N/m





175.1268369864); // exact conversion




//SI N/mto Imperial lb/in





0.1837185501); // exact conversion




//Imperialto SI.  This should convert lb/in to N/m andreturn 175.1268369864(N/m)

//But itdoes not.  Its converting lb (mass) to Kg(mass), 0.454

const auto t2 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::si::lineal_force_unit>>(

1.0 *dimensional_analysis::lineal_force::imperial::lineal_force_unit::unit_type());

//Again, Imperial to SI.  This should convert lb/in to N/m and return 175.1268369864 (N/m)

//But itdoes not.  It returns lb (mass) to Kg(mass)

const auto t3 = boost::units::conversion_factor(



//SI toImperial.  This should convert N/m tolb/in and return 0.1837185501 (lb/in)

//But itdoes not.  Its converting Kg (mass) to lb(mass), 2.205

const auto t1 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::imperial::lineal_force_unit>>(

1.0 *dimensional_analysis::lineal_force::si::lineal_force_unit::unit_type());

//So, I don’t know whythe library is converting mass; I’ve tuned it to use boost::units::force_dimension/boost::units::length_dimension

//I am doing something wrongwhere the library is not using force/length.

//Below does work, mainly.

//This isconvert Si to SI and return value of 1.0 is correct.

const auto t4 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::si::lineal_force_unit>>(

1.0 *boost::units::si::newton / boost::units::si::meter);

//This convert lb/in to SI and return value is 175.1268369864 is correct.

const auto t5 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::si::lineal_force_unit>>(

1.0 * boost::units::us::pound_force_base_unit::unit_type() / boost::units::us::inch_base_unit::unit_type());

//This converts lb/in to lb/in and return value is of 1.0 is correct.

const auto t6 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::imperial::lineal_force_unit>>(

1.0 * boost::units::us::pound_force_base_unit::unit_type() / boost::units::us::inch_base_unit::unit_type());

//This is2.205 and not correct. 

//It’s notconverting SI-force/length to Imperial-force/length

//Itsconverting Kg (mass) to lb (mass), 2.205

const auto t7 = static_cast<boost::units::quantity<dimensional_analysis::lineal_force::imperial::lineal_force_unit>>(

1.0 * boost::units::si::newton /boost::units::si::meter);

//What have I done wrong?
//Any help is appreciated.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at