57#include "communication.hpp"
62#include "system/System.hpp"
71#include <boost/mpi/collectives/all_reduce.hpp>
72#include <boost/mpi/collectives/broadcast.hpp>
73#include <boost/mpi/collectives/reduce.hpp>
74#include <boost/mpi/communicator.hpp>
75#include <boost/range/combine.hpp>
76#include <boost/range/numeric.hpp>
84#include <initializer_list>
95#error "The FFTW3 library shouldn't be visible in this translation unit"
98template <
typename FloatType, Arch Architecture>
104 for (
auto const &p : get_system().
cell_structure->local_particles()) {
112 boost::mpi::all_reduce(
comm_cart, local_n, p3m.sum_qpart, std::plus<>());
113 boost::mpi::all_reduce(
comm_cart, local_q2, p3m.sum_q2, std::plus<>());
114 boost::mpi::all_reduce(
comm_cart, local_q, p3m.square_sum_q, std::plus<>());
115 p3m.square_sum_q =
Utils::sqr(p3m.square_sum_q);
127template <
typename FloatType, Arch Architecture>
129 auto const [KX, KY, KZ] = p3m.fft->get_permutations();
130 p3m.g_force = grid_influence_function<FloatType, 1, P3M_BRILLOUIN>(
131 p3m.params, p3m.mesh.start, p3m.mesh.stop, KX, KY, KZ,
132 get_system().box_geo->length_inv());
138template <
typename FloatType, Arch Architecture>
140 auto const [KX, KY, KZ] = p3m.fft->get_permutations();
141 p3m.g_energy = grid_influence_function<FloatType, 0, P3M_BRILLOUIN>(
142 p3m.params, p3m.mesh.start, p3m.mesh.stop, KX, KY, KZ,
143 get_system().box_geo->length_inv());
154 auto constexpr exp_min = -708.4;
155 auto const factor1 =
Utils::sqr(std::numbers::pi * alpha_L_i);
163 mesh_start, mesh_stop, indices,
165 auto const norm_sq = nm.norm2();
166 auto const exponent = -factor1 * norm_sq;
167 auto const exp_limit = (exp_min + std::log(norm_sq)) / 2.;
168 auto const ex = (exponent < exp_limit) ? 0. : std::exp(exponent);
171 alias2 += energy * ex * (shift * nm) / norm_sq;
173 [&](
unsigned dim,
int n) {
174 nm[dim] = shift[dim] + n * mesh[dim];
178 return std::make_pair(alias1, alias2);
192 double sum_q2,
double alpha_L,
195 return (2. * pref * sum_q2 * exp(-
Utils::sqr(r_cut_iL * alpha_L))) /
196 sqrt(
static_cast<double>(n_c_part) * r_cut_iL * box_l[0] * volume);
213 int cao,
int n_c_part,
double sum_q2,
218 auto const alpha_L_i = 1. / alpha_L;
219 auto const mesh_stop = mesh / 2;
220 auto const mesh_start = -mesh_stop;
226 mesh_start, mesh_stop, indices,
228 if ((indices[0] != 0) or (indices[1] != 0) or (indices[2] != 0)) {
229 auto const n2 = indices.norm2();
231 auto const [alias1, alias2] =
233 auto const d = alias1 -
Utils::sqr(alias2 / cs) / n2;
241 [&values, &mesh_i, cotangent_sum](
unsigned dim,
int n) {
242 values[dim] = cotangent_sum(n, mesh_i[dim]);
245 return 2. * pref * sum_q2 * sqrt(he_q /
static_cast<double>(n_c_part)) /
246 (box_l[1] * box_l[2]);
249template <
typename FloatType, Arch Architecture>
252 assert(p3m.params.cao >= 1 and p3m.params.cao <= 7);
253 assert(p3m.params.alpha > 0.);
255 auto const &system = get_system();
256 auto const &box_geo = *system.box_geo;
257 auto const &local_geo = *system.local_geo;
258 auto const skin = system.cell_structure->get_verlet_skin();
260 p3m.params.cao3 = Utils::int_pow<3>(p3m.params.cao);
261 p3m.params.recalc_a_ai_cao_cut(box_geo.length());
265 auto const &solver = system.coulomb.impl->solver;
266 double elc_layer = 0.;
267 if (
auto actor = get_actor_by_type<ElectrostaticLayerCorrection>(solver)) {
268 elc_layer = actor->elc.space_layer;
272 p3m.local_mesh.calc_local_ca_mesh(p3m.params, local_geo, skin, elc_layer);
273 p3m.fft_buffers->init_halo();
274 p3m.fft->init(p3m.params);
275 p3m.mesh.ks_pnum = p3m.fft->get_ks_pnum();
276 p3m.fft_buffers->init_meshes(p3m.fft->get_ca_mesh_size());
277 p3m.update_mesh_views();
278 p3m.calc_differential_operator();
283 count_charged_particles();
291 typename std::remove_reference_t<
decltype(p3m)>::value_type;
293 p3m.mesh.rs_scalar[ind] += value_type(w * q);
299 auto const w = p3m_calculate_interpolation_weights<cao>(
300 real_pos, p3m.params.ai, p3m.local_mesh);
301 inter_weights.
store(w);
302 this->operator()(p3m, q, real_pos, w);
306 auto const w = p3m_calculate_interpolation_weights<cao>(
307 real_pos, p3m.params.ai, p3m.local_mesh);
308 this->operator()(p3m, q, real_pos, w);
311 template <
typename combined_ranges>
312 void operator()(
auto &p3m, combined_ranges
const &p_q_pos_range) {
313 for (
auto zipped : p_q_pos_range) {
314 auto const p_q = boost::get<0>(zipped);
315 auto const &p_pos = boost::get<1>(zipped);
317 this->operator()(p3m, p_q, p_pos, p3m.inter_weights);
324template <
typename FloatType, Arch Architecture>
327 prepare_fft_mesh(
true);
332 Utils::integral_parameter<int, AssignCharge, 1, 7>(
333 p3m.params.cao, p3m, boost::combine(p_q_range, p_pos_range));
336template <
typename FloatType, Arch Architecture>
340 Utils::integral_parameter<int, AssignCharge, 1, 7>(p3m.params.cao, p3m, q,
343 Utils::integral_parameter<int, AssignCharge, 1, 7>(
344 p3m.params.cao, p3m, q, real_pos, p3m.inter_weights);
349 template <
typename combined_ranges>
351 combined_ranges
const &p_q_force_range)
const {
353 assert(cao == p3m.inter_weights.cao());
356 auto p_index = std::size_t{0ul};
358 for (
auto zipped : p_q_force_range) {
359 auto p_q = boost::get<0>(zipped);
360 auto &p_force = boost::get<1>(zipped);
362 auto const pref = p_q * force_prefac;
363 auto const w = p3m.inter_weights.template load<cao>(p_index);
367 force[0u] += w * double(p3m.mesh.rs_fields[0u][ind]);
368 force[1u] += w * double(p3m.mesh.rs_fields[1u][ind]);
369 force[2u] += w * double(p3m.mesh.rs_fields[2u][ind]);
372 p_force -= pref * force;
379template <
typename combined_ranges>
381 combined_ranges
const &p_q_unfolded_pos_range) {
382 auto const local_dip =
385 auto const p_q = boost::get<0>(q_pos);
386 auto const &p_unfolded_pos = boost::get<1>(q_pos);
387 return dip + p_q * p_unfolded_pos;
389 return boost::mpi::all_reduce(comm, local_dip, std::plus<>());
397template <
typename FloatType, Arch Architecture>
400 auto const &box_geo = *get_system().
box_geo;
403 if (p3m.sum_q2 > 0.) {
405 p3m.fft_buffers->perform_scalar_halo_gather();
406 p3m.fft->forward_fft(p3m.fft_buffers->get_scalar_mesh());
407 p3m.update_mesh_views();
410 auto const &mesh_stop = p3m.mesh.size;
411 auto const &offset = p3m.mesh.start;
412 auto const half_alpha_inv_sq =
Utils::sqr(1. / 2. / p3m.params.alpha);
413 auto const wavevector = (2. * std::numbers::pi) * box_geo.length_inv();
414 auto const [KX, KY, KZ] = p3m.fft->get_permutations();
416 auto index = std::size_t(0u);
419 for_each_3d(mesh_start, mesh_stop, indices, [&]() {
420 auto const shift = indices + offset;
421 auto const kx = p3m.d_op[0u][shift[KX]] * wavevector[0u];
422 auto const ky = p3m.d_op[1u][shift[KY]] * wavevector[1u];
423 auto const kz = p3m.d_op[2u][shift[KZ]] * wavevector[2u];
427 auto const node_k_space_energy =
428 double(p3m.g_energy[index] *
429 (
Utils::sqr(p3m.mesh.rs_scalar[2u * index + 0u]) +
430 Utils::sqr(p3m.mesh.rs_scalar[2u * index + 1u])));
431 auto const vterm = -2. * (1. / norm_sq + half_alpha_inv_sq);
432 auto const pref = node_k_space_energy * vterm;
433 node_k_space_pressure_tensor[0u] += pref * kx * kx;
434 node_k_space_pressure_tensor[1u] += pref * kx * ky;
435 node_k_space_pressure_tensor[2u] += pref * kx * kz;
436 node_k_space_pressure_tensor[4u] += pref * ky * ky;
437 node_k_space_pressure_tensor[5u] += pref * ky * kz;
438 node_k_space_pressure_tensor[8u] += pref * kz * kz;
439 diagonal += node_k_space_energy;
444 node_k_space_pressure_tensor[0u] += diagonal;
445 node_k_space_pressure_tensor[4u] += diagonal;
446 node_k_space_pressure_tensor[8u] += diagonal;
447 node_k_space_pressure_tensor[3u] = node_k_space_pressure_tensor[1u];
448 node_k_space_pressure_tensor[6u] = node_k_space_pressure_tensor[2u];
449 node_k_space_pressure_tensor[7u] = node_k_space_pressure_tensor[5u];
452 return node_k_space_pressure_tensor * prefactor / (2. * box_geo.volume());
455template <
typename FloatType, Arch Architecture>
457 bool force_flag,
bool energy_flag,
ParticleRange const &particles) {
458 auto const &system = get_system();
459 auto const &box_geo = *system.box_geo;
461 auto const npt_flag =
464 auto constexpr npt_flag =
false;
467 if (p3m.sum_q2 > 0.) {
468 if (not has_actor_of_type<ElectrostaticLayerCorrection>(
469 system.coulomb.impl->solver)) {
472 p3m.fft_buffers->perform_scalar_halo_gather();
473 p3m.fft->forward_fft(p3m.fft_buffers->get_scalar_mesh());
474 p3m.update_mesh_views();
479 auto p_unfolded_pos_range =
485 auto const box_dipole =
488 comm_cart, boost::combine(p_q_range, p_unfolded_pos_range)))
490 auto const volume = box_geo.volume();
492 4. * std::numbers::pi / volume / (2. * p3m.params.epsilon + 1.);
498 auto const &mesh_stop = p3m.mesh.size;
499 auto const &offset = p3m.mesh.start;
501 box_geo.length_inv());
503 auto index = std::size_t(0u);
507 for_each_3d(mesh_start, mesh_stop, indices, [&]() {
509 std::complex<FloatType>(p3m.mesh.rs_scalar[2u * index + 0u],
510 p3m.mesh.rs_scalar[2u * index + 1u]);
511 auto const phi_hat = p3m.g_force[index] * rho_hat;
513 for (
int d = 0; d < 3; d++) {
515 int d_rs = (d + p3m.mesh.ks_pnum) % 3;
517 auto const k = FloatType(p3m.d_op[d_rs][indices[d] + offset[d]]) *
521 p3m.mesh.rs_fields[d_rs][2u * index + 0u] = -k * phi_hat.imag();
522 p3m.mesh.rs_fields[d_rs][2u * index + 1u] = +k * phi_hat.real();
528 auto const check_residuals =
529 not p3m.params.tuning and check_complex_residuals;
530 p3m.fft->check_complex_residuals = check_residuals;
531 for (
auto &rs_mesh : p3m.fft_buffers->get_vector_mesh()) {
532 p3m.fft->backward_fft(rs_mesh);
534 p3m.fft_buffers->perform_vector_halo_spread();
535 p3m.fft->check_complex_residuals =
false;
537 auto const force_prefac = prefactor / volume;
538 Utils::integral_parameter<int, AssignForces, 1, 7>(
539 p3m.params.cao, p3m, force_prefac,
540 boost::combine(p_q_range, p_force_range));
545 auto const dm = prefactor * pref * box_dipole.value();
546 for (
auto zipped : boost::combine(p_q_range, p_force_range)) {
547 auto p_q = boost::get<0>(zipped);
548 auto &p_force = boost::get<1>(zipped);
555 if (energy_flag or npt_flag) {
556 auto node_energy = 0.;
558 for (
int i = 0; i < mesh_length; i++) {
562 double(p3m.g_energy[i] * (
Utils::sqr(p3m.mesh.rs_scalar[2 * i + 0]) +
565 node_energy /= 2. * volume;
568 boost::mpi::reduce(
comm_cart, node_energy, energy, std::plus<>(), 0);
572 energy -= p3m.sum_q2 * p3m.params.alpha * std::numbers::inv_sqrtpi;
575 energy -= p3m.square_sum_q * std::numbers::pi /
580 energy += pref * box_dipole.value().norm2();
589 if (not energy_flag) {
598template <
typename FloatType, Arch Architecture>
601 double m_mesh_density_min = -1., m_mesh_density_max = -1.;
603 bool m_tune_mesh =
false;
604 std::pair<std::optional<int>, std::optional<int>> m_tune_limits;
611 double prefactor,
int timings,
612 decltype(m_tune_limits) tune_limits)
614 m_tune_limits{std::move(tune_limits)} {}
621 auto const on_gpu = Architecture ==
Arch::GPU;
623 auto const on_gpu =
false;
625 m_logger = std::make_unique<TuningLogger>(
626 verbose and
this_node == 0, (on_gpu) ?
"CoulombP3MGPU" :
"CoulombP3M",
633 std::optional<std::string>
636 if (
auto actor = get_actor_by_type<ElectrostaticLayerCorrection>(solver)) {
637 return actor->veto_r_cut(r_cut);
645 if constexpr (Architecture ==
Arch::GPU) {
650 auto const [KX, KY, KZ] = p3m.
fft->get_permutations();
651 auto valid_decomposition =
false;
652 Array3i mesh_size_k_space = {};
655 [](Array3i
const &lhs, Array3i
const &rhs) {
656 return Array3i{{std::max(lhs[0u], rhs[0u]),
657 std::max(lhs[1u], rhs[1u]),
658 std::max(lhs[2u], rhs[2u])}};
662 valid_decomposition = (mesh_size_r_space[0u] == mesh_size_k_space[KX] and
663 mesh_size_r_space[1u] == mesh_size_k_space[KY] and
664 mesh_size_r_space[2u] == mesh_size_k_space[KZ]);
666 boost::mpi::broadcast(
::comm_cart, valid_decomposition, 0);
667 std::optional<std::string> retval{
"conflict with FFT domain decomposition"};
668 if (valid_decomposition) {
669 retval = std::nullopt;
674 std::tuple<double, double, double, double>
676 double r_cut_iL)
const override {
678 auto const &box_geo = *m_system.box_geo;
679 double alpha_L, rs_err, ks_err;
683 p3m.
sum_q2, 0., box_geo.length());
687 alpha_L = sqrt(log(std::numbers::sqrt2 * rs_err / p3m.
params.
accuracy)) /
698 p3m.
sum_q2, alpha_L, box_geo.length());
700 if constexpr (Architecture ==
Arch::GPU) {
704 p3m.
sum_q2, alpha_L, box_geo.length().data());
706 boost::mpi::broadcast(
comm_cart, ks_err, 0);
710 p3m.
sum_q2, alpha_L, box_geo.length());
716 auto const &box_geo = *m_system.box_geo;
717 auto const mesh_density =
718 static_cast<double>(p3m.
params.
mesh[0]) * box_geo.length_inv()[0];
722 auto const normalized_box_dim = std::cbrt(box_geo.volume());
723 auto const max_npart_per_dim = 512.;
727 auto const min_npart_per_dim = std::min(
728 max_npart_per_dim, std::cbrt(
static_cast<double>(p3m.
sum_qpart)));
729 m_mesh_density_min = min_npart_per_dim / normalized_box_dim;
730 m_mesh_density_max = max_npart_per_dim / normalized_box_dim;
731 if (m_tune_limits.first or m_tune_limits.second) {
732 auto const &box_l = box_geo.length();
733 auto const dim = std::max({box_l[0], box_l[1], box_l[2]});
734 if (m_tune_limits.first) {
735 m_mesh_density_min =
static_cast<double>(*m_tune_limits.first) / dim;
737 if (m_tune_limits.second) {
738 m_mesh_density_max =
static_cast<double>(*m_tune_limits.second) / dim;
743 m_mesh_density_min = m_mesh_density_max = mesh_density;
747 for (
auto i : {1, 2}) {
749 static_cast<int>(std::round(mesh_density * box_geo.length()[i]));
759 auto const &box_geo = *m_system.box_geo;
760 auto const &solver = m_system.coulomb.impl->solver;
762 auto time_best = time_sentinel;
763 auto mesh_density = m_mesh_density_min;
764 while (mesh_density <= m_mesh_density_max) {
767 for (
auto i : {0, 1, 2}) {
768 trial_params.
mesh[i] =
769 static_cast<int>(std::round(box_geo.length()[i] * mesh_density));
771 trial_params.mesh[i] += trial_params.mesh[i] % 2;
776 trial_params.cao = cao_best;
778 auto const trial_time =
779 get_m_time(trial_params.mesh, trial_params.cao, trial_params.r_cut_iL,
780 trial_params.alpha_L, trial_params.accuracy);
782 if (trial_time >= 0.) {
785 if (has_actor_of_type<CoulombP3M>(solver)) {
786 m_r_cut_iL_max = trial_params.r_cut_iL;
789 if (trial_time < time_best) {
792 tuned_params = trial_params;
793 time_best = tuned_params.time = trial_time;
794 }
else if (trial_time > time_best + time_granularity or
795 get_n_trials() > max_n_consecutive_trials) {
806template <
typename FloatType, Arch Architecture>
808 auto &system = get_system();
809 auto const &box_geo = *system.
box_geo;
816 if (not is_tuned()) {
817 count_charged_particles();
819 throw std::runtime_error(
820 "CoulombP3M: no charged particles in the system");
824 system, p3m, prefactor, tune_timings, tune_limits);
844 auto const &box_geo = *system.
box_geo;
845 auto const &local_geo = *system.
local_geo;
846 for (
auto i = 0u; i < 3u; i++) {
849 std::stringstream msg;
851 <<
" is larger than half of box dimension " << box_geo.length()[i];
852 throw std::runtime_error(msg.str());
855 std::stringstream msg;
857 <<
" is larger than local box dimension " << local_geo.length()[i];
858 throw std::runtime_error(msg.str());
863 if ((box_geo.length()[0] != box_geo.length()[1]) or
864 (box_geo.length()[1] != box_geo.length()[2]) or
867 throw std::runtime_error(
868 "CoulombP3M: non-metallic epsilon requires cubic box");
875 if (!box_geo.periodic(0) or !box_geo.periodic(1) or !box_geo.periodic(2)) {
876 throw std::runtime_error(
877 "CoulombP3M: requires periodicity (True, True, True)");
882 auto const &local_geo = *
get_system().local_geo;
885 throw std::runtime_error(
886 "CoulombP3M: requires the regular or hybrid decomposition cell system");
890 throw std::runtime_error(
891 "CoulombP3M: does not work with the hybrid decomposition cell system, "
892 "if using more than one MPI node");
898 if (node_grid[0] < node_grid[1] || node_grid[1] < node_grid[2]) {
899 throw std::runtime_error(
900 "CoulombP3M: node grid must be sorted, largest first");
904template <
typename FloatType, Arch Architecture>
906 auto const &box_geo = *get_system().
box_geo;
911 sanity_checks_boxl();
912 calc_influence_function_force();
913 calc_influence_function_energy();
917template <
typename FloatType, Arch Architecture>
920 if constexpr (Architecture ==
Arch::GPU) {
923 auto const energy = long_range_energy(particles);
927 static_cast<void>(particles);
930 auto &gpu = get_system().
gpu;
942template <
typename FloatType, Arch Architecture>
944 if constexpr (Architecture ==
Arch::GPU) {
945 auto &system = get_system();
946 if (has_actor_of_type<ElectrostaticLayerCorrection>(
955template <
typename FloatType, Arch Architecture>
957 if constexpr (Architecture ==
Arch::GPU) {
958 auto &gpu_particle_data = get_system().
gpu;
@ HYBRID
Hybrid decomposition.
@ REGULAR
Regular decomposition.
Vector implementation and trait types for boost qvm interoperability.
TuningAlgorithm::Parameters get_time() override
P3MParameters & get_params() override
std::optional< std::string > fft_decomposition_veto(Utils::Vector3i const &mesh_size_r_space) const override
std::tuple< double, double, double, double > calculate_accuracy(Utils::Vector3i const &mesh, int cao, double r_cut_iL) const override
CoulombTuningAlgorithm(System::System &system, auto &input_p3m, double prefactor, int timings, decltype(m_tune_limits) tune_limits)
void setup_logger(bool verbose) override
void on_solver_change() const override
std::optional< std::string > layer_correction_veto_r_cut(double r_cut) const override
void determine_mesh_limits() override
void enable_property(std::size_t property)
std::size_t n_particles() const
std::shared_ptr< LocalBox > local_geo
std::shared_ptr< Propagation > propagation
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
Tuning algorithm for P3M.
System::System & m_system
void determine_cao_limits(int initial_cao)
Determine a sensible range for the charge assignment order.
void determine_r_cut_limits()
Determine a sensible range for the real-space cutoff.
std::unique_ptr< TuningLogger > m_logger
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
Cache for interpolation weights.
void store(const InterpolationWeights< cao > &w)
Push back weights for one point.
Communicator communicator
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
This file contains the defaults for ESPResSo.
#define ROUND_ERROR_PREC
Precision for capture of round off errors.
#define P3M_BRILLOUIN
P3M: Number of Brillouin zones taken into account in the calculation of the optimal influence functio...
void charge_assign(elc_data const &elc, CoulombP3M &solver, combined_ranges const &p_q_pos_range)
ELC algorithm for long-range Coulomb interactions.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
Routines, row decomposition, data structures and communication for the 3D-FFT.
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.
void p3m_interpolate(P3MLocalMesh const &local_mesh, InterpolationWeights< cao > const &weights, Kernel kernel)
P3M grid interpolation.
auto charge_range(ParticleRange const &particles)
auto pos_range(ParticleRange const &particles)
auto force_range(ParticleRange const &particles)
auto unfolded_pos_range(ParticleRange const &particles, BoxGeometry const &box)
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 .
auto get_analytic_cotangent_sum_kernel(int cao)
void npt_add_virial_contribution(double energy)
Exports for the NpT code.
auto constexpr P3M_EPSILON_METALLIC
This value indicates metallic boundary conditions.
static auto p3m_tune_aliasing_sums(Utils::Vector3i const &shift, Utils::Vector3i const &mesh, Utils::Vector3d const &mesh_i, int cao, double alpha_L_i)
Aliasing sum used by p3m_k_space_error.
static double p3m_k_space_error(double pref, Utils::Vector3i const &mesh, int cao, int n_c_part, double sum_q2, double alpha_L, Utils::Vector3d const &box_l)
Calculate the analytic expression of the error estimate for the P3M method in (eq.
static double p3m_real_space_error(double pref, double r_cut_iL, int n_c_part, double sum_q2, double alpha_L, Utils::Vector3d const &box_l)
Calculate the real space contribution to the rms error in the force (as described by Kolafa and Perra...
static auto calc_dipole_moment(boost::mpi::communicator const &comm, combined_ranges const &p_q_unfolded_pos_range)
P3M algorithm for long-range Coulomb interaction.
void p3m_gpu_add_farfield_force(P3MGpuParams &data, GpuParticleData &gpu, double prefactor, std::size_t n_part)
The long-range part of the P3M algorithm.
void p3m_gpu_init(std::shared_ptr< P3MGpuParams > &data, int cao, Utils::Vector3i const &mesh, double alpha, Utils::Vector3d const &box_l, std::size_t n_part)
Initialize the internal data structure of the P3M GPU.
P3M electrostatics on GPU.
double p3m_k_space_error_gpu(double prefactor, const int *mesh, int cao, int npart, double sum_q2, double alpha_L, const double *box)
void operator()(auto &p3m, double force_prefac, combined_ranges const &p_q_force_range) const
Utils::Vector3i node_grid
void charge_assign(ParticleRange const &particles) override
void assign_charge(double q, Utils::Vector3d const &real_pos, bool skip_cache) override
void calc_influence_function_energy() override
Calculate the influence function optimized for the energy and the self energy correction.
void scaleby_box_l() override
void calc_influence_function_force() override
Calculate the optimal influence function of .
Utils::Vector9d long_range_pressure(ParticleRange const &particles) override
void count_charged_particles() override
double long_range_kernel(bool force_flag, bool energy_flag, ParticleRange const &particles)
Compute the k-space part of forces and energies.
void add_long_range_forces_gpu(ParticleRange const &particles)
void sanity_checks_periodicity() const
void sanity_checks_boxl() const
Checks for correctness of the k-space cutoff.
void sanity_checks_cell_structure() const
P3MParameters const & p3m_params
void sanity_checks_node_grid() const
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
static constexpr std::size_t force
static constexpr std::size_t pos
static constexpr std::size_t q
Interpolation weights for one point.
void recalc_ld_pos(P3MParameters const ¶ms)
Recalculate quantities derived from the mesh and box length: ld_pos (position of the left down mesh).
Structure to hold P3M parameters and some dependent variables.
Utils::Vector3d cao_cut
cutoff for charge assignment.
double alpha
unscaled alpha_L for use with fast inline functions only
double r_cut_iL
cutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i.
int cao
charge assignment order ([0,7]).
double accuracy
accuracy of the actual parameter set.
double alpha_L
Ewald splitting parameter (0.
double r_cut
unscaled r_cut_iL for use with fast inline functions only
void recalc_a_ai_cao_cut(Utils::Vector3d const &box_l)
Recalculate quantities derived from the mesh and box length: a, ai and cao_cut.
bool tuning
tuning or production?
Utils::Vector3i mesh
number of mesh points per coordinate direction (>0), in real space.
double epsilon
epsilon of the "surrounding dielectric".
DEVICE_QUALIFIER constexpr pointer data() noexcept
void operator()(auto &p3m, double q, Utils::Vector3d const &real_pos, p3m_interpolation_cache &inter_weights)
void operator()(auto &p3m, double q, Utils::Vector3d const &real_pos, InterpolationWeights< cao > const &w)
void operator()(auto &p3m, combined_ranges const &p_q_pos_range)
void operator()(auto &p3m, double q, Utils::Vector3d const &real_pos)
double sum_q2
Sum of square of charges (only on head node).
int sum_qpart
number of charged particles (only on head node).
P3MLocalMesh local_mesh
Local mesh properties.
P3MParameters params
P3M base parameters.
std::unique_ptr< FFTBackend< FloatType > > fft
FFT algorithm.
P3MFFTMesh< FloatType > mesh
Local mesh FFT buffers.