cellsWallLevel0.hpp
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 #ifndef __cellsWallLevel0_hpp__
22 #define __cellsWallLevel0_hpp__
23 
24 #include "types.hpp"
25 #include "KokkosTypes.hpp"
26 #include "cells.hpp"
27 #include "iBox.hpp"
28 
29 
30 
31 namespace pFlow
32 {
33 
34 template<
35  typename executionSpace
36  >
38 :
39  public cells<int32>
40 {
41 public:
42 
43  using IdType = int32;
44 
45  using IndexType = int32;
46 
48 
49  using CellType = typename Cells::CellType;
50 
51  using execution_space = executionSpace;
52 
53  using memory_space = typename execution_space::memory_space;
54 
56 
58 
59 protected:
60 
61  // - box extent
63 
64  // - number of triangle elements
66 
67  // - number of points
69 
70  // - ref to vectices (borrowed)
72 
73  // - ref to points in the trisurface (borrowed)
75 
76  // cell range of element/triangle bounding box
78 
79 
80  using tpPWContactSearch = Kokkos::TeamPolicy<
82  Kokkos::Schedule<Kokkos::Dynamic>,
83  Kokkos::IndexType<int32>
84  >;
85 
86  using rpFindCellRange2Type =
87  Kokkos::RangePolicy<TagFindCellRange2, execution_space, Kokkos::IndexType<int32>>;
88 
89 
92  {
94  }
95 
96 public:
97 
98  TypeInfoNV("cellsWallLevel0");
99 
102 
103  FUNCTION_H
105  const Cells& ppCells,
106  real cellExtent,
107  int32 numPoints,
109  const ViewType1D<realx3,memory_space>& points,
110  const ViewType1D<int32x3,memory_space>& vertices
111  )
112  :
113  Cells(ppCells),
114  cellExtent_( max(cellExtent, 0.5 ) ),
116  numPoints_(numPoints),
117  vertices_(vertices),
118  points_(points)
119  {
120 
121  allocateArrays();
122  }
123 
124 
125  // - host call
126  // reset triangle elements if they have changed
129  int32 numPoints,
132  {
133 
135  numPoints_ = numPoints;
136  points_ = points;
137  vertices_ = vertices;
138 
139  allocateArrays();
140 
141  return true;
142  }
143 
146  {
147  return elementBox_[i];
148  }
149 
152  {
153  return numElements_;
154  }
155 
156 
157 
158  template<typename PairsContainer, typename particleMapType>
159  bool broadSearch(PairsContainer& pairs, particleMapType& particleMap)
160  {
161 
162  // map walls onto the cells
163  this->build();
164 
165  this->particleWallFindPairs(pairs, particleMap);
166 
167  return true;
168  }
169 
170  bool build()
171  {
172  Kokkos::parallel_for(
173  "cellsSimple::findcellrange2",
175  *this);
176  Kokkos::fence();
177  return true;
178  }
179 
180  template<typename PairsContainer, typename particleMapType>
181  bool particleWallFindPairs(PairsContainer& pairs, particleMapType& particleMap)
182  {
183 
184  int32 getFull = 1;
185 
186  while (getFull)
187  {
188 
189  getFull = findPairsElementRangeCount(pairs, particleMap.getCellIterator(0));
190 
191  if(getFull)
192  {
193  // - resize the container
194  // note that getFull now shows the number of failed insertions.
195  uint32 len = max(getFull, 50);
196  auto oldCap = pairs.capacity();
197  pairs.increaseCapacityBy(len);
198 
199  INFORMATION<<"Contact pair container capacity increased from "<<
200  oldCap << " to "
201  << pairs.capacity() <<" in cellsWallLevel0."<<endINFO;
202 
203  Kokkos::fence();
204  }
205  }
206 
207  return true;
208  }
209 
210 
211  template<typename PairsContainer, typename CellIteratorType>
212  int32 findPairsElementRangeCount(PairsContainer& pairs, CellIteratorType cellIter)
213  {
214  int32 getFull =0;
215 
216  const auto pwPairs = pairs;
217  const auto elementBox = elementBox_;
218 
219  Kokkos::parallel_reduce(
220  "cellsSimple::findPairsElementRangeModified2",
221  tpPWContactSearch(numElements_, Kokkos::AUTO),
222  LAMBDA_HD(
223  const typename tpPWContactSearch::member_type & teamMember,
224  int32& valueToUpdate){
225 
226  const int32 iTri = teamMember.league_rank();
227 
228  const auto triBox = elementBox[iTri];
229 
230  int32 getFull2 = 0;
231 
232  auto bExtent = boxExtent(triBox);
233  int32 numCellBox = bExtent.x()*bExtent.y()*bExtent.z();
234 
235  Kokkos::parallel_reduce(
236  Kokkos::TeamThreadRange( teamMember, numCellBox ),
237  [&] ( const int32 linIndex, int32 &innerUpdate )
238  {
239 
240  CellType cell;
241  indexToCell(linIndex, triBox, cell);
242 
243  int32 n = cellIter.start(cell.x(),cell.y(),cell.z());
244 
245  while( n>-1)
246  {
247  // id is wall id the pair is (particle id, wall id)
248  if( pairs.insert(static_cast<IdType>(n), iTri) < 0 )
249  innerUpdate++;
250  n = cellIter.getNext(n);
251  }
252 
253  },
254  getFull2
255  );
256 
257  if ( teamMember.team_rank() == 0 ) valueToUpdate += getFull2;
258  },
259  getFull
260  );
261 
262  return getFull;
263  }
264 
267  {
268  auto v = vertices_[i];
269  auto p1 = points_[v.x()];
270  auto p2 = points_[v.y()];
271  auto p3 = points_[v.z()];
272 
273  realx3 minP, maxP;
274 
275  this->extendBox(p1, p2, p3, cellExtent_, minP, maxP);
276  elementBox_[i] = iBoxType(this->pointIndex(minP), this->pointIndex(maxP));
277 
278  }
279 
280 }; // cellsWallLevel0
281 
282 } // pFlow
283 
284 
285 #endif // __cellsWallLevel0_hpp__
pFlow::cellsWallLevel0::IndexType
int32 IndexType
Definition: cellsWallLevel0.hpp:45
pFlow::cellsWallLevel0::cellsWallLevel0
INLINE_FUNCTION_HD cellsWallLevel0()
Definition: cellsWallLevel0.hpp:101
pFlow::cellsWallLevel0::cellExtent_
real cellExtent_
Definition: cellsWallLevel0.hpp:62
pFlow::cellsWallLevel0::rpFindCellRange2Type
Kokkos::RangePolicy< TagFindCellRange2, execution_space, Kokkos::IndexType< int32 > > rpFindCellRange2Type
Definition: cellsWallLevel0.hpp:87
pFlow::real
float real
Definition: builtinTypes.hpp:46
types.hpp
pFlow::cellsWallLevel0::elementBox_
ViewType1D< iBoxType, memory_space > elementBox_
Definition: cellsWallLevel0.hpp:77
pFlow::indexToCell
INLINE_FUNCTION_HD void indexToCell(const indexType idx, const triple< cellIndexType > &extent, triple< cellIndexType > &cell)
Definition: contactSearchFunctions.hpp:71
pFlow::cellsWallLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, particleMapType &particleMap)
Definition: cellsWallLevel0.hpp:159
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::cellsWallLevel0::numPoints_
int32 numPoints_
Definition: cellsWallLevel0.hpp:68
pFlow::cellsWallLevel0::CellType
typename Cells::CellType CellType
Definition: cellsWallLevel0.hpp:49
KokkosTypes.hpp
pFlow::cellsWallLevel0::IdType
int32 IdType
Definition: cellsWallLevel0.hpp:43
pFlow::cells< int32 >::extendBox
INLINE_FUNCTION_HD void extendBox(const CellType &p1, const CellType &p2, const CellType &p3, int32 extent, CellType &minP, CellType &maxP) const
Definition: cells.hpp:203
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
pFlow::cellsWallLevel0::points_
ViewType1D< realx3, memory_space > points_
Definition: cellsWallLevel0.hpp:74
pFlow::cellsWallLevel0::numElements
INLINE_FUNCTION_HD int32 numElements() const
Definition: cellsWallLevel0.hpp:151
pFlow
Definition: demComponent.hpp:28
pFlow::cells::CellType
triple< indexType > CellType
Definition: cells.hpp:36
pFlow::cellsWallLevel0::particleWallFindPairs
bool particleWallFindPairs(PairsContainer &pairs, particleMapType &particleMap)
Definition: cellsWallLevel0.hpp:181
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::cellsWallLevel0::execution_space
executionSpace execution_space
Definition: cellsWallLevel0.hpp:51
iBox.hpp
pFlow::cellsWallLevel0::TypeInfoNV
TypeInfoNV("cellsWallLevel0")
pFlow::cellsWallLevel0::iBoxType
iBox< IndexType > iBoxType
Definition: cellsWallLevel0.hpp:55
pFlow::cellsWallLevel0::TagFindCellRange2
Definition: cellsWallLevel0.hpp:57
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::cellsWallLevel0::resetElements
bool resetElements(int32 numElements, int32 numPoints, ViewType1D< realx3, memory_space > &points, ViewType1D< int32x3, memory_space > &vertices)
Definition: cellsWallLevel0.hpp:127
pFlow::cellsWallLevel0::elementBox
INLINE_FUNCTION_HD iBoxType elementBox(int32 i) const
Definition: cellsWallLevel0.hpp:145
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cellsWallLevel0::memory_space
typename execution_space::memory_space memory_space
Definition: cellsWallLevel0.hpp:53
pFlow::cellsWallLevel0::operator()
INLINE_FUNCTION_HD void operator()(TagFindCellRange2, int32 i) const
Definition: cellsWallLevel0.hpp:266
pFlow::boxExtent
INLINE_FUNCTION_HD triple< cellIndexType > boxExtent(const iBox< cellIndexType > &box)
Definition: contactSearchFunctions.hpp:82
pFlow::cellsWallLevel0::tpPWContactSearch
Kokkos::TeamPolicy< execution_space, Kokkos::Schedule< Kokkos::Dynamic >, Kokkos::IndexType< int32 > > tpPWContactSearch
Definition: cellsWallLevel0.hpp:84
cells.hpp
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::cellsWallLevel0::findPairsElementRangeCount
int32 findPairsElementRangeCount(PairsContainer &pairs, CellIteratorType cellIter)
Definition: cellsWallLevel0.hpp:212
pFlow::cellsWallLevel0::numElements_
int32 numElements_
Definition: cellsWallLevel0.hpp:65
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::cellsWallLevel0
Definition: cellsWallLevel0.hpp:37
pFlow::iBox
Definition: iBox.hpp:33
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< real >
pFlow::cells< int32 >::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
endINFO
#define endINFO
Definition: streams.hpp:38
pFlow::cellsWallLevel0::cellsWallLevel0
FUNCTION_H cellsWallLevel0(const Cells &ppCells, real cellExtent, int32 numPoints, int32 numElements, const ViewType1D< realx3, memory_space > &points, const ViewType1D< int32x3, memory_space > &vertices)
Definition: cellsWallLevel0.hpp:104
INFORMATION
#define INFORMATION
Definition: streams.hpp:37
pFlow::cellsWallLevel0::vertices_
ViewType1D< int32x3, memory_space > vertices_
Definition: cellsWallLevel0.hpp:71
pFlow::cellsWallLevel0::allocateArrays
FUNCTION_H void allocateArrays()
Definition: cellsWallLevel0.hpp:91
pFlow::cellsWallLevel0::build
bool build()
Definition: cellsWallLevel0.hpp:170