77template <std::
size_t S, std::
size_t m>
80 auto const k2 = k.
norm2();
85 auto constexpr exp_limit = 30.;
88 auto const cao =
params.cao;
90 auto const wavevector = (2. * std::numbers::pi) /
params.a;
91 auto const wavevector_i = 1. / wavevector;
96 auto denominator = 0.;
99 m_start, m_stop, indices,
102 auto const km2 = km.norm2();
103 auto const exp_term = exponent_prefactor * km2;
104 if (exp_term < exp_limit) {
105 auto const f3 = std::exp(-exp_term) * (4. * std::numbers::pi / km2);
106 numerator += U2 * f3 * Utils::int_pow<S>(k * km);
110 [&](
unsigned dim,
int n) {
111 km[dim] = k[dim] + n * wavevector[dim];
112 fnm[dim] =
math::sinc(km[dim] * wavevector_i[dim]);
115 return numerator / (Utils::int_pow<S>(k2) *
Utils::sqr(denominator));
136template <
typename FloatType, std::
size_t S, std::
size_t m>
139 Utils::Vector3i const &n_stop,
int const KX,
int const KY,
int const KZ,
143 auto const size = n_stop - n_start;
146 auto g = std::vector<FloatType>(
Utils::product(size), FloatType(0));
154 auto const wavevector = (2. * std::numbers::pi) * inv_box_l;
155 auto const half_mesh =
params.mesh / 2;
157 auto index = std::size_t(0u);
160 if ((indices[KX] % half_mesh[0u] != 0) or
161 (indices[KY] % half_mesh[1u] != 0) or
162 (indices[KZ] % half_mesh[2u] != 0)) {
165 shifts[1u][indices[KY]] * wavevector[1u],
166 shifts[2u][indices[KZ]] * wavevector[2u]}};
167 g[index] = FloatType(G_opt<S, m>(
params, k));
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.
This file contains the defaults for ESPResSo.
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.
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.
double G_opt(P3MParameters const ¶ms, Utils::Vector3d const &k)
Calculate the aliasing sums for the optimal influence function.
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.
std::array< std::vector< int >, 3 > calc_p3m_mesh_shift(Utils::Vector3i const &mesh_size, bool zero_out_midpoint=false)
Calculate indices that shift P3MParameters::mesh by mesh/2.
static SteepestDescentParameters params
Currently active steepest descent instance.
Structure to hold P3M parameters and some dependent variables.