www.cemf.ir
sphereInteractionKernels.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 __sphereInteractionKernels_hpp__
22 #define __sphereInteractionKernels_hpp__
23 
24 
26 
28 {
29 
30 template<
31  typename ContactForceModel,
32  typename ContactListType>
34 {
35 
36  using PairType = typename ContactListType::PairType;
37  using ValueType = typename ContactListType::ValueType;
38 
40 
41  ContactForceModel forceModel_;
42  ContactListType tobeFilled_;
43 
51 
52 
54  real dt,
55  ContactForceModel forceModel,
56  ContactListType tobeFilled,
63  deviceViewType1D<realx3> cTorque )
64  :
65  dt_(dt),
66  forceModel_(forceModel),
67  tobeFilled_(tobeFilled),
68  diam_(diam),
69  propId_(propId),
70  pos_(pos),
71  lVel_(lVel),
72  rVel_(rVel),
73  cForce_(cForce), // this is converted to an atomic vector
74  cTorque_(cTorque) // this is converted to an atomic vector
75  {}
76 
78  void operator()(const uint32 n)const
79  {
80 
81  if(!tobeFilled_.isValid(n))return;
82 
83  auto [i,j] = tobeFilled_.getPair(n);
84 
85  real Ri = 0.5*diam_[i];
86  real Rj = 0.5*diam_[j];
87  realx3 xi = pos_[i];
88  realx3 xj = pos_[j];
89  real dist = length(xj-xi);
90  real ovrlp = (Ri+Rj) - dist;
91 
92  if( ovrlp >0.0 )
93  {
94 
95  auto Vi = lVel_[i];
96  auto Vj = lVel_[j];
97  auto wi = rVel_[i];
98  auto wj = rVel_[j];
99  auto Nij = (xj-xi)/dist;
100  auto Vr = Vi - Vj + cross((Ri*wi+Rj*wj), Nij);
101 
102  auto history = tobeFilled_.getValue(n);
103 
104  int32 propId_i = propId_[i];
105  int32 propId_j = propId_[j];
106 
107  realx3 FCn, FCt, Mri, Mrj, Mij, Mji;
108 
109  // calculates contact force
110  forceModel_.contactForce(
111  dt_, i, j,
112  propId_i, propId_j,
113  Ri, Rj,
114  ovrlp,
115  Vr, Nij,
116  history,
117  FCn, FCt
118  );
119 
120  forceModel_.rollingFriction(
121  dt_, i, j,
122  propId_i, propId_j,
123  Ri, Rj,
124  wi, wj,
125  Nij,
126  FCn,
127  Mri, Mrj
128  );
129 
130  auto M = cross(Nij,FCt);
131  Mij = Ri*M+Mri;
132  Mji = Rj*M+Mrj;
133 
134  auto FC = FCn + FCt;
135 
136  Kokkos::atomic_add(&cForce_[i].x_,FC.x_);
137  Kokkos::atomic_add(&cForce_[i].y_,FC.y_);
138  Kokkos::atomic_add(&cForce_[i].z_,FC.z_);
139 
140  Kokkos::atomic_add(&cForce_[j].x_,-FC.x_);
141  Kokkos::atomic_add(&cForce_[j].y_,-FC.y_);
142  Kokkos::atomic_add(&cForce_[j].z_,-FC.z_);
143 
144  Kokkos::atomic_add(&cTorque_[i].x_, Mij.x_);
145  Kokkos::atomic_add(&cTorque_[i].y_, Mij.y_);
146  Kokkos::atomic_add(&cTorque_[i].z_, Mij.z_);
147 
148  Kokkos::atomic_add(&cTorque_[j].x_, Mji.x_);
149  Kokkos::atomic_add(&cTorque_[j].y_, Mji.y_);
150  Kokkos::atomic_add(&cTorque_[j].z_, Mji.z_);
151 
152 
153  tobeFilled_.setValue(n,history);
154 
155  }
156  else
157  {
158  tobeFilled_.setValue(n, ValueType());
159  }
160 
161  }
162 };
163 
164 
165 template<
166  typename ContactForceModel,
167  typename ContactListType,
168  typename TraingleAccessor,
169  typename MotionModel>
171 {
172  using PairType = typename ContactListType::PairType;
173  using ValueType = typename ContactListType::ValueType;
174 
176 
177  ContactForceModel forceModel_;
178  ContactListType tobeFilled_;
179 
180  TraingleAccessor triangles_;
182 
193 
194 
196  real dt,
197  ContactForceModel forceModel,
198  ContactListType tobeFilled,
199  TraingleAccessor triangles,
200  MotionModel motionModel ,
207  deviceViewType1D<realx3> cTorque ,
208  deviceViewType1D<uint32> wTriMotionIndex,
209  deviceViewType1D<uint32> wPropId,
210  deviceViewType1D<realx3> wCForce)
211  :
212  dt_(dt),
213  forceModel_(forceModel),
214  tobeFilled_(tobeFilled),
215  triangles_(triangles) ,
216  motionModel_(motionModel) ,
217  diam_(diam) ,
218  propId_(propId),
219  pos_(pos) ,
220  lVel_(lVel),
221  rVel_(rVel) ,
222  cForce_(cForce),
223  cTorque_(cTorque) ,
224  wTriMotionIndex_(wTriMotionIndex) ,
225  wPropId_(wPropId),
226  wCForce_(wCForce)
227  {}
228 
230  void operator()(const int32 n)const
231  {
232 
233  if(!tobeFilled_.isValid(n))return;
234 
235  auto [i,tj] = tobeFilled_.getPair(n);
236 
237  real Ri = 0.5*diam_[i];
238  real Rj = 10000.0;
239  realx3 xi = pos_[i];
240 
241  realx3x3 tri = triangles_(tj);
242  real ovrlp;
243  realx3 Nij, cp;
244 
246  tri, xi, Ri, ovrlp, Nij, cp) )
247  {
248  auto Vi = lVel_[i];
249  auto wi = rVel_[i];
250 
251  int32 mInd = wTriMotionIndex_[tj];
252 
253  auto Vw = motionModel_(mInd, cp);
254 
255  //output<< "par-wall index "<< i<<" - "<< tj<<endl;
256 
257  auto Vr = Vi - Vw + cross(Ri*wi, Nij);
258 
259  auto history = tobeFilled_.getValue(n);
260 
261  int32 propId_i = propId_[i];
262  int32 wPropId_j = wPropId_[tj];
263 
264  realx3 FCn, FCt, Mri, Mrj, Mij;
265  //output<< "before "<<history.overlap_t_<<endl;
266  // calculates contact force
267  forceModel_.contactForce(
268  dt_, i, tj,
269  propId_i, wPropId_j,
270  Ri, Rj,
271  ovrlp,
272  Vr, Nij,
273  history,
274  FCn, FCt
275  );
276 
277  //output<< "after "<<history.overlap_t_<<endl;
278 
279  forceModel_.rollingFriction(
280  dt_, i, tj,
281  propId_i, wPropId_j,
282  Ri, Rj,
283  wi, 0.0,
284  Nij,
285  FCn,
286  Mri, Mrj
287  );
288 
289  auto M = cross(Nij,FCt);
290  Mij = Ri*M+Mri;
291  //output<< "FCt = "<<FCt <<endl;
292  //output<< "FCn = "<<FCn <<endl;
293  //output<<"propId i, tj"<< propId_i << " "<<wPropId_j<<endl;
294  //output<<"par i , wj"<< i<<" "<< tj<<endl;
295 
296  auto FC = FCn + FCt;
297 
298  Kokkos::atomic_add(&cForce_[i].x_,FC.x_);
299  Kokkos::atomic_add(&cForce_[i].y_,FC.y_);
300  Kokkos::atomic_add(&cForce_[i].z_,FC.z_);
301 
302  Kokkos::atomic_add(&wCForce_[tj].x_,-FC.x_);
303  Kokkos::atomic_add(&wCForce_[tj].y_,-FC.y_);
304  Kokkos::atomic_add(&wCForce_[tj].z_,-FC.z_);
305 
306 
307  Kokkos::atomic_add(&cTorque_[i].x_, Mij.x_);
308  Kokkos::atomic_add(&cTorque_[i].y_, Mij.y_);
309  Kokkos::atomic_add(&cTorque_[i].z_, Mij.z_);
310 
311  tobeFilled_.setValue(n,history);
312 
313  }
314  else
315  {
316  tobeFilled_.setValue(n,ValueType());
317  }
318 
319  }
320 
321 };
322 
323 }
324 
325 #endif //__sphereInteractionKernels_hpp__
pFlow::sphereInteractionKernels::ppInteractionFunctor
Definition: sphereInteractionKernels.hpp:33
pFlow::sphereInteractionKernels::ppInteractionFunctor::lVel_
deviceViewType1D< realx3 > lVel_
Definition: sphereInteractionKernels.hpp:47
pFlow::sphereInteractionKernels::ppInteractionFunctor::ValueType
typename ContactListType::ValueType ValueType
Definition: sphereInteractionKernels.hpp:37
pFlow::sphereInteractionKernels::ppInteractionFunctor::dt_
real dt_
Definition: sphereInteractionKernels.hpp:39
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::sphereInteractionKernels::ppInteractionFunctor::diam_
deviceViewType1D< real > diam_
Definition: sphereInteractionKernels.hpp:44
pFlow::sphereInteractionKernels::pwInteractionFunctor::pwInteractionFunctor
pwInteractionFunctor(real dt, ContactForceModel forceModel, ContactListType tobeFilled, TraingleAccessor triangles, MotionModel motionModel, deviceViewType1D< real > diam, deviceViewType1D< uint32 > propId, deviceViewType1D< realx3 > pos, deviceViewType1D< realx3 > lVel, deviceViewType1D< realx3 > rVel, deviceViewType1D< realx3 > cForce, deviceViewType1D< realx3 > cTorque, deviceViewType1D< uint32 > wTriMotionIndex, deviceViewType1D< uint32 > wPropId, deviceViewType1D< realx3 > wCForce)
Definition: sphereInteractionKernels.hpp:195
pFlow::sphereInteractionKernels::ppInteractionFunctor::operator()
INLINE_FUNCTION_HD void operator()(const uint32 n) const
Definition: sphereInteractionKernels.hpp:78
pFlow::sphereInteractionKernels::pwInteractionFunctor::wCForce_
deviceViewType1D< realx3 > wCForce_
Definition: sphereInteractionKernels.hpp:192
pFlow::sphereInteractionKernels::ppInteractionFunctor::PairType
typename ContactListType::PairType PairType
Definition: sphereInteractionKernels.hpp:36
pFlow::sphereInteractionKernels::pwInteractionFunctor::forceModel_
ContactForceModel forceModel_
Definition: sphereInteractionKernels.hpp:177
pFlow::sphereInteractionKernels::pwInteractionFunctor::cTorque_
deviceViewType1D< realx3 > cTorque_
Definition: sphereInteractionKernels.hpp:189
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::sphereInteractionKernels::ppInteractionFunctor::ppInteractionFunctor
ppInteractionFunctor(real dt, ContactForceModel forceModel, ContactListType tobeFilled, deviceViewType1D< real > diam, deviceViewType1D< uint32 > propId, deviceViewType1D< realx3 > pos, deviceViewType1D< realx3 > lVel, deviceViewType1D< realx3 > rVel, deviceViewType1D< realx3 > cForce, deviceViewType1D< realx3 > cTorque)
Definition: sphereInteractionKernels.hpp:53
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::sphereInteractionKernels::pwInteractionFunctor
Definition: sphereInteractionKernels.hpp:170
sphereTriSurfaceContact.hpp
pFlow::sphereInteractionKernels::pwInteractionFunctor::ValueType
typename ContactListType::ValueType ValueType
Definition: sphereInteractionKernels.hpp:173
pFlow::sphereInteractionKernels::pwInteractionFunctor::rVel_
deviceViewType1D< realx3 > rVel_
Definition: sphereInteractionKernels.hpp:187
pFlow::sphereInteractionKernels
Definition: sphereInteractionKernels.hpp:27
pFlow::sphereInteractionKernels::ppInteractionFunctor::cTorque_
deviceViewType1D< realx3 > cTorque_
Definition: sphereInteractionKernels.hpp:50
cross
INLINE_FUNCTION_HD triple< T > cross(const triple< T > &v1, const triple< T > &v2)
pFlow::sphereInteractionKernels::pwInteractionFunctor::wPropId_
deviceViewType1D< uint32 > wPropId_
Definition: sphereInteractionKernels.hpp:191
pFlow::sphereInteractionKernels::pwInteractionFunctor::triangles_
TraingleAccessor triangles_
Definition: sphereInteractionKernels.hpp:180
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::sphereInteractionKernels::pwInteractionFunctor::pos_
deviceViewType1D< realx3 > pos_
Definition: sphereInteractionKernels.hpp:185
pFlow::sphereInteractionKernels::pwInteractionFunctor::lVel_
deviceViewType1D< realx3 > lVel_
Definition: sphereInteractionKernels.hpp:186
pFlow::sphereInteractionKernels::pwInteractionFunctor::diam_
deviceViewType1D< real > diam_
Definition: sphereInteractionKernels.hpp:183
pFlow::sphereInteractionKernels::pwInteractionFunctor::tobeFilled_
ContactListType tobeFilled_
Definition: sphereInteractionKernels.hpp:178
pFlow::triple::x_
T x_
data members
Definition: triple.hpp:49
pFlow::sphereInteractionKernels::pwInteractionFunctor::wTriMotionIndex_
deviceViewType1D< uint32 > wTriMotionIndex_
Definition: sphereInteractionKernels.hpp:190
pFlow::sphereInteractionKernels::ppInteractionFunctor::propId_
deviceViewType1D< uint32 > propId_
Definition: sphereInteractionKernels.hpp:45
pFlow::sphereInteractionKernels::pwInteractionFunctor::cForce_
deviceViewType1D< realx3 > cForce_
Definition: sphereInteractionKernels.hpp:188
pFlow::sphereInteractionKernels::ppInteractionFunctor::forceModel_
ContactForceModel forceModel_
Definition: sphereInteractionKernels.hpp:41
pFlow::sphereInteractionKernels::pwInteractionFunctor::propId_
deviceViewType1D< uint32 > propId_
Definition: sphereInteractionKernels.hpp:184
pFlow::triple::y_
T y_
Definition: triple.hpp:50
pFlow::sphereInteractionKernels::pwInteractionFunctor::motionModel_
MotionModel motionModel_
Definition: sphereInteractionKernels.hpp:181
pFlow::triple::z_
T z_
Definition: triple.hpp:51
n
uint32 n
Definition: NBSLoop.hpp:24
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::MotionModel
Motion model abstract class (CRTP) for all the motion models.
Definition: MotionModel.hpp:39
pFlow::sphereInteractionKernels::ppInteractionFunctor::pos_
deviceViewType1D< realx3 > pos_
Definition: sphereInteractionKernels.hpp:46
pFlow::sphereInteractionKernels::pwInteractionFunctor::PairType
typename ContactListType::PairType PairType
Definition: sphereInteractionKernels.hpp:172
pFlow::sphereInteractionKernels::pwInteractionFunctor::dt_
real dt_
Definition: sphereInteractionKernels.hpp:175
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple< real >
pFlow::sphereInteractionKernels::ppInteractionFunctor::cForce_
deviceViewType1D< realx3 > cForce_
Definition: sphereInteractionKernels.hpp:49
pFlow::sphereInteractionKernels::ppInteractionFunctor::rVel_
deviceViewType1D< realx3 > rVel_
Definition: sphereInteractionKernels.hpp:48
pFlow::sphereInteractionKernels::pwInteractionFunctor::operator()
INLINE_FUNCTION_HD void operator()(const int32 n) const
Definition: sphereInteractionKernels.hpp:230
pFlow::sphereInteractionKernels::ppInteractionFunctor::tobeFilled_
ContactListType tobeFilled_
Definition: sphereInteractionKernels.hpp:42