# PhasicFlow: src/Interaction/contactLists/unsortedPairs.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.

unsortedPairs.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 __unsortedPairs_hpp__
#define __unsortedPairs_hpp__
#include "KokkosTypes.hpp"
#include "types.hpp"
namespace pFlow
{
template<typename executionSpace, typename idType>
class unsortedPairs
{
public:
using UnsortedPairs = unsortedPairs<executionSpace,idType>;
using IdType = idType;
using ExecutionSpace = executionSpace;
using memory_space = typename ExecutionSpace::memory_space;
using PairType = Pair<idType,idType>;
using ContainerType = unorderedSet<PairType, ExecutionSpace>;
struct pairAccessor
{
using PairType = typename UnsortedPairs::PairType;
ContainerType Container_;
INLINE_FUNCTION_HD
uint32 size()const { return Container_.size(); }
INLINE_FUNCTION_HD
uint32 loopCount()const { return Container_.capacity(); }
INLINE_FUNCTION_HD
bool isValid(uint32 idx)const { return Container_.valid_at(idx); }
INLINE_FUNCTION_HD
PairType getPair(uint32 idx)const { return Container_.key_at(idx); }
INLINE_FUNCTION_HD
bool getPair(uint32 idx, PairType& pair)const {
if(Container_.valid_at(idx)) {
pair = Container_.key_at(idx);
return true;
}
return false;
}
};
protected:
ContainerType container_;
public:
// - type info
TypeInfoNV("unsorderedPairs");
// constructor
explicit unsortedPairs(uint32 capacity=1)
:
container_(capacity) // the minimum capacity would be 128
{}
bool beforeBroadSearch()
{
container_.clear();
return true;
}
bool afterBroadSearch()
{
return true;
}
// - Device call
INLINE_FUNCTION_HD
uint32 insert(idType i, idType j)const
{
if(auto insertResult = container_.insert(PairType(i,j)); insertResult.failed())
return static_cast< uint32 >(-1);
else
return insertResult.index();
}
INLINE_FUNCTION_HD
uint32 insert(const PairType& p)const
{
if(auto insertResult = container_.insert(p); insertResult.failed())
return static_cast< uint32 >(-1);
else
return insertResult.index();
}
// - Device call
// return the pair at index idx
// perform no check for size and existance
INLINE_FUNCTION_HD
PairType getPair(uint32 idx)const
{
return container_.key_at(idx);
}
// - Device call
// return the pair at index idx
INLINE_FUNCTION_HD
bool getPair(uint32 idx, PairType& p)const
{
if(container_.valid_at(idx))
{
p = container_.key_at(idx);
return true;
}
else
{
return false;
}
}
INLINE_FUNCTION_HD
uint32 find(const PairType & p)const
{
if( auto idx = container_.find(p);
idx != Kokkos::UnorderedMapInvalidIndex )
return idx;
else
return static_cast< uint32 >(-1);
}
INLINE_FUNCTION_HD
bool isValid(uint32 idx)const
{
return container_.valid_at(idx);
}
INLINE_FUNCTION_HD
uint32 capacity() const
{
return container_.capacity();
}
uint32 loopCount()const
{
return container_.capacity();
}
//use this when the value of size_ is updated
INLINE_FUNCTION_H
uint32 size()const
{
return container_.size();
}
pairAccessor getPairs()const
{
return {container_};
}
INLINE_FUNCTION_H
void increaseCapacityBy(uint32 len)
{
uint newCap = container_.capacity()+len;
this->clear();
container_.rehash(newCap);
}
INLINE_FUNCTION_H
void clear()
{
container_.clear();
}
const ContainerType& container()const
{
return container_;
}
};
}
#endif //__unsortedPairs_hpp__
pFlow::unsortedPairs::insert
INLINE_FUNCTION_HD uint32 insert(const PairType &p) const
Definition: unsortedPairs.hpp:115
pFlow::unsortedPairs::pairAccessor::getPair
INLINE_FUNCTION_HD bool getPair(uint32 idx, PairType &pair) const
Definition: unsortedPairs.hpp:67
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::unsortedPairs::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: unsortedPairs.hpp:42
pFlow::unsortedPairs::pairAccessor::isValid
INLINE_FUNCTION_HD bool isValid(uint32 idx) const
Definition: unsortedPairs.hpp:61
pFlow::unsortedPairs::PairType
Pair< idType, idType > PairType
Definition: unsortedPairs.hpp:44
types.hpp
pFlow::Pair
Kokkos::pair< T1, T2 > Pair
Pair of two variables.
Definition: KokkosTypes.hpp:85
pFlow::unsortedPairs::pairAccessor::getPair
INLINE_FUNCTION_HD PairType getPair(uint32 idx) const
Definition: unsortedPairs.hpp:64
pFlow::unsortedPairs::insert
INLINE_FUNCTION_HD uint32 insert(idType i, idType j) const
Definition: unsortedPairs.hpp:105
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
KokkosTypes.hpp
pFlow::unsortedPairs::afterBroadSearch
bool afterBroadSearch()
Definition: unsortedPairs.hpp:98
pFlow::unsortedPairs
Definition: unsortedPairs.hpp:32
pFlow::unsortedPairs::IdType
idType IdType
Definition: unsortedPairs.hpp:38
pFlow
Definition: demGeometry.hpp:27
pFlow::unsortedPairs::unsortedPairs
unsortedPairs(uint32 capacity=1)
Definition: unsortedPairs.hpp:87
pFlow::unsortedPairs::pairAccessor::size
INLINE_FUNCTION_HD uint32 size() const
Definition: unsortedPairs.hpp:55
pFlow::unsortedPairs::container_
ContainerType container_
Definition: unsortedPairs.hpp:78
pFlow::unsortedPairs::TypeInfoNV
TypeInfoNV("unsorderedPairs")
pFlow::unorderedSet
Kokkos::UnorderedMap< Key, void, properties... > unorderedSet
unordered set
Definition: KokkosTypes.hpp:113
pFlow::unsortedPairs::increaseCapacityBy
INLINE_FUNCTION_H void increaseCapacityBy(uint32 len)
increase the capacity of the container by at-least len the content will be erased.
Definition: unsortedPairs.hpp:193
pFlow::unsortedPairs::isValid
INLINE_FUNCTION_HD bool isValid(uint32 idx) const
Definition: unsortedPairs.hpp:161
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::unsortedPairs::clear
INLINE_FUNCTION_H void clear()
Definition: unsortedPairs.hpp:201
pFlow::unsortedPairs::pairAccessor::Container_
ContainerType Container_
Definition: unsortedPairs.hpp:52
pFlow::unsortedPairs::getPairs
pairAccessor getPairs() const
Definition: unsortedPairs.hpp:185
pFlow::unsortedPairs::getPair
INLINE_FUNCTION_HD bool getPair(uint32 idx, PairType &p) const
Definition: unsortedPairs.hpp:136
pFlow::unsortedPairs::getPair
INLINE_FUNCTION_HD PairType getPair(uint32 idx) const
Definition: unsortedPairs.hpp:128
pFlow::unsortedPairs::ContainerType
unorderedSet< PairType, ExecutionSpace > ContainerType
Definition: unsortedPairs.hpp:46
pFlow::unsortedPairs::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedPairs.hpp:92
pFlow::unsortedPairs::size
INLINE_FUNCTION_H uint32 size() const
Definition: unsortedPairs.hpp:180
pFlow::unsortedPairs::pairAccessor::loopCount
INLINE_FUNCTION_HD uint32 loopCount() const
Definition: unsortedPairs.hpp:58
pFlow::unsortedPairs::pairAccessor
Definition: unsortedPairs.hpp:48
pFlow::unsortedPairs::loopCount
uint32 loopCount() const
Definition: unsortedPairs.hpp:173
pFlow::unsortedPairs::find
INLINE_FUNCTION_HD uint32 find(const PairType &p) const
Definition: unsortedPairs.hpp:151
pFlow::unsortedPairs::container
const ContainerType & container() const
Definition: unsortedPairs.hpp:206
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::unsortedPairs::ExecutionSpace
executionSpace ExecutionSpace
Definition: unsortedPairs.hpp:40
pFlow::unsortedPairs::pairAccessor::PairType
typename UnsortedPairs::PairType PairType
Definition: unsortedPairs.hpp:50