AutoPas  3.0.0
Loading...
Searching...
No Matches
LJPotential.h
Go to the documentation of this file.
1
9#pragma once
11
21constexpr double calculateLJPotential(const std::array<double, 3> &posI, const std::array<double, 3> &posJ,
22 double cutoff, double sigma, double epsilon) {
23 using namespace autopas::utils::ArrayMath::literals;
24
25 // the vector from particle j to i
26 const auto posIMinusPosJ = posI - posJ;
27
28 // the distance between both particles
29 const auto dist =
30 autopas::utils::ConstexprMath::sqrt(autopas::utils::ArrayMath::dot(posIMinusPosJ, posIMinusPosJ), 1e-16);
31
32 // if the distance between the two particles is larger then cutoff, we don't
33 // consider this interaction
34 if (dist > cutoff) {
35 return 0;
36 }
37
38 // (sigma / dist)
39 const auto sdr = sigma / dist;
40 // (sigma / dist)^6
41 const auto lj6 = sdr * sdr * sdr * sdr * sdr * sdr;
42 // (sigma / dist)^12
43 const auto lj12 = lj6 * lj6;
44 // the lennard jones potential
45 const auto potentialEnergy = 4.0 * epsilon * (lj12 - lj6);
46
47 return potentialEnergy;
48}
49
59constexpr std::array<double, 3> calculateLJForce(const std::array<double, 3> &posI, const std::array<double, 3> &posJ,
60 double cutoff, double sigma, double epsilon) {
61 using namespace autopas::utils::ArrayMath::literals;
62
63 // the vector from particle j to i
64 const auto posIMinusPosJ = posI - posJ;
65
66 // the distance between both particles
67 const auto dist =
68 autopas::utils::ConstexprMath::sqrt(autopas::utils::ArrayMath::dot(posIMinusPosJ, posIMinusPosJ), 1e-16);
69
70 // if the distance between the two prticles is larger thn cutoff, we don't
71 // consider this interaction
72 if (dist > cutoff) {
73 return {0, 0, 0};
74 }
75
76 // r^6
77 const auto r6 = dist * dist * dist * dist * dist * dist;
78 // sigma^6
79 const auto sigma6 = sigma * sigma * sigma * sigma * sigma * sigma;
80 // sigma^6 / r^7
81 const auto dlj6 = sigma6 / (r6 * dist);
82 // sigma^12 / r^13
83 const auto dlj12 = (sigma6 * sigma6) / (r6 * r6 * dist);
84 // the derivative with respect to r of the lennard jones potential
85 const auto dUr = 48. * epsilon * (dlj12 - 0.5 * dlj6);
86
87 // the forces in x, y and z direction
88 const auto fx = (posIMinusPosJ[0] / dist) * dUr;
89 const auto fy = (posIMinusPosJ[1] / dist) * dUr;
90 const auto fz = (posIMinusPosJ[2] / dist) * dUr;
91
92 const auto force = std::array<double, 3>{fx, fy, fz};
93
94 return force;
95}
96
106constexpr std::array<double, 3> calculateLJVirial(const std::array<double, 3> &posI, const std::array<double, 3> &posJ,
107 double cutoff, double sigma, double epsilon) {
108 using namespace autopas::utils::ArrayMath::literals;
109
110 // first we need the forces
111 const auto force = calculateLJForce(posI, posJ, cutoff, sigma, epsilon);
112 // the vector from particle j to i
113 const auto posIMinusPosJ = posI - posJ;
114 const auto virial =
115 std::array<double, 3>{posIMinusPosJ[0] * force[0], posIMinusPosJ[1] * force[1], posIMinusPosJ[2] * force[2]};
116 return virial;
117}
118
128constexpr double calculateLJVirialTotal(const std::array<double, 3> &posI, const std::array<double, 3> &posJ,
129 double cutoff, double sigma, double epsilon) {
130 const auto virial = calculateLJVirial(posI, posJ, cutoff, sigma, epsilon);
131 return virial[0] + virial[1] + virial[2];
132}
constexpr double calculateLJPotential(const std::array< double, 3 > &posI, const std::array< double, 3 > &posJ, double cutoff, double sigma, double epsilon)
Calculates the potential energy between particle i and j using the Lennard Jones 12-6 potential.
Definition: LJPotential.h:21
constexpr std::array< double, 3 > calculateLJVirial(const std::array< double, 3 > &posI, const std::array< double, 3 > &posJ, double cutoff, double sigma, double epsilon)
Calculates the virial between particle i and j using the Lennard Jones 12-6 potential.
Definition: LJPotential.h:106
constexpr double calculateLJVirialTotal(const std::array< double, 3 > &posI, const std::array< double, 3 > &posJ, double cutoff, double sigma, double epsilon)
Calculates the sum of all components of the virial between particle i and j using the Lennard Jones 1...
Definition: LJPotential.h:128
constexpr std::array< double, 3 > calculateLJForce(const std::array< double, 3 > &posI, const std::array< double, 3 > &posJ, double cutoff, double sigma, double epsilon)
Calculates the force exerted by particle j on particle i using the 12-6 potential of Lennard Jones.
Definition: LJPotential.h:59
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233