49#if defined(ESPRESSO_P3M) or defined(ESPRESSO_DP3M)
106 auto constexpr value_to_tune = -1.;
109 throw std::domain_error(
"Parameter 'epsilon' must be >= 0");
113 throw std::domain_error(
"Parameter 'accuracy' must be > 0");
120 throw std::domain_error(
"Parameter 'r_cut' must be > 0");
128 throw std::domain_error(
"Parameter 'alpha' must be > 0");
135 throw std::domain_error(
"Parameter 'mesh' must be > 0");
143 throw std::domain_error(
"Parameter 'mesh_off' must be >= 0 and <= 1");
147 if ((cao < 1 or cao > 7) and (not
tuning or
cao != -1)) {
148 throw std::domain_error(
"Parameter 'cao' must be >= 1 and <= 7");
152 throw std::domain_error(
"Parameter 'cao' cannot be larger than 'mesh'");
214 for (
auto i = 0u; i < 3u; i++) {
224 LocalBox const &local_geo,
double skin,
251 std::pair<std::optional<int>, std::optional<int>>
limits;
263template <
unsigned int r2c_dir>
265 auto const &local_size,
auto const &local_origin) {
266 auto const cutoff_right = global_size[r2c_dir] / 2 - local_origin[r2c_dir];
267 std::remove_cvref_t<
decltype(g_function)> g_function_r2c;
268 g_function_r2c.reserve(g_function.size() / 2ul);
270 auto &short_dim = local_index[r2c_dir];
271 auto &nx = local_index[0u];
272 auto &ny = local_index[1u];
273 auto &nz = local_index[2u];
274 std::size_t index = 0u;
275 for (nx = 0; nx < local_size[0u]; ++nx) {
276 for (ny = 0; ny < local_size[1u]; ++ny) {
277 for (nz = 0; nz < local_size[2u]; ++nz) {
278 if (short_dim <= cutoff_right) {
279 g_function_r2c.emplace_back(g_function[index]);
285 std::swap(g_function, g_function_r2c);
299 std::array<std::vector<int>, 3> ret{};
301 for (
auto i = 0u; i < 3u; ++i) {
302 ret[i] = std::vector<int>(
static_cast<std::size_t
>(mesh_size[i]));
304 for (
int j = 1; j <= mesh_size[i] / 2; j++) {
306 ret[i][mesh_size[i] - j] = -j;
308 if (zero_out_midpoint)
309 ret[i][mesh_size[i] / 2] = 0;
317 bool UseR2C =
false,
unsigned int R2CDir = 2u>
Vector implementation and trait types for boost qvm interoperability.
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.
auto hadamard_division(Vector< T, N > const &a, Vector< U, N > const &b)
auto hadamard_product(Vector< T, N > const &a, Vector< U, N > const &b)
Arch
P3M kernel architecture.
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.
void influence_function_r2c(auto &g_function, auto const &global_size, auto const &local_size, auto const &local_origin)
Adapt an influence function grid for real-to-complex FFTs.
auto constexpr P3M_EPSILON_METALLIC
This value indicates metallic boundary conditions.
static SteepestDescentParameters params
Currently active steepest descent instance.
static auto constexpr r2c_dir
Direction of the reduced dimension (if use_r2c is true).
static auto constexpr use_r2c
Use real-to-complex implementation.
static auto constexpr r_space_order
Data layout of the input real-space 3D matrix.
static auto constexpr k_space_order
Data layout of the output k-space 3D matrix.
std::array< std::span< FloatType >, 3 > rs_fields
real-space vector meshes for the electric or dipolar field.
int ks_pnum
number of permutations in k_space
Utils::Vector3i start
Indices of the lower left corner of the local mesh grid.
std::span< FloatType > rs_scalar
real-space scalar mesh for charge assignment and FFT.
std::span< FloatType > rs_charge_density
real-space scalar charge density.
Utils::Vector3i stop
Indices of the upper right corner of the local mesh grid.
Utils::Vector3i size
Extents of the local mesh grid.
Properties of the local mesh.
Utils::Vector3i ur_no_halo
Utils::Vector3i ld_ind
index of lower left corner of the local mesh in the global mesh.
std::size_t size
number of local mesh points including halo layers.
Utils::Vector3i dim
dimension (size) of local mesh including halo layers.
void recalc_ld_pos(P3MParameters const ¶ms)
Recalculate quantities derived from the mesh and box length: ld_pos (position of the left down mesh).
void calc_local_ca_mesh(P3MParameters const ¶ms, LocalBox const &local_geo, double skin, double space_layer)
Calculate properties of the local FFT mesh for the charge assignment process.
Utils::Vector3i dim_no_halo
Utils::Vector3i n_halo_ld
Utils::Vector3i inner
dimension of mesh inside node domain.
Utils::Vector3i in_ld
inner left down grid point
int r_margin[6]
number of margin mesh points from neighbour nodes
int margin[6]
number of margin mesh points.
int q_2_off
offset between mesh lines of the last dimension
Utils::Vector3i ld_no_halo
Utils::Vector3i in_ur
inner up right grid point + (1,1,1)
Utils::Vector3d ld_pos
position of the first local mesh point.
Utils::Vector3i n_halo_ur
int q_21_off
offset between mesh lines of the two last dimensions
Structure to hold P3M parameters and some dependent variables.
auto calc_grid_pos(Utils::Vector3d const &pos) const
Convert spatial position to grid position.
Utils::Vector3d cao_cut
cutoff for charge assignment.
double alpha
unscaled alpha_L for use with fast inline functions only
P3MParameters(bool tuning, double epsilon, double r_cut, Utils::Vector3i const &mesh, Utils::Vector3d const &mesh_off, int cao, double alpha, double accuracy)
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.
int cao3
number of points unto which a single charge is interpolated, i.e.
Utils::Vector3d mesh_off
offset of the first mesh point (lower left corner) from the coordinate origin ([0,...
Utils::Vector3d ai
inverse mesh constant.
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".
Utils::Vector3d a
mesh constant.
std::pair< std::optional< int >, std::optional< int > > limits