doc/library/units/units.h

00001 #include <boost/mpl/vector_c.hpp>
00002 
00003 using namespace mpl = boost::mpl;
00004     
00005 namespace remcas {
00006 namespace unit
00007 {   
00008 
00009     typedef mpl::vector_c<int, 0, 0, 0, 0, 0, 0> scalar;
00010 
00013 
00014     // The most commonly used basis for dimensional quantities
00015     // See also: http://en.wikipedia.org/wiki/Natural_units
00016     typedef mpl::vector_c<int, 1, 0, 0, 0, 0, 0> mass;        // Kilogram
00017     typedef mpl::vector_c<int, 0, 1, 0, 0, 0, 0> length;      // Meter
00018     typedef mpl::vector_c<int, 0, 0, 1, 0, 0, 0> time;        // Second
00019     typedef mpl::vector_c<int, 0, 0, 0, 1, 0, 0> charge;      // Coulomb
00020     typedef mpl::vector_c<int, 0, 0, 0, 0, 1, 0> temperature; // Kelvin
00021     typedef mpl::vector_c<int, 0, 0, 0, 0, 0, 1> matter;      // Mole
00022 
00023     // Derived quantities
00024     // See also: http://en.wikipedia.org/wiki/SI_derived_unit
00025     typedef mpl::vector_c<int, 0, 2, 0, 0, 0, 0> area;         // l2
00026     typedef mpl::vector_c<int, 0, 2, 0, 0, 0, 0> volume;       // l3
00027     typedef mpl::vector_c<int, 0, 0,-1, 0, 0, 0> frequency;    // 1/t
00028     typedef mpl::vector_c<int, 0, 1,-1, 0, 0, 0> velocity;     // l/t
00029     typedef mpl::vector_c<int, 0, 1,-2, 0, 0, 0> acceleration; // l/(t2)
00030     typedef mpl::vector_c<int, 0, 1,-3, 0, 0, 0> jerk;         // l/t3
00031     typedef mpl::vector_c<int, 1, 1,-1, 0, 0, 0> momentum;     // ml/t
00032     typedef mpl::vector_c<int, 1, 1,-2, 0, 0, 0> force;        // ml/(t2)
00033     
00034     typedef mpl::vector_c<int, 0, 0,-1, 0, 0, 0> angular_velocity; // s−1
00035     typedef mpl::vector_c<int, 1, 2,-1, 0, 0, 0> angular_momentum; // kg·m2·s−1
00036     typedef mpl::vector_c<int, 1, 2,-2, 0, 0, 0> torque;       // kg·m2·s−2
00037 
00038     typedef mpl::vector_c<int, 1,-3, 0, 0, 0, 0> density;      // m/l3
00039     typedef mpl::vector_c<int, 0,-1, 0, 0, 0, 0> wavenumber;   // 1/l
00040 
00041     typedef mpl::vector_c<int, 1,-1,-2, 0, 0, 0> pressure;     // m−1∙kg∙s−2
00042     typedef mpl::vector_c<int, 1, 2,-2, 0, 0, 0> energy;       // m2∙kg∙s−2
00043     typedef mpl::vector_c<int, 1, 2,-3, 0, 0, 0> power;        // m2∙kg∙s−3
00044     typedef mpl::vector_c<int, 0, 0,-1, 1, 0, 0> current;      // C∙s−1
00045     typedef mpl::vector_c<int, 1, 2,-2,-1, 0, 0> voltage;      // m2∙kg∙s−2∙C−1
00046     typedef mpl::vector_c<int,-1,-2, 2, 2, 0, 0> capacitance;  // m−2∙kg−1∙s2∙C2
00047     typedef mpl::vector_c<int,-1,-2, 2, 2, 0, 0> resistance;   // m2∙kg∙s−1∙C−2
00048     typedef mpl::vector_c<int, 1, 2,-2,-2, 0, 0> conductance;  // m−2∙kg−1∙s∙C2
00049     typedef mpl::vector_c<int, 1, 2, 0,-2, 0, 0> inductance;   // m2∙kg∙C−2
00050     typedef mpl::vector_c<int, 1, 2,-1,-1, 0, 0> flux;         // m2∙kg∙s−1∙C−1
00051     typedef mpl::vector_c<int, 0, 1,-2,-1, 0, 0> field;        // kg∙s−2∙C−1
00052 
00053     // Orientational analysis
00054     typedef mpl::vector_c<int, 0> o0;
00055     typedef mpl::vector_c<int, 1> ox;
00056     typedef mpl::vector_c<int, 2> oy;
00057     typedef mpl::vector_c<int, 3> oz;
00058 
00059     template <class T, class Dimensions>
00060     struct quantity
00061     {
00062         explicit quantity(T x)
00063         : m_value(x)
00064         {}
00065 
00066         T value() const { return m_value; }
00067         private:
00068         T m_value;
00069     };
00070 
00071     template <class T, class D>
00072     quantity<T,D> operator+(quantity<T,D> x, quantity<T,D> y)
00073     {
00074         return quantity<T,D>(x.value() + y.value());
00075     }
00076 
00077     template <class T, class D>
00078     quantity<T,D> operator-(quantity<T,D> x, quantity<T,D> y)
00079     {
00080         return quantity<T,D>(x.value() - y.value());
00081     }
00082 
00083     template <class OtherDimensions>
00084     quantity(quantity<T,OtherDimensions> const& rhs)
00085     : m_value(rhs.value())
00086     {
00087         BOOST_STATIC_ASSERT((
00088             mpl::equal<Dimensions,OtherDimensions>::type::value;
00089         ));
00090     }
00091 
00092     template <class T, class D1, class D2>
00093     quantity<T, typename mpl::transform<D1,D2,mpl::minus<_1,_2> >::type>
00094     operator/(quantity<T,D1> x, quantity<T,D2> y)
00095     {
00096         typedef typename mpl::transform<D1,D2,mpl::minus<_1,_2> >::type dim;
00097         return quantity<T,dim>( x.value() / y.value() );
00098     }
00099 
00100 }}

Copyright © 2007-2008 Remco Bloemen.

Generated on Tue Jan 22 17:35:31 2008 for symbolism by doxygen 1.5.4

Hosted by SourceForge.net Logo