multiGridNBS.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 __multiGridNBS_hpp__
23 #define __multiGridNBS_hpp__
24 
25 #include "NBSLevels.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 template<typename executionSpace>
33 {
34 public:
35 
37 
39 
40  using IdType = typename NBSLevelsType::IdType;
41 
43 
44  using Cells = typename NBSLevelsType::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("multiGridNBS");
84 
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.getVal<real>("sizeRatio"),
96  1.0
97  )),
99  max(
100  dict.getVal<int32>("updateFrequency"),
101  1
102  )),
103  NBSLevels_(
104  domain,
105  minSize,
106  maxSize,
107  sizeRatio_,
108  position,
109  diam)
110  {}
111 
113  multiGridNBS(const multiGridNBS&) = default;
114 
116  multiGridNBS& operator = (const multiGridNBS&) = default;
117 
119  ~multiGridNBS()=default;
120 
122 
123  bool enterBoadSearch()const
124  {
125  return currentIter_%updateFrequency_==0;
126  }
127 
128  bool performedSearch()const
129  {
130  return performedSearch_;
131  }
132 
134  {
135  return NBSLevels_.numLevels();
136  }
137 
138  auto getCellsLevels()const
139  {
140  Vector<Cells> cellsLvl("cells", numLevels(), numLevels(), RESERVE());
141 
142  for(int32 lvl=0; lvl<numLevels(); lvl++)
143  {
144  cellsLvl[lvl] = NBSLevels_.getCells(lvl) ;
145  }
146 
147  return cellsLvl;
148  }
149 
150  auto getCells(int32 lvl)const
151  {
152  return NBSLevels_.getCells(lvl);
153  }
154 
155  auto getCellIterator(int32 lvl)const
156  {
157  return NBSLevels_.getCellIterator(lvl);
158  }
159 
160  bool objectSizeChanged(int32 newSize)
161  {
162  NBSLevels_.checkAllocateNext(newSize);
163  return true;
164  }
165 
166  // - Perform the broad search to find pairs
167  // with force = true, perform broad search regardless of
168  // updateFrequency_ value
169  // on all the points in the range of [0,numPoints_)
170  template<typename PairsContainer>
171  bool broadSearch(PairsContainer& pairs, range activeRange, bool force=false)
172  {
173 
174  if(force) currentIter_ = 0;
175  performedSearch_ = false;
176 
177  if( !performSearch() ) return true;
178 
179 
180  NBSLevels_.build(activeRange);
181 
182  NBSLevels_.findPairs(pairs);
183 
184 
185  performedSearch_ = true;
186  return true;
187  }
188 
189  // - Perform the broad search to find pairs,
190  // ignore particles with incld(i) = true,
191  // with force = true, perform broad search regardless of
192  // updateFrequency_ value
193  template<typename PairsContainer, typename IncludeFunction>
194  bool broadSearch(PairsContainer& pairs, range activeRange, IncludeFunction incld, bool force = false)
195  {
196  if(force) currentIter_ = 0;
197  performedSearch_ = false;
198 
199  if( !performSearch() ) return true;
200 
201  NBSLevels_.build(activeRange, incld);
202 
203  NBSLevels_.findPairs(pairs);
204 
205  performedSearch_ = true;
206  return true;
207  }
208 
209 };
210 
211 }
212 
213 #endif
pFlow::NBSLevels::execution_space
typename NBSLevelType::execution_space execution_space
Definition: NBSLevels.hpp:29
pFlow::NBSLevels::IndexType
typename NBSLevelType::IndexType IndexType
Definition: NBSLevels.hpp:23
pFlow::multiGridNBS::Cells
typename NBSLevelsType::Cells Cells
Definition: multiGridNBS.hpp:44
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevels
Definition: NBSLevels.hpp:12
pFlow::multiGridNBS::objectSizeChanged
bool objectSizeChanged(int32 newSize)
Definition: multiGridNBS.hpp:160
pFlow::multiGridNBS::TypeInfoNV
TypeInfoNV("multiGridNBS")
pFlow::multiGridNBS::performSearch
bool performSearch()
Definition: multiGridNBS.hpp:67
pFlow::multiGridNBS::sizeRatio_
real sizeRatio_
Definition: multiGridNBS.hpp:55
pFlow::multiGridNBS::memory_space
typename NBSLevelsType::memory_space memory_space
Definition: multiGridNBS.hpp:50
pFlow::multiGridNBS::~multiGridNBS
INLINE_FUNCTION_HD ~multiGridNBS()=default
pFlow::multiGridNBS
Definition: multiGridNBS.hpp:32
pFlow::multiGridNBS::currentIter_
int32 currentIter_
Definition: multiGridNBS.hpp:59
pFlow::multiGridNBS::IdType
typename NBSLevelsType::IdType IdType
Definition: multiGridNBS.hpp:40
pFlow::multiGridNBS::NBSLevels_
NBSLevelsType NBSLevels_
Definition: multiGridNBS.hpp:63
pFlow::multiGridNBS::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: multiGridNBS.hpp:155
pFlow::multiGridNBS::multiGridNBS
multiGridNBS(const dictionary &dict, const box &domain, real minSize, real maxSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: multiGridNBS.hpp:85
pFlow
Definition: demComponent.hpp:28
NBSLevels.hpp
RESERVE
Definition: Vector.hpp:38
pFlow::NBSLevels::cellIterator
typename NBSLevelType::cellIterator cellIterator
Definition: NBSLevels.hpp:19
pFlow::NBSLevels::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: NBSLevels.hpp:276
pFlow::multiGridNBS::execution_space
typename NBSLevelsType::execution_space execution_space
Definition: multiGridNBS.hpp:48
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::multiGridNBS::cellIterator
typename NBSLevelsType::cellIterator cellIterator
Definition: multiGridNBS.hpp:38
pFlow::NBSLevels::memory_space
typename NBSLevelType::memory_space memory_space
Definition: NBSLevels.hpp:31
pFlow::multiGridNBS::CellType
typename Cells::CellType CellType
Definition: multiGridNBS.hpp:46
pFlow::multiGridNBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld, bool force=false)
Definition: multiGridNBS.hpp:194
pFlow::NBSLevels::numLevels
int32 numLevels() const
Definition: NBSLevels.hpp:205
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::multiGridNBS::IndexType
typename NBSLevelsType::IndexType IndexType
Definition: multiGridNBS.hpp:42
pFlow::multiGridNBS::performedSearch_
bool performedSearch_
Definition: multiGridNBS.hpp:61
pFlow::NBSLevels::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevels.hpp:217
pFlow::NBSLevels::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: NBSLevels.hpp:200
pFlow::multiGridNBS::numLevels
int32 numLevels() const
Definition: multiGridNBS.hpp:133
pFlow::box
Definition: box.hpp:32
pFlow::multiGridNBS::updateFrequency_
int32 updateFrequency_
Definition: multiGridNBS.hpp:57
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::multiGridNBS::getCells
auto getCells(int32 lvl) const
Definition: multiGridNBS.hpp:150
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::multiGridNBS::operator=
INLINE_FUNCTION_HD multiGridNBS & operator=(const multiGridNBS &)=default
pFlow::Vector
Definition: Vector.hpp:46
pFlow::multiGridNBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, bool force=false)
Definition: multiGridNBS.hpp:171
pFlow::NBSLevels::IdType
typename NBSLevelType::IdType IdType
Definition: NBSLevels.hpp:21
pFlow::NBSLevels::getCells
Cells getCells(int32 lvl) const
Definition: NBSLevels.hpp:210
pFlow::multiGridNBS::performedSearch
bool performedSearch() const
Definition: multiGridNBS.hpp:128
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::NBSLevels::Cells
typename NBSLevelType::Cells Cells
Definition: NBSLevels.hpp:25
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::multiGridNBS::enterBoadSearch
bool enterBoadSearch() const
Definition: multiGridNBS.hpp:123
pFlow::multiGridNBS::getCellsLevels
auto getCellsLevels() const
Definition: multiGridNBS.hpp:138