Boost logo

Boost :

From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2007-07-24 14:16:01

First, ignore the value problems and such...I know the tests will fail.
  Just trying to understand typing for now.

In one unit test this compiles and succeeds:

     CPPUNIT_ASSERT(abs(sr.get<0>() - (773.0 * rpm)) < (1.0 * rpm));
     CPPUNIT_ASSERT(abs(sr.get<1>() - (.11666667 * hp)) < (.002 * hp));

That is a custom system (actually a set of independent systems since I
was working in units that aren't systemic). "sr" is a tuple containing
quantities of the corresponding units.

In another unit test trying to work with the SI system this won't compile:

   vflow_qty Q = 10.0 * gpm; // 0.000630901967 m^3s^-1
   vflow_qty x = .6 * m3ps;

   CPPUNIT_ASSERT( abs(Q - x) < (.00006 * m3ps)); // less than +/- 1%

Right now gpm is just another unit instance just like m3ps - I never got
past this stage in my unit testing.

This DOES compile:

   CPPUNIT_ASSERT( abs(Q - x) < (.00006)); // less than +/- 1%

The compile failure shows that abs() is returning a dimensionless type;
this seems to coincide better with the documentation. If this is the
case, how did the previous versions work just fine? The rpm and hp
units are not dimensionless. Looking at it, the first version doesn't
use my own creation of composite dimensions - maybe I don't understand
how to do that correctly. Full code of the two setups follows, first is
the one that works, second is the one that does not:


     namespace gearpump_system
       /// \cond
       struct gp_sys_press_tag : boost::units::ordinal<101> {};
       struct gp_sys_speed_tag : boost::units::ordinal<102> {};
       struct gp_sys_flow_tag : boost::units::ordinal<103> {};
       struct gp_sys_visc_tag : boost::units::ordinal<104> {};
       struct gp_sys_power_tag : boost::units::ordinal<105> {};
       /// \endcond

       /// System for pressure quantities (psi)
       typedef boost::units::heterogeneous_system<gp_sys_press_tag>
       /// System for frequency quantities (rpm)
       typedef boost::units::heterogeneous_system<gp_sys_speed_tag>
       /// System for volumetric flow quantities (gpm)
       typedef boost::units::heterogeneous_system<gp_sys_flow_tag>
       /// System for kinematic viscosity quantities (ssu)
       typedef boost::units::heterogeneous_system<gp_sys_visc_tag>
       /// System for power quantities (hp)
       typedef boost::units::heterogeneous_system<gp_sys_power_tag>

       /// \cond
boost::units::composite_dimension<boost::units::length_tag, 3,
boost::units::time_tag, -1> flow_type;
       typedef boost::units::composite_dimension
             boost::units::length_tag, 2
           , boost::units::time_tag, -1
       /// \endcond

       /// Unit type for pressure quantitien
       typedef boost::units::unit<boost::units::pressure_type,
pressure_system> pressure;
       /// Unit type for volumetric flow quantities
       typedef boost::units::unit<flow_type, flow_system> flow_rate;
       /// Unit for frequency quantities
       typedef boost::units::unit<boost::units::frequency_type,
speed_system> frequency;
       /// Unit for power quantities
       typedef boost::units::unit<boost::units::power_type,
power_system> power;
       /// Unit for kinematic viscosity quantities
       typedef boost::units::unit<kinematic_viscosity_type, visc_system>

       // This doesn't work for doxygen. Figure out later maybe...
       ** \var static pressure psi
       ** \brief Pressure unit instance
       BOOST_UNITS_STATIC_CONSTANT(psi, pressure);
       BOOST_UNITS_STATIC_CONSTANT(gpm, flow_rate);
       BOOST_UNITS_STATIC_CONSTANT(rpm, frequency);
       BOOST_UNITS_STATIC_CONSTANT(ssu, kinematic_viscosity);

       /// Pressure values
       typedef boost::units::quantity<pressure> pressure_qty;
       /// Volumetric flow values
       typedef boost::units::quantity<flow_rate> flow_qty;
       /// Frequency values
       typedef boost::units::quantity<frequency> frequency_qty;
       /// Power values
       typedef boost::units::quantity<power> power_qty;
       /// Kinematic viscosity values
       typedef boost::units::quantity<kinematic_viscosity>

   namespace units
     using namespace boost::units;

     namespace gearpump_system
       using namespace boost::units::SI;

       typedef composite_dimension<boost::units::length_tag, 3,
boost::units::time_tag, -1> vflow_type;

       typedef unit<vflow_type, SI::system> vflow;

       typedef quantity<vflow> vflow_qty;

       BOOST_UNITS_STATIC_CONSTANT(gpm, vflow_qty);
       BOOST_UNITS_STATIC_CONSTANT(m3ps, vflow_qty);

Boost list run by bdawes at, gregod at, cpdaniel at, john at