www.cemf.ir
scatteredFieldAccess.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 __scatteredFieldAccess_hpp__
22 #define __scatteredFieldAccess_hpp__
23 
24 
25 #include "phasicFlowKokkos.hpp"
26 
27 namespace pFlow
28 {
29 
30 
31 template<typename T, typename MemorySpace=void>
33 {
34 public:
35 
37 
38  using device_type = typename viewType::device_type;
39 
40  using memory_space = typename viewType::memory_space;
41 
42  using execution_space = typename viewType::execution_space;
43 
44 private:
45 
47 
49 
51 
52 public:
53 
55  indices_(),
56  fieldVals_()
57  {}
58 
60  uint32 sz,
62  const ViewType1D<T, memory_space>& fVals)
63  :
64  size_(sz),
65  indices_(ind),
66  fieldVals_(fVals)
67  {}
68 
70 
72 
74 
76 
77  ~scatteredFieldAccess() = default;
78 
79  // - Methods
80 
83  {
84  return fieldVals_(indices_(i));
85  }
86 
88  const T& operator()(uint32 i)const
89  {
90  return fieldVals_(indices_(i));
91  }
92 
95  {
96  return fieldVals_[indices_[i]];
97  }
98 
100  const T& operator[](uint32 i)const
101  {
102  return fieldVals_[indices_[i]];
103  }
104 
106  const viewType& field()const
107  {
108  return fieldVals_;
109  }
110 
113  {
114  return fieldVals_;
115  }
116 
117  auto& indices()
118  {
119  return indices_;
120  }
121 
122  const auto& indices()const
123  {
124  return indices_;
125  }
126 
129  {
130  return indices_[i];
131  }
132 
134  uint32 size()const
135  {
136  return size_;
137  }
138 
140  bool empty()const
141  {
142  return size_ == 0;
143  }
144 
145  T getFirstCopy()const
146  {
147  T val;
148  uint32 n = indices_(0);
149  getNth(val, fieldVals_, n);
150  return val;
151  }
152 
153  T getLastCopy()const
154  {
155  T val;
156  if(empty())return val;
157  uint32 n = indices_(size()-1);
158  getNth(val, fieldVals_, n);
159  return val;
160  }
161 
162 };
163 
164 template<typename T>
167 
168 template<typename T>
169  using hostScatteredFieldAccess =
171 
172 } // pFlow
173 
174 
175 #endif //__scatteredFieldAccess_hpp__
176 
pFlow::scatteredFieldAccess::~scatteredFieldAccess
~scatteredFieldAccess()=default
pFlow::scatteredFieldAccess::scatteredFieldAccess
scatteredFieldAccess()
Definition: scatteredFieldAccess.hpp:54
pFlow::scatteredFieldAccess::device_type
typename viewType::device_type device_type
Definition: scatteredFieldAccess.hpp:38
pFlow::scatteredFieldAccess::field
const INLINE_FUNCTION_HD viewType & field() const
Definition: scatteredFieldAccess.hpp:106
pFlow::scatteredFieldAccess
Definition: scatteredFieldAccess.hpp:32
pFlow::scatteredFieldAccess::operator[]
const INLINE_FUNCTION_HD T & operator[](uint32 i) const
Definition: scatteredFieldAccess.hpp:100
pFlow::scatteredFieldAccess::size
INLINE_FUNCTION_HD uint32 size() const
Definition: scatteredFieldAccess.hpp:134
pFlow::scatteredFieldAccess::getLastCopy
T getLastCopy() const
Definition: scatteredFieldAccess.hpp:153
pFlow::scatteredFieldAccess::fieldVals_
viewType fieldVals_
Definition: scatteredFieldAccess.hpp:50
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::scatteredFieldAccess::operator=
scatteredFieldAccess & operator=(const scatteredFieldAccess &)=default
pFlow::scatteredFieldAccess::indices
const auto & indices() const
Definition: scatteredFieldAccess.hpp:122
pFlow::getNth
INLINE_FUNCTION_H void getNth(Type &dst, const ViewType1D< Type, sProperties... > &src, const uint32 n)
Definition: ViewAlgorithms.hpp:270
pFlow
Definition: demGeometry.hpp:27
pFlow::deviceScatteredFieldAccess
scatteredFieldAccess< T, typename DefaultExecutionSpace::memory_space > deviceScatteredFieldAccess
Definition: scatteredFieldAccess.hpp:166
pFlow::scatteredFieldAccess::indices_
ViewType1D< uint32, memory_space > indices_
Definition: scatteredFieldAccess.hpp:48
phasicFlowKokkos.hpp
pFlow::scatteredFieldAccess::getFirstCopy
T getFirstCopy() const
Definition: scatteredFieldAccess.hpp:145
pFlow::scatteredFieldAccess::operator()
INLINE_FUNCTION_HD T & operator()(uint32 i)
Definition: scatteredFieldAccess.hpp:82
pFlow::scatteredFieldAccess::memory_space
typename viewType::memory_space memory_space
Definition: scatteredFieldAccess.hpp:40
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
pFlow::scatteredFieldAccess::size_
uint32 size_
Definition: scatteredFieldAccess.hpp:46
pFlow::scatteredFieldAccess::index
INLINE_FUNCTION_HD uint32 index(uint32 i) const
Definition: scatteredFieldAccess.hpp:128
pFlow::scatteredFieldAccess::indices
auto & indices()
Definition: scatteredFieldAccess.hpp:117
pFlow::scatteredFieldAccess::execution_space
typename viewType::execution_space execution_space
Definition: scatteredFieldAccess.hpp:42
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::scatteredFieldAccess::field
INLINE_FUNCTION_HD viewType & field()
Definition: scatteredFieldAccess.hpp:112
pFlow::scatteredFieldAccess::operator()
const INLINE_FUNCTION_HD T & operator()(uint32 i) const
Definition: scatteredFieldAccess.hpp:88
pFlow::scatteredFieldAccess::scatteredFieldAccess
scatteredFieldAccess(uint32 sz, const ViewType1D< uint32, memory_space > &ind, const ViewType1D< T, memory_space > &fVals)
Definition: scatteredFieldAccess.hpp:59
pFlow::scatteredFieldAccess::viewType
ViewType1D< T, MemorySpace > viewType
Definition: scatteredFieldAccess.hpp:36
pFlow::scatteredFieldAccess::empty
INLINE_FUNCTION_HD bool empty() const
Definition: scatteredFieldAccess.hpp:140
pFlow::scatteredFieldAccess::operator[]
INLINE_FUNCTION_HD T & operator[](uint32 i)
Definition: scatteredFieldAccess.hpp:94
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55