Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with user defined Boost Units system
From: Stephen Torri (stephen.torri_at_[hidden])
Date: 2011-12-01 12:06:21


I am trying to understand the dimensionality of the following two equations.

--- first equation ---
example::types::radii_t val1 = 5 * example::types::radii;
example::types::radii_t val2 = 4 * example::types::radii;

example::types::radii_t L1 = 1 / ( val1 - va2 );

If I was doing the dimensional analysis by hand I would see

1 / ( radii - radii )

Such that the end type would be

radii^-1

Given that end type here is the second equation:

example::types::radii_t val3 = 5 * example::types::radii;
example::types::dimensionless_t val4 = 10;
example::types::dimensionless_t L2 = L1 * val4 * val3;

Doing the dimensional analysis by hand I think I should see:

L2 = radii * (nothing) * radii^-1
    = (nothing) or dimensionless

What Boost Units is reporting is that L2 is actually units in radii_t.

--------- QUESTIONS --------------

Q1: How do you print out the types at compile time?

Q2: How can you confirm you have the correc power for a type? For
example radii is indeed raised to the -1 power.

Stephen

On 11/30/11, Michael Powell <mwpowellnm_at_[hidden]> wrote:
> Thanks, Matthias. IMHO, this is one of the greatest things about
> boost::units, compile time unit safety. If your dimensions aren't correct
> then, there's no point in proceeding until they are. Runtimes are another
> question, though; but, for compile time, I like that about it.
>
> On Wed, Nov 30, 2011 at 1:08 PM, Matthias Schabel
> <boost_at_[hidden]>wrote:
>
>> > I am using Boost 1.45 and trying to use Boost Units to map the types
>> > of astrodynamic equation variables. I am getting an error with the
>> > following equation. The error is saying that the lvalue type for
>> > k2_divded_by_semi_major is wrong.
>>
>> This is the library doing what it is supposed to do : your equation is
>> dimensionally incorrect...
>>
>> > The questions I have are:
>> >
>> > Q1: Did I defined my system correctly? (System file is attached -
>> types.hpp)
>> >
>> > Q2: How do I define ratio in the system? For example I have some
>> > constants that define a conversion (1 earth radii = 6378 km).
>>
>> Look at <boost/units/base_units/us/yard.hpp> for an example defining a new
>> base unit of length with conversion to metric. You can look at the macro
>> details to see how it is implemented.
>>
>> > Q3: How do I define a variable type if its a fraction (e.g. radii /
>> radian )?
>>
>> typedef
>> derived_dimension<length_base_dimension,1,plane_angle_base_dimension,-1>::type
>> length_over_angle_dimension;
>> typedef unit<length_over_angle_dimension,my_system> length_over_angle;
>>
>>
>> > sgp4::types::radii_t k2_divided_by_semi_major = m_k2 / pow<2> (
>> semi_major );
>> >
>> > The types of variables are:
>> >
>> > m_k2 sgp4::types::radii_t
>> > semi_major sgp4::types::radian_t
>>
>> You are trying to assign a [length]/[plane_angle^2] to a [length] which is
>> clearly dimensionally incorrect. Depending on your perspective, one of the
>> upsides/downsides of Boost.Units is that it requires that you be precise
>> in
>> formulation of equations...
>>
>> Matthias
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net