www.cemf.ir
cellsWallLevel0.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 "cellsWallLevel0.hpp"
22 #include "streams.hpp"
23 
25 (
26  real cellExtent,
27  uint32 numPoints,
28  uint32 numElements,
30  const ViewType1D<uint32x3, memory_space> &vertices,
32 )
33 :
34  cellExtent_( max(cellExtent, 0.5 ) ),
35  numElements_(numElements),
36  numPoints_(numPoints),
37  vertices_(vertices),
38  points_(points),
39  normals_(normals)
40 {
41  allocateArrays();
42 }
43 
45 (
46  uint32 numElements,
47  uint32 numPoints,
48  const ViewType1D<realx3, memory_space>& points,
49  const ViewType1D<uint32x3, memory_space>& vertices,
51 )
52 {
53 
54  numElements_ = numElements;
55  numPoints_ = numPoints;
56  points_ = points;
57  vertices_ = vertices;
58  normals_ = normals;
59 
60  allocateArrays();
61 
62  return true;
63 }
64 
66 (
67  csPairContainerType &pairs,
68  const cells& searchBox,
69  const mapperNBS::CellIterator &particleMap,
70  const deviceViewType1D<realx3>& pPoints,
71  const deviceViewType1D<real>& pDiams,
72  real sizeRatio
73 )
74 {
75 
76  // map walls onto the cells
77 
78  this->build(searchBox);
79 
80  this->particleWallFindPairs(pairs, particleMap, pPoints, pDiams, sizeRatio);
81 
82  return true;
83 }
84 
85 bool pFlow::cellsWallLevel0::build(const cells & searchBox)
86 {
87 
88  const auto& points = points_;
89  const auto& vertices = vertices_;
90  const auto& elementBox = elementBox_;
91  const auto cellExtent = cellExtent_;
92 
93  Kokkos::parallel_for(
94  "pFlow::cellsWallLevel0::build",
96  LAMBDA_HD(uint32 i)
97  {
98  auto v = vertices[i];
99  auto p1 = points[v.x()];
100  auto p2 = points[v.y()];
101  auto p3 = points[v.z()];
102 
103  realx3 minP;
104  realx3 maxP;
105 
106  searchBox.extendBox(p1, p2, p3, cellExtent, minP, maxP);
107  elementBox[i] = iBoxType(searchBox.pointIndex(minP), searchBox.pointIndex(maxP));
108  });
109  Kokkos::fence();
110 
111  return true;
112 }
113 
115 (
116  csPairContainerType &pairs,
117  const mapperNBS::CellIterator &particleMap,
118  const deviceViewType1D<realx3>& pPoints,
119  const deviceViewType1D<real>& pDiams,
120  real sizeRatio
121 )
122 {
123 
124  uint32 getFull = 1;
125 
126  while (getFull)
127  {
128 
129  getFull = findPairsElementRangeCount(pairs, particleMap, pPoints, pDiams, sizeRatio);
130 
131  if(getFull)
132  {
133  // - resize the container
134  // note that getFull now shows the number of failed insertions.
135  uint32 len = max(getFull, 50u);
136  auto oldCap = pairs.capacity();
137  pairs.increaseCapacityBy(len);
138 
139  INFORMATION<<"Contact pair container capacity increased from "<<
140  oldCap << " to "
141  << pairs.capacity() <<" in cellsWallLevel0."<<END_INFO;
142 
143  Kokkos::fence();
144  }
145  }
146 
147  return true;
148 }
149 
151 (
152  csPairContainerType &pairs,
153  const mapperNBS::CellIterator &particleMap,
154  const deviceViewType1D<realx3>& pPoints,
155  const deviceViewType1D<real>& pDiams,
156  real sizeRatio
157 )
158 {
159  uint32 getFull =0;
160 
161  const auto& elementBox = elementBox_;
162  const auto& normals = normals_;
163  const auto& points = points_;
164  const auto& vertices = vertices_;
165  const auto cellExtent = cellExtent_;
166 
167  Kokkos::parallel_reduce(
168  "pFlow::cellsWallLevel0::findPairsElementRangeCount",
169  tpPWContactSearch(numElements_, Kokkos::AUTO),
170  LAMBDA_HD(
171  const typename tpPWContactSearch::member_type & teamMember,
172  uint32& valueToUpdate){
173 
174  const uint32 iTri = teamMember.league_rank();
175 
176  const auto triBox = elementBox[iTri];
177  const auto triPlane = infinitePlane(
178  normals[iTri],
179  points[vertices[iTri].x()]);
180 
181  uint32 getFull2 = 0;
182 
183  auto bExtent = boxExtent(triBox);
184  uint32 numCellBox = bExtent.x()*bExtent.y()*bExtent.z();
185 
186  Kokkos::parallel_reduce(
187  Kokkos::TeamThreadRange( teamMember, numCellBox ),
188  [&] ( const uint32 linIndex, uint32 &innerUpdate )
189  {
190 
191  int32x3 cell;
192  indexToCell(linIndex, triBox, cell);
193 
194  uint32 n = particleMap.start(cell.x(),cell.y(),cell.z());
195 
196  while( n != particleMap.NoPos)
197  {
198  // id is wall id the pair is (particle id, wall id)
199  if( abs(triPlane.pointFromPlane(pPoints[n]))< pDiams[n]*sizeRatio*cellExtent)
200  {
201  if( pairs.insert(
202  static_cast<csIdType>(n),
203  static_cast<csIdType>(iTri) ) == static_cast<csIdType>(-1)
204  )
205  innerUpdate++;
206  }
207  n = particleMap.next(n);
208 
209  }
210 
211  },
212  getFull2
213  );
214 
215  if ( teamMember.team_rank() == 0 ) valueToUpdate += getFull2;
216  },
217  getFull
218  );
219  return getFull;
220 }
pFlow::mapperNBS::CellIterator::next
INLINE_FUNCTION_HD uint32 next(uint32 n) const
Definition: mapperNBS.hpp:76
pFlow::cellsWallLevel0::cellsWallLevel0
INLINE_FUNCTION_HD cellsWallLevel0()
Definition: cellsWallLevel0.hpp:86
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::cellsWallLevel0::cellExtent_
real cellExtent_
Definition: cellsWallLevel0.hpp:49
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::csIdType
uint32 csIdType
Definition: contactSearchGlobals.hpp:32
pFlow::cellsWallLevel0::elementBox_
ViewType1D< iBoxType, memory_space > elementBox_
Definition: cellsWallLevel0.hpp:67
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::indexToCell
INLINE_FUNCTION_HD void indexToCell(const indexType idx, const triple< cellIndexType > &extent, triple< cellIndexType > &cell)
Definition: contactSearchFunctions.hpp:71
pFlow::infinitePlane
Definition: infinitePlane.hpp:32
pFlow::cellsWallLevel0::numElements_
uint32 numElements_
Definition: cellsWallLevel0.hpp:52
pFlow::unsortedPairs::insert
INLINE_FUNCTION_HD uint32 insert(idType i, idType j) const
Definition: unsortedPairs.hpp:105
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
cellsWallLevel0.hpp
pFlow::mapperNBS::CellIterator
Definition: mapperNBS.hpp:45
pFlow::cellsWallLevel0::iBoxType
iBox< int32 > iBoxType
Definition: cellsWallLevel0.hpp:42
pFlow::cellsWallLevel0::points_
ViewType1D< realx3, memory_space > points_
Definition: cellsWallLevel0.hpp:61
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const realx3 &p1, const realx3 &p2, const realx3 &p3, real extent, realx3 &minP, realx3 &maxP) const
Definition: cells.hpp:178
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::unsortedPairs
Definition: unsortedPairs.hpp:32
pFlow::cellsWallLevel0::tpPWContactSearch
Kokkos::TeamPolicy< execution_space, Kokkos::Schedule< Kokkos::Dynamic >, Kokkos::IndexType< uint32 > > tpPWContactSearch
Definition: cellsWallLevel0.hpp:73
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::unsortedPairs::increaseCapacityBy
INLINE_FUNCTION_H void increaseCapacityBy(uint32 len)
increase the capacity of the container by at-least len the content will be erased.
Definition: unsortedPairs.hpp:193
pFlow::boxExtent
INLINE_FUNCTION_HD triple< cellIndexType > boxExtent(const iBox< cellIndexType > &box)
Definition: contactSearchFunctions.hpp:82
pFlow::mapperNBS::CellIterator::start
INLINE_FUNCTION_HD uint32 start(int32 i, int32 j, int32 k) const
Definition: mapperNBS.hpp:67
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
streams.hpp
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::cellsWallLevel0::elementBox
INLINE_FUNCTION_HD iBoxType elementBox(uint32 i) const
Definition: cellsWallLevel0.hpp:110
pFlow::cells::pointIndex
INLINE_FUNCTION_HD int32x3 pointIndex(const realx3 &p) const
Definition: cells.hpp:133
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::mapperNBS::CellIterator::NoPos
static constexpr uint32 NoPos
Definition: mapperNBS.hpp:60
pFlow::cellsWallLevel0::findPairsElementRangeCount
int32 findPairsElementRangeCount(csPairContainerType &pairs, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:151
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::cellsWallLevel0::build
bool build(const cells &searchBox)
Definition: cellsWallLevel0.cpp:85
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
pFlow::cells
Definition: cells.hpp:31
pFlow::triple< real >
END_INFO
#define END_INFO
Definition: streams.hpp:37
INFORMATION
#define INFORMATION
Definition: streams.hpp:36
pFlow::cellsWallLevel0::resetElements
bool resetElements(uint32 numElements, uint32 numPoints, const ViewType1D< realx3, memory_space > &points, const ViewType1D< uint32x3, memory_space > &vertices, const ViewType1D< realx3, memory_space > &normals)
Definition: cellsWallLevel0.cpp:45
pFlow::cellsWallLevel0::broadSearch
bool broadSearch(csPairContainerType &pairs, const cells &searchBox, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:66
pFlow::cellsWallLevel0::vertices_
ViewType1D< uint32x3, memory_space > vertices_
Definition: cellsWallLevel0.hpp:58
pFlow::cellsWallLevel0::particleWallFindPairs
bool particleWallFindPairs(csPairContainerType &pairs, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:115