Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-08-24 06:24:18


"Matthias Troyer" <troyer_at_[hidden]> wrote in message
news:0F6E6AED-1E91-4356-A72E-AFA684879045_at_itp.phys.ethz.ch...
>
> On Aug 23, 2006, at 8:40 PM, Andy Little wrote:
>
>>
>> "Matthias Troyer" <troyer_at_[hidden]> wrote in message
>> news:14AD1E01-8077-42A7-A25E-5B5AF8AB1EFA_at_itp.phys.ethz.ch...
>>
>>> I have a question here: what is the purpose of these named quantities
>>> - is it to output J instead of kgm^2s^2 for energy and Nm instead
>>> of kgm^2s^2 for torque?
>>
>> Basically yes. Way back someone requested that they be
>> differentiated, so I
>> differentiated them and hence (BTW) the notion of an anonymous
>> quantity was born
>> as a logical result of not being able to distinguish the two in
>> some cases.
>>
>> After all torque is a vector quantity and energy is a scalar
>> quantity, so they
>> are quite different.
>> One could output energy units as N.m , but the joule is the more
>> well known SI
>> energy unit, so it helps to put things in a familiar context.
>>
>> Also there are various non SI units which specifically mean
>> torque, such as
>> (reading from the SI manual) dyne centimeter, kilogram-force meter,
>> etc.
>>
>> And for energy: erg per square centimeter second, watt per square
>> inch etc..
>
> OK, to be able to output specific unit symbols is a good thing.
>
>>
>>
>>> - is it to prevent adding energy and torque?
>>
>> It could be in Quan, by more querying of the unit and disallowing the
>> calculation in this case. At one point Quan (in a previous
>> incarnation) did do
>> this, but then maybe there are situations where adding or comparing
>> torque and
>> energy is appropriate, so I opted for the freer semantics. If there
>> is a proof
>> of some sort that they can never be compared or added then I will
>> change the
>> current semantics, but I am not enough of an expert to say for sure.
>
> I am strictly against any disallowing of calculations. Just consider
> the following pseudo code (I do not refer to any specific
> implementation but hope the types are self-explanatory
>
> unit::force::N force;
> unit::length::m distance;
>
> unit::energy::J energy;
> unit::torque::Nm torque;
>
> energy = force*distance; // should this be allowed?
> torque = force*distance; // should this be allowed?

Quan allows this as it stands.

> I think that in both cases the implicit conversion from the
> (annonymous?) quantity force*distance to either energy or torque. I
> think that to make the library usable one needs to allow these
> conversions.

The temporary result of force * distance is a so-called anonymous quantity.

> If one want to prevent the operations then because one is a vector
> scalar product (the energy) and the other a vector cross product (the
> torque) then this should be done at the level of the value_type of
> the quantity and not at the unit level.

Yes the obvious way to make a quantity a vector quantity is simple. Put it as
the value_type of a vector. Currently quan has 2D and 3D vectors in separate
namespaces, but it was suggested that it would be more flexible to just have a
quan::simple_vector<N_dimensions,quantity> and hopefully that will be
implemented at some stage.

regards
Andy Little


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