AutoPas  3.0.0
Loading...
Searching...
No Matches
VerletLists.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "VerletListHelpers.h"
19
20namespace autopas {
21
31template <class Particle_T>
32class VerletLists : public VerletListsLinkedBase<Particle_T> {
34
35 public:
48 };
49
61 VerletLists(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
62 const double skin, const unsigned int rebuildFrequency,
63 const BuildVerletListType buildVerletListType = BuildVerletListType::VerletSoA,
64 const double cellSizeFactor = 1.0)
65 : VerletListsLinkedBase<Particle_T>(boxMin, boxMax, cutoff, skin, rebuildFrequency,
66 compatibleTraversals::allVLCompatibleTraversals(), cellSizeFactor),
67 _buildVerletListType(buildVerletListType) {}
68
72 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::verletLists; }
73
74 void computeInteractions(TraversalInterface *traversal) override {
75 // Check if traversal is allowed for this container and give it the data it needs.
76 auto *verletTraversalInterface = dynamic_cast<VLTraversalInterface<LinkedParticleCell> *>(traversal);
77 if (verletTraversalInterface) {
78 verletTraversalInterface->setCellsAndNeighborLists(this->_linkedCells.getCells(), _aosNeighborLists,
79 _soaNeighborLists);
80 } else {
82 "trying to use a traversal of wrong type in VerletLists::computeInteractions");
83 }
84
85 traversal->initTraversal();
86 traversal->traverseParticles();
87 traversal->endTraversal();
88 }
89
95
101 void rebuildNeighborLists(TraversalInterface *traversal) override {
102 this->_verletBuiltNewton3 = traversal->getUseNewton3();
103 this->updateVerletListsAoS(traversal->getUseNewton3());
104 // the neighbor list is now valid
105 this->_neighborListIsValid.store(true, std::memory_order_relaxed);
106
107 if (not _soaListIsValid and traversal->getDataLayout() == DataLayoutOption::soa) {
108 // only do this if we need it, i.e., if we are using soa!
110 }
111 }
112
113 protected:
118 virtual void updateVerletListsAoS(bool useNewton3) {
121 this->getCutoff() + this->getVerletSkin());
122
124 DataLayoutOption dataLayout;
125 if (_buildVerletListType == BuildVerletListType::VerletAoS) {
126 dataLayout = DataLayoutOption::aos;
127 } else if (_buildVerletListType == BuildVerletListType::VerletSoA) {
128 dataLayout = DataLayoutOption::soa;
129 } else {
130 utils::ExceptionHandler::exception("VerletLists::updateVerletListsAoS(): unsupported BuildVerletListType: {}",
131 _buildVerletListType);
132 }
133 auto traversal =
135 this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(), &f, this->getInteractionLength(),
136 this->_linkedCells.getCellBlock().getCellLength(), dataLayout, useNewton3);
137 this->_linkedCells.computeInteractions(&traversal);
138
139 _soaListIsValid = false;
140 }
141
148 size_t numParticles = 0;
149 _aosNeighborLists.clear();
150 // DON'T simply parallelize this loop!!! this needs modifications if you want to parallelize it!
151 // We have to iterate also over dummy particles here to ensure a correct size of the arrays.
152 for (auto iter = this->begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++numParticles) {
153 // create the verlet list entries for all particles
154 _aosNeighborLists[&(*iter)];
155 }
156
157 return numParticles;
158 }
159
164 // resize the list to the size of the aos neighborlist
165 _soaNeighborLists.resize(_aosNeighborLists.size());
166 // clear the aos 2 soa map
167 _particlePtr2indexMap.clear();
168
169 _particlePtr2indexMap.reserve(_aosNeighborLists.size());
170 size_t index = 0;
171
172 // Here we have to iterate over all particles, as particles might be later on marked for deletion, and we cannot
173 // differentiate them from particles already marked for deletion.
174 for (auto iter = this->begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++index) {
175 // set the map
176 _particlePtr2indexMap[&(*iter)] = index;
177 }
178 size_t accumulatedListSize = 0;
179 for (const auto &[particlePtr, neighborPtrVector] : _aosNeighborLists) {
180 accumulatedListSize += neighborPtrVector.size();
181 size_t i_id = _particlePtr2indexMap[particlePtr];
182 // each soa neighbor list should be of the same size as for aos
183 _soaNeighborLists[i_id].resize(neighborPtrVector.size());
184 size_t j = 0;
185 for (auto &neighborPtr : neighborPtrVector) {
186 _soaNeighborLists[i_id][j] = _particlePtr2indexMap[neighborPtr];
187 j++;
188 }
189 }
190
191 AutoPasLog(DEBUG,
192 "VerletLists::generateSoAListFromAoSVerletLists: average verlet list "
193 "size is {}",
194 static_cast<double>(accumulatedListSize) / _aosNeighborLists.size());
195 _soaListIsValid = true;
196 }
197
198 private:
203
208 std::unordered_map<const Particle_T *, size_t> _particlePtr2indexMap;
209
214 std::vector<std::vector<size_t, autopas::AlignedAllocator<size_t>>> _soaNeighborLists;
215
219 bool _soaListIsValid{false};
220
224 BuildVerletListType _buildVerletListType;
225};
226
227} // namespace autopas
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
This class provides the lc_c08 traversal.
Definition: LCC08Traversal.h:28
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual void endTraversal()=0
Finalizes the traversal.
virtual void traverseParticles()=0
Traverse the particles by pairs, triplets etc.
virtual void initTraversal()=0
Initializes the traversal.
DataLayoutOption getDataLayout() const
Return the data layout option.
Definition: TraversalInterface.h:69
bool getUseNewton3() const
Return whether the traversal uses newton 3.
Definition: TraversalInterface.h:63
This class provides the Traversal Interface for the verlet lists container.
Definition: VLTraversalInterface.h:22
virtual void setCellsAndNeighborLists(std::vector< LinkedParticleCell > &cells, typename VerletListHelpers< typename LinkedParticleCell::ParticleType >::NeighborListAoSType &aosNeighborLists, std::vector< std::vector< size_t, autopas::AlignedAllocator< size_t > > > &soaNeighborLists)
Sets the information the traversal needs for the iteration.
Definition: VLTraversalInterface.h:35
This functor can generate verlet lists using the typical pairwise traversal.
Definition: VerletListHelpers.h:31
std::unordered_map< Particle_T *, std::vector< Particle_T * > > NeighborListAoSType
Neighbor list AoS style.
Definition: VerletListHelpers.h:26
Base class for Verlet lists which use an underlying linked cells container.
Definition: VerletListsLinkedBase.h:26
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, true, false >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: VerletListsLinkedBase.h:205
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:329
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:314
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:319
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:326
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:323
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:304
Verlet Lists container.
Definition: VerletLists.h:32
VerletLists(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const unsigned int rebuildFrequency, const BuildVerletListType buildVerletListType=BuildVerletListType::VerletSoA, const double cellSizeFactor=1.0)
Constructor of the VerletLists class.
Definition: VerletLists.h:61
BuildVerletListType
Enum that specifies how the verlet lists should be build.
Definition: VerletLists.h:39
@ VerletSoA
Build it using AoS.
Definition: VerletLists.h:47
@ VerletAoS
Build it using AoS.
Definition: VerletLists.h:43
virtual void updateVerletListsAoS(bool useNewton3)
Update the verlet lists for AoS usage.
Definition: VerletLists.h:118
size_t generateAoSNeighborLists()
Clears and then generates the AoS neighbor lists.
Definition: VerletLists.h:147
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: VerletLists.h:72
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the verlet lists, marks them valid and resets the internal counter.
Definition: VerletLists.h:101
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: VerletLists.h:74
void generateSoAListFromAoSVerletLists()
Fills SoA neighbor list with particle indices.
Definition: VerletLists.h:163
VerletListHelpers< Particle_T >::NeighborListAoSType & getVerletListsAoS()
get the actual neighbor list
Definition: VerletLists.h:94
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32