www.cemf.ir
grainParticles.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 #include "grainParticles.hpp"
22 #include "systemControl.hpp"
23 #include "vocabs.hpp"
25 
27 {
28 
29  using exeSpace = typename realPointField_D::execution_space;
30  using policy = Kokkos::RangePolicy<
31  exeSpace,
32  Kokkos::IndexType<uint32>>;
33 
34  auto [minIndex, maxIndex] = minMax(shapeIndex().internal());
35 
36  if( !grains_.indexValid(maxIndex) )
37  {
39  "the maximum value of shapeIndex is "<< maxIndex <<
40  " which is not valid."<<endl;
41  return false;
42  }
43 
44  auto aPointsMask = dynPointStruct().activePointsMaskDevice();
45  auto aRange = aPointsMask.activeRange();
46 
47  auto field_shapeIndex = shapeIndex().deviceView();
48  auto field_diameter = grainDiameter_.deviceView();
49  auto field_coarseGrainFactor = coarseGrainFactor_.deviceView();
50  auto field_mass = mass_.deviceView();
51  auto field_propId = propertyId_.deviceView();
52  auto field_I = I_.deviceView();
53 
54  // get info from grains shape
55  realVector_D d("diameter", grains_.boundingDiameter());
56  realVector_D coarseGrainFactor("coarse Grain Factor", grains_.coarseGrainFactor());
57  realVector_D mass("mass",grains_.mass());
58  uint32Vector_D propId("propId", grains_.shapePropertyIds());
59  realVector_D I("I", grains_.Inertia());
60 
61  auto d_d = d.deviceView();
62  auto d_coarseGrainFactor = coarseGrainFactor.deviceView();
63  auto d_mass = mass.deviceView();
64  auto d_propId = propId.deviceView();
65  auto d_I = I.deviceView();
66 
67  Kokkos::parallel_for(
68  "particles::initInertia",
69  policy(aRange.start(), aRange.end()),
70  LAMBDA_HD(uint32 i)
71  {
72  if(aPointsMask(i))
73  {
74  uint32 index = field_shapeIndex[i];
75  field_I[i] = d_I[index];
76  field_diameter[i] = d_d[index];
77  field_coarseGrainFactor[i] = d_coarseGrainFactor[index];
78  field_mass[i] = d_mass[index];
79  field_propId[i] = d_propId[index];
80  }
81  });
82  Kokkos::fence();
83 
84  return true;
85 }
86 
87 bool
89  const wordVector& shapeNames,
90  uint32Vector& propIds,
91  realVector& diams,
92  realVector& coarseGrainFactors,
93 
94  realVector& m,
95  realVector& Is,
96  uint32Vector& shIndex
97 )
98 {
99  auto numNew = static_cast<uint32>(shapeNames.size());
100 
101  propIds.clear();
102  propIds.reserve(numNew);
103 
104  diams.clear();
105  diams.reserve(numNew);
106 
107  coarseGrainFactors.clear();
108  coarseGrainFactors.reserve(numNew);
109 
110  m.clear();
111  m.reserve(numNew);
112 
113  Is.clear();
114  Is.reserve(numNew);
115 
116  shIndex.clear();
117  shIndex.reserve(numNew);
118 
119 
120  for(const auto& name:shapeNames)
121  {
122  uint32 indx;
123  if(grains_.shapeNameToIndex(name,indx))
124  {
125  shIndex.push_back(indx);
126  Is.push_back( grains_.Inertia(indx));
127  m.push_back(grains_.mass(indx));
128  diams.push_back(grains_.boundingDiameter(indx));
129  coarseGrainFactors.push_back(grains_.coarseGrainFactor(indx));
130  propIds.push_back( grains_.propertyId(indx));
131  }
132  else
133  {
134  fatalErrorInFunction<<"Shape name "<< name <<
135  "does not exist. The list is "<<grains_.shapeNameList()<<endl;
136  return false;
137  }
138  }
139 
140  return true;
141 }
142 
144  systemControl &control,
145  const property& prop
146 )
147 :
148  particles(control),
149  grains_
150  (
151  shapeFile__,
152  &control.caseSetup(),
153  prop
154  ),
155  propertyId_
156  (
157  objectFile
158  (
159  "propertyId",
160  "",
161  objectFile::READ_NEVER,
162  objectFile::WRITE_NEVER
163  ),
164  dynPointStruct(),
165  0u
166  ),
167  grainDiameter_
168  (
169  objectFile(
170  "diameter",
171  "",
172  objectFile::READ_NEVER,
173  objectFile::WRITE_NEVER),
174  dynPointStruct(),
175  0.00000000001
176  ),
177  coarseGrainFactor_
178  (
179  objectFile(
180  "coarseGrainFactor",
181  "",
182  objectFile::READ_NEVER,
183  objectFile::WRITE_NEVER),
184  dynPointStruct(),
185  0.00000000001
186  ),
187  mass_
188  (
189  objectFile(
190  "mass",
191  "",
192  objectFile::READ_NEVER,
193  objectFile::WRITE_NEVER),
194  dynPointStruct(),
195  0.0000000001
196  ),
197  I_
198  (
199  objectFile
200  (
201  "I",
202  "",
203  objectFile::READ_NEVER,
204  objectFile::WRITE_NEVER
205  ),
206  dynPointStruct(),
207  static_cast<real>(0.0000000001)
208  ),
209  rVelocity_
210  (
211  objectFile
212  (
213  "rVelocity",
214  "",
215  objectFile::READ_IF_PRESENT,
216  objectFile::WRITE_ALWAYS
217  ),
218  dynPointStruct(),
219  zero3
220  ),
221  rAcceleration_
222  (
223  objectFile(
224  "rAcceleration",
225  "",
226  objectFile::READ_IF_PRESENT,
227  objectFile::WRITE_ALWAYS
228  ),
229  dynPointStruct(),
230  zero3
231  ),
232  boundaryGrainParticles_
233  (
234  dynPointStruct().boundaries(),
235  *this
236  ),
237  accelerationTimer_(
238  "Acceleration", &this->timers() ),
239  intPredictTimer_(
240  "Integration-predict", &this->timers() ),
241  intCorrectTimer_(
242  "Integration-correct", &this->timers() ),
243  fieldUpdateTimer_(
244  "fieldUpdate", &this->timers() )
245 {
246 
247  auto intMethod = control.settingsDict().getVal<word>("integrationMethod");
248  REPORT(1)<<"Creating integration method "<<Green_Text(intMethod)
249  << " for rotational velocity."<<END_REPORT;
250 
252  (
253  "rVelocity",
254  dynPointStruct(),
255  intMethod,
256  rVelocity_.field()
257  );
258 
259  if( !rVelIntegration_ )
260  {
262  " error in creating integration object for rVelocity. \n";
263  fatalExit;
264  }
265 
266  WARNING<<"setFields for rVelIntegration_"<<END_WARNING;
267 
268  if(!initializeParticles())
269  {
271  fatalExit;
272  }
273 
274 }
275 
276 
277 
279 {
281  intPredictTimer_.start();
282  auto dt = this->dt();
283  dynPointStruct().predict(dt, accelertion());
284  rVelIntegration_().predict(dt,rVelocity_, rAcceleration_);
285  intPredictTimer_.end();
286 
287  fieldUpdateTimer_.start();
288  propertyId_.updateBoundariesSlaveToMasterIfRequested();
289  grainDiameter_.updateBoundariesSlaveToMasterIfRequested();
290  coarseGrainFactor_.updateBoundariesSlaveToMasterIfRequested();
291  mass_.updateBoundariesSlaveToMasterIfRequested();
292  I_.updateBoundariesSlaveToMasterIfRequested();
293  rVelocity_.updateBoundariesSlaveToMasterIfRequested();
294  rAcceleration_.updateBoundariesSlaveToMasterIfRequested();
295  rVelIntegration_().updateBoundariesSlaveToMasterIfRequested();
296  fieldUpdateTimer_.end();
297 
298  return true;
299 }
300 
302 {
303 
304  timeInfo ti = TimeInfo();
305  realx3 g = control().g();
306 
308  accelerationTimer_.start();
310  g,
311  mass().deviceViewAll(),
312  contactForce().deviceViewAll(),
313  I().deviceViewAll(),
314  contactTorque().deviceViewAll(),
315  dynPointStruct().activePointsMaskDevice(),
316  accelertion().deviceViewAll(),
317  rAcceleration().deviceViewAll()
318  );
319  for(auto& bndry:boundaryGrainParticles_)
320  {
321  bndry->acceleration(ti, g);
322  }
323  accelerationTimer_.end();
324 
325  intCorrectTimer_.start();
326 
327  if(!dynPointStruct().correct(dt(), accelertion()))
328  {
329  return false;
330  }
331  if(!rVelIntegration_().correct(
332  dt(),
333  rVelocity_,
334  rAcceleration_))
335  {
336  return false;
337  }
338 
339  intCorrectTimer_.end();
340 
341  return true;
342 }
343 
345 (
346  const realx3Vector &position,
347  const wordVector &shapesNames,
348  const anyList &setVarList
349 )
350 {
351  anyList newVarList(setVarList);
352 
353  realVector mass("mass");
354  realVector I("I");
355  realVector diameter("diameter");
356  realVector coarseGrainFactor("coarseGrainFactor");
357  uint32Vector propId("propId");
358  uint32Vector shapeIdx("shapeIdx");
359 
360  if(!getParticlesInfoFromShape(
361  shapesNames,
362  propId,
363  diameter,
364  coarseGrainFactor,
365  mass,
366  I,
367  shapeIdx))
368  {
369  return false;
370  }
371 
372  newVarList.emplaceBack(
373  mass_.name()+"Vector",
374  std::move(mass));
375 
376  newVarList.emplaceBack(
377  I_.name()+"Vector",
378  std::move(I));
379 
380  newVarList.emplaceBack(
381  grainDiameter_.name()+"Vector",
382  std::move(diameter));
383 
384  newVarList.emplaceBack(
385  coarseGrainFactor_.name()+"Vector",
386  std::move(coarseGrainFactor));
387 
388  newVarList.emplaceBack(
389  propertyId_.name()+"Vector",
390  std::move(propId));
391 
392  newVarList.emplaceBack(
393  shapeIndex().name()+"Vector",
394  std::move(shapeIdx));
395 
396  if(!dynPointStruct().insertPoints(position, newVarList))
397  {
398  return false;
399  }
400 
401  return true;
402 }
403 
405 {
406  return "grain";
407 }
408 
410 {
411  return grains_;
412 }
413 
415 (
416  real & minDiam,
417  real& maxDiam
418 )const
419 {
420  minDiam = grains_.minBoundingSphere();
421  maxDiam = grains_.maxBoundingSphere();
422 }
pFlow::minMax
Pair< T, T > minMax(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:132
pFlow::grainParticles::mass_
realPointField_D mass_
mass of particles field
Definition: grainParticles.hpp:63
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::particles::beforeIteration
bool beforeIteration() override
This is called in time loop, before iterate.
Definition: particles.cpp:86
pFlow::grainParticlesKernels::acceleration
void acceleration(const realx3 &g, const deviceViewType1D< real > &mass, const deviceViewType1D< realx3 > &force, const deviceViewType1D< real > &I, const deviceViewType1D< realx3 > &torque, const pFlagTypeDevice &incld, deviceViewType1D< realx3 > lAcc, deviceViewType1D< realx3 > rAcc)
Definition: grainParticlesKernels.cpp:62
pFlow::particles::iterate
bool iterate() override
This is called in time loop.
Definition: particles.cpp:104
pFlow::grainParticles::rVelocity_
realx3PointField_D rVelocity_
pointField of rotational Velocity of particles on device
Definition: grainParticles.hpp:69
pFlow::grainShape::coarseGrainFactor
real coarseGrainFactor(uint32 index) const
Definition: grainShape.cpp:113
grainParticlesKernels.hpp
pFlow::grainParticles::grains_
ShapeType grains_
reference to shapes
Definition: grainParticles.hpp:51
pFlow::grainParticles::insertParticles
bool insertParticles(const realx3Vector &position, const wordVector &shapesNames, const anyList &setVarList) override
Definition: grainParticles.cpp:345
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::grainParticles::getShapes
const shape & getShapes() const override
Definition: grainParticles.cpp:409
pFlow::demComponent::control
const auto & control() const
Const ref to systemControl.
Definition: demComponent.hpp:88
REPORT
#define REPORT(n)
Definition: streams.hpp:39
systemControl.hpp
pFlow::grainParticles::grainDiameter_
realPointField_D grainDiameter_
diameter / boundig sphere size of particles on device
Definition: grainParticles.hpp:57
pFlow::grainParticles::propertyId_
uint32PointField_D propertyId_
property id on device
Definition: grainParticles.hpp:54
pFlow::Vector::reserve
void reserve(size_t cap)
Reserve capacity for vector Preserve the content.
Definition: Vector.hpp:284
pFlow::grainParticles::shapeTypeName
word shapeTypeName() const override
Definition: grainParticles.cpp:404
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::baseShapeNames::indexValid
bool indexValid(uint32 index) const
Definition: baseShapeNames.hpp:140
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::shape::shapePropertyIds
const auto & shapePropertyIds() const
Definition: shape.hpp:80
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::grainParticles::iterate
bool iterate() override
iterate particles
Definition: grainParticles.cpp:301
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:137
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::grainParticles::I
const auto & I() const
const reference to inertia pointField
Definition: grainParticles.hpp:153
pFlow::grainParticles::getParticlesInfoFromShape
bool getParticlesInfoFromShape(const wordVector &shapeNames, uint32Vector &propIds, realVector &diams, realVector &coarseGrainFactors, realVector &m, realVector &Is, uint32Vector &shIndex)
Definition: grainParticles.cpp:88
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::grainParticles::initializeParticles
bool initializeParticles()
Insert new particles in position with specified shapes.
Definition: grainParticles.cpp:26
policy
Kokkos::RangePolicy< pFlow::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > policy
Definition: grainParticlesKernels.cpp:25
pFlow::pointField::execution_space
typename InternalFieldType::execution_space execution_space
Definition: pointField.hpp:52
grainParticles.hpp
pFlow::VectorSingle::deviceView
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
Definition: VectorSingle.cpp:263
pFlow::grainParticles::mass
const realPointField_D & mass() const override
Definition: grainParticles.hpp:207
pFlow::grainParticles::I_
realPointField_D I_
pointField of inertial of particles
Definition: grainParticles.hpp:66
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
pFlow::anyList
Definition: anyList.hpp:35
pFlow::grainParticles::boundingSphereMinMax
void boundingSphereMinMax(real &minDiam, real &maxDiam) const override
Definition: grainParticles.cpp:415
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::shape
Definition: shape.hpp:30
pFlow::internalField::field
const FieldType & field() const
Definition: internalField.hpp:109
pFlow::grainParticles::beforeIteration
bool beforeIteration() override
before iteration step
Definition: grainParticles.cpp:278
pFlow::particles::shapeIndex
auto & shapeIndex()
Definition: particles.hpp:89
pFlow::grainShape::Inertia
bool Inertia(uint32 index, real &I) const override
Definition: grainShape.cpp:189
pFlow::grainParticles::rVelIntegration_
uniquePtr< integration > rVelIntegration_
rotational velocity integrator
Definition: grainParticles.hpp:78
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::shapeFile__
const char *const shapeFile__
Definition: vocabs.hpp:41
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::grainShape::mass
bool mass(uint32 index, real &m) const override
Definition: grainShape.cpp:150
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:37
pFlow::grainParticles::coarseGrainFactor_
realPointField_D coarseGrainFactor_
Definition: grainParticles.hpp:59
pFlow::grainParticles::coarseGrainFactor
const realPointField_D & coarseGrainFactor() const
Definition: grainParticles.hpp:201
pFlow::grainParticles::grainParticles
grainParticles(systemControl &control, const property &prop)
construct from systemControl and property
Definition: grainParticles.cpp:143
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::particles::dynPointStruct
auto & dynPointStruct()
Definition: particles.hpp:74
pFlow::grainShape::boundingDiameter
bool boundingDiameter(uint32 index, real &bDiam) const override
Definition: grainShape.cpp:86
vocabs.hpp
pFlow::triple< real >
pFlow::Vector< word >
m
uint32 m
Definition: NBSLoop.hpp:22
pFlow::integration::create
static uniquePtr< integration > create(const word &baseName, pointStructure &pStruct, const word &method, const realx3Field_D &initialValField)
Create the polymorphic object based on inputs.
Definition: integration.cpp:41
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
pFlow::internalField::deviceView
auto deviceView() const
Definition: internalField.hpp:97
WARNING
#define WARNING
Definition: streams.hpp:43