33template <
class Particle_T,
class Functor_T>
35 using SoAArraysType = Particle_T::SoAArraysType;
48 : _source(source), _sortedSoa(cachedSoa), _projIdx(cachedProjIdx) {
49 const size_t n = source.
size();
51 _sortedSoa.resizeArrays(0);
57 const auto *xPtr = source.template begin<Particle_T::AttributeNames::posX>();
58 const auto *yPtr = source.template begin<Particle_T::AttributeNames::posY>();
59 const auto *zPtr = source.template begin<Particle_T::AttributeNames::posZ>();
60 for (
size_t i = 0; i < n; ++i) {
61 _projIdx[i] = {xPtr[i] * sortingDirection[0] + yPtr[i] * sortingDirection[1] + zPtr[i] * sortingDirection[2], i};
63 std::sort(_projIdx.begin(), _projIdx.end(), [](
const auto &a,
const auto &b) { return a.first < b.first; });
66 _sortedSoa.resizeArrays(n);
69 packNeededImpl(std::make_index_sequence<Functor_T::getNeededAttr().size()>{}, n);
72 zeroComputedImpl(std::make_index_sequence<Functor_T::getComputedAttr().size()>{}, n);
86 scatterBackImpl(std::make_index_sequence<Functor_T::getComputedAttr().size()>{}, _projIdx.size());
95 template <
size_t AttrIdx>
96 void packAttr(
size_t n) {
97 constexpr size_t attr =
static_cast<size_t>(Functor_T::getNeededAttr()[AttrIdx]);
98 auto *dst = _sortedSoa.template begin<attr>();
99 const auto *src = _source.template begin<attr>();
100 for (
size_t i = 0; i < n; ++i) {
101 dst[i] = src[_projIdx[i].second];
110 template <
size_t... AttrIdxs>
111 void packNeededImpl(std::index_sequence<AttrIdxs...>,
size_t n) {
112 (packAttr<AttrIdxs>(n), ...);
120 template <
size_t AttrIdx>
121 void zeroAttr(
size_t n) {
122 constexpr size_t attr =
static_cast<size_t>(Functor_T::getComputedAttr()[AttrIdx]);
123 auto *ptr = _sortedSoa.template begin<attr>();
124 std::fill(ptr, ptr + n, 0);
132 template <
size_t... AttrIdxs>
133 void zeroComputedImpl(std::index_sequence<AttrIdxs...>,
size_t n) {
134 (zeroAttr<AttrIdxs>(n), ...);
143 template <
size_t AttrIdx>
144 void scatterAttr(
size_t n) {
145 constexpr size_t attr =
static_cast<size_t>(Functor_T::getComputedAttr()[AttrIdx]);
146 auto *orig = _source.template begin<attr>();
147 const auto *sorted = _sortedSoa.template begin<attr>();
148 for (
size_t i = 0; i < n; ++i) {
149 orig[_projIdx[i].second] += sorted[i];
158 template <
size_t... AttrIdxs>
159 void scatterBackImpl(std::index_sequence<AttrIdxs...>,
size_t n) {
160 (scatterAttr<AttrIdxs>(n), ...);
163 SoAView<SoAArraysType> _source;
164 SoA<SoAArraysType> &_sortedSoa;
168 std::vector<std::pair<double, size_t>> &_projIdx;
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:25
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:85
Structur of the array class.
Definition: SoA.h:28
A sorted view on a SoA buffer.
Definition: SortedSoAView.h:34
SoAView< SoAArraysType > getView()
Returns a SoAView into the sorted, contiguous internal buffer.
Definition: SortedSoAView.h:79
SortedSoAView(SoAView< SoAArraysType > source, const std::array< double, 3 > &sortingDirection, SoA< SoAArraysType > &cachedSoa, std::vector< std::pair< double, size_t > > &cachedProjIdx)
Projects particles onto sortingDirection, sorts by projection, and packs needed attributes into an in...
Definition: SortedSoAView.h:46
void scatterBack()
Scatters computed attribute contributions accumulated in the sorted SoA back to the source via +=.
Definition: SortedSoAView.h:85
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34