# PhasicFlow: src/phasicFlow/containers/indexContainer/indexContainer.hpp Source File

indexContainer.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __indexContainer_hpp__
#define __indexContainer_hpp__
#include "span.hpp"
#include "KokkosTypes.hpp"
#include "KokkosUtilities.hpp"
#include "ViewAlgorithms.hpp"
namespace pFlow
{
template<typename IndexType>
class indexContainer
{
public:
using DualViewType = Kokkos::DualView<IndexType*>;
// - viewType of data on device
using DeviceViewType = typename DualViewType::t_dev;
// - viewType of data on host
using HostViewType = typename DualViewType::t_host;
template<typename ViewType>
class IndexAccessor
{
protected:
ViewType view_;
public:
IndexAccessor(ViewType v):
view_(v){}
INLINE_FUNCTION_HD
IndexType operator()(int32 i)const
{
return view_[i];
}
};
protected:
int32 min_ = 0;
int32 max_ = 0;
size_t size_ = 0;
DualViewType views_;
public:
indexContainer(){}
// half open [begin,end)
indexContainer(IndexType begin, IndexType end)
:
min_(begin),
max_(end-1),
size_(end-begin),
views_("indexContainer", size_)
{
pFlow::fillSequence(views_.h_view, 0, size_, min_);
copy(views_.d_view, views_.h_view);
}
indexContainer(IndexType* data, int32 numElems)
:
size_(numElems),
views_("indexContainer", numElems)
{
HostViewType hData(data, numElems);
copy(views_.h_view, hData);
copy(views_.d_view, views_.h_view);
min_ = pFlow::min(views_.d_view, 0, numElems);
max_ = pFlow::max(views_.d_view, 0, numElems);
}
indexContainer(const indexContainer&) = default;
indexContainer& operator = (const indexContainer&) = default;
~indexContainer() = default;
INLINE_FUNCTION_HD
size_t size()const
{
return size_;
}
INLINE_FUNCTION_HD
size_t empty()const
{
return size_==0;
}
INLINE_FUNCTION_HD
IndexType min()const
{
return min_;
}
INLINE_FUNCTION_HD
IndexType max()const
{
return max_;
}
template<typename executionSpace>
INLINE_FUNCTION_HD
IndexType operator()(selectSide<executionSpace>,int32 i)const
{
if constexpr (isHostAccessible<executionSpace>())
{
return views_.h_view(i);
}else
{
return views_.d_view(i);
}
}
const HostViewType& hostView()const
{
return views_.h_view;
}
const DeviceViewType& deviceView()const
{
return views_.d_view;
}
auto indicesHost()const
{
return IndexAccessor<HostViewType>(views_.h_view);
}
auto indicesDevice()const
{
return IndexAccessor<DeviceViewType>(views_.d_veiw);
}
};
using int32IndexContainer = indexContainer<int32>;
using int64IndexContainer = indexContainer<int64>;
}
#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