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 <cmath>
34#include <optional>
35
36/** Parameters for Coulomb bond Potential */
38 /** Coulomb prefactor */
39 double prefactor;
40
41 double cutoff() const { return 0.; }
42
43 static constexpr int num = 1;
44
45 BondedCoulomb(double prefactor) { this->prefactor = prefactor; }
46
47 std::optional<Utils::Vector3d> force(double q1q2,
48 Utils::Vector3d const &dx) const;
49 std::optional<double> energy(double q1q2, Utils::Vector3d const &dx) const;
50};
51
52/** Compute the bonded Coulomb pair force.
53 * @param[in] q1q2 Product of the particle charges.
54 * @param[in] dx Distance between the particles.
55 */
56inline std::optional<Utils::Vector3d>
57BondedCoulomb::force(double const q1q2, Utils::Vector3d const &dx) const {
58#ifdef ELECTROSTATICS
59 auto const dist2 = dx.norm2();
60 auto const dist3 = dist2 * std::sqrt(dist2);
61 auto const fac = prefactor * q1q2 / dist3;
62 return fac * dx;
63#else
64 return Utils::Vector3d{};
65#endif
66}
67
68/** Compute the bonded Coulomb pair energy.
69 * @param[in] q1q2 Product of the particle charges.
70 * @param[in] dx Distance between the particles.
71 */
72inline std::optional<double>
73BondedCoulomb::energy(double const q1q2, Utils::Vector3d const &dx) const {
74#ifdef ELECTROSTATICS
75 auto const dist = dx.norm();
76 return prefactor * q1q2 / dist;
77#else
78 return .0;
79#endif
80}
Vector implementation and trait types for boost qvm interoperability.
T norm2() const
Definition Vector.hpp:137
T norm() const
Definition Vector.hpp:138
This file contains the defaults for ESPResSo.
Parameters for Coulomb bond Potential.
static constexpr int num
std::optional< Utils::Vector3d > force(double q1q2, Utils::Vector3d const &dx) const
Compute the bonded Coulomb pair force.
std::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