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>
31#include <utils/matrix.hpp>
32
33#include <functional>
34#include <memory>
35#include <optional>
36#include <tuple>
37#include <variant>
38
39namespace Coulomb {
40
42
44 using result_type = std::optional<kernel_type>;
45
46#ifdef ESPRESSO_ELECTROSTATICS
47 template <typename T>
48 result_type operator()(std::shared_ptr<T> const &ptr) const {
49 auto const &actor = *ptr;
50 return kernel_type{
51 [&actor](double q1q2, Utils::Vector3d const &d, double dist) {
52 return actor.pair_force(q1q2, d, dist);
53 }};
54 }
55#endif // ESPRESSO_ELECTROSTATICS
56};
57
59
61 using result_type = std::optional<kernel_type>;
62
63#ifdef ESPRESSO_ELECTROSTATICS
64 template <typename T>
65 result_type operator()(std::shared_ptr<T> const &) const {
66 return std::nullopt;
67 }
68#endif // ESPRESSO_ELECTROSTATICS
69
70#ifdef ESPRESSO_P3M
72 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
73 auto const &actor = *ptr;
74 return kernel_type{[&actor](Utils::Vector3d const &pos1,
75 Utils::Vector3d const &pos2,
76 Utils::Vector3d &p1f_asym,
77 Utils::Vector3d &p2f_asym, double q1q2) {
78 actor.add_pair_force_corrections(pos1, pos2, p1f_asym, p2f_asym, q1q2);
79 }};
80 }
81#endif // ESPRESSO_P3M
82};
83
85
87 using result_type = std::optional<kernel_type>;
88
89#ifdef ESPRESSO_ELECTROSTATICS
90 template <typename T>
91 result_type operator()(std::shared_ptr<T> const &ptr) const {
92 if constexpr (traits::has_pressure<T>::value) {
93 return kernel_type{
94 [&actor = *ptr](double q1q2, Utils::Vector3d const &d, double dist) {
95 return Utils::tensor_product(actor.pair_force(q1q2, d, dist), d);
96 }};
97 }
98 return std::nullopt;
99 }
100#endif // ESPRESSO_ELECTROSTATICS
101};
102
104
106 using result_type = std::optional<kernel_type>;
107
108#ifdef ESPRESSO_ELECTROSTATICS
109 template <typename T>
110 result_type operator()(std::shared_ptr<T> const &ptr) const {
111 auto const &actor = *ptr;
112 return kernel_type{
113 [&actor](Utils::Vector3d const &, Utils::Vector3d const &, double q1q2,
114 Utils::Vector3d const &,
115 double dist) { return actor.pair_energy(q1q2, dist); }};
116 }
117#ifdef ESPRESSO_P3M
119 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
120 auto const &actor = *ptr;
121 auto const energy_kernel = std::visit(*this, actor.base_solver);
122 return kernel_type{
123 [&actor, energy_kernel](Utils::Vector3d const &pos1,
124 Utils::Vector3d const &pos2, double q1q2,
125 Utils::Vector3d const &d, double dist) {
126 auto energy = 0.;
127 if (energy_kernel) {
128 energy = (*energy_kernel)(pos1, pos2, q1q2, d, dist);
129 }
130 return energy + actor.pair_energy_correction(pos1, pos2, q1q2);
131 }};
132 }
133#endif // ESPRESSO_P3M
134#ifdef ESPRESSO_GSL
135 result_type operator()(std::shared_ptr<CoulombMMM1D> const &actor) const {
136 return kernel_type{
137 [&actor](Utils::Vector3d const &, Utils::Vector3d const &, double q1q2,
138 Utils::Vector3d const &d,
139 double dist) { return actor->pair_energy(q1q2, d, dist); }};
140 }
141#endif // ESPRESSO_GSL
142#endif // ESPRESSO_ELECTROSTATICS
143};
144
145inline std::optional<Solver::ShortRangeForceKernel>
147#ifdef ESPRESSO_ELECTROSTATICS
148 if (auto &solver = impl->solver; solver.has_value()) {
149 auto const visitor = Coulomb::ShortRangeForceKernel();
150 return std::visit(visitor, *solver);
151 }
152#endif // ESPRESSO_ELECTROSTATICS
153 return std::nullopt;
154}
155
156inline std::optional<Solver::ShortRangeForceCorrectionsKernel>
158#ifdef ESPRESSO_ELECTROSTATICS
159 if (auto &solver = impl->solver; solver.has_value()) {
160 auto const visitor = Coulomb::ShortRangeForceCorrectionsKernel();
161 return std::visit(visitor, *solver);
162 }
163#endif // ESPRESSO_ELECTROSTATICS
164 return std::nullopt;
165}
166
167inline std::optional<Solver::ShortRangePressureKernel>
169#ifdef ESPRESSO_ELECTROSTATICS
170 if (auto &solver = impl->solver; solver.has_value()) {
171 auto const visitor = Coulomb::ShortRangePressureKernel();
172 return std::visit(visitor, *solver);
173 }
174#endif // ESPRESSO_ELECTROSTATICS
175 return std::nullopt;
176}
177
178inline std::optional<Solver::ShortRangeEnergyKernel>
180#ifdef ESPRESSO_ELECTROSTATICS
181 if (auto &solver = impl->solver; solver.has_value()) {
182 auto const visitor = Coulomb::ShortRangeEnergyKernel();
183 return std::visit(visitor, *solver);
184 }
185#endif // ESPRESSO_ELECTROSTATICS
186 return std::nullopt;
187}
188
189} // namespace Coulomb
Vector implementation and trait types for boost qvm interoperability.
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
Solver::ShortRangeForceKernel kernel_type
result_type operator()(std::shared_ptr< T > const &ptr) const
std::optional< kernel_type > result_type
Solver::ShortRangePressureKernel kernel_type
std::optional< ShortRangePressureKernel > pair_pressure_kernel() const
std::function< Utils::Matrix< double, 3, 3 >(double, Utils::Vector3d const &, double)> ShortRangePressureKernel
std::function< double(Utils::Vector3d const &, Utils::Vector3d const &, double, Utils::Vector3d const &, double)> ShortRangeEnergyKernel
std::function< Utils::Vector3d(double, Utils::Vector3d const &, double)> ShortRangeForceKernel
std::function< void(Utils::Vector3d const &, Utils::Vector3d const &, Utils::Vector3d &, Utils::Vector3d &, double)> ShortRangeForceCorrectionsKernel
std::optional< ShortRangeForceKernel > pair_force_kernel() const
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
std::optional< ShortRangeEnergyKernel > pair_energy_kernel() const
std::optional< ShortRangeForceCorrectionsKernel > pair_force_elc_kernel() const
The electrostatic method supports pressure calculation.
Definition coulomb.hpp:78