NBSLevel0.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 
22 #ifndef __NBSLevel0_hpp__
23 #define __NBSLevel0_hpp__
24 
25 #include "mapperNBS.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 template<typename executionSpace>
32 class NBSLevel0
33 :
34  public mapperNBS<executionSpace>
35 {
36 public:
37 
39 
41 
42  using IdType = typename MapperType::IdType;
43 
44  using IndexType = typename MapperType::IndexType;
45 
46  using Cells = typename MapperType::Cells;
47 
48  using CellType = typename Cells::CellType;
49 
51 
53 
54  using HeadType = typename MapperType::HeadType;
55 
56  using NextType = typename MapperType::NextType;
57 
58  struct TagFindPairs{};
59 
60 
61 protected:
62 
64 
65  // borrowed ownership
67 
68 
69  using mdrPolicyFindPairs =
70  Kokkos::MDRangePolicy<
71  Kokkos::Rank<3>,
72  Kokkos::Schedule<Kokkos::Dynamic>,
74 
75  static INLINE_FUNCTION_HD
76  void Swap(int32& x, int32& y)
77  {
78  int32 tmp = x;
79  x = y;
80  y = tmp;
81  }
82 
83 public:
84 
85  TypeInfoNV("NBSLevel0");
86 
89 
91  const box& domain,
92  real cellSize,
93  const ViewType1D<realx3, memory_space>& position,
95  :
96  MapperType(domain, cellSize, position),
97  diameter_(diam)
98  {}
99 
101  const box& domain,
102  int32 nx,
103  int32 ny,
104  int32 nz,
105  const ViewType1D<realx3, memory_space>& position,
106  const ViewType1D<real, memory_space>& diam)
107  :
108  MapperType(domain, nx, ny, nz, position),
109  diameter_(diam)
110  { }
111 
113  const box& domain,
114  real cellSize,
115  real sizeRatio,
116  const ViewType1D<realx3, memory_space>& position,
117  const ViewType1D<real, memory_space>& diam,
118  bool nextOwner = true)
119  :
120  MapperType(domain, cellSize, position, nextOwner),
122  diameter_(diam)
123  {}
124 
126  NBSLevel0(const NBSLevel0&) = default;
127 
129  NBSLevel0& operator = (const NBSLevel0&) = default;
130 
132  ~NBSLevel0()=default;
133 
134 
136  auto sizeRatio()const
137  {
138  return sizeRatio_;
139  }
140 
142  auto& diameter()
143  {
144  return diameter_;
145  }
146 
147  // - Perform the broad search to find pairs
148  // with force = true, perform broad search regardless of
149  // updateFrequency_ value
150  // on all the points in the range of [0,numPoints_)
151  template<typename PairsContainer>
152  bool broadSearch(PairsContainer& pairs, range activeRange)
153  {
154 
155 
156  this->build(activeRange);
157 
158  findPairs(pairs);
159 
160  return true;
161  }
162 
163  // - Perform the broad search to find pairs,
164  // ignore particles with incld(i) = true,
165  // with force = true, perform broad search regardless of
166  // updateFrequency_ value
167  template<typename PairsContainer, typename IncludeFunction>
168  bool broadSearch(PairsContainer& pairs, range activeRange, IncludeFunction incld)
169  {
170 
171  this->build(activeRange, incld);
172 
173  findPairs(pairs);
174 
175  return true;
176  }
177 
178  template<typename PairsContainer>
180  bool findPairs(PairsContainer& pairs)
181  {
182 
183 
184  int32 getFull = 1;
185 
186 
187  // loop until the container size fits the numebr of contact pairs
188  while (getFull > 0)
189  {
190 
191  getFull = findPairsCount(pairs);
192 
193  if(getFull)
194  {
195  // - resize the container
196  // note that getFull now shows the number of failed insertions.
197  uint32 len = max(getFull,500) ;
198 
199  auto oldCap = pairs.capacity();
200 
201  pairs.increaseCapacityBy(len);
202 
203  INFORMATION<< "The contact pair container capacity increased from "<<
204  oldCap << " to "<<pairs.capacity()<<" in NBSLevel0."<<endINFO;
205 
206  }
207 
208  Kokkos::fence();
209  }
210 
211  return true;
212  }
213 
214  template<typename PairsContainer>
216  int32 findPairsCount(PairsContainer& pairs)
217  {
219  mdrPolicy(
220  {0,0,0},
221  {this->nx(),this->ny(),this->nz()} );
222 
223  int32 notInsertedPairs;
224 
225  Kokkos::parallel_reduce (
226  "NBSLevel0::findPairs",
227  mdrPolicy,
228  CLASS_LAMBDA_HD(int32 i, int32 j, int32 k, int32& getFullUpdate){
229  #include "NBSLoop.hpp"
230  }, notInsertedPairs);
231 
232  return notInsertedPairs;
233 
234  }
235 
236 };
237 
238 } // pFlow
239 
240 #endif // __NBSLevel0_hpp__
pFlow::cells< int32 >::nz
INLINE_FUNCTION_HD int32 nz() const
Definition: cells.hpp:139
pFlow::NBSLevel0::~NBSLevel0
INLINE_FUNCTION_HD ~NBSLevel0()=default
mapperNBS.hpp
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevel0
Definition: NBSLevel0.hpp:32
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::NBSLevel0::cellIterator
typename MapperType::cellIterator cellIterator
Definition: NBSLevel0.hpp:40
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, real cellSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBSLevel0.hpp:90
pFlow::cells< int32 >::nx
INLINE_FUNCTION_HD int32 nx() const
Definition: cells.hpp:127
pFlow::NBSLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange)
Definition: NBSLevel0.hpp:152
pFlow::mapperNBS::NextType
ViewType1D< int32, memory_space > NextType
Definition: mapperNBS.hpp:54
pFlow::mapperNBS
Definition: mapperNBS.hpp:34
pFlow
Definition: demComponent.hpp:28
pFlow::NBSLevel0::TypeInfoNV
TypeInfoNV("NBSLevel0")
pFlow::NBSLevel0::TagFindPairs
Definition: NBSLevel0.hpp:58
pFlow::NBSLevel0::sizeRatio
INLINE_FUNCTION_HD auto sizeRatio() const
Definition: NBSLevel0.hpp:136
pFlow::NBSLevel0::operator=
INLINE_FUNCTION_HD NBSLevel0 & operator=(const NBSLevel0 &)=default
pFlow::mapperNBS::IdType
int32 IdType
Definition: mapperNBS.hpp:40
CLASS_LAMBDA_HD
#define CLASS_LAMBDA_HD
Definition: pFlowMacros.hpp:56
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cells< int32 >::domain
const auto & domain() const
Definition: cells.hpp:152
pFlow::mapperNBS::IndexType
int32 IndexType
Definition: mapperNBS.hpp:42
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, real cellSize, real sizeRatio, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam, bool nextOwner=true)
Definition: NBSLevel0.hpp:112
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::NBSLevel0::sizeRatio_
real sizeRatio_
Definition: NBSLevel0.hpp:63
pFlow::mapperNBS::CellType
typename Cells::CellType CellType
Definition: mapperNBS.hpp:46
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::mapperNBS::HeadType
ViewType3D< int32, memory_space > HeadType
Definition: mapperNBS.hpp:52
pFlow::mapperNBS::execution_space
executionSpace execution_space
Definition: mapperNBS.hpp:48
pFlow::mapperNBS::cellIterator
Definition: mapperNBS.hpp:56
pFlow::box
Definition: box.hpp:32
pFlow::mapperNBS::Cells
cells< IndexType > Cells
Definition: mapperNBS.hpp:44
pFlow::NBSLevel0::NBSLevel0
INLINE_FUNCTION_HD NBSLevel0()
Definition: NBSLevel0.hpp:88
pFlow::NBSLevel0::findPairsCount
INLINE_FUNCTION_H int32 findPairsCount(PairsContainer &pairs)
Definition: NBSLevel0.hpp:216
pFlow::cells< int32 >::ny
INLINE_FUNCTION_HD int32 ny() const
Definition: cells.hpp:133
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::cells< int32 >::cellSize
INLINE_FUNCTION_HD realx3 cellSize() const
Definition: cells.hpp:115
pFlow::NBSLevel0::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevel0.hpp:180
pFlow::NBSLevel0::Swap
static INLINE_FUNCTION_HD void Swap(int32 &x, int32 &y)
Definition: NBSLevel0.hpp:76
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< indexType >
pFlow::NBSLevel0::diameter
INLINE_FUNCTION_HD auto & diameter()
Definition: NBSLevel0.hpp:142
pFlow::mapperNBS::memory_space
typename execution_space::memory_space memory_space
Definition: mapperNBS.hpp:50
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, int32 nx, int32 ny, int32 nz, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBSLevel0.hpp:100
endINFO
#define endINFO
Definition: streams.hpp:38
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: mapperNBS.hpp:274
NBSLoop.hpp
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::NBSLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld)
Definition: NBSLevel0.hpp:168
INFORMATION
#define INFORMATION
Definition: streams.hpp:37
pFlow::NBSLevel0::mdrPolicyFindPairs
Kokkos::MDRangePolicy< Kokkos::Rank< 3 >, Kokkos::Schedule< Kokkos::Dynamic >, execution_space > mdrPolicyFindPairs
Definition: NBSLevel0.hpp:73
pFlow::NBSLevel0::diameter_
ViewType1D< real, memory_space > diameter_
Definition: NBSLevel0.hpp:66