30template <
class Particle_T>
35 using ParticleType = Particle_T;
66 VerletLists(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax,
const double cutoff,
68 const double cellSizeFactor = 1.0)
70 _buildVerletListType(buildVerletListType) {}
75 [[nodiscard]] ContainerOption
getContainerType()
const override {
return ContainerOption::verletLists; }
80 if (verletTraversalInterface) {
104 const std::unordered_map<const Particle_T *, size_t> &
getParticleIndex()
const {
return _particleToIndex; }
126 size_t buildParticleIndex() {
127 _particleToIndex.clear();
129 _indexToParticle.clear();
132 for (
auto iter = this->
begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++idx) {
133 _particleToIndex[&(*iter)] = idx;
134 _indexToParticle.push_back(&*iter);
147 virtual void updateNeighborLists(
bool useNewton3) {
148 const size_t N = buildParticleIndex();
151 DataLayoutOption dataLayout;
153 dataLayout = DataLayoutOption::aos;
155 dataLayout = DataLayoutOption::soa;
158 static_cast<int>(_buildVerletListType));
162 updateNeighborListsSingleThread(N, interactionLength, dataLayout, useNewton3);
164 updateNeighborListsMultiThread(N, interactionLength, dataLayout, useNewton3);
172 void updateNeighborListsSingleThread(
size_t N,
double interactionLength, DataLayoutOption dataLayout,
174 std::vector<std::vector<size_t>> tempLists(N);
176 typename VerletListHelpers<Particle_T>::CRSNeighborListPolicy policy(tempLists, _particleToIndex);
178 InteractionListGeneratorFunctor<Particle_T, typename VerletListHelpers<Particle_T>::CRSNeighborListPolicy> f(
179 policy, interactionLength, useNewton3);
180 auto traversal = LCC08Traversal<
182 InteractionListGeneratorFunctor<Particle_T, typename VerletListHelpers<Particle_T>::CRSNeighborListPolicy>>(
184 this->
_linkedCells.getCellBlock().getCellLength(), dataLayout, useNewton3);
188 _neighborList.offsets.resize(N + 1);
189 _neighborList.offsets[0] = 0;
190 for (
size_t i = 0; i < N; ++i) {
191 _neighborList.offsets[i + 1] = _neighborList.offsets[i] + tempLists[i].size();
193 const size_t totalNeighbors = _neighborList.offsets[N];
194 _neighborList.indices.resize(totalNeighbors);
195 for (
size_t i = 0; i < N; ++i) {
196 std::copy(tempLists[i].
begin(), tempLists[i].
end(),
197 _neighborList.indices.begin() +
static_cast<std::ptrdiff_t
>(_neighborList.offsets[i]));
200 AutoPasLog(DEBUG,
"VerletLists::updateNeighborLists (1T): {} particles, {} neighbors, avg {:.2f}", N,
201 totalNeighbors, N > 0 ?
static_cast<double>(totalNeighbors) /
static_cast<double>(N) : 0.0);
220 void updateNeighborListsMultiThread(
size_t N,
double interactionLength, DataLayoutOption dataLayout,
222 using PaddedAtomic = VerletListHelpers<Particle_T>::VerletListCounterFunctor::PaddedAtomic;
225 std::vector<PaddedAtomic> counts(N);
227 typename VerletListHelpers<Particle_T>::VerletListCounterFunctor counter(counts, _particleToIndex,
230 LCC08Traversal<ParticleCellType, typename VerletListHelpers<Particle_T>::VerletListCounterFunctor>(
232 this->
_linkedCells.getCellBlock().getCellLength(), dataLayout, useNewton3);
237 _neighborList.offsets.resize(N + 1);
238 _neighborList.offsets[0] = 0;
239 for (
size_t i = 0; i < N; ++i) {
240 _neighborList.offsets[i + 1] = _neighborList.offsets[i] + counts[i].value.load(std::memory_order_relaxed);
242 const size_t totalNeighbors = _neighborList.offsets[N];
243 _neighborList.indices.resize(totalNeighbors);
245 AutoPasLog(DEBUG,
"VerletLists::updateNeighborLists (MT): {} particles, {} neighbors, avg {:.2f}", N,
246 totalNeighbors, N > 0 ?
static_cast<double>(totalNeighbors) /
static_cast<double>(N) : 0.0);
250 for (
size_t i = 0; i < N; ++i) {
251 counts[i].value.store(_neighborList.offsets[i], std::memory_order_relaxed);
254 typename VerletListHelpers<Particle_T>::VerletListFillerFunctor filler(_neighborList, counts, _particleToIndex,
257 LCC08Traversal<ParticleCellType, typename VerletListHelpers<Particle_T>::VerletListFillerFunctor>(
259 this->
_linkedCells.getCellBlock().getCellLength(), dataLayout, useNewton3);
270 std::unordered_map<const Particle_T *, size_t> _particleToIndex;
277 std::vector<ParticleType *> _indexToParticle;
283 VerletListHelpers<Particle_T>::NeighborListCRS _neighborList;
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:74
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
constexpr bool end() const
Dummy to make range-based for loops work.
Definition: ParticleContainerInterface.h:248
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.
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, VerletListHelpers< ParticleType >::NeighborListCRS &neighborList, const std::unordered_map< const ParticleType *, size_t > &particleToIndex, const std::vector< ParticleType * > &indexToParticle)
Sets the information the traversal needs for the iteration.
Definition: VLTraversalInterface.h:38
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:212
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:338
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:323
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:328
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:335
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:332
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:313
Verlet Lists container.
Definition: VerletLists.h:31
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:66
BuildVerletListType
Enum that specifies how the verlet lists should be built.
Definition: VerletLists.h:45
@ VerletSoA
Build it using AoS.
Definition: VerletLists.h:53
@ VerletAoS
Build it using AoS.
Definition: VerletLists.h:49
const VerletListHelpers< Particle_T >::NeighborListCRS & getNeighborList() const
Returns the flat CRS neighbor list.
Definition: VerletLists.h:97
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: VerletLists.h:75
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists, marks them valid and resets the internal counter.
Definition: VerletLists.h:112
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: VerletLists.h:77
const std::unordered_map< const Particle_T *, size_t > & getParticleIndex() const
Returns the particle-pointer-to-SoA-index map.
Definition: VerletLists.h:104
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
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144
Flat Compressed-Row-Storage (CRS) neighbor list.
Definition: VerletListHelpers.h:32