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 (
24  const triple<T> & oprnd1,
25  const triple<T> & oprnd2
26 )
27 {
28  return oprnd1.x_ * oprnd2.x_ +
29  oprnd1.y_ * oprnd2.y_ +
30  oprnd1.z_ * oprnd2.z_ ;
31 }
32 
33 template<typename T>
35 (
36  const triple<T> & v1,
37  const triple<T> & v2
38 )
39 {
40  return triple<T>(
41  v1.y_*v2.z_ - v1.z_*v2.y_,
42  v1.z_*v2.x_ - v1.x_*v2.z_,
43  v1.x_*v2.y_ - v1.y_*v2.x_
44  );
45 }
46 
47 template<typename T>
49 (
50  const triple<T> & v1
51 )
52 {
53  return v1.length();
54 }
55 
56 template<typename T>
58 {
59  return v1/max(length(v1),verySmallValue);
60 }
61 
62 template<typename T>
64 (
65 )const
66 {
67  return sqrt(dot(*this,*this));
68 }
69 
70 template<typename T>
72 (
73 )
74 {
75  *this = *this/max(length(),verySmallValue);
76 }
77 
78 template<typename T>
79 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
80 (
81  const triple<T> & oprnd1,
82  const triple<T> & oprnd2
83 )
84 {
85  return triple<T>(
86  oprnd1.x_ + oprnd2.x_,
87  oprnd1.y_ + oprnd2.y_,
88  oprnd1.z_ + oprnd2.z_
89  );
90 }
91 
92 
93 template<typename T>
94 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
95 (
96  const triple<T> & oprnd1,
97  const T & oprnd2
98 )
99 {
100  return triple<T>(
101  oprnd1.x_ + oprnd2,
102  oprnd1.y_ + oprnd2,
103  oprnd1.z_ + oprnd2
104  );
105 }
106 
107 template<typename T>
108 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
109 (
110  const T & oprnd1,
111  const triple<T> & oprnd2
112 )
113 {
114  return triple<T>(
115  oprnd1 + oprnd2.x_,
116  oprnd1 + oprnd2.y_,
117  oprnd1 + oprnd2.z_
118  );
119 }
120 
121 
122 template<typename T>
123 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
124 (
125  const triple<T> & oprnd1,
126  const triple<T> & oprnd2
127 )
128 {
129  return triple<T>(
130  oprnd1.x_ - oprnd2.x_,
131  oprnd1.y_ - oprnd2.y_,
132  oprnd1.z_ - oprnd2.z_
133  );
134 }
135 
136 
137 template<typename T>
138 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
139 (
140  const triple<T> & oprnd1,
141  const T & oprnd2
142 )
143 {
144  return triple<T>(
145  oprnd1.x_ - oprnd2,
146  oprnd1.y_ - oprnd2,
147  oprnd1.z_ - oprnd2
148  );
149 }
150 
151 template<typename T>
152 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
153 (
154  const T & oprnd1,
155  const triple<T> & oprnd2
156 )
157 {
158  return triple<T>(
159  oprnd1 - oprnd2.x_,
160  oprnd1 - oprnd2.y_,
161  oprnd1 - oprnd2.z_
162  );
163 }
164 
165 
166 template<typename T>
167 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
168 (
169  const triple<T> & oprnd1,
170  const triple<T> & oprnd2
171 )
172 {
173  return triple<T>(
174  oprnd1.x_ * oprnd2.x_,
175  oprnd1.y_ * oprnd2.y_,
176  oprnd1.z_ * oprnd2.z_
177  );
178 }
179 
180 
181 template<typename T>
182 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
183 (
184  const triple<T> & oprnd1,
185  const T & oprnd2
186 )
187 {
188  return triple<T>(
189  oprnd1.x_ * oprnd2,
190  oprnd1.y_ * oprnd2,
191  oprnd1.z_ * oprnd2
192  );
193 }
194 
195 template<typename T>
196 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
197 (
198  const T & oprnd1,
199  const triple<T> & oprnd2
200 )
201 {
202  return triple<T>(
203  oprnd1 * oprnd2.x_,
204  oprnd1 * oprnd2.y_,
205  oprnd1 * oprnd2.z_
206  );
207 }
208 
209 
210 template<typename T>
211 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
212 (
213  const triple<T> & oprnd1,
214  const triple<T> & oprnd2
215 )
216 {
217  return triple<T>(
218  oprnd1.x_ / oprnd2.x_,
219  oprnd1.y_ / oprnd2.y_,
220  oprnd1.z_ / oprnd2.z_
221  );
222 }
223 
224 
225 template<typename T>
226 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
227 (
228  const triple<T> & oprnd1,
229  const T & oprnd2
230 )
231 {
232  return triple<T>(
233  oprnd1.x_ / oprnd2,
234  oprnd1.y_ / oprnd2,
235  oprnd1.z_ / oprnd2
236  );
237 }
238 
239 template<typename T>
240 INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
241 (
242  const T & oprnd1,
243  const triple<T> & oprnd2
244 )
245 {
246  return triple<T>(
247  oprnd1 / oprnd2.x_,
248  oprnd1 / oprnd2.y_,
249  oprnd1 / oprnd2.z_
250  );
251 }
252 
253 template<typename T>
255 (
256  const triple<T> & oprnd2
257 )
258 {
259  this->x_ = this->x_ + oprnd2.x_;
260  this->y_ = this->y_ + oprnd2.y_;
261  this->z_ = this->z_ + oprnd2.z_;
262 }
263 
264 template<typename T>
266 (
267  const triple<T> & oprnd2
268 )
269 {
270  this->x_ = this->x_ - oprnd2.x_;
271  this->y_ = this->y_ - oprnd2.y_;
272  this->z_ = this->z_ - oprnd2.z_;
273 }
274 
275 template<typename T>
277 (
278  const triple<T> & oprnd2
279 )
280 {
281  this->x_ = this->x_ * oprnd2.x_;
282  this->y_ = this->y_ * oprnd2.y_;
283  this->z_ = this->z_ * oprnd2.z_;
284 }
285 
286 template<typename T>
288 (
289  const triple<T> & oprnd2
290 )
291 {
292  this->x_ = this->x_ / oprnd2.x_;
293  this->y_ = this->y_ / oprnd2.y_;
294  this->z_ = this->z_ / oprnd2.z_;
295 }
296 
297 template<typename T>
299 (
300 ) const
301 {
302  return triple<T>(-this->x_, -this->y_, -this->z_);
303 }
304 
305 template<typename T>
307 (
308 ) const
309 {
310  return *this;
311 }
312 
313 
314 template<typename T>
315 INLINE_FUNCTION_HD bool pFlow::operator ==
316 (
317  const triple<T> &opr1,
318  const triple<T> &opr2
319 ){
320  return equal(opr1, opr2);
321 };
322 
323 template<typename T>
324 INLINE_FUNCTION_HD bool pFlow::operator <
325 (
326  const triple<T> &opr1,
327  const triple<T> &opr2
328 )
329 {
330  if( opr1.x_ < opr2.x_ && opr1.y_ < opr2.y_ && opr1.z_ < opr2.z_)
331  {
332  return true;
333  }
334  else
335  {
336  return false;
337  }
338 };
339 
340 template<typename T>
341 INLINE_FUNCTION_HD bool pFlow::operator >
342 (
343  const triple<T> &opr1,
344  const triple<T> &opr2
345 )
346 {
347  if( opr1.x_ > opr2.x_ && opr1.y_ > opr2.y_ && opr1.z_ > opr2.z_)
348  {
349  return true;
350  }
351  else
352  {
353  return false;
354  }
355 };
356 
357 template<typename T>
358 INLINE_FUNCTION_HD bool pFlow::operator <=
359 (
360  const triple<T> &opr1,
361  const triple<T> &opr2
362 )
363 {
364  if( opr1.x_ <= opr2.x_ && opr1.y_ <= opr2.y_ && opr1.z_ <= opr2.z_)
365  {
366  return true;
367  }
368  else
369  {
370  return false;
371  }
372 }
373 
374 
375 template<typename T>
376 INLINE_FUNCTION_HD bool pFlow::operator >=
377 (
378  const triple<T> &opr1,
379  const triple<T> &opr2
380 )
381 {
382  if( opr1.x_ >= opr2.x_ && opr1.y_ >= opr2.y_ && opr1.z_ >= opr2.z_)
383  {
384  return true;
385  }
386  else
387  {
388  return false;
389  }
390 }
391 
392 
393 template<typename T>
394 INLINE_FUNCTION pFlow::iOstream& pFlow::operator <<
395 (
396  iOstream & str,
397  const triple<T> & ov
398 )
399 {
400 
401  str << token::BEGIN_LIST << ov.x_
402  << token::SPACE << ov.y_
403  << token::SPACE << ov.z_
404  << token::END_LIST;
405 
406  str.check(FUNCTION_NAME);
407 
408  return str;
409 }
410 
411 template<typename T>
412 INLINE_FUNCTION pFlow::iIstream& pFlow::operator >>
413 (
414  iIstream & str,
415  triple<T> & iv
416 )
417 {
418 
419  str.readBegin("triple<T>");
420 
421  str >> iv.x_;
422  str >> iv.y_;
423  str >> iv.z_;
424 
425 
426  str.readEnd("triple<T>");
427 
428  str.check(FUNCTION_NAME);
429 
430  return str;
431 }
432 
433 template<typename T>
435 (
436  iIstream & str,
437  triple<T> & iv
438 )
439 {
440 
441  str.readBegin("triple<T>");
442  T val;
443 
444  readIstream(str, val);
445  iv.x_ = val;
446 
447  readIstream(str, val);
448  iv.y_ = val;
449 
450  readIstream(str, val);
451  iv.z_ = val;
452 
453  str.readEnd("triple<T>");
454 
455  str.check(FUNCTION_NAME);
456 
457 }
458 
459 template<typename T>
461 (
462  const triple<T>& opr1,
463  const triple<T>& opr2
464 )
465 {
466  return equal( opr1.x(), opr2.x() ) && equal( opr1.y(), opr2.y() ) && equal( opr1.z(), opr2.z() );
467 }
normalize
INLINE_FUNCTION_HD triple< T > normalize(const triple< T > &v1)
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:203
pFlow::verySmallValue
const real verySmallValue
Definition: numericConstants.hpp:34
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:62
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow::IOstream::check
virtual bool check(const char *operation) const
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
Definition: iIstream.hpp:33
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::triple::normalize
INLINE_FUNCTION_HD void normalize()
Definition: tripleI.hpp:72
pFlow::triple::x_
T x_
Definition: triple.hpp:49
readIstream
INLINE_FUNCTION_H void readIstream(iIstream &str, quadruple< T > &iv)
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
pFlow::sqrt
INLINE_FUNCTION_HD real sqrt(real x)
Definition: math.hpp:148
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple
Definition: triple.hpp:37
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::equal
INLINE_FUNCTION_HD bool equal(const real &s1, const real &s2)
Definition: bTypesFunctions.hpp:188
pFlow::triple::length
INLINE_FUNCTION_HD T length() const
Definition: tripleI.hpp:64