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

unsortedContactList.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 __unsortedContactList_hpp__
#define __unsortedContactList_hpp__
#include "unsortedPairs.hpp"
namespace pFlow
{
template<typename valueType, typename executionSpace, typename idType>
class unsortedContactList
:
public unsortedPairs<executionSpace, idType>
{
public:
using ValueType = valueType;
using UnsortedPairs = unsortedPairs<executionSpace, idType>;
using IdType = typename UnsortedPairs::IdType;
using ExecutionSpace = typename UnsortedPairs::ExecutionSpace;
using memory_space = typename ExecutionSpace::memory_space;
using PairType = typename UnsortedPairs::PairType;
using ContainerType = typename UnsortedPairs::ContainerType;
class TagReFillPairs{};
protected:
ViewType1D<ValueType,ExecutionSpace> values_;
ContainerType container0_;
ViewType1D<ValueType,ExecutionSpace> values0_;
void adjustCapacity()
{
auto cap = this->capacity();
if(cap > values_.size())
{
reallocNoInit(values_, cap);
}
}
using rpFillPairs = Kokkos::RangePolicy<
ExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<uint32>,
TagReFillPairs>;
public:
TypeInfoNV("unsortedContactList");
explicit unsortedContactList(uint32 capacity=1)
:
UnsortedPairs(capacity),
values_("values", UnsortedPairs::capacity()),
container0_(capacity),
values0_("values0",container0_.capacity())
{}
bool beforeBroadSearch()
{
// swap conainer and values
swapViews(values0_, values_);
swapViews(container0_, this->container_);
UnsortedPairs::beforeBroadSearch();
return true;
}
bool afterBroadSearch()
{
UnsortedPairs::afterBroadSearch();
adjustCapacity();
Kokkos::parallel_for(
"reFillPairs",
rpFillPairs(0,this->capacity()),
*this);
Kokkos::fence();
return true;
}
INLINE_FUNCTION_HD
ValueType getValue(int32 idx)const
{
return values_[idx];
}
INLINE_FUNCTION_HD
bool getValue(const PairType& p, ValueType& val)const
{
if(auto idx = this->find(p); idx!=static_cast< uint32 >(-1))
{
val = getValue(idx);
return true;
}
return false;
}
INLINE_FUNCTION_HD
void setValue(uint32 idx, const ValueType& val)const
{
values_[idx] = val;
}
INLINE_FUNCTION_HD
bool setValue(const PairType& p, const ValueType& val)const
{
if(uint32 idx = this->find(p); idx!=static_cast< uint32 >(-1))
{
setValue(idx, val);
return true;;
}
return false;
}
INLINE_FUNCTION_HD
void operator()(TagReFillPairs, uint32 idx)const
{
if( this->isValid(idx) )
{
if( uint32 idx0 =
container0_.find(this->getPair(idx));
idx0!= static_cast< uint32 >(-1) )
{
values_[idx] = values0_[idx0];
}
else
{
values_[idx] = ValueType();
}
}
// invalid locations should not be filled.
}
}; //unsortedContactList
} // pFlow
#endif //__unsortedContactList_hpp__
pFlow::unsortedContactList::values_
ViewType1D< ValueType, ExecutionSpace > values_
storage for keeping the values of the current list
Definition: unsortedContactList.hpp:55
pFlow::unsortedContactList::ContainerType
typename UnsortedPairs::ContainerType ContainerType
Definition: unsortedContactList.hpp:48
pFlow::unsortedContactList::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: unsortedContactList.hpp:44
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD bool getValue(const PairType &p, ValueType &val) const
Definition: unsortedContactList.hpp:125
pFlow::unsortedContactList::ExecutionSpace
typename UnsortedPairs::ExecutionSpace ExecutionSpace
Definition: unsortedContactList.hpp:42
pFlow::unsortedContactList::values0_
ViewType1D< ValueType, ExecutionSpace > values0_
storage for keeping values from the previous list
Definition: unsortedContactList.hpp:61
pFlow::unsortedPairs::PairType
Pair< idType, idType > PairType
Definition: unsortedPairs.hpp:44
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD ValueType getValue(int32 idx) const
Definition: unsortedContactList.hpp:119
pFlow::unsortedContactList::adjustCapacity
void adjustCapacity()
Definition: unsortedContactList.hpp:63
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, uint32 len)
Definition: KokkosUtilities.hpp:64
pFlow::unsortedContactList::afterBroadSearch
bool afterBroadSearch()
Definition: unsortedContactList.hpp:102
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::unsortedContactList::ValueType
valueType ValueType
Definition: unsortedContactList.hpp:36
pFlow::unsortedContactList::unsortedContactList
unsortedContactList(uint32 capacity=1)
Definition: unsortedContactList.hpp:84
pFlow::unsortedPairs::container_
ContainerType container_
Definition: unsortedPairs.hpp:78
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD void setValue(uint32 idx, const ValueType &val) const
Definition: unsortedContactList.hpp:136
pFlow::unsortedContactList::PairType
typename UnsortedPairs::PairType PairType
Definition: unsortedContactList.hpp:46
pFlow::unsortedPairs::isValid
INLINE_FUNCTION_HD bool isValid(uint32 idx) const
Definition: unsortedPairs.hpp:161
pFlow::unsortedContactList
Definition: unsortedContactList.hpp:30
unsortedPairs.hpp
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD bool setValue(const PairType &p, const ValueType &val) const
Definition: unsortedContactList.hpp:142
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::unsortedPairs::ContainerType
unorderedSet< PairType, ExecutionSpace > ContainerType
Definition: unsortedPairs.hpp:46
pFlow::unsortedPairs::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedPairs.hpp:92
pFlow::unsortedContactList::IdType
typename UnsortedPairs::IdType IdType
Definition: unsortedContactList.hpp:40
pFlow::unsortedContactList::container0_
ContainerType container0_
storage for keeping pairs from the previous list
Definition: unsortedContactList.hpp:58
pFlow::unsortedContactList::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedContactList.hpp:93
pFlow::unsortedContactList::rpFillPairs
Kokkos::RangePolicy< ExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< uint32 >, TagReFillPairs > rpFillPairs
Definition: unsortedContactList.hpp:77
pFlow::unsortedPairs::find
INLINE_FUNCTION_HD uint32 find(const PairType &p) const
Definition: unsortedPairs.hpp:151
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::unsortedPairs::ExecutionSpace
executionSpace ExecutionSpace
Definition: unsortedPairs.hpp:40
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:158
pFlow::unsortedContactList::TagReFillPairs
Definition: unsortedContactList.hpp:50
pFlow::unsortedContactList::TypeInfoNV
TypeInfoNV("unsortedContactList")
pFlow::unsortedContactList::operator()
INLINE_FUNCTION_HD void operator()(TagReFillPairs, uint32 idx) const
Definition: unsortedContactList.hpp:153