NBS.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 __NBS_hpp__
23 #define __NBS_hpp__
24 
25 #include "NBSLevel0.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 template<typename executionSpace>
32 class NBS
33 {
34 public:
35 
37 
39 
40  using IdType = typename NBSLevel0Type::IdType;
41 
43 
44  using Cells = typename NBSLevel0Type::Cells;
45 
46  using CellType = typename Cells::CellType;
47 
49 
51 
52 
53 protected:
54 
56 
58 
60 
61  bool performedSearch_ = false;
62 
64 
65 private:
66 
68  {
70  {
71  currentIter_++;
72  return true;
73 
74  }else
75  {
76  currentIter_++;
77  return false;
78  }
79  }
80 
81 public:
82 
83  TypeInfoNV("NBS");
84 
85  NBS(
86  const dictionary& dict,
87  const box& domain,
88  real minSize,
89  real maxSize,
90  const ViewType1D<realx3, memory_space>& position,
92  :
93  sizeRatio_(
94  max(
95  dict.getValOrSet<real>("sizeRatio", 1.0),
96  1.0
97  )),
99  max(
100  dict.getValOrSet<int32>("updateFrequency", 1),
101  1
102  )),
103  NBSLevel0_(
104  domain,
105  maxSize*sizeRatio_,
106  sizeRatio_,
107  position,
108  diam)
109  {}
110 
112  NBS(const NBS&) = default;
113 
115  NBS& operator = (const NBS&) = default;
116 
118  ~NBS()=default;
119 
121 
122  bool enterBoadSearch()const
123  {
124  return currentIter_%updateFrequency_==0;
125  }
126 
127  bool performedSearch()const
128  {
129  return performedSearch_;
130  }
131 
133  {
134  return Vector<cellIterator>("cellIterator", 1, NBSLevel0_.getCellIterator());
135  }
136 
137  auto getCellIterator(int32 lvl)const
138  {
139  return NBSLevel0_.getCellIterator();
140  }
141 
143  {
144  return 1;
145  }
146 
148  {
149  return Vector<Cells>("Cells", 1, NBSLevel0_.getCells());
150  }
151 
152  auto getCells()const
153  {
154  return NBSLevel0_.getCells();
155  }
156 
157  bool objectSizeChanged(int32 newSize)
158  {
159  NBSLevel0_.checkAllocateNext(newSize);
160  return true;
161  }
162 
163  // - Perform the broad search to find pairs
164  // with force = true, perform broad search regardless of
165  // updateFrequency_ value
166  // on all the points in the range of [0,numPoints_)
167  template<typename PairsContainer>
168  bool broadSearch(PairsContainer& pairs, range activeRange, bool force=false)
169  {
170 
171  if(force) currentIter_ = 0;
172  performedSearch_ = false;
173 
174  if( !performSearch() ) return true;
175 
176 
177  NBSLevel0_.build(activeRange);
178 
179  NBSLevel0_.findPairs(pairs);
180 
181  performedSearch_ = true;
182  return true;
183  }
184 
185  // - Perform the broad search to find pairs,
186  // ignore particles with incld(i) = true,
187  // with force = true, perform broad search regardless of
188  // updateFrequency_ value
189  template<typename PairsContainer, typename IncludeFunction>
190  bool broadSearch(PairsContainer& pairs, range activeRange, IncludeFunction incld, bool force = false)
191  {
192  if(force) currentIter_ = 0;
193  performedSearch_ = false;
194 
195  if( !performSearch() ) return true;
196 
197  NBSLevel0_.build(activeRange, incld);
198 
199  NBSLevel0_.findPairs(pairs);
200 
201  performedSearch_ = true;
202  return true;
203  }
204 
205 };
206 
207 }
208 
209 #endif
pFlow::NBS::sizeRatio_
real sizeRatio_
Definition: NBS.hpp:55
pFlow::NBS::objectSizeChanged
bool objectSizeChanged(int32 newSize)
Definition: NBS.hpp:157
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevel0
Definition: NBSLevel0.hpp:32
pFlow::NBS::getCellsLevels
Vector< Cells > getCellsLevels() const
Definition: NBS.hpp:147
pFlow::NBS::getCells
auto getCells() const
Definition: NBS.hpp:152
pFlow::NBS::updateFrequency_
int32 updateFrequency_
Definition: NBS.hpp:57
pFlow::NBS::NBS
NBS(const dictionary &dict, const box &domain, real minSize, real maxSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBS.hpp:85
pFlow::NBS::~NBS
INLINE_FUNCTION_HD ~NBS()=default
NBSLevel0.hpp
pFlow::NBS::CellType
typename Cells::CellType CellType
Definition: NBS.hpp:46
pFlow::NBS::execution_space
typename NBSLevel0Type::execution_space execution_space
Definition: NBS.hpp:48
pFlow::NBS::NBSLevel0_
NBSLevel0Type NBSLevel0_
Definition: NBS.hpp:63
pFlow::NBS::TypeInfoNV
TypeInfoNV("NBS")
pFlow::NBS::performedSearch_
bool performedSearch_
Definition: NBS.hpp:61
pFlow::NBSLevel0::cellIterator
typename MapperType::cellIterator cellIterator
Definition: NBSLevel0.hpp:40
pFlow::NBS::operator=
INLINE_FUNCTION_HD NBS & operator=(const NBS &)=default
pFlow::NBS::numLevels
int32 numLevels() const
Definition: NBS.hpp:142
pFlow::NBS::memory_space
typename NBSLevel0Type::memory_space memory_space
Definition: NBS.hpp:50
pFlow::NBS::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: NBS.hpp:137
pFlow
Definition: demComponent.hpp:28
pFlow::NBS::getCellIteratorLevels
Vector< cellIterator > getCellIteratorLevels()
Definition: NBS.hpp:132
pFlow::NBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, bool force=false)
Definition: NBS.hpp:168
pFlow::NBS::IndexType
typename NBSLevel0Type::IndexType IndexType
Definition: NBS.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::NBS::performSearch
bool performSearch()
Definition: NBS.hpp:67
pFlow::NBS::enterBoadSearch
bool enterBoadSearch() const
Definition: NBS.hpp:122
pFlow::mapperNBS::checkAllocateNext
void checkAllocateNext(int newCap)
Definition: mapperNBS.hpp:141
pFlow::NBSLevel0::memory_space
typename MapperType::memory_space memory_space
Definition: NBSLevel0.hpp:52
pFlow::NBSLevel0::execution_space
typename MapperType::execution_space execution_space
Definition: NBSLevel0.hpp:50
pFlow::NBS
Definition: NBS.hpp:32
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::box
Definition: box.hpp:32
pFlow::NBSLevel0::IndexType
typename MapperType::IndexType IndexType
Definition: NBSLevel0.hpp:44
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::NBSLevel0::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevel0.hpp:180
pFlow::NBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld, bool force=false)
Definition: NBS.hpp:190
pFlow::NBSLevel0::Cells
typename MapperType::Cells Cells
Definition: NBSLevel0.hpp:46
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::Vector
Definition: Vector.hpp:46
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: mapperNBS.hpp:274
pFlow::NBS::Cells
typename NBSLevel0Type::Cells Cells
Definition: NBS.hpp:44
pFlow::NBS::currentIter_
int32 currentIter_
Definition: NBS.hpp:59
pFlow::NBS::IdType
typename NBSLevel0Type::IdType IdType
Definition: NBS.hpp:40
pFlow::NBSLevel0::IdType
typename MapperType::IdType IdType
Definition: NBSLevel0.hpp:42
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::mapperNBS::getCellIterator
cellIterator getCellIterator() const
Definition: mapperNBS.hpp:219
pFlow::NBS::cellIterator
typename NBSLevel0Type::cellIterator cellIterator
Definition: NBS.hpp:38
pFlow::NBS::performedSearch
bool performedSearch() const
Definition: NBS.hpp:127
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::cells::getCells
cells getCells() const
Definition: cells.hpp:95