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:
25
30 bool isDirty() { return _dirty; }
31
35 void markAsClean() {
36 _dirty = false;
37 _dirtyIndex = _particleListImp.size();
38 }
39
44 _particleListImp.erase(std::remove_if(_particleListImp.begin(), _particleListImp.end(),
45 [](const auto &particle) { return particle.isHalo(); }),
46 _particleListImp.end());
47 _dirty = true;
48 _dirtyIndex = 0;
49 }
50
55 _particleListImp.erase(std::remove_if(_particleListImp.begin(), _particleListImp.end(),
56 [](const auto &particle) { return particle.isDummy(); }),
57 _particleListImp.end());
58 _dirty = true;
59 _dirtyIndex = 0;
60 }
61
66 void push_back(const Particle_T &particle) {
67 _particleListLock.lock();
68 _dirty = true;
69 if (_particleListImp.capacity() == _particleListImp.size()) {
70 _dirtyIndex = 0;
71 }
72 _particleListImp.push_back(particle);
73 _particleListLock.unlock();
74 }
75
80 int totalSize() { return _particleListImp.size(); }
81
86 int dirtySize() { return totalSize() - _dirtyIndex; }
87
92 bool needsRebuild() { return _dirtyIndex == 0; }
93
98 auto beginDirty() { return _particleListImp.begin() + _dirtyIndex; }
103 auto endDirty() { return _particleListImp.end(); }
104
109 template <typename Lambda>
110 void forEach(Lambda forEachLambda) {
111 for (Particle_T &p : _particleListImp) {
112 forEachLambda(p);
113 }
114 }
115
121 template <typename Lambda, typename A>
122 void reduce(Lambda reduceLambda, A &result) {
123 for (Particle_T &p : _particleListImp) {
124 reduceLambda(p, result);
125 }
126 }
127
128 private:
132 bool _dirty = false;
136 size_t _dirtyIndex{0};
137 autopas::AutoPasLock _particleListLock;
138 std::vector<Particle_T> _particleListImp;
139};
ParticleVector class.
Definition: ParticleVector.h:22
bool needsRebuild()
Indicates, whether References already stored in cells need to be updated.
Definition: ParticleVector.h:92
int totalSize()
Get the number of Particles in the data structure.
Definition: ParticleVector.h:80
void push_back(const Particle_T &particle)
Add a Particle to the data structure.
Definition: ParticleVector.h:66
auto endDirty()
End of the iterator over dirty Particles.
Definition: ParticleVector.h:103
void clearHaloParticles()
Remove all halo 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:122
int dirtySize()
Get the number of dirty Particles in the data structure.
Definition: ParticleVector.h:86
void markAsClean()
Marks the ParticleVector as clean.
Definition: ParticleVector.h:35
auto beginDirty()
Begin of the iterator over dirty Particles.
Definition: ParticleVector.h:98
void forEach(Lambda forEachLambda)
Iterate over all particles and execute lambda function on them.
Definition: ParticleVector.h:110
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:54
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