
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); } };