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
57 [[nodiscard]] bool isApplicable() const override { return this->_useNewton3; }
58
65 static void assignIDs(std::vector<OctreeLeafNode<Particle_T> *> &leaves, int startID = 0) {
66 for (int i = 0; i < leaves.size(); ++i) {
67 leaves[i]->setID(startID + i);
68 }
69 }
70
71 void initTraversal() override {
72 // Preprocess all leaves
73 this->loadBuffers(_dataLayoutConverter, this->getOwned(), this->_ownedLeaves);
74 this->loadBuffers(_dataLayoutConverter, this->getHalo(), this->_haloLeaves);
75
76 // Assign IDs to the leaves
78 assignIDs(this->_haloLeaves, this->_ownedLeaves.size());
79 }
80
81 void endTraversal() override {
82 // Postprocess all leaves
83 this->unloadBuffers(_dataLayoutConverter, this->_ownedLeaves);
84 this->unloadBuffers(_dataLayoutConverter, this->_haloLeaves);
85 }
86
91 void traverseParticles() override {
92 using namespace autopas::utils::ArrayMath::literals;
93
94 auto *haloWrapper = this->getHalo();
95
96 // Get neighboring cells for each leaf
97 for (OctreeLeafNode<Particle_T> *leaf : this->_ownedLeaves) {
98 // Process cell itself
99 _cellFunctor.processCell(*leaf);
100
101 // Process connection to all neighbors
102 auto uniqueNeighboringLeaves = leaf->getNeighborLeaves();
103 for (OctreeLeafNode<Particle_T> *neighborLeaf : uniqueNeighboringLeaves) {
104 if (leaf->getID() < neighborLeaf->getID()) {
105 // Execute the cell functor
106 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
107 }
108 }
109
110 // Process particles in halo cell that are in range
111 auto min = leaf->getBoxMin() - this->_interactionLength;
112 auto max = leaf->getBoxMax() + this->_interactionLength;
113 auto haloNeighbors = haloWrapper->getLeavesInRange(min, max);
114
115 for (OctreeLeafNode<Particle_T> *neighborLeaf : haloNeighbors) {
116 if (leaf->getID() < neighborLeaf->getID()) {
117 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
118 }
119 }
120 }
121 }
122
126 void setSortingThreshold(size_t sortingThreshold) override { _cellFunctor.setSortingThreshold(sortingThreshold); }
127
128 private:
132 internal::CellFunctor<ParticleCell, PairwiseFunctor, /*bidirectional*/ false> _cellFunctor;
133
138};
139} // 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
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:91
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: OTC18Traversal.h:55
OTC18Traversal(PairwiseFunctor *pairwiseFunctor, double cutoff, double interactionLength, DataLayoutOption dataLayout, bool useNewton3)
Constructor for the Octree traversal.
Definition: OTC18Traversal.h:45
void endTraversal() override
Finalizes the traversal.
Definition: OTC18Traversal.h:81
static void assignIDs(std::vector< OctreeLeafNode< Particle_T > * > &leaves, int startID=0)
Assign an integer ID to every leaf.
Definition: OTC18Traversal.h:65
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: OTC18Traversal.h:126
void initTraversal() override
Initializes the traversal.
Definition: OTC18Traversal.h:71
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: OTC18Traversal.h:57
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:31
bool _useNewton3
If this traversal makes use of newton3.
Definition: TraversalInterface.h:80
A cell functor.
Definition: CellFunctor.h:25
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:32