AutoPas  3.0.0
Loading...
Searching...
No Matches
VerletListsCellsHelpers.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <array>
10#include <cstddef>
11#include <unordered_map>
12#include <utility>
13#include <vector>
14
17
29template <class Particle_T>
30using AllCellsNeighborListsType = std::vector<std::vector<std::pair<Particle_T *, std::vector<Particle_T *>>>>;
31
39template <class Particle_T>
41 std::vector<std::vector<std::vector<std::pair<Particle_T *, std::vector<Particle_T *>>>>>;
42
47enum class VLCBuildType {
48 aosBuild,
49 soaBuild,
50};
51
68
74 bool operator==(const BaseStepOffsets &rhs) const;
75
81 bool operator!=(const BaseStepOffsets &rhs) const;
82};
83
100std::vector<BaseStepOffsets> buildBaseStep(const std::array<int, 3> &cellsPerDim, const TraversalOption traversal);
101
112size_t estimateListLength(size_t numParticles, const std::array<double, 3> &boxSize, double interactionLength,
113 double correctionFactor);
114
126template <class Cells>
127size_t estimateNumLists(size_t baseCellIndex, bool useNewton3, const Cells &cells,
128 const std::vector<BaseStepOffsets> &offsetsC08, const std::array<size_t, 3> cellsPerDim) {
129 // First for every cell, find its biggest factor.
130 // Meaning, find out what is the closest interaction type this cell is involved in.
131 std::unordered_map<int, double> offsetFactors{};
132 std::unordered_map<int, double> offsetFactorsNoN3{};
133 for (const auto [offsetA, offsetB, factor] : offsetsC08) {
134 offsetFactors[offsetA] = std::max(offsetFactors[offsetA], factor);
135 offsetFactorsNoN3[offsetB] = std::max(offsetFactors[offsetB], factor);
136 }
137 // The estimate is constructed by summing the involved cells' sizes weighted by their factors.
138 size_t estimate = 0;
139 for (const auto &[offset, factor] : offsetFactors) {
140 const auto otherCellCoords = utils::ThreeDimensionalMapping::oneToThreeD(baseCellIndex + offset, cellsPerDim);
141 if (otherCellCoords[0] < cellsPerDim[0] and otherCellCoords[1] < cellsPerDim[1] and
142 otherCellCoords[2] < cellsPerDim[2]) {
143 estimate += cells[baseCellIndex + offset].size() * factor;
144 }
145 }
146 // For the non Newton3 case, lists have to be created for particles that otherwise would already be covered.
147 if (not useNewton3) {
148 for (const auto &[offset, factor] : offsetFactorsNoN3) {
149 const auto otherCellCoords = utils::ThreeDimensionalMapping::oneToThreeD(baseCellIndex + offset, cellsPerDim);
150 if (otherCellCoords[0] < cellsPerDim[0] and otherCellCoords[1] < cellsPerDim[1] and
151 otherCellCoords[2] < cellsPerDim[2]) {
152 estimate += cells[baseCellIndex + offset].size() * factor;
153 }
154 }
155 }
156 return estimate;
157};
158} // namespace autopas::VerletListsCellsHelpers
Helper functions and type aliases for verlet lists cells.
Definition: VerletListsCellsHelpers.cpp:14
std::vector< std::vector< std::pair< Particle_T *, std::vector< Particle_T * > > > > AllCellsNeighborListsType
Cell wise verlet lists for neighbors from all adjacent cells: For every cell, a vector of pairs.
Definition: VerletListsCellsHelpers.h:30
VLCBuildType
Indicates which build functor should be used for the generation of the neighbor list.
Definition: VerletListsCellsHelpers.h:47
std::vector< std::vector< std::vector< std::pair< Particle_T *, std::vector< Particle_T * > > > > > PairwiseNeighborListsType
Pairwise verlet lists: For every cell a vector, for every neighboring cell a vector of particle-neigh...
Definition: VerletListsCellsHelpers.h:41
size_t estimateNumLists(size_t baseCellIndex, bool useNewton3, const Cells &cells, const std::vector< BaseStepOffsets > &offsetsC08, const std::array< size_t, 3 > cellsPerDim)
Function to estimate the number of neighbor lists for one base step.
Definition: VerletListsCellsHelpers.h:127
size_t estimateListLength(size_t numParticles, const std::array< double, 3 > &boxSize, double interactionLength, double correctionFactor)
Simple heuristic to calculate the average number of particles per verlet list assuming particles are ...
Definition: VerletListsCellsHelpers.cpp:16
std::vector< BaseStepOffsets > buildBaseStep(const std::array< int, 3 > &cellsPerDim, const TraversalOption traversal)
Builds the list of offsets from the base cell for the c01, c08, and c18 base step.
Definition: VerletListsCellsHelpers.cpp:26
constexpr std::array< T, 3 > oneToThreeD(T ind, const std::array< T, 3 > &dims)
Convert a 1d index to a 3d index.
Definition: ThreeDimensionalMapping.h:55
Helper Struct to bundle all information about base step offsets.
Definition: VerletListsCellsHelpers.h:55
bool operator!=(const BaseStepOffsets &rhs) const
Inequality operator.
Definition: VerletListsCellsHelpers.cpp:156
int offset1
Offset from the base cell for cell 1.
Definition: VerletListsCellsHelpers.h:59
int offset2
Offset from the base cell for cell 2.
Definition: VerletListsCellsHelpers.h:63
double listSizeEstimateFactor
Estimation factor on the fraction of particles that will end up needing a neighbor list in the base c...
Definition: VerletListsCellsHelpers.h:67
bool operator==(const BaseStepOffsets &rhs) const
Equality operator.
Definition: VerletListsCellsHelpers.cpp:152