unsortedPairs.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 __unsortedPairs_hpp__
22 #define __unsortedPairs_hpp__
23 
24 #include "KokkosTypes.hpp"
25 #include "types.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 template<typename executionSpace, typename idType>
33 {
34 public:
35 
37 
38  using IdType = idType;
39 
40  using ExecutionSpace = executionSpace;
41 
42  using memory_space = typename ExecutionSpace::memory_space;
43 
45 
47 
48  struct pairAccessor
49  {
51 
53 
55  int32 size()const { return Container_.size(); }
56 
58  int32 loopCount()const { return Container_.capacity(); }
59 
61  bool isValid(int32 idx)const { return Container_.valid_at(idx); }
62 
64  PairType getPair(int idx)const { return Container_.key_at(idx); }
65 
67  bool getPair(int32 idx, PairType& pair)const {
68  if(Container_.valid_at(idx)) {
69  pair = Container_.key_at(idx);
70  return true;
71  }
72  return false;
73  }
74  };
75 
76 protected:
77 
79 
80 
81 public:
82 
83  // - type info
84  TypeInfoNV("unsorderedPairs");
85 
86  // constructor
88  :
89  container_(capacity) // the minimum capacity would be 128
90  {}
91 
93  {
94  container_.clear();
95  return true;
96  }
97 
99  {
100  return true;
101  }
102 
103  // - Device call
105  int32 insert(idType i, idType j)const
106  {
107  if(auto insertResult = container_.insert(PairType(i,j)); insertResult.failed())
108  return -1;
109  else
110  return insertResult.index();
111 
112  }
113 
115  int32 insert(const PairType& p)const
116  {
117  if(auto insertResult = container_.insert(p); insertResult.failed())
118  return -1;
119  else
120  return insertResult.index();
121 
122  }
123 
124  // - Device call
125  // return the pair at index idx
126  // perform no check for size and existance
129  {
130  return container_.key_at(idx);
131  }
132 
133  // - Device call
134  // return the pair at index idx
136  bool getPair(int32 idx, PairType& p)const
137  {
138  if(container_.valid_at(idx))
139  {
140  p = container_.key_at(idx);
141  return true;
142  }
143  else
144  {
145 
146  return false;
147  }
148  }
149 
151  int32 find(const PairType & p)const
152  {
153  if( auto idx = container_.find(p);
154  idx != Kokkos::UnorderedMapInvalidIndex )
155  return idx;
156  else
157  return -1;
158  }
159 
161  bool isValid(int32 idx)const
162  {
163  return container_.valid_at(idx);
164  }
165 
166 
168  int32 capacity() const
169  {
170  return container_.capacity();
171  }
172 
174  {
175  return container_.capacity();
176  }
177 
178  //use this when the value of size_ is updated
180  int32 size()const
181  {
182  return container_.size();
183  }
184 
186  {
187  return {container_};
188  }
189 
194  {
195  uint newCap = container_.capacity()+len;
196  this->clear();
197  container_.rehash(newCap);
198  }
199 
201  void clear()
202  {
203  container_.clear();
204  }
205 
206  const ContainerType& container()const
207  {
208  return container_;
209  }
210 
211 };
212 
213 
214 }
215 
216 #endif //__unsortedPairs_hpp__
pFlow::unsortedPairs::pairAccessor::size
INLINE_FUNCTION_HD int32 size() const
Definition: unsortedPairs.hpp:55
pFlow::unsortedPairs::getPair
INLINE_FUNCTION_HD bool getPair(int32 idx, PairType &p) const
Definition: unsortedPairs.hpp:136
pFlow::unsortedPairs::size
INLINE_FUNCTION_H int32 size() const
Definition: unsortedPairs.hpp:180
pFlow::unsortedPairs::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: unsortedPairs.hpp:42
pFlow::unsortedPairs::PairType
kPair< idType, idType > PairType
Definition: unsortedPairs.hpp:44
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD int32 capacity() const
Definition: unsortedPairs.hpp:168
types.hpp
pFlow::unsortedPairs::pairAccessor::getPair
INLINE_FUNCTION_HD PairType getPair(int idx) const
Definition: unsortedPairs.hpp:64
pFlow::unsortedPairs::pairAccessor::getPair
INLINE_FUNCTION_HD bool getPair(int32 idx, PairType &pair) const
Definition: unsortedPairs.hpp:67
KokkosTypes.hpp
pFlow::unsortedPairs::afterBroadSearch
bool afterBroadSearch()
Definition: unsortedPairs.hpp:98
pFlow::unsortedPairs::getPair
INLINE_FUNCTION_HD PairType getPair(int32 idx) const
Definition: unsortedPairs.hpp:128
pFlow::unsortedPairs
Definition: unsortedPairs.hpp:32
pFlow::unsortedPairs::IdType
idType IdType
Definition: unsortedPairs.hpp:38
pFlow
Definition: demComponent.hpp:28
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::unsortedPairs::insert
INLINE_FUNCTION_HD int32 insert(const PairType &p) const
Definition: unsortedPairs.hpp:115
pFlow::unsortedPairs::pairAccessor::loopCount
INLINE_FUNCTION_HD int32 loopCount() const
Definition: unsortedPairs.hpp:58
pFlow::unsortedPairs::TypeInfoNV
TypeInfoNV("unsorderedPairs")
pFlow::unsortedPairs::pairAccessor::isValid
INLINE_FUNCTION_HD bool isValid(int32 idx) const
Definition: unsortedPairs.hpp:61
pFlow::unorderedSet
Kokkos::UnorderedMap< Key, void, properties... > unorderedSet
Definition: KokkosTypes.hpp:74
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::unsortedPairs::insert
INLINE_FUNCTION_HD int32 insert(idType i, idType j) const
Definition: unsortedPairs.hpp:105
pFlow::unsortedPairs::clear
INLINE_FUNCTION_H void clear()
Definition: unsortedPairs.hpp:201
pFlow::unsortedPairs::pairAccessor::Container_
ContainerType Container_
Definition: unsortedPairs.hpp:52
pFlow::unsortedPairs::loopCount
int32 loopCount() const
Definition: unsortedPairs.hpp:173
pFlow::unsortedPairs::getPairs
pairAccessor getPairs() const
Definition: unsortedPairs.hpp:185
pFlow::unsortedPairs::ContainerType
unorderedSet< PairType, ExecutionSpace > ContainerType
Definition: unsortedPairs.hpp:46
pFlow::unsortedPairs::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedPairs.hpp:92
pFlow::unsortedPairs::pairAccessor
Definition: unsortedPairs.hpp:48
pFlow::unsortedPairs::unsortedPairs
unsortedPairs(int32 capacity=1)
Definition: unsortedPairs.hpp:87
pFlow::unsortedPairs::find
INLINE_FUNCTION_HD int32 find(const PairType &p) const
Definition: unsortedPairs.hpp:151
pFlow::unsortedPairs::increaseCapacityBy
INLINE_FUNCTION_H void increaseCapacityBy(int32 len)
increase the capacity of the container by at-least len the content will be erased.
Definition: unsortedPairs.hpp:193
pFlow::unsortedPairs::container
const ContainerType & container() const
Definition: unsortedPairs.hpp:206
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::unsortedPairs::ExecutionSpace
executionSpace ExecutionSpace
Definition: unsortedPairs.hpp:40
pFlow::unsortedPairs::pairAccessor::PairType
typename UnsortedPairs::PairType PairType
Definition: unsortedPairs.hpp:50
pFlow::kPair
Kokkos::pair< T1, T2 > kPair
Definition: KokkosTypes.hpp:52