AutoPas  3.0.0
Loading...
Searching...
No Matches
AsBuildPairGeneratorFunctor.h
Go to the documentation of this file.
1
7#pragma once
8
12
13namespace autopas {
14
15template <class Particle_T>
16class VerletNeighborListAsBuild;
17
18namespace internal {
19
28template <class Particle_T, bool callCheckInstead = false>
30 : public autopas::PairwiseFunctor<Particle_T, AsBuildPairGeneratorFunctor<Particle_T, callCheckInstead>> {
31 public:
35 using SoAArraysType = typename Particle_T::SoAArraysType;
36
40 constexpr static auto getNeededAttr() {
41 return std::array<typename Particle_T::AttributeNames, 4>{
42 Particle_T::AttributeNames::ptr, Particle_T::AttributeNames::posX, Particle_T::AttributeNames::posY,
43 Particle_T::AttributeNames::posZ};
44 }
45
49 constexpr static auto getNeededAttr(std::false_type) {
50 return std::array<typename Particle_T::AttributeNames, 4>{
51 Particle_T::AttributeNames::id, Particle_T::AttributeNames::posX, Particle_T::AttributeNames::posY,
52 Particle_T::AttributeNames::posZ};
53 }
54
58 constexpr static auto getComputedAttr() { return std::array<typename Particle_T::AttributeNames, 0>{}; }
59
60 bool allowsNewton3() override { return true; }
61 bool allowsNonNewton3() override { return true; }
62
69 : autopas::PairwiseFunctor<Particle_T, AsBuildPairGeneratorFunctor>(cutoffskin),
70 _list(neighborList),
71 _cutoffskinsquared(cutoffskin * cutoffskin) {}
72
73 std::string getName() override { return "AsBuildPairGeneratorFunctor"; }
74
75 [[nodiscard]] bool isRelevantForTuning() override { return false; }
76
83 void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3) override {
84 using namespace autopas::utils::ArrayMath::literals;
85
86 const auto dist = i.getR() - j.getR();
87 const double distsquare = utils::ArrayMath::dot(dist, dist);
88 if (distsquare < _cutoffskinsquared) {
89 if (callCheckInstead) {
90 _list.checkPair(&i, &j);
91 } else {
92 _list.addPair(&i, &j);
93 }
94 }
95 }
96
102 void SoAFunctorSingle(SoAView<SoAArraysType> soa, bool newton3) override {
103 if (soa.size() == 0) return;
104
105 auto **const __restrict ptrptr = soa.template begin<Particle_T::AttributeNames::ptr>();
106 double *const __restrict xptr = soa.template begin<Particle_T::AttributeNames::posX>();
107 double *const __restrict yptr = soa.template begin<Particle_T::AttributeNames::posY>();
108 double *const __restrict zptr = soa.template begin<Particle_T::AttributeNames::posZ>();
109
110 size_t numPart = soa.size();
111 for (unsigned int i = 0; i < numPart; ++i) {
112 for (unsigned int j = i + 1; j < numPart; ++j) {
113 const double drx = xptr[i] - xptr[j];
114 const double dry = yptr[i] - yptr[j];
115 const double drz = zptr[i] - zptr[j];
116
117 const double drx2 = drx * drx;
118 const double dry2 = dry * dry;
119 const double drz2 = drz * drz;
120
121 const double dr2 = drx2 + dry2 + drz2;
122
123 if (dr2 < _cutoffskinsquared) {
124 _list.addPair(ptrptr[i], ptrptr[j]);
125 if (not newton3) {
126 _list.addPair(ptrptr[j], ptrptr[i]);
127 }
128 }
129 }
130 }
131 }
132
138 void SoAFunctorPair(SoAView<SoAArraysType> soa1, SoAView<SoAArraysType> soa2, bool /*newton3*/) override {
139 if (soa1.size() == 0 || soa2.size() == 0) return;
140
141 auto **const __restrict ptrptr1 = soa1.template begin<Particle_T::AttributeNames::ptr>();
142 double *const __restrict x1ptr = soa1.template begin<Particle_T::AttributeNames::posX>();
143 double *const __restrict y1ptr = soa1.template begin<Particle_T::AttributeNames::posY>();
144 double *const __restrict z1ptr = soa1.template begin<Particle_T::AttributeNames::posZ>();
145
146 auto **const __restrict ptrptr2 = soa2.template begin<Particle_T::AttributeNames::ptr>();
147 double *const __restrict x2ptr = soa2.template begin<Particle_T::AttributeNames::posX>();
148 double *const __restrict y2ptr = soa2.template begin<Particle_T::AttributeNames::posY>();
149 double *const __restrict z2ptr = soa2.template begin<Particle_T::AttributeNames::posZ>();
150
151 size_t numPart1 = soa1.size();
152 for (unsigned int i = 0; i < numPart1; ++i) {
153 size_t numPart2 = soa2.size();
154 for (unsigned int j = 0; j < numPart2; ++j) {
155 const double drx = x1ptr[i] - x2ptr[j];
156 const double dry = y1ptr[i] - y2ptr[j];
157 const double drz = z1ptr[i] - z2ptr[j];
158
159 const double drx2 = drx * drx;
160 const double dry2 = dry * dry;
161 const double drz2 = drz * drz;
162
163 const double dr2 = drx2 + dry2 + drz2;
164
165 if (dr2 < _cutoffskinsquared) {
166 _list.addPair(ptrptr1[i], ptrptr2[j]);
167 }
168 }
169 }
170 }
171
172 private:
180 double _cutoffskinsquared;
181};
182
183} // namespace internal
184
185} // namespace autopas
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:23
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:83
This class implements a neighbor list that remembers which thread added which particle pair and at wh...
Definition: VerletNeighborListAsBuild.h:22
This functor can generate or check variable verlet lists using the typical pairwise traversal.
Definition: AsBuildPairGeneratorFunctor.h:30
void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3) override
Adds the given pair to the neighbor list.
Definition: AsBuildPairGeneratorFunctor.h:83
AsBuildPairGeneratorFunctor(VerletNeighborListAsBuild< Particle_T > &neighborList, double cutoffskin)
Constructor of the functor.
Definition: AsBuildPairGeneratorFunctor.h:68
void SoAFunctorSingle(SoAView< SoAArraysType > soa, bool newton3) override
Adds all pairs of the SoA to the neighbor list.
Definition: AsBuildPairGeneratorFunctor.h:102
static constexpr auto getNeededAttr(std::false_type)
Get attributes needed for computation without N3 optimization.
Definition: AsBuildPairGeneratorFunctor.h:49
bool allowsNewton3() override
Specifies whether the functor is capable of Newton3-like functors.
Definition: AsBuildPairGeneratorFunctor.h:60
typename Particle_T::SoAArraysType SoAArraysType
The structure of the SoAs is defined by the particle.
Definition: AsBuildPairGeneratorFunctor.h:35
static constexpr auto getNeededAttr()
Get attributes needed for computation.
Definition: AsBuildPairGeneratorFunctor.h:40
void SoAFunctorPair(SoAView< SoAArraysType > soa1, SoAView< SoAArraysType > soa2, bool) override
Adds all pairs (p1, p2), p1 element soa1, p2 element soa2 to the neighbor list.
Definition: AsBuildPairGeneratorFunctor.h:138
std::string getName() override
Returns name of functor.
Definition: AsBuildPairGeneratorFunctor.h:73
bool isRelevantForTuning() override
Specifies whether the functor should be considered for the auto-tuning process.
Definition: AsBuildPairGeneratorFunctor.h:75
static constexpr auto getComputedAttr()
Get attributes computed by this functor.
Definition: AsBuildPairGeneratorFunctor.h:58
bool allowsNonNewton3() override
Specifies whether the functor is capable of non-Newton3-like functors.
Definition: AsBuildPairGeneratorFunctor.h:61
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:32