AutoPas  3.0.0
Loading...
Searching...
No Matches
ParticleVector.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <vector>
11
13
21template <class Particle_T>
23 public:
24 ParticleVector() = default;
25
30 bool isDirty() { return _dirty; }
31
35 void markAsClean() {
36 _dirty = false;
37 _dirtyIndex = _particleListImp.size();
38 }
39
44 _particleListImp.clear();
45 _dirty = true;
46 _dirtyIndex = 0;
47 }
48
53 _particleListImp.erase(std::remove_if(_particleListImp.begin(), _particleListImp.end(),
54 [](const auto &particle) { return particle.isHalo(); }),
55 _particleListImp.end());
56 _dirty = true;
57 _dirtyIndex = 0;
58 }
59
64 _particleListImp.erase(std::remove_if(_particleListImp.begin(), _particleListImp.end(),
65 [](const auto &particle) { return particle.isDummy(); }),
66 _particleListImp.end());
67 _dirty = true;
68 _dirtyIndex = 0;
69 }
70
75 void push_back(const Particle_T &particle) {
76 _particleListLock.lock();
77 _dirty = true;
78 if (_particleListImp.capacity() == _particleListImp.size()) {
79 _dirtyIndex = 0;
80 }
81 _particleListImp.push_back(particle);
82 _particleListLock.unlock();
83 }
84
89 int totalSize() { return _particleListImp.size(); }
90
95 int dirtySize() { return totalSize() - _dirtyIndex; }
96
101 bool needsRebuild() { return _dirtyIndex == 0; }
102
107 auto beginDirty() { return _particleListImp.begin() + _dirtyIndex; }
112 auto endDirty() { return _particleListImp.end(); }
113
118 template <typename Lambda>
119 void forEach(Lambda forEachLambda) {
120 for (Particle_T &p : _particleListImp) {
121 forEachLambda(p);
122 }
123 }
124
130 template <typename Lambda, typename A>
131 void reduce(Lambda reduceLambda, A &result) {
132 for (Particle_T &p : _particleListImp) {
133 reduceLambda(p, result);
134 }
135 }
136
137 private:
141 bool _dirty = false;
145 size_t _dirtyIndex{0};
146 autopas::AutoPasLock _particleListLock;
147 std::vector<Particle_T> _particleListImp;
148};
ParticleVector class.
Definition: ParticleVector.h:22
bool needsRebuild()
Indicates, whether References already stored in cells need to be updated.
Definition: ParticleVector.h:101
int totalSize()
Get the number of Particles in the data structure.
Definition: ParticleVector.h:89
void push_back(const Particle_T &particle)
Add a Particle to the data structure.
Definition: ParticleVector.h:75
auto endDirty()
End of the iterator over dirty Particles.
Definition: ParticleVector.h:112
void clearHaloParticles()
Remove all halo particles from the container and mark it as dirty.
Definition: ParticleVector.h:52
void clearAllParticles()
Remove all particles from the container and mark it as dirty.
Definition: ParticleVector.h:43
void reduce(Lambda reduceLambda, A &result)
Iterate over all particles and execute lambda function on them.
Definition: ParticleVector.h:131
int dirtySize()
Get the number of dirty Particles in the data structure.
Definition: ParticleVector.h:95
void markAsClean()
Marks the ParticleVector as clean.
Definition: ParticleVector.h:35
auto beginDirty()
Begin of the iterator over dirty Particles.
Definition: ParticleVector.h:107
void forEach(Lambda forEachLambda)
Iterate over all particles and execute lambda function on them.
Definition: ParticleVector.h:119
bool isDirty()
Returns the dirty flag, indicating whether Particles exist in the vector that are not stored in a cel...
Definition: ParticleVector.h:30
void deleteDummyParticles()
Remove all dummy particles from the container and mark it as dirty.
Definition: ParticleVector.h:63
AutoPasLock for the sequential case.
Definition: WrapOpenMP.h:155
void unlock()
Release the lock.
Definition: WrapOpenMP.h:200
void lock()
Acquire the lock.
Definition: WrapOpenMP.h:190