# PhasicFlow: src/phasicFlow/structuredData/pointStructure/pointStructure/pointSorting/mortonIndexing.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

mortonIndexing.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "mortonIndexing.hpp"
#include "cells.hpp"
pFlow::uint32IndexContainer pFlow::getSortedIndices(
box boundingBox,
real dx,
const ViewType1D<realx3>& pos,
const pFlagTypeDevice& flag
)
{
if(flag.numActive() == 0u)return uint32IndexContainer();
// obtain the morton code of the particles
cells allCells( boundingBox, dx);
auto aRange = flag.activeRange();
uint32IndexContainer sortedIndex(aRange.start(), aRange.end());
ViewType1D<uint64_t> mortonCode("mortonCode", aRange.end());
Kokkos::parallel_for
(
"mortonIndexing::getIndex::morton",
deviceRPolicyStatic(aRange.start(), aRange.end()),
LAMBDA_HD(uint32 i){
if( flag.isActive(i)) // active point
{
auto cellInd = allCells.pointIndex(pos[i]);
mortonCode[i] = xyzToMortonCode64(cellInd.x(), cellInd.y(), cellInd.z());
}else
{
mortonCode[i] = xyzToMortonCode64
(
largestPosInt32,
largestPosInt32,
largestPosInt32
);
}
}
);
Kokkos::fence();
permuteSort(
mortonCode,
aRange.start(),
aRange.end(),
sortedIndex.deviceView(),
0 );
sortedIndex.modifyOnDevice();
sortedIndex.syncViews(flag.numActive());
return sortedIndex;
}
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