|
Boost Users : |
Subject: Re: [Boost-users] Problem with user defined Boost Units system
From: Stephen Torri (stephen.torri_at_[hidden])
Date: 2011-12-01 14:15:30
Matthias,
I appreciate your response. Yes I did not compile my example. I should
have done that. I took your example and then trimmed down the header
file so I can reproduce the error. I am not sure what is wrong here. I
get an error not because the destination type is incorrect. It does
not even reach that point. I get an error that there is no division
operator:
[storri_at_fedora Source]$ g++ -o boost_units boost_units.cpp
boost_units.cpp: In function int main(int, char**):
boost_units.cpp:44:39: error: no match for operator/ in 1 /
boost::units::operator-(const boost::units::quantity<Unit1, X>&, const
boost::units::quantity<Unit2, Y>&) [with Unit1 =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1l> >,
boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<myproject::types::radii_base_unit,
boost::units::list<myproject::types::minute_base_unit,
boost::units::dimensionless_type> > > > >, Unit2 =
boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1l> >,
boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<myproject::types::radii_base_unit,
boost::units::list<myproject::types::minute_base_unit,
boost::units::dimensionless_type> > > > >, X = double, Y = double,
typename boost::units::subtract_typeof_helper<boost::units::quantity<Unit1,
X>, boost::units::quantity<Unit2, Y> >::type =
boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1l> >,
boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<myproject::types::radii_base_unit,
boost::units::list<myproject::types::minute_base_unit,
boost::units::dimensionless_type> > > > >, double>]((*(const
boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1l> >,
boost::units::dimensionless_type>,
boost::units::homogeneous_system<boost::units::list<boost::units::angle::radian_base_unit,
boost::units::list<myproject::types::radii_base_unit,
boost::units::list<myproject::types::minute_base_unit,
boost::units::dimensionless_type> > > > >, double>*)(& val2)))
If I remove the "radii_t result =" from the following code and comment
out the IO statement I get the same error as previously quoted above.
Below is the code I used. I appreciate your patience as I learn Boost
Units.
Q1: What is the reason for this error? What in the error output helped
you to figure that out.
Q2: Even if the above error did not exist you mentioned that it would
fail the dimensional analysis. I think we both agree the type would be
radii^-1. How do you declare a type to be raised to the correct power?
Stephen
-------------------------
#include <boost/units/base_unit.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/io.hpp>
#include <boost/units/make_system.hpp>
#include <boost/units/physical_dimensions/length.hpp>
#include <boost/units/physical_dimensions/time.hpp>
#include <boost/units/static_constant.hpp>
#include <iostream>
namespace myproject {
namespace types {
struct radii_base_unit : public
boost::units::base_unit<radii_base_unit,
boost::units::length_dimension, 1>
{
static std::string name() { return("radii"); }
static std::string symbol() { return("r"); }
};
struct minute_base_unit : public
boost::units::base_unit<minute_base_unit,
boost::units::time_dimension,3>
{
static std::string name() { return ("minute"); }
static std::string symbol() { return ("min"); }
};
typedef boost::units::make_system<radii_base_unit,
minute_base_unit,
boost::units::angle::radian_base_unit >::type myproject_system_t;
typedef boost::units::unit<boost::units::length_dimension,myproject_system_t>
myproject_length;
typedef boost::units::quantity<myproject_length, double> radii_t;
BOOST_UNITS_STATIC_CONSTANT(radii,myproject_length);
}
}
int main ( int, char** )
{
using namespace myproject::types;
radii_t val1 ( 5 * radii );
radii_t val2 ( 3 * radii );
radii_t result = 1.0 / ( val1 - val2 );
std::cout << result << std::endl;
return 0;
}
On 12/1/11, Matthias Schabel <boost_at_[hidden]> wrote:
>> 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 );
>
> va2->val2
>
> This should give you a compile error anyway, since you are trying to assign
> a length to an inverse length...
>
>> 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.
>
> I'm not sure I believe you; the code you pasted is not compilable...did you
> actually compile anything?
>
>>
>> --------- 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.
>
> Using your earlier header :
>
> #include "types.hpp"
>
> #include <iostream>
> #include <boost/units/io.hpp>
>
> using namespace myproject::types;
>
> int main()
> {
> radii_t val1(5*radii),
> val2(4*radii);
>
> //auto L1 = 1/(val1-val2); // compile time error due to failed dimensional
> consistency
>
> radii_t val3(5*radii);
>
> dimensionless_t val4 = 10;
> dimensionless_t L2(val3*val4/(val1-val2));
>
> std::cout << val1 << std::endl
> << val2 << std::endl
> << val3 << std::endl
> << val4 << std::endl
> << L2 << std::endl;
>
> return 0;
> }
>
> gives
>
> 5 r
> 4 r
> 5 r
> 10 dimensionless
> 50 dimensionless
>
>
>
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