AutoPas  3.0.0
Loading...
Searching...
No Matches
DSSequentialTraversal.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <vector>
10
19
20namespace autopas {
21
28template <class ParticleCell, class Functor>
29class DSSequentialTraversal : public CellTraversal<ParticleCell>,
30 public TraversalInterface,
32 public:
40 explicit DSSequentialTraversal(Functor *functor, double cutoff, DataLayoutOption dataLayout, bool useNewton3)
41 : CellTraversal<ParticleCell>({2, 1, 1}),
42 TraversalInterface(dataLayout, useNewton3),
43 _cellFunctor(functor, cutoff /*should use cutoff here, if not used to build verlet-lists*/, dataLayout,
44 useNewton3),
45 _dataLayoutConverter(functor, dataLayout) {}
46
47 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::ds_sequential; }
48
49 [[nodiscard]] bool isApplicable() const override { return true; }
50
51 void initTraversal() override {
52 auto &cells = *(this->_cells);
53 for (auto &cell : cells) {
54 _dataLayoutConverter.loadDataLayout(cell);
55 }
56 }
57
58 void endTraversal() override {
59 auto &cells = *(this->_cells);
60 for (auto &cell : cells) {
61 _dataLayoutConverter.storeDataLayout(cell);
62 }
63 }
64
69 void traverseParticles() override;
70
74 void setSortingThreshold(size_t sortingThreshold) override { _cellFunctor.setSortingThreshold(sortingThreshold); }
75
76 private:
77 // CellFunctor type for either Pairwise or Triwise Functors.
78 using CellFunctorType = std::conditional_t<decltype(utils::isPairwiseFunctor<Functor>())::value,
81
85 CellFunctorType _cellFunctor;
86
90 utils::DataLayoutConverter<Functor> _dataLayoutConverter;
91};
92
93template <class ParticleCell, class Functor>
95 using namespace autopas::utils::ArrayMath::literals;
96
97 // cells[0] is the owned domain and cells[1-6] are the halo cells.
98 auto &cells = *(this->_cells);
99
100 // Process interactions between 3 owned particles.
101 _cellFunctor.processCell(cells[0]);
102
103 constexpr std::array<std::array<double, 3>, 7> haloDirections{
104 {{0., 0., 0.}, {-1., 0., 0.}, {1., 0., 0.}, {0., -1., 0.}, {0., 1., 0.}, {0., 0., -1.}, {0., 0., 1.}}};
105
106 // Process pair interactions with all six halo cells.
107 for (int i = 1; i < cells.size(); i++) {
108 _cellFunctor.processCellPair(cells[0], cells[i], std::array<double, 3>(haloDirections[i]));
109 }
110
111 if constexpr (utils::isTriwiseFunctor<Functor>()) {
112 // Process cell triplet interactions with 1 owned particle and two halo particles from different cells.
113 for (int i = 1; i < cells.size(); i++) {
114 for (int j = i + 1; j < cells.size(); j++) {
115 // Sorting direction should be from owned to first halo cell.
116 _cellFunctor.processCellTriple(cells[0], cells[i], cells[j], haloDirections[i]);
117 }
118 }
119 }
120}
121
122} // namespace autopas
A cell pair traversal.
Definition: CellTraversal.h:23
std::vector< ParticleCell > * _cells
The cells to traverse.
Definition: CellTraversal.h:60
This sum defines the traversal typically used by the DirectSum container.
Definition: DSSequentialTraversal.h:31
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: DSSequentialTraversal.h:94
void setSortingThreshold(size_t sortingThreshold) override
Set the sorting-threshold for traversals that use the CellFunctor If the sum of the number of particl...
Definition: DSSequentialTraversal.h:74
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: DSSequentialTraversal.h:49
DSSequentialTraversal(Functor *functor, double cutoff, DataLayoutOption dataLayout, bool useNewton3)
Constructor for the DirectSum traversal.
Definition: DSSequentialTraversal.h:40
void endTraversal() override
Finalizes the traversal.
Definition: DSSequentialTraversal.h:58
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: DSSequentialTraversal.h:47
void initTraversal() override
Initializes the traversal.
Definition: DSSequentialTraversal.h:51
Interface for traversals used by the DirectSum container.
Definition: DSTraversalInterface.h:18
Functor base class.
Definition: Functor.h:40
Class for Cells of Particles.
Definition: ParticleCell.h:51
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
A cell functor.
Definition: CellFunctor3B.h:24
A cell functor.
Definition: CellFunctor.h:25
This converts cells to the target data Layout using the given functor.
Definition: DataLayoutConverter.h:19
decltype(isTriwiseFunctorImpl(std::declval< FunctorT >())) isTriwiseFunctor
Check whether a Functor Type is inheriting from TriwiseFunctor.
Definition: checkFunctorType.h:56
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32