Molecular Dynamics  v0.4
Project for the Practical hosted by the Scientific Computing Chair
Public Member Functions | Private Attributes | List of all members
DefaultParticleContainer Class Reference

Container to store the particles for simulation using the direct sum algorithm. More...

#include <DefaultParticleContainer.h>

Inheritance diagram for DefaultParticleContainer:
Inheritance graph
Collaboration diagram for DefaultParticleContainer:
Collaboration graph

Public Member Functions

 DefaultParticleContainer ()=default
 
 DefaultParticleContainer (size_t capacity)
 Create a ParticleContainer which can store up to capacity particles. More...
 
void add (Particle &p) override
 Add one particle to this container. More...
 
Particleat (size_t i)
 Obtain particle at position i. More...
 
size_t size () const override
 Retrieve the size of the data structure. More...
 
size_t capacity ()
 Retrieve the capacity of this container. More...
 
std::vector< Particle >::iterator begin ()
 Obtain an iterator to the first particle in this container. More...
 
std::vector< Particle >::iterator end ()
 Obtain an iterator to the last element of this container. More...
 
void reserve (size_t n)
 Used to reserve the capacity of the vector used to storing particles. More...
 
bool contains (Particle &p)
 Check, if this particle container contains an particle p' that equals p. More...
 
void applyToEachParticle (const std::function< void(Particle &)> &function) override
 Iterate over all particles in this container and apply a lambda function to them. More...
 
void applyToEachParticleInDomain (const std::function< void(Particle &)> &function) override
 Iterate over all particles that are part of the domain and apply a lambda function to them. For this container this method does the same as applyToEachParticle(), because every particle is in the simulation domain. More...
 
void applyToAllUniquePairsInDomain (const std::function< void(Particle &, Particle &)> &function) override
 Iterate over all unique pairs of particles being part of the simulation domain (in this container all particles) and apply a lambda function to them. More...
 
- Public Member Functions inherited from ParticleContainer
virtual ~ParticleContainer ()=default
 Virtual default constructor to guarantee appropriate memory clean up. More...
 

Private Attributes

std::vector< Particleparticles
 

Detailed Description

Container to store the particles for simulation using the direct sum algorithm.

The storage of the particles is based on std::vector. This guarantees fast iteration over the particles, because they are stored consecutively in memory.

Constructor & Destructor Documentation

◆ DefaultParticleContainer() [1/2]

DefaultParticleContainer::DefaultParticleContainer ( )
default

◆ DefaultParticleContainer() [2/2]

DefaultParticleContainer::DefaultParticleContainer ( size_t  capacity)
explicit

Create a ParticleContainer which can store up to capacity particles.

Parameters
capacityIf the capacity is exceeded the whole data structure will be extended leading to reallocation.
Here is the call graph for this function:

Member Function Documentation

◆ add()

void DefaultParticleContainer::add ( Particle p)
overridevirtual

Add one particle to this container.

Parameters
pParticle to be added to this container.

Add one particle to this container. It will be appended.

Implements ParticleContainer.

◆ applyToAllUniquePairsInDomain()

void DefaultParticleContainer::applyToAllUniquePairsInDomain ( const std::function< void(Particle &, Particle &)> &  function)
overridevirtual

Iterate over all unique pairs of particles being part of the simulation domain (in this container all particles) and apply a lambda function to them.

Parameters
functionLambda function that is applied to each unique pair of particles.

The purpose of this function is provide an easy way of calculating the force between all particles by using Newton's third law of motion.

Implements ParticleContainer.

◆ applyToEachParticle()

void DefaultParticleContainer::applyToEachParticle ( const std::function< void(Particle &)> &  function)
overridevirtual

Iterate over all particles in this container and apply a lambda function to them.

Parameters
functionLambda function that is applied to each particle.

Implements ParticleContainer.

Here is the caller graph for this function:

◆ applyToEachParticleInDomain()

void DefaultParticleContainer::applyToEachParticleInDomain ( const std::function< void(Particle &)> &  function)
overridevirtual

Iterate over all particles that are part of the domain and apply a lambda function to them. For this container this method does the same as applyToEachParticle(), because every particle is in the simulation domain.

Parameters
functionLambda function that is applied to each particle.

Implements ParticleContainer.

Here is the call graph for this function:

◆ at()

Particle & DefaultParticleContainer::at ( size_t  i)

Obtain particle at position i.

Parameters
iPosition of the particle of concern.
Returns
Particle at position i.

Before access, it will be checked, if the position is valid. Otherwise an exception will be thrown.

◆ begin()

std::vector< Particle >::iterator DefaultParticleContainer::begin ( )

Obtain an iterator to the first particle in this container.

Returns
Iterator to first particle in this container.

Obtain an iterator to the first particle in this container.

◆ capacity()

size_t DefaultParticleContainer::capacity ( )

Retrieve the capacity of this container.

Returns
Capacity of this container.

The capacity of this container is the number of particles which can be stored, before the data structure has to be extended.

Here is the caller graph for this function:

◆ contains()

bool DefaultParticleContainer::contains ( Particle p)

Check, if this particle container contains an particle p' that equals p.

Parameters
pParticle to look for
Returns
true, if this particle container contains some particle p' that equals p, false otherwise.

This method should only be used for testing purposes in small instances, because the implementation is not that efficient.

◆ end()

std::vector< Particle >::iterator DefaultParticleContainer::end ( )

Obtain an iterator to the last element of this container.

Returns
Iterator to last element of this container.

Obtain an iterator to the last element of this container.

◆ reserve()

void DefaultParticleContainer::reserve ( size_t  n)

Used to reserve the capacity of the vector used to storing particles.

Parameters
ndesired size

◆ size()

size_t DefaultParticleContainer::size ( ) const
overridevirtual

Retrieve the size of the data structure.

Returns
Number of particles in this container.

Provides the number of particles currently stored in the data structure.

Implements ParticleContainer.

Member Data Documentation

◆ particles

std::vector<Particle> DefaultParticleContainer::particles
private

The documentation for this class was generated from the following files: