# PhasicFlow: src/phasicFlow/structuredData/pointStructure/internalPoints/pointFlag.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

pointFlag.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 __pointFlag_hpp__
#define __pointFlag_hpp__
#include "phasicFlowKokkos.hpp"
#include "domain.hpp"
#include "scatteredFieldAccess.hpp"
#include "globalSettings.hpp"
namespace pFlow
{
template<typename ExecutionSpace>
class pointFlag
{
enum Flag: uint8
{
DELETED = 1, //00000001
INTERNAL = 2, //00000010
LEFT = 4, //00000100
RIGHT = 8, //00001000
BOTTOM = 16, //00010000
TOP = 32, //00100000
REAR = 64, //01000000
FRONT = 128 //10000000
};
using execution_space = ExecutionSpace;
using memory_space = typename execution_space::memory_space;
using viewType = ViewType1D<uint8, memory_space>;
using device_type = typename viewType::device_type;
using rPolicy = Kokkos::RangePolicy<
execution_space,
Kokkos::IndexType<uint32>>;
protected:
friend class internalPoints;
viewType flags_;
uint32 numActive_ = 0;
rangeU32 activeRange_ = {0,0};
bool isAllActive_ = false;
uint32 nLeft_ = 0;
uint32 nRight_ = 0;
uint32 nBottom_= 0;
uint32 nTop_ = 0;
uint32 nRear_ = 0;
uint32 nFront_ = 0;
//- Protected methods
uint8 getBoundaryFlag(uint32 index)const
{
uint8 flg;
switch (index){
case 0u:
flg = Flag::LEFT;
break;
case 1u:
flg = Flag::RIGHT;
break;
case 2u:
flg = Flag::BOTTOM;
break;
case 3u:
flg = Flag::TOP;
break;
case 4u:
flg = Flag::REAR;
break;
case 5u:
flg = Flag::FRONT;
break;
default:
flg=0;
}
return flg;
}
void resetFlags(uint32 cap, uint32 start, uint32 end)
{
if(cap != capacity() )
{
reallocFill(flags_, cap, static_cast< uint8 >(Flag::DELETED));
}
else
{
fill(flags_, end, cap, static_cast< uint8 >(Flag::DELETED));
}
activeRange_ = {start, end};
numActive_ = activeRange_.numElements();
isAllActive_ = true;
fill(flags_, activeRange_, static_cast< uint8 >(Flag::INTERNAL));
nLeft_ = nRight_ = 0;
nBottom_ = nTop_ = 0;
nRear_ = nFront_ = 0;
}
public:
pointFlag() = default;
pointFlag(uint32 capacity, uint32 start, uint32 end )
:
flags_("pointFlag", capacity ),
numActive_(end-start),
activeRange_(start, end),
isAllActive_(true)
{
fill(flags_, end, capacity, static_cast< uint8 >(Flag::DELETED));
fill(flags_, activeRange_, static_cast< uint8 >(Flag::INTERNAL));
}
pointFlag(
viewType flags,
uint32 numActive,
rangeU32 activeRange,
bool isAllActive)
:
flags_(flags),
numActive_(numActive),
activeRange_(activeRange),
isAllActive_(isAllActive)
{}
pointFlag(const pointFlag&) = default;
pointFlag& operator=(const pointFlag&) = default;
pointFlag(pointFlag&&) = default;
pointFlag& operator=(pointFlag&&) = default;
~pointFlag() = default;
INLINE_FUNCTION_HD
bool isAllActive()const
{
return isAllActive_;
}
INLINE_FUNCTION_HD
const auto& activeRange()const
{
return activeRange_;
}
INLINE_FUNCTION_HD
uint32 capacity()const
{
return flags_.extent(0);
}
INLINE_FUNCTION_HD
auto numActive()const
{
return numActive_;
}
INLINE_FUNCTION_HD
auto leftSize()const
{
return nLeft_;
}
INLINE_FUNCTION_HD
auto rightSize()const
{
return nRight_;
}
INLINE_FUNCTION_HD
auto bottomSize()const
{
return nBottom_;
}
INLINE_FUNCTION_HD
auto topSize()const
{
return nTop_;
}
INLINE_FUNCTION_HD
auto rearSize()const
{
return nRear_;
}
INLINE_FUNCTION_HD
auto frontSize()const
{
return nFront_;
}
INLINE_FUNCTION_HD
bool operator()(uint32 i)const
{
return isActive(i);
}
INLINE_FUNCTION_HD
bool isActive(uint32 i)const
{
return flags_[i] > DELETED;
}
INLINE_FUNCTION_HD
bool isBoundary(uint8 flg)const
{
return flg > INTERNAL;
}
INLINE_FUNCTION_HD
bool isLeft(uint8 flg)const
{
return flg&LEFT;
}
INLINE_FUNCTION_HD
bool isRight(uint8 flg)const
{
return flg&RIGHT;
}
INLINE_FUNCTION_HD
bool isBottom(uint8 flg)const
{
return flg&BOTTOM;
}
INLINE_FUNCTION_HD
bool isTop(uint8 flg)const
{
return flg&TOP;
}
INLINE_FUNCTION_HD
bool isRear(uint8 flg)const
{
return flg&REAR;
}
INLINE_FUNCTION_HD
bool isFront(uint8 flg)const
{
return flg&FRONT;
}
template<typename ExeSpace>
pointFlag<ExeSpace> clone()const
{
using newViewType = ViewType1D<uint8, typename ExeSpace::memory_space>;
newViewType newFlags(
"pointFlag",
flags_.size());
copy(newFlags, flags_);
return pointFlag<ExeSpace>(
newFlags,
numActive_,
activeRange_,
isAllActive_);
}
ViewType1D<uint32, memory_space> getActivePoints();
ViewType1D<uint32, memory_space> getEmptyPoints(uint32 numToGet)const;
uint32 markOutOfBoxDelete(
const box& validBox,
ViewType1D<realx3, memory_space> points);
uint32 addInternalPoints(
const ViewType1D<uint32, memory_space>& points);
bool deletePoints(
scatteredFieldAccess<uint32, memory_space> points);
bool deletePoints(
ViewType1D<uint32, memory_space> points);
bool changeFlags(
ViewType1D<uint32, memory_space> changePoints,
uint32 boundaryIndex);
uint32 markPointRegions(
domain dm,
ViewType1D<realx3, memory_space> points,
real leftLength,
real rightLength,
real bottomLength,
real topLength,
real rearLength,
real frontLength);
void fillNeighborsLists(
ViewType1D<uint32, memory_space> leftList,
ViewType1D<uint32, memory_space> rightList,
ViewType1D<uint32, memory_space> bottomList,
ViewType1D<uint32, memory_space> topList,
ViewType1D<uint32, memory_space> rearList,
ViewType1D<uint32, memory_space> frontList);
uint32 markDelete(
const plane& pln,
ViewType1D<realx3, memory_space> points,
ViewType1D<uint32, memory_space> indices,
ViewType1D<uint32, memory_space> onOff);
uint32 changeCapacity( uint32 reqEmptySpots );
};
using pFlagTypeDevice = pointFlag<DefaultExecutionSpace>;
using pFlagTypeHost = pointFlag<DefaultHostExecutionSpace>;
}
#include "pointFlagKernels.hpp"
#endif // __pointFlag_hpp__
pFlow::pointFlag::isRight
INLINE_FUNCTION_HD bool isRight(uint8 flg) const
Definition: pointFlag.hpp:260
pFlow::pointFlag::isBottom
INLINE_FUNCTION_HD bool isBottom(uint8 flg) const
Definition: pointFlag.hpp:267
pFlow::pointFlag::REAR
@ REAR
Definition: pointFlag.hpp:42
pointFlagKernels.hpp
pFlow::pointFlag::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: pointFlag.hpp:185
pFlow::reallocFill
INLINE_FUNCTION_H void reallocFill(ViewType1D< Type, Properties... > &view, uint32 len, Type val)
Definition: KokkosUtilities.hpp:71
pFlow::pointFlag::~pointFlag
~pointFlag()=default
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::pointFlag::pointFlag
pointFlag()=default
pFlow::pointFlag::isAllActive_
bool isAllActive_
Definition: pointFlag.hpp:68
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::real
float real
Definition: builtinTypes.hpp:45
domain.hpp
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
pFlow::plane
Definition: plane.hpp:30
pFlow::pointFlag::isBoundary
INLINE_FUNCTION_HD bool isBoundary(uint8 flg) const
Definition: pointFlag.hpp:247
pFlow::pointFlag::isFront
INLINE_FUNCTION_HD bool isFront(uint8 flg) const
Definition: pointFlag.hpp:285
pFlow::pointFlag::activeRange_
rangeU32 activeRange_
Definition: pointFlag.hpp:66
pFlow::pointFlag::isLeft
INLINE_FUNCTION_HD bool isLeft(uint8 flg) const
Definition: pointFlag.hpp:254
pFlow::pointFlag::TOP
@ TOP
Definition: pointFlag.hpp:41
pFlow::pointFlag::changeFlags
bool changeFlags(ViewType1D< uint32, memory_space > changePoints, uint32 boundaryIndex)
Definition: pointFlagKernels.hpp:308
pFlow::pointFlag::getActivePoints
ViewType1D< uint32, memory_space > getActivePoints()
Definition: pointFlagKernels.hpp:25
pFlow::pointFlag::markOutOfBoxDelete
uint32 markOutOfBoxDelete(const box &validBox, ViewType1D< realx3, memory_space > points)
Loop over the active points and mark those out of the box and return number of deleted points.
Definition: pointFlagKernels.hpp:102
pFlow::copy
INLINE_FUNCTION_H void copy(const ViewType1D< dType, dProperties... > &dst, const ViewType1D< sType, sProperties... > &src)
Definition: ViewAlgorithms.hpp:234
pFlow::pointFlag::LEFT
@ LEFT
Definition: pointFlag.hpp:38
pFlow::pointFlag::frontSize
INLINE_FUNCTION_HD auto frontSize() const
Definition: pointFlag.hpp:227
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::pointFlag< DefaultHostExecutionSpace >::execution_space
DefaultHostExecutionSpace execution_space
Definition: pointFlag.hpp:46
pFlow::pointFlag::numActive
INLINE_FUNCTION_HD auto numActive() const
Definition: pointFlag.hpp:191
pFlow::pointFlag::DELETED
@ DELETED
Definition: pointFlag.hpp:36
pFlow::pointFlag::FRONT
@ FRONT
Definition: pointFlag.hpp:43
pFlow::pointFlag::flags_
viewType flags_
Definition: pointFlag.hpp:62
pFlow::pointFlag::nFront_
uint32 nFront_
Definition: pointFlag.hpp:80
pFlow::pointFlag::rightSize
INLINE_FUNCTION_HD auto rightSize() const
Definition: pointFlag.hpp:203
pFlow::pointFlag::nLeft_
uint32 nLeft_
Definition: pointFlag.hpp:70
pFlow::pointFlag::clone
pointFlag< ExeSpace > clone() const
Definition: pointFlag.hpp:291
pFlow::pointFlag::pointFlag
pointFlag(viewType flags, uint32 numActive, rangeU32 activeRange, bool isAllActive)
Definition: pointFlag.hpp:150
pFlow
Definition: demGeometry.hpp:27
pFlow::pointFlag< DefaultHostExecutionSpace >::viewType
ViewType1D< uint8, memory_space > viewType
Definition: pointFlag.hpp:50
pFlow::pointFlag< DefaultHostExecutionSpace >::memory_space
typename execution_space::memory_space memory_space
Definition: pointFlag.hpp:48
pFlow::pointFlag< DefaultHostExecutionSpace >::rPolicy
Kokkos::RangePolicy< execution_space, Kokkos::IndexType< uint32 > > rPolicy
Definition: pointFlag.hpp:56
pFlow::pointFlag::isActive
INLINE_FUNCTION_HD bool isActive(uint32 i) const
Definition: pointFlag.hpp:240
pFlow::pointFlag::markDelete
uint32 markDelete(const plane &pln, ViewType1D< realx3, memory_space > points, ViewType1D< uint32, memory_space > indices, ViewType1D< uint32, memory_space > onOff)
Definition: pointFlagKernels.hpp:510
phasicFlowKokkos.hpp
globalSettings.hpp
pFlow::pointFlag::markPointRegions
uint32 markPointRegions(domain dm, ViewType1D< realx3, memory_space > points, real leftLength, real rightLength, real bottomLength, real topLength, real rearLength, real frontLength)
mark points based on their position in the domain.
Definition: pointFlagKernels.hpp:330
pFlow::pointFlag::nTop_
uint32 nTop_
Definition: pointFlag.hpp:76
pFlow::pointFlag::addInternalPoints
uint32 addInternalPoints(const ViewType1D< uint32, memory_space > &points)
Definition: pointFlagKernels.hpp:174
pFlow::Range::numElements
INLINE_FUNCTION_HD T numElements()
Definition: Range.hpp:119
pFlow::pointFlag::Flag
Flag
Definition: pointFlag.hpp:34
pFlow::pointFlag::nRear_
uint32 nRear_
Definition: pointFlag.hpp:78
pFlow::pointFlag::RIGHT
@ RIGHT
Definition: pointFlag.hpp:39
pFlow::pointFlag::isAllActive
INLINE_FUNCTION_HD bool isAllActive() const
Definition: pointFlag.hpp:173
pFlow::pointFlag::fillNeighborsLists
void fillNeighborsLists(ViewType1D< uint32, memory_space > leftList, ViewType1D< uint32, memory_space > rightList, ViewType1D< uint32, memory_space > bottomList, ViewType1D< uint32, memory_space > topList, ViewType1D< uint32, memory_space > rearList, ViewType1D< uint32, memory_space > frontList)
fill the lists for boundary faces.
Definition: pointFlagKernels.hpp:467
pFlow::pointFlag::nRight_
uint32 nRight_
Definition: pointFlag.hpp:72
pFlow::pointFlag::isRear
INLINE_FUNCTION_HD bool isRear(uint8 flg) const
Definition: pointFlag.hpp:279
pFlow::pointFlag::isTop
INLINE_FUNCTION_HD bool isTop(uint8 flg) const
Definition: pointFlag.hpp:273
pFlow::pointFlag::operator=
pointFlag & operator=(const pointFlag &)=default
pFlow::pointFlag::nBottom_
uint32 nBottom_
Definition: pointFlag.hpp:74
pFlow::pointFlag::getBoundaryFlag
uint8 getBoundaryFlag(uint32 index) const
Definition: pointFlag.hpp:84
pFlow::pointFlag::activeRange
const INLINE_FUNCTION_HD auto & activeRange() const
Definition: pointFlag.hpp:179
pFlow::pointFlag::topSize
INLINE_FUNCTION_HD auto topSize() const
Definition: pointFlag.hpp:215
pFlow::pointFlag::numActive_
uint32 numActive_
Definition: pointFlag.hpp:64
pFlow::pointFlag::operator()
INLINE_FUNCTION_HD bool operator()(uint32 i) const
Definition: pointFlag.hpp:234
pFlow::Range< uint32 >
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::pointFlag::resetFlags
void resetFlags(uint32 cap, uint32 start, uint32 end)
Definition: pointFlag.hpp:113
pFlow::pointFlag::BOTTOM
@ BOTTOM
Definition: pointFlag.hpp:40
pFlow::box
Definition: box.hpp:32
pFlow::pointFlag::getEmptyPoints
ViewType1D< uint32, memory_space > getEmptyPoints(uint32 numToGet) const
Definition: pointFlagKernels.hpp:55
pFlow::pointFlag::changeCapacity
uint32 changeCapacity(uint32 reqEmptySpots)
Definition: pointFlagKernels.hpp:582
pFlow::pointFlag::bottomSize
INLINE_FUNCTION_HD auto bottomSize() const
Definition: pointFlag.hpp:209
pFlow::domain
Definition: domain.hpp:31
pFlow::pointFlag::rearSize
INLINE_FUNCTION_HD auto rearSize() const
Definition: pointFlag.hpp:221
pFlow::pointFlag< DefaultHostExecutionSpace >::device_type
typename viewType::device_type device_type
Definition: pointFlag.hpp:52
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
scatteredFieldAccess.hpp
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::pointFlag::pointFlag
pointFlag(uint32 capacity, uint32 start, uint32 end)
Definition: pointFlag.hpp:139
pFlow::pointFlag::deletePoints
bool deletePoints(scatteredFieldAccess< uint32, memory_space > points)
Definition: pointFlagKernels.hpp:221
pFlow::pointFlag::leftSize
INLINE_FUNCTION_HD auto leftSize() const
Definition: pointFlag.hpp:197
pFlow::pointFlag
Definition: pointFlag.hpp:32
pFlow::pointFlag::INTERNAL
@ INTERNAL
Definition: pointFlag.hpp:37