/*------------------------------- 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 class sortedContactList : public sortedPairs { public: using SortedPairs = sortedPairs; 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 values_; int32 size0_ = 0; ViewType1D sortedPairs0_; ViewType1D values0_; void adjustCapacity() { if(auto s = this->size(); s > values_.size()) { reallocNoInit(values_, s); } } using rpReFillPairs = Kokkos::RangePolicy< ExecutionSpace, Kokkos::Schedule, Kokkos::IndexType, 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__