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 isApplicableToDomain() 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 setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold) override {
75 _cellFunctor.setAoSSortingThresholds(aosSortingThreshold);
76 }
77
81 void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold) override {
82 _cellFunctor.setSoASortingThresholds(soaSortingThreshold);
83 }
84
85 private:
86 // CellFunctor type for either Pairwise or Triwise Functors.
87 using CellFunctorType = std::conditional_t<decltype(utils::isPairwiseFunctor<Functor>())::value,
90
94 CellFunctorType _cellFunctor;
95
99 utils::DataLayoutConverter<Functor> _dataLayoutConverter;
100};
101
102template <class ParticleCell, class Functor>
104 using namespace autopas::utils::ArrayMath::literals;
105
106 // cells[0] is the owned domain and cells[1-6] are the halo cells.
107 auto &cells = *(this->_cells);
108
109 // Process interactions between 3 owned particles.
110 _cellFunctor.processCell(cells[0]);
111
112 constexpr std::array<std::array<double, 3>, 7> haloDirections{
113 {{0., 0., 0.}, {-1., 0., 0.}, {1., 0., 0.}, {0., -1., 0.}, {0., 1., 0.}, {0., 0., -1.}, {0., 0., 1.}}};
114
115 // Process pair interactions with all six halo cells.
116 for (int i = 1; i < cells.size(); i++) {
117 _cellFunctor.processCellPair(cells[0], cells[i], std::array<double, 3>(haloDirections[i]));
118 }
119
120 if constexpr (utils::isTriwiseFunctor<Functor>()) {
121 // Process cell triplet interactions with 1 owned particle and two halo particles from different cells.
122 for (int i = 1; i < cells.size(); i++) {
123 for (int j = i + 1; j < cells.size(); j++) {
124 // Sorting direction should be from owned to first halo cell.
125 _cellFunctor.processCellTriple(cells[0], cells[i], cells[j], haloDirections[i]);
126 }
127 }
128 }
129}
130
131} // namespace autopas
A cell pair traversal.
Definition: CellTraversal.h:25
std::vector< ParticleCell > * _cells
The cells to traverse.
Definition: CellTraversal.h:75
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:103
void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold) override
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: DSSequentialTraversal.h:74
bool isApplicableToDomain() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: DSSequentialTraversal.h:49
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
void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: DSSequentialTraversal.h:81
DSSequentialTraversal(Functor &functor, double cutoff, DataLayoutOption dataLayout, bool useNewton3)
Constructor for the DirectSum traversal.
Definition: DSSequentialTraversal.h:40
Interface for traversals used by the DirectSum container.
Definition: DSTraversalInterface.h:18
Functor base class.
Definition: Functor.h:41
Class for Cells of Particles.
Definition: ParticleCell.h:49
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
A cell functor.
Definition: CellFunctor3B.h:25
A cell functor.
Definition: CellFunctor.h:32
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:34
Polymorphic base for sorting-threshold storage.
Definition: SortingThresholdInfoInterface.h:18