ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
fene.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 FENE potential between particle pairs.
26 */
27
28#include "config/config.hpp"
29#include "errorhandling.hpp"
30
31#include <utils/Vector.hpp>
32#include <utils/math/sqr.hpp>
33
34#include <boost/optional.hpp>
35
36#include <cmath>
37
38/** Parameters for FENE bond Potential. */
39struct FeneBond {
40 /** spring constant */
41 double k;
42 /** maximal bond stretching */
43 double drmax;
44 /** equilibrium bond length */
45 double r0;
46 /** square of @p drmax (internal parameter) */
47 double drmax2;
48 /** inverse square of @p drmax (internal parameter) */
49 double drmax2i;
50
51 double cutoff() const { return r0 + drmax; }
52
53 static constexpr int num = 1;
54
55 FeneBond(double k, double drmax, double r0) {
56 this->k = k;
57 this->drmax = drmax;
58 this->r0 = r0;
59
60 this->drmax2 = Utils::sqr(this->drmax);
61 this->drmax2i = 1. / this->drmax2;
62 }
63
64 boost::optional<Utils::Vector3d> force(Utils::Vector3d const &dx) const;
65 boost::optional<double> energy(Utils::Vector3d const &dx) const;
66
67private:
68 friend boost::serialization::access;
69 template <typename Archive>
70 void serialize(Archive &ar, long int /* version */) {
71 ar & k;
72 ar & drmax;
73 ar & r0;
74 ar & drmax2;
75 ar & drmax2i;
76 }
77};
78
79/** Compute the FENE bond force.
80 * @param[in] dx Distance between the particles.
81 */
82inline boost::optional<Utils::Vector3d>
84 auto const len = dx.norm();
85 auto const dr = len - r0;
86
87 if (dr >= drmax) {
88 return {};
89 }
90
91 auto fac = -k * dr / (1.0 - dr * dr * drmax2i);
92 if (len > ROUND_ERROR_PREC) {
93 fac /= len;
94 } else {
95 if (r0 > 0.) {
96 runtimeErrorMsg() << "FENE bond: Particles have zero distance. "
97 "This is most likely an error in the system setup.";
98 }
99 }
100
101 return fac * dx;
102}
103
104/** Compute the FENE bond energy.
105 * @param[in] dx Distance between the particles.
106 */
107inline boost::optional<double>
109 /* compute bond stretching (r-r0) */
110 double const dr = dx.norm() - r0;
111
112 /* check bond stretching */
113 if (dr >= drmax) {
114 return {};
115 }
116
117 return -0.5 * k * drmax2 * log(1.0 - dr * dr * drmax2i);
118}
Vector implementation and trait types for boost qvm interoperability.
__global__ float * force
float dr[3]
T norm() const
Definition Vector.hpp:131
This file contains the defaults for ESPResSo.
#define ROUND_ERROR_PREC
Precision for capture of round off errors.
Definition config.hpp:66
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:26
Parameters for FENE bond Potential.
Definition fene.hpp:39
double drmax2i
inverse square of drmax (internal parameter)
Definition fene.hpp:49
double drmax
maximal bond stretching
Definition fene.hpp:43
boost::optional< double > energy(Utils::Vector3d const &dx) const
Compute the FENE bond energy.
Definition fene.hpp:108
FeneBond(double k, double drmax, double r0)
Definition fene.hpp:55
double drmax2
square of drmax (internal parameter)
Definition fene.hpp:47
double cutoff() const
Definition fene.hpp:51
static constexpr int num
Definition fene.hpp:53
double r0
equilibrium bond length
Definition fene.hpp:45
double k
spring constant
Definition fene.hpp:41
boost::optional< Utils::Vector3d > force(Utils::Vector3d const &dx) const
Compute the FENE bond force.
Definition fene.hpp:83