ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
angle_harmonic.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_harmonic.
28 */
29
30#include "angle_common.hpp"
31
32#include <utils/Vector.hpp>
33#include <utils/math/sqr.hpp>
34
35#include <cmath>
36#include <tuple>
37
38/** Parameters for three-body angular potential (harmonic). */
40 /** bending constant */
41 double bend;
42 /** equilibrium angle (default is 180 degrees) */
43 double phi0;
44
45 double cutoff() const { return 0.; }
46
47 static constexpr int num = 2;
48
49 AngleHarmonicBond(double bend, double phi0) {
50 this->bend = bend;
51 this->phi0 = phi0;
52 }
53
54 std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
55 forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
56 double energy(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const;
57};
58
59/** Compute the three-body angle interaction force.
60 * @param[in] vec1 Vector from central particle to left particle.
61 * @param[in] vec2 Vector from central particle to right particle.
62 * @return Forces on the second, first and third particles, in that order.
63 */
64inline std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
66 Utils::Vector3d const &vec2) const {
67
68 auto forceFactor = [this](double const cos_phi) {
69 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
70 auto const phi = acos(cos_phi);
71 return -bend * (phi - phi0) / sin_phi;
72 };
73
74 return angle_generic_force(vec1, vec2, forceFactor, true);
75}
76
77/** Compute the three-body angle interaction energy.
78 * @param[in] vec1 Vector from central particle to left particle.
79 * @param[in] vec2 Vector from central particle to right particle.
80 */
82 Utils::Vector3d const &vec2) const {
83 auto const cos_phi = calc_cosine(vec1, vec2, true);
84 auto const phi = acos(cos_phi);
85 return 0.5 * bend * Utils::sqr(phi - phi0);
86}
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 (harmonic).
double bend
bending constant
AngleHarmonicBond(double bend, double phi0)
static constexpr int num
double cutoff() const
double phi0
equilibrium angle (default is 180 degrees)
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.
double energy(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const
Compute the three-body angle interaction energy.