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

NBS.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 __NBS_hpp__
#define __NBS_hpp__
#include "NBSLevel0.hpp"
namespace pFlow
{
template<typename executionSpace>
class NBS
{
public:
using NBSLevel0Type = NBSLevel0<executionSpace>;
using cellIterator = typename NBSLevel0Type::cellIterator;
using IdType = typename NBSLevel0Type::IdType;
using IndexType = typename NBSLevel0Type::IndexType;
using Cells = typename NBSLevel0Type::Cells;
using CellType = typename Cells::CellType;
using execution_space = typename NBSLevel0Type::execution_space;
using memory_space = typename NBSLevel0Type::memory_space;
protected:
real sizeRatio_ = 1.0;
int32 updateFrequency_= 1;
int32 currentIter_ = 0;
bool performedSearch_ = false;
NBSLevel0Type NBSLevel0_;
private:
bool performSearch()
{
if(currentIter_ % updateFrequency_ == 0)
{
currentIter_++;
return true;
}else
{
currentIter_++;
return false;
}
}
public:
TypeInfoNV("NBS");
NBS(
const dictionary& dict,
const box& domain,
real minSize,
real maxSize,
const ViewType1D<realx3, memory_space>& position,
const ViewType1D<real, memory_space>& diam)
:
sizeRatio_(
max(
dict.getValOrSet<real>("sizeRatio", 1.0),
1.0
)),
updateFrequency_(
max(
dict.getValOrSet<int32>("updateFrequency", 1),
1
)),
NBSLevel0_(
domain,
maxSize*sizeRatio_,
sizeRatio_,
position,
diam)
{}
INLINE_FUNCTION_HD
NBS(const NBS&) = default;
INLINE_FUNCTION_HD
NBS& operator = (const NBS&) = default;
INLINE_FUNCTION_HD
~NBS()=default;
bool enterBoadSearch()const
{
return currentIter_%updateFrequency_==0;
}
bool performedSearch()const
{
return performedSearch_;
}
Vector<cellIterator> getCellIteratorLevels()
{
return Vector<cellIterator>("cellIterator", 1, NBSLevel0_.getCellIterator());
}
auto getCellIterator(int32 lvl)const
{
return NBSLevel0_.getCellIterator();
}
int32 numLevels()const
{
return 1;
}
Vector<Cells> getCellsLevels()const
{
return Vector<Cells>("Cells", 1, NBSLevel0_.getCells());
}
auto getCells()const
{
return NBSLevel0_.getCells();
}
bool objectSizeChanged(int32 newSize)
{
NBSLevel0_.checkAllocateNext(newSize);
return true;
}
// - 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, bool force=false)
{
if(force) currentIter_ = 0;
performedSearch_ = false;
if( !performSearch() ) return true;
NBSLevel0_.build(activeRange);
NBSLevel0_.findPairs(pairs);
performedSearch_ = true;
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, bool force = false)
{
if(force) currentIter_ = 0;
performedSearch_ = false;
if( !performSearch() ) return true;
NBSLevel0_.build(activeRange, incld);
NBSLevel0_.findPairs(pairs);
performedSearch_ = true;
return true;
}
};
}
#endif
pFlow::NBS::sizeRatio_
real sizeRatio_
Definition: NBS.hpp:55
pFlow::NBS::objectSizeChanged
bool objectSizeChanged(int32 newSize)
Definition: NBS.hpp:157
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevel0
Definition: NBSLevel0.hpp:32
pFlow::NBS::getCellsLevels
Vector< Cells > getCellsLevels() const
Definition: NBS.hpp:147
pFlow::NBS::getCells
auto getCells() const
Definition: NBS.hpp:152
pFlow::NBS::updateFrequency_
int32 updateFrequency_
Definition: NBS.hpp:57
pFlow::NBS::NBS
NBS(const dictionary &dict, const box &domain, real minSize, real maxSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: NBS.hpp:85
pFlow::NBS::~NBS
INLINE_FUNCTION_HD ~NBS()=default
NBSLevel0.hpp
pFlow::NBS::CellType
typename Cells::CellType CellType
Definition: NBS.hpp:46
pFlow::NBS::execution_space
typename NBSLevel0Type::execution_space execution_space
Definition: NBS.hpp:48
pFlow::NBS::NBSLevel0_
NBSLevel0Type NBSLevel0_
Definition: NBS.hpp:63
pFlow::NBS::TypeInfoNV
TypeInfoNV("NBS")
pFlow::NBS::performedSearch_
bool performedSearch_
Definition: NBS.hpp:61
pFlow::NBSLevel0::cellIterator
typename MapperType::cellIterator cellIterator
Definition: NBSLevel0.hpp:40
pFlow::NBS::operator=
INLINE_FUNCTION_HD NBS & operator=(const NBS &)=default
pFlow::NBS::numLevels
int32 numLevels() const
Definition: NBS.hpp:142
pFlow::NBS::memory_space
typename NBSLevel0Type::memory_space memory_space
Definition: NBS.hpp:50
pFlow::NBS::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: NBS.hpp:137
pFlow
Definition: demComponent.hpp:28
pFlow::NBS::getCellIteratorLevels
Vector< cellIterator > getCellIteratorLevels()
Definition: NBS.hpp:132
pFlow::NBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, bool force=false)
Definition: NBS.hpp:168
pFlow::NBS::IndexType
typename NBSLevel0Type::IndexType IndexType
Definition: NBS.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::NBS::performSearch
bool performSearch()
Definition: NBS.hpp:67
pFlow::NBS::enterBoadSearch
bool enterBoadSearch() const
Definition: NBS.hpp:122
pFlow::mapperNBS::checkAllocateNext
void checkAllocateNext(int newCap)
Definition: mapperNBS.hpp:141
pFlow::NBSLevel0::memory_space
typename MapperType::memory_space memory_space
Definition: NBSLevel0.hpp:52
pFlow::NBSLevel0::execution_space
typename MapperType::execution_space execution_space
Definition: NBSLevel0.hpp:50
pFlow::NBS
Definition: NBS.hpp:32
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::box
Definition: box.hpp:32
pFlow::NBSLevel0::IndexType
typename MapperType::IndexType IndexType
Definition: NBSLevel0.hpp:44
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::NBSLevel0::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevel0.hpp:180
pFlow::NBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld, bool force=false)
Definition: NBS.hpp:190
pFlow::NBSLevel0::Cells
typename MapperType::Cells Cells
Definition: NBSLevel0.hpp:46
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::Vector
Definition: Vector.hpp:46
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: mapperNBS.hpp:274
pFlow::NBS::Cells
typename NBSLevel0Type::Cells Cells
Definition: NBS.hpp:44
pFlow::NBS::currentIter_
int32 currentIter_
Definition: NBS.hpp:59
pFlow::NBS::IdType
typename NBSLevel0Type::IdType IdType
Definition: NBS.hpp:40
pFlow::NBSLevel0::IdType
typename MapperType::IdType IdType
Definition: NBSLevel0.hpp:42
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::mapperNBS::getCellIterator
cellIterator getCellIterator() const
Definition: mapperNBS.hpp:219
pFlow::NBS::cellIterator
typename NBSLevel0Type::cellIterator cellIterator
Definition: NBS.hpp:38
pFlow::NBS::performedSearch
bool performedSearch() const
Definition: NBS.hpp:127
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::cells::getCells
cells getCells() const
Definition: cells.hpp:95