Molecular Dynamics Simulation  1.0
Functions
MaxwellBoltzmannDistribution.h File Reference
#include <array>
#include <random>
Include dependency graph for MaxwellBoltzmannDistribution.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::array< double, 3 > maxwellBoltzmannDistributedVelocity (double averageVelocity, size_t dimensions)
 

Function Documentation

◆ maxwellBoltzmannDistributedVelocity()

std::array<double, 3> maxwellBoltzmannDistributedVelocity ( double  averageVelocity,
size_t  dimensions 
)

MaxwellBoltzmannDistribution.h

Date
: 13.12.2019
Author
: F. Gratl Generate a random velocity vector according to the Maxwell-Boltzmann distribution, with a given average velocity.
Parameters
averageVelocityThe average velocity of the brownian motion for the system.
dimensionsNumber of dimensions for which the velocity vector shall be generated. Set this to 2 or 3.
Returns
Array containing the generated velocity vector.

Definition at line 3 of file MaxwellBoltzmannDistribution.cpp.

3  {
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 > averageVelocity(const std::unique_ptr< ParticleContainer > &particle_container)