indexContainer.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 __indexContainer_hpp__
22 #define __indexContainer_hpp__
23 
24 #include "span.hpp"
25 #include "KokkosTypes.hpp"
26 #include "KokkosUtilities.hpp"
27 #include "ViewAlgorithms.hpp"
28 
29 
30 namespace pFlow
31 {
32 
33 template<typename IndexType>
35 {
36 public:
37 
38  using DualViewType = Kokkos::DualView<IndexType*>;
39 
40  // - viewType of data on device
41  using DeviceViewType = typename DualViewType::t_dev;
42 
43  // - viewType of data on host
44  using HostViewType = typename DualViewType::t_host;
45 
46  template<typename ViewType>
48  {
49  protected:
50  ViewType view_;
51 
52  public:
53  IndexAccessor(ViewType v):
54  view_(v){}
55 
57  IndexType operator()(int32 i)const
58  {
59  return view_[i];
60  }
61  };
62 
63 protected:
64 
65  int32 min_ = 0;
66  int32 max_ = 0;
67  size_t size_ = 0;
68 
70 
71 public:
72 
74 
75  // half open [begin,end)
76  indexContainer(IndexType begin, IndexType end)
77  :
78  min_(begin),
79  max_(end-1),
80  size_(end-begin),
81  views_("indexContainer", size_)
82  {
83  pFlow::fillSequence(views_.h_view, 0, size_, min_);
84  copy(views_.d_view, views_.h_view);
85  }
86 
87 
88  indexContainer(IndexType* data, int32 numElems)
89  :
90  size_(numElems),
91  views_("indexContainer", numElems)
92  {
93  HostViewType hData(data, numElems);
94  copy(views_.h_view, hData);
95  copy(views_.d_view, views_.h_view);
96  min_ = pFlow::min(views_.d_view, 0, numElems);
97  max_ = pFlow::max(views_.d_view, 0, numElems);
98  }
99 
100  indexContainer(const indexContainer&) = default;
101 
102  indexContainer& operator = (const indexContainer&) = default;
103 
104  ~indexContainer() = default;
105 
107  size_t size()const
108  {
109  return size_;
110  }
111 
113  size_t empty()const
114  {
115  return size_==0;
116  }
117 
119  IndexType min()const
120  {
121  return min_;
122  }
123 
125  IndexType max()const
126  {
127  return max_;
128  }
129 
130  template<typename executionSpace>
133  {
134  if constexpr (isHostAccessible<executionSpace>())
135  {
136  return views_.h_view(i);
137  }else
138  {
139  return views_.d_view(i);
140  }
141  }
142 
143  const HostViewType& hostView()const
144  {
145  return views_.h_view;
146  }
147 
149  {
150  return views_.d_view;
151  }
152 
153  auto indicesHost()const
154  {
155  return IndexAccessor<HostViewType>(views_.h_view);
156  }
157 
158  auto indicesDevice()const
159  {
160  return IndexAccessor<DeviceViewType>(views_.d_veiw);
161  }
162 };
163 
164 
167 
168 
169 }
170 
171 
172 #endif
pFlow::indexContainer::indicesDevice
auto indicesDevice() const
Definition: indexContainer.hpp:158
pFlow::fillSequence
void fillSequence(Vector< T, Allocator > &vec, int32 start, int32 end, const T &startVal)
Definition: VectorAlgorithm.hpp:50
pFlow::indexContainer::indexContainer
indexContainer(IndexType *data, int32 numElems)
Definition: indexContainer.hpp:88
KokkosUtilities.hpp
pFlow::indexContainer::size_
size_t size_
Definition: indexContainer.hpp:67
pFlow::indexContainer::max
INLINE_FUNCTION_HD IndexType max() const
Definition: indexContainer.hpp:125
pFlow::indexContainer::empty
INLINE_FUNCTION_HD size_t empty() const
Definition: indexContainer.hpp:113
pFlow::indexContainer::views_
DualViewType views_
Definition: indexContainer.hpp:69
pFlow::indexContainer::min_
int32 min_
Definition: indexContainer.hpp:65
pFlow::copy
INLINE_FUNCTION_H void copy(const ViewType1D< dType, dProperties... > &dst, const ViewType1D< sType, sProperties... > &src)
Definition: ViewAlgorithms.hpp:296
pFlow::indexContainer::~indexContainer
~indexContainer()=default
ViewAlgorithms.hpp
pFlow::indexContainer::max_
int32 max_
Definition: indexContainer.hpp:66
KokkosTypes.hpp
pFlow::indexContainer::size
INLINE_FUNCTION_HD size_t size() const
Definition: indexContainer.hpp:107
pFlow::indexContainer< int32 >::DeviceViewType
typename DualViewType::t_dev DeviceViewType
Definition: indexContainer.hpp:41
pFlow::indexContainer::indexContainer
indexContainer(IndexType begin, IndexType end)
Definition: indexContainer.hpp:76
pFlow::indexContainer::IndexAccessor::operator()
INLINE_FUNCTION_HD IndexType operator()(int32 i) const
Definition: indexContainer.hpp:57
pFlow::indexContainer::IndexAccessor::view_
ViewType view_
Definition: indexContainer.hpp:50
pFlow
Definition: demComponent.hpp:28
pFlow::indexContainer::operator=
indexContainer & operator=(const indexContainer &)=default
pFlow::indexContainer::min
INLINE_FUNCTION_HD IndexType min() const
Definition: indexContainer.hpp:119
pFlow::indexContainer::operator()
INLINE_FUNCTION_HD IndexType operator()(selectSide< executionSpace >, int32 i) const
Definition: indexContainer.hpp:132
pFlow::indexContainer::hostView
const HostViewType & hostView() const
Definition: indexContainer.hpp:143
pFlow::indexContainer::IndexAccessor::IndexAccessor
IndexAccessor(ViewType v)
Definition: indexContainer.hpp:53
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::indexContainer::indicesHost
auto indicesHost() const
Definition: indexContainer.hpp:153
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::indexContainer< int32 >::HostViewType
typename DualViewType::t_host HostViewType
Definition: indexContainer.hpp:44
pFlow::selectSide
Definition: KokkosTypes.hpp:37
pFlow::indexContainer::indexContainer
indexContainer()
Definition: indexContainer.hpp:73
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::indexContainer::IndexAccessor
Definition: indexContainer.hpp:47
span.hpp
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::indexContainer< int32 >::DualViewType
Kokkos::DualView< int32 * > DualViewType
Definition: indexContainer.hpp:38
pFlow::indexContainer
Definition: indexContainer.hpp:34
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Definition: indexContainer.hpp:148