unsortedContactList.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __unsortedContactList_hpp__
22 #define __unsortedContactList_hpp__
23 
24 namespace pFlow
25 {
26 
27 
28 template<typename valueType, typename executionSpace, typename idType>
30 :
31  public unsortedPairs<executionSpace, idType>
32 {
33 public:
34 
35  using ValueType = valueType;
36 
38 
39  using IdType = typename UnsortedPairs::IdType;
40 
42 
43  using memory_space = typename ExecutionSpace::memory_space;
44 
46 
48 
49  class TagReFillPairs{};
50 
51 protected:
52 
55 
58 
61 
63  {
64  auto cap = this->capacity();
65  if(cap > values_.size())
66  {
67  reallocNoInit(values_, cap);
68  }
69 
70  }
71 
72  using rpFillPairs = Kokkos::RangePolicy<
74  Kokkos::Schedule<Kokkos::Static>,
75  Kokkos::IndexType<int32>,
77 
78 
79 public:
80 
81  TypeInfoNV("unsortedContactList");
82 
84  :
86  values_("values", UnsortedPairs::capacity()),
88  values0_("values0",container0_.capacity())
89  {}
90 
91 
93  {
94  // swap conainer and values
98  }
99 
101  {
102 
104 
105  adjustCapacity();
106 
107  Kokkos::parallel_for(
108  "reFillPairs",
109  rpFillPairs(0,this->capacity()),
110  *this);
111  Kokkos::fence();
112 
113  return true;
114  }
115 
118  {
119  return values_[idx];
120  }
121 
123  bool getValue(const PairType& p, ValueType& val)const
124  {
125  if(auto idx = this->find(p); idx>=0)
126  {
127  val = getValue(idx);
128  return true;
129  }
130  return false;
131  }
132 
134  void setValue(int32 idx, const ValueType& val)const
135  {
136  values_[idx] = val;
137  }
138 
140  bool setValue(const PairType& p, const ValueType& val)const
141  {
142  if(auto idx = this->find(p); idx>=0)
143  {
144  setValue(idx, val);
145  return true;;
146  }
147  return false;
148  }
149 
152  {
153  if( this->isValid(idx) )
154  {
155  if( int32 idx0 =
156  container0_.find(this->getPair(idx));
157  idx0>=0 )
158  {
159  values_[idx] = values0_[idx0];
160  }
161  else
162  {
163  values_[idx] = ValueType();
164  }
165  }
166  // invalid locations should not be filled.
167  }
168 
169 }; //unsortedContactList
170 
171 
172 } // pFlow
173 
174 
175 #endif //__unsortedContactList_hpp__
pFlow::unsortedContactList::values_
ViewType1D< ValueType, ExecutionSpace > values_
storage for keeping the values of the current list
Definition: unsortedContactList.hpp:54
pFlow::unsortedContactList::ContainerType
typename UnsortedPairs::ContainerType ContainerType
Definition: unsortedContactList.hpp:47
pFlow::unsortedContactList::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: unsortedContactList.hpp:43
pFlow::unsortedContactList::rpFillPairs
Kokkos::RangePolicy< ExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 >, TagReFillPairs > rpFillPairs
Definition: unsortedContactList.hpp:76
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD bool getValue(const PairType &p, ValueType &val) const
Definition: unsortedContactList.hpp:123
pFlow::unsortedContactList::ExecutionSpace
typename UnsortedPairs::ExecutionSpace ExecutionSpace
Definition: unsortedContactList.hpp:41
pFlow::unsortedContactList::values0_
ViewType1D< ValueType, ExecutionSpace > values0_
storage for keeping values from the previous list
Definition: unsortedContactList.hpp:60
pFlow::unsortedPairs::PairType
kPair< idType, idType > PairType
Definition: unsortedPairs.hpp:44
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD int32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD ValueType getValue(int32 idx) const
Definition: unsortedContactList.hpp:117
pFlow::unsortedContactList::adjustCapacity
void adjustCapacity()
Definition: unsortedContactList.hpp:62
pFlow::unsortedContactList::unsortedContactList
unsortedContactList(int32 capacity=1)
Definition: unsortedContactList.hpp:83
pFlow::unsortedContactList::afterBroadSearch
bool afterBroadSearch()
Definition: unsortedContactList.hpp:100
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
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: demComponent.hpp:28
pFlow::unsortedContactList::ValueType
valueType ValueType
Definition: unsortedContactList.hpp:35
pFlow::unsortedPairs::isValid
INLINE_FUNCTION_HD bool isValid(int32 idx) const
Definition: unsortedPairs.hpp:161
pFlow::unsortedPairs::container_
ContainerType container_
Definition: unsortedPairs.hpp:78
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::unsortedContactList::PairType
typename UnsortedPairs::PairType PairType
Definition: unsortedContactList.hpp:45
pFlow::unsortedContactList
Definition: unsortedContactList.hpp:29
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD bool setValue(const PairType &p, const ValueType &val) const
Definition: unsortedContactList.hpp:140
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:39
pFlow::unsortedContactList::container0_
ContainerType container0_
storage for keeping pairs from the previous list
Definition: unsortedContactList.hpp:57
pFlow::unsortedContactList::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedContactList.hpp:92
pFlow::unsortedPairs::find
INLINE_FUNCTION_HD int32 find(const PairType &p) const
Definition: unsortedPairs.hpp:151
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD void setValue(int32 idx, const ValueType &val) const
Definition: unsortedContactList.hpp:134
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:67
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::unsortedPairs::ExecutionSpace
executionSpace ExecutionSpace
Definition: unsortedPairs.hpp:40
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:121
pFlow::unsortedContactList::TagReFillPairs
Definition: unsortedContactList.hpp:49
pFlow::unsortedContactList::operator()
INLINE_FUNCTION_HD void operator()(TagReFillPairs, int32 idx) const
Definition: unsortedContactList.hpp:151
pFlow::unsortedContactList::TypeInfoNV
TypeInfoNV("unsortedContactList")