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
58private:
59 friend boost::serialization::access;
60 template <typename Archive>
61 void serialize(Archive &ar, long int /* version */) {
62 ar & bend;
63 ar & phi0;
64 }
65};
66
67/** Compute the three-body angle interaction force.
68 * @param[in] vec1 Vector from central particle to left particle.
69 * @param[in] vec2 Vector from central particle to right particle.
70 * @return Forces on the second, first and third particles, in that order.
71 */
72inline std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
74 Utils::Vector3d const &vec2) const {
75
76 auto forceFactor = [this](double const cos_phi) {
77 auto const sin_phi = sqrt(1 - Utils::sqr(cos_phi));
78 auto const phi = acos(cos_phi);
79 return -bend * (phi - phi0) / sin_phi;
80 };
81
82 return angle_generic_force(vec1, vec2, forceFactor, true);
83}
84
85/** Compute 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 */
90 Utils::Vector3d const &vec2) const {
91 auto const cos_phi = calc_cosine(vec1, vec2, true);
92 auto const phi = acos(cos_phi);
93 return 0.5 * bend * Utils::sqr(phi - phi0);
94}
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 (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.