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 <variant>
39
40namespace Coulomb {
41
43
45 using result_type = std::optional<kernel_type>;
46
47#ifdef ESPRESSO_ELECTROSTATICS
48 template <typename T>
49 result_type operator()(std::shared_ptr<T> const &ptr) const {
50 auto const &actor = *ptr;
51 return kernel_type{
52 [&actor](double q1q2, Utils::Vector3d const &d, double dist) {
53 return actor.pair_force(q1q2, d, dist);
54 }};
55 }
56
57#ifdef ESPRESSO_P3M
58 auto
59 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
60 return std::visit(*this, ptr->base_solver);
61 }
62#endif // ESPRESSO_P3M
63#endif // ESPRESSO_ELECTROSTATICS
64};
65
67
69 using result_type = std::optional<kernel_type>;
70
71 template <typename T>
72 result_type operator()(std::shared_ptr<T> const &) const {
73 return {};
74 }
75
76#ifdef ESPRESSO_P3M
78 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
79 auto const &actor = *ptr;
80 return kernel_type{[&actor](Utils::Vector3d const &pos1,
81 Utils::Vector3d const &pos2,
83 Utils::Vector3d &p2f_asym, double q1q2) {
84 actor.add_pair_force_corrections(pos1, pos2, p1f_asym, p2f_asym, q1q2);
85 }};
86 }
87#endif // ESPRESSO_P3M
88};
89
91
93 using result_type = std::optional<kernel_type>;
94
95#ifdef ESPRESSO_ELECTROSTATICS
96 template <typename T>
97 result_type operator()(std::shared_ptr<T> const &ptr) const {
98 if constexpr (traits::has_pressure<T>::value) {
99 return kernel_type{
100 [&actor = *ptr](double q1q2, Utils::Vector3d const &d, double dist) {
101 return Utils::tensor_product(actor.pair_force(q1q2, d, dist), d);
102 }};
103 }
104 return {};
105 }
106#endif // ESPRESSO_ELECTROSTATICS
107};
108
110
112 using result_type = std::optional<kernel_type>;
113
114#ifdef ESPRESSO_ELECTROSTATICS
115 template <typename T>
116 result_type operator()(std::shared_ptr<T> const &ptr) const {
117 auto const &actor = *ptr;
118 return kernel_type{
119 [&actor](Utils::Vector3d const &, Utils::Vector3d const &, double q1q2,
120 Utils::Vector3d const &,
121 double dist) { return actor.pair_energy(q1q2, dist); }};
122 }
123#ifdef ESPRESSO_P3M
125 operator()(std::shared_ptr<ElectrostaticLayerCorrection> const &ptr) const {
126 auto const &actor = *ptr;
127 auto const energy_kernel = std::visit(*this, actor.base_solver);
128 return kernel_type{
129 [&actor, energy_kernel](Utils::Vector3d const &pos1,
130 Utils::Vector3d const &pos2, double q1q2,
131 Utils::Vector3d const &d, double dist) {
132 auto energy = 0.;
133 if (energy_kernel) {
134 energy = (*energy_kernel)(pos1, pos2, q1q2, d, dist);
135 }
136 return energy + actor.pair_energy_correction(pos1, pos2, q1q2);
137 }};
138 }
139#endif // ESPRESSO_P3M
140#ifdef ESPRESSO_GSL
141 result_type operator()(std::shared_ptr<CoulombMMM1D> const &actor) const {
142 return kernel_type{
143 [&actor](Utils::Vector3d const &, Utils::Vector3d const &, double q1q2,
144 Utils::Vector3d const &d,
145 double dist) { return actor->pair_energy(q1q2, d, dist); }};
146 }
147#endif // ESPRESSO_GSL
148#endif // ESPRESSO_ELECTROSTATICS
149};
150
151inline std::optional<Solver::ShortRangeForceKernel>
153#ifdef ESPRESSO_ELECTROSTATICS
154 if (auto &solver = impl->solver; solver.has_value()) {
156 return std::visit(visitor, *solver);
157 }
158#endif // ESPRESSO_ELECTROSTATICS
159 return std::nullopt;
160}
161
162inline std::optional<Solver::ShortRangeForceCorrectionsKernel>
164#ifdef ESPRESSO_ELECTROSTATICS
165 if (auto &solver = impl->solver; solver.has_value()) {
167 return std::visit(visitor, *solver);
168 }
169#endif // ESPRESSO_ELECTROSTATICS
170 return std::nullopt;
171}
172
173inline std::optional<Solver::ShortRangePressureKernel>
175#ifdef ESPRESSO_ELECTROSTATICS
176 if (auto &solver = impl->solver; solver.has_value()) {
178 return std::visit(visitor, *solver);
179 }
180#endif // ESPRESSO_ELECTROSTATICS
181 return std::nullopt;
182}
183
184inline std::optional<Solver::ShortRangeEnergyKernel>
186#ifdef ESPRESSO_ELECTROSTATICS
187 if (auto &solver = impl->solver; solver.has_value()) {
189 return std::visit(visitor, *solver);
190 }
191#endif // ESPRESSO_ELECTROSTATICS
192 return std::nullopt;
193}
194
195} // namespace Coulomb
Vector implementation and trait types for boost qvm interoperability.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
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 &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