ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
angle_cosine.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24/** \file
25 * Routines to calculate the angle energy or/and and force
26 * for a particle triple using the potential described in
27 * @ref bondedIA_angle_cosine.
28 */
29
30#include "BoxGeometry.hpp"
31#include "angle_common.hpp"
32
33#include <utils/Vector.hpp>
34#include <utils/math/sqr.hpp>
35
36#include <cmath>
37#include <tuple>
38
39/** Parameters for three-body angular potential (cosine). */
41 /** bending constant */
42 double bend;
43 /** equilibrium angle (default is 180 degrees) */
44 double phi0;
45 /** cosine of @p phi0 (internal parameter) */
46 double cos_phi0;
47 /** sine of @p phi0 (internal parameter) */
48 double sin_phi0;
49
50 double cutoff() const { return 0.; }
51
52 static constexpr int num = 2;
53
54 AngleCosineBond(double bend, double phi0) {
55 this->bend = bend;
56 this->phi0 = phi0;
57 this->cos_phi0 = cos(phi0);
58 this->sin_phi0 = sin(phi0);
59 }
60
61 std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
62 forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
63 double energy(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
64
65private:
66 friend boost::serialization::access;
67 template <typename Archive>
68 void serialize(Archive &ar, long int /* version */) {
69 ar & bend;
70 ar & phi0;
71 ar & cos_phi0;
72 ar & sin_phi0;
73 }
74};
75
76/** Compute the three-body angle interaction force.
77 * @param[in] vec1 Vector from central particle to left particle.
78 * @param[in] vec2 Vector from central particle to right particle.
79 * @return Forces on the second, first and third particles, in that order.
80 */
81inline std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
83 Utils::Vector3d const &vec2) const {
84
85 auto forceFactor = [this](double const cos_phi) {
86 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
87 // angle force term: K(phi) = -k * sin(phi - phi0) / sin(phi)
88 // trig identity: sin(a - b) = sin(a)cos(b) - cos(a)sin(b)
89 return -bend * (sin_phi * cos_phi0 - cos_phi * sin_phi0) / sin_phi;
90 };
91
92 return angle_generic_force(vec1, vec2, forceFactor, false);
93}
94
95/** Computes the three-body angle interaction energy.
96 * @param[in] vec1 Vector from central particle to left particle.
97 * @param[in] vec2 Vector from central particle to right particle.
98 */
99inline double AngleCosineBond::energy(Utils::Vector3d const &vec1,
100 Utils::Vector3d const &vec2) const {
101 auto const cos_phi = calc_cosine(vec1, vec2, true);
102 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
103 // potential: U(phi) = k * [1 - cos(phi - phi0)]
104 // trig identity: cos(phi - phi0) = cos(phi)cos(phi0) + sin(phi)sin(phi0)
105 return bend * (1 - (cos_phi * cos_phi0 + sin_phi * sin_phi0));
106}
Vector implementation and trait types for boost qvm interoperability.
Common code for functions calculating angle forces.
std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > angle_generic_force(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2, ForceFactor forceFactor, bool sanitize_cosine)
Compute a three-body angle interaction force.
double calc_cosine(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2, bool sanitize_cosine=false)
Compute the cosine of the angle between three particles.
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:26
Parameters for three-body angular potential (cosine).
double cutoff() const
double energy(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const
Computes the three-body angle interaction energy.
std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const
Compute the three-body angle interaction force.
AngleCosineBond(double bend, double phi0)
static constexpr int num
double sin_phi0
sine of phi0 (internal parameter)
double phi0
equilibrium angle (default is 180 degrees)
double bend
bending constant
double cos_phi0
cosine of phi0 (internal parameter)