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