www.cemf.ir
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, false);
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 
123  dynPointStruct_.correct(this->dt(), accelertion_);
124 
125  rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_);
126 
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  bool setId
143  )
144 {
145 
146  if(names.size()!= indices.size())
147  {
149  "sizes of names ("<<names.size()<<") and indices ("
150  << indices.size()<<") do not match \n";
151  return false;
152  }
153 
154  auto len = names.size();
155 
156  realVector diamVec(len, RESERVE());
157  realVector massVec(len, RESERVE());
158  realVector IVec(len, RESERVE());
159  int8Vector pIdVec(len, RESERVE());
160  int32Vector IdVec(len, RESERVE());
161 
162  real d, m, I;
163  int8 pId;
164 
165  ForAll(i, names )
166  {
167 
168  if (diameterMassInertiaPropId(names[i], d, m, I, pId))
169  {
170  diamVec.push_back(d);
171  massVec.push_back(m);
172  IVec.push_back(I);
173  pIdVec.push_back(pId);
174  if(setId) IdVec.push_back(idHandler_.getNextId());
175  //output<<" we are in sphereParticles nextId "<< idHandler_.nextId()<<endl;
176  }
177  else
178  {
179  fatalErrorInFunction<< "failed to calculate properties of shape " <<
180  names[i]<<endl;
181  return false;
182  }
183 
184  }
185 
186  if(!diameter_.insertSetElement(indices, diamVec))
187  {
188  fatalErrorInFunction<< " failed to insert diameters to the diameter field. \n";
189  return false;
190  }
191 
192  if(!mass_.insertSetElement(indices, massVec))
193  {
194  fatalErrorInFunction<< " failed to insert mass to the mass field. \n";
195  return false;
196  }
197 
198  if(!I_.insertSetElement(indices, IVec))
199  {
200  fatalErrorInFunction<< " failed to insert I to the I field. \n";
201  return false;
202  }
203 
204  if(!propertyId_.insertSetElement(indices, pIdVec))
205  {
206  fatalErrorInFunction<< " failed to insert propertyId to the propertyId field. \n";
207  return false;
208  }
209 
210  if(setId)
211  {
212  if( !id_.insertSetElement(indices, IdVec))
213  {
214  fatalErrorInFunction<< " failed to insert id to the id field. \n";
215  return false;
216  }
217  }
218 
219 
220  return true;
221 
222 }
223 
224 
226  systemControl &control,
227  const property& prop
228 )
229 :
230  particles(
231  control,
232  control.settingsDict().getValOrSet(
233  "integrationMethod",
234  word("AdamsBashforth3")
235  )
236  ),
237  property_(prop),
238  shapes_(
239  control.caseSetup().emplaceObjectOrGet<sphereShape>(
240  objectFile(
242  "",
243  objectFile::READ_ALWAYS,
244  objectFile::WRITE_NEVER
245  )
246  )
247  ),
248  I_(
249  this->time().emplaceObject<realPointField_D>(
250  objectFile(
251  "I",
252  "",
253  objectFile::READ_NEVER,
254  objectFile::WRITE_ALWAYS
255  ),
256  pStruct(),
257  static_cast<real>(0.0000000001)
258  )
259  ),
260  rVelocity_(
261  this->time().emplaceObject<realx3PointField_D>(
262  objectFile(
263  "rVelocity",
264  "",
265  objectFile::READ_IF_PRESENT,
266  objectFile::WRITE_ALWAYS
267  ),
268  pStruct(),
269  zero3
270  )
271  ),
272  rAcceleration_(
273  this->time().emplaceObject<realx3PointField_D>(
274  objectFile(
275  "rAcceleration",
276  "",
277  objectFile::READ_IF_PRESENT,
278  objectFile::WRITE_ALWAYS
279  ),
280  pStruct(),
281  zero3
282  )
283  ),
284  accelerationTimer_(
285  "Acceleration", &this->timers() ),
286  intPredictTimer_(
287  "Integration-predict", &this->timers() ),
288  intCorrectTimer_(
289  "Integration-correct", &this->timers() )
290 
291 {
292 
293  REPORT(1)<<"Creating integration method "<<greenText(this->integrationMethod())
294  << " for rotational velocity."<<endREPORT;
295 
298  "rVelocity",
299  this->time().integration(),
300  this->pStruct(),
301  this->integrationMethod());
302 
303  if( !rVelIntegration_ )
304  {
306  " error in creating integration object for rVelocity. \n";
307  fatalExit;
308  }
309 
310  if(rVelIntegration_->needSetInitialVals())
311  {
312 
313  auto [minInd, maxInd] = pStruct().activeRange();
314  int32IndexContainer indexHD(minInd, maxInd);
315 
316  auto n = indexHD.size();
317  auto index = indexHD.indicesHost();
318 
319  realx3Vector rvel(n,RESERVE());
320  const auto hrVel = rVelocity_.hostVector();
321 
322  for(auto i=0; i<n; i++)
323  {
324  rvel.push_back( hrVel[index(i)]);
325  }
326 
327  REPORT(2)<< "Initializing the required vectors for rotational velocity integratoin\n "<<endREPORT;
328  rVelIntegration_->setInitialVals(indexHD, rvel);
329 
330  }
331 
332 
333  if(!initializeParticles())
334  {
335  fatalExit;
336  }
337 
338 }
339 
341 {
342 
343  if(rVelIntegration_->needSetInitialVals())
344  {
345 
346 
347  auto indexHD = pStruct().insertedPointIndex();
348 
349  auto n = indexHD.size();
350  auto index = indexHD.indicesHost();
351 
352  realx3Vector rvel(n,RESERVE());
353  const auto hrVel = rVelocity_.hostVector();
354 
355  for(auto i=0; i<n; i++)
356  {
357  rvel.push_back( hrVel[index(i)]);
358  }
359 
360  rVelIntegration_->setInitialVals(indexHD, rvel);
361 
362  }
363 
364  return true;
365 }
366 
368 (
369  const realx3Vector& position,
370  const wordVector& shapes,
371  const setFieldList& setField
372  )
373 {
374 
375  if( position.size() != shapes.size() )
376  {
378  " size of vectors position ("<<position.size()<<
379  ") and shapes ("<<shapes.size()<<") are not the same. \n";
380  return false;
381  }
382 
383  auto exclusionListAllPtr = getFieldObjectList();
384 
385  auto newInsertedPtr = pStruct().insertPoints( position, setField, time(), exclusionListAllPtr());
386 
387  if(!newInsertedPtr)
388  {
390  " error in inserting points into pStruct. \n";
391  return false;
392  }
393 
394  auto& newInserted = newInsertedPtr();
395 
396  if(!shapeName_.insertSetElement(newInserted, shapes))
397  {
399  " error in inserting shapes into sphereParticles system.\n";
400  return false;
401  }
402 
403  if( !insertSphereParticles(shapes, newInserted) )
404  {
406  "error in inserting shapes into the sphereParticles. \n";
407  return false;
408  }
409 
410 
411  auto activeR = this->activeRange();
412 
413  REPORT(1)<< "Active range is "<<yellowText("["<<activeR.first<<", "<<activeR.second<<")")<<
414  " and number of active points is "<< cyanText(this->numActive())<<
415  " and pointStructure capacity is "<<cyanText(this->capacity())<<endREPORT;
416 
417  return true;
418 
419 }
pFlow::sphereShapeFile__
const char * sphereShapeFile__
Definition: vocabs.hpp:41
pFlow::particles::beforeIteration
bool beforeIteration() override
Definition: particles.cpp:153
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::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:225
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:115
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:97
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:301
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)
Add newline and flush stream.
Definition: iOstream.hpp:320
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:340
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:368
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:183
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::indexContainer::indicesHost
auto indicesHost() const
Definition: indexContainer.hpp:171
pFlow::sphereParticles::iterate
bool iterate() override
iterate particles
Definition: sphereParticles.cpp:104
pFlow::sphereParticles::insertSphereParticles
bool insertSphereParticles(const wordVector &names, const int32IndexContainer &indices, bool setId=true)
Definition: sphereParticles.cpp:139
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 >