pointStructure.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 __pointStructure_hpp__
23 #define __pointStructure_hpp__
24 
25 
26 
27 #include "Vectors.hpp"
28 #include "VectorSingles.hpp"
29 #include "VectorDuals.hpp"
30 #include "Fields.hpp"
31 #include "eventSubscriber.hpp"
32 #include "indexContainer.hpp"
33 
34 
35 
36 namespace pFlow
37 {
38 
39 //forward
40 class box;
41 class setFieldList;
42 class repository;
43 
45 :
46  public eventSubscriber
47 {
48 public:
49 
51  {
52  DELETED = -1,
53  ACTIVE = 1
54  };
55 
56 
57  inline static const size_t maxSizeDefault_ = 10000;
58 
60  {
61  protected:
63 
64  bool allActive_;
65 
67 
68  public:
69 
72  :
73  flag_(flag),
75  activeRange_(active)
76  {}
77 
79  activePointsDevice(const activePointsDevice&) = default;
80 
83 
85  bool operator()(int32 i)const {
86  if(i<activeRange_.second && flag_[i] == 1)return true;
87  return false;
88  }
89 
91  auto activeRange()const {
92  return activeRange_;
93  }
94 
96  auto allActive()const {
97  return allActive_;
98  }
99 
100  };
101 
103  {
104  protected:
105 
107 
109 
111 
112  public:
113 
116  :
117  flag_(flag),
119  activeRange_(active){}
120 
122  activePointsHost(const activePointsHost&) = default;
123 
125  activePointsHost& operator=(const activePointsHost&) = default;
126 
128  bool operator()(int32 i)const {
129  if(i <activeRange_.second && flag_[i] == PointFlag::ACTIVE)return true;
130  return false;
131  }
132 
134  auto activeRange()const{
135  return activeRange_;
136  }
137 
139  bool allActive()const {
140  return allActive_;
141  }
142  };
143 
144 protected:
145 
147 
148  // number of points / size of structure
149  size_t numPoints_ = 0;
150 
151  // maximum number of points
153 
154  // flag of points on device
156 
157  // position of points on device
159 
160  // number of active points
161  size_t numActivePoints_ = 0;
162 
163  // index range of active points (half-open range)
165 
168 
171 
172 
174  FUNCTION_H
175  bool evaluatePointStructure();
176 
177  FUNCTION_H
178  void setNumMaxPoints();
179 
180  // - access to pointPosition
181  FUNCTION_H
183 
184  // - access to pointFlag
185  FUNCTION_H
187 
188  FUNCTION_H
190  getNewPointsIndices(int32 numNewPoints)const;
191 
192 public:
193 
194  friend class dynamicPointStructure;
195 
196  // - type info
197  TypeInfo("pointStructure");
198 
199 
201 
202  // - an empty pointStructure, good for reading from file
203  pointStructure();
204 
205  // - construct from components
206  pointStructure(const int8Vector& flgVec, const realx3Vector& posVec);
207 
208  // - construct from point positions, assume all points are active
209  pointStructure(const realx3Vector& posVec);
210 
211  // - copy construct
212  //
213  // should be changed, may causs undefined behavior
215  pointStructure(const pointStructure&) = default;
216 
217 
218  // - no move construct
219  pointStructure(pointStructure&&) = delete;
220 
221  // - copy assignment
222  //
223  // should be changed, may causs undefined behavior
225  pointStructure& operator=(const pointStructure&) = default;
226 
227  // - no move assignment
229 
230  // - destructor
231  virtual ~pointStructure() = default;
232 
233 
236  {
237  return activePointsDevice(
238  this->allActive(),
239  activeRange(),
240  pointFlag_.deviceVectorAll()
241  );
242  }
243 
245  {
246  return activePointsHost(
247  this->allActive(),
248  activeRange(),
249  pointFlag_.hostVectorAll()
250  );
251  }
252 
253  // - const access pointPosition
254  FUNCTION_H
255  const realx3Field_D& pointPosition()const;
256 
257  // - const access to pointFlag
258  FUNCTION_H
259  const int8Field_HD& pointFlag()const;
260 
263  {
264  return pointPosition_.hostVectorAll();
265  }
266 
267  // - size of data structure
268  FUNCTION_H
269  label size()const;
270 
271  // - maximum capacity of data structure
272  FUNCTION_H
273  label capacity()const;
274 
275  // - number of active points
276  FUNCTION_H
277  label numActive() const;
278 
279  // - if all points are active
280  FUNCTION_H
281  bool allActive()const;
282 
285  {
286  return activeRange_;
287  }
288 
290  bool isActive(label i)const
291  {
292  return pointFlag_[i] == ACTIVE;
293  }
294 
295  FUNCTION_H
296  size_t markDeleteOutOfBox(const box& domain);
297 
298  // - update data structure by removing the marked points
299  // Notifies all the fields that are built based on this data structure
300  // and then apply removing to the pointPosition_ and pointFlag_
301  FUNCTION_H
302  virtual bool updateForDelete();
303 
304 
305  FUNCTION_H
306  virtual bool mortonSortPoints(const box& domain, real dx);
307 
309 
310  // - const access to points to be newly inserted
311  FUNCTION_H
312  auto insertedPointIndex()const
313  {
314  return tobeInsertedIndex_;
315  }
316 
317  FUNCTION_H
319  {
320  return tobeInsertedIndex_.hostView();
321  }
322 
323  FUNCTION_H
325  {
327  }
328 
329 
330  FUNCTION_H
331  auto mortonSortedIndex()const
332  {
333  return mortonSortedIndex_;
334  }
335 
336 
337  // - update data structure by inserting/setting new points
338  // Notifies all the fields in the registered list of data structure
339  // and exclude the fields that re in the exclusionList
340  // retrun nullptr if it fails
341  FUNCTION_H
343  const realx3Vector& pos,
344  const setFieldList& setField,
345  repository& owner,
346  const List<eventObserver*>& exclusionList={nullptr}
347  );
348 
349 
351  // - read pointStructure from is
352  FUNCTION_H
353  bool readPointStructure(iIstream& is);
354 
355  // - write pointStructure to os
356  FUNCTION_H
357  bool writePointStructure(iOstream& os)const;
358 
359  // - read
360  FUNCTION_H
361  bool read(iIstream& is)
362  {
363  return readPointStructure(is);
364  }
365 
366  // - write
367  FUNCTION_H
368  bool write(iOstream& os)const
369  {
370  return writePointStructure(os);
371  }
372 
373 };
374 
375 
376 } // pFlow
377 
378 
379 
380 
381 #endif //__pointStructure_hpp__
pFlow::pointStructure::evaluatePointStructure
FUNCTION_H bool evaluatePointStructure()
Definition: pointStructure.cpp:31
pFlow::pointStructure::activePointsDevice::allActive_
bool allActive_
Definition: pointStructure.hpp:64
pFlow::pointStructure::activePointsHost
Definition: pointStructure.hpp:102
pFlow::List
Definition: List.hpp:39
pFlow::pointStructure::activePointsHost::allActive
INLINE_FUNCTION_H bool allActive() const
Definition: pointStructure.hpp:139
pFlow::pointStructure::numActivePoints_
size_t numActivePoints_
Definition: pointStructure.hpp:161
pFlow::eventSubscriber
Definition: eventSubscriber.hpp:34
pFlow::pointStructure::maxPoints_
size_t maxPoints_
Definition: pointStructure.hpp:152
pFlow::pointStructure::PointFlag
PointFlag
Definition: pointStructure.hpp:50
pFlow::pointStructure::pointPosition_
realx3Field_D pointPosition_
Definition: pointStructure.hpp:158
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::pointStructure::DELETED
@ DELETED
Definition: pointStructure.hpp:52
pFlow::range
kRange< int > range
Definition: KokkosTypes.hpp:59
pFlow::pointStructure::activePointsDevice::allActive
INLINE_FUNCTION_HD auto allActive() const
Definition: pointStructure.hpp:96
pFlow::pointStructure::activePointsDevice::activeRange_
range activeRange_
Definition: pointStructure.hpp:66
pFlow::pointStructure::activePointsDevice::flag_
ViewType1D< int8 > flag_
Definition: pointStructure.hpp:62
pFlow::pointStructure::write
FUNCTION_H bool write(iOstream &os) const
Definition: pointStructure.hpp:368
pFlow::VectorDual::hostVectorAll
INLINE_FUNCTION_H hostViewType & hostVectorAll()
Definition: VectorDual.hpp:345
pFlow::pointStructure::activePointsMaskH
activePointsHost activePointsMaskH() const
Definition: pointStructure.hpp:244
pFlow::VectorSingle::hostVectorAll
const INLINE_FUNCTION_H auto hostVectorAll() const
Definition: VectorSingle.hpp:322
pFlow::pointStructure::insertedPointIndexD
FUNCTION_H auto insertedPointIndexD() const
Definition: pointStructure.hpp:324
pFlow::pointStructure::markDeleteOutOfBox
FUNCTION_H size_t markDeleteOutOfBox(const box &domain)
Definition: pointStructure.cpp:286
pFlow::pointStructure::pointFlag
FUNCTION_H int8Field_HD & pointFlag()
Definition: pointStructure.cpp:71
pFlow::pointStructure::readPointStructure
FUNCTION_H bool readPointStructure(iIstream &is)
Definition: pointStructure.cpp:437
pFlow::pointStructure::activeRange
INLINE_FUNCTION_H range activeRange() const
Definition: pointStructure.hpp:284
pFlow::pointStructure::pointPositionHostAll
INLINE_FUNCTION_H auto pointPositionHostAll()
Definition: pointStructure.hpp:262
pFlow::pointStructure::activePointsHost::activePointsHost
INLINE_FUNCTION_H activePointsHost(bool allActive, range active, const ViewType1D< int8, HostSpace > &flag)
Definition: pointStructure.hpp:115
pFlow::pointStructure::ACTIVE
@ ACTIVE
Definition: pointStructure.hpp:53
pFlow::pointStructure::writePointStructure
FUNCTION_H bool writePointStructure(iOstream &os) const
Definition: pointStructure.cpp:465
Vectors.hpp
pFlow::pointStructure::operator=
pointStructure & operator=(const pointStructure &)=default
pFlow::Field< VectorDual, int8 >
pFlow::pointStructure::mortonSortedIndex
FUNCTION_H auto mortonSortedIndex() const
Definition: pointStructure.hpp:331
pFlow::pointStructure::activePointsHost::allActive_
bool allActive_
Definition: pointStructure.hpp:108
pFlow::pointStructure::maxSizeDefault_
static const size_t maxSizeDefault_
Definition: pointStructure.hpp:57
pFlow::dynamicPointStructure
Definition: dynamicPointStructure.hpp:33
pFlow::pointStructure::insertedPointIndex
FUNCTION_H auto insertedPointIndex() const
Definition: pointStructure.hpp:312
pFlow::pointStructure::updateForDelete
virtual FUNCTION_H bool updateForDelete()
Definition: pointStructure.cpp:342
pFlow::pointStructure::activePointsDevice
Definition: pointStructure.hpp:59
pFlow::pointStructure::pointPosition
FUNCTION_H realx3Field_D & pointPosition()
Definition: pointStructure.cpp:65
pFlow::pointStructure::numActive
FUNCTION_H label numActive() const
Definition: pointStructure.cpp:224
pFlow::pointStructure::activePointsHost::activeRange
INLINE_FUNCTION_H auto activeRange() const
Definition: pointStructure.hpp:134
pFlow
Definition: demComponent.hpp:28
VectorSingles.hpp
pFlow::pointStructure::isActive
INLINE_FUNCTION_H bool isActive(label i) const
Definition: pointStructure.hpp:290
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::pointStructure::allActive
FUNCTION_H bool allActive() const
Definition: pointStructure.cpp:230
pFlow::VectorDual::deviceVectorAll
INLINE_FUNCTION_H deviceViewType & deviceVectorAll()
Definition: VectorDual.hpp:335
pFlow::pointStructure::activePointsDevice::operator()
INLINE_FUNCTION_HD bool operator()(int32 i) const
Definition: pointStructure.hpp:85
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::pointStructure::~pointStructure
virtual ~pointStructure()=default
pFlow::indexContainer::hostView
const HostViewType & hostView() const
Definition: indexContainer.hpp:151
pFlow::pointStructure::activePointsDevice::activeRange
INLINE_FUNCTION_HD auto activeRange() const
Definition: pointStructure.hpp:91
pFlow::pointStructure::mortonSortPoints
virtual FUNCTION_H bool mortonSortPoints(const box &domain, real dx)
Definition: pointStructure.cpp:236
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::setFieldList
Definition: setFieldList.hpp:32
Fields.hpp
pFlow::pointStructure::activePointsHost::flag_
ViewType1D< int8, HostSpace > flag_
Definition: pointStructure.hpp:106
pFlow::pointStructure::insertedPointIndexH
FUNCTION_H auto insertedPointIndexH() const
Definition: pointStructure.hpp:318
pFlow::pointStructure::getNewPointsIndices
FUNCTION_H uniquePtr< int32IndexContainer > getNewPointsIndices(int32 numNewPoints) const
Definition: pointStructure.cpp:77
pFlow::pointStructure::activeRange_
range activeRange_
Definition: pointStructure.hpp:164
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::pointStructure::activePointsHost::operator=
INLINE_FUNCTION_H activePointsHost & operator=(const activePointsHost &)=default
pFlow::pointStructure::mortonSortedIndex_
int32IndexContainer mortonSortedIndex_
Sorted index of particles based on morton code.
Definition: pointStructure.hpp:170
pFlow::pointStructure::activePointsHost::activeRange_
range activeRange_
Definition: pointStructure.hpp:110
pFlow::pointStructure::read
FUNCTION_H bool read(iIstream &is)
Definition: pointStructure.hpp:361
pFlow::pointStructure::activePointsDevice::activePointsDevice
INLINE_FUNCTION_H activePointsDevice(bool allActive, range active, const ViewType1D< int8 > &flag)
Definition: pointStructure.hpp:71
pFlow::pointStructure::capacity
FUNCTION_H label capacity() const
Definition: pointStructure.cpp:218
pFlow::pointStructure::activePointsDevice::operator=
INLINE_FUNCTION_HD activePointsDevice & operator=(const activePointsDevice &)=default
pFlow::pointStructure::tobeInsertedIndex_
int32IndexContainer tobeInsertedIndex_
Index vector for points to be inserted.
Definition: pointStructure.hpp:167
pFlow::box
Definition: box.hpp:32
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
eventSubscriber.hpp
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:67
pFlow::pointStructure::insertPoints
virtual FUNCTION_H uniquePtr< int32IndexContainer > insertPoints(const realx3Vector &pos, const setFieldList &setField, repository &owner, const List< eventObserver * > &exclusionList={nullptr})
Definition: pointStructure.cpp:351
pFlow::pointStructure::pointStructure
pointStructure()
Definition: pointStructure.cpp:144
pFlow::pointStructure::activePointsMaskD
activePointsDevice activePointsMaskD() const
Definition: pointStructure.hpp:235
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::repository
Definition: repository.hpp:34
pFlow::pointStructure::size
FUNCTION_H label size() const
Definition: pointStructure.cpp:212
pFlow::pointStructure::activePointsHost::operator()
INLINE_FUNCTION_H bool operator()(int32 i) const
Definition: pointStructure.hpp:128
pFlow::pointStructure::numPoints_
size_t numPoints_
Definition: pointStructure.hpp:149
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::pointStructure::TypeInfo
TypeInfo("pointStructure")
pFlow::Vector
Definition: Vector.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53
indexContainer.hpp
VectorDuals.hpp
pFlow::indexContainer< int32 >
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Definition: indexContainer.hpp:156
pFlow::pointStructure::setNumMaxPoints
FUNCTION_H void setNumMaxPoints()
Definition: pointStructure.cpp:58
pFlow::pointStructure::pointFlag_
int8Field_HD pointFlag_
Definition: pointStructure.hpp:155