pLine.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 __pLine_hpp__
22 #define __pLine_hpp__
23 
24 #include "types.hpp"
25 
27 {
28 
29 struct pLine
30 {
31 
32  realx3 p1_; // point 1
33  realx3 p2_; // piont 2
34  realx3 v_; // direction vector
35  real L_; // line lenght
36 
38  pLine(){}
39 
41  pLine(const realx3 &p1, const realx3 &p2)
42  :
43  p1_(p1),
44  p2_(p2),
45  v_(p2-p1),
46  L_(length(v_))
47  {}
48 
49  // get a point on the line based on input 0<= t <= 1
51  realx3 point(real t)const {
52  return v_ * t + p1_;
53  }
54 
55  // return the projected point of point p on line
57  realx3 projectPoint(const realx3 &p) const
58  {
59  return point(projectNormLength(p));
60  }
61 
62  // calculates the normalized distance between projected p and p1
65  {
66  realx3 w = p - p1_;
67  return dot(w,v_) / (L_*L_);
68  }
69 
72  const realx3 pos,
73  real Rad,
74  realx3 &nv,
75  realx3 &cp,
76  real &ovrlp)const
77  {
78 
79 
80  real t = projectNormLength(pos);
81 
82  if(t >= 0.0 && t <= 1.0) cp = point(t);
83  else if(t >= (-Rad / L_) && t < 0.0) cp = point(0.0);
84  else if(t>1.0 && t >= (1.0 + Rad / L_)) cp = point(1.0);
85  else return false;
86 
87  realx3 vec = pos - cp; // from cp to pos
88 
89  real dist = length(vec);
90  ovrlp = Rad - dist;
91 
92  if (ovrlp >= 0.0)
93  {
94  if (dist > 0)
95  nv = vec / dist;
96  else
97  nv = v_;
98  return true;
99  }
100 
101  return false;
102  }
103 };
104 
105 } //pFlow::sphTriInteractio
106 
107 #endif
pFlow::sphTriInteraction::pLine::point
INLINE_FUNCTION_HD realx3 point(real t) const
Definition: pLine.hpp:51
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::sphTriInteraction::pLine::v_
realx3 v_
Definition: pLine.hpp:34
types.hpp
pFlow::sphTriInteraction::pLine
Definition: pLine.hpp:29
pFlow::sphTriInteraction::pLine::pLine
INLINE_FUNCTION_HD pLine(const realx3 &p1, const realx3 &p2)
Definition: pLine.hpp:41
pFlow::sphTriInteraction::pLine::lineSphereCheck
INLINE_FUNCTION_HD bool lineSphereCheck(const realx3 pos, real Rad, realx3 &nv, realx3 &cp, real &ovrlp) const
Definition: pLine.hpp:71
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::sphTriInteraction::pLine::projectPoint
INLINE_FUNCTION_HD realx3 projectPoint(const realx3 &p) const
Definition: pLine.hpp:57
pFlow::sphTriInteraction::pLine::p2_
realx3 p2_
Definition: pLine.hpp:33
pFlow::sphTriInteraction::pLine::p1_
realx3 p1_
Definition: pLine.hpp:32
pFlow::sphTriInteraction::pLine::projectNormLength
INLINE_FUNCTION_HD real projectNormLength(realx3 p) const
Definition: pLine.hpp:64
pFlow::sphTriInteraction::pLine::L_
real L_
Definition: pLine.hpp:35
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< real >
pFlow::sphTriInteraction::pLine::pLine
INLINE_FUNCTION_HD pLine()
Definition: pLine.hpp:38
pFlow::sphTriInteraction
Definition: pLine.hpp:26