ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
dipolar_direct_sum_kernels.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <config/config.hpp>
25
26#ifdef ESPRESSO_DIPOLES
27
28#include <utils/Vector.hpp>
29
30#include <cmath>
31
32/** @brief Force and torque of one pair interaction. */
33struct PairForce {
37 f += o.f;
38 torque += o.torque;
39 return *this;
40 }
41};
42
43/** @brief Pair force of two interacting dipoles (see dipolar_direct_sum.cpp).
44 */
46 Utils::Vector3d const &m2) {
47 auto const pe2 = m1 * d;
48 auto const pe3 = m2 * d;
49
50 auto const r2 = d.norm2();
51 auto const r = std::sqrt(r2);
52 auto const r5 = r2 * r2 * r;
53 auto const r7 = r5 * r2;
54
55 auto const a = 3.0 * (m1 * m2) / r5;
56 auto const b = -15.0 * pe2 * pe3 / r7;
57
58 auto const f = (a + b) * d + 3.0 * (pe3 * m1 + pe2 * m2) / r5;
59 auto const r3 = r2 * r;
60 auto const t =
61 -vector_product(m1, m2) / r3 + 3.0 * pe3 * vector_product(m1, d) / r5;
62
63 return PairForce{f, t};
64}
65
66/** @brief Pair potential for two interacting dipoles. */
67inline double pair_potential(Utils::Vector3d const &d,
68 Utils::Vector3d const &m1,
69 Utils::Vector3d const &m2) {
70 auto const r2 = d * d;
71 auto const r = std::sqrt(r2);
72 auto const r3 = r2 * r;
73 auto const r5 = r3 * r2;
74
75 auto const pe1 = m1 * m2;
76 auto const pe2 = m1 * d;
77 auto const pe3 = m2 * d;
78
79 return pe1 / r3 - 3.0 * pe2 * pe3 / r5;
80}
81
82#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
83/** @brief Dipole field contribution from a dipole @c m1 at distance @c d. */
85 Utils::Vector3d const &m1) {
86 auto const r2 = d * d;
87 auto const r = std::sqrt(r2);
88 auto const r3 = r2 * r;
89 auto const r5 = r3 * r2;
90 auto const pe2 = m1 * d;
91
92 return 3.0 * pe2 * d / r5 - m1 / r3;
93}
94#endif // ESPRESSO_DIPOLE_FIELD_TRACKING
95
96#endif // ESPRESSO_DIPOLES
Vector implementation and trait types for boost qvm interoperability.
constexpr T norm2() const
Definition Vector.hpp:159
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
__device__ void vector_product(float const *a, float const *b, float *out)
Utils::Vector3d dipole_field(Utils::Vector3d const &d, Utils::Vector3d const &m1)
Dipole field contribution from a dipole m1 at distance d.
PairForce pair_force(Utils::Vector3d const &d, Utils::Vector3d const &m1, Utils::Vector3d const &m2)
Pair force of two interacting dipoles (see dipolar_direct_sum.cpp).
double pair_potential(Utils::Vector3d const &d, Utils::Vector3d const &m1, Utils::Vector3d const &m2)
Pair potential for two interacting dipoles.
Force and torque of one pair interaction.
PairForce & operator+=(PairForce const &o)