# PhasicFlow: src/Interaction/contactLists/sortedContactList.hpp Source File

sortedContactList.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 __sortedContactList_hpp__
#define __sortedContactList_hpp__
#include "sortedPairs.hpp"
namespace pFlow
{
template<typename valueType, typename executionSpace, typename idType>
class sortedContactList
:
public sortedPairs<executionSpace, idType>
{
public:
using SortedPairs = sortedPairs<executionSpace, idType>;
using ValueType = valueType;
using IdType = typename SortedPairs::IdType;
using ExecutionSpace = typename SortedPairs::ExecutionSpace;
using memory_space = typename SortedPairs::memory_space;
using PairType = typename SortedPairs::PairType;
using ContainerType = typename SortedPairs::ContainerType;
class TagReFillPairs{};
protected:
ViewType1D<ValueType,ExecutionSpace> values_;
int32 size0_ = 0;
ViewType1D<PairType,ExecutionSpace> sortedPairs0_;
ViewType1D<ValueType,ExecutionSpace> values0_;
void adjustCapacity()
{
if(auto s = this->size(); s > values_.size())
{
reallocNoInit(values_, s);
}
}
using rpReFillPairs = Kokkos::RangePolicy<
ExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>,
TagReFillPairs>;
public:
TypeInfoNV("sortedContactList");
sortedContactList(int32 initialSize =1)
:
SortedPairs(initialSize),
values_("values", SortedPairs::capacity()),
sortedPairs0_("sortedPairs0", SortedPairs::capacity()),
values0_("values0", SortedPairs::capacity())
{}
bool beforeBroadSearch()
{
swapViews(values0_, values_);
swapViews(sortedPairs0_, this->sortedPairs_);
size0_ = this->size();
return SortedPairs::beforeBroadSearch();
}
bool afterBroadSearch()
{
SortedPairs::afterBroadSearch();
adjustCapacity();
Kokkos::parallel_for(
"sortedContactList::reFillPairs",
rpReFillPairs(0, this->size() ),
*this
);
Kokkos::fence();
return true;
}
INLINE_FUNCTION_HD
ValueType getValue(int32 idx)const
{
return values_[idx];
}
INLINE_FUNCTION_HD
void setValue(int32 idx, const ValueType& val)const
{
values_[idx] = val;
}
INLINE_FUNCTION_HD
void operator()(TagReFillPairs, int32 idx)const
{
auto searchLen = max(size0_/1000,10);
auto start = max(0,idx-searchLen);
auto end = min(size0_,idx+searchLen);
auto newPair = this->sortedPairs_[idx];
if( auto idx0 = binarySearch(
sortedPairs0_,
start,
end,
newPair);
idx0>=0)
{
values_[idx] = values0_[idx0];
}
else if(auto idx0 = binarySearch(
sortedPairs0_,
start,
end,
newPair);
idx0>=0)
{
values_[idx] = values0_[idx0];
}
else
{
values_[idx] = ValueType();
}
}
}; // sortedContactList
} // pFlow
#endif //__sortedContactList_hpp__
pFlow::sortedContactList::getValue
INLINE_FUNCTION_HD ValueType getValue(int32 idx) const
Definition: sortedContactList.hpp:117
pFlow::sortedPairs::IdType
typename UnsortedPairs::IdType IdType
Definition: sortedPairs.hpp:41
pFlow::sortedContactList::memory_space
typename SortedPairs::memory_space memory_space
Definition: sortedContactList.hpp:44
pFlow::sortedPairs::sortedPairs_
ViewType1D< PairType, ExecutionSpace > sortedPairs_
Definition: sortedPairs.hpp:92
pFlow::sortedPairs::beforeBroadSearch
bool beforeBroadSearch()
Definition: sortedPairs.hpp:121
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD int32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::sortedPairs::PairType
typename UnsortedPairs::PairType PairType
Definition: sortedPairs.hpp:47
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
pFlow::sortedContactList::values0_
ViewType1D< ValueType, ExecutionSpace > values0_
Definition: sortedContactList.hpp:60
pFlow::sortedContactList::operator()
INLINE_FUNCTION_HD void operator()(TagReFillPairs, int32 idx) const
Definition: sortedContactList.hpp:129
pFlow
Definition: demComponent.hpp:28
pFlow::sortedContactList::sortedPairs0_
ViewType1D< PairType, ExecutionSpace > sortedPairs0_
Definition: sortedContactList.hpp:58
pFlow::sortedContactList::adjustCapacity
void adjustCapacity()
Definition: sortedContactList.hpp:63
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::sortedPairs::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: sortedPairs.hpp:45
pFlow::sortedContactList::TypeInfoNV
TypeInfoNV("sortedContactList")
pFlow::sortedContactList::afterBroadSearch
bool afterBroadSearch()
Definition: sortedContactList.hpp:100
pFlow::sortedContactList::values_
ViewType1D< ValueType, ExecutionSpace > values_
Definition: sortedContactList.hpp:54
pFlow::binarySearch
INLINE_FUNCTION_HD int32 binarySearch(const ViewType1D< Type, properties... > &view, int32 start, int32 end, const Type &val)
Definition: ViewAlgorithms.hpp:495
pFlow::sortedPairs::afterBroadSearch
bool afterBroadSearch()
Definition: sortedPairs.hpp:127
pFlow::sortedPairs::size
INLINE_FUNCTION_H int32 size() const
Definition: sortedPairs.hpp:167
pFlow::sortedContactList::ExecutionSpace
typename SortedPairs::ExecutionSpace ExecutionSpace
Definition: sortedContactList.hpp:42
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::sortedContactList::sortedContactList
sortedContactList(int32 initialSize=1)
Definition: sortedContactList.hpp:84
pFlow::sortedPairs::ContainerType
typename UnsortedPairs::ContainerType ContainerType
Definition: sortedPairs.hpp:49
pFlow::sortedContactList::TagReFillPairs
Definition: sortedContactList.hpp:50
pFlow::sortedPairs
Definition: sortedPairs.hpp:33
pFlow::sortedContactList
Definition: sortedContactList.hpp:30
pFlow::sortedContactList::ContainerType
typename SortedPairs::ContainerType ContainerType
Definition: sortedContactList.hpp:48
pFlow::sortedContactList::ValueType
valueType ValueType
Definition: sortedContactList.hpp:38
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::sortedContactList::IdType
typename SortedPairs::IdType IdType
Definition: sortedContactList.hpp:40
pFlow::sortedContactList::rpReFillPairs
Kokkos::RangePolicy< ExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 >, TagReFillPairs > rpReFillPairs
Definition: sortedContactList.hpp:77
pFlow::sortedContactList::PairType
typename SortedPairs::PairType PairType
Definition: sortedContactList.hpp:46
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::sortedContactList::size0_
int32 size0_
Definition: sortedContactList.hpp:56
pFlow::sortedContactList::setValue
INLINE_FUNCTION_HD void setValue(int32 idx, const ValueType &val) const
Definition: sortedContactList.hpp:123
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:121
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::sortedPairs::ExecutionSpace
typename UnsortedPairs::ExecutionSpace ExecutionSpace
Definition: sortedPairs.hpp:43
sortedPairs.hpp
pFlow::sortedContactList::beforeBroadSearch
bool beforeBroadSearch()
Definition: sortedContactList.hpp:92