# PhasicFlow: src/Interaction/contactSearch/methods/NBSLevel0.hpp Source File

NBSLevel0.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 __NBSLevel0_hpp__
#define __NBSLevel0_hpp__
#include "mapperNBS.hpp"
namespace pFlow
{
template<typename executionSpace>
class NBSLevel0
:
public mapperNBS<executionSpace>
{
public:
using MapperType = mapperNBS<executionSpace>;
using cellIterator = typename MapperType::cellIterator;
using IdType = typename MapperType::IdType;
using IndexType = typename MapperType::IndexType;
using Cells = typename MapperType::Cells;
using CellType = typename Cells::CellType;
using execution_space = typename MapperType::execution_space;
using memory_space = typename MapperType::memory_space;
using HeadType = typename MapperType::HeadType;
using NextType = typename MapperType::NextType;
struct TagFindPairs{};
protected:
real sizeRatio_ = 1.0;
// borrowed ownership
ViewType1D<real, memory_space> diameter_;
using mdrPolicyFindPairs =
Kokkos::MDRangePolicy<
Kokkos::Rank<3>,
Kokkos::Schedule<Kokkos::Dynamic>,
execution_space>;
static INLINE_FUNCTION_HD
void Swap(int32& x, int32& y)
{
int32 tmp = x;
x = y;
y = tmp;
}
public:
TypeInfoNV("NBSLevel0");
INLINE_FUNCTION_HD
NBSLevel0(){}
NBSLevel0(
const box& domain,
real cellSize,
const ViewType1D<realx3, memory_space>& position,
const ViewType1D<real, memory_space>& diam)
:
MapperType(domain, cellSize, position),
diameter_(diam)
{}
NBSLevel0(
const box& domain,
int32 nx,
int32 ny,
int32 nz,
const ViewType1D<realx3, memory_space>& position,
const ViewType1D<real, memory_space>& diam)
:
MapperType(domain, nx, ny, nz, position),
diameter_(diam)
{ }
NBSLevel0(
const box& domain,
real cellSize,
real sizeRatio,
const ViewType1D<realx3, memory_space>& position,
const ViewType1D<real, memory_space>& diam,
bool nextOwner = true)
:
MapperType(domain, cellSize, position, nextOwner),
sizeRatio_(sizeRatio),
diameter_(diam)
{}
INLINE_FUNCTION_HD
NBSLevel0(const NBSLevel0&) = default;
INLINE_FUNCTION_HD
NBSLevel0& operator = (const NBSLevel0&) = default;
INLINE_FUNCTION_HD
~NBSLevel0()=default;
INLINE_FUNCTION_HD
auto sizeRatio()const
{
return sizeRatio_;
}
INLINE_FUNCTION_HD
auto& diameter()
{
return diameter_;
}
// - Perform the broad search to find pairs
// with force = true, perform broad search regardless of
// updateFrequency_ value
// on all the points in the range of [0,numPoints_)
template<typename PairsContainer>
bool broadSearch(PairsContainer& pairs, range activeRange)
{
this->build(activeRange);
findPairs(pairs);
return true;
}
// - Perform the broad search to find pairs,
// ignore particles with incld(i) = true,
// with force = true, perform broad search regardless of
// updateFrequency_ value
template<typename PairsContainer, typename IncludeFunction>
bool broadSearch(PairsContainer& pairs, range activeRange, IncludeFunction incld)
{
this->build(activeRange, incld);
findPairs(pairs);
return true;
}
template<typename PairsContainer>
INLINE_FUNCTION_H
bool findPairs(PairsContainer& pairs)
{
int32 getFull = 1;
// loop until the container size fits the numebr of contact pairs
while (getFull > 0)
{
getFull = findPairsCount(pairs);
if(getFull)
{
// - resize the container
// note that getFull now shows the number of failed insertions.
uint32 len = max(getFull,500) ;
auto oldCap = pairs.capacity();
pairs.increaseCapacityBy(len);
INFORMATION<< "The contact pair container capacity increased from "<<
oldCap << " to "<<pairs.capacity()<<" in NBSLevel0."<<endINFO;
}
Kokkos::fence();
}
return true;
}
template<typename PairsContainer>
INLINE_FUNCTION_H
int32 findPairsCount(PairsContainer& pairs)
{
mdrPolicyFindPairs
mdrPolicy(
{0,0,0},
{this->nx(),this->ny(),this->nz()} );
int32 notInsertedPairs;
Kokkos::parallel_reduce (
"NBSLevel0::findPairs",
mdrPolicy,
CLASS_LAMBDA_HD(int32 i, int32 j, int32 k, int32& getFullUpdate){
#include "NBSLoop.hpp"
}, notInsertedPairs);
return notInsertedPairs;
}
};
} // pFlow
#endif // __NBSLevel0_hpp__
pFlow::cells< int32 >::nz
INLINE_FUNCTION_HD int32 nz() const
Definition: cells.hpp:139
pFlow::NBSLevel0::~NBSLevel0
INLINE_FUNCTION_HD ~NBSLevel0()=default
mapperNBS.hpp
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevel0
Definition: NBSLevel0.hpp:32
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::NBSLevel0::cellIterator
typename MapperType::cellIterator cellIterator
Definition: NBSLevel0.hpp:40
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, real cellSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBSLevel0.hpp:90
pFlow::cells< int32 >::nx
INLINE_FUNCTION_HD int32 nx() const
Definition: cells.hpp:127
pFlow::NBSLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange)
Definition: NBSLevel0.hpp:152
pFlow::mapperNBS::NextType
ViewType1D< int32, memory_space > NextType
Definition: mapperNBS.hpp:54
pFlow::mapperNBS
Definition: mapperNBS.hpp:34
pFlow
Definition: demComponent.hpp:28
pFlow::NBSLevel0::TypeInfoNV
TypeInfoNV("NBSLevel0")
pFlow::NBSLevel0::TagFindPairs
Definition: NBSLevel0.hpp:58
pFlow::NBSLevel0::sizeRatio
INLINE_FUNCTION_HD auto sizeRatio() const
Definition: NBSLevel0.hpp:136
pFlow::NBSLevel0::operator=
INLINE_FUNCTION_HD NBSLevel0 & operator=(const NBSLevel0 &)=default
pFlow::mapperNBS::IdType
int32 IdType
Definition: mapperNBS.hpp:40
CLASS_LAMBDA_HD
#define CLASS_LAMBDA_HD
Definition: pFlowMacros.hpp:56
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cells< int32 >::domain
const auto & domain() const
Definition: cells.hpp:152
pFlow::mapperNBS::IndexType
int32 IndexType
Definition: mapperNBS.hpp:42
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, real cellSize, real sizeRatio, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam, bool nextOwner=true)
Definition: NBSLevel0.hpp:112
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::NBSLevel0::sizeRatio_
real sizeRatio_
Definition: NBSLevel0.hpp:63
pFlow::mapperNBS::CellType
typename Cells::CellType CellType
Definition: mapperNBS.hpp:46
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::mapperNBS::HeadType
ViewType3D< int32, memory_space > HeadType
Definition: mapperNBS.hpp:52
pFlow::mapperNBS::execution_space
executionSpace execution_space
Definition: mapperNBS.hpp:48
pFlow::mapperNBS::cellIterator
Definition: mapperNBS.hpp:56
pFlow::box
Definition: box.hpp:32
pFlow::mapperNBS::Cells
cells< IndexType > Cells
Definition: mapperNBS.hpp:44
pFlow::NBSLevel0::NBSLevel0
INLINE_FUNCTION_HD NBSLevel0()
Definition: NBSLevel0.hpp:88
pFlow::NBSLevel0::findPairsCount
INLINE_FUNCTION_H int32 findPairsCount(PairsContainer &pairs)
Definition: NBSLevel0.hpp:216
pFlow::cells< int32 >::ny
INLINE_FUNCTION_HD int32 ny() const
Definition: cells.hpp:133
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::cells< int32 >::cellSize
INLINE_FUNCTION_HD realx3 cellSize() const
Definition: cells.hpp:115
pFlow::NBSLevel0::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevel0.hpp:180
pFlow::NBSLevel0::Swap
static INLINE_FUNCTION_HD void Swap(int32 &x, int32 &y)
Definition: NBSLevel0.hpp:76
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< indexType >
pFlow::NBSLevel0::diameter
INLINE_FUNCTION_HD auto & diameter()
Definition: NBSLevel0.hpp:142
pFlow::mapperNBS::memory_space
typename execution_space::memory_space memory_space
Definition: mapperNBS.hpp:50
pFlow::NBSLevel0::NBSLevel0
NBSLevel0(const box &domain, int32 nx, int32 ny, int32 nz, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBSLevel0.hpp:100
endINFO
#define endINFO
Definition: streams.hpp:38
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: mapperNBS.hpp:274
NBSLoop.hpp
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::NBSLevel0::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld)
Definition: NBSLevel0.hpp:168
INFORMATION
#define INFORMATION
Definition: streams.hpp:37
pFlow::NBSLevel0::mdrPolicyFindPairs
Kokkos::MDRangePolicy< Kokkos::Rank< 3 >, Kokkos::Schedule< Kokkos::Dynamic >, execution_space > mdrPolicyFindPairs
Definition: NBSLevel0.hpp:73
pFlow::NBSLevel0::diameter_
ViewType1D< real, memory_space > diameter_
Definition: NBSLevel0.hpp:66