AutoPas  3.0.0
Loading...
Searching...
No Matches
ParticleCellHelpers.h
Go to the documentation of this file.
1
7#pragma once
9
10namespace autopas::internal {
20template <class CellType>
21static bool checkParticleInCellAndUpdateByID(CellType &cell, const typename CellType::ParticleType &particle) {
22 for (auto &p : cell) {
23 if (p.getID() == particle.getID()) {
24 p = particle;
25 return true;
26 }
27 }
28 return false;
29}
30
38template <class CellType>
39static bool checkParticleInCellAndUpdateByIDAndPosition(CellType &cell, const typename CellType::ParticleType &particle,
40 double absError) {
41 using namespace autopas::utils::ArrayMath::literals;
42 // This lock is relevant for octree and directSum.
43 std::lock_guard<AutoPasLock> cellLock(cell.getCellLock());
44 for (auto &p : cell) {
45 if (p.getID() == particle.getID()) {
46 auto distanceVec = p.getR() - particle.getR();
47 auto distanceSqr = autopas::utils::ArrayMath::dot(distanceVec, distanceVec);
48 if (distanceSqr < absError * absError) {
49 p = particle;
50 // found the particle, returning.
51 return true;
52 }
53 }
54 }
55 return false;
56}
57} // namespace autopas::internal
This namespace is used for implementation specifics.
Definition: CellFunctor.h:14
static bool checkParticleInCellAndUpdateByID(CellType &cell, const typename CellType::ParticleType &particle)
Updates a found particle within cellI to the values of particleI.
Definition: ParticleCellHelpers.h:21
static bool checkParticleInCellAndUpdateByIDAndPosition(CellType &cell, const typename CellType::ParticleType &particle, double absError)
Same as checkParticleInCellAndUpdateByID(CellType, ParticleType), but additionally checks whether the...
Definition: ParticleCellHelpers.h:39
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
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19