ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
bspline_3d.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "utils/Vector.hpp"
23
26
27#include <array>
28
29namespace Utils {
30namespace Interpolation {
31
32/**
33 * @brief cardinal B-spline interpolation with internal iteration.
34 *
35 * @tparam order The number of interpolation points in each direction.
36 * @tparam Kernel Callable that can be called at every point with the
37 * index of the point and its weight as arguments.
38 *
39 * @param pos The point at which the interpolation should be run.
40 * @param kernel Function to run for every point.
41 * @param grid_spacing The distance between the grid points.
42 * @param offset Shift of the grid relative to the origin.
43 */
44template <int order, typename Kernel>
45void bspline_3d(Vector3d const &pos, Kernel const &kernel,
46 Vector3d const &grid_spacing, Vector3d const &offset) {
47 using Utils::bspline;
48
49 /* The coordinates and relative distance of the assignment cube. */
50 auto const block = detail::ll_and_dist<order>(pos, grid_spacing, offset);
51
52 /* Precalc weights that are used multiple times. */
53 std::array<double, order> w_y{};
54 std::array<double, order> w_z{};
55 for (int i = 0; i < order; i++) {
56 w_y[static_cast<unsigned>(i)] = bspline<order>(i, block.distance[1]);
57 w_z[static_cast<unsigned>(i)] = bspline<order>(i, block.distance[2]);
58 }
59
60 std::array<int, 3> ind;
61 for (int i = 0; i < order; i++) {
62 ind[0] = block.corner[0] + i;
63 auto const wx = bspline<order>(i, block.distance[0]);
64 for (int j = 0; j < order; j++) {
65 ind[1] = block.corner[1] + j;
66 auto const wxy = wx * w_y[static_cast<unsigned>(j)];
67 for (int k = 0; k < order; k++) {
68 ind[2] = block.corner[2] + k;
69 kernel(ind, wxy * w_z[static_cast<unsigned>(k)]);
70 }
71 }
72 }
73}
74
75/**
76 * @brief cardinal B-spline weighted sum.
77 */
78template <int order, typename T, typename Kernel>
79T bspline_3d_accumulate(Vector3d const &pos, Kernel const &kernel,
80 Vector3d const &grid_spacing, Vector3d const &offset,
81 T const &init) {
82 T value = init;
83 bspline_3d<order>(
84 pos,
85 [&value, &kernel](std::array<int, 3> const &ind, double w) {
86 value += w * kernel(ind);
87 },
88 grid_spacing, offset);
89
90 return value;
91}
92
93} // namespace Interpolation
94} // namespace Utils
Vector implementation and trait types for boost qvm interoperability.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:174
void bspline_3d(Vector3d const &pos, Kernel const &kernel, Vector3d const &grid_spacing, Vector3d const &offset)
cardinal B-spline interpolation with internal iteration.
T bspline_3d_accumulate(Vector3d const &pos, Kernel const &kernel, Vector3d const &grid_spacing, Vector3d const &offset, T const &init)
cardinal B-spline weighted sum.
DEVICE_QUALIFIER auto bspline(int i, T x) -> std::enable_if_t<(order > 0) &&(order<=7), T >
Formula of the B-spline.
Definition bspline.hpp:32