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

multiGridNBS.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 __multiGridNBS_hpp__
#define __multiGridNBS_hpp__
#include "NBSLevels.hpp"
namespace pFlow
{
template<typename executionSpace>
class multiGridNBS
{
public:
using NBSLevelsType = NBSLevels<executionSpace>;
using cellIterator = typename NBSLevelsType::cellIterator;
using IdType = typename NBSLevelsType::IdType;
using IndexType = typename NBSLevelsType::IndexType;
using Cells = typename NBSLevelsType::Cells;
using CellType = typename Cells::CellType;
using execution_space = typename NBSLevelsType::execution_space;
using memory_space = typename NBSLevelsType::memory_space;
protected:
real sizeRatio_ = 1.0;
int32 updateFrequency_= 1;
int32 currentIter_ = 0;
bool performedSearch_ = false;
NBSLevelsType NBSLevels_;
private:
bool performSearch()
{
if(currentIter_ % updateFrequency_ == 0)
{
currentIter_++;
return true;
}else
{
currentIter_++;
return false;
}
}
public:
TypeInfoNV("multiGridNBS");
multiGridNBS(
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.getVal<real>("sizeRatio"),
1.0
)),
updateFrequency_(
max(
dict.getVal<int32>("updateFrequency"),
1
)),
NBSLevels_(
domain,
minSize,
maxSize,
sizeRatio_,
position,
diam)
{}
INLINE_FUNCTION_HD
multiGridNBS(const multiGridNBS&) = default;
INLINE_FUNCTION_HD
multiGridNBS& operator = (const multiGridNBS&) = default;
INLINE_FUNCTION_HD
~multiGridNBS()=default;
bool enterBoadSearch()const
{
return currentIter_%updateFrequency_==0;
}
bool performedSearch()const
{
return performedSearch_;
}
int32 numLevels()const
{
return NBSLevels_.numLevels();
}
auto getCellsLevels()const
{
Vector<Cells> cellsLvl("cells", numLevels(), numLevels(), RESERVE());
for(int32 lvl=0; lvl<numLevels(); lvl++)
{
cellsLvl[lvl] = NBSLevels_.getCells(lvl) ;
}
return cellsLvl;
}
auto getCells(int32 lvl)const
{
return NBSLevels_.getCells(lvl);
}
auto getCellIterator(int32 lvl)const
{
return NBSLevels_.getCellIterator(lvl);
}
bool objectSizeChanged(int32 newSize)
{
NBSLevels_.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;
NBSLevels_.build(activeRange);
NBSLevels_.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;
NBSLevels_.build(activeRange, incld);
NBSLevels_.findPairs(pairs);
performedSearch_ = true;
return true;
}
};
}
#endif
pFlow::NBSLevels::execution_space
typename NBSLevelType::execution_space execution_space
Definition: NBSLevels.hpp:29
pFlow::NBSLevels::IndexType
typename NBSLevelType::IndexType IndexType
Definition: NBSLevels.hpp:23
pFlow::multiGridNBS::Cells
typename NBSLevelsType::Cells Cells
Definition: multiGridNBS.hpp:44
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::NBSLevels
Definition: NBSLevels.hpp:12
pFlow::multiGridNBS::objectSizeChanged
bool objectSizeChanged(int32 newSize)
Definition: multiGridNBS.hpp:160
pFlow::multiGridNBS::TypeInfoNV
TypeInfoNV("multiGridNBS")
pFlow::multiGridNBS::performSearch
bool performSearch()
Definition: multiGridNBS.hpp:67
pFlow::multiGridNBS::sizeRatio_
real sizeRatio_
Definition: multiGridNBS.hpp:55
pFlow::multiGridNBS::memory_space
typename NBSLevelsType::memory_space memory_space
Definition: multiGridNBS.hpp:50
pFlow::multiGridNBS::~multiGridNBS
INLINE_FUNCTION_HD ~multiGridNBS()=default
pFlow::multiGridNBS
Definition: multiGridNBS.hpp:32
pFlow::multiGridNBS::currentIter_
int32 currentIter_
Definition: multiGridNBS.hpp:59
pFlow::multiGridNBS::IdType
typename NBSLevelsType::IdType IdType
Definition: multiGridNBS.hpp:40
pFlow::multiGridNBS::NBSLevels_
NBSLevelsType NBSLevels_
Definition: multiGridNBS.hpp:63
pFlow::multiGridNBS::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: multiGridNBS.hpp:155
pFlow::multiGridNBS::multiGridNBS
multiGridNBS(const dictionary &dict, const box &domain, real minSize, real maxSize, const ViewType1D< realx3, memory_space > &position, const ViewType1D< real, memory_space > &diam)
Definition: multiGridNBS.hpp:85
pFlow
Definition: demComponent.hpp:28
NBSLevels.hpp
RESERVE
Definition: Vector.hpp:38
pFlow::NBSLevels::cellIterator
typename NBSLevelType::cellIterator cellIterator
Definition: NBSLevels.hpp:19
pFlow::NBSLevels::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: NBSLevels.hpp:276
pFlow::multiGridNBS::execution_space
typename NBSLevelsType::execution_space execution_space
Definition: multiGridNBS.hpp:48
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::multiGridNBS::cellIterator
typename NBSLevelsType::cellIterator cellIterator
Definition: multiGridNBS.hpp:38
pFlow::NBSLevels::memory_space
typename NBSLevelType::memory_space memory_space
Definition: NBSLevels.hpp:31
pFlow::multiGridNBS::CellType
typename Cells::CellType CellType
Definition: multiGridNBS.hpp:46
pFlow::multiGridNBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, IncludeFunction incld, bool force=false)
Definition: multiGridNBS.hpp:194
pFlow::NBSLevels::numLevels
int32 numLevels() const
Definition: NBSLevels.hpp:205
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::multiGridNBS::IndexType
typename NBSLevelsType::IndexType IndexType
Definition: multiGridNBS.hpp:42
pFlow::multiGridNBS::performedSearch_
bool performedSearch_
Definition: multiGridNBS.hpp:61
pFlow::NBSLevels::findPairs
INLINE_FUNCTION_H bool findPairs(PairsContainer &pairs)
Definition: NBSLevels.hpp:217
pFlow::NBSLevels::getCellIterator
auto getCellIterator(int32 lvl) const
Definition: NBSLevels.hpp:200
pFlow::multiGridNBS::numLevels
int32 numLevels() const
Definition: multiGridNBS.hpp:133
pFlow::box
Definition: box.hpp:32
pFlow::multiGridNBS::updateFrequency_
int32 updateFrequency_
Definition: multiGridNBS.hpp:57
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::multiGridNBS::getCells
auto getCells(int32 lvl) const
Definition: multiGridNBS.hpp:150
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::multiGridNBS::operator=
INLINE_FUNCTION_HD multiGridNBS & operator=(const multiGridNBS &)=default
pFlow::Vector
Definition: Vector.hpp:46
pFlow::multiGridNBS::broadSearch
bool broadSearch(PairsContainer &pairs, range activeRange, bool force=false)
Definition: multiGridNBS.hpp:171
pFlow::NBSLevels::IdType
typename NBSLevelType::IdType IdType
Definition: NBSLevels.hpp:21
pFlow::NBSLevels::getCells
Cells getCells(int32 lvl) const
Definition: NBSLevels.hpp:210
pFlow::multiGridNBS::performedSearch
bool performedSearch() const
Definition: multiGridNBS.hpp:128
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::NBSLevels::Cells
typename NBSLevelType::Cells Cells
Definition: NBSLevels.hpp:25
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::multiGridNBS::enterBoadSearch
bool enterBoadSearch() const
Definition: multiGridNBS.hpp:123
pFlow::multiGridNBS::getCellsLevels
auto getCellsLevels() const
Definition: multiGridNBS.hpp:138