www.cemf.ir
pointFlag.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 #ifndef __pointFlag_hpp__
21 #define __pointFlag_hpp__
22 
23 #include "phasicFlowKokkos.hpp"
24 #include "domain.hpp"
25 #include "scatteredFieldAccess.hpp"
26 #include "globalSettings.hpp"
27 
28 namespace pFlow
29 {
30 
31 template<typename ExecutionSpace>
32 class pointFlag
33 {
34  enum Flag: uint8
35  {
36  DELETED = 1, //00000001
37  INTERNAL = 2, //00000010
38  LEFT = 4, //00000100
39  RIGHT = 8, //00001000
40  BOTTOM = 16, //00010000
41  TOP = 32, //00100000
42  REAR = 64, //01000000
43  FRONT = 128 //10000000
44  };
45 
46  using execution_space = ExecutionSpace;
47 
48  using memory_space = typename execution_space::memory_space;
49 
51 
52  using device_type = typename viewType::device_type;
53 
54  using rPolicy = Kokkos::RangePolicy<
56  Kokkos::IndexType<uint32>>;
57 
58 protected:
59 
60  friend class internalPoints;
61 
63 
65 
67 
68  bool isAllActive_ = false;
69 
71 
73 
75 
77 
79 
81 
82  //- Protected methods
83 
85  {
86  uint8 flg;
87  switch (index){
88  case 0u:
89  flg = Flag::LEFT;
90  break;
91  case 1u:
92  flg = Flag::RIGHT;
93  break;
94  case 2u:
95  flg = Flag::BOTTOM;
96  break;
97  case 3u:
98  flg = Flag::TOP;
99  break;
100  case 4u:
101  flg = Flag::REAR;
102  break;
103  case 5u:
104  flg = Flag::FRONT;
105  break;
106  default:
107  flg=0;
108  }
109 
110  return flg;
111  }
112 
113  void resetFlags(uint32 cap, uint32 start, uint32 end)
114  {
115  if(cap != capacity() )
116  {
117  reallocFill(flags_, cap, static_cast<uint8>(Flag::DELETED));
118  }
119  else
120  {
121  fill(flags_, end, cap, static_cast<uint8>(Flag::DELETED));
122  }
123 
124  activeRange_ = {start, end};
126  isAllActive_ = true;
127  fill(flags_, activeRange_, static_cast<uint8>(Flag::INTERNAL));
128 
129  nLeft_ = nRight_ = 0;
130  nBottom_ = nTop_ = 0;
131  nRear_ = nFront_ = 0;
132  }
133 
134 public:
135 
136 
137  pointFlag() = default;
138 
140  :
141  flags_("pointFlag", capacity ),
142  numActive_(end-start),
143  activeRange_(start, end),
144  isAllActive_(true)
145  {
146  fill(flags_, end, capacity, static_cast<uint8>(Flag::DELETED));
147  fill(flags_, activeRange_, static_cast<uint8>(Flag::INTERNAL));
148  }
149 
151  viewType flags,
154  bool isAllActive)
155  :
156  flags_(flags),
160  {}
161 
162  pointFlag(const pointFlag&) = default;
163 
164  pointFlag& operator=(const pointFlag&) = default;
165 
166  pointFlag(pointFlag&&) = default;
167 
168  pointFlag& operator=(pointFlag&&) = default;
169 
170  ~pointFlag() = default;
171 
173  bool isAllActive()const
174  {
175  return isAllActive_;
176  }
177 
179  const auto& activeRange()const
180  {
181  return activeRange_;
182  }
183 
186  {
187  return flags_.extent(0);
188  }
189 
191  auto numActive()const
192  {
193  return numActive_;
194  }
195 
197  auto leftSize()const
198  {
199  return nLeft_;
200  }
201 
203  auto rightSize()const
204  {
205  return nRight_;
206  }
207 
209  auto bottomSize()const
210  {
211  return nBottom_;
212  }
213 
215  auto topSize()const
216  {
217  return nTop_;
218  }
219 
221  auto rearSize()const
222  {
223  return nRear_;
224  }
225 
227  auto frontSize()const
228  {
229  return nFront_;
230  }
231 
232 
234  bool operator()(uint32 i)const
235  {
236  return isActive(i);
237  }
238 
240  bool isActive(uint32 i)const
241  {
242  return flags_[i] > DELETED;
243  }
244 
245 
247  bool isBoundary(uint8 flg)const
248  {
249  return flg > INTERNAL;
250  }
251 
252 
254  bool isLeft(uint8 flg)const
255  {
256  return flg&LEFT;
257  }
258 
260  bool isRight(uint8 flg)const
261  {
262  return flg&RIGHT;
263  }
264 
265 
267  bool isBottom(uint8 flg)const
268  {
269  return flg&BOTTOM;
270  }
271 
273  bool isTop(uint8 flg)const
274  {
275  return flg&TOP;
276  }
277 
279  bool isRear(uint8 flg)const
280  {
281  return flg&REAR;
282  }
283 
285  bool isFront(uint8 flg)const
286  {
287  return flg&FRONT;
288  }
289 
290  template<typename ExeSpace>
292  {
294  newViewType newFlags(
295  "pointFlag",
296  flags_.size());
297 
298  copy(newFlags, flags_);
299 
300  return pointFlag<ExeSpace>(
301  newFlags,
302  numActive_,
303  activeRange_,
304  isAllActive_);
305  }
306 
308 
309 
311 
312 
319  const box& validBox,
321 
323  const ViewType1D<uint32, memory_space>& points);
324 
325  bool deletePoints(
327 
328  bool deletePoints(
330 
331  bool changeFlags(
332  ViewType1D<uint32, memory_space> changePoints,
333  uint32 boundaryIndex);
334 
348  domain dm,
350  real leftLength,
351  real rightLength,
352  real bottomLength,
353  real topLength,
354  real rearLength,
355  real frontLength);
356 
357 
367  void fillNeighborsLists(
374 
376  const plane& pln,
380 
381  uint32 changeCapacity( uint32 reqEmptySpots );
382 
383 
384 
385 };
386 
388 
390 
391 }
392 
393 #include "pointFlagKernels.hpp"
394 
395 #endif // __pointFlag_hpp__
pFlow::pointFlag::isRight
INLINE_FUNCTION_HD bool isRight(uint8 flg) const
Definition: pointFlag.hpp:260
pFlow::pointFlag::isBottom
INLINE_FUNCTION_HD bool isBottom(uint8 flg) const
Definition: pointFlag.hpp:267
pFlow::pointFlag::REAR
@ REAR
Definition: pointFlag.hpp:42
pointFlagKernels.hpp
pFlow::pointFlag::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: pointFlag.hpp:185
pFlow::reallocFill
INLINE_FUNCTION_H void reallocFill(ViewType1D< Type, Properties... > &view, uint32 len, Type val)
Definition: KokkosUtilities.hpp:71
pFlow::pointFlag::~pointFlag
~pointFlag()=default
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::pointFlag::pointFlag
pointFlag()=default
pFlow::pointFlag::isAllActive_
bool isAllActive_
Definition: pointFlag.hpp:68
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::real
float real
Definition: builtinTypes.hpp:45
domain.hpp
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
pFlow::plane
Definition: plane.hpp:30
pFlow::pointFlag::isBoundary
INLINE_FUNCTION_HD bool isBoundary(uint8 flg) const
Definition: pointFlag.hpp:247
pFlow::pointFlag::isFront
INLINE_FUNCTION_HD bool isFront(uint8 flg) const
Definition: pointFlag.hpp:285
pFlow::pointFlag::activeRange_
rangeU32 activeRange_
Definition: pointFlag.hpp:66
pFlow::pointFlag::isLeft
INLINE_FUNCTION_HD bool isLeft(uint8 flg) const
Definition: pointFlag.hpp:254
pFlow::pointFlag::TOP
@ TOP
Definition: pointFlag.hpp:41
pFlow::pointFlag::changeFlags
bool changeFlags(ViewType1D< uint32, memory_space > changePoints, uint32 boundaryIndex)
Definition: pointFlagKernels.hpp:308
pFlow::pointFlag::getActivePoints
ViewType1D< uint32, memory_space > getActivePoints()
Definition: pointFlagKernels.hpp:25
pFlow::pointFlag::markOutOfBoxDelete
uint32 markOutOfBoxDelete(const box &validBox, ViewType1D< realx3, memory_space > points)
Loop over the active points and mark those out of the box and return number of deleted points.
Definition: pointFlagKernels.hpp:102
pFlow::copy
INLINE_FUNCTION_H void copy(const ViewType1D< dType, dProperties... > &dst, const ViewType1D< sType, sProperties... > &src)
Definition: ViewAlgorithms.hpp:234
pFlow::pointFlag::LEFT
@ LEFT
Definition: pointFlag.hpp:38
pFlow::pointFlag::frontSize
INLINE_FUNCTION_HD auto frontSize() const
Definition: pointFlag.hpp:227
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::pointFlag< DefaultHostExecutionSpace >::execution_space
DefaultHostExecutionSpace execution_space
Definition: pointFlag.hpp:46
pFlow::pointFlag::numActive
INLINE_FUNCTION_HD auto numActive() const
Definition: pointFlag.hpp:191
pFlow::pointFlag::DELETED
@ DELETED
Definition: pointFlag.hpp:36
pFlow::pointFlag::FRONT
@ FRONT
Definition: pointFlag.hpp:43
pFlow::pointFlag::flags_
viewType flags_
Definition: pointFlag.hpp:62
pFlow::pointFlag::nFront_
uint32 nFront_
Definition: pointFlag.hpp:80
pFlow::pointFlag::rightSize
INLINE_FUNCTION_HD auto rightSize() const
Definition: pointFlag.hpp:203
pFlow::pointFlag::nLeft_
uint32 nLeft_
Definition: pointFlag.hpp:70
pFlow::pointFlag::clone
pointFlag< ExeSpace > clone() const
Definition: pointFlag.hpp:291
pFlow::pointFlag::pointFlag
pointFlag(viewType flags, uint32 numActive, rangeU32 activeRange, bool isAllActive)
Definition: pointFlag.hpp:150
pFlow
Definition: demGeometry.hpp:27
pFlow::pointFlag< DefaultHostExecutionSpace >::viewType
ViewType1D< uint8, memory_space > viewType
Definition: pointFlag.hpp:50
pFlow::pointFlag< DefaultHostExecutionSpace >::memory_space
typename execution_space::memory_space memory_space
Definition: pointFlag.hpp:48
pFlow::pointFlag< DefaultHostExecutionSpace >::rPolicy
Kokkos::RangePolicy< execution_space, Kokkos::IndexType< uint32 > > rPolicy
Definition: pointFlag.hpp:56
pFlow::pointFlag::isActive
INLINE_FUNCTION_HD bool isActive(uint32 i) const
Definition: pointFlag.hpp:240
pFlow::pointFlag::markDelete
uint32 markDelete(const plane &pln, ViewType1D< realx3, memory_space > points, ViewType1D< uint32, memory_space > indices, ViewType1D< uint32, memory_space > onOff)
Definition: pointFlagKernels.hpp:510
phasicFlowKokkos.hpp
globalSettings.hpp
pFlow::pointFlag::markPointRegions
uint32 markPointRegions(domain dm, ViewType1D< realx3, memory_space > points, real leftLength, real rightLength, real bottomLength, real topLength, real rearLength, real frontLength)
mark points based on their position in the domain.
Definition: pointFlagKernels.hpp:330
pFlow::pointFlag::nTop_
uint32 nTop_
Definition: pointFlag.hpp:76
pFlow::pointFlag::addInternalPoints
uint32 addInternalPoints(const ViewType1D< uint32, memory_space > &points)
Definition: pointFlagKernels.hpp:174
pFlow::Range::numElements
INLINE_FUNCTION_HD T numElements()
Definition: Range.hpp:119
pFlow::pointFlag::Flag
Flag
Definition: pointFlag.hpp:34
pFlow::pointFlag::nRear_
uint32 nRear_
Definition: pointFlag.hpp:78
pFlow::pointFlag::RIGHT
@ RIGHT
Definition: pointFlag.hpp:39
pFlow::pointFlag::isAllActive
INLINE_FUNCTION_HD bool isAllActive() const
Definition: pointFlag.hpp:173
pFlow::pointFlag::fillNeighborsLists
void fillNeighborsLists(ViewType1D< uint32, memory_space > leftList, ViewType1D< uint32, memory_space > rightList, ViewType1D< uint32, memory_space > bottomList, ViewType1D< uint32, memory_space > topList, ViewType1D< uint32, memory_space > rearList, ViewType1D< uint32, memory_space > frontList)
fill the lists for boundary faces.
Definition: pointFlagKernels.hpp:467
pFlow::pointFlag::nRight_
uint32 nRight_
Definition: pointFlag.hpp:72
pFlow::pointFlag::isRear
INLINE_FUNCTION_HD bool isRear(uint8 flg) const
Definition: pointFlag.hpp:279
pFlow::pointFlag::isTop
INLINE_FUNCTION_HD bool isTop(uint8 flg) const
Definition: pointFlag.hpp:273
pFlow::pointFlag::operator=
pointFlag & operator=(const pointFlag &)=default
pFlow::pointFlag::nBottom_
uint32 nBottom_
Definition: pointFlag.hpp:74
pFlow::pointFlag::getBoundaryFlag
uint8 getBoundaryFlag(uint32 index) const
Definition: pointFlag.hpp:84
pFlow::pointFlag::activeRange
const INLINE_FUNCTION_HD auto & activeRange() const
Definition: pointFlag.hpp:179
pFlow::pointFlag::topSize
INLINE_FUNCTION_HD auto topSize() const
Definition: pointFlag.hpp:215
pFlow::pointFlag::numActive_
uint32 numActive_
Definition: pointFlag.hpp:64
pFlow::pointFlag::operator()
INLINE_FUNCTION_HD bool operator()(uint32 i) const
Definition: pointFlag.hpp:234
pFlow::Range< uint32 >
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::pointFlag::resetFlags
void resetFlags(uint32 cap, uint32 start, uint32 end)
Definition: pointFlag.hpp:113
pFlow::pointFlag::BOTTOM
@ BOTTOM
Definition: pointFlag.hpp:40
pFlow::box
Definition: box.hpp:32
pFlow::pointFlag::getEmptyPoints
ViewType1D< uint32, memory_space > getEmptyPoints(uint32 numToGet) const
Definition: pointFlagKernels.hpp:55
pFlow::pointFlag::changeCapacity
uint32 changeCapacity(uint32 reqEmptySpots)
Definition: pointFlagKernels.hpp:582
pFlow::pointFlag::bottomSize
INLINE_FUNCTION_HD auto bottomSize() const
Definition: pointFlag.hpp:209
pFlow::domain
Definition: domain.hpp:31
pFlow::pointFlag::rearSize
INLINE_FUNCTION_HD auto rearSize() const
Definition: pointFlag.hpp:221
pFlow::pointFlag< DefaultHostExecutionSpace >::device_type
typename viewType::device_type device_type
Definition: pointFlag.hpp:52
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
scatteredFieldAccess.hpp
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::pointFlag::pointFlag
pointFlag(uint32 capacity, uint32 start, uint32 end)
Definition: pointFlag.hpp:139
pFlow::pointFlag::deletePoints
bool deletePoints(scatteredFieldAccess< uint32, memory_space > points)
Definition: pointFlagKernels.hpp:221
pFlow::pointFlag::leftSize
INLINE_FUNCTION_HD auto leftSize() const
Definition: pointFlag.hpp:197
pFlow::pointFlag
Definition: pointFlag.hpp:32
pFlow::pointFlag::INTERNAL
@ INTERNAL
Definition: pointFlag.hpp:37