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

mapperNBS.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 __mapperNBS_hpp__
#define __mapperNBS_hpp__
#include "cells.hpp"
#include "contactSearchFunctions.hpp"
#include "baseAlgorithms.hpp"
#include "ViewAlgorithms.hpp"
namespace pFlow
{
template<typename executionSpace>
class mapperNBS
:
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 HeadType = ViewType3D<int32, memory_space>;
using NextType = ViewType1D<int32, memory_space>;
class cellIterator
{
private:
HeadType head_;
NextType next_;
public:
cellIterator(ViewType3D<int32, memory_space> head, ViewType1D<int32, memory_space> next)
:
head_(head),
next_(next)
{}
INLINE_FUNCTION_HD
Cells cellsSize()const {
return Cells(head_.extent(0), head_.extent(1), head_.extent(2));}
INLINE_FUNCTION_HD
int32 start(IndexType i, IndexType j, IndexType k)const {
return head_(i,j,k); }
INLINE_FUNCTION_HD
int32 getNext(int32 n)const {
if(n<0) return n;
return next_(n); }
};
protected:
int32 capacity_ = 1;
ViewType3D<int32, memory_space> head_;
ViewType1D<int32, memory_space> next_;
bool nextOwner_ = true;
// borrowed ownership
ViewType1D<realx3, memory_space> pointPosition_;
using rangePolicyType =
Kokkos::RangePolicy<
Kokkos::IndexType<int32>,
Kokkos::Schedule<Kokkos::Static>,
execution_space>;
INLINE_FUNCTION_H
void nullifyHead()
{
fill(
head_,
range(0,this->nx()),
range(0,this->ny()),
range(0,this->nz()),
static_cast< int32 >(-1)
);
}
void nullifyNext(range nextRng)
{
if(!nextOwner_)return;
fill(
next_,
nextRng,
static_cast< int32 >(-1)
);
}
void nullify()
{
nullifyHead();
nullifyNext(range(0,capacity_));
}
void nullify(range nextRng)
{
nullifyHead();
nullifyNext(nextRng);
}
void checkAllocateNext(int newCap)
{
if( capacity_ < newCap)
{
capacity_ = newCap;
if(!nextOwner_)return;
reallocNoInit(next_, capacity_);
}
}
void allocateHead()
{
reallocNoInit(head_, this->nx(), this->ny(), this->nz());
}
public:
TypeInfoNV("mapperNBS");
INLINE_FUNCTION_HD
mapperNBS(){}
mapperNBS(
const box& domain,
real cellSize,
const ViewType1D<realx3, memory_space>& position,
bool nextOwner = true)
:
Cells(domain, cellSize),
pointPosition_(position),
head_(
"mapperNBS::head_",
this->nx(),
this->ny(),
this->nz()
),
next_("mapperNBS::next_",1), //,position.size()),
nextOwner_(nextOwner)
{
checkAllocateNext(pointPosition_.size());
}
mapperNBS(
const box& domain,
int32 nx,
int32 ny,
int32 nz,
const ViewType1D<realx3, memory_space>& position,
bool nextOwner = true)
:
Cells(domain, nx, ny, nz),
pointPosition_(position),
head_("mapperNBS::head_",nx,ny,nz),
next_("mapperNBS::next_",1),
nextOwner_(nextOwner)
{
checkAllocateNext(pointPosition_.size());
}
INLINE_FUNCTION_HD
mapperNBS(const mapperNBS&) = default;
INLINE_FUNCTION_HD
mapperNBS& operator = (const mapperNBS&) = default;
INLINE_FUNCTION_HD
~mapperNBS()=default;
INLINE_FUNCTION_HD
auto capacity()const
{
return capacity_;
}
cellIterator getCellIterator()const
{
return cellIterator(head_, next_);
}
bool particlesCapcityChanged(int32 newCap)
{
checkAllocateNext(newCap);
return true;
}
INLINE_FUNCTION_HD
auto& head()
{
return head_;
}
INLINE_FUNCTION_HD
auto& next()
{
return next_;
}
INLINE_FUNCTION_HD
const auto& head()const
{
return head_;
}
INLINE_FUNCTION_HD
const auto& next()const
{
return next_;
}
INLINE_FUNCTION_HD
auto& pointPosition()
{
return pointPosition_;
}
INLINE_FUNCTION_H
void setNext(ViewType1D<int32, memory_space>& next)
{
if(!nextOwner_)
{
next_ = next;
capacity_ = next.size();
}
}
// - build based on all points in active range
INLINE_FUNCTION_H
void build(range activeRange)
{
checkAllocateNext(activeRange.second);
nullify(activeRange);
Cells cellIndex = static_cast< Cells >(*this);
auto points = pointPosition_;
auto next = next_;
auto head = head_;
rangePolicyType rPolicy(activeRange.first, activeRange.second);
Kokkos::parallel_for(
"mapperNBS::build",
rPolicy,
LAMBDA_HD(int32 i){
CellType ind = cellIndex.pointIndex(points[i]);
int32 old = Kokkos::atomic_exchange(&head(ind.x(), ind.y(), ind.z()), i);
next[i] = old;
});
Kokkos::fence();
}
template<typename IncludeFunction>
INLINE_FUNCTION_H
void build(range activeRange, IncludeFunction incld)
{
checkAllocateNext(activeRange.second);
nullify(activeRange);
Cells cellIndex = static_cast< Cells >(*this);
auto points = pointPosition_;
auto next = next_;
auto head = head_;
rangePolicyType rPolicy(activeRange.first, activeRange.second);
Kokkos::parallel_for(
"mapperNBS::build_Include",
rPolicy,
LAMBDA_HD(int32 i){
if( incld(i) )
{
CellType ind = cellIndex.pointIndex(points[i]);
auto old = Kokkos::atomic_exchange(&head(ind.x(), ind.y(), ind.z()), i);
next[i] = old;
}
});
Kokkos::fence();
}
INLINE_FUNCTION_H
void buildCheckInDomain(range activeRange)
{
checkAllocateNext(activeRange.second);
nullify(activeRange);
Cells cellIndex = static_cast< Cells >(*this);
auto points = pointPosition_;
auto next = next_;
auto head = head_;
rangePolicyType rPolicy(activeRange.first, activeRange.second);
Kokkos::parallel_for(
"mapperNBS::buildCheckInDomain",
rPolicy,
LAMBDA_HD(int32 i){
CellType ind;
if( cellIndex.pointIndexInDomain(points[i], ind) )
{
int32 old = Kokkos::atomic_exchange(&head(ind.x(), ind.y(), ind.z()), i);
next[i] = old;
}
});
Kokkos::fence();
}
template<typename IncludeFunction>
INLINE_FUNCTION_H
void buildCheckInDomain(range activeRange, IncludeFunction incld)
{
checkAllocateNext(activeRange.second);
nullify(activeRange);
Cells cellIndex = static_cast< Cells >(*this);
auto points = pointPosition_;
auto next = next_;
auto head = head_;
rangePolicyType rPolicy(activeRange.first, activeRange.second);
Kokkos::parallel_for(
"mapperNBS::buildCheckInDomain_Include",
rPolicy,
LAMBDA_HD(int32 i){
CellType ind;
if( incld(i) && cellIndex.pointIndexInDomain(points[i], ind) )
{
auto old = Kokkos::atomic_exchange(&head(ind.x(), ind.y(), ind.z()), i);
next[i] = old;
}
});
Kokkos::fence();
}
};
} // pFlow
#endif // __mapperNBS_hpp__
pFlow::mapperNBS< DefaultHostExecutionSpace >::rangePolicyType
Kokkos::RangePolicy< Kokkos::IndexType< int32 >, Kokkos::Schedule< Kokkos::Static >, execution_space > rangePolicyType
Definition: mapperNBS.hpp:102
pFlow::mapperNBS::mapperNBS
mapperNBS(const box &domain, real cellSize, const ViewType1D< realx3, memory_space > &position, bool nextOwner=true)
Definition: mapperNBS.hpp:165
pFlow::mapperNBS::head_
ViewType3D< int32, memory_space > head_
Definition: mapperNBS.hpp:89
pFlow::mapperNBS::cellIterator::start
INLINE_FUNCTION_HD int32 start(IndexType i, IndexType j, IndexType k) const
Definition: mapperNBS.hpp:76
pFlow::cells< int32 >::nz
INLINE_FUNCTION_HD int32 nz() const
Definition: cells.hpp:139
pFlow::mapperNBS::next_
ViewType1D< int32, memory_space > next_
Definition: mapperNBS.hpp:91
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
pFlow::mapperNBS::nullifyNext
void nullifyNext(range nextRng)
Definition: mapperNBS.hpp:116
pFlow::mapperNBS::capacity_
int32 capacity_
Definition: mapperNBS.hpp:87
pFlow::mapperNBS::nextOwner_
bool nextOwner_
Definition: mapperNBS.hpp:93
pFlow::mapperNBS::~mapperNBS
INLINE_FUNCTION_HD ~mapperNBS()=default
contactSearchFunctions.hpp
pFlow::mapperNBS::head
INLINE_FUNCTION_HD auto & head()
Definition: mapperNBS.hpp:231
ViewAlgorithms.hpp
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
pFlow::mapperNBS::setNext
INLINE_FUNCTION_H void setNext(ViewType1D< int32, memory_space > &next)
Definition: mapperNBS.hpp:261
pFlow::cells< int32 >::nx
INLINE_FUNCTION_HD int32 nx() const
Definition: cells.hpp:127
pFlow::mapperNBS::mapperNBS
INLINE_FUNCTION_HD mapperNBS()
Definition: mapperNBS.hpp:163
pFlow::mapperNBS< DefaultHostExecutionSpace >::NextType
ViewType1D< int32, memory_space > NextType
Definition: mapperNBS.hpp:54
pFlow::cells::pointIndexInDomain
INLINE_FUNCTION_HD bool pointIndexInDomain(const realx3 p, CellType &index) const
Definition: cells.hpp:164
pFlow::mapperNBS::cellIterator::next_
NextType next_
Definition: mapperNBS.hpp:61
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow::mapperNBS
Definition: mapperNBS.hpp:34
pFlow
Definition: demComponent.hpp:28
pFlow::cells::CellType
triple< indexType > CellType
Definition: cells.hpp:36
pFlow::mapperNBS::next
const INLINE_FUNCTION_HD auto & next() const
Definition: mapperNBS.hpp:249
pFlow::mapperNBS::TypeInfoNV
TypeInfoNV("mapperNBS")
pFlow::mapperNBS::mapperNBS
mapperNBS(const box &domain, int32 nx, int32 ny, int32 nz, const ViewType1D< realx3, memory_space > &position, bool nextOwner=true)
Definition: mapperNBS.hpp:185
pFlow::mapperNBS::cellIterator::head_
HeadType head_
Definition: mapperNBS.hpp:59
pFlow::mapperNBS::buildCheckInDomain
INLINE_FUNCTION_H void buildCheckInDomain(range activeRange)
Definition: mapperNBS.hpp:329
pFlow::mapperNBS< DefaultHostExecutionSpace >::IdType
int32 IdType
Definition: mapperNBS.hpp:40
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::mapperNBS::particlesCapcityChanged
bool particlesCapcityChanged(int32 newCap)
Definition: mapperNBS.hpp:224
pFlow::mapperNBS::allocateHead
void allocateHead()
Definition: mapperNBS.hpp:151
pFlow::cells< int32 >::domain
const auto & domain() const
Definition: cells.hpp:152
pFlow::mapperNBS::nullify
void nullify()
Definition: mapperNBS.hpp:126
pFlow::mapperNBS< DefaultHostExecutionSpace >::IndexType
int32 IndexType
Definition: mapperNBS.hpp:42
pFlow::mapperNBS::cellIterator::getNext
INLINE_FUNCTION_HD int32 getNext(int32 n) const
Definition: mapperNBS.hpp:80
pFlow::mapperNBS::checkAllocateNext
void checkAllocateNext(int newCap)
Definition: mapperNBS.hpp:141
pFlow::mapperNBS::pointPosition
INLINE_FUNCTION_HD auto & pointPosition()
Definition: mapperNBS.hpp:255
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::mapperNBS::next
INLINE_FUNCTION_HD auto & next()
Definition: mapperNBS.hpp:237
cells.hpp
pFlow::mapperNBS::cellIterator::cellsSize
INLINE_FUNCTION_HD Cells cellsSize() const
Definition: mapperNBS.hpp:72
pFlow::mapperNBS::head
const INLINE_FUNCTION_HD auto & head() const
Definition: mapperNBS.hpp:243
pFlow::mapperNBS::nullify
void nullify(range nextRng)
Definition: mapperNBS.hpp:133
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::mapperNBS< DefaultHostExecutionSpace >::HeadType
ViewType3D< int32, memory_space > HeadType
Definition: mapperNBS.hpp:52
pFlow::mapperNBS< DefaultHostExecutionSpace >::execution_space
DefaultHostExecutionSpace execution_space
Definition: mapperNBS.hpp:48
pFlow::mapperNBS::cellIterator
Definition: mapperNBS.hpp:56
pFlow::box
Definition: box.hpp:32
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::mapperNBS::Cells
cells< IndexType > Cells
Definition: mapperNBS.hpp:44
pFlow::mapperNBS::operator=
INLINE_FUNCTION_HD mapperNBS & operator=(const mapperNBS &)=default
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::mapperNBS::cellIterator::cellIterator
cellIterator(ViewType3D< int32, memory_space > head, ViewType1D< int32, memory_space > next)
Definition: mapperNBS.hpp:65
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
pFlow::cells
Definition: cells.hpp:32
pFlow::mapperNBS::nullifyHead
INLINE_FUNCTION_H void nullifyHead()
Definition: mapperNBS.hpp:105
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< int32 >
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
baseAlgorithms.hpp
pFlow::mapperNBS< DefaultHostExecutionSpace >::memory_space
typename execution_space::memory_space memory_space
Definition: mapperNBS.hpp:50
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange)
Definition: mapperNBS.hpp:274
pFlow::mapperNBS::build
INLINE_FUNCTION_H void build(range activeRange, IncludeFunction incld)
Definition: mapperNBS.hpp:300
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::mapperNBS::getCellIterator
cellIterator getCellIterator() const
Definition: mapperNBS.hpp:219
pFlow::ViewType3D
Kokkos::View< T ***, properties... > ViewType3D
Definition: KokkosTypes.hpp:68
pFlow::mapperNBS::capacity
INLINE_FUNCTION_HD auto capacity() const
Definition: mapperNBS.hpp:214
pFlow::mapperNBS::buildCheckInDomain
INLINE_FUNCTION_H void buildCheckInDomain(range activeRange, IncludeFunction incld)
Definition: mapperNBS.hpp:359
pFlow::mapperNBS::pointPosition_
ViewType1D< realx3, memory_space > pointPosition_
Definition: mapperNBS.hpp:96