Molecular Dynamics Simulation  1.0
LennardJonesRepulsiveForce.cpp
Go to the documentation of this file.
2 
3 #include "utils/ArrayUtils.h"
4 
5 std::array<double, 3UL> LennardJonesRepulsiveForce::calculateForce(const Particle& p, const Particle& q) const {
6  const auto displacement = q.getX() - p.getX();
7  const double dist = ArrayUtils::L2Norm(displacement);
8  const double sigma = (p.getSigma() + q.getSigma()) / 2;
9 
10  if (dist > std::pow(2, 1.0 / 6.0) * sigma) return std::array<double, 3UL>{0, 0, 0};
11 
12  const double epsilon = std::sqrt(p.getEpsilon() * q.getEpsilon());
13 
14  const auto f_lennard_jones =
15  (24 * epsilon / (std::pow(dist, 2))) * (std::pow(sigma / dist, 6) - 2 * std::pow(sigma / dist, 12)) * displacement;
16 
17  return f_lennard_jones;
18 };
19 
20 LennardJonesRepulsiveForce::operator std::string() const { return "Lennard-Jones (Repulsive Only)"; };
std::array< double, 3UL > calculateForce(const Particle &p, const Particle &q) const override
Calculates only the repulsive part of 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 L2Norm(const Container &c)
Definition: ArrayUtils.h:174