# PhasicFlow: src/phasicFlow/containers/indexContainer/indexContainer.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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 <vector>
#include "phasicFlowKokkos.hpp"
#include "typeInfo.hpp"
namespace pFlow
{
template<typename IndexType>
class indexContainer
{
public:
using DVType = DualViewType1D<IndexType>;
using DeviceViewType = typename DVType::t_dev;
using HostViewType = typename DVType::t_host;
using HostType = typename HostViewType::device_type;
using DeviceType = typename DeviceViewType::device_type;
template<typename ViewType>
class IndexAccessor
{
protected:
ViewType view_;
public:
IndexAccessor(ViewType v):
view_(v){}
INLINE_FUNCTION_HD
IndexType operator()(uint32 i)const
{
return view_[i];
}
uint32 size()const
{
return view_.extent(0);
}
};
protected:
IndexType min_ = 0;
IndexType max_ = 0;
uint32 size_ = 0;
DVType views_;
public:
TypeInfoTemplateNV11("indexContainer", IndexType);
indexContainer(){}
template<typename T>
indexContainer(const Range<T>& rng)
:
indexContainer
(
static_cast<IndexType>(rng.begin()),
static_cast<IndexType>(rng.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(std::vector<IndexType> &ind)
:
indexContainer(ind.data(), ind.size())
{}
indexContainer(const DeviceViewType& ind):
size_(ind.size()),
views_("indexContainer", size_)
{
copy(views_.h_view, ind);
copy(views_.d_view, ind);
min_ = pFlow::min(views_.d_view, 0, size_);
max_ = pFlow::max(views_.d_view, 0, size_);
}
indexContainer(const indexContainer&) = default;
indexContainer& operator = (const indexContainer&) = default;
indexContainer(indexContainer&&) = default;
indexContainer& operator = (indexContainer&&) = default;
~indexContainer() = default;
INLINE_FUNCTION_HD
auto size()const
{
return size_;
}
INLINE_FUNCTION_HD
bool empty()const
{
return size_==0;
}
INLINE_FUNCTION_HD
IndexType min()const
{
return min_;
}
INLINE_FUNCTION_HD
IndexType max()const
{
return max_;
}
const HostViewType& hostView()const
{
return views_.h_view;
}
const DeviceViewType& deviceView()const
{
return views_.d_view;
}
HostViewType& hostView()
{
return views_.h_view;
}
DeviceViewType& deviceView()
{
return views_.d_view;
}
auto indicesHost()const
{
return IndexAccessor<HostViewType>(views_.h_view);
}
auto indicesDevice()const
{
return IndexAccessor<DeviceViewType>(views_.d_view);
}
void modifyOnHost()
{
views_.modify_host();
}
void modifyOnDevice()
{
views_.modify_device();
}
void syncViews()
{
bool findMinMax = false;
if(views_.template need_sync<DeviceType>())
{
Kokkos::deep_copy(views_.d_view, views_.h_view);
views_.clear_sync_state();
findMinMax = true;
}
else if(views_.template need_sync<HostType>())
{
Kokkos::deep_copy(views_.h_view, views_.d_view);
views_.clear_sync_state();
findMinMax = true;
}
if(findMinMax)
{
min_ = pFlow::min(views_.d_view, 0, size_);
max_ = pFlow::max(views_.d_view, 0, size_);
}
}
void syncViews(uint32 newSize)
{
size_ = newSize;
syncViews();
}
};
using int32IndexContainer = indexContainer<int32>;
using int64IndexContainer = indexContainer<int64>;
using uint32IndexContainer = indexContainer<uint32>;
using uint64IndexContainer = indexContainer<uint64>;
}
#endif
pFlow::indexContainer::max_
IndexType max_
max value in the indices
Definition: indexContainer.hpp:87
pFlow::indexContainer::indicesDevice
auto indicesDevice() const
Return index accessor that works on Device.
Definition: indexContainer.hpp:232
pFlow::indexContainer::min_
IndexType min_
min value in indices
Definition: indexContainer.hpp:84
pFlow::indexContainer::IndexAccessor::size
uint32 size() const
Definition: indexContainer.hpp:75
pFlow::indexContainer::indexContainer
indexContainer(const DeviceViewType &ind)
Definition: indexContainer.hpp:146
pFlow::indexContainer::indexContainer
indexContainer(IndexType *data, int32 numElems)
From data and number of elements in data.
Definition: indexContainer.hpp:129
pFlow::indexContainer::indexContainer
indexContainer(const Range< T > &rng)
Construct from a Range (half open)
Definition: indexContainer.hpp:106
pFlow::indexContainer::max
INLINE_FUNCTION_HD IndexType max() const
Max value of indices.
Definition: indexContainer.hpp:196
pFlow::indexContainer::views_
DVType views_
views to hold indices on Host and Device
Definition: indexContainer.hpp:93
pFlow::copy
INLINE_FUNCTION_H void copy(const ViewType1D< dType, dProperties... > &dst, const ViewType1D< sType, sProperties... > &src)
Definition: ViewAlgorithms.hpp:234
pFlow::indexContainer::~indexContainer
~indexContainer()=default
Destructor.
pFlow::indexContainer::size_
uint32 size_
number/size of index vector
Definition: indexContainer.hpp:90
pFlow::indexContainer::DVType
DualViewType1D< IndexType > DVType
Definition: indexContainer.hpp:43
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::indexContainer::syncViews
void syncViews()
synchronize views
Definition: indexContainer.hpp:250
pFlow::indexContainer::modifyOnHost
void modifyOnHost()
Mark host is modified.
Definition: indexContainer.hpp:238
pFlow::indexContainer::DeviceViewType
typename DVType::t_dev DeviceViewType
Device type on device.
Definition: indexContainer.hpp:45
pFlow::indexContainer::indexContainer
indexContainer(IndexType begin, IndexType end)
Construct half open [begin,end)
Definition: indexContainer.hpp:116
pFlow::indexContainer::DeviceType
typename DeviceViewType::device_type DeviceType
Device memory ype.
Definition: indexContainer.hpp:54
pFlow::indexContainer::IndexAccessor::view_
ViewType view_
Definition: indexContainer.hpp:63
pFlow::DualViewType1D
Kokkos::DualView< T *, properties... > DualViewType1D
1D dual view as a vector
Definition: KokkosTypes.hpp:105
pFlow::indexContainer::HostType
typename HostViewType::device_type HostType
Host memory type.
Definition: indexContainer.hpp:51
pFlow
Definition: demGeometry.hpp:27
pFlow::indexContainer::indexContainer
indexContainer(std::vector< IndexType > &ind)
Definition: indexContainer.hpp:141
pFlow::indexContainer::deviceView
DeviceViewType & deviceView()
Return Device veiw.
Definition: indexContainer.hpp:220
pFlow::indexContainer::operator=
indexContainer & operator=(const indexContainer &)=default
Copy assignment.
pFlow::indexContainer::min
INLINE_FUNCTION_HD IndexType min() const
Min value of indices.
Definition: indexContainer.hpp:189
pFlow::indexContainer::syncViews
void syncViews(uint32 newSize)
Definition: indexContainer.hpp:273
pFlow::indexContainer::TypeInfoTemplateNV11
TypeInfoTemplateNV11("indexContainer", IndexType)
phasicFlowKokkos.hpp
pFlow::indexContainer::hostView
HostViewType & hostView()
Return Host veiw.
Definition: indexContainer.hpp:214
pFlow::indexContainer::hostView
const HostViewType & hostView() const
Return Host veiw.
Definition: indexContainer.hpp:202
pFlow::indexContainer::IndexAccessor::IndexAccessor
IndexAccessor(ViewType v)
Definition: indexContainer.hpp:66
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::indexContainer::modifyOnDevice
void modifyOnDevice()
Mark device is modified.
Definition: indexContainer.hpp:244
pFlow::indexContainer::indicesHost
auto indicesHost() const
Return index accessor that works on Host.
Definition: indexContainer.hpp:226
pFlow::indexContainer::empty
INLINE_FUNCTION_HD bool empty() const
If the container empty.
Definition: indexContainer.hpp:182
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::Range
Range for elements in an vector [start,end)
Definition: Range.hpp:38
typeInfo.hpp
pFlow::indexContainer::size
INLINE_FUNCTION_HD auto size() const
Size.
Definition: indexContainer.hpp:175
pFlow::indexContainer::IndexAccessor::operator()
INLINE_FUNCTION_HD IndexType operator()(uint32 i) const
Definition: indexContainer.hpp:70
pFlow::indexContainer::indexContainer
indexContainer()
Default.
Definition: indexContainer.hpp:102
pFlow::fillSequence
void fillSequence(internalField< T, MemorySpace > &iField, const T &startVal)
Definition: internalFieldAlgorithms.hpp:198
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::indexContainer::IndexAccessor
Helper class for accessing index on host or device.
Definition: indexContainer.hpp:60
pFlow::indexContainer::HostViewType
typename DVType::t_host HostViewType
Host type on device.
Definition: indexContainer.hpp:48
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Return Device view.
Definition: indexContainer.hpp:208