Molecular Dynamics Simulation  1.0
CuboidSpawner.cpp
Go to the documentation of this file.
1 #include "CuboidSpawner.h"
2 
3 #include "particles/Particle.h"
5 #include "utils/ArrayUtils.h"
6 
7 CuboidSpawner::CuboidSpawner(const std::array<double, 3>& lower_left_corner, const std::array<int, 3>& grid_dimensions, double grid_spacing,
8  double mass, const std::array<double, 3>& initial_velocity, int type, double epsilon, double sigma,
9  LockState lock_state, ThirdDimension third_dimension, double initial_temperature)
10  : lower_left_corner(lower_left_corner),
11  grid_dimensions(grid_dimensions),
12  grid_spacing(grid_spacing),
13  mass(mass),
14  type(type),
15  epsilon(epsilon),
16  sigma(sigma),
17  lock_state(lock_state),
18  initial_velocity(initial_velocity),
19  third_dimension(third_dimension),
20  initial_temperature(initial_temperature) {}
21 
22 int CuboidSpawner::spawnParticles(std::vector<Particle>& particles) const {
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 }
39 
41  return static_cast<size_t>(grid_dimensions[0]) * grid_dimensions[1] * grid_dimensions[2];
42 }
ThirdDimension
Enum class to define the dimension count of the simulation (2D or 3D). Affects primarily the dimensio...
Definition: Enums.h:7
LockState
Enum class to define the lockstate of particles. Locked particles are not allowed to move.
Definition: Enums.h:12
int spawnParticles(std::vector< Particle > &particles) const override
Spawns particles in the given container.
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
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.
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
size_t getEstimatedNumberOfParticles() const override
Estimate the number of particles to be spawned.
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
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