ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
coulomb_inline.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "config/config.hpp"
23
26
27#include "Particle.hpp"
28
29#include <utils/Vector.hpp>
30#include <utils/demangle.hpp>
32#include <utils/matrix.hpp>
33
34#include <functional>
35#include <memory>
36#include <optional>
37#include <tuple>
38#include <type_traits>
39#include <variant>
40
41namespace Coulomb {
42
44
46 using result_type = std::optional<kernel_type>;
47
48#ifdef ELECTROSTATICS
49 template <typename T>
50 result_type operator()(std::shared_ptr<T> const &ptr) const {
51 auto const &actor = *ptr;
52 return kernel_type{
53 [&actor](double q1q2, Utils::Vector3d const &d, double dist) {
54 return actor.pair_force(q1q2, d, dist);
55 }};
56 }
57
58#ifdef P3M
59 auto
60 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
61 return std::visit(*this, ptr->base_solver);
62 }
63#endif // P3M
64
65#ifdef MMM1D_GPU
66 result_type operator()(std::shared_ptr<CoulombMMM1DGpu> const &) const {
67 return {};
68 }
69#endif // MMM1D_GPU
70#endif // ELECTROSTATICS
71};
72
74
76 using result_type = std::optional<kernel_type>;
77
78 template <typename T>
79 result_type operator()(std::shared_ptr<T> const &) const {
80 return {};
81 }
82
83#ifdef P3M
85 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
86 auto const &actor = *ptr;
87 return kernel_type{[&actor](Particle &p1, Particle &p2, double q1q2) {
88 actor.add_pair_force_corrections(p1, p2, q1q2);
89 }};
90 }
91#endif // P3M
92};
93
95
97 using result_type = std::optional<kernel_type>;
98
99#ifdef ELECTROSTATICS
100 template <typename T,
101 std::enable_if_t<traits::has_pressure<T>::value> * = nullptr>
102 result_type operator()(std::shared_ptr<T> const &ptr) const {
103 auto const &actor = *ptr;
104 return kernel_type{
105 [&actor](double q1q2, Utils::Vector3d const &d, double dist) {
106 return Utils::tensor_product(actor.pair_force(q1q2, d, dist), d);
107 }};
108 }
109
110 template <typename T,
111 std::enable_if_t<!traits::has_pressure<T>::value> * = nullptr>
112 result_type operator()(std::shared_ptr<T> const &) const {
113 return {};
114 }
115#endif // ELECTROSTATICS
116};
117
119
121 using result_type = std::optional<kernel_type>;
122
123#ifdef ELECTROSTATICS
124 template <typename T>
125 result_type operator()(std::shared_ptr<T> const &ptr) const {
126 auto const &actor = *ptr;
127 return kernel_type{[&actor](Particle const &, Particle const &, double q1q2,
128 Utils::Vector3d const &, double dist) {
129 return actor.pair_energy(q1q2, dist);
130 }};
131 }
132#ifdef P3M
134 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
135 auto const &actor = *ptr;
136 auto const energy_kernel = std::visit(*this, actor.base_solver);
137 return kernel_type{[&actor, energy_kernel](
138 Particle const &p1, Particle const &p2, double q1q2,
139 Utils::Vector3d const &d, double dist) {
140 auto energy = 0.;
141 if (energy_kernel) {
142 energy = (*energy_kernel)(p1, p2, q1q2, d, dist);
143 }
144 return energy + actor.pair_energy_correction(p1, p2, q1q2);
145 }};
146 }
147#endif // P3M
148#ifdef MMM1D_GPU
149 result_type operator()(std::shared_ptr<CoulombMMM1DGpu> const &) const {
150 return {};
151 }
152#endif // MMM1D_GPU
153 result_type operator()(std::shared_ptr<CoulombMMM1D> const &actor) const {
154 return kernel_type{[&actor](Particle const &, Particle const &, double q1q2,
155 Utils::Vector3d const &d, double dist) {
156 return actor->pair_energy(q1q2, d, dist);
157 }};
158 }
159#endif // ELECTROSTATICS
160};
161
162inline std::optional<Solver::ShortRangeForceKernel>
164#ifdef ELECTROSTATICS
165 if (auto &solver = impl->solver; solver.has_value()) {
166 auto const visitor = Coulomb::ShortRangeForceKernel();
167 return std::visit(visitor, *solver);
168 }
169#endif // ELECTROSTATICS
170 return std::nullopt;
171}
172
173inline std::optional<Solver::ShortRangeForceCorrectionsKernel>
175#ifdef ELECTROSTATICS
176 if (auto &solver = impl->solver; solver.has_value()) {
177 auto const visitor = Coulomb::ShortRangeForceCorrectionsKernel();
178 return std::visit(visitor, *solver);
179 }
180#endif // ELECTROSTATICS
181 return std::nullopt;
182}
183
184inline std::optional<Solver::ShortRangePressureKernel>
186#ifdef ELECTROSTATICS
187 if (auto &solver = impl->solver; solver.has_value()) {
188 auto const visitor = Coulomb::ShortRangePressureKernel();
189 return std::visit(visitor, *solver);
190 }
191#endif // ELECTROSTATICS
192 return std::nullopt;
193}
194
195inline std::optional<Solver::ShortRangeEnergyKernel>
197#ifdef ELECTROSTATICS
198 if (auto &solver = impl->solver; solver.has_value()) {
199 auto const visitor = Coulomb::ShortRangeEnergyKernel();
200 return std::visit(visitor, *solver);
201 }
202#endif // ELECTROSTATICS
203 return std::nullopt;
204}
205
206} // namespace Coulomb
Vector implementation and trait types for boost qvm interoperability.
This file contains the defaults for ESPResSo.
Matrix implementation and trait types for boost qvm interoperability.
Matrix< T, N, M > tensor_product(const Vector< T, N > &x, const Vector< T, M > &y)
result_type operator()(std::shared_ptr< T > const &ptr) const
std::optional< kernel_type > result_type
result_type operator()(std::shared_ptr< CoulombMMM1DGpu > const &) const
result_type operator()(std::shared_ptr< ElectrostaticLayerCorrection > const &ptr) const
result_type operator()(std::shared_ptr< CoulombMMM1D > const &actor) const
Solver::ShortRangeEnergyKernel kernel_type
result_type operator()(std::shared_ptr< T > const &) const
Solver::ShortRangeForceCorrectionsKernel kernel_type
std::optional< kernel_type > result_type
result_type operator()(std::shared_ptr< ElectrostaticLayerCorrection > const &ptr) const
result_type operator()(std::shared_ptr< CoulombMMM1DGpu > const &) const
std::optional< kernel_type > result_type
result_type operator()(std::shared_ptr< T > const &ptr) const
auto operator()(std::shared_ptr< ElectrostaticLayerCorrection > const &ptr) const
Solver::ShortRangeForceKernel kernel_type
result_type operator()(std::shared_ptr< T > const &) const
std::optional< kernel_type > result_type
Solver::ShortRangePressureKernel kernel_type
result_type operator()(std::shared_ptr< T > const &ptr) const
std::optional< ShortRangePressureKernel > pair_pressure_kernel() const
std::function< Utils::Matrix< double, 3, 3 >(double, Utils::Vector3d const &, double)> ShortRangePressureKernel
std::function< Utils::Vector3d(double, Utils::Vector3d const &, double)> ShortRangeForceKernel
std::function< double(Particle const &, Particle const &, double, Utils::Vector3d const &, double)> ShortRangeEnergyKernel
std::optional< ShortRangeForceKernel > pair_force_kernel() const
std::function< void(Particle &, Particle &, double)> ShortRangeForceCorrectionsKernel
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
std::optional< ShortRangeEnergyKernel > pair_energy_kernel() const
std::optional< ShortRangeForceCorrectionsKernel > pair_force_elc_kernel() const
Struct holding all information for one particle.
Definition Particle.hpp:393