Molecular Dynamics Simulation  1.0
Public Member Functions | List of all members
LennardJonesForce Class Reference

Class to calculate the Lennard-Jones force between particles. Implements the interface PairwiseForceSource. More...

#include <LennardJonesForce.h>

Inheritance diagram for LennardJonesForce:
Inheritance graph
Collaboration diagram for LennardJonesForce:
Collaboration graph

Public Member Functions

std::array< double, 3UL > calculateForce (const Particle &p, const Particle &q) const override
 Calculates the Lennard-Jones forces between two particles. More...
 
 operator std::string () const override
 Returns "Lennard-Jones" as name of the force. More...
 
- Public Member Functions inherited from PairwiseForceSource
virtual ~PairwiseForceSource ()=default
 Virtual destructor for correct cleanup of derived classes. More...
 

Detailed Description

Class to calculate the Lennard-Jones force between particles. Implements the interface PairwiseForceSource.

Implementation of the force calculation to simulate Lennard-Jones forces between particles.

Definition at line 10 of file LennardJonesForce.h.

Member Function Documentation

◆ calculateForce()

std::array< double, 3UL > LennardJonesForce::calculateForce ( const Particle p,
const Particle q 
) const
overridevirtual

Calculates the Lennard-Jones forces between two particles.

Parameters
pParticle
qParticle
Returns
Lennard-Jones force exerted by q on p

Calculates the Lennard-Jones force which q exerts on p

Implements PairwiseForceSource.

Definition at line 5 of file LennardJonesForce.cpp.

5  {
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 };
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

◆ operator std::string()

LennardJonesForce::operator std::string ( ) const
explicitoverridevirtual

Returns "Lennard-Jones" as name of the force.

Implements PairwiseForceSource.

Definition at line 19 of file LennardJonesForce.cpp.

19 { return "Lennard-Jones"; }

The documentation for this class was generated from the following files: