
Boost Users : 
Subject: Re: [Boostusers] boost::units primer explained / conversion factors required
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 20110721 19:23:26
On 7/21/2011 3:16 PM, Michael Powell wrote:
> Okay, here's what we need to get at, for starters. And maybe an
> illustration or three and a little exchange will go a long way towards
> helping my better comprehend units.
>
> I'm starting with a set of SI calculations for oil and gas constants
> calculations. Eventually we will need to accommodate US units as well.
> But not quite yet.
>
> We need to get at a calculation involving Pressure Gradient, which ends
> up being metric::bar/si::meter (bars over meters) in specific units, or
> I suppose si::pressure/si::length might also work.
>
> Then we need to get after Fluid Density, which ends up being
> si::kilogram/si:meter^3 (kilograms over cubic meters) in specific units,
> or I suppose si::mass/si::meter^3 (I don't know what this looks like in
> terms of boost::units, maybe one of the volumes?), or perhaps make use
> of mass_density?
Yes, it's mass_density.
>
> We take all that and divide Pressure Gradient by Fluid Density to arrive
> at what we hope will be the the conversion factor: 0.0000981. Which we
> could specify that as a constant, but I like proving it through the
> software first (plausibly once) when we ask for it.
So, by your description:
ML^3 * (ML^1T^2 * L^1)^1 = L^1T^2.
This latter part is the dimension your factor is in.
using namespace boost::units;
typedef derived_dimension<length_base_dimension, 1,
time_base_dimension, 2>::type funky_factor_dimension
typedef unit<funky_factor_dimension, si::system> funky_factor;
quantity<funky_factor> factor(quantity<si::pressure> p,
quantity<si::length> l, quantity<si::mass_density> d)
{
return (p / l) / d;
}
Alternatively:
template < typename System >
quantity<unit<funky_factor_dimension, System>>
factor( quantity<unit<pressure_dimension,System>> p
, quantity<unit<length_dimension,System>> l
, quantity<unit<mass_density_dimension,System>> d )
{
return (p / l) / d;
}
>
> Similar type calculations would follow for US units involving gallons,
> cubic inches, inches, and inches per foot, along these lines.
As long as you use a coherent system, the template version above should
work (assuming I got all the types correct).
Boostusers 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