# PhasicFlow: src/Interaction/contactSearch/methods/cellBased/NBS/cellsWallLevel0.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.

cellsWallLevel0.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 "cellsWallLevel0.hpp"
#include "streams.hpp"
pFlow::cellsWallLevel0::cellsWallLevel0
(
real cellExtent,
uint32 numPoints,
uint32 numElements,
const ViewType1D<realx3, memory_space> &points,
const ViewType1D<uint32x3, memory_space> &vertices,
const ViewType1D<realx3, memory_space>& normals
)
:
cellExtent_( max(cellExtent, 0.5 ) ),
numElements_(numElements),
numPoints_(numPoints),
vertices_(vertices),
points_(points),
normals_(normals)
{
allocateArrays();
}
bool pFlow::cellsWallLevel0::resetElements
(
uint32 numElements,
uint32 numPoints,
const ViewType1D<realx3, memory_space>& points,
const ViewType1D<uint32x3, memory_space>& vertices,
const ViewType1D<realx3, memory_space>& normals
)
{
numElements_ = numElements;
numPoints_ = numPoints;
points_ = points;
vertices_ = vertices;
normals_ = normals;
allocateArrays();
return true;
}
bool pFlow::cellsWallLevel0::broadSearch
(
csPairContainerType &pairs,
const cells& searchBox,
const mapperNBS::CellIterator &particleMap,
const deviceViewType1D<realx3>& pPoints,
const deviceViewType1D<real>& pDiams,
real sizeRatio
)
{
// map walls onto the cells
this->build(searchBox);
this->particleWallFindPairs(pairs, particleMap, pPoints, pDiams, sizeRatio);
return true;
}
bool pFlow::cellsWallLevel0::build(const cells & searchBox)
{
const auto& points = points_;
const auto& vertices = vertices_;
const auto& elementBox = elementBox_;
const auto cellExtent = cellExtent_;
Kokkos::parallel_for(
"pFlow::cellsWallLevel0::build",
deviceRPolicyStatic(0,numElements_),
LAMBDA_HD(uint32 i)
{
auto v = vertices[i];
auto p1 = points[v.x()];
auto p2 = points[v.y()];
auto p3 = points[v.z()];
realx3 minP;
realx3 maxP;
searchBox.extendBox(p1, p2, p3, cellExtent, minP, maxP);
elementBox[i] = iBoxType(searchBox.pointIndex(minP), searchBox.pointIndex(maxP));
});
Kokkos::fence();
return true;
}
bool pFlow::cellsWallLevel0::particleWallFindPairs
(
csPairContainerType &pairs,
const mapperNBS::CellIterator &particleMap,
const deviceViewType1D<realx3>& pPoints,
const deviceViewType1D<real>& pDiams,
real sizeRatio
)
{
uint32 getFull = 1;
while (getFull)
{
getFull = findPairsElementRangeCount(pairs, particleMap, pPoints, pDiams, sizeRatio);
if(getFull)
{
// - resize the container
// note that getFull now shows the number of failed insertions.
uint32 len = max(getFull, 50u);
auto oldCap = pairs.capacity();
pairs.increaseCapacityBy(len);
INFORMATION<<"Contact pair container capacity increased from "<<
oldCap << " to "
<< pairs.capacity() <<" in cellsWallLevel0."<<END_INFO;
Kokkos::fence();
}
}
return true;
}
pFlow::int32 pFlow::cellsWallLevel0::findPairsElementRangeCount
(
csPairContainerType &pairs,
const mapperNBS::CellIterator &particleMap,
const deviceViewType1D<realx3>& pPoints,
const deviceViewType1D<real>& pDiams,
real sizeRatio
)
{
uint32 getFull =0;
const auto& elementBox = elementBox_;
const auto& normals = normals_;
const auto& points = points_;
const auto& vertices = vertices_;
const auto cellExtent = cellExtent_;
Kokkos::parallel_reduce(
"pFlow::cellsWallLevel0::findPairsElementRangeCount",
tpPWContactSearch(numElements_, Kokkos::AUTO),
LAMBDA_HD(
const typename tpPWContactSearch::member_type & teamMember,
uint32& valueToUpdate){
const uint32 iTri = teamMember.league_rank();
const auto triBox = elementBox[iTri];
const auto triPlane = infinitePlane(
normals[iTri],
points[vertices[iTri].x()]);
uint32 getFull2 = 0;
auto bExtent = boxExtent(triBox);
uint32 numCellBox = bExtent.x()*bExtent.y()*bExtent.z();
Kokkos::parallel_reduce(
Kokkos::TeamThreadRange( teamMember, numCellBox ),
[&] ( const uint32 linIndex, uint32 &innerUpdate )
{
int32x3 cell;
indexToCell(linIndex, triBox, cell);
uint32 n = particleMap.start(cell.x(),cell.y(),cell.z());
while( n != particleMap.NoPos)
{
// id is wall id the pair is (particle id, wall id)
if( abs(triPlane.pointFromPlane(pPoints[n]))< pDiams[n]*sizeRatio*cellExtent)
{
if( pairs.insert(
static_cast< csIdType >(n),
static_cast< csIdType >(iTri) ) == static_cast< csIdType >(-1)
)
innerUpdate++;
}
n = particleMap.next(n);
}
},
getFull2
);
if ( teamMember.team_rank() == 0 ) valueToUpdate += getFull2;
},
getFull
);
return getFull;
}
pFlow::mapperNBS::CellIterator::next
INLINE_FUNCTION_HD uint32 next(uint32 n) const
Definition: mapperNBS.hpp:76
pFlow::cellsWallLevel0::cellsWallLevel0
INLINE_FUNCTION_HD cellsWallLevel0()
Definition: cellsWallLevel0.hpp:86
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::cellsWallLevel0::cellExtent_
real cellExtent_
Definition: cellsWallLevel0.hpp:49
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::csIdType
uint32 csIdType
Definition: contactSearchGlobals.hpp:32
pFlow::cellsWallLevel0::elementBox_
ViewType1D< iBoxType, memory_space > elementBox_
Definition: cellsWallLevel0.hpp:67
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::indexToCell
INLINE_FUNCTION_HD void indexToCell(const indexType idx, const triple< cellIndexType > &extent, triple< cellIndexType > &cell)
Definition: contactSearchFunctions.hpp:71
pFlow::infinitePlane
Definition: infinitePlane.hpp:32
pFlow::cellsWallLevel0::numElements_
uint32 numElements_
Definition: cellsWallLevel0.hpp:52
pFlow::unsortedPairs::insert
INLINE_FUNCTION_HD uint32 insert(idType i, idType j) const
Definition: unsortedPairs.hpp:105
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
cellsWallLevel0.hpp
pFlow::mapperNBS::CellIterator
Definition: mapperNBS.hpp:45
pFlow::cellsWallLevel0::iBoxType
iBox< int32 > iBoxType
Definition: cellsWallLevel0.hpp:42
pFlow::cellsWallLevel0::points_
ViewType1D< realx3, memory_space > points_
Definition: cellsWallLevel0.hpp:61
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::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow::unsortedPairs
Definition: unsortedPairs.hpp:32
pFlow::cellsWallLevel0::tpPWContactSearch
Kokkos::TeamPolicy< execution_space, Kokkos::Schedule< Kokkos::Dynamic >, Kokkos::IndexType< uint32 > > tpPWContactSearch
Definition: cellsWallLevel0.hpp:73
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
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::boxExtent
INLINE_FUNCTION_HD triple< cellIndexType > boxExtent(const iBox< cellIndexType > &box)
Definition: contactSearchFunctions.hpp:82
pFlow::mapperNBS::CellIterator::start
INLINE_FUNCTION_HD uint32 start(int32 i, int32 j, int32 k) const
Definition: mapperNBS.hpp:67
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
streams.hpp
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::cellsWallLevel0::elementBox
INLINE_FUNCTION_HD iBoxType elementBox(uint32 i) const
Definition: cellsWallLevel0.hpp:110
pFlow::cells::pointIndex
INLINE_FUNCTION_HD int32x3 pointIndex(const realx3 &p) const
Definition: cells.hpp:133
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::mapperNBS::CellIterator::NoPos
static constexpr uint32 NoPos
Definition: mapperNBS.hpp:60
pFlow::cellsWallLevel0::findPairsElementRangeCount
int32 findPairsElementRangeCount(csPairContainerType &pairs, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:151
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::cellsWallLevel0::build
bool build(const cells &searchBox)
Definition: cellsWallLevel0.cpp:85
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
pFlow::cells
Definition: cells.hpp:31
pFlow::triple< real >
END_INFO
#define END_INFO
Definition: streams.hpp:37
INFORMATION
#define INFORMATION
Definition: streams.hpp:36
pFlow::cellsWallLevel0::resetElements
bool resetElements(uint32 numElements, uint32 numPoints, const ViewType1D< realx3, memory_space > &points, const ViewType1D< uint32x3, memory_space > &vertices, const ViewType1D< realx3, memory_space > &normals)
Definition: cellsWallLevel0.cpp:45
pFlow::cellsWallLevel0::broadSearch
bool broadSearch(csPairContainerType &pairs, const cells &searchBox, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:66
pFlow::cellsWallLevel0::vertices_
ViewType1D< uint32x3, memory_space > vertices_
Definition: cellsWallLevel0.hpp:58
pFlow::cellsWallLevel0::particleWallFindPairs
bool particleWallFindPairs(csPairContainerType &pairs, const mapperNBS::CellIterator &particleMap, const deviceViewType1D< realx3 > &pPoints, const deviceViewType1D< real > &pDiams, real sizeRatio)
Definition: cellsWallLevel0.cpp:115