30#include "communication.hpp"
42#include <Kokkos_Core.hpp>
56template <
typename FloatType, Arch Architecture,
class FFTConfig>
class P3MFFT;
63template <
typename FloatType, Arch Architecture,
class FFTConfig>
97 std::shared_ptr<P3MFFTBackend<FloatType, FFTConfig>>
fft;
98 Kokkos::View<FloatType **, r_space_layout, Kokkos::HostSpace>
104 "CoulombP3MState::rs_charge_density_kokkos", 0, 0);
112template <
typename FloatType, Arch Architecture,
class FFTConfig>
123 std::shared_ptr<KokkosHandle> m_kokkos_handle;
124 std::unique_ptr<CoulombP3MStateClass> p3m_state_ptr;
129 auto constexpr memory_order = CoulombP3MStateClass::memory_order;
141 tuning{
std::move(tuning_params)} {
143 if (tuning.timings <= 0) {
144 throw std::domain_error(
"Parameter 'timings' must be > 0");
146 m_is_tuned = not
p3m.params.tuning;
147 p3m.params.tuning =
false;
153 if constexpr (Architecture ==
Arch::CPU) {
162 void tune()
override;
165 double square_sum_q)
override {
168 p3m.square_sum_q = square_sum_q;
174 [[nodiscard]]
bool is_tuned() const noexcept
override {
return m_is_tuned; }
175 [[nodiscard]]
bool is_gpu() const noexcept
override {
179 return std::is_same_v<FloatType, double>;
202 if constexpr (Architecture ==
Arch::CPU) {
216 bool skip_cache)
override;
219 p3m.inter_weights.reset(
p3m.params.cao);
221 p3m.rs_charge_density.resize(
p3m.local_mesh.size);
222 using execution_space = Kokkos::DefaultHostExecutionSpace;
223 auto const num_threads = execution_space().concurrency();
224 Kokkos::realloc(Kokkos::WithoutInitializing,
p3m.rs_charge_density_kokkos,
225 num_threads,
p3m.local_mesh.size);
228 if (num_threads > 1 or zero_rs) {
229 std::ranges::fill(
p3m.rs_charge_density, FloatType{0});
247 void kernel_ks_charge_density();
248 void kernel_rs_electric_field();
Vector implementation and trait types for boost qvm interoperability.
void set_prefactor(double new_prefactor)
Cache for interpolation weights.
std::shared_ptr< KokkosHandle > kokkos_handle
ESPRESSO_ATTR_ALWAYS_INLINE void kokkos_deep_copy(auto const &exec_space, auto const &view, auto const &value)
Wrapper for Kokkos::deep_copy that skips fork/join when the number of threads is 1.
std::vector< T, allocator< T > > vector
Common functions for dipolar and charge P3M.
auto constexpr P3M_EPSILON_METALLIC
This value indicates metallic boundary conditions.
P3M algorithm for long-range Coulomb interaction.
~CoulombP3MImpl() override=default
void count_charged_particles() override
bool is_tuned() const noexcept override
bool is_gpu() const noexcept override
void add_long_range_forces_gpu()
void add_long_range_forces() override
CoulombP3MStateClass & p3m
Coulomb P3M parameters.
CoulombP3MImpl(std::unique_ptr< CoulombP3MStateClass > &&p3m_state, TuningParameters tuning_params, double prefactor)
void charge_assign() override
double long_range_energy() override
double long_range_kernel(bool force_flag, bool energy_flag)
Compute the k-space part of forces and energies.
Utils::Vector9d long_range_pressure() override
void scaleby_box_l() override
void calc_influence_function_force() override
Calculate the optimal influence function of hockney88a.
void count_charged_particles_elc(std::size_t n, double sum_q2, double square_sum_q) override
void assign_charge(double q, Utils::Vector3d const &real_pos, bool skip_cache) override
std::shared_ptr< P3MGpuParams > m_gpu_data
bool is_double_precision() const noexcept override
CoulombP3MState< FloatType, Architecture, FFTConfig > CoulombP3MStateClass
void prepare_fft_mesh(bool reset_weights, bool zero_rs) override
void adapt_epsilon_elc() override
void calc_influence_function_energy() override
Calculate the influence function optimized for the energy and the self energy correction.
void on_activation() override
Base class for the electrostatics P3M algorithm.
Kokkos::DefaultHostExecutionSpace execution_space
Kokkos::View< FloatType **, r_space_layout, Kokkos::HostSpace > rs_charge_density_kokkos
fft::vector< ComplexType > ks_charge_density
charge density in k-space without halo
fft::vector< FloatType > rs_charge_density
charge density in real-space with halo
FFTConfig::r_space_layout r_space_layout
Kokkos::HostSpace memory_space
std::array< std::span< ComplexType >, 3 > ks_E_fields
electric fields in k-space without halo
fft::vector< ComplexType > ks_E_fields_batched
fft::vector< FloatType > rs_E_fields_no_halo_batched
FFTConfig::k_space_layout k_space_layout
p3m_interpolation_cache inter_weights
double square_sum_q
square of sum of charges.
std::array< std::span< FloatType >, 3 > rs_E_fields_no_halo
electric fields in real-space without halo
std::array< fft::vector< FloatType >, 3 > rs_E_fields
electric fields in real-space with halo
std::complex< value_type > ComplexType
std::size_t sum_qpart
number of charged particles.
p3m_send_mesh< FloatType > halo_comm
double sum_q2
Sum of square of charges.
CoulombP3M(P3MParameters const &p3m_params)
void sanity_checks() const
P3MStateCommon(P3MParameters &¶meters)