Molecular Dynamics Simulation  1.0
MaxwellBoltzmannDistribution.cpp
Go to the documentation of this file.
2 
3 std::array<double, 3> maxwellBoltzmannDistributedVelocity(double averageVelocity, size_t dimensions) {
4  // we use a constant seed for repeatability.
5  // random engine needs static lifetime otherwise it would be recreated for every call.
6  static std::default_random_engine random_engine(10242);
7 
8  // when adding independent normally distributed values to all velocity components
9  // the velocity change is maxwell boltzmann distributed
10  std::normal_distribution<double> normal_distribution{0, 1};
11  std::array<double, 3> random_velocity{};
12  for (size_t i = 0; i < dimensions; ++i) {
13  random_velocity[i] = averageVelocity * normal_distribution(random_engine);
14  }
15  return random_velocity;
16 }
std::array< double, 3 > maxwellBoltzmannDistributedVelocity(double averageVelocity, size_t dimensions)
std::array< double, 3 > averageVelocity(const std::unique_ptr< ParticleContainer > &particle_container)