www.cemf.ir
wallBoundaryContactSearch.cpp
Go to the documentation of this file.
2 #include "streams.hpp"
3 
5 (
6  real cellExtent,
7  uint32 numPoints,
8  uint32 numElements,
10  const ViewType1D<uint32x3, memory_space> &vertices,
12 )
13 :
14  cellExtent_( max(cellExtent, 0.5 ) ),
15  numElements_(numElements),
16  numPoints_(numPoints),
17  vertices_(vertices),
18  points_(points),
19  normals_(normals)
20 {
21  allocateArrays();
22 }
23 
24 bool pFlow::wallBoundaryContactSearch::build(const cells &searchBox, const realx3& transferVec)
25 {
26  Kokkos::parallel_for(
27  "pFlow::cellsWallLevel0::build",
30  {
31  auto v = vertices_[i];
32  auto p1 = points_[v.x()]+transferVec;
33  auto p2 = points_[v.y()]+transferVec;
34  auto p3 = points_[v.z()]+transferVec;
35 
36  realx3 minP;
37  realx3 maxP;
38 
39  searchBox.extendBox(p1, p2, p3, cellExtent_, minP, maxP);
40  elementBox_[i] = iBoxType(searchBox.pointIndex(minP), searchBox.pointIndex(maxP));
41  auto d = elementBox_[i].maxPoint()-elementBox_[i].minPoint();
42  validBox_[i] = (d.x()*d.y()*d.z())==0? 0:1;
43  });
44  Kokkos::fence();
45 
46  return true;
47 }
48 
50 (
51  csPairContainerType &pairs,
52  const cells &searchCells,
53  const deviceScatteredFieldAccess<realx3> &thisPoints,
54  const deviceScatteredFieldAccess<real> &thisDiams,
55  const deviceScatteredFieldAccess<realx3> &mirrorPoints,
56  const deviceScatteredFieldAccess<real> &mirroDiams,
57  const realx3 &transferVec,
58  real sizeRatio
59 )
60 {
61  uint32 nNotInserted = 1;
62 
63  while (nNotInserted>0u)
64  {
65  build(searchCells,{0,0,0});
66  nNotInserted = findPairsElementRangeCount(
67  pairs,
68  searchCells,
69  thisPoints,
70  thisDiams,
71  {0,0,0},
72  0
73  );
74 
75  build(searchCells, transferVec);
76  nNotInserted += findPairsElementRangeCount(
77  pairs,
78  searchCells,
79  mirrorPoints,
80  mirroDiams,
81  transferVec,
83  );
84 
85  if(nNotInserted>0u)
86  {
87  // note that getFull now shows the number of failed insertions.
88  uint32 incCap = max(nNotInserted,50u) ;
89 
90  auto oldCap = pairs.capacity();
91 
92  pairs.increaseCapacityBy(incCap);
93 
94  INFORMATION<< "The contact pair container capacity increased from "<<
95  oldCap << " to "<<pairs.capacity()<<" in wallBoundaryContactSearch."<<END_INFO;
96  }
97  }
98  return true;
99 }
100 
102 (
103  csPairContainerType &pairs,
104  const cells &searchCells,
105  const deviceScatteredFieldAccess<realx3> &pPoints,
106  const deviceScatteredFieldAccess<real> &pDiams,
107  const realx3 &transferVec,
108  uint baseTriIndex
109 )
110 {
111 
112  if(pPoints.empty())return 0u;
113 
114  uint32 nNotInserted = 0;
115  uint32 nThis = pPoints.size();
116  const auto& numElements = numElements_;
117  const auto& elementBox = elementBox_;
118  const auto& validBox = validBox_;
119 
120  Kokkos::parallel_reduce(
121  "pFlow::wallBoundaryContactSearch::findPairsElementRangeCount",
122  deviceRPolicyDynamic(0,nThis),
123  LAMBDA_HD(uint32 i, uint32 &notInsertedUpdate)
124  {
125  auto p = pPoints[i]+transferVec;
126  int32x3 ind;
127  if( searchCells.pointIndexInDomain(p, ind) )
128  {
129  for(uint32 nTri=0; nTri<numElements; nTri++)
130  {
131  if( validBox[nTri]== 0)continue;
132  if( elementBox[nTri].isInside(ind)&&
133  pairs.insert(i,nTri+baseTriIndex) == static_cast<uint32>(-1))
134  {
135  notInsertedUpdate++;
136  }
137  }
138  }
139  },
140  nNotInserted
141  );
142 
143  return nNotInserted;
144 }
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::scatteredFieldAccess::size
INLINE_FUNCTION_HD uint32 size() const
Definition: scatteredFieldAccess.hpp:134
wallBoundaryContactSearch.hpp
pFlow::wallBoundaryContactSearch::cellExtent_
real cellExtent_
Definition: wallBoundaryContactSearch.hpp:49
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::cells::pointIndexInDomain
INLINE_FUNCTION_HD bool pointIndexInDomain(const realx3 p, int32x3 &index) const
Definition: cells.hpp:139
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::wallBoundaryContactSearch::vertices_
ViewType1D< uint32x3, memory_space > vertices_
Definition: wallBoundaryContactSearch.hpp:58
pFlow::wallBoundaryContactSearch::findPairsElementRangeCount
uint32 findPairsElementRangeCount(csPairContainerType &pairs, const cells &searchCells, const deviceScatteredFieldAccess< realx3 > &pPoints, const deviceScatteredFieldAccess< real > &pDiams, const realx3 &transferVec, uint baseTriIndex)
Definition: wallBoundaryContactSearch.cpp:102
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const realx3 &p1, const realx3 &p2, const realx3 &p3, real extent, realx3 &minP, realx3 &maxP) const
Definition: cells.hpp:178
pFlow::wallBoundaryContactSearch::iBoxType
iBox< int32 > iBoxType
Definition: wallBoundaryContactSearch.hpp:44
pFlow::unsortedPairs
Definition: unsortedPairs.hpp:32
pFlow::wallBoundaryContactSearch::wallBoundaryContactSearch
INLINE_FUNCTION_HD wallBoundaryContactSearch()=default
CLASS_LAMBDA_HD
#define CLASS_LAMBDA_HD
Definition: pFlowMacros.hpp:60
pFlow::wallBoundaryContactSearch::build
bool build(const cells &searchBox, const realx3 &transferVec)
Definition: wallBoundaryContactSearch.cpp:24
pFlow::BASE_MIRROR_WALL_INDEX
const uint32 BASE_MIRROR_WALL_INDEX
Definition: contactSearchGlobals.hpp:37
pFlow::unsortedPairs::increaseCapacityBy
INLINE_FUNCTION_H void increaseCapacityBy(uint32 len)
increase the capacity of the container by at-least len the content will be erased.
Definition: unsortedPairs.hpp:193
pFlow::wallBoundaryContactSearch::broadSearch
bool broadSearch(csPairContainerType &pairs, const cells &searchCells, const deviceScatteredFieldAccess< realx3 > &thisPoints, const deviceScatteredFieldAccess< real > &thisDiams, const deviceScatteredFieldAccess< realx3 > &mirrorPoints, const deviceScatteredFieldAccess< real > &mirroDiams, const realx3 &transferVec, real sizeRatio)
Definition: wallBoundaryContactSearch.cpp:50
streams.hpp
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::wallBoundaryContactSearch::elementBox_
ViewType1D< iBoxType, memory_space > elementBox_
Definition: wallBoundaryContactSearch.hpp:67
pFlow::cells::pointIndex
INLINE_FUNCTION_HD int32x3 pointIndex(const realx3 &p) const
Definition: cells.hpp:133
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::deviceRPolicyDynamic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Dynamic >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyDynamic
Definition: KokkosTypes.hpp:76
pFlow::deviceRPolicyStatic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyStatic
Definition: KokkosTypes.hpp:66
pFlow::wallBoundaryContactSearch::numElements_
uint32 numElements_
Definition: wallBoundaryContactSearch.hpp:52
pFlow::scatteredFieldAccess::empty
INLINE_FUNCTION_HD bool empty() const
Definition: scatteredFieldAccess.hpp:140
pFlow::cells
Definition: cells.hpp:31
pFlow::triple< real >
pFlow::wallBoundaryContactSearch::validBox_
ViewType1D< uint8, memory_space > validBox_
Definition: wallBoundaryContactSearch.hpp:69
pFlow::wallBoundaryContactSearch::points_
ViewType1D< realx3, memory_space > points_
Definition: wallBoundaryContactSearch.hpp:61
END_INFO
#define END_INFO
Definition: streams.hpp:37
INFORMATION
#define INFORMATION
Definition: streams.hpp:36