sphereTriSurfaceContact.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 
22 #ifndef __sphereTriSurfaceContact_hpp__
23 #define __sphereTriSurfaceContact_hpp__
24 
25 #include "triWall.hpp"
26 #include "pLine.hpp"
27 
29 {
30 
33  const realx3& p1,
34  const realx3& p2,
35  const realx3& p3,
36  const realx3& p )
37 {
38 
39  realx3 p1p = p1 - p;
40  realx3 p2p = p2 - p;
41  realx3 p3p = p3 - p;
42 
43  real p1p2 = dot(p1p, p2p);
44  real p2p3 = dot(p2p, p3p);
45  real p2p2 = dot(p2p, p2p);
46  real p1p3 = dot(p1p, p3p);
47 
48  // first condition u.v < 0
49  // u.v = [(p1-p)x(p2-p)].[(p2-p)x(p3-p)] = (p1p.p2p)(p2p.p3p) - (p2p.p2p)(p1p.p3p)
50  if (p1p2*p2p3 - p2p2*p1p3 < 0.0) return false;
51 
52 
53  // second condition u.w < 0
54  // u.w = [(p1-p)x(p2-p)].[(p3-p)x(p1-p)] = (p1p.p3p)(p2p.p1p) - (p2p.p3p)(p1p.p1p)
55  real p1p1 = dot(p1p, p1p);
56  if (p1p3*p1p2 - p2p3*p1p1 < (0.0)) return false;
57 
58  return true;
59 }
60 
62 void cramerRule2(real A[2][2], real B[2], real & x1, real &x2)
63 {
64  real det = (A[0][0] * A[1][1] - A[1][0]*A[0][1]);
65  x1 = (B[0]*A[1][1] - B[1]*A[0][1]) / det;
66  x2 = (A[0][0] * B[1] - A[1][0] * B[0])/ det;
67 }
68 
71  const realx3& p1,
72  const realx3& p2,
73  const realx3& p3,
74  const realx3 &p,
75  int32 &Ln)
76 {
77  realx3 v0 = p2 - p1;
78  realx3 v1 = p3 - p1;
79  realx3 v2 = p - p1;
80 
81  real A[2][2] = { dot(v0, v0), dot(v0, v1), dot(v1, v0), dot(v1, v1) };
82  real B[2] = { dot(v0, v2), dot(v1, v2) };
83  real nu, w;
84 
85  cramerRule2(A, B, nu, w);
86  real nuW = nu + w;
87 
88 
89  if (nuW > 1)
90  {
91  Ln = 2; return true;
92  }
93  else if (nuW >= 0)
94  {
95  if (nu >= 0 && w >= 0)
96  {
97  Ln = 0; return true;
98  }
99  if (nu > 0 && w < 0)
100  {
101  Ln = 1; return true;
102  }
103  if (nu < 0 && w > 0)
104  {
105  Ln = 3; return true;
106  }
107  }
108  else
109  {
110  Ln = 1; return true;
111  }
112 
113  return false;
114 }
115 
118  const realx3& p1,
119  const realx3& p2,
120  const realx3& p3,
121  const realx3& cntr,
122  real rad,
123  real& ovrlp,
124  realx3& norm,
125  realx3& cp)
126 {
127 
128  triWall wall(true, p1,p2,p3);
129 
130  real dist = wall.normalDistFromWall(cntr);
131 
132  if(dist < 0.0 )return false;
133 
134  ovrlp = rad - dist;
135 
136  if (ovrlp > 0)
137  {
138  realx3 ptOnPlane = wall.nearestPointOnWall(cntr);
139 
140  if (pointInPlane(p1, p2, p3, ptOnPlane))
141  {
142  cp = ptOnPlane;
143  norm = -wall.n_;
144  return true;
145  }
146 
147  realx3 lnv;
148 
149  if (pLine(p1,p2).lineSphereCheck(cntr, rad, lnv, cp, ovrlp))
150  {
151  norm = -lnv;
152  return true;
153  }
154 
155  if ( pLine(p2,p3).lineSphereCheck(cntr, rad, lnv, cp, ovrlp))
156  {
157  norm = -lnv;
158  return true;
159  }
160 
161  if ( pLine(p3,p1).lineSphereCheck(cntr, rad, lnv, cp, ovrlp))
162  {
163  norm = -lnv;
164  return true;
165  }
166  }
167 
168  return false;
169 }
170 
173  const realx3x3& tri,
174  const realx3& cntr,
175  real Rad,
176  real& ovrlp,
177  realx3& norm,
178  realx3& cp)
179 {
180 
181  triWall wall(true, tri.x_,tri.y_,tri.z_);
182 
183  real dist = wall.normalDistFromWall(cntr);
184 
185 
186  ovrlp = Rad - abs(dist);
187 
188  if (ovrlp > 0)
189  {
190  realx3 ptOnPlane = wall.nearestPointOnWall(cntr);
191 
192  if (pointInPlane(tri.x_,tri.y_,tri.z_,ptOnPlane))
193  {
194  cp = ptOnPlane;
195 
196  if(dist >= 0.0)
197  norm = -wall.n_;
198  else
199  norm = wall.n_;
200  return true;
201  }
202 
203  realx3 lnv;
204 
205  if (pLine(tri.x_, tri.y_).lineSphereCheck(cntr, Rad, lnv, cp, ovrlp))
206  {
207  norm = -lnv;
208  return true;
209  }
210 
211  if ( pLine(tri.y_, tri.z_).lineSphereCheck(cntr, Rad, lnv, cp, ovrlp))
212  {
213  norm = -lnv;
214  return true;
215  }
216 
217  if ( pLine(tri.z_, tri.x_).lineSphereCheck(cntr, Rad, lnv, cp, ovrlp))
218  {
219  norm = -lnv;
220  return true;
221  }
222  }
223 
224  return false;
225 }
226 
227 
228 } // pFlow::sphTriInteraction
229 
230 
231 #endif //__sphereTriSurfaceContact_hpp__
pFlow::sphTriInteraction::isSphereInContactActiveSide
INLINE_FUNCTION_HD bool isSphereInContactActiveSide(const realx3 &p1, const realx3 &p2, const realx3 &p3, const realx3 &cntr, real rad, real &ovrlp, realx3 &norm, realx3 &cp)
Definition: sphereTriSurfaceContact.hpp:117
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::sphTriInteraction::pointInPlane
INLINE_FUNCTION_HD bool pointInPlane(const realx3 &p1, const realx3 &p2, const realx3 &p3, const realx3 &p)
Definition: sphereTriSurfaceContact.hpp:32
pFlow::sphTriInteraction::pLine
Definition: pLine.hpp:29
pFlow::sphTriInteraction::triWall
Definition: triWall.hpp:29
pFlow::sphTriInteraction::triWall::n_
realx3 n_
Definition: triWall.hpp:32
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)
triWall.hpp
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::abs
INLINE_FUNCTION_HD real abs(real x)
Definition: math.hpp:43
pFlow::triple::x_
T x_
Definition: triple.hpp:49
pFlow::sphTriInteraction::triWall::normalDistFromWall
INLINE_FUNCTION_HD real normalDistFromWall(const realx3 &p) const
Definition: triWall.hpp:75
pFlow::sphTriInteraction::cramerRule2
INLINE_FUNCTION_HD void cramerRule2(real A[2][2], real B[2], real &x1, real &x2)
Definition: sphereTriSurfaceContact.hpp:62
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::triple::z_
T z_
Definition: triple.hpp:51
pFlow::sphTriInteraction::isSphereInContactBothSides
INLINE_FUNCTION_HD bool isSphereInContactBothSides(const realx3x3 &tri, const realx3 &cntr, real Rad, real &ovrlp, realx3 &norm, realx3 &cp)
Definition: sphereTriSurfaceContact.hpp:172
pFlow::sphTriInteraction::triWall::nearestPointOnWall
INLINE_FUNCTION_HD realx3 nearestPointOnWall(const realx3 &p) const
Definition: triWall.hpp:81
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< real >
pLine.hpp
pFlow::sphTriInteraction
Definition: pLine.hpp:26