Boost logo

Boost Users :

Subject: [Boost-users] Feedback on units use
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2009-08-27 18:44:42


Is there a better way to do the following? The purpose is to provide a
conversion from a pressure to a head given the density of the fluid the
head should be in. Head is "hydrostatic pressure" and is a measure of
the length a fluid can be pushed up a column at pressure X. The value
is a function of the fluid and of the pressure acted upon that fluid.

Object is to do this in any system. Part of the equation is the
constant "g", which is acceleration due to gravity. We're modeling
objects on earth so the value of g is 9.80665 m/s^2. The conversion
equation is very basic:

h = p / (d * g)

where h is the headloss in length, p is pressure, d is mass density, and
g is the gravitational constant.

#include <boost/units/quantity.hpp>
#include <boost/units/physical_dimensions.hpp>

template < typename T, typename System >
struct acceleration_due_to_gravity;

template < typename T, typename System >
boost::units::quantity<
boost::units::unit<boost::units::length_dimension, System>, T >
pressure_to_head( boost::units::quantity<
boost::units::unit<boost::units::pressure_dimension, System>, T > press
                 , boost::units::quantity<
boost::units::unit<boost::units::mass_density_dimension, System>, T>
density)
{
   return press / (density *
acceleration_due_to_gravity<T,System>::value());
}

#include <boost/units/systems/si.hpp>
template < typename T >
struct acceleration_due_to_gravity<T, boost::units::si::system>
{
   typedef boost::units::si::system System;

   static boost::units::quantity< boost::units::unit<
boost::units::acceleration_dimension, System>, T>
     value() { return boost::units::quantity<boost::units::unit<
boost::units::acceleration_dimension, System>, T>::from_value(9.80665); }
};


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