AutoPas  3.0.0
Loading...
Searching...
No Matches
VerletLists.h
Go to the documentation of this file.
1
7#pragma once
8
19
20namespace autopas {
21
31template <class Particle_T>
32class VerletLists : public VerletListsLinkedBase<Particle_T> {
36 using ParticleType = Particle_T;
41
42 public:
55 };
56
67 VerletLists(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
68 const double skin, const BuildVerletListType buildVerletListType = BuildVerletListType::VerletSoA,
69 const double cellSizeFactor = 1.0)
70 : VerletListsLinkedBase<Particle_T>(boxMin, boxMax, cutoff, skin, cellSizeFactor),
71 _buildVerletListType(buildVerletListType) {}
72
76 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::verletLists; }
77
78 void computeInteractions(TraversalInterface *traversal) override {
79 // Check if traversal is allowed for this container and give it the data it needs.
80 auto *verletTraversalInterface = dynamic_cast<VLTraversalInterface<ParticleCellType> *>(traversal);
81 if (verletTraversalInterface) {
82 verletTraversalInterface->setCellsAndNeighborLists(this->_linkedCells.getCells(), _aosNeighborLists,
83 _soaNeighborLists);
84 } else {
85 utils::ExceptionHandler::exception("trying to use a traversal of wrong type in VerletLists::computeInteractions");
86 }
87
88 traversal->initTraversal();
89 traversal->traverseParticles();
90 traversal->endTraversal();
91 }
92
98 return _aosNeighborLists;
99 }
100
106 void rebuildNeighborLists(TraversalInterface *traversal) override {
107 this->_verletBuiltNewton3 = traversal->getUseNewton3();
108 this->updateVerletListsAoS(traversal->getUseNewton3());
109 // the neighbor list is now valid
110 this->_neighborListIsValid.store(true, std::memory_order_relaxed);
111
112 if (not _soaListIsValid and traversal->getDataLayout() == DataLayoutOption::soa) {
113 // only do this if we need it, i.e., if we are using soa!
115 }
116 }
117
118 protected:
123 virtual void updateVerletListsAoS(bool useNewton3) {
126 useNewton3);
127
129 DataLayoutOption dataLayout;
130 if (_buildVerletListType == BuildVerletListType::VerletAoS) {
131 dataLayout = DataLayoutOption::aos;
132 } else if (_buildVerletListType == BuildVerletListType::VerletSoA) {
133 dataLayout = DataLayoutOption::soa;
134 } else {
135 utils::ExceptionHandler::exception("VerletLists::updateVerletListsAoS(): unsupported BuildVerletListType: {}",
136 static_cast<int>(_buildVerletListType));
137 }
139 this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(), f, this->getInteractionLength(),
140 this->_linkedCells.getCellBlock().getCellLength(), dataLayout, useNewton3);
141 this->_linkedCells.computeInteractions(&traversal);
142
143 _soaListIsValid = false;
144 }
145
152 size_t numParticles = 0;
153 _aosNeighborLists.clear();
154 // DON'T simply parallelize this loop!!! this needs modifications if you want to parallelize it!
155 // We have to iterate also over dummy particles, as the SoA list from AoS list conversion, requires a list structure
156 // matching the SoA structure, which includes dummies. Because of this, we do not use the
157 // InteractionListGeneratorFunctor::initializeNeighborList function.
158 for (auto iter = this->begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++numParticles) {
159 // create the verlet list entries for all particles
160 _aosNeighborLists[&(*iter)];
161 }
162
163 return numParticles;
164 }
165
170 // resize the list to the size of the aos neighborlist
171 _soaNeighborLists.resize(_aosNeighborLists.size());
172 // clear the aos 2 soa map
173 _particlePtr2indexMap.clear();
174
175 _particlePtr2indexMap.reserve(_aosNeighborLists.size());
176 size_t index = 0;
177
178 // Here we have to iterate over all particles, as particles might be later on marked for deletion, and we cannot
179 // differentiate them from particles already marked for deletion.
180 for (auto iter = this->begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++index) {
181 // set the map
182 _particlePtr2indexMap[&(*iter)] = index;
183 }
184 size_t accumulatedListSize = 0;
185 for (const auto &[particlePtr, neighborPtrVector] : _aosNeighborLists) {
186 accumulatedListSize += neighborPtrVector.size();
187 size_t i_id = _particlePtr2indexMap[particlePtr];
188 // each soa neighbor list should be of the same size as for aos
189 _soaNeighborLists[i_id].resize(neighborPtrVector.size());
190 size_t j = 0;
191 for (auto &neighborPtr : neighborPtrVector) {
192 _soaNeighborLists[i_id][j] = _particlePtr2indexMap[neighborPtr];
193 j++;
194 }
195 }
196
197 AutoPasLog(DEBUG,
198 "VerletLists::generateSoAListFromAoSVerletLists: average verlet list "
199 "size is {}",
200 static_cast<double>(accumulatedListSize) / _aosNeighborLists.size());
201 _soaListIsValid = true;
202 }
203
204 private:
209
214 std::unordered_map<const Particle_T *, size_t> _particlePtr2indexMap;
215
220 std::vector<std::vector<size_t, AlignedAllocator<size_t>>> _soaNeighborLists;
221
225 bool _soaListIsValid{false};
226
230 BuildVerletListType _buildVerletListType;
231};
232
233} // 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 functor generates lists of particles within interactionLength of each other: can be used interna...
Definition: InteractionListGeneratorFunctor.h:30
std::unordered_map< Particle_T *, std::vector< Particle_T * > > NeighborListAoSType
Neighbor list AoS style.
Definition: InteractionListGeneratorFunctor.h:40
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:71
bool getUseNewton3() const
Return whether the traversal uses newton 3.
Definition: TraversalInterface.h:65
This class provides the Traversal Interface for the verlet lists container.
Definition: VLTraversalInterface.h:22
virtual void setCellsAndNeighborLists(std::vector< LinkedParticleCell > &cells, InteractionListGeneratorFunctor< typename LinkedParticleCell::ParticleType, true >::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
Base class for Verlet lists which use an underlying linked cells container.
Definition: VerletListsLinkedBase.h:25
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, true, false >::ParticleVecType > additionalVectors=std::nullopt) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: VerletListsLinkedBase.h:200
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:326
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:311
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:316
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:323
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:320
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:301
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 BuildVerletListType buildVerletListType=BuildVerletListType::VerletSoA, const double cellSizeFactor=1.0)
Constructor of the VerletLists class.
Definition: VerletLists.h:67
BuildVerletListType
Enum that specifies how the verlet lists should be build.
Definition: VerletLists.h:46
@ VerletSoA
Build it using AoS.
Definition: VerletLists.h:54
@ VerletAoS
Build it using AoS.
Definition: VerletLists.h:50
virtual void updateVerletListsAoS(bool useNewton3)
Update the verlet lists for AoS usage.
Definition: VerletLists.h:123
size_t generateAoSNeighborLists()
Clears and then generates the AoS neighbor lists.
Definition: VerletLists.h:151
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: VerletLists.h:76
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the verlet lists, marks them valid and resets the internal counter.
Definition: VerletLists.h:106
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: VerletLists.h:78
InteractionListGeneratorFunctor< Particle_T, true >::NeighborListAoSType & getVerletListsAoS()
get the actual neighbor list
Definition: VerletLists.h:97
void generateSoAListFromAoSVerletLists()
Fills SoA neighbor list with particle indices.
Definition: VerletLists.h:169
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34