www.cemf.ir
tripleI.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 template<typename T>
23 pFlow::dot(const triple<T>& oprnd1, const triple<T>& oprnd2)
24 {
25  return oprnd1.x_ * oprnd2.x_ + oprnd1.y_ * oprnd2.y_ +
26  oprnd1.z_ * oprnd2.z_;
27 }
28 
29 template<typename T>
31  pFlow::cross(const triple<T>& v1, const triple<T>& v2)
32 {
33  return triple<T>(
34  v1.y_ * v2.z_ - v1.z_ * v2.y_,
35  v1.z_ * v2.x_ - v1.x_ * v2.z_,
36  v1.x_ * v2.y_ - v1.y_ * v2.x_
37  );
38 }
39 
40 template<typename T>
42 pFlow::length(const triple<T>& v1)
43 {
44  return v1.length();
45 }
46 
47 template<typename T>
49  pFlow::normalize(const triple<T>& v1)
50 {
51  return v1 / max(length(v1), verySmallValue);
52 }
53 
54 template<typename T>
57 {
58  return sqrt(dot(*this, *this));
59 }
60 
61 template<typename T>
64 {
65  *this = *this / max(length(), verySmallValue);
66 }
67 
68 template<typename T>
70 pFlow::operator+(const triple<T>& oprnd1, const triple<T>& oprnd2)
71 {
72  return triple<T>(
73  oprnd1.x_ + oprnd2.x_, oprnd1.y_ + oprnd2.y_, oprnd1.z_ + oprnd2.z_
74  );
75 }
76 
77 template<typename T>
79  pFlow::operator+(const triple<T>& oprnd1, const T& oprnd2)
80 {
81  return triple<T>(
82  oprnd1.x_ + oprnd2, oprnd1.y_ + oprnd2, oprnd1.z_ + oprnd2
83  );
84 }
85 
86 template<typename T>
88  pFlow::operator+(const T& oprnd1, const triple<T>& oprnd2)
89 {
90  return triple<T>(
91  oprnd1 + oprnd2.x_, oprnd1 + oprnd2.y_, oprnd1 + oprnd2.z_
92  );
93 }
94 
95 template<typename T>
97 pFlow::operator-(const triple<T>& oprnd1, const triple<T>& oprnd2)
98 {
99  return triple<T>(
100  oprnd1.x_ - oprnd2.x_, oprnd1.y_ - oprnd2.y_, oprnd1.z_ - oprnd2.z_
101  );
102 }
103 
104 template<typename T>
106  pFlow::operator-(const triple<T>& oprnd1, const T& oprnd2)
107 {
108  return triple<T>(
109  oprnd1.x_ - oprnd2, oprnd1.y_ - oprnd2, oprnd1.z_ - oprnd2
110  );
111 }
112 
113 template<typename T>
115  pFlow::operator-(const T& oprnd1, const triple<T>& oprnd2)
116 {
117  return triple<T>(
118  oprnd1 - oprnd2.x_, oprnd1 - oprnd2.y_, oprnd1 - oprnd2.z_
119  );
120 }
121 
122 template<typename T>
124 pFlow::operator*(const triple<T>& oprnd1, const triple<T>& oprnd2)
125 {
126  return triple<T>(
127  oprnd1.x_ * oprnd2.x_, oprnd1.y_ * oprnd2.y_, oprnd1.z_ * oprnd2.z_
128  );
129 }
130 
131 template<typename T>
133  pFlow::operator*(const triple<T>& oprnd1, const T& oprnd2)
134 {
135  return triple<T>(
136  oprnd1.x_ * oprnd2, oprnd1.y_ * oprnd2, oprnd1.z_ * oprnd2
137  );
138 }
139 
140 template<typename T>
142  pFlow::operator*(const T& oprnd1, const triple<T>& oprnd2)
143 {
144  return triple<T>(
145  oprnd1 * oprnd2.x_, oprnd1 * oprnd2.y_, oprnd1 * oprnd2.z_
146  );
147 }
148 
149 template<typename T>
151 pFlow::operator/(const triple<T>& oprnd1, const triple<T>& oprnd2)
152 {
153  return triple<T>(
154  oprnd1.x_ / oprnd2.x_, oprnd1.y_ / oprnd2.y_, oprnd1.z_ / oprnd2.z_
155  );
156 }
157 
158 template<typename T>
160  pFlow::operator/(const triple<T>& oprnd1, const T& oprnd2)
161 {
162  return triple<T>(
163  oprnd1.x_ / oprnd2, oprnd1.y_ / oprnd2, oprnd1.z_ / oprnd2
164  );
165 }
166 
167 template<typename T>
169  pFlow::operator/(const T& oprnd1, const triple<T>& oprnd2)
170 {
171  return triple<T>(
172  oprnd1 / oprnd2.x_, oprnd1 / oprnd2.y_, oprnd1 / oprnd2.z_
173  );
174 }
175 
176 template<typename T>
179 {
180  this->x_ = this->x_ + oprnd2.x_;
181  this->y_ = this->y_ + oprnd2.y_;
182  this->z_ = this->z_ + oprnd2.z_;
183 }
184 
185 template<typename T>
188 {
189  this->x_ = this->x_ - oprnd2.x_;
190  this->y_ = this->y_ - oprnd2.y_;
191  this->z_ = this->z_ - oprnd2.z_;
192 }
193 
194 template<typename T>
197 {
198  this->x_ = this->x_ * oprnd2.x_;
199  this->y_ = this->y_ * oprnd2.y_;
200  this->z_ = this->z_ * oprnd2.z_;
201 }
202 
203 template<typename T>
206 {
207  this->x_ = this->x_ / oprnd2.x_;
208  this->y_ = this->y_ / oprnd2.y_;
209  this->z_ = this->z_ / oprnd2.z_;
210 }
211 
212 template<typename T>
215 {
216  return triple<T>(-this->x_, -this->y_, -this->z_);
217 }
218 
219 template<typename T>
222 {
223  return *this;
224 }
225 
226 template<typename T>
228 pFlow::operator==(const triple<T>& opr1, const triple<T>& opr2)
229 {
230  return equal(opr1, opr2);
231 };
232 
233 template<typename T>
235 pFlow::operator<(const triple<T>& opr1, const triple<T>& opr2)
236 {
237  if (opr1.x_ < opr2.x_ && opr1.y_ < opr2.y_ && opr1.z_ < opr2.z_)
238  {
239  return true;
240  }
241  else
242  {
243  return false;
244  }
245 };
246 
247 template<typename T>
249 pFlow::operator>(const triple<T>& opr1, const triple<T>& opr2)
250 {
251  if (opr1.x_ > opr2.x_ && opr1.y_ > opr2.y_ && opr1.z_ > opr2.z_)
252  {
253  return true;
254  }
255  else
256  {
257  return false;
258  }
259 };
260 
261 template<typename T>
263 pFlow::operator<=(const triple<T>& opr1, const triple<T>& opr2)
264 {
265  if (opr1.x_ <= opr2.x_ && opr1.y_ <= opr2.y_ && opr1.z_ <= opr2.z_)
266  {
267  return true;
268  }
269  else
270  {
271  return false;
272  }
273 }
274 
275 template<typename T>
277 pFlow::operator>=(const triple<T>& opr1, const triple<T>& opr2)
278 {
279  if (opr1.x_ >= opr2.x_ && opr1.y_ >= opr2.y_ && opr1.z_ >= opr2.z_)
280  {
281  return true;
282  }
283  else
284  {
285  return false;
286  }
287 }
288 
289 template<typename T>
291  pFlow::operator<<(iOstream& str, const triple<T>& ov)
292 {
293  str << token::BEGIN_LIST << ov.x_ << token::SPACE << ov.y_ << token::SPACE
294  << ov.z_ << token::END_LIST;
295 
296  str.check(FUNCTION_NAME);
297 
298  return str;
299 }
300 
301 template<typename T>
303  pFlow::operator>>(iIstream& str, triple<T>& iv)
304 {
305  str.readBegin("triple<T>");
306 
307  str >> iv.x_;
308  str >> iv.y_;
309  str >> iv.z_;
310 
311  str.readEnd("triple<T>");
312 
313  str.check(FUNCTION_NAME);
314 
315  return str;
316 }
317 
318 template<typename T>
319 INLINE_FUNCTION void
320 pFlow::readIstream(iIstream& str, triple<T>& iv)
321 {
322  str.readBegin("triple<T>");
323  T val;
324 
325  readIstream(str, val);
326  iv.x_ = val;
327 
328  readIstream(str, val);
329  iv.y_ = val;
330 
331  readIstream(str, val);
332  iv.z_ = val;
333 
334  str.readEnd("triple<T>");
335 
336  str.check(FUNCTION_NAME);
337 }
338 
339 template<typename T>
341 pFlow::equal(const triple<T>& opr1, const triple<T>& opr2)
342 {
343  return equal(opr1.x(), opr2.x()) && equal(opr1.y(), opr2.y()) &&
344  equal(opr1.z(), opr2.z());
345 }
normalize
INLINE_FUNCTION_HD triple< T > normalize(const triple< T > &v1)
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:238
pFlow::triple::operator+=
INLINE_FUNCTION_HD void operator+=(const triple &oprnd2)
Definition: tripleI.hpp:178
pFlow::verySmallValue
const real verySmallValue
Definition: numericConstants.hpp:32
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:66
pFlow::triple::operator*=
INLINE_FUNCTION_HD void operator*=(const triple &oprnd2)
Definition: tripleI.hpp:196
pFlow::sqrt
Vector< T, Allocator > sqrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:90
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::equal
INLINE_FUNCTION_HD bool equal(const box &b1, const box &b2, real tol=smallValue)
Definition: box.hpp:135
pFlow::operator==
INLINE_FUNCTION_HD bool operator==(const box &b1, const box &b2)
Definition: box.hpp:142
pFlow::operator/
fileSystem operator/(const fileSystem &fs1, const fileSystem &fs2)
Definition: fileSystem.cpp:280
operator<
INLINE_FUNCTION_HD bool operator<(const triple< T > &opr1, const triple< T > &opr2)
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::operator-
array2D< T, nRow, nCol > operator-(const array2D< T, nRow, nCol > &arr1, const array2D< T, nRow, nCol > &arr2)
Definition: array2D.hpp:60
operator<=
INLINE_FUNCTION_HD bool operator<=(const triple< T > &opr1, const triple< T > &opr2)
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
cross
INLINE_FUNCTION_HD triple< T > cross(const triple< T > &v1, const triple< T > &v2)
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::triple::operator-
INLINE_FUNCTION_HD triple operator-() const
unary negate operator
Definition: tripleI.hpp:214
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::triple::operator-=
INLINE_FUNCTION_HD void operator-=(const triple &oprnd2)
Definition: tripleI.hpp:187
pFlow::triple::normalize
INLINE_FUNCTION_HD void normalize()
Normalize the vector.
Definition: tripleI.hpp:63
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::triple::x_
T x_
data members
Definition: triple.hpp:49
readIstream
INLINE_FUNCTION_H void readIstream(iIstream &str, quadruple< T > &iv)
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
operator>
INLINE_FUNCTION_HD bool operator>(const triple< T > &opr1, const triple< T > &opr2)
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::operator*
array2D< T, nRow, nCol > operator*(const array2D< T, nRow, nCol > &arr1, const array2D< T, nRow, nCol > &arr2)
Definition: array2D.hpp:73
pFlow::triple::z_
T z_
Definition: triple.hpp:51
operator>=
INLINE_FUNCTION_HD bool operator>=(const triple< T > &opr1, const triple< T > &opr2)
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::operator+
message operator+(message::EVENT evnt1, message::EVENT evnt2)
Definition: message.hpp:216
pFlow::triple::length
INLINE_FUNCTION_HD T length() const
Length of the vector.
Definition: tripleI.hpp:56