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

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

#include <SphereSpawner.h>

Inheritance diagram for SphereSpawner:
Inheritance graph
Collaboration diagram for SphereSpawner:
Collaboration graph

Public Member Functions

 SphereSpawner (const std::array< double, 3 > &center, int sphere_radius, 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
 Returns the number of particles to be spawned. More...
 

Private Attributes

const std::array< double, 3 > center
 Defines the center of the sphere. More...
 
const int sphere_radius
 Defines the radius of the sphere. More...
 
const double grid_spacing
 Defines the spacing between neighboring particles in the sphere. More...
 
const double mass
 Defines the mass of the particles in the sphere. More...
 
const int type
 Defines the type of the particles in the sphere. More...
 
const double espilon
 Defines the Lennard-Jones epsilon parameter of the particles in the sphere. More...
 
const double sigma
 Defines the Lennard-Jones sigma parameter of the particles in the sphere. More...
 
const LockState lock_state
 Defines whether the particles in the sphere are locked. More...
 
const std::array< double, 3 > initial_velocity
 Defines the initial velocity of the particles in the sphere. More...
 
const double initial_temperature
 Defines the initial temperature of the particles in the sphere. More...
 
const ThirdDimension third_dimension
 Defines whether to use the third dimension. More...
 

Detailed Description

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

Implementation of the particle spawning in a cuboid. It is possible to specify the center of the sphere, the radius of the sphere, the spacing between neighboring particles, the mass of the particles, the initial velocity of the particles and the type of the particles.

The radius is given in terms of number of particles along the radius.

Definition at line 15 of file SphereSpawner.h.

Constructor & Destructor Documentation

◆ SphereSpawner()

SphereSpawner::SphereSpawner ( const std::array< double, 3 > &  center,
int  sphere_radius,
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
centerCenter of the sphere
sphere_radiusRadius of the sphere [number of particles along the radius]
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_dimensionNumber of dimensions of the sphere
initial_temperatureInital 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 SphereSpawner.cpp.

10  : center(center),
13  mass(mass),
14  type(type),
15  espilon(epsilon),
16  sigma(sigma),
const std::array< double, 3 > center
Defines the center of the sphere.
Definition: SphereSpawner.h:20
const double grid_spacing
Defines the spacing between neighboring particles in the sphere.
Definition: SphereSpawner.h:30
const double initial_temperature
Defines the initial temperature of the particles in the sphere.
Definition: SphereSpawner.h:65
const double espilon
Defines the Lennard-Jones epsilon parameter of the particles in the sphere.
Definition: SphereSpawner.h:45
const std::array< double, 3 > initial_velocity
Defines the initial velocity of the particles in the sphere.
Definition: SphereSpawner.h:60
const int sphere_radius
Defines the radius of the sphere.
Definition: SphereSpawner.h:25
const LockState lock_state
Defines whether the particles in the sphere are locked.
Definition: SphereSpawner.h:55
const double mass
Defines the mass of the particles in the sphere.
Definition: SphereSpawner.h:35
const ThirdDimension third_dimension
Defines whether to use the third dimension.
Definition: SphereSpawner.h:70
const int type
Defines the type of the particles in the sphere.
Definition: SphereSpawner.h:40
const double sigma
Defines the Lennard-Jones sigma parameter of the particles in the sphere.
Definition: SphereSpawner.h:50

Member Function Documentation

◆ getEstimatedNumberOfParticles()

size_t SphereSpawner::getEstimatedNumberOfParticles ( ) const
overridevirtual

Returns the number of particles to be spawned.

Returns
Number of particles to be spawned

Returns the number of particles to be spawned.

Implements ParticleSpawner.

Definition at line 49 of file SphereSpawner.cpp.

49 { return static_cast<size_t>(4.0 / 3.0 * M_PI * std::pow(sphere_radius, 3)); }

◆ spawnParticles()

int SphereSpawner::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 SphereSpawner.cpp.

22  {
23  particles.reserve(particles.size() + getEstimatedNumberOfParticles());
24  int num_particles_spawned = 0;
25  for (int x = -sphere_radius; x <= sphere_radius; x++) {
26  for (int y = -sphere_radius; y <= sphere_radius; y++) {
27  for (int z = -sphere_radius; z <= sphere_radius; z++) {
28  if (third_dimension == ThirdDimension::DISABLED && z != 0) {
29  continue;
30  }
31 
32  const auto displacement = std::array<double, 3>{x * grid_spacing, y * grid_spacing, z * grid_spacing};
33  const double dist = ArrayUtils::L2Norm(displacement);
34 
35  if (dist <= sphere_radius * grid_spacing) {
36  const auto position = center + displacement;
37  Particle particle(position, initial_velocity, mass, type, espilon, sigma, lock_state);
39 
40  particles.push_back(std::move(particle));
41  num_particles_spawned++;
42  }
43  }
44  }
45  }
46  return num_particles_spawned;
47 }
Class to represent a particle.
Definition: Particle.h:26
size_t getEstimatedNumberOfParticles() const override
Returns the number of particles to be spawned.
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
auto L2Norm(const Container &c)
Definition: ArrayUtils.h:174

Member Data Documentation

◆ center

const std::array<double, 3> SphereSpawner::center
private

Defines the center of the sphere.

Definition at line 20 of file SphereSpawner.h.

◆ espilon

const double SphereSpawner::espilon
private

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

Definition at line 45 of file SphereSpawner.h.

◆ grid_spacing

const double SphereSpawner::grid_spacing
private

Defines the spacing between neighboring particles in the sphere.

Definition at line 30 of file SphereSpawner.h.

◆ initial_temperature

const double SphereSpawner::initial_temperature
private

Defines the initial temperature of the particles in the sphere.

Definition at line 65 of file SphereSpawner.h.

◆ initial_velocity

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

Defines the initial velocity of the particles in the sphere.

Definition at line 60 of file SphereSpawner.h.

◆ lock_state

const LockState SphereSpawner::lock_state
private

Defines whether the particles in the sphere are locked.

Definition at line 55 of file SphereSpawner.h.

◆ mass

const double SphereSpawner::mass
private

Defines the mass of the particles in the sphere.

Definition at line 35 of file SphereSpawner.h.

◆ sigma

const double SphereSpawner::sigma
private

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

Definition at line 50 of file SphereSpawner.h.

◆ sphere_radius

const int SphereSpawner::sphere_radius
private

Defines the radius of the sphere.

Definition at line 25 of file SphereSpawner.h.

◆ third_dimension

const ThirdDimension SphereSpawner::third_dimension
private

Defines whether to use the third dimension.

Definition at line 70 of file SphereSpawner.h.

◆ type

const int SphereSpawner::type
private

Defines the type of the particles in the sphere.

Definition at line 40 of file SphereSpawner.h.


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