19#ifndef ESPRESSO_P3M_INFLUENCE_FUNCTION_HPP
20#define ESPRESSO_P3M_INFLUENCE_FUNCTION_HPP
31#include <boost/range/numeric.hpp>
54template <std::
size_t S, std::
size_t m>
57 using namespace detail::FFT_indexing;
62 auto constexpr two_pi_i = 1. / two_pi;
63 auto constexpr limit = 30.;
65 auto const k2 = k.
norm2();
70 double numerator = 0.0;
71 double denominator = 0.0;
73 for (
int mx = -m; mx <= m; mx++) {
74 for (
int my = -m; my <= m; my++) {
75 for (
int mz = -m; mz <= m; mz++) {
78 auto const U2 = std::pow(sinc(km[RX] *
h[RX] * two_pi_i) *
79 sinc(km[RY] *
h[RY] * two_pi_i) *
80 sinc(km[RZ] *
h[RZ] * two_pi_i),
83 auto const km2 = km.norm2();
84 auto const exponent =
Utils::sqr(1. / (2. * alpha)) * km2;
85 if (exponent < limit) {
86 auto const f3 = std::exp(-exponent) * (4. *
Utils::pi() / km2);
87 numerator += U2 * f3 * int_pow<S>(k * km);
94 return numerator / (int_pow<S>(k2) *
Utils::sqr(denominator));
113template <std::
size_t S, std::
size_t m = 0>
118 using namespace detail::FFT_indexing;
120 auto const shifts = detail::calc_meshift(
params.mesh);
122 auto const size = n_end - n_start;
126 std::vector<double>(boost::accumulate(size, 1, std::multiplies<>()), 0.);
137 for (n[0] = n_start[0]; n[0] < n_end[0]; n[0]++) {
138 for (n[1] = n_start[1]; n[1] < n_end[1]; n[1]++) {
139 for (n[2] = n_start[2]; n[2] < n_end[2]; n[2]++) {
142 if ((n[KX] % (
params.mesh[RX] / 2) == 0) &&
143 (n[KY] % (
params.mesh[RY] / 2) == 0) &&
144 (n[KZ] % (
params.mesh[RZ] / 2) == 0)) {
149 shifts[RY][n[KY]] / box_l[RY],
150 shifts[RZ][n[KZ]] / box_l[RZ]};
Vector implementation and trait types for boost qvm interoperability.
Common functions for dipolar and charge P3M.
double G_opt(int cao, double alpha, Utils::Vector3d const &k, Utils::Vector3d const &h)
Hockney/Eastwood/Ballenegger optimal influence function.
std::vector< double > grid_influence_function(const P3MParameters ¶ms, const Utils::Vector3i &n_start, const Utils::Vector3i &n_end, const Utils::Vector3d &box_l)
Map influence function over a grid.
DEVICE_QUALIFIER constexpr T pi()
Ratio of diameter and circumference of a circle.
int get_linear_index(int a, int b, int c, const Vector3i &adim, MemoryOrder memory_order=MemoryOrder::COLUMN_MAJOR)
get the linear index from the position (a,b,c) in a 3D grid of dimensions adim.
DEVICE_QUALIFIER T sinc(T d)
Calculates the sinc-function as sin(PI*x)/(PI*x).
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
DEVICE_QUALIFIER constexpr T int_pow(T x)
Calculate integer powers.
static SteepestDescentParameters params
Currently active steepest descent instance.
Structure to hold P3M parameters and some dependent variables.