www.cemf.ir
Range.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 #ifndef __Range_hpp__
21 #define __Range_hpp__
22 
23 #include <Kokkos_Core.hpp>
24 
25 #include "builtinTypes.hpp"
26 #include "iOstream.hpp"
27 #include "pFlowMacros.hpp"
28 #include "typeInfo.hpp"
29 
30 namespace pFlow
31 {
32 
37 template<typename T>
38 struct Range : public Kokkos::pair<T, T>
39 {
40  using Pair = Kokkos::pair<T, T>;
41 
42  TypeInfoTemplateNV11("Range", T)
43 
44 
45 
47  INLINE_FUNCTION_HD Range() = default;
48 
51  explicit Range(const T& e)
52  : Range(0, e)
53  {
54  }
55 
58  Range(const T& s, const T& e)
59  : Range::Pair(s, e)
60  {
61  }
62 
65  Range(const Range::Pair& src)
66  : Range::Pair(src)
67  {
68  }
69 
72  Range(const Range&) = default;
73 
76  Range(Range&&) = default;
77 
80  Range& operator=(const Range&) = default;
81 
84  Range& operator=(Range&&) = default;
85 
88  ~Range() = default;
89 
91 
94  T& start()
95  {
96  return this->first;
97  }
98 
101  T& end()
102  {
103  return this->second;
104  }
105 
107  const T& start() const
108  {
109  return this->first;
110  }
111 
113  const T& end() const
114  {
115  return this->second;
116  }
117 
120  {
121  return end() - start();
122  }
123 
125  auto getPair() const
126  {
127  return Pair(this->first, this->second);
128  }
129 };
130 
131 template<typename T>
132 INLINE_FUNCTION_H iOstream&
133 operator<<(iOstream& os, const Range<T>& rng)
134 {
135  os << "[" << rng.start() << " " << rng.end() << ")";
136  return os;
137 }
138 
140 
142 
144 
146 
147 } // pFlow
148 
149 #endif //__KokkosTypes_hpp__
pFlow::Range::TypeInfoTemplateNV11
TypeInfoTemplateNV11("Range", T) INLINE_FUNCTION_HD Range()=default
Default.
pFlow::Range::~Range
INLINE_FUNCTION_HD ~Range()=default
Destructor.
pFlow::Range::end
INLINE_FUNCTION_HD T & end()
End.
Definition: Range.hpp:101
pFlow::Range::start
INLINE_FUNCTION_HD T & start()
Start.
Definition: Range.hpp:94
pFlow::Range::Range
INLINE_FUNCTION_HD Range(const T &s, const T &e)
From componeents.
Definition: Range.hpp:58
pFlow
Definition: demGeometry.hpp:27
pFlow::Range::Range
INLINE_FUNCTION_HD Range(const T &e)
From end, set start to 0.
Definition: Range.hpp:51
pFlowMacros.hpp
pFlow::Range::numElements
INLINE_FUNCTION_HD T numElements()
Definition: Range.hpp:119
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::Range
Range for elements in an vector [start,end)
Definition: Range.hpp:38
pFlow::Range::operator=
INLINE_FUNCTION_HD Range & operator=(const Range &)=default
Copy assignment.
pFlow::Range::Range
INLINE_FUNCTION_HD Range(const Range::Pair &src)
From pair.
Definition: Range.hpp:65
pFlow::Range::getPair
INLINE_FUNCTION_HD auto getPair() const
Definition: Range.hpp:125
pFlow::Range::start
const INLINE_FUNCTION_HD T & start() const
Definition: Range.hpp:107
typeInfo.hpp
pFlow::Range::end
const INLINE_FUNCTION_HD T & end() const
Definition: Range.hpp:113
iOstream.hpp
builtinTypes.hpp
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::Range< uint32 >::Pair
Kokkos::pair< uint32, uint32 > Pair
Definition: Range.hpp:40
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59