www.cemf.ir
boundaryBaseKernels.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 "boundaryBaseKernels.hpp"
22 
24 (
25  uint32 numTotal,
26  uint32 numRemove,
27  const uint32Vector_D& removeMask,
28  uint32Vector_D& removeList,
29  uint32Vector_D& keepList
30 )
31 {
32  uint32 numKeep = numTotal - numRemove;
33  removeList.reallocate(numRemove,numRemove);
34  keepList.reallocate(numKeep,numKeep);
35 
36  auto maskD = removeMask.deviceViewAll();
37  const auto& removeD = removeList.deviceViewAll();
38  const auto& keepD = keepList.deviceViewAll();
39 
41  maskD,
42  0u,
43  numTotal+1,
44  maskD,
45  0u);
46 
47  Kokkos::parallel_for
48  (
49  "pFlow::boundaryBaseKernels::createRemoveKeepLists",
50  deviceRPolicyStatic(0, numTotal),
51  LAMBDA_HD(uint32 i)
52  {
53  if(maskD(i)!= maskD(i+1))
54  removeD(maskD(i)) = i;
55  else
56  keepD(i-maskD(i)) = i;
57  }
58  );
59  Kokkos::fence();
60 
61 }
62 
63 
65 (
66  const uint32Vector_D& indices,
67  uint32 numRemove,
68  const uint32Vector_D& removeMask,
69  uint32Vector_D& removeIndices,
70  uint32Vector_D& keepIndices,
71  bool exactCap
72 )
73 {
74  uint32 numTotal = indices.size();
75  uint32 numKeep = numTotal - numRemove;
76  if(exactCap)
77  {
78  removeIndices.reallocate(numRemove, numRemove);
79  keepIndices.reallocate(numKeep, numKeep);
80  }
81  else
82  {
83  removeIndices.clear();
84  removeIndices.resize(numRemove);
85 
86  keepIndices.clear();
87  keepIndices.resize(numKeep);
88  }
89 
90 
91  auto maskD = removeMask.deviceViewAll();
92  const auto& removeD = removeIndices.deviceViewAll();
93  const auto& keepD = keepIndices.deviceViewAll();
94  const auto& indicesD = indices.deviceViewAll();
95 
96  exclusiveScan(maskD, 0u, numTotal+1, maskD, 0u);
97 
98  Kokkos::parallel_for
99  (
100  "pFlow::boundaryBaseKernels::createRemoveKeepLists",
101  deviceRPolicyStatic(0, numTotal),
102  LAMBDA_HD(uint32 i)
103  {
104  if(maskD(i)!= maskD(i+1))
105  removeD(maskD(i)) = indicesD(i);
106  else
107  keepD(i-maskD(i)) = indicesD(i);
108  }
109  );
110  Kokkos::fence();
111 }
pFlow::VectorSingle::resize
INLINE_FUNCTION_H void resize(uint32 n)
Resize the vector and preserve the content.
Definition: VectorSingle.cpp:344
pFlow::VectorSingle::reallocate
INLINE_FUNCTION_H void reallocate(uint32 cap)
Reallocate memory to new cap and set size to 0.
Definition: VectorSingle.cpp:326
pFlow::VectorSingle::clear
INLINE_FUNCTION_H void clear()
Clear the vector, but keep the allocated memory unchanged.
Definition: VectorSingle.cpp:358
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::boundaryBaseKernels::createRemoveKeepLists
void createRemoveKeepLists(uint32 numTotal, uint32 numRemove, const uint32Vector_D &removeMask, uint32Vector_D &removeList, uint32Vector_D &keepList)
Definition: boundaryBaseKernels.cpp:24
boundaryBaseKernels.hpp
pFlow::algorithms::KOKKOS::exclusiveScan
void exclusiveScan(Type *first, Type *dFirst, uint32 numElems)
Definition: kokkosAlgorithms.hpp:148
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::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
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::VectorSingle::size
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
Definition: VectorSingle.cpp:297