ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ll_and_dist.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
24#include <array>
25#include <cmath>
26
27namespace Utils::Interpolation::detail {
28
29struct Block {
30 /** Index of the lower left corner of the assignment cube */
31 std::array<int, 3> corner;
32 /** Distance to the nearest mesh point in units of agrid in [-0.5, 0.5) */
33 std::array<double, 3> distance;
34};
35
36/**
37 * @brief Calculate the lower left index of a block
38 * stencil with @c order points side length.
39 */
40template <int order>
41auto ll_and_dist(Vector3d const &pos, Vector3d const &grid_spacing,
42 Vector3d const &offset) {
43 Block block{};
44 for (unsigned int dim = 0u; dim < 3u; ++dim) {
45 auto const fractional_index = (pos[dim] - offset[dim]) / grid_spacing[dim];
46 int nmp;
47 if constexpr (order % 2 == 0) {
48 nmp = static_cast<int>(std::floor(fractional_index));
49 block.distance[dim] = fractional_index - nmp - 0.5;
50 } else {
51 nmp = static_cast<int>(std::floor(fractional_index + 0.5));
52 block.distance[dim] = fractional_index - nmp;
53 }
54 block.corner[dim] = nmp - (order - 1) / 2;
55 }
56 return block;
57}
58
59} // namespace Utils::Interpolation::detail
Vector implementation and trait types for boost qvm interoperability.
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:172
VectorXd< 3 > Vector3d
Definition Vector.hpp:164