ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
bonded_coulomb.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 bonded Coulomb potential between
26 * particle pairs.
27 */
28
29#include "config/config.hpp"
30
31#include <utils/Vector.hpp>
32
33#include <boost/optional.hpp>
34
35#include <cmath>
36
37/** Parameters for Coulomb bond Potential */
39 /** Coulomb prefactor */
40 double prefactor;
41
42 double cutoff() const { return 0.; }
43
44 static constexpr int num = 1;
45
46 BondedCoulomb(double prefactor) { this->prefactor = prefactor; }
47
48 boost::optional<Utils::Vector3d> force(double q1q2,
49 Utils::Vector3d const &dx) const;
50 boost::optional<double> energy(double q1q2, Utils::Vector3d const &dx) const;
51
52private:
53 friend boost::serialization::access;
54 template <typename Archive>
55 void serialize(Archive &ar, long int /* version */) {
56 ar & prefactor;
57 }
58};
59
60/** Compute the bonded Coulomb pair force.
61 * @param[in] q1q2 Product of the particle charges.
62 * @param[in] dx Distance between the particles.
63 */
64inline boost::optional<Utils::Vector3d>
65BondedCoulomb::force(double const q1q2, Utils::Vector3d const &dx) const {
66#ifdef ELECTROSTATICS
67 auto const dist2 = dx.norm2();
68 auto const dist3 = dist2 * std::sqrt(dist2);
69 auto const fac = prefactor * q1q2 / dist3;
70 return fac * dx;
71#else
72 return Utils::Vector3d{};
73#endif
74}
75
76/** Compute the bonded Coulomb pair energy.
77 * @param[in] q1q2 Product of the particle charges.
78 * @param[in] dx Distance between the particles.
79 */
80inline boost::optional<double>
81BondedCoulomb::energy(double const q1q2, Utils::Vector3d const &dx) const {
82#ifdef ELECTROSTATICS
83 auto const dist = dx.norm();
84 return prefactor * q1q2 / dist;
85#else
86 return .0;
87#endif
88}
Vector implementation and trait types for boost qvm interoperability.
__global__ float * force
T norm2() const
Definition Vector.hpp:130
T norm() const
Definition Vector.hpp:131
This file contains the defaults for ESPResSo.
Parameters for Coulomb bond Potential.
static constexpr int num
boost::optional< double > energy(double q1q2, Utils::Vector3d const &dx) const
Compute the bonded Coulomb pair energy.
double prefactor
Coulomb prefactor.
BondedCoulomb(double prefactor)
double cutoff() const
boost::optional< Utils::Vector3d > force(double q1q2, Utils::Vector3d const &dx) const
Compute the bonded Coulomb pair force.