www.cemf.ir
sphereInteraction.cpp
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 cFM,typename gMM,template <class, class, class> class cLT>
23 {
24 
25  realVector_D rhoD("densities", this->densities());
26 
27  auto modelDict = this->subDict("model");
28 
29  forceModel_ = makeUnique<ContactForceModel>(
30  this->numMaterials(),
31  rhoD.deviceView(),
32  modelDict );
33 
34 
35  uint32 nPrtcl = sphParticles_.size();
36 
37  contactSearch_ = contactSearch::create(
38  subDict("contactSearch"),
39  sphParticles_.extendedDomain().domainBox(),
40  sphParticles_,
41  geometryMotion_,
42  timers());
43 
44  ppContactList_ = makeUnique<ContactListType>(nPrtcl+1);
45 
46  pwContactList_ = makeUnique<ContactListType>(nPrtcl/5+1);
47 
48  return true;
49 }
50 
51 
52 template<typename cFM,typename gMM,template <class, class, class> class cLT>
54 {
55  auto lastItem = ppContactList_().loopCount();
56 
57  // create the kernel functor
59  ppInteraction(
60  this->dt(),
61  this->forceModel_(),
62  ppContactList_(), // to be read
63  sphParticles_.diameter().deviceViewAll(),
64  sphParticles_.propertyId().deviceViewAll(),
65  sphParticles_.pointPosition().deviceViewAll(),
66  sphParticles_.velocity().deviceViewAll(),
67  sphParticles_.rVelocity().deviceViewAll(),
68  sphParticles_.contactForce().deviceViewAll(),
69  sphParticles_.contactTorque().deviceViewAll()
70  );
71 
72  Kokkos::parallel_for(
73  "ppInteraction",
74  rpPPInteraction(0,lastItem),
75  ppInteraction
76  );
77 
78  Kokkos::fence();
79 
80  return true;
81 }
82 
83 
84 template<typename cFM,typename gMM,template <class, class, class> class cLT>
86 {
87 
88  uint32 lastItem = pwContactList_().loopCount();
89  uint32 iter = this->currentIter();
90  real t = this->currentTime();
91  real dt = this->dt();
92 
94  pwInteraction(
95  dt,
96  this->forceModel_(),
97  pwContactList_(),
98  geometryMotion_.getTriangleAccessor(),
99  geometryMotion_.getModel(iter, t, dt) ,
100  sphParticles_.diameter().deviceViewAll() ,
101  sphParticles_.propertyId().deviceViewAll(),
102  sphParticles_.pointPosition().deviceViewAll(),
103  sphParticles_.velocity().deviceViewAll(),
104  sphParticles_.rVelocity().deviceViewAll() ,
105  sphParticles_.contactForce().deviceViewAll(),
106  sphParticles_.contactTorque().deviceViewAll() ,
107  geometryMotion_.triMotionIndex().deviceViewAll(),
108  geometryMotion_.propertyId().deviceViewAll(),
109  geometryMotion_.contactForceWall().deviceViewAll()
110  );
111 
112  Kokkos::parallel_for(
113  "",
114  rpPWInteraction(0,lastItem),
115  pwInteraction
116  );
117 
118 
119  Kokkos::fence();
120 
121  return true;
122 }
123 
124 
125 template<typename cFM,typename gMM,template <class, class, class> class cLT>
127 (
128  systemControl& control,
129  const particles& prtcl,
130  const geometry& geom
131 )
132 :
133  interaction(control, prtcl, geom),
134  geometryMotion_(dynamic_cast<const GeometryMotionModel&>(geom)),
135  sphParticles_(dynamic_cast<const sphereParticles&>(prtcl)),
136  boundaryInteraction_(sphParticles_,geometryMotion_),
137  ppInteractionTimer_("sphere-sphere interaction (internal)", &this->timers()),
138  pwInteractionTimer_("sphere-wall interaction (internal)", &this->timers()),
139  boundaryInteractionTimer_("sphere-sphere interaction (boundary)",&this->timers()),
140  contactListMangementTimer_("list management (interal)", &this->timers()),
141  contactListMangementBoundaryTimer_("list management (boundary)", &this->timers())
142 {
143 
144  if(!createSphereInteraction())
145  {
146  fatalExit;
147  }
148 
149  for(uint32 i=0; i<6; i++)
150  {
151  activeBoundaries_[i] = boundaryInteraction_[i].ppPairsAllocated();
152  }
153 }
154 
155 template<typename cFM,typename gMM,template <class, class, class> class cLT>
157 {
158  return true;
159 }
160 
161 template<typename cFM,typename gMM,template <class, class, class> class cLT>
163 {
164 
165  timeInfo ti = this->TimeInfo();
166  auto iter = ti.iter();
167  auto t = ti.t();
168  auto dt = ti.dt();
169 
170  auto& contactSearchRef = contactSearch_();
171 
172  bool broadSearch = contactSearchRef.enterBroadSearch(ti);
173  bool broadSearchBoundary = contactSearchRef.enterBroadSearchBoundary(ti);
174 
176  sphParticles_.diameter().updateBoundaries(DataDirection::SlaveToMaster);
177  sphParticles_.velocity().updateBoundaries(DataDirection::SlaveToMaster);
178  sphParticles_.rVelocity().updateBoundaries(DataDirection::SlaveToMaster);
179  sphParticles_.propertyId().updateBoundaries(DataDirection::SlaveToMaster);
180 
182  if(broadSearch)
183  {
184  contactListMangementTimer_.start();
186  ppContactList_().beforeBroadSearch();
187  pwContactList_().beforeBroadSearch();
188  ComputationTimer().end();
189  contactListMangementTimer_.pause();
190  }
191 
192  if(broadSearchBoundary)
193  {
194  contactListMangementBoundaryTimer_.start();
196  for(uint32 i=0; i<6u; i++)
197  {
198  if(activeBoundaries_[i])
199  {
200  auto& BI = boundaryInteraction_[i];
201  BI.ppPairs().beforeBroadSearch();
202  BI.pwPairs().beforeBroadSearch();
203  }
204  }
205  ComputationTimer().end();
206  contactListMangementBoundaryTimer_.pause();
207  }
208 
209  if( sphParticles_.numActive()<=0)return true;
210 
212  if( !contactSearchRef.broadSearch(
213  ti,
214  ppContactList_(),
215  pwContactList_()) )
216  {
218  "unable to perform broadSearch.\n";
219  fatalExit;
220  }
221 
222  for(uint32 i=0; i<6u; i++)
223  {
224  if(activeBoundaries_[i])
225  {
226  auto& BI = boundaryInteraction_[i];
227  if(!contactSearchRef.boundaryBroadSearch(
228  i,
229  ti,
230  BI.ppPairs(),
231  BI.pwPairs())
232  )
233  {
235  "failed to perform broadSearch for boundary index "<<i<<endl;
236  return false;
237  }
238  }
239  }
240  ComputationTimer().end();
241 
242  if(broadSearch && contactSearchRef.performedSearch())
243  {
244  contactListMangementTimer_.resume();
246  ppContactList_().afterBroadSearch();
247  pwContactList_().afterBroadSearch();
248  ComputationTimer().end();
249  contactListMangementTimer_.end();
250  }
251 
252  if(broadSearchBoundary && contactSearchRef.performedSearchBoundary())
253  {
254  contactListMangementBoundaryTimer_.resume();
256  for(uint32 i=0; i<6u; i++)
257  {
258  if(activeBoundaries_[i])
259  {
260  auto& BI = boundaryInteraction_[i];
261  BI.ppPairs().afterBroadSearch();
262  BI.pwPairs().afterBroadSearch();
263  }
264  }
265  ComputationTimer().end();
266  contactListMangementBoundaryTimer_.end();
267  }
268 
270  auto requireStep = boundariesMask<6>(true);
271  const auto& cfModel = this->forceModel_();
272  uint32 step=1;
273  boundaryInteractionTimer_.start();
275  while(requireStep.anyElement(true) && step <= 10)
276  {
277  for(uint32 i=0; i<6u; i++)
278  {
279  if(requireStep[i] )
280  {
281  requireStep[i] = boundaryInteraction_[i].sphereSphereInteraction(
282  dt,
283  this->forceModel_(),
284  step
285  );
286  }
287  }
288  step++;
289  }
290  ComputationTimer().end();
291  boundaryInteractionTimer_.pause();
292 
293 
294  ppInteractionTimer_.start();
297  ComputationTimer().end();
298  ppInteractionTimer_.end();
299 
300 
301  pwInteractionTimer_.start();
303  sphereWallInteraction();
305  pwInteractionTimer_.end();
306 
307  {
308  boundaryInteractionTimer_.resume();
310  auto requireStep = boundariesMask<6>(true);
311 
312  uint32 step = 11;
313  const auto& cfModel = this->forceModel_();
314  while( requireStep.anyElement(true) && step < 20 )
315  {
316  for(uint32 i=0; i<6u; i++)
317  {
318  if(requireStep[i])
319  {
320  requireStep[i] = boundaryInteraction_[i].sphereSphereInteraction(
321  dt,
322  cfModel,
323  step
324  );
325  }
326  }
327  step++;
328  }
329  ComputationTimer().end();
330  boundaryInteractionTimer_.end();
331  }
332 
333  return true;
334 }
335 
336 template<typename cFM,typename gMM,template <class, class, class> class cLT>
338 {
339  return true;
340 }
341 
342 template<typename cFM,typename gMM,template <class, class, class> class cLT>
344 (
345  real t,
346  real dt,
347  uint32 iter,
348  const message& msg,
349  const anyList& varList
350 )
351 {
352  if(msg.equivalentTo(message::ITEM_REARRANGE))
353  {
355  }
356  return true;
357 }
pFlow::sphereInteraction::sphereWallInteraction
bool sphereWallInteraction()
Definition: sphereInteraction.cpp:85
pFlow::sphereInteractionKernels::ppInteractionFunctor
Definition: sphereInteractionKernels.hpp:33
pFlow::message::equivalentTo
bool equivalentTo(EVENT evnt) const
Definition: message.hpp:131
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::sphereInteraction::beforeIteration
bool beforeIteration() override
This is called in time loop, before iterate. (overriden from demComponent)
Definition: sphereInteraction.cpp:156
pFlow::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::sphereInteraction::afterIteration
bool afterIteration() override
This is called in time loop, after iterate. (overriden from demComponent)
Definition: sphereInteraction.cpp:337
pFlow::Timer::start
void start()
Definition: Timer.hpp:105
pFlow::sphereInteraction::createSphereInteraction
bool createSphereInteraction()
Definition: sphereInteraction.cpp:22
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::sphereInteraction::GeometryMotionModel
geometryMotionModel GeometryMotionModel
Definition: sphereInteraction.hpp:47
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::sphereInteraction::rpPWInteraction
rpPPInteraction rpPWInteraction
range policy for p-w interaction execution
Definition: sphereInteraction.hpp:122
pFlow::sphereInteraction::sphereInteraction
sphereInteraction(systemControl &control, const particles &prtcl, const geometry &geom)
Constructor from components.
Definition: sphereInteraction.cpp:127
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::sphereInteractionKernels::pwInteractionFunctor
Definition: sphereInteractionKernels.hpp:170
pFlow::periodicBoundarySIKernels::sphereSphereInteraction
void sphereSphereInteraction(real dt, const ContactListType &cntctList, const ContactForceModel &forceModel, const realx3 &transferVec, const deviceScatteredFieldAccess< realx3 > &thisPoints, const deviceScatteredFieldAccess< realx3 > &mirrorPoints, const deviceViewType1D< real > &diam, const deviceViewType1D< uint32 > &propId, const deviceViewType1D< realx3 > &vel, const deviceViewType1D< realx3 > &rVel, const deviceViewType1D< realx3 > &cForce, const deviceViewType1D< realx3 > &cTorque)
Definition: periodicBoundarySIKernels.hpp:8
pFlow::VectorSingle::deviceView
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
Definition: VectorSingle.cpp:263
pFlow::sphereParticles
Class for managing spherical particles.
Definition: sphereParticles.hpp:42
pFlow::Timer::end
void end()
Definition: Timer.hpp:129
pFlow::anyList
Definition: anyList.hpp:35
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::timeInfo::dt
const real & dt() const
Definition: timeInfo.hpp:51
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::boundariesMask< 6 >
pFlow::sphereInteraction::rpPPInteraction
Kokkos::RangePolicy< Kokkos::IndexType< uint32 >, Kokkos::Schedule< Kokkos::Dynamic > > rpPPInteraction
range policy for p-p interaction execution
Definition: sphereInteraction.hpp:119
pFlow::timeInfo::t
const real & t() const
Definition: timeInfo.hpp:47
pFlow::timeInfo::iter
const uint32 & iter() const
Definition: timeInfo.hpp:55
pFlow::geometry
Base class for geometry for managing tri-surfaces, geometry motion, and surface physical properties.
Definition: geometry.hpp:44
pFlow::sphereInteraction::iterate
bool iterate() override
This is called in time loop.
Definition: sphereInteraction.cpp:162
pFlow::sphereInteraction::hearChanges
bool hearChanges(real t, real dt, uint32 iter, const message &msg, const anyList &varList) override
Check for changes in the point structures. (overriden from observer)
Definition: sphereInteraction.cpp:344
pFlow::interaction
Definition: interaction.hpp:38
pFlow::ComputationTimer
MPITimer & ComputationTimer()
Definition: MPITimer.cpp:85
pFlow::sphereInteraction::sphereSphereInteraction
bool sphereSphereInteraction()
Definition: sphereInteraction.cpp:53