OpenStructure
Loading...
Searching...
No Matches
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
29namespace ost { namespace img { namespace physics{
30
31namespace detail{
32
33namespace mpl = boost::mpl;
34
35typedef mpl::vector_c<int,1,0,0,0,0,0,0> mass_dimension;
36typedef mpl::vector_c<int,0,1,0,0,0,0,0> length_dimension; // or position
37typedef mpl::vector_c<int,0,0,1,0,0,0,0> time_dimension;
38typedef mpl::vector_c<int,0,0,0,1,0,0,0> charge_dimension;
39typedef mpl::vector_c<int,0,0,0,0,1,0,0> temperature_dimension;
40typedef mpl::vector_c<int,0,0,0,0,0,1,0> intensity_dimension;
41typedef mpl::vector_c<int,0,0,0,0,0,0,1> amount_dimension;
42typedef mpl::vector_c<int,0,1,-1,0,0,0,0> velocity_dimension; // l/t
43typedef mpl::vector_c<int,0,1,-2,0,0,0,0> acceleration_dimension; // l/(t2)
44typedef mpl::vector_c<int,1,1,-1,0,0,0,0> momentum_dimension; // ml/t
45typedef mpl::vector_c<int,1,1,-2,0,0,0,0> force_dimension; // ml/(t2)
46typedef mpl::vector_c<int,0,0,0,0,0,0,0> scalar_dimension;
47
48
49template <class Dimensions>
51{
52public:
54 template <class D2>
56 explicit quantity(Real x);
57 Real value() const;
58
59protected:
61};
62
63template <class D>
65template <class D>
67
68
69template <class D1, class D2>
70struct multiply_dimensions: mpl::transform<D1,D2,mpl::plus<mpl::placeholders::_1,mpl::placeholders::_2> >
71{
72};
73template <class D1, class D2>
75
76template <class D1, class D2>
77struct divide_dimensions: mpl::transform<D1,D2,mpl::minus<mpl::placeholders::_1,mpl::placeholders::_2> >
78{
79};
80template <class D1, class D2>
82
83
84}// detail ns
85
86
97
98
99// provide implicit conversion from/to Real for Scalar
100class Scalar : public detail::quantity<detail::scalar_dimension>
101{
102public:
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)
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
mpl::vector_c< int, 0, 0, 1, 0, 0, 0, 0 > time_dimension
quantity< D > operator-(quantity< D > x, quantity< D > 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
quantity< typename divide_dimensions< D1, D2 >::type > operator/(quantity< D1 > x, quantity< D2 > y)
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
quantity< typename multiply_dimensions< D1, D2 >::type > operator*(quantity< D1 > x, quantity< D2 > y)
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