OpenStructure
physical_units.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 #ifndef IMG_PHYSICS_UNITS_HH
21 #define IMG_PHYSICS_UNITS_HH
22 
23 #include <boost/mpl/vector_c.hpp>
24 #include<boost/mpl/placeholders.hpp>
25 #include <boost/mpl/plus.hpp>
26 #include <boost/mpl/transform.hpp>
27 #include <ost/base.hh>
28 
29 namespace ost { namespace img { namespace physics{
30 
31 namespace detail{
32 
33 namespace mpl = boost::mpl;
34 
35 typedef mpl::vector_c<int,1,0,0,0,0,0,0> mass_dimension;
36 typedef mpl::vector_c<int,0,1,0,0,0,0,0> length_dimension; // or position
37 typedef mpl::vector_c<int,0,0,1,0,0,0,0> time_dimension;
38 typedef mpl::vector_c<int,0,0,0,1,0,0,0> charge_dimension;
39 typedef mpl::vector_c<int,0,0,0,0,1,0,0> temperature_dimension;
40 typedef mpl::vector_c<int,0,0,0,0,0,1,0> intensity_dimension;
41 typedef mpl::vector_c<int,0,0,0,0,0,0,1> amount_dimension;
42 typedef mpl::vector_c<int,0,1,-1,0,0,0,0> velocity_dimension; // l/t
43 typedef mpl::vector_c<int,0,1,-2,0,0,0,0> acceleration_dimension; // l/(t2)
44 typedef mpl::vector_c<int,1,1,-1,0,0,0,0> momentum_dimension; // ml/t
45 typedef mpl::vector_c<int,1,1,-2,0,0,0,0> force_dimension; // ml/(t2)
46 typedef mpl::vector_c<int,0,0,0,0,0,0,0> scalar_dimension;
47 
48 
49 template <class Dimensions>
50 class quantity
51 {
52 public:
54  template <class D2>
55  quantity(const quantity<D2>& rhs);
56  explicit quantity(Real x);
57  Real value() const;
58 
59 protected:
61 };
62 
63 template <class D>
65 template <class D>
67 
68 
69 template <class D1, class D2>
70 struct multiply_dimensions: mpl::transform<D1,D2,mpl::plus<mpl::placeholders::_1,mpl::placeholders::_2> >
71 {
72 };
73 template <class D1, class D2>
75 
76 template <class D1, class D2>
77 struct divide_dimensions: mpl::transform<D1,D2,mpl::minus<mpl::placeholders::_1,mpl::placeholders::_2> >
78 {
79 };
80 template <class D1, class D2>
82 
83 
84 }// detail ns
85 
86 
97 
98 
99 // provide implicit conversion from/to Real for Scalar
100 class Scalar : public detail::quantity<detail::scalar_dimension>
101 {
102 public:
103  Scalar(Real x): detail::quantity<detail::scalar_dimension>(x)
104  {
105  }
106 
107  operator Real()
108  {
109  return value_;
110  }
111 
112 };
113 }}}//ns
114 
115 #endif
quantity(const quantity< D2 > &rhs)
float Real
Definition: base.hh:44
mpl::vector_c< int, 0, 1,-2, 0, 0, 0, 0 > acceleration_dimension
mpl::vector_c< int, 1, 1,-2, 0, 0, 0, 0 > force_dimension
mpl::vector_c< int, 0, 0, 0, 0, 0, 0, 1 > amount_dimension
mpl::vector_c< int, 0, 0, 0, 0, 0, 0, 0 > scalar_dimension
quantity< D > operator-(quantity< D > x, quantity< D > y)
quantity< D > operator+(quantity< D > x, quantity< D > y)
mpl::vector_c< int, 1, 1,-1, 0, 0, 0, 0 > momentum_dimension
mpl::vector_c< int, 0, 1,-1, 0, 0, 0, 0 > velocity_dimension
quantity< typename multiply_dimensions< D1, D2 >::type > operator*(quantity< D1 > x, quantity< D2 > y)
mpl::vector_c< int, 0, 0, 1, 0, 0, 0, 0 > time_dimension
quantity< typename divide_dimensions< D1, D2 >::type > operator/(quantity< D1 > x, quantity< D2 > y)
mpl::vector_c< int, 0, 0, 0, 0, 0, 1, 0 > intensity_dimension
mpl::vector_c< int, 0, 0, 0, 1, 0, 0, 0 > charge_dimension
mpl::vector_c< int, 0, 1, 0, 0, 0, 0, 0 > length_dimension
mpl::vector_c< int, 0, 0, 0, 0, 1, 0, 0 > temperature_dimension
mpl::vector_c< int, 1, 0, 0, 0, 0, 0, 0 > mass_dimension
detail::quantity< detail::intensity_dimension > Intensity
detail::quantity< detail::time_dimension > Time
detail::quantity< detail::length_dimension > Length
detail::quantity< detail::temperature_dimension > Temperature
detail::quantity< detail::force_dimension > Force
detail::quantity< detail::charge_dimension > Charge
detail::quantity< detail::mass_dimension > Mass
detail::quantity< detail::velocity_dimension > Velocity
detail::quantity< detail::amount_dimension > Amount
detail::quantity< detail::momentum_dimension > Momentum
Definition: base.dox:1