30#include "communication.hpp"
39#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
40#include <Kokkos_Core.hpp>
53#ifdef ESPRESSO_ADDITIONAL_CHECKS
54#define ESPRESSO_DP3M_HEFFTE_CROSS_CHECKS
57template <
typename FloatType,
class FFTConfig>
class P3MFFT;
64template <
typename FloatType,
class FFTConfig>
89 std::unique_ptr<FFTBackend<FloatType>>
fft;
94 auto const mesh_size_ptr =
fft->get_mesh_size();
95 auto const mesh_start_ptr =
fft->get_mesh_start();
96 for (
auto i = 0u; i < 3u; ++i) {
97 mesh.size[i] = mesh_size_ptr[i];
98 mesh.start[i] = mesh_start_ptr[i];
105 assert(
fft ==
nullptr);
106 fft = std::make_unique<T>(std::as_const(
local_mesh), args...);
114#ifdef ESPRESSO_DP3M_HEFFTE_CROSS_CHECKS
133 std::shared_ptr<P3MFFT<FloatType, FFTConfig>>
fft;
139#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
145#ifdef ESPRESSO_DP3M_HEFFTE_CROSS_CHECKS
146 assert(
heffte.rs_dipole_density[0u].empty());
147 assert(
heffte.rs_dipole_density[1u].empty());
148 assert(
heffte.rs_dipole_density[2u].empty());
151 "DipolarP3MState::rs_fields_kokkos", 0, 0, 0);
156template <
typename FloatType, Arch Architecture,
class FFTConfig>
169#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
171 std::shared_ptr<KokkosHandle> m_kokkos_handle;
174 std::unique_ptr<DipolarP3MStateClass> dp3m_impl;
182#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
185 dp3m_impl{
std::move(dp3m_state)}, tuning{
std::move(tuning_params)} {
188 throw std::domain_error(
"Parameter 'timings' must be > 0");
191 throw std::domain_error(
"DipolarP3M requires a cubic mesh");
196#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
202 if constexpr (Architecture ==
Arch::CPU) {
206 void tune()
override;
209 [[nodiscard]]
bool is_tuned() const noexcept
override {
return m_is_tuned; }
210 [[nodiscard]]
bool is_gpu() const noexcept
override {
214 return std::is_same_v<FloatType, double>;
225 if constexpr (Architecture ==
Arch::CPU) {
233 void prepare_fft_mesh() {
235#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
236 using execution_space = Kokkos::DefaultExecutionSpace;
237 auto const num_threads = execution_space().concurrency();
242 for (
auto &rs_mesh_field :
dp3m.mesh.rs_fields) {
243 std::ranges::fill(rs_mesh_field, FloatType{0});
245#ifdef ESPRESSO_DP3M_HEFFTE_CROSS_CHECKS
246 for (
auto dir : {0u, 1u, 2u}) {
Vector implementation and trait types for boost qvm interoperability.
void set_prefactor(double new_prefactor)
double prefactor
Magnetostatics prefactor.
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 reset(int cao)
Reset the cache.
std::shared_ptr< KokkosHandle > kokkos_handle
P3M algorithm for long-range magnetic dipole-dipole interaction.
Common functions for dipolar and charge P3M.
double calc_surface_term(bool force_flag, bool energy_flag) override
bool is_double_precision() const noexcept override
void npt_add_virial_contribution(double energy) const override
DipolarP3MHeffte(std::unique_ptr< DipolarP3MStateClass > &&dp3m_state, TuningParameters tuning_params, double prefactor)
void dipole_assign() override
~DipolarP3MHeffte() override=default
void calc_influence_function_energy() override
void scaleby_box_l() override
void calc_influence_function_force() override
void count_magnetic_particles() override
DipolarP3MStateClass & dp3m
Dipolar P3M parameters.
void add_long_range_forces() override
double long_range_kernel(bool force_flag, bool energy_flag)
Compute the k-space part of forces and energies.
void on_activation() override
double calc_average_self_energy_k_space() const override
double long_range_energy() override
void calc_energy_correction() override
bool is_gpu() const noexcept override
bool is_tuned() const noexcept override
Base class for the magnetostatics P3M algorithm.
std::vector< FloatType > g_force
Force optimised influence function (k-space)
std::vector< ComplexType > ks_B_field_storage
magnetic fields in k-space without halo
double sum_mu2
Sum of square of magnetic dipoles.
p3m_interpolation_cache inter_weights
std::complex< FloatType > ComplexType
std::array< std::vector< FloatType >, 3 > rs_B_fields
magnetic fields in real-space with halo
std::size_t sum_dip_part
number of dipolar particles.
std::unique_ptr< FFTBackend< FloatType > > fft
FFT algorithm.
P3MFFTMesh< FloatType > mesh
std::array< std::vector< FloatType >, 3u > rs_dipole_density
dipole density in real-space with halo
p3m_send_mesh< FloatType > halo_comm
std::vector< FloatType > g_energy
Energy optimised influence function (k-space)
std::unique_ptr< FFTBuffers< FloatType > > fft_buffers
FFT buffers.
std::array< std::vector< FloatType >, 3u > rs_B_fields_no_halo
magnetic fields in real-space without halo
double pos_shift
position shift for calculation of first assignment mesh point.
void make_fft_instance(Args... args)
double energy_correction
cached k-space self-energy correction
std::vector< ComplexType > ks_scalar
k-space scalar mesh for k-space calculations.
std::shared_ptr< P3MFFT< FloatType, FFTConfig > > fft
void resize_heffte_buffers()
struct DipolarP3MState::@1 heffte
Kokkos::View< FloatType ***, Kokkos::LayoutRight, Kokkos::HostSpace > rs_fields_kokkos
std::array< std::vector< ComplexType >, 3u > ks_dipole_density
dipole density in k-space without halo
void make_mesh_instance(Args... args)
void sanity_checks() const
std::size_t size
number of local mesh points including halo layers.
int cao
charge assignment order ([0,7]).
bool tuning
tuning or production?
Utils::Vector3i mesh
number of mesh points per coordinate direction (>0), in real space.
State of the p3m methods, the part which applies to both, electrostatic and dipolar p3m.
P3MParameters params
P3M base parameters.
P3MLocalMesh local_mesh
Local mesh geometry information for this MPI rank.