# PhasicFlow: src/Interaction/contactSearch/wallMappings/cellsWallLevel0.hpp Source File

cellsWallLevel0.hpp
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.
-----------------------------------------------------------------------------*/
#ifndef __cellsWallLevel0_hpp__
#define __cellsWallLevel0_hpp__
#include "types.hpp"
#include "KokkosTypes.hpp"
#include "cells.hpp"
#include "iBox.hpp"
namespace pFlow
{
template<
typename executionSpace
>
class cellsWallLevel0
:
public cells<int32>
{
public:
using IdType = int32;
using IndexType = int32;
using Cells = cells<IndexType>;
using CellType = typename Cells::CellType;
using execution_space = executionSpace;
using memory_space = typename execution_space::memory_space;
using iBoxType = iBox<IndexType>;
class TagFindCellRange2{};
protected:
// - box extent
real cellExtent_ = 0.5;
// - number of triangle elements
int32 numElements_ = 0;
// - number of points
int32 numPoints_ = 0;
// - ref to vectices (borrowed)
ViewType1D<int32x3, memory_space> vertices_;
// - ref to points in the trisurface (borrowed)
ViewType1D<realx3, memory_space> points_;
// cell range of element/triangle bounding box
ViewType1D<iBoxType, memory_space> elementBox_;
using tpPWContactSearch = Kokkos::TeamPolicy<
execution_space,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<int32>
>;
using rpFindCellRange2Type =
Kokkos::RangePolicy<TagFindCellRange2, execution_space, Kokkos::IndexType<int32>>;
FUNCTION_H
void allocateArrays()
{
reallocNoInit( elementBox_, numElements_);
}
public:
TypeInfoNV("cellsWallLevel0");
INLINE_FUNCTION_HD
cellsWallLevel0(){}
FUNCTION_H
cellsWallLevel0(
const Cells& ppCells,
real cellExtent,
int32 numPoints,
int32 numElements,
const ViewType1D<realx3,memory_space>& points,
const ViewType1D<int32x3,memory_space>& vertices
)
:
Cells(ppCells),
cellExtent_( max(cellExtent, 0.5 ) ),
numElements_(numElements),
numPoints_(numPoints),
vertices_(vertices),
points_(points)
{
allocateArrays();
}
// - host call
// reset triangle elements if they have changed
bool resetElements(
int32 numElements,
int32 numPoints,
ViewType1D<realx3, memory_space>& points,
ViewType1D<int32x3, memory_space>& vertices )
{
numElements_ = numElements;
numPoints_ = numPoints;
points_ = points;
vertices_ = vertices;
allocateArrays();
return true;
}
INLINE_FUNCTION_HD
iBoxType elementBox(int32 i)const
{
return elementBox_[i];
}
INLINE_FUNCTION_HD
int32 numElements()const
{
return numElements_;
}
template<typename PairsContainer, typename particleMapType>
bool broadSearch(PairsContainer& pairs, particleMapType& particleMap)
{
// map walls onto the cells
this->build();
this->particleWallFindPairs(pairs, particleMap);
return true;
}
bool build()
{
Kokkos::parallel_for(
"cellsSimple::findcellrange2",
rpFindCellRange2Type(0,numElements_),
*this);
Kokkos::fence();
return true;
}
template<typename PairsContainer, typename particleMapType>
bool particleWallFindPairs(PairsContainer& pairs, particleMapType& particleMap)
{
int32 getFull = 1;
while (getFull)
{
getFull = findPairsElementRangeCount(pairs, particleMap.getCellIterator(0));
if(getFull)
{
// - resize the container
// note that getFull now shows the number of failed insertions.
uint32 len = max(getFull, 50);
auto oldCap = pairs.capacity();
pairs.increaseCapacityBy(len);
INFORMATION<<"Contact pair container capacity increased from "<<
oldCap << " to "
<< pairs.capacity() <<" in cellsWallLevel0."<<endINFO;
Kokkos::fence();
}
}
return true;
}
template<typename PairsContainer, typename CellIteratorType>
int32 findPairsElementRangeCount(PairsContainer& pairs, CellIteratorType cellIter)
{
int32 getFull =0;
const auto pwPairs = pairs;
const auto elementBox = elementBox_;
Kokkos::parallel_reduce(
"cellsSimple::findPairsElementRangeModified2",
tpPWContactSearch(numElements_, Kokkos::AUTO),
LAMBDA_HD(
const typename tpPWContactSearch::member_type & teamMember,
int32& valueToUpdate){
const int32 iTri = teamMember.league_rank();
const auto triBox = elementBox[iTri];
int32 getFull2 = 0;
auto bExtent = boxExtent(triBox);
int32 numCellBox = bExtent.x()*bExtent.y()*bExtent.z();
Kokkos::parallel_reduce(
Kokkos::TeamThreadRange( teamMember, numCellBox ),
[&] ( const int32 linIndex, int32 &innerUpdate )
{
CellType cell;
indexToCell(linIndex, triBox, cell);
int32 n = cellIter.start(cell.x(),cell.y(),cell.z());
while( n>-1)
{
// id is wall id the pair is (particle id, wall id)
if( pairs.insert(static_cast< IdType >(n), iTri) < 0 )
innerUpdate++;
n = cellIter.getNext(n);
}
},
getFull2
);
if ( teamMember.team_rank() == 0 ) valueToUpdate += getFull2;
},
getFull
);
return getFull;
}
INLINE_FUNCTION_HD
void operator()(TagFindCellRange2, int32 i) const
{
auto v = vertices_[i];
auto p1 = points_[v.x()];
auto p2 = points_[v.y()];
auto p3 = points_[v.z()];
realx3 minP, maxP;
this->extendBox(p1, p2, p3, cellExtent_, minP, maxP);
elementBox_[i] = iBoxType(this->pointIndex(minP), this->pointIndex(maxP));
}
}; // cellsWallLevel0
} // pFlow
#endif // __cellsWallLevel0_hpp__
pFlow::cellsWallLevel0::IndexType
int32 IndexType
Definition: cellsWallLevel0.hpp:45
pFlow::cellsWallLevel0::cellsWallLevel0
INLINE_FUNCTION_HD cellsWallLevel0()
Definition: cellsWallLevel0.hpp:101
pFlow::cellsWallLevel0::cellExtent_
real cellExtent_
Definition: cellsWallLevel0.hpp:62
pFlow::cellsWallLevel0::rpFindCellRange2Type
Kokkos::RangePolicy< TagFindCellRange2, execution_space, Kokkos::IndexType< int32 > > rpFindCellRange2Type
Definition: cellsWallLevel0.hpp:87
pFlow::real
float real
Definition: builtinTypes.hpp:46
types.hpp
pFlow::cellsWallLevel0::elementBox_
ViewType1D< iBoxType, memory_space > elementBox_
Definition: cellsWallLevel0.hpp:77
pFlow::indexToCell
INLINE_FUNCTION_HD void indexToCell(const indexType idx, const triple< cellIndexType > &extent, triple< cellIndexType > &cell)
Definition: contactSearchFunctions.hpp:71
pFlow::cellsWallLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, particleMapType &particleMap)
Definition: cellsWallLevel0.hpp:159
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::cellsWallLevel0::numPoints_
int32 numPoints_
Definition: cellsWallLevel0.hpp:68
pFlow::cellsWallLevel0::CellType
typename Cells::CellType CellType
Definition: cellsWallLevel0.hpp:49
KokkosTypes.hpp
pFlow::cellsWallLevel0::IdType
int32 IdType
Definition: cellsWallLevel0.hpp:43
pFlow::cells< int32 >::extendBox
INLINE_FUNCTION_HD void extendBox(const CellType &p1, const CellType &p2, const CellType &p3, int32 extent, CellType &minP, CellType &maxP) const
Definition: cells.hpp:203
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
pFlow::cellsWallLevel0::points_
ViewType1D< realx3, memory_space > points_
Definition: cellsWallLevel0.hpp:74
pFlow::cellsWallLevel0::numElements
INLINE_FUNCTION_HD int32 numElements() const
Definition: cellsWallLevel0.hpp:151
pFlow
Definition: demComponent.hpp:28
pFlow::cells::CellType
triple< indexType > CellType
Definition: cells.hpp:36
pFlow::cellsWallLevel0::particleWallFindPairs
bool particleWallFindPairs(PairsContainer &pairs, particleMapType &particleMap)
Definition: cellsWallLevel0.hpp:181
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::cellsWallLevel0::execution_space
executionSpace execution_space
Definition: cellsWallLevel0.hpp:51
iBox.hpp
pFlow::cellsWallLevel0::TypeInfoNV
TypeInfoNV("cellsWallLevel0")
pFlow::cellsWallLevel0::iBoxType
iBox< IndexType > iBoxType
Definition: cellsWallLevel0.hpp:55
pFlow::cellsWallLevel0::TagFindCellRange2
Definition: cellsWallLevel0.hpp:57
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::cellsWallLevel0::resetElements
bool resetElements(int32 numElements, int32 numPoints, ViewType1D< realx3, memory_space > &points, ViewType1D< int32x3, memory_space > &vertices)
Definition: cellsWallLevel0.hpp:127
pFlow::cellsWallLevel0::elementBox
INLINE_FUNCTION_HD iBoxType elementBox(int32 i) const
Definition: cellsWallLevel0.hpp:145
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cellsWallLevel0::memory_space
typename execution_space::memory_space memory_space
Definition: cellsWallLevel0.hpp:53
pFlow::cellsWallLevel0::operator()
INLINE_FUNCTION_HD void operator()(TagFindCellRange2, int32 i) const
Definition: cellsWallLevel0.hpp:266
pFlow::boxExtent
INLINE_FUNCTION_HD triple< cellIndexType > boxExtent(const iBox< cellIndexType > &box)
Definition: contactSearchFunctions.hpp:82
pFlow::cellsWallLevel0::tpPWContactSearch
Kokkos::TeamPolicy< execution_space, Kokkos::Schedule< Kokkos::Dynamic >, Kokkos::IndexType< int32 > > tpPWContactSearch
Definition: cellsWallLevel0.hpp:84
cells.hpp
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::cellsWallLevel0::findPairsElementRangeCount
int32 findPairsElementRangeCount(PairsContainer &pairs, CellIteratorType cellIter)
Definition: cellsWallLevel0.hpp:212
pFlow::cellsWallLevel0::numElements_
int32 numElements_
Definition: cellsWallLevel0.hpp:65
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::cellsWallLevel0
Definition: cellsWallLevel0.hpp:37
pFlow::iBox
Definition: iBox.hpp:33
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< real >
pFlow::cells< int32 >::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
endINFO
#define endINFO
Definition: streams.hpp:38
pFlow::cellsWallLevel0::cellsWallLevel0
FUNCTION_H cellsWallLevel0(const Cells &ppCells, real cellExtent, int32 numPoints, int32 numElements, const ViewType1D< realx3, memory_space > &points, const ViewType1D< int32x3, memory_space > &vertices)
Definition: cellsWallLevel0.hpp:104
INFORMATION
#define INFORMATION
Definition: streams.hpp:37
pFlow::cellsWallLevel0::vertices_
ViewType1D< int32x3, memory_space > vertices_
Definition: cellsWallLevel0.hpp:71
pFlow::cellsWallLevel0::allocateArrays
FUNCTION_H void allocateArrays()
Definition: cellsWallLevel0.hpp:91
pFlow::cellsWallLevel0::build
bool build()
Definition: cellsWallLevel0.hpp:170