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};
65
66/** Compute the three-body angle interaction force.
67 * @param[in] vec1 Vector from central particle to left particle.
68 * @param[in] vec2 Vector from central particle to right particle.
69 * @return Forces on the second, first and third particles, in that order.
70 */
71inline std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
73 Utils::Vector3d const &vec2) const {
74
75 auto forceFactor = [this](double const cos_phi) {
76 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
77 // angle force term: K(phi) = -k * sin(phi - phi0) / sin(phi)
78 // trig identity: sin(a - b) = sin(a)cos(b) - cos(a)sin(b)
79 return -bend * (sin_phi * cos_phi0 - cos_phi * sin_phi0) / sin_phi;
80 };
81
82 return angle_generic_force(vec1, vec2, forceFactor, false);
83}
84
85/** Computes the three-body angle interaction energy.
86 * @param[in] vec1 Vector from central particle to left particle.
87 * @param[in] vec2 Vector from central particle to right particle.
88 */
89inline double AngleCosineBond::energy(Utils::Vector3d const &vec1,
90 Utils::Vector3d const &vec2) const {
91 auto const cos_phi = calc_cosine(vec1, vec2, true);
92 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
93 // potential: U(phi) = k * [1 - cos(phi - phi0)]
94 // trig identity: cos(phi - phi0) = cos(phi)cos(phi0) + sin(phi)sin(phi0)
95 return bend * (1 - (cos_phi * cos_phi0 + sin_phi * sin_phi0));
96}
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:28
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)