ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
reaction_field.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/**
23 * @file
24 * Calculate the Reaction Field energy and force
25 * for a particle pair @cite neumann85b, @cite tironi95a.
26 */
27
28#pragma once
29
30#include "config/config.hpp"
31
32#ifdef ELECTROSTATICS
33
35
36#include "Particle.hpp"
37
38#include <utils/Vector.hpp>
40
41#include <stdexcept>
42
43/** @brief Reaction Field parameters. */
44struct ReactionField : public Coulomb::Actor<ReactionField> {
45 /** @brief Ionic strength. */
46 double kappa;
47 /** @brief Continuum dielectric constant inside the cavity. */
48 double epsilon1;
49 /** @brief Continuum dielectric constant outside the cavity. */
50 double epsilon2;
51 /** @brief Interaction cutoff. */
52 double r_cut;
53 /** @brief Interaction prefactor. Corresponds to the quantity
54 * @f$ 1 + B_1 @f$ from eq. 22 in @cite tironi95a.
55 */
56 double B;
57 ReactionField(double prefactor, double kappa, double epsilon1,
58 double epsilon2, double r_cut) {
59 if (kappa < 0.0) {
60 throw std::domain_error("Parameter 'kappa' must be >= 0");
61 }
62 if (epsilon1 < 0.0) {
63 throw std::domain_error("Parameter 'epsilon1' must be >= 0");
64 }
65 if (epsilon2 < 0.0) {
66 throw std::domain_error("Parameter 'epsilon2' must be >= 0");
67 }
68 if (r_cut < 0.0) {
69 throw std::domain_error("Parameter 'r_cut' must be >= 0");
70 }
71
73 this->kappa = kappa;
74 this->epsilon1 = epsilon1;
75 this->epsilon2 = epsilon2;
76 this->r_cut = r_cut;
77 B = (2. * (epsilon1 - epsilon2) * (1. + kappa * r_cut) -
78 epsilon2 * kappa * kappa * r_cut * r_cut) /
79 ((epsilon1 + 2. * epsilon2) * (1. + kappa * r_cut) +
81 }
82
83 void on_activation() const { sanity_checks(); }
84 void on_boxl_change() const {}
85 void on_node_grid_change() const {}
86 void on_periodicity_change() const {}
88 void init() const {}
89
91
92 /** @brief Compute the Reaction Field pair force.
93 * @param[in] q1q2 Product of the charges on p1 and p2.
94 * @param[in] d Vector pointing from p1 to p2.
95 * @param[in] dist Distance between p1 and p2.
96 */
97 Utils::Vector3d pair_force(double const q1q2, Utils::Vector3d const &d,
98 double const dist) const {
99 if (dist >= r_cut) {
100 return {};
101 }
102 auto fac = 1. / Utils::int_pow<3>(dist) + B / Utils::int_pow<3>(r_cut);
103 return (prefactor * q1q2 * fac) * d;
104 }
105
106 /** @brief Compute the Reaction Field pair energy.
107 * @param q1q2 Product of the charges on p1 and p2.
108 * @param dist Distance between p1 and p2.
109 */
110 double pair_energy(double const q1q2, double const dist) const {
111 if (dist >= r_cut) {
112 return 0.;
113 }
114 auto fac = 1. / dist - (B * dist * dist) / (2. * Utils::int_pow<3>(r_cut));
115 // remove discontinuity at dist = r_cut
116 fac -= (1. - B / 2.) / r_cut;
117 return prefactor * q1q2 * fac;
118 }
119};
120
121#endif // ELECTROSTATICS
Vector implementation and trait types for boost qvm interoperability.
void set_prefactor(double new_prefactor)
double prefactor
Electrostatics prefactor.
This file contains the defaults for ESPResSo.
Reaction Field parameters.
void on_cell_structure_change() const
double epsilon1
Continuum dielectric constant inside the cavity.
void on_node_grid_change() const
double kappa
Ionic strength.
double r_cut
Interaction cutoff.
ReactionField(double prefactor, double kappa, double epsilon1, double epsilon2, double r_cut)
void on_activation() const
void init() const
Utils::Vector3d pair_force(double const q1q2, Utils::Vector3d const &d, double const dist) const
Compute the Reaction Field pair force.
void sanity_checks() const
double B
Interaction prefactor.
void on_periodicity_change() const
double pair_energy(double const q1q2, double const dist) const
Compute the Reaction Field pair energy.
double epsilon2
Continuum dielectric constant outside the cavity.
void on_boxl_change() const