# PhasicFlow: src/phasicFlow/structuredData/boundaries/boundaryBase/scatteredFieldAccess.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.

scatteredFieldAccess.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 __scatteredFieldAccess_hpp__
#define __scatteredFieldAccess_hpp__
#include "phasicFlowKokkos.hpp"
namespace pFlow
{
template<typename T, typename MemorySpace=void>
class scatteredFieldAccess
{
public:
using viewType = ViewType1D<T, MemorySpace>;
using device_type = typename viewType::device_type;
using memory_space = typename viewType::memory_space;
using execution_space = typename viewType::execution_space;
private:
uint32 size_ = 0;
ViewType1D<uint32, memory_space> indices_;
viewType fieldVals_;
public:
scatteredFieldAccess():
indices_(),
fieldVals_()
{}
scatteredFieldAccess(
uint32 sz,
const ViewType1D<uint32, memory_space>& ind,
const ViewType1D<T, memory_space>& fVals)
:
size_(sz),
indices_(ind),
fieldVals_(fVals)
{}
scatteredFieldAccess(const scatteredFieldAccess&) = default;
scatteredFieldAccess(scatteredFieldAccess&&) = default;
scatteredFieldAccess& operator=(const scatteredFieldAccess&) = default;
scatteredFieldAccess& operator=(scatteredFieldAccess&&) = default;
~scatteredFieldAccess() = default;
// - Methods
INLINE_FUNCTION_HD
T& operator()(uint32 i)
{
return fieldVals_(indices_(i));
}
INLINE_FUNCTION_HD
const T& operator()(uint32 i)const
{
return fieldVals_(indices_(i));
}
INLINE_FUNCTION_HD
T& operator[](uint32 i)
{
return fieldVals_[indices_[i]];
}
INLINE_FUNCTION_HD
const T& operator[](uint32 i)const
{
return fieldVals_[indices_[i]];
}
INLINE_FUNCTION_HD
const viewType& field()const
{
return fieldVals_;
}
INLINE_FUNCTION_HD
viewType& field()
{
return fieldVals_;
}
auto& indices()
{
return indices_;
}
const auto& indices()const
{
return indices_;
}
INLINE_FUNCTION_HD
uint32 index(uint32 i)const
{
return indices_[i];
}
INLINE_FUNCTION_HD
uint32 size()const
{
return size_;
}
INLINE_FUNCTION_HD
bool empty()const
{
return size_ == 0;
}
T getFirstCopy()const
{
T val;
uint32 n = indices_(0);
getNth(val, fieldVals_, n);
return val;
}
T getLastCopy()const
{
T val;
if(empty())return val;
uint32 n = indices_(size()-1);
getNth(val, fieldVals_, n);
return val;
}
};
template<typename T>
using deviceScatteredFieldAccess =
scatteredFieldAccess<T, typename DefaultExecutionSpace::memory_space>;
template<typename T>
using hostScatteredFieldAccess =
scatteredFieldAccess<T,HostSpace>;
} // pFlow
#endif //__scatteredFieldAccess_hpp__
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