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 
166  // - index vector for points to be inserted
168 
169 
171  FUNCTION_H
172  bool evaluatePointStructure();
173 
174  FUNCTION_H
175  void setNumMaxPoints();
176 
177  // - access to pointPosition
178  FUNCTION_H
180 
181  // - access to pointFlag
182  FUNCTION_H
184 
185  FUNCTION_H
187  getNewPointsIndices(int32 numNewPoints)const;
188 
189 public:
190 
191  friend class dynamicPointStructure;
192 
193  // - type info
194  TypeInfo("pointStructure");
195 
196 
198 
199  // - an empty pointStructure, good for reading from file
200  pointStructure();
201 
202  // - construct from components
203  pointStructure(const int8Vector& flgVec, const realx3Vector& posVec);
204 
205  // - construct from point positions, assume all points are active
206  pointStructure(const realx3Vector& posVec);
207 
208  // - copy construct
209  //
210  // should be changed, may causs undefined behavior
212  pointStructure(const pointStructure&) = default;
213 
214 
215  // - no move construct
216  pointStructure(pointStructure&&) = delete;
217 
218  // - copy assignment
219  //
220  // should be changed, may causs undefined behavior
222  pointStructure& operator=(const pointStructure&) = default;
223 
224  // - no move assignment
226 
227  // - destructor
228  virtual ~pointStructure() = default;
229 
230 
233  {
234  return activePointsDevice(
235  this->allActive(),
236  activeRange(),
237  pointFlag_.deviceVectorAll()
238  );
239  }
240 
242  {
243  return activePointsHost(
244  this->allActive(),
245  activeRange(),
246  pointFlag_.hostVectorAll()
247  );
248  }
249 
250  // - const access pointPosition
251  FUNCTION_H
252  const realx3Field_D& pointPosition()const;
253 
254  // - const access to pointFlag
255  FUNCTION_H
256  const int8Field_HD& pointFlag()const;
257 
260  {
261  return pointPosition_.hostVectorAll();
262  }
263 
264  // - size of data structure
265  FUNCTION_H
266  label size()const;
267 
268  // - maximum capacity of data structure
269  FUNCTION_H
270  label capacity()const;
271 
272  // - number of active points
273  FUNCTION_H
274  label numActive() const;
275 
276  // - if all points are active
277  FUNCTION_H
278  bool allActive()const;
279 
282  {
283  return activeRange_;
284  }
285 
287  bool isActive(label i)const
288  {
289  return pointFlag_[i] == ACTIVE;
290  }
291 
292  FUNCTION_H
293  size_t markDeleteOutOfBox(const box& domain);
294 
295  // - update data structure by removing the marked points
296  // Notifies all the fields that are built based on this data structure
297  // and then apply removing to the pointPosition_ and pointFlag_
298  FUNCTION_H
299  virtual bool updateForDelete();
300 
302 
303  // - const access to points to be newly inserted
304  FUNCTION_H
305  auto insertedPointIndex()const
306  {
307  return tobeInsertedIndex_;
308  }
309 
310  FUNCTION_H
312  {
313  return tobeInsertedIndex_.hostView();
314  }
315 
316  FUNCTION_H
318  {
320  }
321 
322 
323  // - update data structure by inserting/setting new points
324  // Notifies all the fields in the registered list of data structure
325  // and exclude the fields that re in the exclusionList
326  // retrun nullptr if it fails
327  FUNCTION_H
329  const realx3Vector& pos,
330  const setFieldList& setField,
331  repository& owner,
332  const List<eventObserver*>& exclusionList={nullptr}
333  );
334 
335 
337  // - read pointStructure from is
338  FUNCTION_H
339  bool readPointStructure(iIstream& is);
340 
341  // - write pointStructure to os
342  FUNCTION_H
343  bool writePointStructure(iOstream& os)const;
344 
345  // - read
346  FUNCTION_H
347  bool read(iIstream& is)
348  {
349  return readPointStructure(is);
350  }
351 
352  // - write
353  FUNCTION_H
354  bool write(iOstream& os)const
355  {
356  return writePointStructure(os);
357  }
358 
359 };
360 
361 
362 } // pFlow
363 
364 
365 
366 
367 #endif //__pointStructure_hpp__
pFlow::pointStructure::evaluatePointStructure
FUNCTION_H bool evaluatePointStructure()
Definition: pointStructure.cpp:30
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::pointStructure::DELETED
@ DELETED
Definition: pointStructure.hpp:52
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:354
pFlow::VectorDual::hostVectorAll
INLINE_FUNCTION_H hostViewType & hostVectorAll()
Definition: VectorDual.hpp:345
pFlow::pointStructure::activePointsMaskH
activePointsHost activePointsMaskH() const
Definition: pointStructure.hpp:241
pFlow::VectorSingle::hostVectorAll
const INLINE_FUNCTION_H auto hostVectorAll() const
Definition: VectorSingle.hpp:320
pFlow::pointStructure::insertedPointIndexD
FUNCTION_H auto insertedPointIndexD() const
Definition: pointStructure.hpp:317
pFlow::pointStructure::markDeleteOutOfBox
FUNCTION_H size_t markDeleteOutOfBox(const box &domain)
Definition: pointStructure.cpp:235
pFlow::pointStructure::pointFlag
FUNCTION_H int8Field_HD & pointFlag()
Definition: pointStructure.cpp:70
pFlow::pointStructure::readPointStructure
FUNCTION_H bool readPointStructure(iIstream &is)
Definition: pointStructure.cpp:389
pFlow::pointStructure::activeRange
INLINE_FUNCTION_H range activeRange() const
Definition: pointStructure.hpp:281
pFlow::pointStructure::pointPositionHostAll
INLINE_FUNCTION_H auto pointPositionHostAll()
Definition: pointStructure.hpp:259
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:417
Vectors.hpp
pFlow::pointStructure::operator=
pointStructure & operator=(const pointStructure &)=default
pFlow::Field< VectorDual, int8 >
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:305
pFlow::pointStructure::updateForDelete
virtual FUNCTION_H bool updateForDelete()
Definition: pointStructure.cpp:291
pFlow::pointStructure::activePointsDevice
Definition: pointStructure.hpp:59
pFlow::pointStructure::pointPosition
FUNCTION_H realx3Field_D & pointPosition()
Definition: pointStructure.cpp:64
pFlow::pointStructure::numActive
FUNCTION_H label numActive() const
Definition: pointStructure.cpp:222
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:287
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::pointStructure::allActive
FUNCTION_H bool allActive() const
Definition: pointStructure.cpp:228
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:143
pFlow::pointStructure::activePointsDevice::activeRange
INLINE_FUNCTION_HD auto activeRange() const
Definition: pointStructure.hpp:91
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:311
pFlow::pointStructure::getNewPointsIndices
FUNCTION_H uniquePtr< int32IndexContainer > getNewPointsIndices(int32 numNewPoints) const
Definition: pointStructure.cpp:76
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::activePointsHost::activeRange_
range activeRange_
Definition: pointStructure.hpp:110
pFlow::pointStructure::read
FUNCTION_H bool read(iIstream &is)
Definition: pointStructure.hpp:347
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:216
pFlow::pointStructure::activePointsDevice::operator=
INLINE_FUNCTION_HD activePointsDevice & operator=(const activePointsDevice &)=default
pFlow::pointStructure::tobeInsertedIndex_
int32IndexContainer tobeInsertedIndex_
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:62
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:300
pFlow::pointStructure::pointStructure
pointStructure()
Definition: pointStructure.cpp:142
pFlow::pointStructure::activePointsMaskD
activePointsDevice activePointsMaskD() const
Definition: pointStructure.hpp:232
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:210
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
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
VectorDuals.hpp
pFlow::indexContainer< int32 >
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Definition: indexContainer.hpp:148
pFlow::pointStructure::setNumMaxPoints
FUNCTION_H void setNumMaxPoints()
Definition: pointStructure.cpp:57
pFlow::pointStructure::pointFlag_
int8Field_HD pointFlag_
Definition: pointStructure.hpp:155