Molecular Dynamics Simulation  1.0
SmoothedLennardJonesForce.cpp
Go to the documentation of this file.
2 
4 #include "utils/ArrayUtils.h"
5 
6 std::array<double, 3UL> SmoothedLennardJonesForce::calculateForce(const Particle& p, const Particle& q) const {
7  const auto displacement = q.getX() - p.getX();
8  const double dist = ArrayUtils::L2Norm(displacement);
9 
10  if (dist <= r_l) {
11  static LennardJonesForce lennard_jones_force;
12  return lennard_jones_force.calculateForce(p, q);
13  } else if (dist <= r_c) {
14  const double sigma = (p.getSigma() + q.getSigma()) / 2;
15  const double epsilon = std::sqrt(p.getEpsilon() * q.getEpsilon());
16 
17  const double sigma_pow_6 = std::pow(sigma, 6);
18  const double dist_pow_6 = std::pow(dist, 6);
19 
20  const auto f_smoothed_lennard_jones =
21  (-24 * sigma_pow_6 * epsilon) / (std::pow(dist, 14) * std::pow(r_c - r_l, 3)) * (r_c - dist) *
22  (r_c * r_c * (2 * sigma_pow_6 - dist_pow_6) + r_c * (3 * r_l - dist) * (dist_pow_6 - 2 * sigma_pow_6) +
23  dist * (5 * r_l * sigma_pow_6 - 2 * r_l * dist_pow_6 - 3 * sigma_pow_6 * dist + std::pow(dist, 7))) *
24  displacement;
25 
26  return f_smoothed_lennard_jones;
27  } else {
28  return {0, 0, 0};
29  }
30 };
31 
32 SmoothedLennardJonesForce::operator std::string() const { return "SmoothedLennardJones"; };
Class to calculate the Lennard-Jones force between particles. Implements the interface PairwiseForceS...
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
double r_c
the radius after which the force is 0
std::array< double, 3UL > calculateForce(const Particle &p, const Particle &q) const override
Calculates the smoothed Lennard-Jones forces between two particles.
double r_l
the radius whithin the normal Lennard-Jones force is applied. Between r_l and r_c the force is smooth...
auto L2Norm(const Container &c)
Definition: ArrayUtils.h:174