www.cemf.ir
mapperNBS.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 "mapperNBS.hpp"
22 #include "mapperNBSKernels.hpp"
23 #include "streams.hpp"
24 
27 
29 (
30  const deviceViewType1D<realx3> &pointPos,
31  const pFlagTypeDevice &flags,
32  real cellSize
33 )
34 {
35  box domainBox = domainCells_.domainBox();
36 
37 
38  if(adjustableBox_)
39  {
40  lastCheckForBox_ = buildCount_;
41 
42  realx3 minP;
43  realx3 maxP;
45  (
46  pointPos,
47  flags,
48  minP, maxP
49  );
50 
51  minP = max( minP - enlargementFactor_*cellSize, domainBox.minPoint());
52  maxP = min( maxP + enlargementFactor_*cellSize, domainBox.maxPoint());
53 
54  box searchBox = {minP, maxP};
55  searchCells_ = cells(searchBox, cellSize);
56  INFORMATION<<"Search box for contact search has changed: "<<
57  "search box is ["<<searchCells_.domainBox().minPoint()<<
58  " "<<searchCells_.domainBox().maxPoint()<<"]"<<END_INFO;
59 
60  return true;
61 
62  }
63  else
64  {
65  searchCells_ = cells(domainBox, cellSize);
66  INFORMATION<<"Search box for contact search is: ["
67  << domainBox.minPoint()<<" "<<domainBox.maxPoint()<<"]"<<END_INFO;
68 
69  return false;
70  }
71 
72 }
73 
75 {
76  checkAllocateNext(nextRng);
77  nullifyNext(nextRng);
79 }
80 
82 {
83 
84  auto newCap = nextRng.end();
85 
86  if( nextCapacity_ < newCap)
87  {
88  nextCapacity_ = newCap;
89  if(!nextOwner_)return;
90  reallocNoInit(next_, nextCapacity_);
91  }
92 }
93 
95 {
96  fill(head_, NoPos);
97 }
98 
100 {
101  if(!nextOwner_)return;
102  fill(next_, nextRng, NoPos);
103 }
104 
106  const box &domain,
107  real cellSize,
108  const deviceViewType1D<realx3> &pointPos,
109  const pFlagTypeDevice &flags,
110  bool adjustableBox,
111  bool nextOwner
112 )
113 :
114  domainCells_(domain, cellSize),
115  searchCells_(domain, cellSize),
116  adjustableBox_(adjustableBox),
117  nextOwner_(nextOwner)
118 {
119  setSearchBox(pointPos, flags, cellSize);
120 
121  allocateArrays(flags.activeRange());
122 }
123 
125 (
126  const deviceViewType1D<realx3>& pointPos,
127  const pFlagTypeDevice & flags,
128  bool& searchBoxChanged
129 )
130 {
131  auto aRange = flags.activeRange();
132  buildCount_++;
133  if(adjustableBox_ && buildCount_%checkInterval_ == 0)
134  {
135 
136  if(searchBoxChanged =
137  setSearchBox(pointPos, flags, searchCells_.cellSize());searchBoxChanged)
138  {
139  allocateArrays(aRange);
140  }
141 
142  }
143  else
144  {
145  checkAllocateNext(aRange);
146  nullifyHead();
147  nullifyNext(aRange);
148  }
149 
150  if( adjustableBox_ )
151  {
153  searchCells_,
154  head_,
155  next_,
156  pointPos,
157  flags) )
158  {
159 
160  buildCount_++;
161  setSearchBox(pointPos, flags, searchCells_.cellSize());
162 
163  searchBoxChanged = true;
164 
165  allocateArrays(flags.activeRange());
166 
168  searchCells_,
169  head_,
170  next_,
171  pointPos,
172  flags))
173  {
174  fatalErrorInFunction<<"failed to build list in anjustable search box mode!"<<endl;
175  return false;
176  }
177  }
178  }
179  else
180  {
182  searchCells_,
183  head_,
184  next_,
185  pointPos,
186  flags
187  );
188  searchBoxChanged = false;
189  }
190 
191  return true;
192 
193 }
194 
pFlow::mapperNBSKernels::buildLists
bool buildLists(const cells &searchCell, const deviceViewType3D< uint32 > &head, const deviceViewType1D< uint32 > &next, const deviceViewType1D< realx3 > &points, const pFlagTypeDevice &flags)
Definition: mapperNBSKernels.cpp:148
pFlow::mapperNBS::mapperNBS
INLINE_FUNCTION_HD mapperNBS()=default
pFlow::reallocFill
INLINE_FUNCTION_H void reallocFill(ViewType1D< Type, Properties... > &view, uint32 len, Type val)
Definition: KokkosUtilities.hpp:71
mapperNBS.hpp
pFlow::mapperNBS::allocateArrays
void allocateArrays(rangeU32 nextRng)
Definition: mapperNBS.cpp:74
pFlow::cells::nz
INLINE_FUNCTION_HD int32 nz() const
Definition: cells.hpp:114
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
pFlow::cells::ny
INLINE_FUNCTION_HD int32 ny() const
Definition: cells.hpp:108
mapperNBSKernels.hpp
pFlow::mapperNBS::build
bool build(const deviceViewType1D< realx3 > &pointPos, const pFlagTypeDevice &flags, bool &searchBoxChanged)
Definition: mapperNBS.cpp:125
pFlow::Range::end
INLINE_FUNCTION_HD T & end()
End.
Definition: Range.hpp:101
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::algorithms::KOKKOS::min
INLINE_FUNCTION_H Type min(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:124
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, uint32 len)
Definition: KokkosUtilities.hpp:64
pFlow::mapperNBS::setSearchBox
bool setSearchBox(const deviceViewType1D< realx3 > &pointPos, const pFlagTypeDevice &flags, real cellSize)
Definition: mapperNBS.cpp:29
pFlow::mapperNBS::nullifyHead
void nullifyHead()
Definition: mapperNBS.cpp:94
pFlow::cells::nx
INLINE_FUNCTION_HD int32 nx() const
Definition: cells.hpp:102
pFlow::mapperNBSKernels::findPointExtends
void findPointExtends(const deviceViewType1D< realx3 > &points, const pFlagTypeDevice &flags, realx3 &minPoint, realx3 &maxPoint)
Definition: mapperNBSKernels.cpp:27
pFlow::mapperNBS::NoPos
static constexpr uint32 NoPos
Definition: mapperNBS.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::box::maxPoint
const INLINE_FUNCTION_HD realx3 & maxPoint() const
Definition: box.hpp:97
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::mapperNBS::nullifyNext
void nullifyNext(rangeU32 nextRng)
Definition: mapperNBS.cpp:99
pFlow::mapperNBS::enlargementFactor_
static real enlargementFactor_
Definition: mapperNBS.hpp:102
pFlow::mapperNBS::searchCells_
cells searchCells_
Definition: mapperNBS.hpp:84
pFlow::mapperNBSKernels::buildListsReduce
bool buildListsReduce(const cells &searchCell, const deviceViewType3D< uint32 > &head, const deviceViewType1D< uint32 > &next, const deviceViewType1D< realx3 > &points, const pFlagTypeDevice &flags)
Definition: mapperNBSKernels.cpp:85
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::pointFlag::activeRange
const INLINE_FUNCTION_HD auto & activeRange() const
Definition: pointFlag.hpp:179
pFlow::Range< uint32 >
streams.hpp
pFlow::mapperNBS::checkInterval_
static uint32 checkInterval_
Definition: mapperNBS.hpp:100
pFlow::box::minPoint
const INLINE_FUNCTION_HD realx3 & minPoint() const
Definition: box.hpp:91
pFlow::box
Definition: box.hpp:32
pFlow::mapperNBS::head_
HeadType head_
Definition: mapperNBS.hpp:86
pFlow::mapperNBS::checkAllocateNext
void checkAllocateNext(rangeU32 nextRng)
Definition: mapperNBS.cpp:81
pFlow::domain
Definition: domain.hpp:31
pFlow::cells
Definition: cells.hpp:31
pFlow::triple< real >
END_INFO
#define END_INFO
Definition: streams.hpp:37
pFlow::pointFlag< DefaultExecutionSpace >
INFORMATION
#define INFORMATION
Definition: streams.hpp:36