Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Units.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SKA_CHEETAH_DATA_UNITS_H
25 #define SKA_CHEETAH_DATA_UNITS_H
26 
27 #include <pss/astrotypes/units/Units.h>
28 #include <pss/astrotypes/multiarray/DimensionSpan.h>
29 #include <pss/astrotypes/multiarray/DimensionSize.h>
30 #include <pss/astrotypes/multiarray/DimensionIndex.h>
31 
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wall"
34 #pragma GCC diagnostic ignored "-Wpragmas"
35 #pragma GCC diagnostic ignored "-Wunused-parameter"
36 #pragma GCC diagnostic ignored "-Wunused-variable"
37 #include <boost/units/quantity.hpp>
38 #include <boost/units/conversion.hpp>
39 #include <boost/units/systems/si/frequency.hpp>
40 #include <boost/units/systems/si/prefixes.hpp>
41 #include <boost/units/systems/si/time.hpp>
42 #include <boost/units/systems/si/acceleration.hpp>
43 #include <boost/units/make_scaled_unit.hpp>
44 #include <boost/units/io.hpp>
45 #include <boost/units/systems/si/codata_constants.hpp>
46 #include <boost/chrono/chrono.hpp>
47 #pragma GCC diagnostic pop
48 
49 
50 namespace ska {
51 namespace cheetah {
52 namespace data {
53 
54  using pss::astrotypes::units::Frequency;
55  using pss::astrotypes::units::Time;
56  template<typename T> using DimensionSize = pss::astrotypes::DimensionSize<T>;
57  template<typename T> using DimensionIndex = pss::astrotypes::DimensionIndex<T>;
58  template<typename T> using DimensionSpan = pss::astrotypes::DimensionSpan<T>;
59 
60  // units to be used in boost::quantity<unit, Rep> types
61  typedef typename pss::astrotypes::units::Hertz Hertz;
62  typedef typename pss::astrotypes::units::KiloHertz KiloHertz;
63  typedef typename pss::astrotypes::units::MegaHertz MegaHertz;
64  typedef typename pss::astrotypes::units::Seconds Seconds;
65  typedef typename pss::astrotypes::units::MilliSeconds MilliSeconds;
66  typedef typename pss::astrotypes::units::MicroSeconds MicroSeconds;
67  typedef typename pss::astrotypes::units::NanoSeconds NanoSeconds;
68 
69  static boost::units::si::frequency const hz = boost::units::si::hertz;
70  static boost::units::si::frequency const hertz = boost::units::si::hertz;
71  static const pss::astrotypes::units::MegaHertz megahertz = pss::astrotypes::units::megahertz;
72 
73  static boost::units::si::time const second = boost::units::si::second;
74  static boost::units::si::time const seconds = boost::units::si::second;
75  static const MilliSeconds millisecond;
76  static const MilliSeconds milliseconds;
77  static boost::units::si::acceleration const metres_per_second_squared = boost::units::si::metres_per_second_squared;
78  static boost::units::si::acceleration const metre_per_second_squared = boost::units::si::metres_per_second_squared;
79  static boost::units::si::acceleration const meter_per_second_squared = boost::units::si::metres_per_second_squared;
80  static boost::units::si::acceleration const meters_per_second_squared = boost::units::si::metres_per_second_squared;
81 
82  // add typedefs for commonly used quantities here
83  typedef boost::units::quantity<Hertz, double> FourierFrequencyType; //Hz used for fluctuation frequencies
84  typedef boost::units::quantity<boost::units::si::time, double> TimeType; //s
85  typedef boost::units::quantity<boost::units::si::acceleration, double> AccelerationType; //m/s/s
86  //typedef boost::units::quantity<boost::units::si::dimensionless, float> SigmaType; // sigma of candidate
87  typedef boost::units::quantity<MegaHertz, double> FrequencyType; /* used for observing frequencies */
88 
89  template <typename T>
90  class SecondsType : public boost::units::quantity<boost::units::si::time, T>
91  {
92  typedef boost::units::quantity<boost::units::si::time, T> BaseT;
93 
94  public:
95  SecondsType() {}
96 
97  template<typename Unit, typename YY>
98  SecondsType(boost::units::quantity<Unit, YY> const& arg) : BaseT(arg) {}
99 
101  template<typename DurationRep, typename Period>
102  explicit SecondsType(std::chrono::duration<DurationRep, Period> const& d)
103  : BaseT(std::chrono::duration_cast<std::chrono::duration<DurationRep, std::ratio<1,1>>>(d).count() * seconds)
104  {
105  }
106  };
107 
108 } // namespace data
109 } // namespace cheetah
110 } // namespace ska
111 
112 namespace boost {
113 namespace units {
114  template<typename Unit, typename X, typename Y>
115  inline typename multiply_typeof_helper< X, quantity< Unit, X > >::type
116  operator*(const Y & lhs, const quantity< Unit, X > & rhs)
117  {
118  return static_cast<X>(lhs) * rhs;
119  }
120 
121  template<typename Unit, typename X, typename Y>
122  inline typename divide_typeof_helper< X, quantity< Unit, X > >::type
123  operator/(const Y & lhs, const quantity< Unit, X > & rhs)
124  {
125  return static_cast<X>(lhs) / rhs;
126  }
127 } // namespace units
128 } // namespace boost
129 
130 #endif // SKA_CHEETAH_DATA_UNITS_H
Definition: Units.h:112
Some limits and constants for FLDO.
Definition: Brdz.h:35
SecondsType(std::chrono::duration< DurationRep, Period > const &d)
conversion from std::chrono::duration types
Definition: Units.h:102