AutoPas  3.0.0
Loading...
Searching...
No Matches
OTC01Traversal.h
Go to the documentation of this file.
1
8#pragma once
9
19
20namespace autopas {
21
28template <class Particle_T, class PairwiseFunctor>
29class OTC01Traversal : public CellTraversal<OctreeLeafNode<Particle_T>>,
30 public OTTraversalInterface<OctreeNodeWrapper<Particle_T>> {
31 public:
36
45 explicit OTC01Traversal(PairwiseFunctor *pairwiseFunctor, double cutoff, double interactionLength,
46 DataLayoutOption dataLayout, bool useNewton3)
47 : CellTraversal<ParticleCell>({2, 1, 1}),
48 OTTraversalInterface<OctreeNodeWrapper<Particle_T>>(interactionLength, dataLayout, useNewton3),
49 _cellFunctor(pairwiseFunctor, cutoff /*should use cutoff here, if not used to build verlet-lists*/, dataLayout,
50 useNewton3),
51 _dataLayoutConverter(pairwiseFunctor, dataLayout) {}
52
53 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::ot_c01; }
54
55 [[nodiscard]] bool isApplicable() const override { return not this->_useNewton3; }
56
57 void initTraversal() override {
58 // Preprocess all leaves
59 this->loadBuffers(_dataLayoutConverter, this->getOwned(), this->_ownedLeaves);
60 this->loadBuffers(_dataLayoutConverter, this->getHalo(), this->_haloLeaves);
61 }
62
63 void endTraversal() override {
64 // Postprocess all leaves
65 this->unloadBuffers(_dataLayoutConverter, this->_ownedLeaves);
66 this->unloadBuffers(_dataLayoutConverter, this->_haloLeaves);
67 }
68
73 void traverseParticles() override {
74 using namespace autopas::utils::ArrayMath::literals;
75
76 auto *haloWrapper = this->getHalo();
77
78 OctreeLogger<Particle_T>::octreeToJSON(this->getOwned()->getRaw(), this->getHalo()->getRaw(), this->_ownedLeaves,
79 this->_haloLeaves);
80
81 // Get neighboring cells for each leaf
82 // #pragma omp parallel for
83 for (int i = 0; i < this->_ownedLeaves.size(); ++i) {
85
86 // Process cell itself
87 _cellFunctor.processCell(*leaf);
88
89 // Process connection to all neighbors in this octree
90 auto uniqueNeighboringLeaves = leaf->getNeighborLeaves();
91 for (OctreeLeafNode<Particle_T> *neighborLeaf : uniqueNeighboringLeaves) {
92 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
93 }
94
95 // Process particles in halo cell that are in range
96 auto min = leaf->getBoxMin() - this->_interactionLength;
97 auto max = leaf->getBoxMax() + this->_interactionLength;
98 auto haloNeighbors = haloWrapper->getLeavesInRange(min, max);
99
100 for (OctreeLeafNode<Particle_T> *neighborLeaf : haloNeighbors) {
101 _cellFunctor.processCellPair(*leaf, *neighborLeaf);
102 }
103 }
104 }
105
109 void setSortingThreshold(size_t sortingThreshold) override { _cellFunctor.setSortingThreshold(sortingThreshold); }
110
111 private:
115 internal::CellFunctor<ParticleCell, PairwiseFunctor, /*bidirectional*/ false> _cellFunctor;
116
121};
122
123} // 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: OTC01Traversal.h:30
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: OTC01Traversal.h:73
void initTraversal() override
Initializes the traversal.
Definition: OTC01Traversal.h:57
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: OTC01Traversal.h:109
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: OTC01Traversal.h:53
void endTraversal() override
Finalizes the traversal.
Definition: OTC01Traversal.h:63
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: OTC01Traversal.h:55
OTC01Traversal(PairwiseFunctor *pairwiseFunctor, double cutoff, double interactionLength, DataLayoutOption dataLayout, bool useNewton3)
Constructor for the Octree traversal.
Definition: OTC01Traversal.h:45
OctreeLeafNode< Particle_T > ParticleCell
A shortcut to specify the type of the actual iterated cell.
Definition: OTC01Traversal.h:35
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
static void octreeToJSON(OctreeNodeInterface< Particle_T > *owned, OctreeNodeInterface< Particle_T > *halo, std::vector< OctreeLeafNode< Particle_T > * > &ownedLeaves, std::vector< OctreeLeafNode< Particle_T > * > &haloLeaves)
Log the octree to JSON files understandable by https://github.com/AutoPas/OctreeVisualization.
Definition: OctreeLogger.h:310
const std::array< double, 3 > & getBoxMax() const
Get the maximum coordinate of the enclosing box.
Definition: OctreeNodeInterface.h:370
const std::array< double, 3 > & getBoxMin() const
Get the minimum coordinate of the enclosing box.
Definition: OctreeNodeInterface.h:364
std::vector< OctreeLeafNode< Particle_T > * > getNeighborLeaves(const octree::Any direction)
This function combines all required functions when traversing down a subtree of the octree and findin...
Definition: OctreeNodeInterface.h:316
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