|
Boost Users : |
Subject: Re: [Boost-users] Problem with user defined Boost Units system
From: Michael Powell (mwpowellnm_at_[hidden])
Date: 2011-11-30 12:04:00
When I got exposure to boost::units, or Units of Measure in general, it is
best to think of Dimensions first, line Length (L), Time (T), and so forth.
Then think of your units second. After that, values and calculations are of
a certain quantity.
I might recommend you use the built-in velocity, or acceleration, as a
template for your radii / radian dimension.
You will end up with something like this in your dimension type definition,
and forgive me the names aren't exact,
//...
typedef boost::units:dimension<radii_dimension,1,radian_dimension,-1>
radii_radian_dimension;
//...
quantity<radii_t> my_radii;
quantity<radian_t> my_radian;
quantity<radii_radian_dimension> result = my_radii / my_radian;
//...
I think what you're missing are the quantity<>'s involved. In other words,
you can't just go from unit (or dimension) to value; you have to run that
through quantity<> to do anything useful with it.
The kitchen sink examples are pretty good to learn from.
After that, however, I find the compile-time safety to be quite attractive.
HTH
On Wed, Nov 30, 2011 at 9:49 AM, Stephen Torri <stephen.torri_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.
>
> 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).
>
> Q3: How do I define a variable type if its a fraction (e.g. radii / radian
> )?
>
> ---- EQUATION ----
>
> 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
>
> ---- ERROR ----
>
> 1> [
> 1>
> Unit=boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,boost::units::static_rational<-1>>,boost::units::detail::merge_dimensions_impl<0,0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>,boost::units::homogeneous_system<boost::units::list<sgp4::types::radii_base_unit,boost::units::list<sgp4::types::radian_base_unit,boost::units::dimensionless_type>>>>,
> 1> Y=double
> 1> ]
> 1> and
> 1> [
> 1> Unit=sgp4::types::sgp4_length_t,
> 1> Y=double
> 1> ]
> 1> Constructor for class 'boost::units::quantity<Unit,Y>' is
> declared 'explicit'
> 1> with
> 1> [
> 1> Unit=sgp4::types::sgp4_length_t,
> 1> Y=double
> 1> ]
>
> Regards,
>
> Stephen
>
> _______________________________________________
> 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