www.cemf.ir
geometry.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 "geometry.hpp"
22 #include "systemControl.hpp"
23 #include "vocabs.hpp"
24 
25 
27 {
28  if(materialName_.size() != numSurfaces() )
29  {
31  "number of subSurface and material names do not match"<<endl;
32  return false;
33  }
34 
35  uint32Vector propId(
36  "propId",
37  capacity(),
38  size(),
39  RESERVE());
40 
42  {
43  uint32 pIdx =0;
44 
45  if( !wallProperty_.nameToIndex(materialName_[i], pIdx) )
46  {
48  "Property/material name is invalid "<<materialName_[i]<<
49  ". A list of valid names are \n"<< wallProperty_.materials()<<endl;
50  return false;
51  }
52 
53  auto triRange = subSurfaceRange(i);
54  propId.fill(triRange.start(), triRange.end(), pIdx);
55 
56  }
57 
58  propertyId_.assign(propId);
59 
60  return true;
61 
62 }
63 
65 {
66  contactForceWall_.fill(zero3);
67 }
68 
70 (
71  systemControl& control,
72  const property& prop
73 )
74 :
76  (
78  (
80  "",
83  ),
84  &control.geometry()
85  ),
87  (
88  "geometry",
89  control
90  ),
91  wallProperty_(prop),
92  propertyId_
93  (
95  (
96  "propertyId",
97  "",
100  ),
101  *this,
102  0u
103  ),
104  contactForceWall_
105  (
106  objectFile
107  (
108  "contactForcWall",
109  "",
112  ),
113  *this,
114  zero3
115  ),
116  normalStressWall_
117  (
118  objectFile
119  (
120  "normalStressWall",
121  "",
124  ),
125  *this,
126  zero3
127  ),
128  shearStressWall_
129  (
130  objectFile
131  (
132  "shearStressWall",
133  "",
136  ),
137  *this,
138  zero3
139  )
140 {
141 
142  readWholeObject_ = false;
143  if( !IOobject::readObject() )
144  {
146  "Error in reading from file "<<IOobject::path()<<endl;
147  fatalExit;
148  }
149  readWholeObject_ = true;
150 
151  if( this->numSurfaces() != motionComponentName_.size() )
152  {
154  "Number of surfaces is not equal to number of motion component names"<<endl;
155  fatalExit;
156  }
157 
158  if(!createPropertyId())
159  {
160  fatalExit;
161  }
162 }
163 
165 (
166  systemControl &control,
167  const property &prop,
168  multiTriSurface &surf,
169  const wordVector &motionCompName,
170  const wordVector &materialName,
171  const dictionary& motionDict
172 )
173 :
175  (
176  objectFile
177  (
179  "",
182  ),
183  &control.geometry(),
184  surf
185  ),
187  (
188  "geometry",
189  control
190  ),
191  wallProperty_
192  (
193  prop
194  ),
195  propertyId_
196  (
197  objectFile
198  (
199  "propertyId",
200  "",
203  ),
204  *this,
205  0u
206  ),
207  contactForceWall_
208  (
209  objectFile
210  (
211  "contactForcWall",
212  "",
215  ),
216  *this,
217  zero3
218  ),
219  normalStressWall_
220  (
221  objectFile
222  (
223  "normalStressWall",
224  "",
227  ),
228  *this,
229  zero3
230  ),
231  shearStressWall_
232  (
233  objectFile
234  (
235  "shearStressWall",
236  "",
239  ),
240  *this,
241  zero3
242  )
243 
244 {
245  motionComponentName_.assign(motionCompName);
246  materialName_.assign(materialName);
247 
248 
249  if( this->numSurfaces() != motionComponentName_.size() )
250  {
252  "Number of surfaces ("<< this->numSurfaces() <<
253  ") is not equal to number of motion component names("<<
254  motionComponentName_.size()<<")"<<endl;
255  fatalExit;
256  }
257 
258  if(!createPropertyId())
259  {
260  fatalExit;
261  }
262 }
263 
265 {
266  zeroForce();
267  return true;
268 }
269 
271 {
272  return true;
273 }
274 
276 {
277  auto numTris = size();
278  auto& normalsD = normals().deviceViewAll();
279  auto& areaD = area().deviceViewAll();
280  auto& cForceD = contactForceWall_.deviceViewAll();
281  auto& sStressD = shearStressWall_.deviceViewAll();
282  auto& nStressD = normalStressWall_.deviceViewAll();
283 
284  Kokkos::parallel_for(
285  "pFlow::geometry::afterIteration",
286  deviceRPolicyStatic(0, numTris),
287  LAMBDA_HD(uint32 i)
288  {
289  realx3 n = normalsD[i];
290  real A = max(areaD[i],smallValue);
291  realx3 nF = dot(cForceD[i],n)*n;
292  realx3 sF = cForceD[i] - nF;
293  nStressD[i] = nF/A;
294  sStressD[i] = sF/A;
295  });
296  Kokkos::fence();
297 
298  return true;
299 }
300 
302 {
303  motionComponentName_.read(is, iop);
304 
305  materialName_.read(is, iop);
306 
307  if( readWholeObject_ )
308  {
309  return multiTriSurface::read(is, iop);
310  }
311 
312  return true;
313 }
314 
315 bool pFlow::geometry::write(iOstream &os, const IOPattern &iop) const
316 {
317 
318  if( !motionComponentName_.write(os, iop) )
319  {
321  return false;
322  }
323 
324  if( !materialName_.write(os,iop))
325  {
327  return false;
328  }
329 
330  return multiTriSurface::write(os,iop);
331 }
332 
333 
336 (
337  systemControl& control,
338  const property& prop
339 )
340 {
341 
342  //
343  fileDictionary dict( motionModelFile__, control.time().geometry().path());
344 
345  word model = dict.getVal<word>("motionModel");
346 
347  auto geomModel = angleBracketsNames("geometry", model);
348 
349  REPORT(1)<< "Selecting geometry model . . ."<<END_REPORT;
350  if( systemControlvCtorSelector_.search(geomModel) )
351  {
352  auto objPtr = systemControlvCtorSelector_[geomModel] (control, prop);
353  REPORT(2)<<"Model "<< Green_Text(geomModel)<<" is created.\n"<<END_REPORT;
354  return objPtr;
355  }
356  else
357  {
358  printKeys
359  (
360  fatalError << "Ctor Selector "<< Yellow_Text(geomModel) << " dose not exist. \n"
361  <<"Avaiable ones are: \n\n"
362  ,
363  systemControlvCtorSelector_
364  );
365  fatalExit;
366  }
367 
368  return nullptr;
369 }
370 
373  (
374  systemControl& control,
375  const property& prop,
376  multiTriSurface& surf,
377  const wordVector& motionCompName,
378  const wordVector& materialName,
379  const dictionary& motionDic
380  )
381 {
382 
383  word model = motionDic.getVal<word>("motionModel");
384 
385  auto geomModel = angleBracketsNames("geometry", model);
386 
387  REPORT(1)<< "Selecting geometry model . . ."<<END_REPORT;
388 
389  if( dictionaryvCtorSelector_.search(geomModel) )
390  {
391  auto objPtr = dictionaryvCtorSelector_[geomModel]
392  (
393  control,
394  prop,
395  surf,
396  motionCompName,
397  materialName,
398  motionDic
399  );
400  REPORT(2)<<"Model "<< Green_Text(geomModel)<<" is created.\n"<<END_REPORT;
401  return objPtr;
402  }
403  else
404  {
405  printKeys
406  (
407  fatalError << "Ctor Selector "<< Yellow_Text(geomModel) << " dose not exist. \n"
408  <<"Avaiable ones are: \n\n"
409  ,
410  dictionaryvCtorSelector_
411  );
412  fatalExit;
413  }
414  return nullptr;
415 }
416 
417 
418 
419 
420 /*pFlow::geometry::geometry
421 (
422  systemControl& control,
423  const property& prop,
424  const multiTriSurface& triSurface,
425  const wordVector& motionCompName,
426  const wordVector& matName
427 )
428 :
429  demGeometry(control),
430  wallProperty_(prop),
431  geometryRepository_(control.geometry()),
432  triSurface_(
433  control.geometry().emplaceObject<multiTriSurface>(
434  objectFile(
435  "triSurface",
436  "",
437  objectFile::READ_NEVER,
438  objectFile::WRITE_ALWAYS
439  ),
440  triSurface
441  )
442  ),
443  motionComponentName_(
444  control.geometry().emplaceObject<wordField>(
445  objectFile(
446  "motionComponentName",
447  "",
448  objectFile::READ_NEVER,
449  objectFile::WRITE_ALWAYS
450  ),
451  "motionNamesList",
452  motionCompName
453  )
454  ),
455  materialName_(
456  control.geometry().emplaceObject<wordField>(
457  objectFile(
458  "materialName",
459  "",
460  objectFile::READ_NEVER,
461  objectFile::WRITE_ALWAYS
462  ),
463  "materialNamesList",
464  matName
465  )
466  ),
467  propertyId_(
468  control.geometry().emplaceObject<int8TriSurfaceField_D>(
469  objectFile(
470  "propertyId",
471  "",
472  objectFile::READ_NEVER,
473  objectFile::WRITE_NEVER),
474  surface(),
475  0 ) ),
476  contactForceWall_(
477  control.geometry().emplaceObject<realx3TriSurfaceField_D>(
478  objectFile(
479  "contactForceWall",
480  "",
481  objectFile::READ_NEVER,
482  objectFile::WRITE_ALWAYS),
483  surface(),
484  zero3) ),
485  stressWall_(
486  control.geometry().emplaceObject<realx3TriSurfaceField_D>(
487  objectFile(
488  "stressWall",
489  "",
490  objectFile::READ_NEVER,
491  objectFile::WRITE_ALWAYS),
492  surface(),
493  zero3) )
494 {
495  if(!findPropertyId())
496  {
497  fatalExit;
498  }
499 }
500 
501 pFlow::geometry::geometry
502 (
503  systemControl& control,
504  const property& prop,
505  const dictionary& dict,
506  const multiTriSurface& triSurface,
507  const wordVector& motionCompName,
508  const wordVector& matName
509 )
510 :
511  geometry(control, prop, triSurface, motionCompName, matName)
512 {}
513 
514 
515 
516 
517 bool pFlow::geometry::beforeIteration()
518 {
519  this->zeroForce();
520  return true;
521 }
522 
523 
524 bool pFlow::geometry::afterIteration()
525 {
526 
527  auto Force = contactForceWall_.deviceVectorAll();
528  auto area = triSurface_.area().deviceVectorAll();
529  auto stress = stressWall_.deviceVectorAll();
530  auto numTri =triSurface_.size();
531 
532 
533  Kokkos::parallel_for(
534  "geometry::calculateStress",
535  numTri,
536  LAMBDA_HD(int32 i){
537  stress[i] = Force[i]/area[i];
538  });
539  Kokkos::fence();
540  return true;
541 
542 }*/
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::geometry::materialName_
wordField_H materialName_
Material name of each wall surface
Definition: geometry.hpp:62
pFlow::triSurface::capacity
uint32 capacity() const
Definition: triSurface.hpp:167
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:31
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
REPORT
#define REPORT(n)
Definition: streams.hpp:39
systemControl.hpp
pFlow::geometry::create
static uniquePtr< geometry > create(systemControl &control, const property &prop)
Definition: geometry.cpp:336
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::VectorSingle< word, HostSpace >::size
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
Definition: wordVectorHost.hpp:231
pFlow::geometry::createPropertyId
bool createPropertyId()
Find property id of each triangle based on the supplied material name and the surface wall that the t...
Definition: geometry.cpp:26
pFlow::multiTriSurface::write
bool write(iOstream &os, const IOPattern &iop) const override
Definition: multiTriSurface.cpp:91
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:137
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::motionModelFile__
const char *const motionModelFile__
Definition: vocabs.hpp:45
pFlow::geometry::wallProperty_
const property & wallProperty_
Const reference to physical property of materials.
Definition: geometry.hpp:54
pFlow::Time::geometry
const repository & geometry() const
Definition: Time.hpp:68
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::multiTriSurface
Definition: multiTriSurface.hpp:32
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:44
pFlow::geometry::afterIteration
bool afterIteration() override
This is called in time loop, after iterate.
Definition: geometry.cpp:275
RESERVE
Definition: Vector.hpp:40
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::triSurface::size
uint32 size() const
Definition: triSurface.hpp:162
pFlow::IOobject::readObject
bool readObject(bool rdHdr=true)
Definition: IOobject.cpp:83
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::property::materials
const auto & materials() const
Return list of material names.
Definition: property.hpp:117
pFlow::IOfileHeader::path
fileSystem path() const
Definition: IOfileHeader.cpp:63
pFlow::angleBracketsNames
word angleBracketsNames(const word &w1, const word &w2)
Output <w1,w2>
Definition: bTypesFunctions.cpp:156
pFlow::demComponent
A base class for every main component of DEM system.
Definition: demComponent.hpp:42
pFlow::geometry::propertyId_
uint32TriSurfaceField_D propertyId_
Property id of each triangle in the set of wall surfaces.
Definition: geometry.hpp:67
pFlow::systemControl::time
const Time & time() const
Definition: systemControl.hpp:122
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::IOPattern
Definition: IOPattern.hpp:32
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::multiTriSurface::read
bool read(iIstream &is, const IOPattern &iop) override
Definition: multiTriSurface.cpp:76
geometry.hpp
pFlow::geometry::beforeIteration
bool beforeIteration() override
This is called in time loop, before iterate.
Definition: geometry.cpp:264
pFlow::geometry::read
bool read(iIstream &is, const IOPattern &iop) override
Definition: geometry.cpp:301
pFlow::property::nameToIndex
bool nameToIndex(const word &name, uint32 &idx) const
Get the name of material in index idx Return true, if the name found, otherwise false.
Definition: property.hpp:172
pFlow::geometry::iterate
bool iterate() override
This is called in time loop.
Definition: geometry.cpp:270
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::geometry::zeroForce
void zeroForce()
Initialize contact force to zero.
Definition: geometry.cpp:64
fatalError
#define fatalError
Report a fatal error and exit the applicaiton.
Definition: error.hpp:70
pFlow::triSurfaceFile__
const char *const triSurfaceFile__
Definition: vocabs.hpp:43
pFlow::repository::path
virtual fileSystem path() const
Definition: repository.cpp:70
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:37
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:37
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::systemControl::geometry
const repository & geometry() const
Definition: systemControl.hpp:132
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::deviceRPolicyStatic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyStatic
Definition: KokkosTypes.hpp:66
pFlow::Vector::fill
void fill(const T &val)
Definition: VectorI.hpp:23
pFlow::triSurfaceField::assign
void assign(const std::vector< T > &vals)
Definition: triSurfaceField.hpp:123
pFlow::objectFile::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: objectFile.hpp:38
vocabs.hpp
pFlow::triple< real >
pFlow::Vector< uint32 >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::multiTriSurface::numSurfaces
uint32 numSurfaces() const
Definition: multiTriSurface.hpp:81
pFlow::geometry::write
bool write(iOstream &os, const IOPattern &iop) const override
write
Definition: geometry.cpp:315
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::geometry::geometry
geometry(systemControl &control, const property &prop)
Construct from controlSystem and property, for reading from file.
Definition: geometry.cpp:70
pFlow::multiTriSurface::subSurfaceRange
rangeU32 subSurfaceRange(uint32 nSub) const
Definition: multiTriSurface.hpp:91