58 std::vector<double> ca_frac;
60 std::vector<int> ca_fmp;
67 auto size()
const {
return ca_fmp.size(); }
73 auto cao()
const {
return m_cao; }
85 ca_fmp.push_back(w.
ind);
86 auto it = std::back_inserter(ca_frac);
87 std::ranges::copy(w.
w_x, it);
88 std::ranges::copy(w.
w_y, it);
89 std::ranges::copy(w.
w_z, it);
104 assert(
cao == m_cao);
110 auto const view = std::span(std::as_const(ca_frac));
111 auto const offset = 3ul * i *
static_cast<std::size_t
>(
cao);
113 std::ranges::copy(view.subspan(offset + 0ul *
cao,
cao), ret.
w_x.
begin());
114 std::ranges::copy(view.subspan(offset + 1ul *
cao,
cao), ret.
w_y.
begin());
115 std::ranges::copy(view.subspan(offset + 2ul *
cao,
cao), ret.
w_z.
begin());
138template <
int cao, Utils::MemoryOrder memory_order>
144 auto const pos_shift = std::floor((cao - 1) / 2.0) - (cao % 2) / 2.0;
152 for (
unsigned int d = 0; d < 3; d++) {
154 auto const pos = ((position[d] - local_mesh.
ld_pos[d]) * ai[d]) - pos_shift;
156 nmp[d] =
static_cast<int>(pos);
159 dist[d] = (pos - nmp[d]) - 0.5;
168 for (
int i = 0; i < cao; i++) {
171 ret.
w_x[i] = bspline<cao>(i, dist[0]);
172 ret.
w_y[i] = bspline<cao>(i, dist[1]);
173 ret.
w_z[i] = bspline<cao>(i, dist[2]);
190template <
int cao,
class Kernel>
193 auto q_ind = weights.ind;
194 for (
int i0 = 0; i0 < cao; i0++) {
195 auto const w_x = weights.w_x[i0];
196 for (
int i1 = 0; i1 < cao; i1++) {
197 auto const w_xy = w_x * weights.w_y[i1];
198 for (
int i2 = 0; i2 < cao; i2++) {
199 auto const w_xyz = w_xy * weights.w_z[i2];
200 kernel(q_ind, w_xyz);
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.
InterpolationWeights< cao > load(std::size_t i) const
Load entry from the cache.
auto cao() const
Charge assignment order the weights are for.
void reset(int cao)
Reset the cache.
auto size() const
Number of points in the cache.
InterpolationWeights< cao > p3m_calculate_interpolation_weights(const Utils::Vector3d &position, const Utils::Vector3d &ai, P3MLocalMesh const &local_mesh)
Calculate the P-th order interpolation weights.
void p3m_interpolate(P3MLocalMesh const &local_mesh, InterpolationWeights< cao > const &weights, Kernel kernel)
P3M grid interpolation.
int get_linear_index(int a, int b, int c, const Vector3i &adim, MemoryOrder memory_order=MemoryOrder::COLUMN_MAJOR)
get the linear index from the position (a,b,c) in a 3D grid of dimensions adim.
DEVICE_QUALIFIER auto bspline(int i, T x) -> std::enable_if_t<(order > 0) &&(order<=7), T >
Formula of the B-spline.
Interpolation weights for one point.
Utils::Array< double, cao > w_y
Utils::Array< double, cao > w_x
Weights for the directions.
int ind
Linear index of the corner of the interpolation cube.
Utils::Array< double, cao > w_z
Properties of the local mesh.
Utils::Vector3i dim
dimension (size) of local mesh including halo layers.
int q_2_off
offset between mesh lines of the last dimension
Utils::Vector3d ld_pos
position of the first local mesh point.
int q_21_off
offset between mesh lines of the two last dimensions
DEVICE_QUALIFIER constexpr iterator begin() noexcept