Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
CuboidSpawner Class Reference

Class to spawn particles in a cuboid. Implements the interface ParticleSpawner. More...

#include <CuboidSpawner.h>

Inheritance diagram for CuboidSpawner:
Inheritance graph
Collaboration diagram for CuboidSpawner:
Collaboration graph

Public Member Functions

 CuboidSpawner (const std::array< double, 3 > &lower_left_corner, const std::array< int, 3 > &grid_dimensions, double grid_spacing, double mass, const std::array< double, 3 > &initial_velocity, int type, double epsilon=1.0, double sigma=1.2, LockState lock_state=LockState::UNLOCKED, ThirdDimension third_dimension=ThirdDimension::ENABLED, double initial_temperature=0.1)
 Constructor. More...
 
int spawnParticles (std::vector< Particle > &particles) const override
 Spawns particles in the given container. More...
 
size_t getEstimatedNumberOfParticles () const override
 Estimate the number of particles to be spawned. More...
 

Private Attributes

const std::array< double, 3 > lower_left_corner
 Defines the lower left corner where the cuboid will be spawned. More...
 
const std::array< int, 3 > grid_dimensions
 Defines how big the cuboid will be. Each entry defines the number of particles in the respective direction. More...
 
const double grid_spacing
 Defines the spacing between neighboring particles in the cuboid. More...
 
const double mass
 Defines the mass of the particles in the cuboid. More...
 
const int type
 Defines the type of the particles in the cuboid. More...
 
double epsilon
 Defines the Lennard-Jones epsilon parameter of the particles in the cuboid. More...
 
double sigma
 Defines the Lennard-Jones sigma parameter of the particles in the cuboid. More...
 
const LockState lock_state
 Defines whether the particles in the cuboid are locked. More...
 
const std::array< double, 3 > initial_velocity
 Defines the initial velocity of the particles in the cuboid. More...
 
const ThirdDimension third_dimension
 Defines whether to use the third dimension. More...
 
const double initial_temperature
 Defines the initial temperature of the particles in the cuboid. More...
 

Detailed Description

Class to spawn particles in a cuboid. Implements the interface ParticleSpawner.

Implementation of the particle spawning in a cuboid. It is possible to specify the lower left corner of the cuboid, the grid dimensions, the spacing between neighboring particles, the mass of the particles, the initial velocity of the particles and the type of the particles.

Definition at line 15 of file CuboidSpawner.h.

Constructor & Destructor Documentation

◆ CuboidSpawner()

CuboidSpawner::CuboidSpawner ( const std::array< double, 3 > &  lower_left_corner,
const std::array< int, 3 > &  grid_dimensions,
double  grid_spacing,
double  mass,
const std::array< double, 3 > &  initial_velocity,
int  type,
double  epsilon = 1.0,
double  sigma = 1.2,
LockState  lock_state = LockState::UNLOCKED,
ThirdDimension  third_dimension = ThirdDimension::ENABLED,
double  initial_temperature = 0.1 
)

Constructor.

Parameters
lower_left_cornerLower left corner of the cuboid
grid_dimensionsGrid dimensions
grid_spacingSpacing between neighboring particles
massMass of the particles
initial_velocityInitial velocity of the particles, the velocity is then jittered by a Maxwell-Boltzmann distribution
typeType of the particles in the cuboid
epsilonLennard-Jones epsilon parameter of the particles in the cuboid
sigmaLennard-Jones sigma parameter of the particles in the cuboid
lock_stateWhether the particles in the cuboid are locked
third_dimensionWhether to spawn particles in the third dimension
initial_temperatureInitial temperature of the particles

Constructor to initialize the cuboid spawner. The velocity of the particles is jittered by a Maxwell-Boltzmann distribution.

Definition at line 7 of file CuboidSpawner.cpp.

13  mass(mass),
14  type(type),
16  sigma(sigma),
const ThirdDimension third_dimension
Defines whether to use the third dimension.
Definition: CuboidSpawner.h:65
const int type
Defines the type of the particles in the cuboid.
Definition: CuboidSpawner.h:40
double sigma
Defines the Lennard-Jones sigma parameter of the particles in the cuboid.
Definition: CuboidSpawner.h:50
const double initial_temperature
Defines the initial temperature of the particles in the cuboid.
Definition: CuboidSpawner.h:70
const std::array< double, 3 > lower_left_corner
Defines the lower left corner where the cuboid will be spawned.
Definition: CuboidSpawner.h:20
const LockState lock_state
Defines whether the particles in the cuboid are locked.
Definition: CuboidSpawner.h:55
const double mass
Defines the mass of the particles in the cuboid.
Definition: CuboidSpawner.h:35
const std::array< int, 3 > grid_dimensions
Defines how big the cuboid will be. Each entry defines the number of particles in the respective dire...
Definition: CuboidSpawner.h:25
const double grid_spacing
Defines the spacing between neighboring particles in the cuboid.
Definition: CuboidSpawner.h:30
double epsilon
Defines the Lennard-Jones epsilon parameter of the particles in the cuboid.
Definition: CuboidSpawner.h:45
const std::array< double, 3 > initial_velocity
Defines the initial velocity of the particles in the cuboid.
Definition: CuboidSpawner.h:60

Member Function Documentation

◆ getEstimatedNumberOfParticles()

size_t CuboidSpawner::getEstimatedNumberOfParticles ( ) const
overridevirtual

Estimate the number of particles to be spawned.

returns the number of particles to be spawned by this spawner this can be used to reserve enought memory in the particle container

Implements ParticleSpawner.

Definition at line 40 of file CuboidSpawner.cpp.

40  {
41  return static_cast<size_t>(grid_dimensions[0]) * grid_dimensions[1] * grid_dimensions[2];
42 }

◆ spawnParticles()

int CuboidSpawner::spawnParticles ( std::vector< Particle > &  particles) const
overridevirtual

Spawns particles in the given container.

Parameters
particlesA vector of particles to spawn
Returns
Number of particles spawned Spawns particles in the given container.

Implements ParticleSpawner.

Definition at line 22 of file CuboidSpawner.cpp.

22  {
23  particles.reserve(particles.size() + getEstimatedNumberOfParticles());
24  for (int i = 0; i < grid_dimensions[0]; i++) {
25  for (int j = 0; j < grid_dimensions[1]; j++) {
26  for (int k = 0; k < grid_dimensions[2]; k++) {
27  const auto grid_pos = std::array<double, 3>{static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)};
28 
29  const auto x = lower_left_corner + grid_spacing * grid_pos;
30 
33  particles.push_back(particle);
34  }
35  }
36  }
38 }
size_t getEstimatedNumberOfParticles() const override
Estimate the number of particles to be spawned.
Class to represent a particle.
Definition: Particle.h:26
static void setParticleTemperature(double new_temperature, Particle &particle, ThirdDimension third_dimension)
Set the temperature of a particle. This method adds a random velocity to the particle according to th...
Definition: Thermostat.cpp:20

Member Data Documentation

◆ epsilon

double CuboidSpawner::epsilon
private

Defines the Lennard-Jones epsilon parameter of the particles in the cuboid.

Definition at line 45 of file CuboidSpawner.h.

◆ grid_dimensions

const std::array<int, 3> CuboidSpawner::grid_dimensions
private

Defines how big the cuboid will be. Each entry defines the number of particles in the respective direction.

Definition at line 25 of file CuboidSpawner.h.

◆ grid_spacing

const double CuboidSpawner::grid_spacing
private

Defines the spacing between neighboring particles in the cuboid.

Definition at line 30 of file CuboidSpawner.h.

◆ initial_temperature

const double CuboidSpawner::initial_temperature
private

Defines the initial temperature of the particles in the cuboid.

Definition at line 70 of file CuboidSpawner.h.

◆ initial_velocity

const std::array<double, 3> CuboidSpawner::initial_velocity
private

Defines the initial velocity of the particles in the cuboid.

Definition at line 60 of file CuboidSpawner.h.

◆ lock_state

const LockState CuboidSpawner::lock_state
private

Defines whether the particles in the cuboid are locked.

Definition at line 55 of file CuboidSpawner.h.

◆ lower_left_corner

const std::array<double, 3> CuboidSpawner::lower_left_corner
private

Defines the lower left corner where the cuboid will be spawned.

Definition at line 20 of file CuboidSpawner.h.

◆ mass

const double CuboidSpawner::mass
private

Defines the mass of the particles in the cuboid.

Definition at line 35 of file CuboidSpawner.h.

◆ sigma

double CuboidSpawner::sigma
private

Defines the Lennard-Jones sigma parameter of the particles in the cuboid.

Definition at line 50 of file CuboidSpawner.h.

◆ third_dimension

const ThirdDimension CuboidSpawner::third_dimension
private

Defines whether to use the third dimension.

Definition at line 65 of file CuboidSpawner.h.

◆ type

const int CuboidSpawner::type
private

Defines the type of the particles in the cuboid.

Definition at line 40 of file CuboidSpawner.h.


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