|
Boost Users : |
Subject: [Boost-users] [units] conversion factor for non-base
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2010-04-20 15:31:44
I'm unsure how to go about what I need. I've looked at the library code
and the documentation and am not even sure what I want is possible,
though it should be.
In most of our code we use the si system and have defined composite
dimensions for most of what is unique to our application. However,
there is one dimension where there is no standard unit in the si system:
flow coefficient.
The flow coefficient is Q/sqrt(dP), a volumetric flow/sqrt(pressure).
We have derived and defined a unit that would be the si standard for
this quantity if there was one and things work fine. I have a runtime
unit system that then converts between user values that make sense, to
our internal si version that does not but works.
However, now I want to write some alternative functions that use the
actual units that engineers really use: Cv and Kv. I would like these
alternative functions to then convert into this si unit we've created
but the interface should distinguish between Cv, Kv, and my made up
unit.
The first part is easy: make a system that only contains this funky
dimension and then use it to make quantities that are not in the si
system.
The second part is what I can't find. The conversion templates in
conversion.hpp seem to specifically expect base units which at least the
si part is not and my conversions should use my funky si unit as their
basis. So the question I have is how can I write conversions such that
I can do this:
quantity<si::flow_coefficient> fc(42 * Kv);
and this:
void f(quantity<Kv::coefficient>);
void f(quantity<Cv::coefficient>);
void f(quantity<si::coefficient>);
Where Kv and Cv are base units in their own systems.
The problem is sort of like degrees and radians, which I was going to
use as a basis when I first was looking at this issue, except that in
that case the unit is a base unit for a base dimension and in my case
I'm working with a derived dimension within the si system.
The only way I can think of to do it is to make a system with the
components within the derived dimension and make conversion factors for
those. The problem is that I am not sure such systems can be coherent
and it would be a significant effort above and beyond the direct
conversion factors I already know.
-- http://crazyeddiecpp.blogspot.com/
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