mortonIndexing.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 "mortonIndexing.hpp"
22 #include "cells.hpp"
23 
24 #include "streams.hpp"
25 
27  box boundingBox,
28  real dx,
29  range activeRange,
30  ViewType1D<realx3> pos,
31  ViewType1D<int8> flag,
32  int32IndexContainer& sortedIndex)
33 {
34 
35  // obtain the morton code of the particles
36  cells<size_t> allCells( boundingBox, dx);
37  int32IndexContainer index(activeRange.first, activeRange.second);
38 
39  ViewType1D<uint64_t> mortonCode("mortonCode", activeRange.second);
40 
41  output<<"before first kernel"<<endl;;
42 
43  using rpMorton =
44  Kokkos::RangePolicy<Kokkos::IndexType<int32>>;
45  int32 numActive = 0;
46  Kokkos::parallel_reduce
47  (
48  "mortonIndexing::getIndex::morton",
49  rpMorton(activeRange.first, activeRange.second),
50  LAMBDA_HD(int32 i, int32& sumToUpdate){
51  if( flag[i] == 1 ) // active point
52  {
53  auto cellInd = allCells.pointIndex(pos[i]);
54  mortonCode[i] = xyzToMortonCode64(cellInd.x(), cellInd.y(), cellInd.z());
55  sumToUpdate++;
56  }else
57  {
58  mortonCode[i] = xyzToMortonCode64
59  (
60  static_cast<uint64_t>(-1),
61  static_cast<uint64_t>(-1),
62  static_cast<uint64_t>(-1)
63  );
64  }
65  },
66  numActive
67  );
68 
70  mortonCode,
71  activeRange.first,
72  activeRange.second,
73  index.deviceView(),
74  0 );
75  index.modifyOnDevice();
76  index.setSize(numActive);
77  index.syncViews();
78 
79  sortedIndex = index;
80 
81  return true;
82 }
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::range
kRange< int > range
Definition: KokkosTypes.hpp:59
pFlow::indexContainer::syncViews
void syncViews()
Definition: indexContainer.hpp:191
pFlow::getSortedIndex
bool getSortedIndex(box boundingBox, real dx, range activeRange, ViewType1D< realx3 > pos, ViewType1D< int8 > flag, int32IndexContainer &sortedIndex)
Definition: mortonIndexing.cpp:26
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:320
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::indexContainer::setSize
size_t setSize(size_t ns)
Definition: indexContainer.hpp:212
pFlow::output
Ostream output
pFlow::indexContainer::modifyOnDevice
void modifyOnDevice()
Definition: indexContainer.hpp:186
pFlow::xyzToMortonCode64
INLINE_FUNCTION_HD uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
Definition: contactSearchFunctions.hpp:42
streams.hpp
pFlow::algorithms::STD::permuteSort
INLINE_FUNCTION_H void permuteSort(const Type *first, PermuteType *pFirst, int32 numElems)
Definition: stdAlgorithms.hpp:188
pFlow::box
Definition: box.hpp:32
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:67
mortonIndexing.hpp
pFlow::cells
Definition: cells.hpp:32
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
pFlow::indexContainer< int32 >
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Definition: indexContainer.hpp:156