www.cemf.ir
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 #include "mortonIndexing.hpp"
21 #include "cells.hpp"
22 
23 
25  box boundingBox,
26  real dx,
27  const ViewType1D<realx3>& pos,
28  const pFlagTypeDevice& flag
29 )
30 {
31  if(flag.numActive() == 0u)return uint32IndexContainer();
32 
33  // obtain the morton code of the particles
34  cells allCells( boundingBox, dx);
35  auto aRange = flag.activeRange();
36 
37  uint32IndexContainer sortedIndex(aRange.start(), aRange.end());
38 
39  ViewType1D<uint64_t> mortonCode("mortonCode", aRange.end());
40 
41 
42  Kokkos::parallel_for
43  (
44  "mortonIndexing::getIndex::morton",
45  deviceRPolicyStatic(aRange.start(), aRange.end()),
46  LAMBDA_HD(uint32 i){
47  if( flag.isActive(i)) // active point
48  {
49  auto cellInd = allCells.pointIndex(pos[i]);
50  mortonCode[i] = xyzToMortonCode64(cellInd.x(), cellInd.y(), cellInd.z());
51  }else
52  {
53  mortonCode[i] = xyzToMortonCode64
54  (
55  largestPosInt32,
56  largestPosInt32,
57  largestPosInt32
58  );
59  }
60  }
61  );
62 
63  Kokkos::fence();
64 
66  mortonCode,
67  aRange.start(),
68  aRange.end(),
69  sortedIndex.deviceView(),
70  0 );
71 
72  sortedIndex.modifyOnDevice();
73  sortedIndex.syncViews(flag.numActive());
74 
75  return sortedIndex;
76 }
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::pointFlag::numActive
INLINE_FUNCTION_HD auto numActive() const
Definition: pointFlag.hpp:191
pFlow::indexContainer::syncViews
void syncViews()
synchronize views
Definition: indexContainer.hpp:250
pFlow::uint32IndexContainer
indexContainer< uint32 > uint32IndexContainer
Definition: indexContainer.hpp:286
pFlow::getSortedIndices
uint32IndexContainer getSortedIndices(box boundingBox, real dx, const ViewType1D< realx3 > &pos, const pFlagTypeDevice &flag)
Definition: mortonIndexing.cpp:24
pFlow::pointFlag::isActive
INLINE_FUNCTION_HD bool isActive(uint32 i) const
Definition: pointFlag.hpp:240
pFlow::indexContainer::modifyOnDevice
void modifyOnDevice()
Mark device is modified.
Definition: indexContainer.hpp:244
pFlow::pointFlag::activeRange
const INLINE_FUNCTION_HD auto & activeRange() const
Definition: pointFlag.hpp:179
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
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:58
pFlow::deviceRPolicyStatic
Kokkos::RangePolicy< Kokkos::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > deviceRPolicyStatic
Definition: KokkosTypes.hpp:66
mortonIndexing.hpp
pFlow::cells
Definition: cells.hpp:31
pFlow::pointFlag< DefaultExecutionSpace >
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Return Device view.
Definition: indexContainer.hpp:208