www.cemf.ir
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 #ifndef __unsortedContactList_hpp__
21 #define __unsortedContactList_hpp__
22 
23 #include "unsortedPairs.hpp"
24 
25 namespace pFlow
26 {
27 
28 
29 template<typename valueType, typename executionSpace, typename idType>
31 :
32  public unsortedPairs<executionSpace, idType>
33 {
34 public:
35 
36  using ValueType = valueType;
37 
39 
40  using IdType = typename UnsortedPairs::IdType;
41 
43 
44  using memory_space = typename ExecutionSpace::memory_space;
45 
47 
49 
50  class TagReFillPairs{};
51 
52 protected:
53 
56 
59 
62 
64  {
65  auto cap = this->capacity();
66  if(cap > values_.size())
67  {
68  reallocNoInit(values_, cap);
69  }
70 
71  }
72 
73  using rpFillPairs = Kokkos::RangePolicy<
75  Kokkos::Schedule<Kokkos::Static>,
76  Kokkos::IndexType<uint32>,
78 
79 
80 public:
81 
82  TypeInfoNV("unsortedContactList");
83 
85  :
87  values_("values", UnsortedPairs::capacity()),
89  values0_("values0",container0_.capacity())
90  {}
91 
92 
94  {
95  // swap conainer and values
99  return true;
100  }
101 
103  {
104 
106 
107  adjustCapacity();
108 
109  Kokkos::parallel_for(
110  "reFillPairs",
111  rpFillPairs(0,this->capacity()),
112  *this);
113  Kokkos::fence();
114 
115  return true;
116  }
117 
120  {
121  return values_[idx];
122  }
123 
125  bool getValue(const PairType& p, ValueType& val)const
126  {
127  if(auto idx = this->find(p); idx!=static_cast<uint32>(-1))
128  {
129  val = getValue(idx);
130  return true;
131  }
132  return false;
133  }
134 
136  void setValue(uint32 idx, const ValueType& val)const
137  {
138  values_[idx] = val;
139  }
140 
142  bool setValue(const PairType& p, const ValueType& val)const
143  {
144  if(uint32 idx = this->find(p); idx!=static_cast<uint32>(-1))
145  {
146  setValue(idx, val);
147  return true;;
148  }
149  return false;
150  }
151 
154  {
155  if( this->isValid(idx) )
156  {
157  if( uint32 idx0 =
158  container0_.find(this->getPair(idx));
159  idx0!= static_cast<uint32>(-1) )
160  {
161  values_[idx] = values0_[idx0];
162  }
163  else
164  {
165  values_[idx] = ValueType();
166  }
167  }
168  // invalid locations should not be filled.
169  }
170 
171 }; //unsortedContactList
172 
173 
174 } // pFlow
175 
176 
177 #endif //__unsortedContactList_hpp__
pFlow::unsortedContactList::values_
ViewType1D< ValueType, ExecutionSpace > values_
storage for keeping the values of the current list
Definition: unsortedContactList.hpp:55
pFlow::unsortedContactList::ContainerType
typename UnsortedPairs::ContainerType ContainerType
Definition: unsortedContactList.hpp:48
pFlow::unsortedContactList::memory_space
typename ExecutionSpace::memory_space memory_space
Definition: unsortedContactList.hpp:44
pFlow::unsortedPairs::capacity
INLINE_FUNCTION_HD uint32 capacity() const
Definition: unsortedPairs.hpp:168
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD bool getValue(const PairType &p, ValueType &val) const
Definition: unsortedContactList.hpp:125
pFlow::unsortedContactList::ExecutionSpace
typename UnsortedPairs::ExecutionSpace ExecutionSpace
Definition: unsortedContactList.hpp:42
pFlow::unsortedContactList::values0_
ViewType1D< ValueType, ExecutionSpace > values0_
storage for keeping values from the previous list
Definition: unsortedContactList.hpp:61
pFlow::unsortedPairs::PairType
Pair< idType, idType > PairType
Definition: unsortedPairs.hpp:44
pFlow::unsortedContactList::getValue
INLINE_FUNCTION_HD ValueType getValue(int32 idx) const
Definition: unsortedContactList.hpp:119
pFlow::unsortedContactList::adjustCapacity
void adjustCapacity()
Definition: unsortedContactList.hpp:63
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, uint32 len)
Definition: KokkosUtilities.hpp:64
pFlow::unsortedContactList::afterBroadSearch
bool afterBroadSearch()
Definition: unsortedContactList.hpp:102
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: demGeometry.hpp:27
pFlow::unsortedContactList::ValueType
valueType ValueType
Definition: unsortedContactList.hpp:36
pFlow::unsortedContactList::unsortedContactList
unsortedContactList(uint32 capacity=1)
Definition: unsortedContactList.hpp:84
pFlow::unsortedPairs::container_
ContainerType container_
Definition: unsortedPairs.hpp:78
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD void setValue(uint32 idx, const ValueType &val) const
Definition: unsortedContactList.hpp:136
pFlow::unsortedContactList::PairType
typename UnsortedPairs::PairType PairType
Definition: unsortedContactList.hpp:46
pFlow::unsortedPairs::isValid
INLINE_FUNCTION_HD bool isValid(uint32 idx) const
Definition: unsortedPairs.hpp:161
pFlow::unsortedContactList
Definition: unsortedContactList.hpp:30
unsortedPairs.hpp
pFlow::unsortedContactList::setValue
INLINE_FUNCTION_HD bool setValue(const PairType &p, const ValueType &val) const
Definition: unsortedContactList.hpp:142
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
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:40
pFlow::unsortedContactList::container0_
ContainerType container0_
storage for keeping pairs from the previous list
Definition: unsortedContactList.hpp:58
pFlow::unsortedContactList::beforeBroadSearch
bool beforeBroadSearch()
Definition: unsortedContactList.hpp:93
pFlow::unsortedContactList::rpFillPairs
Kokkos::RangePolicy< ExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< uint32 >, TagReFillPairs > rpFillPairs
Definition: unsortedContactList.hpp:77
pFlow::unsortedPairs::find
INLINE_FUNCTION_HD uint32 find(const PairType &p) const
Definition: unsortedPairs.hpp:151
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::unsortedPairs::ExecutionSpace
executionSpace ExecutionSpace
Definition: unsortedPairs.hpp:40
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:158
pFlow::unsortedContactList::TagReFillPairs
Definition: unsortedContactList.hpp:50
pFlow::unsortedContactList::TypeInfoNV
TypeInfoNV("unsortedContactList")
pFlow::unsortedContactList::operator()
INLINE_FUNCTION_HD void operator()(TagReFillPairs, uint32 idx) const
Definition: unsortedContactList.hpp:153