MPS-Basic
Loading...
Searching...
No Matches
particles.cpp
Go to the documentation of this file.
1#include "particles.hpp"
2
3#include <vector>
4
5std::vector<Particle>::iterator Particles::begin() {
6 return particles.begin();
7}
8
9std::vector<Particle>::const_iterator Particles::begin() const {
10 return particles.begin();
11}
12
13std::vector<Particle>::iterator Particles::end() {
14 return particles.end();
15}
16
17std::vector<Particle>::const_iterator Particles::end() const {
18 return particles.end();
19}
20
21int Particles::size() const {
22 return particles.size();
23}
24
25void Particles::add(const Particle& particle) {
26 // This class assumes that the index of the inner vector is equal to the id of the particle located there.
27 // To ensure this, assert that the id of the particle is equal to the size of the inner vector.
28 assert(particle.id == particles.size());
29 particles.emplace_back(particle);
30}
31
33 return particles[index];
34}
35
36const Particle& Particles::operator[](size_t index) const {
37 return particles[index];
38}
Class for particle in MPS method.
Definition particle.hpp:47
int id
index of the particle
Definition particle.hpp:50
std::vector< Particle >::iterator end()
Definition particles.cpp:13
Particle & operator[](size_t index)
Get a particle by index.
Definition particles.cpp:32
std::vector< Particle > particles
Definition particles.hpp:49
int size() const
Get the number of particles.
Definition particles.cpp:21
std::vector< Particle >::iterator begin()
Definition particles.cpp:5
void add(const Particle &particle)
Add a particle to the collection.
Definition particles.cpp:25