AutoPas  3.0.0
Loading...
Searching...
No Matches
OTC18Traversal.h
Go to the documentation of this file.
1
8#pragma once
9
18
19namespace autopas {
20
28template <class Particle_T, class PairwiseFunctor>
29class OTC18Traversal : public CellTraversal<OctreeLeafNode<Particle_T>>,
30 public OTTraversalInterface<OctreeNodeWrapper<Particle_T>> {
31 public:
36
45 explicit OTC18Traversal(PairwiseFunctor &pairwiseFunctor, double cutoff, double interactionLength,
46 DataLayoutOption dataLayout, bool useNewton3)
47 // {2, 1, 1} says that there are only two cells in the container (owned and halo), no other cell. Both are along
48 // the (imaginary) x-axis. This results in the cuboid specified by {2, 1, 1}.
49 : CellTraversal<ParticleCell>({2, 1, 1}),
50 OTTraversalInterface<OctreeNodeWrapper<Particle_T>>(interactionLength, dataLayout, useNewton3),
51 _cellFunctor(pairwiseFunctor, cutoff /*should use cutoff here, if not used to build verlet-lists*/, dataLayout,
52 useNewton3),
53 _dataLayoutConverter(pairwiseFunctor, dataLayout) {}
54
55 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::ot_c18; }
56
61 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
62
69 static void assignIDs(std::vector<OctreeLeafNode<Particle_T> *> &leaves, int startID = 0) {
70 for (int i = 0; i < leaves.size(); ++i) {
71 leaves[i]->setID(startID + i);
72 }
73 }
74
75 void initTraversal() override {
76 // Preprocess all leaves
77 this->loadBuffers(_dataLayoutConverter, this->getOwned(), this->_ownedLeaves);
78 this->loadBuffers(_dataLayoutConverter, this->getHalo(), this->_haloLeaves);
79
80 // Assign IDs to the leaves
82 assignIDs(this->_haloLeaves, this->_ownedLeaves.size());
83 }
84
85 void endTraversal() override {
86 // Postprocess all leaves
87 this->unloadBuffers(_dataLayoutConverter, this->_ownedLeaves);
88 this->unloadBuffers(_dataLayoutConverter, this->_haloLeaves);
89 }
90
95 void traverseParticles() override {
96 using namespace autopas::utils::ArrayMath::literals;
97
98 auto *haloWrapper = this->getHalo();
99
100 // Get neighboring cells for each leaf
101 for (OctreeLeafNode<Particle_T> *leaf : this->_ownedLeaves) {
102 // Process cell itself
103 _cellFunctor.processCell(*leaf);
104
105 // Process connection to all neighbors
106 auto uniqueNeighboringLeaves = leaf->getNeighborLeaves();
107 for (OctreeLeafNode<Particle_T> *neighborLeaf : uniqueNeighboringLeaves) {
108 if (leaf->getID() < neighborLeaf->getID()) {
109 // Execute the cell functor
110 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
111 }
112 }
113
114 // Process particles in halo cell that are in range
115 auto min = leaf->getBoxMin() - this->_interactionLength;
116 auto max = leaf->getBoxMax() + this->_interactionLength;
117 auto haloNeighbors = haloWrapper->getLeavesInRange(min, max);
118
119 for (OctreeLeafNode<Particle_T> *neighborLeaf : haloNeighbors) {
120 if (leaf->getID() < neighborLeaf->getID()) {
121 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
122 }
123 }
124 }
125 }
126
130 void setAoSSortingThreshold(size_t aosSortingThreshold) override {
131 _cellFunctor.setAoSSortingThreshold(aosSortingThreshold);
132 }
136 void setSoASortingThreshold(size_t soaSortingThreshold) override {
137 _cellFunctor.setSoASortingThreshold(soaSortingThreshold);
138 }
139
140 private:
144 internal::CellFunctor<ParticleCell, PairwiseFunctor, /*bidirectional*/ false> _cellFunctor;
145
150};
151} // namespace autopas
A cell pair traversal.
Definition: CellTraversal.h:23
This traversal is capable of iterating over particles stored in the Octree data structure.
Definition: OTC18Traversal.h:30
OTC18Traversal(PairwiseFunctor &pairwiseFunctor, double cutoff, double interactionLength, DataLayoutOption dataLayout, bool useNewton3)
Constructor for the Octree traversal.
Definition: OTC18Traversal.h:45
OctreeLeafNode< Particle_T > ParticleCell
A shortcut to specify the type of the actual iterated cell.
Definition: OTC18Traversal.h:35
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: OTC18Traversal.h:95
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: OTC18Traversal.h:55
void endTraversal() override
Finalizes the traversal.
Definition: OTC18Traversal.h:85
static void assignIDs(std::vector< OctreeLeafNode< Particle_T > * > &leaves, int startID=0)
Assign an integer ID to every leaf.
Definition: OTC18Traversal.h:69
bool isApplicableToDomain() const override
OT C18 is always applicable to the domain.
Definition: OTC18Traversal.h:61
void setAoSSortingThreshold(size_t aosSortingThreshold) override
Set the aos-sorting-threshold for traversals that use the CellFunctor If the sum of the number of par...
Definition: OTC18Traversal.h:130
void initTraversal() override
Initializes the traversal.
Definition: OTC18Traversal.h:75
void setSoASortingThreshold(size_t soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: OTC18Traversal.h:136
This interface exists to provide a row interface for octree to add its cells.
Definition: OTTraversalInterface.h:22
std::vector< OctreeLeafNode< ParticleType > * > _ownedLeaves
A list of all leaves in the owned octree.
Definition: OTTraversalInterface.h:103
OctreeNodeWrapper< ParticleType > * getOwned()
Get the octree cell that contains the owned octree.
Definition: OTTraversalInterface.h:85
std::vector< OctreeLeafNode< ParticleType > * > _haloLeaves
A list of all leaves in the halo octree.
Definition: OTTraversalInterface.h:108
double _interactionLength
The interaction length is used for finding neighbors.
Definition: OTTraversalInterface.h:113
void loadBuffers(utils::DataLayoutConverter< PairwiseFunctor > &dataLayoutConverter, OctreeNodeWrapper< ParticleType > *wrapper, std::vector< OctreeLeafNode< ParticleType > * > &leaves)
Gather all leaves and load the SoA/AoS buffers.
Definition: OTTraversalInterface.h:54
OctreeNodeWrapper< ParticleType > * getHalo()
Get the octree cell that contains the halo octree.
Definition: OTTraversalInterface.h:92
void unloadBuffers(utils::DataLayoutConverter< PairwiseFunctor > &dataLayoutConverter, std::vector< OctreeLeafNode< ParticleType > * > &leaves)
Unload the SoA/AoS buffers and clear the gathered leaves list.
Definition: OTTraversalInterface.h:70
An octree leaf node.
Definition: OctreeLeafNode.h:27
This class wraps the functionality provided by the octree leaves and inner nodes in a structure that ...
Definition: OctreeNodeWrapper.h:37
PairwiseFunctor class.
Definition: PairwiseFunctor.h:45
A cell functor.
Definition: CellFunctor.h:29
This converts cells to the target data Layout using the given functor.
Definition: DataLayoutConverter.h:19
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34