#include <particles.h>
The Particles class abstracts the storage and manipulation of particles.
There is one Particles object per Experiment. It stores the data about all existing particles in the experiment (ParticleData).
Definition at line 33 of file particles.h.
Classes | |
class | GenericIterator |
Public Types | |
using | iterator = GenericIterator< ParticleData > |
An alias to the GenericIterator class of ParticleData. More... | |
using | const_iterator = GenericIterator< const ParticleData > |
An alias to the GenericIterator class of const ParticleData. More... | |
Public Member Functions | |
Particles () | |
Creates a new (empty) Particles object. More... | |
Particles (const Particles &)=delete | |
Cannot be copied. More... | |
Particles & | operator= (const Particles &)=delete |
Cannot be copied. More... | |
ParticleList | copy_to_vector () const |
const ParticleData & | insert (const ParticleData &p) |
Inserts the particle into the list of particles. More... | |
void | create (size_t n, PdgCode pdg) |
Add n particles of the same type (pdg ) to the list. More... | |
ParticleData & | create (const PdgCode pdg) |
Add one particle of the given pdg code. More... | |
size_t | size () const |
bool | is_empty () const |
double | time () const |
Returns the time of the computational frame. More... | |
void | reset () |
Reset the state of the Particles object to an empty list and a new id counter. More... | |
bool | is_valid (const ParticleData ©) const |
Check whether the ParticleData copy is still a valid copy of the one stored in the Particles object. More... | |
void | remove (const ParticleData &p) |
Remove the given particle p from the list. More... | |
void | replace (const ParticleList &to_remove, ParticleList &to_add) |
Replace the particles in to_remove with the particles in to_add in the list of current particles. More... | |
const ParticleData & | update_particle (const ParticleData &p, const ParticleData &new_state) |
Updates the particle identified by p with the state stored in new_state . More... | |
void | update (const ParticleList &old_state, ParticleList &new_state, bool do_replace) |
Updates the Particles object, replacing the particles in old_state with the particles in new_state . More... | |
const ParticleData & | lookup (const ParticleData &old_state) const |
Returns the particle that is currently stored in this object given an old copy of that particle. More... | |
ParticleData & | front () |
const ParticleData & | front () const |
const overload of &front() More... | |
ParticleData & | back () |
const ParticleData & | back () const |
const overload of &back() More... | |
iterator | begin () |
const_iterator | begin () const |
const overload of begin() More... | |
iterator | end () |
const_iterator | end () const |
const overload of end() More... | |
const_iterator | cbegin () const |
const_iterator | cend () const |
Private Member Functions | |
void | increase_capacity (unsigned new_capacity) |
void | ensure_capacity (unsigned to_add) |
void | copy_in (ParticleData &to, const ParticleData &from) |
Private Attributes | |
int | id_max_ = -1 |
Highest id of a given particle. More... | |
unsigned | data_size_ = 0u |
unsigned | data_capacity_ = 100u |
std::unique_ptr< ParticleData[]> | data_ |
Points to a dynamically allocated array of ParticleData objects. More... | |
std::vector< unsigned > | dirty_ |
Stores the indexes in data_ that do not hold valid particle data and should be reused when new particles are added. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Particles &particles) |
Print effective mass and type name for all particles to the stream. More... | |
An alias to the GenericIterator class of ParticleData.
Definition at line 369 of file particles.h.
using smash::Particles::const_iterator = GenericIterator<const ParticleData> |
An alias to the GenericIterator class of const ParticleData.
Definition at line 371 of file particles.h.
smash::Particles::Particles | ( | ) |
Creates a new (empty) Particles object.
Definition at line 17 of file particles.cc.
|
delete |
Cannot be copied.
|
inline |
Definition at line 44 of file particles.h.
const ParticleData & smash::Particles::insert | ( | const ParticleData & | p | ) |
Inserts the particle into
the list of particles.
The argument will
afterwards not be a valid copy of a particle of the internal list. I.e.
[in] | p | The data to be added. The id will not be copied. Instead a new unique id is generated by the function. |
Definition at line 50 of file particles.cc.
void smash::Particles::create | ( | size_t | n, |
PdgCode | pdg | ||
) |
Add n
particles of the same type (pdg
) to the list.
[in] | n | The number of the added particles |
[in] | pdg | PDG code of the added particles |
Definition at line 66 of file particles.cc.
ParticleData & smash::Particles::create | ( | const PdgCode | pdg | ) |
Add one particle of the given pdg
code.
[in] | pdg | PDG code of the added particle |
Definition at line 89 of file particles.cc.
|
inline |
|
inline |
|
inline |
Returns the time of the computational frame.
Definition at line 100 of file particles.h.
void smash::Particles::reset | ( | ) |
Reset the state of the Particles object to an empty list and a new id counter.
The object is thus in the same state as right after construction.
Definition at line 139 of file particles.cc.
|
inline |
Check whether the ParticleData copy is still a valid copy of the one stored in the Particles object.
[in] | copy | ParticleData copy whose validity is going to be checked |
Definition at line 120 of file particles.h.
void smash::Particles::remove | ( | const ParticleData & | p | ) |
Remove the given particle p
from the list.
The argument p
must be a valid copy obtained from Particles, i.e. a call to is_valid must return true
.
[in] | p | Particle which is going to be removed |
p
is only enforced in DEBUG builds. Definition at line 108 of file particles.cc.
void smash::Particles::replace | ( | const ParticleList & | to_remove, |
ParticleList & | to_add | ||
) |
Replace the particles in to_remove
with the particles in to_add
in the list of current particles.
The particles in to_remove
must be valid copies obtained from Particles. The particles in to_add
are adjusted to be valid copies of the new particles in the Particles list.
[in] | to_remove | A list of particles which are valid copies out of the Particles list. They identify the entries in Particles to be replaced. |
[in] | to_add | A list of (invalid) ParticleData objects to be placed into the Particles list. |
to_remove
is only enforced in DEBUG builds. Definition at line 120 of file particles.cc.
|
inline |
Updates the particle identified by p
with the state stored in new_state
.
A reference to the resulting ParticleData object in the list is subsequently returned.
The state update copies the id_process, momentum, and position from new_state
.
This function expects p
to be a valid copy (i.e. is_valid returns true
) and it expects the ParticleType of p
and new_state
to be equal. This is enforced in DEBUG builds.
[in] | p | The particle which is going to be updated. |
[in] | new_state | The new state of the particle. |
Definition at line 175 of file particles.h.
|
inline |
Updates the Particles object, replacing the particles in old_state
with the particles in new_state
.
The third parameter do_replace
determines whether the particles are actually replaced (so that they get new IDs etc) or if the old particles are kept and just updated with new properties (e.g. in an elastic collision).
This function expects old_state
to be a valid copy (i.e. is_valid returns true
). This is enforced in DEBUG builds.
[in] | old_state | Particles of old states |
[in] | new_state | New states of these particles |
[in] | do_replace | Whether to replace the old states by the new ones |
Definition at line 200 of file particles.h.
|
inline |
Returns the particle that is currently stored in this object given an old copy of that particle.
This function expects old_state
to be a valid copy (i.e. is_valid returns true
). This is enforced in DEBUG builds.
[in] | old_state | A copy of old state particle. We need its index to know where it's stored in the particles list. |
Definition at line 222 of file particles.h.
|
inline |
|
inline |
const overload of &front()
Definition at line 380 of file particles.h.
|
inline |
|
inline |
const overload of &back()
Definition at line 389 of file particles.h.
|
inline |
Definition at line 395 of file particles.h.
|
inline |
const overload of begin()
Definition at line 407 of file particles.h.
|
inline |
Definition at line 419 of file particles.h.
|
inline |
const overload of end()
Definition at line 425 of file particles.h.
|
inline |
|
inline |
|
private |
Increases the capacity of data_ to new_capacity
.
[in] | new_capacity | new capacity which is expected to be larger than data_capacity_. This is enforced in DEBUG builds. |
Definition at line 30 of file particles.cc.
|
inlineprivate |
Ensure that the capacity of data_ is large enough to hold to_add
more entries. If the capacity does not sufficient increase_capacity is called.
[in] | to_add | Number of particles which is going to be added to the list. |
Definition at line 23 of file particles.cc.
|
inlineprivate |
Common implementation for copying the relevant data of a ParticleData object into data_. This does not implement a 1:1 copy, instead:
from
. [out] | to | The copied version of the particle added to the end of the to particle list. |
[in] | from | the original particle that will be copied. |
Definition at line 44 of file particles.cc.
|
private |
Highest id of a given particle.
The first particle added to data_ will have id 0.
Definition at line 446 of file particles.h.
|
private |
The number of elements in data_ (including holes, but excluding entries behind the last valid particle)
Definition at line 487 of file particles.h.
|
private |
The capacity of the memory pointed to by data_.
Definition at line 492 of file particles.h.
|
private |
Points to a dynamically allocated array of ParticleData objects.
The allocated size is stored in data_capacity_ and the used range (starting from index 0) is stored in data_size_.
Definition at line 498 of file particles.h.
|
private |
Stores the indexes in data_ that do not hold valid particle data and should be reused when new particles are added.
Definition at line 504 of file particles.h.