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 
21 #ifndef __triple_hpp__
22 #define __triple_hpp__
23 
24 #include "pFlowMacros.hpp"
25 #include "numericConstants.hpp"
26 #include "uniquePtr.hpp"
27 #include "iOstream.hpp"
28 #include "iIstream.hpp"
29 #include "error.hpp"
30 
31 
32 
33 namespace pFlow
34 {
35 
36 
37 template<typename T> class triple;
38 
39 
40 #include "tripleFwd.hpp"
41 
42 
43 // for 3D vectors
44 // it should be used only for numeric types, real, unit
45 template <typename T>
46 struct triple
47 {
48  // data members
49  T x_;
50  T y_;
51  T z_;
52 
53  // initilizes to zero
55  x_(0),
56  y_(0),
57  z_(0)
58  {}
59 
60  // Constructors
61  INLINE_FUNCTION_HD triple(const T &x, const T &y, const T &z):
62  x_(x),
63  y_(y),
64  z_(z)
65  {}
66 
68  triple(v, v, v)
69  {}
70 
71  // type conversion trough assignment
72  template <typename T2>
74  {
75  this->x_ = static_cast<T>(rhs.x_);
76  this->y_ = static_cast<T>(rhs.y_);
77  this->z_ = static_cast<T>(rhs.z_);
78  return *this;
79  }
80 
81  // type casting through copy constructor
82  template<typename T2>
84  x_(static_cast<T>(src.x_)),
85  y_(static_cast<T>(src.y_)),
86  z_(static_cast<T>(src.z_))
87  {
88  }
89 
90  // copy construct
92  triple(const triple<T>& src) = default;
93 
94  // volatile copy construct
95  /*INLINE_FUNCTION_HD
96  triple(volatile triple<T>& src):
97  x_(src.x_),
98  y_(src.y_),
99  z_(src.z_)
100  {}*/
101 
102  /*INLINE_FUNCTION_HD
103  triple& operator=(volatile triple<T>& src)
104  {
105  x_ = src.x_;
106  y_ = src.y_;
107  z_ = src.z_;
108  }*/
109 
110  // move construct
112  triple(triple<T>&& src) = default;
113 
114  // copy assignment
116  triple<T>& operator=(const triple<T>& src) = default;
117 
118  // move assignment
120  triple<T>& operator=(triple<T>&& src) = default;
121 
122  // clone
125  {
126  return makeUnique<triple<T>>(*this);
127  }
128 
131  {
132  return new triple<T>(*this);
133  }
134 
136 
137  // access
138  INLINE_FUNCTION_HD T & x(){ return x_; }
139  INLINE_FUNCTION_HD const T & x()const { return x_; }
140 
141  INLINE_FUNCTION_HD T & y(){ return y_; }
142  INLINE_FUNCTION_HD const T & y()const { return y_; }
143 
144  INLINE_FUNCTION_HD T & z(){ return z_; }
145  INLINE_FUNCTION_HD const T & z()const { return z_; }
146 
147  // methods
148  friend FUNCTION_HD T dot <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
149 
150  friend FUNCTION_HD triple<T> cross <T>(const triple<T> & v1, const triple<T> & v2);
151 
152  INLINE_FUNCTION_HD T length() const;
153 
155 
156 
157 
159 
160  // + operator
161  friend FUNCTION_HD triple<T> operator+ <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
162 
163  friend FUNCTION_HD triple<T> operator+ <T> (const triple<T> & oprnd1, const T & oprnd2);
164 
165  friend FUNCTION_HD triple<T> operator+ <T> (const T & oprnd1, const triple<T> & oprnd2);
166 
167  // - operator
168  friend FUNCTION_HD triple<T> operator - <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
169 
170  friend FUNCTION_HD triple<T> operator - <T> (const triple<T> & oprnd1, const T & oprnd2);
171 
172  friend FUNCTION_HD triple<T> operator - <T> (const T & oprnd1, const triple<T> & oprnd2);
173 
174  // * operators
175  friend FUNCTION_HD triple<T> operator * <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
176 
177  friend FUNCTION_HD triple<T> operator * <T> (const triple<T> & oprnd1, const T & oprnd2);
178 
179  friend FUNCTION_HD triple<T> operator * <T> (const T & oprnd1, const triple<T> & oprnd2);
180 
181  // / operators
182  friend FUNCTION_HD triple<T> operator / <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
183 
184  friend FUNCTION_HD triple<T> operator / <T> (const triple<T> & oprnd1, const T & oprnd2);
185 
186  friend FUNCTION_HD triple<T> operator / <T> (const T & oprnd1, const triple<T> & oprnd2);
187 
188 
189  INLINE_FUNCTION_HD void operator+= (const triple & oprnd2);
190 
191  INLINE_FUNCTION_HD void operator-= (const triple & oprnd2);
192 
193  INLINE_FUNCTION_HD void operator*= (const triple & oprnd2);
194 
195  INLINE_FUNCTION_HD void operator/= (const triple & oprnd2);
196 
197 
198  // unary negate operator
200 
201  // unary plus operator
203 
204 
205  friend FUNCTION_HD bool operator == <T> (const triple<T> &opr1, const triple<T> &opr2);
206 
207  friend FUNCTION_HD bool operator < <T> (const triple<T> &opr1, const triple<T> &opr2);
208 
209  friend FUNCTION_HD bool operator > <T> (const triple<T> &opr1, const triple<T> &opr2);
210 
211  friend FUNCTION_HD bool operator >= <T> (const triple<T> &opr1, const triple<T> &opr2);
212 
213  friend FUNCTION_HD bool operator <= <T> (const triple<T> &opr1, const triple<T> &opr2);
214 
215  // << operator
216  friend iOstream& operator<< <T> (iOstream& str, const triple<T> & ov);
217 
218  // >> operator
219  friend iIstream& operator >> <T> (iIstream & str, triple<T> & iv);
220 
221  // same as >> operator, but faster, good for mass read
222  friend void readIstream <T>( iIstream& str, triple<T> &iv);
223 
224 };
225 
226 template<typename T>
227 bool INLINE_FUNCTION_HD equal( const triple<T>& opr1, const triple<T>& opr2 );
228 
229 
230 } // end of pFlow
231 
232 #include "tripleI.hpp"
233 #include "tripleMath.hpp"
234 
235 
236 #endif
pFlow::triple::y
const INLINE_FUNCTION_HD T & y() const
Definition: triple.hpp:142
pFlow::triple::operator+=
INLINE_FUNCTION_HD void operator+=(const triple &oprnd2)
Definition: tripleI.hpp:255
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:62
pFlow::triple::operator*=
INLINE_FUNCTION_HD void operator*=(const triple &oprnd2)
Definition: tripleI.hpp:277
iIstream.hpp
pFlow::triple::clone
INLINE_FUNCTION uniquePtr< triple< T > > clone() const
Definition: triple.hpp:124
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const T &v)
Definition: triple.hpp:67
tripleMath.hpp
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const T &x, const T &y, const T &z)
Definition: triple.hpp:61
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow
Definition: demComponent.hpp:28
pFlow::triple::x
const INLINE_FUNCTION_HD T & x() const
Definition: triple.hpp:139
uniquePtr.hpp
tripleFwd.hpp
pFlow::iIstream
Definition: iIstream.hpp:33
pFlowMacros.hpp
pFlow::triple::clonePtr
INLINE_FUNCTION triple< T > * clonePtr() const
Definition: triple.hpp:130
pFlow::triple::operator-
INLINE_FUNCTION_HD triple operator-() const
Definition: tripleI.hpp:299
pFlow::triple::z
const INLINE_FUNCTION_HD T & z() const
Definition: triple.hpp:145
pFlow::triple::operator-=
INLINE_FUNCTION_HD void operator-=(const triple &oprnd2)
Definition: tripleI.hpp:266
pFlow::triple::triple
INLINE_FUNCTION_HD triple(const triple< T2 > &src)
Definition: triple.hpp:83
pFlow::triple::normalize
INLINE_FUNCTION_HD void normalize()
Definition: tripleI.hpp:72
pFlow::triple::x_
T x_
Definition: triple.hpp:49
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.hpp:57
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::triple::operator=
INLINE_FUNCTION_HD triple< T > & operator=(const triple< T2 > &rhs)
Definition: triple.hpp:73
pFlow::triple::z_
T z_
Definition: triple.hpp:51
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
numericConstants.hpp
iOstream.hpp
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple
Definition: triple.hpp:37
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::triple::operator+
INLINE_FUNCTION_HD triple operator+() const
Definition: tripleI.hpp:307
pFlow::equal
INLINE_FUNCTION_HD bool equal(const real &s1, const real &s2)
Definition: bTypesFunctions.hpp:188
pFlow::triple::operator/=
INLINE_FUNCTION_HD void operator/=(const triple &oprnd2)
Definition: tripleI.hpp:288
pFlow::triple::triple
INLINE_FUNCTION_HD triple()
Definition: triple.hpp:54
error.hpp
tripleI.hpp
pFlow::triple::length
INLINE_FUNCTION_HD T length() const
Definition: tripleI.hpp:64