www.cemf.ir
grainInteraction.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 = grnParticles_.size();
36 
37  contactSearch_ = contactSearch::create(
38  subDict("contactSearch"),
39  grnParticles_.extendedDomain().domainBox(),
40  grnParticles_,
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  grnParticles_.diameter().deviceViewAll(),
64  grnParticles_.coarseGrainFactor().deviceViewAll(),
65  grnParticles_.propertyId().deviceViewAll(),
66  grnParticles_.pointPosition().deviceViewAll(),
67  grnParticles_.velocity().deviceViewAll(),
68  grnParticles_.rVelocity().deviceViewAll(),
69  grnParticles_.contactForce().deviceViewAll(),
70  grnParticles_.contactTorque().deviceViewAll()
71  );
72 
73  Kokkos::parallel_for(
74  "ppInteraction",
75  rpPPInteraction(0,lastItem),
76  ppInteraction
77  );
78 
79  Kokkos::fence();
80 
81  return true;
82 }
83 
84 
85 template<typename cFM,typename gMM,template <class, class, class> class cLT>
87 {
88 
89  uint32 lastItem = pwContactList_().loopCount();
90  uint32 iter = this->currentIter();
91  real t = this->currentTime();
92  real dt = this->dt();
93 
95  pwInteraction(
96  dt,
97  this->forceModel_(),
98  pwContactList_(),
99  geometryMotion_.getTriangleAccessor(),
100  geometryMotion_.getModel(iter, t, dt) ,
101  grnParticles_.diameter().deviceViewAll() ,
102  grnParticles_.coarseGrainFactor().deviceViewAll() ,
103  grnParticles_.propertyId().deviceViewAll(),
104  grnParticles_.pointPosition().deviceViewAll(),
105  grnParticles_.velocity().deviceViewAll(),
106  grnParticles_.rVelocity().deviceViewAll() ,
107  grnParticles_.contactForce().deviceViewAll(),
108  grnParticles_.contactTorque().deviceViewAll() ,
109  geometryMotion_.triMotionIndex().deviceViewAll(),
110  geometryMotion_.propertyId().deviceViewAll(),
111  geometryMotion_.contactForceWall().deviceViewAll()
112  );
113 
114  Kokkos::parallel_for(
115  "",
116  rpPWInteraction(0,lastItem),
117  pwInteraction
118  );
119 
120 
121  Kokkos::fence();
122 
123  return true;
124 }
125 
126 
127 template<typename cFM,typename gMM,template <class, class, class> class cLT>
129 (
130  systemControl& control,
131  const particles& prtcl,
132  const geometry& geom
133 )
134 :
135  interaction(control, prtcl, geom),
136  geometryMotion_(dynamic_cast<const GeometryMotionModel&>(geom)),
137  grnParticles_(dynamic_cast<const grainParticles&>(prtcl)),
138  boundaryInteraction_(grnParticles_,geometryMotion_),
139  ppInteractionTimer_("grain-graine interaction (internal)", &this->timers()),
140  pwInteractionTimer_("grain-wall interaction (internal)", &this->timers()),
141  boundaryInteractionTimer_("grain-grain interaction (boundary)",&this->timers()),
142  contactListMangementTimer_("list management (interal)", &this->timers()),
143  contactListMangementBoundaryTimer_("list management (boundary)", &this->timers())
144 {
145 
146  if(!createGrainInteraction())
147  {
148  fatalExit;
149  }
150 
151  for(uint32 i=0; i<6; i++)
152  {
153  activeBoundaries_[i] = boundaryInteraction_[i].ppPairsAllocated();
154  }
155 }
156 
157 template<typename cFM,typename gMM,template <class, class, class> class cLT>
159 {
160  return true;
161 }
162 
163 template<typename cFM,typename gMM,template <class, class, class> class cLT>
165 {
166 
167  timeInfo ti = this->TimeInfo();
168  auto iter = ti.iter();
169  auto t = ti.t();
170  auto dt = ti.dt();
171 
172  auto& contactSearchRef = contactSearch_();
173 
174  bool broadSearch = contactSearchRef.enterBroadSearch(ti);
175  bool broadSearchBoundary = contactSearchRef.enterBroadSearchBoundary(ti);
176 
178  grnParticles_.diameter().updateBoundaries(DataDirection::SlaveToMaster);
179  grnParticles_.velocity().updateBoundaries(DataDirection::SlaveToMaster);
180  grnParticles_.rVelocity().updateBoundaries(DataDirection::SlaveToMaster);
181  grnParticles_.propertyId().updateBoundaries(DataDirection::SlaveToMaster);
182 
184  if(broadSearch)
185  {
186  contactListMangementTimer_.start();
188  ppContactList_().beforeBroadSearch();
189  pwContactList_().beforeBroadSearch();
190  ComputationTimer().end();
191  contactListMangementTimer_.pause();
192  }
193 
194  if(broadSearchBoundary)
195  {
196  contactListMangementBoundaryTimer_.start();
198  for(uint32 i=0; i<6u; i++)
199  {
200  if(activeBoundaries_[i])
201  {
202  auto& BI = boundaryInteraction_[i];
203  BI.ppPairs().beforeBroadSearch();
204  BI.pwPairs().beforeBroadSearch();
205  }
206  }
207  ComputationTimer().end();
208  contactListMangementBoundaryTimer_.pause();
209  }
210 
211  if( grnParticles_.numActive()<=0)return true;
212 
214  if( !contactSearchRef.broadSearch(
215  ti,
216  ppContactList_(),
217  pwContactList_()) )
218  {
220  "unable to perform broadSearch.\n";
221  fatalExit;
222  }
223 
224  for(uint32 i=0; i<6u; i++)
225  {
226  if(activeBoundaries_[i])
227  {
228  auto& BI = boundaryInteraction_[i];
229  if(!contactSearchRef.boundaryBroadSearch(
230  i,
231  ti,
232  BI.ppPairs(),
233  BI.pwPairs())
234  )
235  {
237  "failed to perform broadSearch for boundary index "<<i<<endl;
238  return false;
239  }
240  }
241  }
242  ComputationTimer().end();
243 
244  if(broadSearch && contactSearchRef.performedSearch())
245  {
246  contactListMangementTimer_.resume();
248  ppContactList_().afterBroadSearch();
249  pwContactList_().afterBroadSearch();
250  ComputationTimer().end();
251  contactListMangementTimer_.end();
252  }
253 
254  if(broadSearchBoundary && contactSearchRef.performedSearchBoundary())
255  {
256  contactListMangementBoundaryTimer_.resume();
258  for(uint32 i=0; i<6u; i++)
259  {
260  if(activeBoundaries_[i])
261  {
262  auto& BI = boundaryInteraction_[i];
263  BI.ppPairs().afterBroadSearch();
264  BI.pwPairs().afterBroadSearch();
265  }
266  }
267  ComputationTimer().end();
268  contactListMangementBoundaryTimer_.end();
269  }
270 
272  auto requireStep = boundariesMask<6>(true);
273  const auto& cfModel = this->forceModel_();
274  uint32 step=1;
275  boundaryInteractionTimer_.start();
277  while(requireStep.anyElement(true) && step <= 10)
278  {
279  for(uint32 i=0; i<6u; i++)
280  {
281  if(requireStep[i] )
282  {
283  requireStep[i] = boundaryInteraction_[i].grainGrainInteraction(
284  dt,
285  this->forceModel_(),
286  step
287  );
288  }
289  }
290  step++;
291  }
292  ComputationTimer().end();
293  boundaryInteractionTimer_.pause();
294 
295 
296  ppInteractionTimer_.start();
299  ComputationTimer().end();
300  ppInteractionTimer_.end();
301 
302 
303  pwInteractionTimer_.start();
305  grainWallInteraction();
307  pwInteractionTimer_.end();
308 
309  {
310  boundaryInteractionTimer_.resume();
312  auto requireStep = boundariesMask<6>(true);
313 
314  uint32 step = 11;
315  const auto& cfModel = this->forceModel_();
316  while( requireStep.anyElement(true) && step < 20 )
317  {
318  for(uint32 i=0; i<6u; i++)
319  {
320  if(requireStep[i])
321  {
322  requireStep[i] = boundaryInteraction_[i].grainGrainInteraction(
323  dt,
324  cfModel,
325  step
326  );
327  }
328  }
329  step++;
330  }
331  ComputationTimer().end();
332  boundaryInteractionTimer_.end();
333  }
334 
335  return true;
336 }
337 
338 template<typename cFM,typename gMM,template <class, class, class> class cLT>
340 {
341  return true;
342 }
343 
344 template<typename cFM,typename gMM,template <class, class, class> class cLT>
346 (
347  real t,
348  real dt,
349  uint32 iter,
350  const message& msg,
351  const anyList& varList
352 )
353 {
354  if(msg.equivalentTo(message::ITEM_REARRANGE))
355  {
357  }
358  return true;
359 }
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::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::grainInteraction::grainGrainInteraction
bool grainGrainInteraction()
Definition: grainInteraction.cpp:53
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::grainInteraction::rpPWInteraction
rpPPInteraction rpPWInteraction
range policy for p-w interaction execution
Definition: grainInteraction.hpp:122
pFlow::Timer::start
void start()
Definition: Timer.hpp:105
pFlow::grainInteraction::beforeIteration
bool beforeIteration() override
This is called in time loop, before iterate. (overriden from demComponent)
Definition: grainInteraction.cpp:158
pFlow::grainInteraction::afterIteration
bool afterIteration() override
This is called in time loop, after iterate. (overriden from demComponent)
Definition: grainInteraction.cpp:339
pFlow::grainInteraction::GeometryMotionModel
geometryMotionModel GeometryMotionModel
Definition: grainInteraction.hpp:47
pFlow::grainParticles
Definition: grainParticles.hpp:42
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::periodicBoundarySIKernels::grainGrainInteraction
void grainGrainInteraction(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< real > &coarseGrainFactor, 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::systemControl
Definition: systemControl.hpp:41
pFlow::grainInteraction::createGrainInteraction
bool createGrainInteraction()
Definition: grainInteraction.cpp:22
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::grainInteraction::grainInteraction
grainInteraction(systemControl &control, const particles &prtcl, const geometry &geom)
Constructor from components.
Definition: grainInteraction.cpp:129
pFlow::VectorSingle::deviceView
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
Definition: VectorSingle.cpp:263
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::grainInteraction::iterate
bool iterate() override
This is called in time loop.
Definition: grainInteraction.cpp:164
pFlow::timeInfo::dt
const real & dt() const
Definition: timeInfo.hpp:51
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::boundariesMask< 6 >
pFlow::grainInteractionKernels::pwInteractionFunctor
Definition: grainInteractionKernels.hpp:177
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::grainInteraction::grainWallInteraction
bool grainWallInteraction()
Definition: grainInteraction.cpp:86
pFlow::interaction
Definition: interaction.hpp:38
pFlow::grainInteraction::rpPPInteraction
Kokkos::RangePolicy< Kokkos::IndexType< uint32 >, Kokkos::Schedule< Kokkos::Dynamic > > rpPPInteraction
range policy for p-p interaction execution
Definition: grainInteraction.hpp:119
pFlow::grainInteractionKernels::ppInteractionFunctor
Definition: grainInteractionKernels.hpp:33
pFlow::ComputationTimer
MPITimer & ComputationTimer()
Definition: MPITimer.cpp:85
pFlow::grainInteraction::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: grainInteraction.cpp:346