53template <std::
size_t S, std::
size_t m>
57 auto const k2 = k.
norm2();
62 auto constexpr limit = 30.;
65 auto const exponent_prefactor =
Utils::sqr(1. / (2. * alpha));
66 auto const wavevector = (2. * std::numbers::pi) / h;
67 auto const wavevector_i = 1. / wavevector;
72 auto denominator = 0.;
75 m_start, m_stop, indices,
78 auto const km2 = km.norm2();
79 auto const exponent = exponent_prefactor * km2;
80 if (exponent < limit) {
81 auto const f3 = std::exp(-exponent) * (4. * std::numbers::pi / km2);
82 numerator += U2 * f3 * Utils::int_pow<S>(k * km);
86 [&](
unsigned dim,
int n) {
87 km[dim] = k[dim] + n * wavevector[dim];
88 fnm[dim] =
math::sinc(km[dim] * wavevector_i[dim]);
91 return numerator / (Utils::int_pow<S>(k2) *
Utils::sqr(denominator));
113template <
typename FloatType, std::
size_t S, std::
size_t m = 0>
116 Utils::Vector3i const &n_stop,
int const KX,
int const KY,
int const KZ,
119 auto const shifts = detail::calc_meshift(
params.mesh);
120 auto const size = n_stop - n_start;
123 auto g = std::vector<FloatType>(
Utils::product(size), FloatType(0));
131 auto const wavevector = (2. * std::numbers::pi) * inv_box_l;
132 auto const half_mesh =
params.mesh / 2;
134 auto index = std::size_t(0u);
137 if ((indices[KX] % half_mesh[0u] != 0) or
138 (indices[KY] % half_mesh[1u] != 0) or
139 (indices[KZ] % half_mesh[2u] != 0)) {
142 shifts[1u][indices[KY]] * wavevector[1u],
143 shifts[2u][indices[KZ]] * wavevector[2u]}};
Vector implementation and trait types for boost qvm interoperability.
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value)
Create a vector that has all entries set to the same value.
and std::invocable< Projector, unsigned, int > void for_each_3d(detail::IndexVectorConcept auto &&start, detail::IndexVectorConcept auto &&stop, detail::IndexVectorConcept auto &&counters, Kernel &&kernel, Projector &&projector=detail::noop_projector)
Repeat an operation on every element of a 3D grid.
double G_opt(int cao, double alpha, Utils::Vector3d const &k, Utils::Vector3d const &h)
Hockney/Eastwood/Ballenegger optimal influence function.
std::vector< FloatType > grid_influence_function(P3MParameters const ¶ms, Utils::Vector3i const &n_start, Utils::Vector3i const &n_stop, int const KX, int const KY, int const KZ, Utils::Vector3d const &inv_box_l)
Map influence function over a grid.
T product(Vector< T, N > const &v)
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
DEVICE_QUALIFIER auto sinc(T x)
Calculate the function .
Common functions for dipolar and charge P3M.
static SteepestDescentParameters params
Currently active steepest descent instance.
Structure to hold P3M parameters and some dependent variables.