mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-22 16:28:30 +00:00
src folder
This commit is contained in:
171
src/Interaction/contactLists/sortedContactList.H
Normal file
171
src/Interaction/contactLists/sortedContactList.H
Normal file
@ -0,0 +1,171 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __sortedContactList_H__
|
||||
|
||||
#include "sortedPairs.H"
|
||||
|
||||
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:
|
||||
|
||||
TypeNameNV("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_H__
|
258
src/Interaction/contactLists/sortedPairs.H
Normal file
258
src/Interaction/contactLists/sortedPairs.H
Normal file
@ -0,0 +1,258 @@
|
||||
/*------------------------------- 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 __sortedPairs_H__
|
||||
#define __sortedPairs_H__
|
||||
|
||||
#include "unsortedPairs.H"
|
||||
#include "KokkosUtilities.H"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
|
||||
template<typename executionSpace, typename idType>
|
||||
class sortedPairs
|
||||
:
|
||||
public unsortedPairs<executionSpace, idType>
|
||||
{
|
||||
public:
|
||||
|
||||
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;
|
||||
|
||||
struct pairAccessor
|
||||
{
|
||||
using PairType = typename sortedPairs::PairType;
|
||||
|
||||
int32 size_;
|
||||
|
||||
ViewType1D<PairType,ExecutionSpace> sortedParis_;
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 size()const { return size_; }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 loopCount()const { return size_; }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool isValid(int32 i)const { return i<size_; }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
PairType getPair(int i)const { return sortedParis_[i]; }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool getPair(int32 i, PairType& pair)const {
|
||||
if(i<size_) {
|
||||
pair = sortedParis_[i];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class TagFillFlag{};
|
||||
|
||||
class TagFillPairs{};
|
||||
|
||||
protected:
|
||||
|
||||
/// size of pair list
|
||||
int32 size_ = 0;
|
||||
|
||||
ViewType1D<int32,ExecutionSpace> flags_;
|
||||
|
||||
ViewType1D<PairType,ExecutionSpace> sortedPairs_;
|
||||
|
||||
using rpFillFlag = Kokkos::RangePolicy<
|
||||
ExecutionSpace,
|
||||
Kokkos::Schedule<Kokkos::Static>,
|
||||
Kokkos::IndexType<int32>,
|
||||
TagFillFlag >;
|
||||
|
||||
using rpFillPairs = Kokkos::RangePolicy<
|
||||
ExecutionSpace,
|
||||
Kokkos::Schedule<Kokkos::Static>,
|
||||
Kokkos::IndexType<int32>,
|
||||
TagFillPairs>;
|
||||
|
||||
public:
|
||||
|
||||
// - type info
|
||||
TypeNameNV("sortedPairs");
|
||||
|
||||
|
||||
// constructors
|
||||
sortedPairs(int32 initialSize =1)
|
||||
:
|
||||
UnsortedPairs(initialSize),
|
||||
flags_("flags_",UnsortedPairs::capacity()+1),
|
||||
sortedPairs_("sortedPairs_",UnsortedPairs::capacity())
|
||||
{}
|
||||
|
||||
|
||||
bool beforeBroadSearch()
|
||||
{
|
||||
this->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool afterBroadSearch()
|
||||
{
|
||||
prepareSorted();
|
||||
return true;
|
||||
}
|
||||
|
||||
// - Device call
|
||||
// return the pair at index idx
|
||||
// perform no check for size and existance
|
||||
INLINE_FUNCTION_HD
|
||||
PairType getPair(int32 idx)const
|
||||
{
|
||||
return sortedPairs_[idx];
|
||||
}
|
||||
|
||||
// - Device/host call
|
||||
// return the pair at index idx
|
||||
INLINE_FUNCTION_HD
|
||||
bool getPair(int32 idx, PairType& p)const
|
||||
{
|
||||
if(isValid(idx))
|
||||
{
|
||||
p = getPair(idx);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool isValid(int32 idx)const
|
||||
{
|
||||
return idx < size_;
|
||||
}
|
||||
|
||||
|
||||
//use this when the value of size_ is updated
|
||||
INLINE_FUNCTION_H
|
||||
int32 size()const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
int32 loopCount()const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
pairAccessor getPairs()const
|
||||
{
|
||||
return {size_, sortedPairs_};
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_H
|
||||
void clear()
|
||||
{
|
||||
UnsortedPairs::clear();
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void prepareSorted()
|
||||
{
|
||||
// first check the size of flags_
|
||||
int32 capacity = UnsortedPairs::capacity();
|
||||
|
||||
if( capacity+1 > flags_.size() )
|
||||
{
|
||||
reallocNoInit(flags_, capacity+1);
|
||||
}
|
||||
|
||||
// fill the flags
|
||||
Kokkos::parallel_for(
|
||||
"contactPairsSorted::fillFlag",
|
||||
rpFillFlag(0,capacity+1),
|
||||
*this);
|
||||
Kokkos::fence();
|
||||
|
||||
|
||||
// inclusive scan on flags_
|
||||
exclusiveScan(flags_, 0, capacity+1,flags_,0);
|
||||
|
||||
Kokkos::fence(); // Kokkos's scan is blocking I guess. So, this could be removed.
|
||||
|
||||
// get the last value of flags_ to obtain the size of sortedPairs_
|
||||
getNth(size_, flags_, capacity);
|
||||
|
||||
if(size_ == 0 )return;
|
||||
|
||||
// resize sortedPairs_ if necessary;
|
||||
if( size_>sortedPairs_.size() )
|
||||
{
|
||||
// get more space to prevent reallocations in next iterations
|
||||
int32 len = size_*1.1+1;
|
||||
reallocNoInit(sortedPairs_, len);
|
||||
}
|
||||
|
||||
Kokkos::parallel_for(
|
||||
"contactPairsSorted::fillPairs",
|
||||
rpFillPairs(0,this->capacity()),
|
||||
*this);
|
||||
Kokkos::fence();
|
||||
|
||||
// - sort paris based on the first and second
|
||||
sort(sortedPairs_, 0, size_ );
|
||||
|
||||
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
void operator()(TagFillFlag, int32 i)const
|
||||
{
|
||||
if(this->container_.valid_at(i) )
|
||||
flags_[i] = 1;
|
||||
else
|
||||
flags_[i] = 0;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
void operator()(TagFillPairs, int32 i)const
|
||||
{
|
||||
auto fi = flags_[i];
|
||||
if(fi!=flags_[i+1])
|
||||
sortedPairs_[fi] = this->container_.key_at(i);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //__sortedPairs_H__
|
175
src/Interaction/contactLists/unsortedContactList.H
Normal file
175
src/Interaction/contactLists/unsortedContactList.H
Normal file
@ -0,0 +1,175 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __unsortedContactList_H__
|
||||
|
||||
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:
|
||||
|
||||
/// storage for keeping the values of the current list
|
||||
ViewType1D<ValueType,ExecutionSpace> values_;
|
||||
|
||||
/// storage for keeping pairs from the previous list
|
||||
ContainerType container0_;
|
||||
|
||||
/// storage for keeping values from the previous list
|
||||
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<int32>,
|
||||
TagReFillPairs>;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
TypeNameNV("unsortedContactList");
|
||||
|
||||
unsortedContactList(int32 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_);
|
||||
return UnsortedPairs::beforeBroadSearch();
|
||||
}
|
||||
|
||||
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>=0)
|
||||
{
|
||||
val = getValue(idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
void setValue(int32 idx, const ValueType& val)const
|
||||
{
|
||||
values_[idx] = val;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool setValue(const PairType& p, const ValueType& val)const
|
||||
{
|
||||
if(auto idx = this->find(p); idx>=0)
|
||||
{
|
||||
setValue(idx, val);
|
||||
return true;;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
void operator()(TagReFillPairs, int32 idx)const
|
||||
{
|
||||
if( this->isValid(idx) )
|
||||
{
|
||||
if( int32 idx0 =
|
||||
container0_.find(this->getPair(idx));
|
||||
idx0>=0 )
|
||||
{
|
||||
values_[idx] = values0_[idx0];
|
||||
}
|
||||
else
|
||||
{
|
||||
values_[idx] = ValueType();
|
||||
}
|
||||
}
|
||||
// invalid locations should not be filled.
|
||||
}
|
||||
|
||||
}; //unsortedContactList
|
||||
|
||||
|
||||
} // pFlow
|
||||
|
||||
|
||||
#endif //__unsortedContactList_H__
|
216
src/Interaction/contactLists/unsortedPairs.H
Normal file
216
src/Interaction/contactLists/unsortedPairs.H
Normal file
@ -0,0 +1,216 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __unsortedPairs_H__
|
||||
|
||||
#include "KokkosTypes.H"
|
||||
#include "types.H"
|
||||
|
||||
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 = kPair<idType,idType>;
|
||||
|
||||
using ContainerType = unorderedSet<PairType, ExecutionSpace>;
|
||||
|
||||
struct pairAccessor
|
||||
{
|
||||
using PairType = typename UnsortedPairs::PairType;
|
||||
|
||||
ContainerType Container_;
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 size()const { return Container_.size(); }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 loopCount()const { return Container_.capacity(); }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool isValid(int32 idx)const { return Container_.valid_at(idx); }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
PairType getPair(int idx)const { return Container_.key_at(idx); }
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool getPair(int32 idx, PairType& pair)const {
|
||||
if(Container_.valid_at(idx)) {
|
||||
pair = Container_.key_at(idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
ContainerType container_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// - type info
|
||||
TypeNameNV("unsorderedPairs");
|
||||
|
||||
// constructor
|
||||
unsortedPairs(int32 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
|
||||
int32 insert(idType i, idType j)const
|
||||
{
|
||||
if(auto insertResult = container_.insert(PairType(i,j)); insertResult.failed())
|
||||
return -1;
|
||||
else
|
||||
return insertResult.index();
|
||||
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 insert(const PairType& p)const
|
||||
{
|
||||
if(auto insertResult = container_.insert(p); insertResult.failed())
|
||||
return -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(int32 idx)const
|
||||
{
|
||||
return container_.key_at(idx);
|
||||
}
|
||||
|
||||
// - Device call
|
||||
// return the pair at index idx
|
||||
INLINE_FUNCTION_HD
|
||||
bool getPair(int32 idx, PairType& p)const
|
||||
{
|
||||
if(container_.valid_at(idx))
|
||||
{
|
||||
p = container_.key_at(idx);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 find(const PairType & p)const
|
||||
{
|
||||
if( auto idx = container_.find(p);
|
||||
idx != Kokkos::UnorderedMapInvalidIndex )
|
||||
return idx;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
bool isValid(int32 idx)const
|
||||
{
|
||||
return container_.valid_at(idx);
|
||||
}
|
||||
|
||||
|
||||
INLINE_FUNCTION_HD
|
||||
int32 capacity() const
|
||||
{
|
||||
return container_.capacity();
|
||||
}
|
||||
|
||||
int32 loopCount()const
|
||||
{
|
||||
return container_.capacity();
|
||||
}
|
||||
|
||||
//use this when the value of size_ is updated
|
||||
INLINE_FUNCTION_H
|
||||
int32 size()const
|
||||
{
|
||||
return container_.size();
|
||||
}
|
||||
|
||||
pairAccessor getPairs()const
|
||||
{
|
||||
return {container_};
|
||||
}
|
||||
|
||||
/// increase the capacity of the container by at-least len
|
||||
/// the content will be erased.
|
||||
INLINE_FUNCTION_H
|
||||
void increaseCapacityBy(int32 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_H__
|
Reference in New Issue
Block a user