Boost logo

Boost :

From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2007-03-26 16:51:14


I have spent a couple of hours looking at the units library. This is
not a full review as I have not been able to compile my simple example
in the time that I have available.

I was motivated to write this review having yesterday needed to do some
rather basic, but unfamiliar, physical calculations. At that time I
used a simple awk script to do the arithmetic. If dimensional analysis
had been available, it would have been a useful confidence builder that
the code was doing the right thing. The problem was this: I have
measured the temperatures on the surfaces of an electrical device - a
power supply - and I want to calculate the power dissipated. The maths
is simple: power = temperature difference to atmosphere * area * heat
transfer coefficient. I tried to write this using the units library.

Power, temperature and area were straightforward:

typedef quantity<power> power_t;
typedef quantity<area> area_t;
typedef quantity<temperature> temp_diff_t;

The units of the heat transfer coefficient are W C^-1 m^-2. As far as
I was able to see, I was not able to write anything like

typedef quantity<power/temperature/area> heat_transfer_coefficient_t;

Rather, it was necessary for me to reduce W C^-1 m^-2 to basic
dimensions manually. This is not easy for me. I have to remember
phyics that I knew in 1988 but have not used much since. My guess was:

power = energy / time
energy = force * distance
force = mass * acceleration
acceleration = length / time^2

so I concluded that the dimensions of power are mass length time^-3 and
hence of heat transfer coefficient are mass time^-3 temperature^-1
length^-1, and wrote this:

typedef composite_dimension<mass_tag,1,time_tag,-3,temperature_tag,-1,length_tag,-1>
   heat_transfer_coefficient_t;

Defining the unit was easier:

const heat_transfer_coefficient_t watts_per_square_meter_per_celcis
   = watts / square_meter / kelvin;

But this fails to compile, with this error:

error: conversion from
‘boost::units::unit<boost::units::dimension_list<boost::units::dim<boost::units::mass_tag,
boost::units::static_rational<1l, 1l> >,
boost::units::dimension_list<boost::units::dim<boost::units::time_tag,
boost::units::static_rational<-0x00000000000000003l, 1l> >,
boost::units::dimension_list<boost::units::dim<boost::units::temperature_tag,
boost::units::static_rational<-0x00000000000000001l, 1l> >,
boost::units::dimensionless_type> > >,
boost::units::homogeneous_system<boost::units::SI::system_tag> >’ to
non-scalar type
‘boost::units::composite_dimension<boost::units::mass_tag, 1,
boost::units::time_tag, -0x00000000000000003,
boost::units::temperature_tag, -0x00000000000000001,
boost::units::length_tag, -0x00000000000000001,
boost::units::dimensionless_type, 0, boost::units::dimensionless_type,
0, boost::units::dimensionless_type, 0,
boost::units::dimensionless_type, 0>’ requested

Presumably this is because I have got something wrong in my working. I
gave up at this point.

For this library to be useful for me, it needs to be quick to learn and
easy to apply. Working only with the included units it does look like
it would work reasonably well, but in the situation I have described
above it was quickly obvious that it was taking more effort to apply it
to my program than the benefit that would result.

There are two areas that I was interested in looking in more detail at,
and I encourage other reviewers who get further than me to have a look
at them:

1. What is the effect on compile time? I used #if to switch between
units and plain floats.
2. Is there any increase in object file size? I know there shouldn't
be, but it would be interesting to know for sure.
3. Are the error messages comprehensible? The one show above is not
great, but it could have been worse; there are some Boost libraries
which I find unusable because of the volumne and inpenetrability of the
error messages that result from a simple typo (though the compiler must
share the blame for this).

Finally some random notes from my reading of the documentation:

- "io" is a misnomer since it only does output, as far as I can see.

- I tend to refer to temperature differences in Celcius, rather than
Kelvin. There is an obvious issue when dealing with absolute
temperatures though.

- "Meter" vs. "Metre". My dictionary says "meter" is "chiefly U.S.".
My physics books say "metre" consistently. Presumably both can be included.

- Am I the only person who uses capital letters for units named after
people? Hmm, maybe I am.

- Please don't call the units used in the U.S. "English" units. Here
in England, we use the S.I. system for everything except pints of beer
and miles on roadsigns. The units that we did use here until about 50
years ago were not the same as the ones that the Americans use.

I hope this helps. I will not express an opinion about whether the
library should be included; I leave that to people who have made more
progress with it.

Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk