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#endif // ELECTROSTATICS
65};
66
68
70 using result_type = std::optional<kernel_type>;
71
72 template <typename T>
73 result_type operator()(std::shared_ptr<T> const &) const {
74 return {};
75 }
76
77#ifdef P3M
79 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
80 auto const &actor = *ptr;
81 return kernel_type{[&actor](Particle &p1, Particle &p2, double q1q2) {
82 actor.add_pair_force_corrections(p1, p2, q1q2);
83 }};
84 }
85#endif // P3M
86};
87
89
91 using result_type = std::optional<kernel_type>;
92
93#ifdef ELECTROSTATICS
94 template <typename T,
95 std::enable_if_t<traits::has_pressure<T>::value> * = nullptr>
96 result_type operator()(std::shared_ptr<T> const &ptr) const {
97 auto const &actor = *ptr;
98 return kernel_type{
99 [&actor](double q1q2, Utils::Vector3d const &d, double dist) {
100 return Utils::tensor_product(actor.pair_force(q1q2, d, dist), d);
101 }};
102 }
103
104 template <typename T,
105 std::enable_if_t<!traits::has_pressure<T>::value> * = nullptr>
106 result_type operator()(std::shared_ptr<T> const &) const {
107 return {};
108 }
109#endif // ELECTROSTATICS
110};
111
113
115 using result_type = std::optional<kernel_type>;
116
117#ifdef ELECTROSTATICS
118 template <typename T>
119 result_type operator()(std::shared_ptr<T> const &ptr) const {
120 auto const &actor = *ptr;
121 return kernel_type{[&actor](Particle const &, Particle const &, double q1q2,
122 Utils::Vector3d const &, double dist) {
123 return actor.pair_energy(q1q2, dist);
124 }};
125 }
126#ifdef P3M
128 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
129 auto const &actor = *ptr;
130 auto const energy_kernel = std::visit(*this, actor.base_solver);
131 return kernel_type{[&actor, energy_kernel](
132 Particle const &p1, Particle const &p2, double q1q2,
133 Utils::Vector3d const &d, double dist) {
134 auto energy = 0.;
135 if (energy_kernel) {
136 energy = (*energy_kernel)(p1, p2, q1q2, d, dist);
137 }
138 return energy + actor.pair_energy_correction(p1, p2, q1q2);
139 }};
140 }
141#endif // P3M
142 result_type operator()(std::shared_ptr<CoulombMMM1D> const &actor) const {
143 return kernel_type{[&actor](Particle const &, Particle const &, double q1q2,
144 Utils::Vector3d const &d, double dist) {
145 return actor->pair_energy(q1q2, d, dist);
146 }};
147 }
148#endif // ELECTROSTATICS
149};
150
151inline std::optional<Solver::ShortRangeForceKernel>
153#ifdef ELECTROSTATICS
154 if (auto &solver = impl->solver; solver.has_value()) {
155 auto const visitor = Coulomb::ShortRangeForceKernel();
156 return std::visit(visitor, *solver);
157 }
158#endif // ELECTROSTATICS
159 return std::nullopt;
160}
161
162inline std::optional<Solver::ShortRangeForceCorrectionsKernel>
164#ifdef ELECTROSTATICS
165 if (auto &solver = impl->solver; solver.has_value()) {
166 auto const visitor = Coulomb::ShortRangeForceCorrectionsKernel();
167 return std::visit(visitor, *solver);
168 }
169#endif // ELECTROSTATICS
170 return std::nullopt;
171}
172
173inline std::optional<Solver::ShortRangePressureKernel>
175#ifdef ELECTROSTATICS
176 if (auto &solver = impl->solver; solver.has_value()) {
177 auto const visitor = Coulomb::ShortRangePressureKernel();
178 return std::visit(visitor, *solver);
179 }
180#endif // ELECTROSTATICS
181 return std::nullopt;
182}
183
184inline std::optional<Solver::ShortRangeEnergyKernel>
186#ifdef ELECTROSTATICS
187 if (auto &solver = impl->solver; solver.has_value()) {
188 auto const visitor = Coulomb::ShortRangeEnergyKernel();
189 return std::visit(visitor, *solver);
190 }
191#endif // ELECTROSTATICS
192 return std::nullopt;
193}
194
195} // 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< 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
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:395