ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
mmm1d.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 * MMM1D algorithm for long-range Coulomb interactions on the CPU.
25 *
26 * Implementation of the MMM1D method for the calculation of the electrostatic
27 * interaction in one-dimensionally periodic systems. For details on the
28 * method see MMM in general. The MMM1D method works only with the N-squared
29 * cell system since neither the near nor far formula can be decomposed.
30 *
31 * MMM1D uses polygamma expansions for the near formula.
32 * The expansion of the polygamma functions is fairly easy and follows
33 * directly from @cite abramowitz65a. For details, see @cite arnold02a.
34 */
35
36#pragma once
37
38#include <config/config.hpp>
39
40#if defined(ESPRESSO_ELECTROSTATICS) and defined(ESPRESSO_GSL)
41
43
44#include "Particle.hpp"
45
46#include <utils/Vector.hpp>
47
48#include <array>
49#include <vector>
50
51/** @brief Parameters for the MMM1D electrostatic interaction */
52struct CoulombMMM1D : public Coulomb::Actor<CoulombMMM1D> {
53 /**
54 * @brief Maximal allowed pairwise error for the potential and force.
55 * This error ignores prefactors, i.e. this is for a pure lattice 1/r-sum.
56 */
57 double maxPWerror;
58 /**
59 * @brief Far switch radius. Represents the xy-distance at which
60 * the calculation switches from the far to the near formula.
61 */
65
66 CoulombMMM1D(double prefactor, double maxPWerror, double switch_rad,
67 int tune_timings, bool tune_verbose);
68
69 /** Compute the pair force.
70 * @param[in] q1q2 Product of the charges on p1 and p2.
71 * @param[in] d Vector pointing from p1 to p2.
72 * @param[in] dist Distance between p1 and p2.
73 */
74 Utils::Vector3d pair_force(double q1q2, Utils::Vector3d const &d,
75 double dist) const;
76
77 /** Compute the pair energy.
78 * @param[in] q1q2 Product of the charges on p1 and p2.
79 * @param[in] d Vector pointing from p1 to p2.
80 * @param[in] dist Distance between p1 and p2.
81 */
82 double pair_energy(double q1q2, Utils::Vector3d const &d, double dist) const;
83
84 void tune();
85 bool is_tuned() const { return m_is_tuned; }
86
89 tune();
90 }
91 /** @brief Recalculate all box-length-dependent parameters. */
92 void on_boxl_change() { recalc_boxl_parameters(); }
93 void on_node_grid_change() const {}
94 void on_periodicity_change() const { sanity_checks_periodicity(); }
95 void on_cell_structure_change() { sanity_checks_cell_structure(); }
96 /** @brief Recalculate all derived parameters. */
97 void init() { recalc_boxl_parameters(); }
98
99 void sanity_checks() const {
100 sanity_checks_periodicity();
101 sanity_checks_cell_structure();
103 }
104
105private:
106 bool m_is_tuned;
107 /** @brief Square of the far switch radius. */
108 double far_switch_radius_sq;
109 /** @brief Squared inverse box length in z-direction. */
110 double uz2;
111 /** @brief Squared inverse box length in z-direction times prefactor. */
112 double prefuz2;
113 /** @brief Cubed inverse box length in z-direction times prefactor. */
114 double prefL3_i;
115 /**
116 * @brief Largest numerically stable cutoff for Bessel function.
117 * Don't change without improving the formulas.
118 */
119 static constexpr auto MAXIMAL_B_CUT = 30;
120 /** @brief From which distance a certain Bessel cutoff is valid. */
121 std::array<double, MAXIMAL_B_CUT> bessel_radii;
122 /** @brief Table of Taylor expansions of the modified polygamma functions. */
123 std::vector<std::vector<double>> modPsi;
124
125 /** @brief Create even and odd polygamma functions up to order `2 * new_n`. */
126 void create_mod_psi_up_to(int new_n);
127 void determine_bessel_radii();
128 void prepare_polygamma_series();
129 void recalc_boxl_parameters();
130 void sanity_checks_periodicity() const;
131 void sanity_checks_cell_structure() const;
132};
133
134#endif // defined(ESPRESSO_ELECTROSTATICS) and defined(ESPRESSO_GSL)
Vector implementation and trait types for boost qvm interoperability.
double prefactor
Electrostatics prefactor.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Parameters for the MMM1D electrostatic interaction.
Definition mmm1d.hpp:52
bool tune_verbose
Definition mmm1d.hpp:64
void on_node_grid_change() const
Definition mmm1d.hpp:93
void sanity_checks() const
Definition mmm1d.hpp:99
double far_switch_radius
Far switch radius.
Definition mmm1d.hpp:62
Utils::Vector3d pair_force(double q1q2, Utils::Vector3d const &d, double dist) const
Compute the pair force.
Definition mmm1d.cpp:187
void on_periodicity_change() const
Definition mmm1d.hpp:94
double pair_energy(double q1q2, Utils::Vector3d const &d, double dist) const
Compute the pair energy.
Definition mmm1d.cpp:274
bool is_tuned() const
Definition mmm1d.hpp:85
void init()
Recalculate all derived parameters.
Definition mmm1d.hpp:97
double maxPWerror
Maximal allowed pairwise error for the potential and force.
Definition mmm1d.hpp:57
int tune_timings
Definition mmm1d.hpp:63
void tune()
Definition mmm1d.cpp:338
void on_cell_structure_change()
Definition mmm1d.hpp:95
void on_boxl_change()
Recalculate all box-length-dependent parameters.
Definition mmm1d.hpp:92
void on_activation()
Definition mmm1d.hpp:87