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