www.cemf.ir
boundaryBase.cpp
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 #include "boundaryBase.hpp"
22 #include "boundaryList.hpp"
23 #include "dictionary.hpp"
24 #include "internalPoints.hpp"
25 #include "anyList.hpp"
26 #include "Time.hpp"
27 #include "pointStructure.hpp"
28 #include "boundaryBaseKernels.hpp"
29 
31 {
32  indexList_.resize(newSize);
33  unSyncLists();
34 }
35 
37 (
38  const uint32Vector_D& newIndices
39 )
40 {
41  indexList_.assign(newIndices, false);
42  unSyncLists();
43 }
44 
45 
47 (
48  const uint32Vector_D& newIndices
49 )
50 {
51 
52  indexList_.append(newIndices);
53  unSyncLists();
54 
55  message msg;
56 
58  anyList varList;
59  varList.emplaceBack(
61  newIndices);
62 
63  if(!notify(
64  internal_.time().currentIter(),
65  internal_.time().currentTime(),
66  internal_.time().dt(),
67  msg,
68  varList))
69  {
71  return false;
72  }
73 
74  return true;
75 
76 }
77 
79 (
80  uint32 numRemove,
81  const uint32Vector_D& removeMask
82 )
83 {
84  if(removeMask.size() != size()+1 )
85  {
86  fatalErrorInFunction<<"size mismatch"<<endl;
87  return false;
88  }
89 
90  uint32Vector_D removeIndices("removeIndices");
91  uint32Vector_D keepIndices("keepIndices");
92 
94  (
95  indexList_,
96  numRemove,
97  removeMask,
98  removeIndices,
99  keepIndices
100  );
101 
102  if(!setRemoveKeepIndices(removeIndices, keepIndices))
103  {
104  return false;
105  }
106 
107  anyList aList;
108 
109  aList.emplaceBack(
111  std::move(keepIndices));
112 
113  message msgBndry = message::BNDR_RESET;
114 
115  uint32 iter = time().currentIter();
116  real t = time().currentTime();
117  real dt = time().dt();
118 
119  if( !this->notify(iter, t, dt, msgBndry, aList) )
120  {
121  fatalErrorInFunction<<"Error in notify operation in boundary "<<
122  name_ <<endl;
123  return false;
124  }
125 
126  return true;
127 }
128 
130 (
131  const uint32Vector_D &removeIndices,
132  const uint32Vector_D &keepIndices
133 )
134 {
135 
136  if(!internal_.deletePoints(removeIndices))
137  {
139  "error in deleting points from boundary "<< name()<<endl;
140  return false;
141  }
142 
143  setNewIndices(keepIndices);
144 
145  return true;
146 }
147 
149 (
150  uint32 numTransfer,
151  const uint32Vector_D& transferMask,
152  uint32 transferBoundaryIndex,
153  realx3 transferVector
154 )
155 {
156  if(transferMask.size() != size()+1 )
157  {
158  fatalErrorInFunction<<"size mismatch"<<endl;
159  return false;
160  }
161 
162  uint32Vector_D transferIndices("transferIndices");
163  uint32Vector_D keepIndices("keepIndices");
164 
166  (
167  indexList_,
168  numTransfer,
169  transferMask,
170  transferIndices,
171  keepIndices
172  );
173 
174  // first, change the flags in the internalPoints
175  if( !internal_.changePointsFlagPosition(
176  transferIndices,
177  transferVector,
178  thisBoundaryIndex(),
179  transferBoundaryIndex) )
180  {
182  return false;
183  }
184 
185  // second, remove the indices from this list
186  setNewIndices(keepIndices);
187 
188  // third, add the indices to the mirror boundary
189  return mirrorBoundary().appendNewIndices(transferIndices);
190 
191 }
192 
194 {
195 
196  uint32 s = size();
197 
198  markedIndices.reallocate(s+1, s+1);
199  markedIndices.fill(0u);
200 
201  const auto& markedIndicesD = markedIndices.deviceViewAll();
202  pointFieldAccessType points = thisPoints();
203  infinitePlane p = boundaryPlane().infPlane();
204 
205  uint32 numMark = 0;
206 
207  Kokkos::parallel_reduce
208  (
209  "boundaryProcessor::afterIteration",
210  deviceRPolicyStatic(0,s),
211  LAMBDA_HD(uint32 i, uint32& markToUpdate)
212  {
213  if(p.pointInNegativeSide(points(i)))
214  {
215  markedIndicesD(i)=1;
216  markToUpdate++;
217  }
218  },
219  numMark
220  );
221 
222  return numMark;
223 }
224 
226  const dictionary &dict,
227  const plane &bplane,
228  internalPoints &internal,
229  boundaryList &bndrs,
230  uint32 thisIndex)
231  : subscriber(dict.name()),
232  boundaryPlane_(bplane),
233  indexList_(groupNames("indexList", dict.name())),
234  indexListHost_(groupNames("hostIndexList", dict.name())),
235  neighborLength_(dict.getVal<real>("neighborLength")),
236  // updateInetrval_(dict.getVal<uint32>("updateInterval")),
237  boundaryExtntionLengthRatio_(dict.getVal<real>("boundaryExtntionLengthRatio")),
238  internal_(internal),
239  boundaries_(bndrs),
240  thisBoundaryIndex_(thisIndex),
241  neighborProcessorNo_(dict.getVal<int32>("neighborProcessorNo")),
242  isBoundaryMaster_(thisProcessorNo() >= neighborProcessorNo()),
243  name_(dict.name()),
244  type_(dict.getVal<word>("type"))
245 {
246  unSyncLists();
247 }
248 
250 {
251  return boundaries_.pStruct();
252 }
253 
255 {
256  return boundaries_.pStruct().time();
257 }
258 
260 {
261  return boundaries_[mirrorBoundaryIndex()];
262 }
263 
265 {
266  return boundaries_[mirrorBoundaryIndex()];
267 }
268 
271 {
272 
273  return pointFieldAccessType
274  (
275  indexList_.size(),
276  indexList_.deviceViewAll(),
277  internal_.pointPosition().deviceViewAll()
278  );
279 
280 }
281 
283 {
284  static realx3Vector_D dummyVector{"dummyVector"};
286  fatalExit;
287  return dummyVector;
288 }
289 
290 const pFlow::realx3Vector_D&
292 {
293  static realx3Vector_D dummyVector{"dummyVector"};
295  fatalExit;
296  return dummyVector;
297 }
298 
300 {
301  const plane& thisP = boundaryPlane();
302  const plane& mirrorP = mirrorBoundary().boundaryPlane();
303  return thisP.normal()*(thisP.d() + mirrorP.d());
304 }
305 
306 
308 (
309  const dictionary &dict,
310  const plane &bplane,
311  internalPoints &internal,
312  boundaryList &bndrs,
313  uint32 thisIndex
314 )
315 {
316  word type = dict.getVal<word>("type");
317  word bType = angleBracketsNames("boundary", type);
318 
319  if( dictionaryvCtorSelector_.search(bType) )
320  {
321  return dictionaryvCtorSelector_[bType] (dict, bplane, internal, bndrs, thisIndex);
322  }
323  else
324  {
325  printKeys
326  (
327  fatalError << "Ctor Selector "<< bType << " does not exist. \n"
328  <<"Avaiable ones are: \n\n"
329  ,
330  dictionaryvCtorSelector_
331  );
332  fatalExit;
333  }
334  return nullptr;
335 }
anyList.hpp
notImplementedFunction
#define notImplementedFunction
Report that a function is yet not implemented.
Definition: error.hpp:84
pFlow::boundaryBase::pStruct
const pointStructure & pStruct() const
Definition: boundaryBase.cpp:249
pFlow::VectorSingle::fill
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
Definition: VectorSingle.cpp:365
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::VectorSingle::resize
INLINE_FUNCTION_H void resize(uint32 n)
Resize the vector and preserve the content.
Definition: VectorSingle.cpp:344
pFlow::boundaryBase::displacementVectroToMirror
virtual realx3 displacementVectroToMirror() const
displacement vector that transfers points to a distance that is equal to the distance between this ...
Definition: boundaryBase.cpp:299
pFlow::infinitePlane::normal
const INLINE_FUNCTION_HD auto & normal() const
Definition: infinitePlane.hpp:155
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::infinitePlane::pointInNegativeSide
INLINE_FUNCTION_HD bool pointInNegativeSide(const realx3 &p) const
Definition: infinitePlane.hpp:107
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::plane
Definition: plane.hpp:30
pFlow::boundaryBase::transferPointsToMirror
bool transferPointsToMirror(uint32 numTransfer, const uint32Vector_D &transferMask, uint32 transferBoundaryIndex, realx3 transferVector)
Definition: boundaryBase.cpp:149
pFlow::boundaryBase::neighborProcPoints
virtual realx3Vector_D & neighborProcPoints()
Return a reference to point positions in the neighbor processor boundary.
Definition: boundaryBase.cpp:282
pFlow::boundaryBase::markInNegativeSide
uint32 markInNegativeSide(const word &name, uint32Vector_D &markedIndices) const
Definition: boundaryBase.cpp:193
pFlow::VectorSingle::reallocate
INLINE_FUNCTION_H void reallocate(uint32 cap)
Reallocate memory to new cap and set size to 0.
Definition: VectorSingle.cpp:326
boundaryBase.hpp
pFlow::infinitePlane
Definition: infinitePlane.hpp:32
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::boundaryList
Definition: boundaryList.hpp:35
pFlow::boundaryBase::mirrorBoundary
boundaryBase & mirrorBoundary()
Definition: boundaryBase.cpp:259
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::subscriber
Definition: subscriber.hpp:37
pFlow::message::BNDR_APPEND
@ BNDR_APPEND
Definition: message.hpp:50
pFlow::boundaryBase::time
const Time & time() const
Definition: boundaryBase.cpp:254
pFlow::message::BNDR_RESET
@ BNDR_RESET
Definition: message.hpp:48
boundaryList.hpp
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::anyList
Definition: anyList.hpp:35
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::angleBracketsNames
word angleBracketsNames(const word &w1, const word &w2)
Output <w1,w2>
Definition: bTypesFunctions.cpp:156
boundaryBaseKernels.hpp
dictionary.hpp
Time.hpp
pFlow::boundaryBase
Definition: boundaryBase.hpp:42
pFlow::boundaryBase::setSize
virtual void setSize(uint32 newSize)
Set the size of indexList.
Definition: boundaryBase.cpp:30
pFlow::VectorSingle< uint32 >
pFlow::boundaryBaseKernels::createRemoveKeepIndices
void createRemoveKeepIndices(const uint32Vector_D &indices, uint32 numRemove, const uint32Vector_D &removeMask, uint32Vector_D &removeIndices, uint32Vector_D &keepIndices, bool exactCap=true)
Definition: boundaryBaseKernels.cpp:65
pFlow::boundaryBase::unSyncLists
void unSyncLists()
Definition: boundaryBase.hpp:127
fatalError
#define fatalError
Report a fatal error and exit the applicaiton.
Definition: error.hpp:70
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::infinitePlane::d
const INLINE_FUNCTION_HD auto & d() const
Definition: infinitePlane.hpp:161
pFlow::boundaryBase::indexList_
uint32Vector_D indexList_
list of particles indices on device
Definition: boundaryBase.hpp:59
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::deviceRPolicyStatic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyStatic
Definition: KokkosTypes.hpp:66
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::boundaryBase::setNewIndices
void setNewIndices(const uint32Vector_D &newIndices)
Definition: boundaryBase.cpp:37
pFlow::boundaryBase::boundaryBase
boundaryBase(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryBase.cpp:225
pFlow::boundaryBase::setRemoveKeepIndices
bool setRemoveKeepIndices(const uint32Vector_D &removeIndices, const uint32Vector_D &keepIndices)
Definition: boundaryBase.cpp:130
pFlow::boundaryBase::appendNewIndices
bool appendNewIndices(const uint32Vector_D &newIndices)
Definition: boundaryBase.cpp:47
pFlow::triple< real >
pointStructure.hpp
internalPoints.hpp
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
pFlow::boundaryBase::thisPoints
pointFieldAccessType thisPoints() const
Definition: boundaryBase.cpp:270
pFlow::boundaryBase::create
static uniquePtr< boundaryBase > create(const dictionary &dict, const plane &bplane, internalPoints &internal, boundaryList &bndrs, uint32 thisIndex)
Definition: boundaryBase.cpp:308
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::VectorSingle::size
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
Definition: VectorSingle.cpp:297
pFlow::message::add
message & add(EVENT evnt)
Definition: message.hpp:113
pFlow::message::eventName
static const word & eventName(size_t event)
Definition: message.hpp:196
pFlow::Time
Definition: Time.hpp:37
pFlow::boundaryBase::removeIndices
bool removeIndices(uint32 numRemove, const uint32Vector_D &removeMask)
Definition: boundaryBase.cpp:79