28template <
class Particle_T,
bool isInternal = false>
30 :
public PairwiseFunctor<Particle_T, InteractionListGeneratorFunctor<Particle_T, isInternal>> {
57 bool gatherNewton3Lists)
59 _neighborListsAoS(neighborListsAoS),
60 _interactionLengthSquared(interactionLength * interactionLength),
61 _gatherNewton3Lists(gatherNewton3Lists) {}
67 std::string
getName()
override {
return "InteractionListGeneratorFunctor"; }
79 template <
class ParticleIterator_T>
81 _neighborListsAoS.clear();
82 for (
auto iter = particlesBegin; iter.isValid(); ++iter) {
83 _neighborListsAoS[&(*iter)];
116 void AoSFunctor(Particle_T &i, Particle_T &j,
bool newton3)
override {
117 using namespace autopas::utils::ArrayMath::literals;
119 if (_gatherNewton3Lists and not newton3) [[unlikely]] {
121 "InteractionListGeneratorFunctor should not be used with newton3=false and gatherNewton3Lists=true.");
124 if (i.isDummy() or j.isDummy()) {
127 auto dist = i.getR() - j.getR();
130 if (distsquare < _interactionLengthSquared) {
146 _neighborListsAoS.at(&i).push_back(&j);
147 if (newton3 and not _gatherNewton3Lists) {
148 _neighborListsAoS.at(&j).push_back(&i);
158 if (soa.
size() == 0)
return;
160 auto **
const __restrict ptrptr = soa.template begin<Particle_T::AttributeNames::ptr>();
161 const double *
const __restrict xptr = soa.template begin<Particle_T::AttributeNames::posX>();
162 const double *
const __restrict yptr = soa.template begin<Particle_T::AttributeNames::posY>();
163 const double *
const __restrict zptr = soa.template begin<Particle_T::AttributeNames::posZ>();
164 const auto *
const __restrict ownedStatePtr = soa.template begin<Particle_T::AttributeNames::ownershipState>();
166 size_t numPart = soa.
size();
167 for (
size_t i = 0; i < numPart; ++i) {
169 auto &iList = _neighborListsAoS.at(ptrptr[i]);
170 for (
size_t j = i + 1; j < numPart; ++j) {
172 const double drx = xptr[i] - xptr[j];
173 const double dry = yptr[i] - yptr[j];
174 const double drz = zptr[i] - zptr[j];
176 const double drx2 = drx * drx;
177 const double dry2 = dry * dry;
178 const double drz2 = drz * drz;
180 const double dr2 = drx2 + dry2 + drz2;
182 if (dr2 < _interactionLengthSquared) {
185 iList.push_back(ptrptr[j]);
186 if (not _gatherNewton3Lists) {
187 _neighborListsAoS.at(ptrptr[j]).push_back(ptrptr[i]);
205 if (_gatherNewton3Lists and not newton3) [[unlikely]] {
207 "InteractionListGeneratorFunctor should not be used with newton3=false and gatherNewton3Lists=true.");
210 if (soa1.
size() == 0 or soa2.
size() == 0)
return;
212 auto **
const __restrict ptr1ptr = soa1.template begin<Particle_T::AttributeNames::ptr>();
213 const double *
const __restrict x1ptr = soa1.template begin<Particle_T::AttributeNames::posX>();
214 const double *
const __restrict y1ptr = soa1.template begin<Particle_T::AttributeNames::posY>();
215 const double *
const __restrict z1ptr = soa1.template begin<Particle_T::AttributeNames::posZ>();
216 const auto *
const __restrict ownedState1Ptr = soa1.template begin<Particle_T::AttributeNames::ownershipState>();
218 auto **
const __restrict ptr2ptr = soa2.template begin<Particle_T::AttributeNames::ptr>();
219 const double *
const __restrict x2ptr = soa2.template begin<Particle_T::AttributeNames::posX>();
220 const double *
const __restrict y2ptr = soa2.template begin<Particle_T::AttributeNames::posY>();
221 const double *
const __restrict z2ptr = soa2.template begin<Particle_T::AttributeNames::posZ>();
222 const auto *
const __restrict ownedState2Ptr = soa2.template begin<Particle_T::AttributeNames::ownershipState>();
224 const size_t numPart1 = soa1.
size();
225 for (
size_t i = 0; i < numPart1; ++i) {
226 auto &iList = _neighborListsAoS.at(ptr1ptr[i]);
228 const size_t numPart2 = soa2.
size();
230 for (
size_t j = 0; j < numPart2; ++j) {
232 const double drx = x1ptr[i] - x2ptr[j];
233 const double dry = y1ptr[i] - y2ptr[j];
234 const double drz = z1ptr[i] - z2ptr[j];
236 const double drx2 = drx * drx;
237 const double dry2 = dry * dry;
238 const double drz2 = drz * drz;
240 const double dr2 = drx2 + dry2 + drz2;
242 if (dr2 < _interactionLengthSquared) {
244 iList.push_back(ptr2ptr[j]);
245 if (newton3 and not _gatherNewton3Lists) {
246 _neighborListsAoS.at(ptr2ptr[j]).push_back(ptr1ptr[i]);
270 if (_gatherNewton3Lists and not newton3) [[unlikely]] {
272 "InteractionListGeneratorFunctor should not be used with newton3=false and gatherNewton3Lists=true.");
275 if (soa.
size() == 0 or verletList.empty())
return;
277 auto **
const __restrict ptrptr = soa.template begin<Particle_T::AttributeNames::ptr>();
278 const double *
const __restrict xptr = soa.template begin<Particle_T::AttributeNames::posX>();
279 const double *
const __restrict yptr = soa.template begin<Particle_T::AttributeNames::posY>();
280 const double *
const __restrict zptr = soa.template begin<Particle_T::AttributeNames::posZ>();
281 const auto *
const __restrict ownedStatePtr = soa.template begin<Particle_T::AttributeNames::ownershipState>();
285 auto &firstList = _neighborListsAoS.at(ptrptr[indexFirst]);
286 const double xFirst = xptr[indexFirst];
287 const double yFirst = yptr[indexFirst];
288 const double zFirst = zptr[indexFirst];
290 for (
const size_t j : verletList) {
292 const double drx = xFirst - xptr[j];
293 const double dry = yFirst - yptr[j];
294 const double drz = zFirst - zptr[j];
296 const double drx2 = drx * drx;
297 const double dry2 = dry * dry;
298 const double drz2 = drz * drz;
300 const double dr2 = drx2 + dry2 + drz2;
302 if (dr2 < _interactionLengthSquared) {
304 firstList.push_back(ptrptr[j]);
305 if (newton3 and not _gatherNewton3Lists) {
306 _neighborListsAoS.at(ptrptr[j]).push_back(ptrptr[indexFirst]);
315 constexpr static std::array<typename Particle_T::AttributeNames, 5>
getNeededAttr() {
316 return std::array<typename Particle_T::AttributeNames, 5>{
317 Particle_T::AttributeNames::ptr, Particle_T::AttributeNames::posX, Particle_T::AttributeNames::posY,
318 Particle_T::AttributeNames::posZ, Particle_T::AttributeNames::ownershipState};
324 constexpr static std::array<typename Particle_T::AttributeNames, 5>
getNeededAttr(std::false_type) {
331 constexpr static std::array<typename Particle_T::AttributeNames, 0>
getComputedAttr() {
332 return std::array<typename Particle_T::AttributeNames, 0>{};
337 double _interactionLengthSquared;
343 bool _gatherNewton3Lists{
false};
AlignedAllocator class.
Definition: AlignedAllocator.h:29
This functor generates lists of particles within interactionLength of each other: can be used interna...
Definition: InteractionListGeneratorFunctor.h:30
static constexpr std::array< typename Particle_T::AttributeNames, 5 > getNeededAttr(std::false_type)
Get attributes needed for computation without N3 optimization.
Definition: InteractionListGeneratorFunctor.h:324
std::unordered_map< Particle_T *, std::vector< Particle_T * > > NeighborListAoSType
Neighbor list AoS style.
Definition: InteractionListGeneratorFunctor.h:40
bool isRelevantForTuning() override
Whether particle is relevant for tuning.
Definition: InteractionListGeneratorFunctor.h:91
Particle_T::SoAArraysType SoAArraysType
Structure of the SoAs defined by the particle.
Definition: InteractionListGeneratorFunctor.h:35
InteractionListGeneratorFunctor(NeighborListAoSType &neighborListsAoS, double interactionLength, bool gatherNewton3Lists)
Constructor.
Definition: InteractionListGeneratorFunctor.h:56
void SoAFunctorPair(SoAView< SoAArraysType > soa1, SoAView< SoAArraysType > soa2, bool newton3) override
SoAFunctor for the verlet list generation.
Definition: InteractionListGeneratorFunctor.h:204
void SoAFunctorVerlet(SoAView< SoAArraysType > soa, const size_t indexFirst, const std::vector< size_t, AlignedAllocator< size_t > > &verletList, bool newton3) override
SoAFunctorVerlet for interaction list generation.
Definition: InteractionListGeneratorFunctor.h:268
bool allowsNewton3() override
Whether InteractionListGeneratorFunctor allows Newton3.
Definition: InteractionListGeneratorFunctor.h:97
static constexpr std::array< typename Particle_T::AttributeNames, 5 > getNeededAttr()
Get attributes needed for computation.
Definition: InteractionListGeneratorFunctor.h:315
void SoAFunctorSingle(SoAView< SoAArraysType > soa, bool) override
SoAFunctor for verlet list generation.
Definition: InteractionListGeneratorFunctor.h:157
static constexpr std::array< typename Particle_T::AttributeNames, 0 > getComputedAttr()
Get attributes computed by this functor.
Definition: InteractionListGeneratorFunctor.h:331
void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3) override
AoSFunctor for interaction list generation.
Definition: InteractionListGeneratorFunctor.h:116
std::string getName() override
Definition: InteractionListGeneratorFunctor.h:67
void initializeNeighborList(ParticleIterator_T particlesBegin)
Initializes the neighbor list map for the given range of particles: clears any previous contents and ...
Definition: InteractionListGeneratorFunctor.h:80
bool allowsNonNewton3() override
Whether InteractionListGeneratorFunctor allows non-newton3.
Definition: InteractionListGeneratorFunctor.h:104
PairwiseFunctor class.
Definition: PairwiseFunctor.h:45
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:25
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:85
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!