sphereParticles.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 "sphereParticles.hpp"
22 #include "setFieldList.hpp"
24 
27 {
28  auto objListPtr = particles::getFieldObjectList();
29 
30  objListPtr().push_back(
31  static_cast<eventObserver*>(&I_) );
32 
33  return objListPtr;
34 }
35 
37 (
38  const word& shName,
39  real& diam,
40  real& mass,
41  real& I,
42  int8& propIdx
43 )
44 {
45  uint32 idx;
46  if( !shapes_.nameToIndex(shName, idx) )
47  {
49  " wrong shape name in the input: "<< shName<<endl<<
50  " available shape names are: ", shapes_.names())<<endl;
51  return false;
52  }
53 
54  diam = shapes_.diameter(idx);
55  word materialName = shapes_.material(idx);
56  uint32 pIdx;
57  if( !property_.nameToIndex(materialName, pIdx) )
58  {
60  " wrong material name "<< materialName <<" specified for shape "<< shName<<
61  " in the sphereShape dictionary.\n"<<
62  " available materials are "<< property_.materials()<<endl;
63  return false;
64  }
65  real rho = property_.density(pIdx);
66 
67  mass = Pi/6.0*pow(diam,3.0)*rho;
68  I = 0.4 * mass * pow(diam/2.0,2.0);
69  propIdx= static_cast<int8>(pIdx);
70  return true;
71 }
72 
74 {
75 
76  int32IndexContainer indices(
77  0,
78  static_cast<int32>(shapeName_.size()));
79 
80  return insertSphereParticles(shapeName_, indices);
81 }
82 
83 
85 {
87 
88  intPredictTimer_.start();
89 
90  //INFO<<"before dyn predict"<<endINFO;
91  dynPointStruct_.predict(this->dt(), accelertion_);
92  //INFO<<"after dyn predict"<<endINFO;
93 
94  //INFO<<"before revel predict"<<endINFO;
95  rVelIntegration_().predict(this->dt(),rVelocity_, rAcceleration_);
96  //INFO<<"after rvel predict"<<endINFO;
97 
98  intPredictTimer_.end();
99 
100  return true;
101 }
102 
103 
105 {
106 
107  accelerationTimer_.start();
108  //INFO<<"before accelerationTimer_ "<<endINFO;
110  control().g(),
111  mass().deviceVectorAll(),
112  contactForce().deviceVectorAll(),
113  I().deviceVectorAll(),
114  contactTorque().deviceVectorAll(),
115  pStruct().activePointsMaskD(),
116  accelertion().deviceVectorAll(),
117  rAcceleration().deviceVectorAll()
118  );
119  accelerationTimer_.end();
120 
121  intCorrectTimer_.start();
122  //INFO<<"before correct dyn "<<endINFO;
123  dynPointStruct_.correct(this->dt(), accelertion_);
124  //INFO<<"after correct dyn "<<endINFO;
125  rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_);
126  //INFO<<"after correct rvel "<<endINFO;
127  intCorrectTimer_.end();
128 
129  return true;
130 }
131 
132 
134 {
135  return true;
136 }
137 
138 
140  const wordVector& names,
141  const int32IndexContainer& indices
142  )
143 {
144 
145  if(names.size()!= indices.size())
146  {
148  "sizes of names ("<<names.size()<<") and indices ("
149  << indices.size()<<") do not match \n";
150  return false;
151  }
152 
153  auto len = names.size();
154 
155  realVector diamVec(len, RESERVE());
156  realVector massVec(len, RESERVE());
157  realVector IVec(len, RESERVE());
158  int8Vector pIdVec(len, RESERVE());
159  int32Vector IdVec(len, RESERVE());
160 
161  real d, m, I;
162  int8 pId;
163 
164  ForAll(i, names )
165  {
166 
167  if (diameterMassInertiaPropId(names[i], d, m, I, pId))
168  {
169  diamVec.push_back(d);
170  massVec.push_back(m);
171  IVec.push_back(I);
172  pIdVec.push_back(pId);
173  IdVec.push_back(idHandler_.getNextId());
174  }
175  else
176  {
177  fatalErrorInFunction<< "failed to calculate properties of shape " <<
178  names[i]<<endl;
179  return false;
180  }
181 
182  }
183 
184  if(!diameter_.insertSetElement(indices, diamVec))
185  {
186  fatalErrorInFunction<< " failed to insert diameters to the diameter field. \n";
187  return false;
188  }
189 
190  if(!mass_.insertSetElement(indices, massVec))
191  {
192  fatalErrorInFunction<< " failed to insert mass to the mass field. \n";
193  return false;
194  }
195 
196  if(!I_.insertSetElement(indices, IVec))
197  {
198  fatalErrorInFunction<< " failed to insert I to the I field. \n";
199  return false;
200  }
201 
202  if(!propertyId_.insertSetElement(indices, pIdVec))
203  {
204  fatalErrorInFunction<< " failed to insert propertyId to the propertyId field. \n";
205  return false;
206  }
207 
208  if(!id_.insertSetElement(indices, IdVec))
209  {
210  fatalErrorInFunction<< " failed to insert id to the id field. \n";
211  return false;
212  }
213 
214  return true;
215 
216 }
217 
218 
220  systemControl &control,
221  const property& prop
222 )
223 :
224  particles(
225  control,
226  control.settingsDict().getValOrSet(
227  "integrationMethod",
228  word("AdamsBashforth3")
229  )
230  ),
231  property_(prop),
232  shapes_(
233  control.caseSetup().emplaceObjectOrGet<sphereShape>(
234  objectFile(
236  "",
237  objectFile::READ_ALWAYS,
238  objectFile::WRITE_NEVER
239  )
240  )
241  ),
242  I_(
243  this->time().emplaceObject<realPointField_D>(
244  objectFile(
245  "I",
246  "",
247  objectFile::READ_NEVER,
248  objectFile::WRITE_ALWAYS
249  ),
250  pStruct(),
251  static_cast<real>(0.0000000001)
252  )
253  ),
254  rVelocity_(
255  this->time().emplaceObject<realx3PointField_D>(
256  objectFile(
257  "rVelocity",
258  "",
259  objectFile::READ_IF_PRESENT,
260  objectFile::WRITE_ALWAYS
261  ),
262  pStruct(),
263  zero3
264  )
265  ),
266  rAcceleration_(
267  this->time().emplaceObject<realx3PointField_D>(
268  objectFile(
269  "rAcceleration",
270  "",
271  objectFile::READ_IF_PRESENT,
272  objectFile::WRITE_ALWAYS
273  ),
274  pStruct(),
275  zero3
276  )
277  ),
278  accelerationTimer_(
279  "Acceleration", &this->timers() ),
280  intPredictTimer_(
281  "Integration-predict", &this->timers() ),
282  intCorrectTimer_(
283  "Integration-correct", &this->timers() )
284 
285 {
286 
287  REPORT(1)<<"Creating integration method "<<greenText(this->integrationMethod())
288  << " for rotational velocity."<<endREPORT;
289 
292  "rVelocity",
293  this->time().integration(),
294  this->pStruct(),
295  this->integrationMethod());
296 
297  if( !rVelIntegration_ )
298  {
300  " error in creating integration object for rVelocity. \n";
301  fatalExit;
302  }
303 
304  if(rVelIntegration_->needSetInitialVals())
305  {
306 
307  auto [minInd, maxInd] = pStruct().activeRange();
308  int32IndexContainer indexHD(minInd, maxInd);
309 
310  auto n = indexHD.size();
311  auto index = indexHD.indicesHost();
312 
313  realx3Vector rvel(n,RESERVE());
314  const auto hrVel = rVelocity_.hostVector();
315 
316  for(auto i=0; i<n; i++)
317  {
318  rvel.push_back( hrVel[index(i)]);
319  }
320 
321  REPORT(2)<< "Initializing the required vectors for rotational velocity integratoin\n "<<endREPORT;
322  rVelIntegration_->setInitialVals(indexHD, rvel);
323 
324  }
325 
326 
327  if(!initializeParticles())
328  {
329  fatalExit;
330  }
331 
332 }
333 
335 {
336 
337  if(rVelIntegration_->needSetInitialVals())
338  {
339 
340 
341  auto indexHD = pStruct().insertedPointIndex();
342 
343  auto n = indexHD.size();
344  auto index = indexHD.indicesHost();
345 
346  realx3Vector rvel(n,RESERVE());
347  const auto hrVel = rVelocity_.hostVector();
348 
349  for(auto i=0; i<n; i++)
350  {
351  rvel.push_back( hrVel[index(i)]);
352  }
353 
354  rVelIntegration_->setInitialVals(indexHD, rvel);
355 
356  }
357 
358  return true;
359 }
360 
362 (
363  const realx3Vector& position,
364  const wordVector& shapes,
365  const setFieldList& setField
366  )
367 {
368 
369  if( position.size() != shapes.size() )
370  {
372  " size of vectors position ("<<position.size()<<
373  ") and shapes ("<<shapes.size()<<") are not the same. \n";
374  return false;
375  }
376 
377  auto exclusionListAllPtr = getFieldObjectList();
378 
379  auto newInsertedPtr = pStruct().insertPoints( position, setField, time(), exclusionListAllPtr());
380 
381  if(!newInsertedPtr)
382  {
384  " error in inserting points into pStruct. \n";
385  return false;
386  }
387 
388  auto& newInserted = newInsertedPtr();
389 
390  if(!shapeName_.insertSetElement(newInserted, shapes))
391  {
393  " error in inserting shapes into sphereParticles system.\n";
394  return false;
395  }
396 
397  if( !insertSphereParticles(shapes, newInserted) )
398  {
400  "error in inserting shapes into the sphereParticles. \n";
401  return false;
402  }
403 
404 
405  auto activeR = this->activeRange();
406 
407  REPORT(1)<< "Active range is "<<yellowText("["<<activeR.first<<", "<<activeR.second<<")")<<
408  " and number of active points is "<< cyanText(this->numActive())<<
409  " and pointStructure capacity is "<<cyanText(this->capacity())<<endREPORT;
410 
411  return true;
412 
413 }
pFlow::sphereShapeFile__
const char * sphereShapeFile__
Definition: vocabs.hpp:41
pFlow::particles::beforeIteration
bool beforeIteration() override
Definition: particles.hpp:244
endREPORT
#define endREPORT
Definition: streams.hpp:41
setFieldList.hpp
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::eventMessage
Definition: eventMessage.hpp:29
pFlow::sphereShape
Definition: sphereShape.hpp:32
REPORT
#define REPORT(n)
Definition: streams.hpp:40
pFlow::sphereParticles::diameterMassInertiaPropId
bool diameterMassInertiaPropId(const word &shName, real &diam, real &mass, real &I, int8 &propIdx)
Definition: sphereParticles.cpp:37
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::sphereParticles::insertSphereParticles
bool insertSphereParticles(const wordVector &names, const int32IndexContainer &indices)
Definition: sphereParticles.cpp:139
pFlow::integration
Definition: integration.hpp:35
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::sphereParticles::sphereParticles
sphereParticles(systemControl &control, const property &prop)
construct from systemControl and property
Definition: sphereParticles.cpp:219
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::indexContainer::size
INLINE_FUNCTION_HD size_t size() const
Definition: indexContainer.hpp:107
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:97
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::sphereParticlesKernels::acceleration
void acceleration(realx3 g, deviceViewType1D< real > mass, deviceViewType1D< realx3 > force, deviceViewType1D< real > I, deviceViewType1D< realx3 > torque, IncludeFunctionType incld, deviceViewType1D< realx3 > lAcc, deviceViewType1D< realx3 > rAcc)
Definition: sphereParticlesKernels.hpp:34
pFlow::eventObserver
Definition: eventObserver.hpp:33
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::particles::integrationMethod
auto integrationMethod() const
Definition: particles.hpp:103
pFlow::sphereParticles::getFieldObjectList
virtual uniquePtr< List< eventObserver * > > getFieldObjectList() const override
Definition: sphereParticles.cpp:26
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::sphereParticles::update
bool update(const eventMessage &msg) override
Definition: sphereParticles.cpp:334
pFlow::sphereParticles::afterIteration
bool afterIteration() override
after iteration step
Definition: sphereParticles.cpp:133
pFlow::particles::time
const auto & time() const
Definition: particles.hpp:95
sphereParticlesKernels.hpp
pFlow::sphereParticles::insertParticles
bool insertParticles(const realx3Vector &position, const wordVector &shapes, const setFieldList &setField) override
Insert new particles in position with specified shapes.
Definition: sphereParticles.cpp:362
RESERVE
Definition: Vector.hpp:38
pFlow::pointField
Definition: pointField.hpp:35
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::particles::pStruct
const auto & pStruct() const
Definition: particles.hpp:118
pFlow::sphereParticles::I_
realPointField_D & I_
pointField of inertial of particles
Definition: sphereParticles.hpp:57
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v, T e)
Definition: VectorMath.hpp:109
pFlow::particles::getFieldObjectList
virtual uniquePtr< List< eventObserver * > > getFieldObjectList() const
Definition: particles.cpp:154
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::indexContainer::indicesHost
auto indicesHost() const
Definition: indexContainer.hpp:153
pFlow::sphereParticles::iterate
bool iterate() override
iterate particles
Definition: sphereParticles.cpp:104
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::integration::create
static uniquePtr< integration > create(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: integration.cpp:40
pFlow::sphereParticles::initializeParticles
bool initializeParticles()
Definition: sphereParticles.cpp:73
pFlow::sphereParticles::beforeIteration
bool beforeIteration() override
before iteration step
Definition: sphereParticles.cpp:84
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::sphereParticles::rVelocity_
realx3PointField_D & rVelocity_
pointField of rotational Velocity of particles on device
Definition: sphereParticles.hpp:60
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
sphereParticles.hpp
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:32
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::sphereParticles::rVelIntegration_
uniquePtr< integration > rVelIntegration_
rotational velocity integrator
Definition: sphereParticles.hpp:66
yellowText
#define yellowText(text)
Definition: streams.hpp:30
pFlow::Vector< word >
m
int32 m
Definition: NBSCrossLoop.hpp:22
pFlow::indexContainer< int32 >