boost::units - converting from one derived_dimension to another across systems (imperial to metric)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:

*.h--------------------------------------------------------------------------------
namespace dimensional_analysis {
    namespace lineal_force {
        //lb/in
        typedef boost::units::derived_dimension<
            boost::units::us::pound_force_base_unit, 1,
            boost::units::us::inch_base_unit, -1
        >::type lb_per_inch_dimension;
        typedef boost::units::unit<
            lb_per_inch_dimension,
            dimensional_analysis::lengths::ip_system
        > lb_per_inch_unit;
        typedef boost::units::quantity<lb_per_inch_unit, double> lb_per_inch_quantity;
        BOOST_UNITS_STATIC_CONSTANT(lbpin, lb_per_inch_quantity);
         //kg/m
        typedef boost::units::derived_dimension<
            boost::units::si::kilogram_base_unit, 1,
            boost::units::si::meter_base_unit, -1
        >::type kg_per_meter_dimension;
        typedef boost::units::unit<
            kg_per_meter_dimension,
            boost::units::si::system
        > kg_per_meter_unit;
        typedef boost::units::quantity<kg_per_meter_unit, double> kg_per_meter_unit_quantity;
        BOOST_UNITS_STATIC_CONSTANT(kgpm, kg_per_meter_unit_quantity);
    }//lineal_force
}//dimensional_analysis

*.cp ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Do I need these?
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit, double, 0.0559974); // exact conversion
BOOST_UNITS_DEFAULT_CONVERSION(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit);


//This does not compile#
const auto conv_factor_try0 = conversion_factor(dimensional_analysis::lineal_force::kg_per_meter_unit::unit_type(), dimensional_analysis::lineal_force::lb_per_inch_unit::unit_type());

# *\boost_1_68_0\boost\units\detail\conversion_impl.hpp(340): error C2672: 'conversion_factor': no matching overloaded function found (compiling source file...*.cpp)

Any help is appreciated

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
AMDG

On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:

It's not going to work.  lb is a unit of
force, but kg is a unit of mass.  They are not
compatible and there is no conversion between
them.

> *.h--------------------------------------------------------------------------------
> namespace dimensional_analysis {
>     namespace lineal_force {        //lb/in
>         typedef boost::units::derived_dimension<
>             boost::units::us::pound_force_base_unit, 1,
>             boost::units::us::inch_base_unit, -1
>         >::type lb_per_inch_dimension;

units are not dimensions.  You can't use
derived_dimension with base_units.

>  <snip>
>

In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list


> On Nov 15, 2018, at 8:18 AM, Steven Watanabe via Boost-users <[hidden email]> wrote:
>
> AMDG
>
>> On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
>> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
>
> It's not going to work.  lb is a unit of
> force, but kg is a unit of mass.  They are not
> compatible and there is no conversion between
> them.
>
>> *.h--------------------------------------------------------------------------------
>> namespace dimensional_analysis {
>>     namespace lineal_force {        //lb/in
>>         typedef boost::units::derived_dimension<
>>             boost::units::us::pound_force_base_unit, 1,
>>             boost::units::us::inch_base_unit, -1
>>         >::type lb_per_inch_dimension;
>
> units are not dimensions.  You can't use
> derived_dimension with base_units.
>
>>  <snip>
>>
>
> In Christ,
> Steven Watanabe
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users

There is technically a kilogram force unit, kg-f or kilopond.  I don’t know if that’s in Units though.

Damien
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 15/11/2018 15:18, Steven Watanabe via Boost-users wrote:
> AMDG
>
> On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
>> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
>
> It's not going to work.  lb is a unit of
> force, but kg is a unit of mass.  They are not
> compatible and there is no conversion between
> them.

lb·f (foot-pounds) is force; lb is mass.

The code in question is using pounds force, so won't be convertible to
inches as you say, just wanted to correct the terminology.


Regards,
Roger


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On Thu, Nov 15, 2018 at 10:29 AM Damien Hocking via Boost-users
<[hidden email]> wrote:

>
>
>
> > On Nov 15, 2018, at 8:18 AM, Steven Watanabe via Boost-users <[hidden email]> wrote:
> >
> > AMDG
> >
> >> On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
> >> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
> >
> > It's not going to work.  lb is a unit of
> > force, but kg is a unit of mass.  They are not
> > compatible and there is no conversion between
> > them.
> >
> >> *.h--------------------------------------------------------------------------------
> >> namespace dimensional_analysis {
> >>     namespace lineal_force {        //lb/in
> >>         typedef boost::units::derived_dimension<
> >>             boost::units::us::pound_force_base_unit, 1,
> >>             boost::units::us::inch_base_unit, -1
> >>         >::type lb_per_inch_dimension;
> >
> > units are not dimensions.  You can't use
> > derived_dimension with base_units.
> >
> >>  <snip>
> >>
> >
> > In Christ,
> > Steven Watanabe
> > _______________________________________________
> > Boost-users mailing list
> > [hidden email]
> > https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> There is technically a kilogram force unit, kg-f or kilopond.  I don’t know if that’s in Units though.

That, or, if memory serves, you need to factor out gravitational, or
whatever other force, is being masked by the lb.

Cheers...

> Damien
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On Thu, Nov 15, 2018 at 11:11 AM Roger Leigh via Boost-users
<[hidden email]> wrote:

>
> On 15/11/2018 15:18, Steven Watanabe via Boost-users wrote:
> > AMDG
> >
> > On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
> >> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
> >
> > It's not going to work.  lb is a unit of
> > force, but kg is a unit of mass.  They are not
> > compatible and there is no conversion between
> > them.
>
> lb·f (foot-pounds) is force; lb is mass.

No, lb-f is a unit of Torque. lb is a unit of Force.

> The code in question is using pounds force, so won't be convertible to
> inches as you say, just wanted to correct the terminology.
>
>
> Regards,
> Roger
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
On 15.11.2018 17:27, Michael Powell via Boost-users wrote:
On Thu, Nov 15, 2018 at 11:11 AM Roger Leigh via Boost-users
[hidden email] wrote:
On 15/11/2018 15:18, Steven Watanabe via Boost-users wrote:
AMDG

On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
It's not going to work.  lb is a unit of
force, but kg is a unit of mass.  They are not
compatible and there is no conversion between
them.
lb·f (foot-pounds) is force; lb is mass.
No, lb-f is a unit of Torque. lb is a unit of Force.

Hmm, that pound is primarily unit of force is a news to me. The following is from the UK's Weights and Measures Act 1963:


"The yard or the metre shall be the unit of measurement of length and the pound or the kilogram shall be the unit of measurement of mass by reference to which any measurement involving a measurement of length or mass shall be made in the United Kingdom; and- (a) the yard shall be 0.9144 metre exactly; (b) the pound shall be 0.45359237 kilogram exactly."

To my knowledge, the US still adhere to 1894's update to Mendenhall Order which defined  that there shall be 2.20462234 pounds to a kilogram.

On the other hand, lbf is often used to denote "pound force" unit, with 1 lbf being approximately 4.448N or 0.454 kp.

So Boost.Units should then not be used for cooking recipes as the conversions from pound based to gram based quantities would only work on Earth?

Cheers,

Leon


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
On 11/16/18 4:57 AM, Leon Mlakar via Boost-users wrote:

> On 15.11.2018 17:27, Michael Powell via Boost-users wrote:
>> On Thu, Nov 15, 2018 at 11:11 AM Roger Leigh via Boost-users
>> <[hidden email]> wrote:
>>> On 15/11/2018 15:18, Steven Watanabe via Boost-users wrote:
>>>> AMDG
>>>>
>>>> On 11/14/2018 05:04 AM, Matt Vinson via Boost-users wrote:
>>>>> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
>>>> It's not going to work.  lb is a unit of
>>>> force, but kg is a unit of mass.  They are not
>>>> compatible and there is no conversion between
>>>> them.
>>> lb·f (foot-pounds) is force; lb is mass.
>> No, lb-f is a unit of Torque. lb is a unit of Force.
>>
> Hmm, that pound is primarily unit of force is a news to me. The
> following is from the UK's Weights and Measures Act 1963:
>
>
> "The yard <https://en.wikipedia.org/wiki/Yard> or the metre
> <https://en.wikipedia.org/wiki/Metre> shall be the unit of measurement
> of length <https://en.wikipedia.org/wiki/Length> and the pound or
> the kilogram <https://en.wikipedia.org/wiki/Kilogram> shall be the
> unit of measurement of mass by reference to which any measurement
> involving a measurement of length or mass
> <https://en.wikipedia.org/wiki/Mass> shall be made in the United
> Kingdom; and- (a) the yard shall be 0.9144 metre exactly; (b) the
> pound shall be 0.45359237 kilogram exactly."
>
> To my knowledge, the US still adhere to 1894's update to Mendenhall
> Order which defined  that there shall be 2.20462234pounds to a kilogram.
>
> On the other hand, lbf is often used to denote "pound force" unit,
> with 1 lbf being approximately 4.448N or 0.454 kp.
>
> So Boost.Units should then not be used for cooking recipes as the
> conversions from pound based to gram based quantities would only work
> on Earth?
>
> Cheers,
>
> Leon
>
In Common, and legal, usage, the Pound represents both a mass unit and a
Force unit, a pound of food is mass, in a pound/sq-in it is a force. In
scientific uses, one shouldn't use the base pound unless it is totally
obvious which one is being used, but instead you use the units of
pound-force or pound-mass, lbf (not lb-f) vs lbm,

Boost, since it can't know which one is being used, as the context will
never be obvious to the compiler, probably should not have a raw lb
unit, but only lbf and lbm.

--
Richard Damon

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::units - converting from one derived_dimension to another across systems (imperial to metric)

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
Hi list,

> I am having trouble converting from one derived_dimension to another across systems (imperial to metric).  I'd like to convert, say, lb/in to, say, kg/m.  I thought I would do the following but get a compiler error #:
>
> *.h--------------------------------------------------------------------------------
> namespace dimensional_analysis {
>     namespace lineal_force {
>         //lb/in
>         typedef boost::units::derived_dimension<
>             boost::units::us::pound_force_base_unit, 1,
>             boost::units::us::inch_base_unit, -1
>         >::type lb_per_inch_dimension;
>         typedef boost::units::unit<
>             lb_per_inch_dimension,
>             dimensional_analysis::lengths::ip_system
>         > lb_per_inch_unit;
>         typedef boost::units::quantity<lb_per_inch_unit, double> lb_per_inch_quantity;
>         BOOST_UNITS_STATIC_CONSTANT(lbpin, lb_per_inch_quantity);
>          //kg/m
>         typedef boost::units::derived_dimension<
>             boost::units::si::kilogram_base_unit, 1,
>             boost::units::si::meter_base_unit, -1
>         >::type kg_per_meter_dimension;
>         typedef boost::units::unit<
>             kg_per_meter_dimension,
>             boost::units::si::system
>         > kg_per_meter_unit;
>         typedef boost::units::quantity<kg_per_meter_unit, double> kg_per_meter_unit_quantity;
>         BOOST_UNITS_STATIC_CONSTANT(kgpm, kg_per_meter_unit_quantity);
>     }//lineal_force
> }//dimensional_analysis
>
> *.cp ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> //Do I need these?
> BOOST_UNITS_DEFINE_CONVERSION_FACTOR(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit, double, 0.0559974); // exact conversion
> BOOST_UNITS_DEFAULT_CONVERSION(dimensional_analysis::lineal_force::kg_per_meter_unit, dimensional_analysis::lineal_force::lb_per_inch_unit);
>
> //This does not compile#
> const auto conv_factor_try0 = conversion_factor(dimensional_analysis::lineal_force::kg_per_meter_unit::unit_type(), dimensional_analysis::lineal_force::lb_per_inch_unit::unit_type());
>
> # *\boost_1_68_0\boost\units\detail\conversion_impl.hpp(340): error C2672: 'conversion_factor': no matching overloaded function found (compiling source file...*.cpp)
>
> Any help is appreciated

I opened a PR (https://github.com/boostorg/units/pull/32) to address
such a situation;
the following code

```cpp
#include <iostream>
#include <boost/units/base_units/us/inch.hpp>
#include <boost/units/base_units/us/pound_force.hpp>
#include <boost/units/io.hpp>
#include <boost/units/physical_dimensions.hpp>
#include <boost/units/systems/si.hpp>

int main() {
  auto force_us{1.0 * boost::units::us::pound_force};
  auto length_us{1.0 * boost::units::us::inch};
  boost::units::quantity<boost::units::si::force, double> force_si{force_us};
  boost::units::quantity<boost::units::si::length, double> length_si{length_us};
  std::cout << force_us << " = " << force_si << '\n';
  std::cout << length_us << " = " << length_si << '\n';
  std::cout << force_us / length_us << " = " << force_si / length_si << '\n';
  return 0;
}
```

will print

```
1 lbf = 4.44822 m kg s^-2
1 in = 0.0254 m
1 lbf in^-1 = 175.127 kg s^-2
```

Best

--
Eisuke Kawashima
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users