www.cemf.ir
geometryMotion.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 MotionModel>
23 {
24 
25  if(motionComponentName().size() != numSurfaces() )
26  {
28  "size of motion component names in the triSurface is not"<<
29  " equal to size of number of sub-surfaces"<<endl;
30  return false;
31  }
32 
33  uint32Vector surfMotionIndex("surfMotionIndex");
34  uint32Vector triMotionIndex("triMotionIndex");
35  uint32Vector pointMotionIndex("pointMotionIndex");
36 
37  ForAll( surfI, motionComponentName())
38  {
39  auto mName = motionComponentName()[surfI];
40  uint32 mInd=0;
41 
42  if( !motionModel_.nameToIndex(mName, mInd) )
43  {
45  mName<< " does not exist in the list of motion names -> "<<
46  motionModel_.componentNames();
47  return false;
48  }
49  surfMotionIndex.push_back(mInd);
50 
51  auto surfRange = subSurfaceRange(surfI);
52 
53  for(uint32 i=0; i<surfRange.numElements(); i++)
54  {
55  triMotionIndex.push_back(mInd);
56  }
57 
58  auto pointRange = subSurfacePointRange(surfI);
59  for(uint32 n=0; n<pointRange.numElements(); n++)
60  {
61  pointMotionIndex.push_back(mInd);
62  }
63  }
64 
65  surfMotionIndex_.assign(surfMotionIndex);
66  triMotionIndex_.assign(triMotionIndex);
67  pointMotionIndex_.assign(pointMotionIndex);
68 
69  return true;
70 }
71 
72 namespace pFlow::GMotion
73 {
74  template<typename ModelInterface>
76  real dt,
77  uint32 nPoints,
78  const ModelInterface& mModel,
79  const deviceViewType1D<uint32>& pointMIndexD,
80  const deviceViewType1D<realx3>& pointsD
81  )
82  {
83  Kokkos::parallel_for(
84  "geometryMotion<MotionModel>::movePoints",
85  deviceRPolicyStatic(0, nPoints),
86  LAMBDA_HD(uint32 i){
87  auto newPos = mModel.transferPoint(pointMIndexD[i], pointsD[i], dt);
88  pointsD[i] = newPos;
89  });
90 
91  Kokkos::fence();
92  }
93 }
94 
95 template<typename MotionModel>
97  {
98 
99  uint32 iter = this->currentIter();
100  real t = this->currentTime();
101  real dt = this->dt();
102 
103  auto mModel = motionModel_.getModelInterface(iter, t, dt);
104 
105  auto& pointMIndexD= pointMotionIndex_.deviceViewAll();
106  auto& pointsD = points().deviceViewAll();
107 
109  dt,
110  numPoints(),
111  motionModel_.getModelInterface(iter, t, dt),
112  pointMotionIndex_.deviceViewAll(),
113  points().deviceViewAll()
114  );
115 
116  /*Kokkos::parallel_for(
117  "geometryMotion<MotionModel>::movePoints",
118  deviceRPolicyStatic(0, numPoints()),
119  LAMBDA_HD(uint32 i){
120  auto newPos = mModel.transferPoint(pointMIndexD[i], pointsD[i], dt);
121  pointsD[i] = newPos;
122  });
123 
124  Kokkos::fence();*/
125 
126  // move the motion components
127  motionModel_.move(iter, t,dt);
128 
129  // end of calculations
130 
131 
132  return true;
133  }
134 
135 template<typename MotionModel>
137 (
138  systemControl& control,
139  const property& prop
140 )
141 :
142  geometry(control, prop),
143  motionModel_
144  (
145  objectFile
146  (
148  "",
149  objectFile::READ_ALWAYS,
150  objectFile::WRITE_ALWAYS
151  ),
152  owner()
153  ),
154  moveGeomTimer_("move geometry", &this->timers())
155 {
156  if(!findMotionIndex())
157  {
158  fatalExit;
159  }
160 }
161 
162 template <typename MotionModelType>
164 (
165  systemControl &control,
166  const property &prop,
167  multiTriSurface &surf,
168  const wordVector &motionCompName,
169  const wordVector &materialName,
170  const dictionary &motionDict
171 )
172 :
173  geometry
174  (
175  control,
176  prop,
177  surf,
178  motionCompName,
179  materialName,
180  motionDict
181  ),
182  motionModel_
183  (
184  objectFile
185  (
187  "",
188  objectFile::READ_NEVER,
189  objectFile::WRITE_ALWAYS
190  ),
191  motionDict,
192  owner()
193  ),
194  moveGeomTimer_("move geometry", &this->timers())
195 {
196  if(!findMotionIndex())
197  {
198  fatalExit;
199  }
200 }
201 
202 
203  template<typename MotionModel>
205  {
206  if( motionModel_.isMoving() )
207  {
208  moveGeomTimer_.start();
209  moveGeometry();
210  this->calculateNormals();
211  moveGeomTimer_.end();
212  }
213  return true;
214  }
pFlow::triSurfaceKernels::calculateNormals
INLINE_FUNCTION_H bool calculateNormals(const realx3Field_D &points, const uint32x3Field_D &vertices, realx3Field_D &normals)
Definition: triSurfaceKernels.hpp:57
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::motionModelFile__
const char *const motionModelFile__
Definition: vocabs.hpp:45
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::geometryMotion::moveGeometry
bool moveGeometry()
Move geometry.
Definition: geometryMotion.cpp:96
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::GMotion::moveGeometry
void moveGeometry(real dt, uint32 nPoints, const ModelInterface &mModel, const deviceViewType1D< uint32 > &pointMIndexD, const deviceViewType1D< realx3 > &pointsD)
Definition: geometryMotion.cpp:75
pFlow::multiTriSurface
Definition: multiTriSurface.hpp:32
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::geometryMotion::geometryMotion
geometryMotion(systemControl &control, const property &prop)
Definition: geometryMotion.cpp:137
pFlow::geometryMotion::iterate
bool iterate() override
Iterate geometry one time step
Definition: geometryMotion.cpp:204
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:37
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::geometryMotion::findMotionIndex
bool findMotionIndex()
determine the motion index of each triangle
Definition: geometryMotion.cpp:22
pFlow::geometry
Base class for geometry for managing tri-surfaces, geometry motion, and surface physical properties.
Definition: geometry.hpp:44
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< uint32 >
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::GMotion
Definition: geometryMotion.cpp:72