www.cemf.ir
triple.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 __triple_hpp__
21 #define __triple_hpp__
22 
23 #include "pFlowMacros.hpp"
24 #include "numericConstants.hpp"
25 #include "typeInfo.hpp"
26 #include "uniquePtr.hpp"
27 #include "iOstream.hpp"
28 #include "iIstream.hpp"
29 #include "error.hpp"
30 
31 namespace pFlow
32 {
33 
35 template<typename T>
36 class triple;
37 
38 #include "tripleFwd.hpp"
39 
45 template<typename T>
46 struct triple
47 {
49  T x_;
50  T y_;
51  T z_;
52 
55 
57 
60  triple() = default;
61 
63  ~triple() = default;
64 
67  triple(const T& x, const T& y, const T& z)
68  : x_(x),
69  y_(y),
70  z_(z)
71  {
72  }
73 
76  triple(const T& v)
77  : triple(v, v, v)
78  {
79  }
80 
82  template<typename T2>
84  {
85  this->x_ = static_cast<T>(rhs.x_);
86  this->y_ = static_cast<T>(rhs.y_);
87  this->z_ = static_cast<T>(rhs.z_);
88  return *this;
89  }
90 
92  template<typename T2>
94  : x_(static_cast<T>(src.x_)),
95  y_(static_cast<T>(src.y_)),
96  z_(static_cast<T>(src.z_))
97  {
98  }
99 
102  triple(const triple<T>& src) = default;
103 
106  triple(triple<T>&& src) = default;
107 
110  triple<T>& operator=(const triple<T>& src) = default;
111 
114  triple<T>& operator=(triple<T>&& src) = default;
115 
119  {
120  return makeUnique<triple<T>>(*this);
121  }
122 
125  {
126  return new triple<T>(*this);
127  }
128 
130 
133  {
134  return x_;
135  }
136 
138  INLINE_FUNCTION_HD const T& x() const
139  {
140  return x_;
141  }
142 
145  {
146  return y_;
147  }
148 
150  INLINE_FUNCTION_HD const T& y() const
151  {
152  return y_;
153  }
154 
157  {
158  return z_;
159  }
160 
162  INLINE_FUNCTION_HD const T& z() const
163  {
164  return z_;
165  }
166 
169  {
170  return x_;
171  }
172 
174  INLINE_FUNCTION_HD const T& comp1() const
175  {
176  return x_;
177  }
178 
181  {
182  return y_;
183  }
184 
186  INLINE_FUNCTION_HD const T& comp2() const
187  {
188  return y_;
189  }
190 
193  {
194  return z_;
195  }
196 
198  INLINE_FUNCTION_HD const T& comp3() const
199  {
200  return z_;
201  }
202 
204 
206  friend FUNCTION_HD T
207  dot<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
208 
210  friend FUNCTION_HD triple<T>
211  cross<T>(const triple<T>& v1, const triple<T>& v2);
212 
214  INLINE_FUNCTION_HD T length() const;
215 
218 
220 
222  friend FUNCTION_HD triple<T> operator+
223  <T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
224 
225  friend FUNCTION_HD triple<T> operator+
226  <T>(const triple<T>& oprnd1, const T& oprnd2);
227 
228  friend FUNCTION_HD triple<T> operator+
229  <T>(const T& oprnd1, const triple<T>& oprnd2);
230 
232  friend FUNCTION_HD triple<T> operator-
233  <T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
234 
235  friend FUNCTION_HD triple<T> operator-
236  <T>(const triple<T>& oprnd1, const T& oprnd2);
237 
238  friend FUNCTION_HD triple<T> operator-
239  <T>(const T& oprnd1, const triple<T>& oprnd2);
240 
242  friend FUNCTION_HD triple<T> operator*
243  <T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
244 
245  friend FUNCTION_HD triple<T> operator*
246  <T>(const triple<T>& oprnd1, const T& oprnd2);
247 
248  friend FUNCTION_HD triple<T> operator*
249  <T>(const T& oprnd1, const triple<T>& oprnd2);
250 
252  friend FUNCTION_HD triple<T> operator/
253  <T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
254 
255  friend FUNCTION_HD triple<T> operator/
256  <T>(const triple<T>& oprnd1, const T& oprnd2);
257 
258  friend FUNCTION_HD triple<T> operator/
259  <T>(const T& oprnd1, const triple<T>& oprnd2);
260 
261  INLINE_FUNCTION_HD void operator+=(const triple& oprnd2);
262 
263  INLINE_FUNCTION_HD void operator-=(const triple& oprnd2);
264 
265  INLINE_FUNCTION_HD void operator*=(const triple& oprnd2);
266 
267  INLINE_FUNCTION_HD void operator/=(const triple& oprnd2);
268 
271 
274 
275  friend FUNCTION_HD bool operator==
276  <T>(const triple<T>& opr1, const triple<T>& opr2);
277 
278  friend FUNCTION_HD bool
279  operator< <T>(const triple<T>& opr1, const triple<T>& opr2);
280 
281  friend FUNCTION_HD bool operator>
282  <T>(const triple<T>& opr1, const triple<T>& opr2);
283 
284  friend FUNCTION_HD bool operator>=
285  <T>(const triple<T>& opr1, const triple<T>& opr2);
286 
287  friend FUNCTION_HD bool operator<=
288  <T>(const triple<T>& opr1, const triple<T>& opr2);
289 
291 
293  friend iOstream& operator<< <T>(iOstream& str, const triple<T>& ov);
294 
296  friend iIstream& operator>> <T>(iIstream& str, triple<T>& iv);
297 
299  friend void readIstream<T>(iIstream& str, triple<T>& iv);
300 };
301 
302 template<typename T>
304 equal(const triple<T>& opr1, const triple<T>& opr2);
305 
307 equal(const triple<real>& opr1, const triple<real>& opr2, real tol)
308 {
309  return equal(opr1.x(), opr2.x(), tol) && equal(opr1.y(), opr2.y(), tol) &&
310  equal(opr1.z(), opr2.z(), tol);
311 }
312 
313 }
314 
315 #include "tripleI.hpp"
316 #include "tripleMath.hpp"
317 
318 #endif
pFlow::triple::y
const INLINE_FUNCTION_HD T & y() const
access component
Definition: triple.hpp:150
pFlow::triple::operator+=
INLINE_FUNCTION_HD void operator+=(const triple &oprnd2)
Definition: tripleI.hpp:178
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:66
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::triple::operator*=
INLINE_FUNCTION_HD void operator*=(const triple &oprnd2)
Definition: tripleI.hpp:196
iIstream.hpp
pFlow::triple::clone
INLINE_FUNCTION uniquePtr< triple< T > > clone() const
clone
Definition: triple.hpp:118
pFlow::triple::triple
INLINE_FUNCTION_HD triple()=default
Initilize to zero.
pFlow::triple::comp3
INLINE_FUNCTION_HD T & comp3()
access component
Definition: triple.hpp:192
pFlow::equal
INLINE_FUNCTION_HD bool equal(const box &b1, const box &b2, real tol=smallValue)
Definition: box.hpp:135
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const T &v)
Construct from v.
Definition: triple.hpp:76
tripleMath.hpp
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const T &x, const T &y, const T &z)
Construct from x, y, z.
Definition: triple.hpp:67
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow
Definition: demGeometry.hpp:27
pFlow::triple::x
const INLINE_FUNCTION_HD T & x() const
access component
Definition: triple.hpp:138
uniquePtr.hpp
pFlow::triple::comp3
const INLINE_FUNCTION_HD T & comp3() const
access component
Definition: triple.hpp:198
tripleFwd.hpp
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlowMacros.hpp
pFlow::triple::clonePtr
INLINE_FUNCTION triple< T > * clonePtr() const
Definition: triple.hpp:124
pFlow::triple::operator-
INLINE_FUNCTION_HD triple operator-() const
unary negate operator
Definition: tripleI.hpp:214
pFlow::triple::z
const INLINE_FUNCTION_HD T & z() const
access component
Definition: triple.hpp:162
pFlow::triple::~triple
INLINE_FUNCTION_HD ~triple()=default
pFlow::triple::operator-=
INLINE_FUNCTION_HD void operator-=(const triple &oprnd2)
Definition: tripleI.hpp:187
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const triple< T2 > &src)
Type casting through copy constructor.
Definition: triple.hpp:93
pFlow::triple::comp1
const INLINE_FUNCTION_HD T & comp1() const
access component
Definition: triple.hpp:174
pFlow::triple::comp2
const INLINE_FUNCTION_HD T & comp2() const
access component
Definition: triple.hpp:186
pFlow::triple::normalize
INLINE_FUNCTION_HD void normalize()
Normalize the vector.
Definition: tripleI.hpp:63
pFlow::triple::comp1
INLINE_FUNCTION_HD T & comp1()
access component
Definition: triple.hpp:168
pFlow::triple::x_
T x_
data members
Definition: triple.hpp:49
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.hpp:61
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::triple::operator=
INLINE_FUNCTION_HD triple< T > & operator=(const triple< T2 > &rhs)
Type conversion trough assignment.
Definition: triple.hpp:83
pFlow::triple::z_
T z_
Definition: triple.hpp:51
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
typeInfo.hpp
numericConstants.hpp
iOstream.hpp
pFlow::triple::TripleTypeInfoNV
TripleTypeInfoNV(T)
Type info for triple.
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple
A set of 3 variables that can be used for vector variables.
Definition: triple.hpp:36
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::triple::operator+
INLINE_FUNCTION_HD triple operator+() const
unary plus operator
Definition: tripleI.hpp:221
pFlow::triple::operator/=
INLINE_FUNCTION_HD void operator/=(const triple &oprnd2)
Definition: tripleI.hpp:205
pFlow::triple::comp2
INLINE_FUNCTION_HD T & comp2()
access component
Definition: triple.hpp:180
error.hpp
tripleI.hpp
pFlow::triple::length
INLINE_FUNCTION_HD T length() const
Length of the vector.
Definition: tripleI.hpp:56