Boost logo

Boost Users :

Subject: [Boost-users] [Units] derived units of SI system (newbie)
From: André Berthe (andre.berthe_at_[hidden])
Date: 2010-12-10 07:52:23


Dear List,
 
I would like to calculate a shear stress based on a shear rate and a
viscosity using Boost.Units. Here I have problems using derived
dimensions and conversion factors based on a existing system. The error
messages of my compiler are in German, so I tried to document my
problems with a test code:
 
<main.cpp>
#include <boost/units/systems/si/dynamic_viscosity.hpp>
#include "stress.h"
#include "shearrate.h"
 
namespace bu = boost::units;
namespace SI = bu::si;
 
main(){
   //Define a quantity of unit stress. Unfortunately there is no
   //realization of the defined physical dimension stress in si.
   //So a user defined type from stress.h (see below) is used:
   bu::quantity<SI::stress> WSS_x;
 
   //Define a shear rate. I did not understand how to use a
   //inverse time as dimension. Therefore I defined the derived
   //dimension per_time in shearrate.h. Is it possible to add it to
   //the si system (as I tried) or do I have to define
   //my own system and a conversion factor?
   bu::quantity<SI::per_time> WSR_x(1*per_second);
 
   //There is a existing si type for the dynamic viscosity.
   //However, there is no defined constant. How is the
   //correct way to assign a value? Should I define this
   //constant?
   bu::quantity<SI::dynamic_viscosity> eta;
 
   //Calculation of the shear stress. It seems that this calculation
   //tries to use a »sizeof« on eta, that seems to have a
   // incomplete type
   //(»boost::STATIC_ASSERTION_FAILURE<false>«). And there
   //seems to be something wrong with the conversion.
   //Do I have to define a conversion factor? Or is this error
   //caused by my previous mistakes?
   WSS_x=WSR_x/eta;
}
</main.cpp>
 
Included header file 1:
<stress.h>
#include <boost/units/systems/si/base.hpp>
#include <boost/units/physical_dimensions/stress.hpp>
#include <boost/units/make_system.hpp>
namespace boost {
   namespace units {
      namespace si {
         typedef unit<stress_dimension,si::system> stress;
      } // namespace si
   } // namespace units
} // namespace boost
</stress.h>
 
Included header file 2:
<shearrate.h>
#include <boost/units/base_dimension.hpp>
#include <boost/units/derived_dimension.hpp>
#include <boost/units/io.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/static_constant.hpp>
#include <boost/units/unit.hpp>
#include <boost/units/base_unit.hpp>
#include <boost/units/systems/si/time.hpp>
namespace boost {
  namespace units {
    namespace si {
      typedef derived_dimension< time_base_dimension,-1>::type
per_time_dimension; // [1/m]
       typedef unit< si::per_time_dimension, si::system > per_time;
       static const per_time per_second;
       static const per_time per_seconds;
    }
  }
}

Thank you,
André


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