ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
dipoles_inline.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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
27
28#include "Particle.hpp"
29
30#include "actor/traits.hpp"
31#include "actor/visitors.hpp"
32
33#include <utils/Vector.hpp>
35#include <utils/matrix.hpp>
36
37#include <functional>
38#include <optional>
39#include <variant>
40
41namespace Dipoles {
42
44
46 using result_type = std::optional<kernel_type>;
47
48#ifdef ESPRESSO_DIPOLES
49 template <typename T>
50 result_type operator()(std::shared_ptr<T> const &) const {
51 return {};
52 }
53
54#ifdef ESPRESSO_DP3M
55 result_type operator()(std::shared_ptr<DipolarP3M> const &ptr) const {
56 auto const &actor = *ptr;
57 return kernel_type{
58 [&actor](double d1d2, Utils::Vector3d const &dip1,
59 Utils::Vector3d const &dip2,
60#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
62#endif
63 Utils::Vector3d const &d, double dist, double dist2) {
64 return actor.pair_force(d1d2, dip1, dip2,
67#endif
68 d, dist, dist2);
69 }};
70 }
71#endif // ESPRESSO_DP3M
72
74 operator()(std::shared_ptr<DipolarLayerCorrection> const &ptr) const {
75 return std::visit(*this, ptr->base_solver);
76 }
77#endif // ESPRESSO_DIPOLES
78};
79
81
83 using result_type = std::optional<kernel_type>;
84
85#ifdef ESPRESSO_DIPOLES
86 template <typename T>
87 result_type operator()(std::shared_ptr<T> const &) const {
88 return {};
89 }
90
91#ifdef ESPRESSO_DP3M
92 result_type operator()(std::shared_ptr<DipolarP3M> const &ptr) const {
93 auto const &actor = *ptr;
94 return kernel_type{
95 [&actor](Utils::Vector3d const &dip1, Utils::Vector3d const &dip2,
96 Utils::Vector3d const &d, double dist, double dist2) {
97 return actor.pair_energy(dip1, dip2, d, dist, dist2);
98 }};
99 }
100#endif // ESPRESSO_DP3M
101
103 operator()(std::shared_ptr<DipolarLayerCorrection> const &ptr) const {
104 return std::visit(*this, ptr->base_solver);
105 }
106#endif // ESPRESSO_DIPOLES
107};
108
110
112 using result_type = std::optional<kernel_type>;
113
114#ifdef ESPRESSO_DIPOLES
115 template <typename T>
116 result_type operator()(std::shared_ptr<T> const &) const {
117 return {};
118 }
119
120#ifdef ESPRESSO_DP3M
121 result_type operator()(std::shared_ptr<DipolarP3M> const &ptr) const {
122 return kernel_type{
123 [&actor = std::as_const(*ptr)
124#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
125 ,
127#endif
128 ](double d1d2, Utils::Vector3d const &dip1, Utils::Vector3d const &dip2,
129 Utils::Vector3d const &d, double dist, double dist2) mutable {
130 // dipole-dipole force is not central (unlike Coulomb), so the
131 // separation-first convention used elsewhere in the pairwise
132 // pressure kernel (non-bonded, DPD) must be matched explicitly
133 auto const pf = actor.pair_force(d1d2, dip1, dip2,
136#endif
137 d, dist, dist2);
138 return Utils::tensor_product(d, pf.f);
139 }};
140 }
141#endif // ESPRESSO_DP3M
142
144 operator()(std::shared_ptr<DipolarLayerCorrection> const &ptr) const {
145 return std::visit(*this, ptr->base_solver);
146 }
147#endif // ESPRESSO_DIPOLES
148};
149
150inline std::optional<Solver::ShortRangeForceKernel>
152#ifdef ESPRESSO_DIPOLES
153 if (auto &solver = impl->solver; solver.has_value()) {
155 return std::visit(visitor, *solver);
156 }
157#endif // ESPRESSO_DIPOLES
158 return std::nullopt;
159}
160
161inline std::optional<Solver::ShortRangeEnergyKernel>
163#ifdef ESPRESSO_DIPOLES
164 if (auto &solver = impl->solver; solver.has_value()) {
166 return std::visit(visitor, *solver);
167 }
168#endif // ESPRESSO_DIPOLES
169 return std::nullopt;
170}
171
172inline std::optional<Solver::ShortRangePressureKernel>
174#ifdef ESPRESSO_DIPOLES
175 if (auto &solver = impl->solver; solver.has_value()) {
177 return std::visit(visitor, *solver);
178 }
179#endif // ESPRESSO_DIPOLES
180 return std::nullopt;
181}
182
183} // namespace Dipoles
Vector implementation and trait types for boost qvm interoperability.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
P3M algorithm for long-range magnetic dipole-dipole interaction.
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 &) const
std::optional< kernel_type > result_type
result_type operator()(std::shared_ptr< DipolarLayerCorrection > const &ptr) const
Solver::ShortRangeEnergyKernel kernel_type
result_type operator()(std::shared_ptr< DipolarP3M > const &ptr) const
result_type operator()(std::shared_ptr< DipolarLayerCorrection > const &ptr) const
std::optional< kernel_type > result_type
result_type operator()(std::shared_ptr< T > const &) const
Solver::ShortRangeForceKernel kernel_type
result_type operator()(std::shared_ptr< DipolarP3M > const &ptr) const
Solver::ShortRangePressureKernel kernel_type
result_type operator()(std::shared_ptr< DipolarLayerCorrection > const &ptr) const
result_type operator()(std::shared_ptr< T > const &) const
result_type operator()(std::shared_ptr< DipolarP3M > const &ptr) const
std::optional< kernel_type > result_type
std::function< ParticleForce(double, Utils::Vector3d const &, Utils::Vector3d const &, Utils::Vector3d &, Utils::Vector3d &, Utils::Vector3d const &, double, double)> ShortRangeForceKernel
std::optional< ShortRangeForceKernel > pair_force_kernel() const
std::function< double(Utils::Vector3d const &, Utils::Vector3d const &, Utils::Vector3d const &, double, double)> ShortRangeEnergyKernel
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
std::optional< ShortRangePressureKernel > pair_pressure_kernel() const
std::optional< ShortRangeEnergyKernel > pair_energy_kernel() const
std::function< Utils::Matrix< double, 3, 3 >(double, Utils::Vector3d const &, Utils::Vector3d const &, Utils::Vector3d const &, double, double)> ShortRangePressureKernel