C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Library for checking dimensional unit correctness?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Scott Meyers
Guest





PostPosted: Sat Oct 22, 2005 3:19 pm    Post subject: Library for checking dimensional unit correctness? Reply with quote



I think the Barton and Nackman approach to enforcing dimensional unit
correctness
(http://se.inf.ethz.ch/~meyer/publications/OTHERS/scott_meyers/dimensions.pdf)
is interesting, because it's genuinely useful and it's a good demonstration
that templates are more than just glorified macros.

In the literature, the best-sounding library offering this functionality is
SIUnits by Walter Brown, but I have been unable to find a way to download
this library in recent years, and a correspondent recently wrote to me that
Walter said the library 'was withdrawn for "licensing issues."' A less
sophisticated (but more portable) implementation was described by Michael
Kenniston
([url]http://www.cuj.com/documents/s=8007/cuj0211kennisto/kennisto.htm)[/url], but I
can't find that for download, either. Googling around shows that there was
discussion of adding Kenniston's library to Boost in 2001, but a current
search at Boost for "quantity" yields hits only for the MPL.

As far as I can tell, there is no commonly available
production-quality library available to enforce dimensional unit
correctness. This seems a shame, as it's not hard to implement, and, if
the people writing to me about it are any indication, there is certainly
interest in one. Most recently, I got mail asking about handling
centigrade-fahrenheit conversions, something I'd never thought about before
and which is different from what's usually discussed due to the need to add
or subtract an arithmetic factor when converting.

Anyway, I have three questions:
- Have I overlooked a commonly-available dimension-checking library?
- If not, is there some technical reason why such a library is hard to
implement, i.e., that would explain its absence?
- Has somebody already handled the addition of support for temperatures
in centigrade, kelvin, and fahrenheit?

Thanks,

Scott

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
lindahlb@hotmail.com
Guest





PostPosted: Sat Oct 22, 2005 6:15 pm    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote



Dr. Keith Nicewarner, who wrote this library:
http://tuoml.sourceforge.net/, is working on a version that supports
dimensions (currently unpublished). The new implementation, I believe,
is based on typelists, as opposed to template math. I'm not sure how
close it is to being completed (published), but he is working on it.

Quote:
Has somebody already handled the addition of support for temperatures
in centigrade, kelvin, and fahrenheit?

The above library currently supports the oddities of temperature
conversions. The problem with temperature conversions is that scaling a
generic temperature results in non-uniform results. The value after
scaling a temperature in kelvins is not the same value after scaling
the temperature in celsius. As such, the above library disallows
scaling the generic temperature measurement (excerpt from
documentation):

Since temperature unit conversions involve an additive offset (for
instance, Kelvin = Celsius + 273), the following arithmetic operations
are not defined for the abstract class: scaling, negation, and ratio.
Doubling a Kelvin value gives quite a different temperature than
doubling a Celsius value! You must specify which units to be operated
on and then convert back to the desired units. For instance:

Temperature a = CelsiusTemperature(23);
Temperature b = a*2; // error
Temperature b = CelsiusTemperature((double)(CelsiusTemperature
&)a)*2);

Not sure if any of this helped, but its all I know of off-hand about
this sort of thing.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Malte Clasen
Guest





PostPosted: Sun Oct 23, 2005 10:10 am    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote



Scott Meyers wrote:
Quote:
Anyway, I have three questions:
- Have I overlooked a commonly-available dimension-checking library?

http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

I only had a short look at the online documentation, so I can't comment
on it.

Malte

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kwikius
Guest





PostPosted: Sun Oct 23, 2005 10:12 am    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Scott Meyers wrote:

Quote:

Anyway, I have three questions:
- Have I overlooked a commonly-available dimension-checking library?

I have written a comprehensive physical quantities library called
'pqs'.

http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

Quote:
- Has somebody already handled the addition of support for temperatures
in centigrade, kelvin, and fahrenheit?

pqs supports kelvin. It would be possible to support the other two by
creating a class for these with the offset and scaling from absolute
zero, however in calculations you would need to use kelvin to get any
meaningful results. This would probably be possible using an implicit
conversion enabled for types with a dimensional signature of
temperature.

regards
Andy little


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Pete Becker
Guest





PostPosted: Mon Oct 24, 2005 12:22 am    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Scott Meyers wrote:

Quote:
I think the Barton and Nackman approach to enforcing dimensional unit
correctness
(http://se.inf.ethz.ch/~meyer/publications/OTHERS/scott_meyers/dimensions.pdf)
is interesting, because it's genuinely useful and it's a good demonstration
that templates are more than just glorified macros.


Just a minor point: that library can detect some (many) cases of
incorrect dimensions, but it does not (and cannot) enforce correctness.
There are many physical quantities with very different meanings whose
fundamental units are the same. For example, torque is measured in
pound-feet, and work is measured in foot-pounds. Knowing that you've got
feet*pounds doesn't mean you've got work. But knowing that you've got
feet*feet means you don't have work.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Scott Meyers
Guest





PostPosted: Mon Oct 24, 2005 1:11 am    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Scott Meyers wrote:
Quote:
sophisticated (but more portable) implementation was described by Michael
Kenniston
([url]http://www.cuj.com/documents/s=8007/cuj0211kennisto/kennisto.htm)[/url], but I
can't find that for download, either.

For the record, I've now found it inside ftp://ftp.cuj.com/pub/2002/cujnov2002.zip.

Scott

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kwikius
Guest





PostPosted: Mon Oct 24, 2005 12:39 pm    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Pete Becker wrote:

Quote:
a minor point: that library can detect some (many) cases of
incorrect dimensions, but it does not (and cannot) enforce correctness.
There are many physical quantities with very different meanings whose
fundamental units are the same. For example, torque is measured in
pound-feet, and work is measured in foot-pounds.

Knowing that you've got
feet*pounds doesn't mean you've got work. But knowing that you've got
feet*feet means you don't have work.

In pqs

http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

, I use a per quantity tag so that dimensionally-equivalent quantities
can be distinguished ( a torque quantity has a different tag to a work
quantity for example). The dimensionful (as opposed to dimensionless)
result of a calculation on two quantities is specially tagged as an
anonymous quantity, which is dimensionally correct but can be assigned
to or initialise any dimensionally-equivalent quantity. It is then up
to the user whether the result of a multiplication of force * distance
is torque or energy. Currently pqs doesnt define work separate from
energy but a user could create separately tagged quantities to
distinguish between work and energy too if required

regards
Andy Little


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Deane Yang
Guest





PostPosted: Wed Oct 26, 2005 1:18 pm    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Scott Meyers wrote:
Quote:
As far as I can tell, there is no commonly available
production-quality library available to enforce dimensional unit
correctness.

That appears to be correct.

Quote:
This seems a shame, as it's not hard to implement, and, if
the people writing to me about it are any indication, there is certainly
interest in one.

I suggest searching on "dimension" or "quantity" in the boost developer
list archives, and you'll see both some attempts at building such a
library and a spirited discussion on how such a library should work.

Incidentally, how to deal with temperature is particularly instructive.
You have to distinguish between a temperature measurement and a
difference between two temperatures. Converting between different units
(e.g., Centigrade to/from Fahrenheit) is just multiplication by a
constant for the latter but a multiplication by a constant and a
additive shift for the former.

But you're right. A lot of us are pining for a good library. I
definitely use a rudimentary version in my own code.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Scott Meyers
Guest





PostPosted: Wed Oct 26, 2005 11:10 pm    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Deane Yang wrote:
Quote:
I suggest searching on "dimension" or "quantity" in the boost developer
list archives, and you'll see both some attempts at building such a
library and a spirited discussion on how such a library should work.

Thanks to David Abrahams, I can point out that the beginning of a recent
discussion on this topic in the Boost developer's list can be found at
http://lists.boost.org/Archives/boost/2005/10/95067.php

Scott

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kwikius
Guest





PostPosted: Wed Oct 26, 2005 11:13 pm    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote


Deane Yang wrote:
Quote:
Scott Meyers wrote:
As far as I can tell, there is no commonly available
production-quality library available to enforce dimensional unit
correctness.

That appears to be correct.

Thanks for the criticism. I assume you have tried pqs?

http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

It sure would be helpful if you could provide some specific information
regarding why you didnt find pqs satisfactory for your needs, or has
the lack of a fahrenheit to kelvin conversion proved so devastating as
to make the library unusable in your application?


cheers
Andy Little


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Deane Yang
Guest





PostPosted: Thu Oct 27, 2005 10:32 am    Post subject: Re: Library for checking dimensional unit correctness? Reply with quote

Andy,

I'm sorry! I was under the apparently mistaken impression that you
yourself did not consider your library ready for wide distribution. But
if that's not the case, I will be happy to point people to it.

To be honest, I haven't had any time to evaluate your library for my own
use. You do seem to have much more documentation than before, but it
will take me some effort to grasp how it all works.

Deane

kwikius wrote:
Quote:
Deane Yang wrote:
Scott Meyers wrote:
As far as I can tell, there is no commonly available
production-quality library available to enforce dimensional unit
correctness.
That appears to be correct.

Thanks for the criticism. I assume you have tried pqs?

http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html

It sure would be helpful if you could provide some specific information
regarding why you didnt find pqs satisfactory for your needs, or has
the lack of a fahrenheit to kelvin conversion proved so devastating as
to make the library unusable in your application?


cheers
Andy Little

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.