Molecular Dynamics Simulation  1.0
LennardJonesForce.cpp
Go to the documentation of this file.
1 #include "LennardJonesForce.h"
2 
3 #include "utils/ArrayUtils.h"
4 
5 std::array<double, 3UL> LennardJonesForce::calculateForce(const Particle& p, const Particle& q) const {
6  const auto displacement = q.getX() - p.getX();
7  const double distSq = ArrayUtils::L2NormSquared(displacement);
8 
9  const double sigma = (p.getSigma() + q.getSigma()) / 2;
10  const double epsilon = std::sqrt(p.getEpsilon() * q.getEpsilon());
11 
12  const double sigma_dist_pow_6 = std::pow(sigma * sigma / distSq, 3);
13 
14  const auto f_lennard_jones = (24 * epsilon / distSq) * (sigma_dist_pow_6 * (1 - 2 * sigma_dist_pow_6)) * displacement;
15 
16  return f_lennard_jones;
17 };
18 
19 LennardJonesForce::operator std::string() const { return "Lennard-Jones"; };
std::array< double, 3UL > calculateForce(const Particle &p, const Particle &q) const override
Calculates the Lennard-Jones forces between two particles.
Class to represent a particle.
Definition: Particle.h:26
double getSigma() const
Gets the Lennard-Jones potential parameter sigma.
Definition: Particle.h:192
const std::array< double, 3 > & getX() const
Gets the position of the particle.
Definition: Particle.h:157
double getEpsilon() const
Gets the Lennard-Jones potential parameter epsilon.
Definition: Particle.h:187
auto L2NormSquared(const Container &c)
Definition: ArrayUtils.h:194