Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
common.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2024 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "config/config.hpp"
23
24#if defined(P3M) or defined(DP3M)
25
26#include "common.hpp"
27
28#include "LocalBox.hpp"
29
30#include <utils/Vector.hpp>
31
32#include <cmath>
33
35 LocalBox const &local_geo, double skin,
36 double space_layer) {
37 int i;
38 int ind[3];
39 // total skin size
40 auto const full_skin = Utils::Vector3d{params.cao_cut} +
42 Utils::Vector3d{0., 0., space_layer};
43 // inner left down corner
44 auto const &inner_ld_pos = local_geo.my_left();
45 // inner up right corner
46 auto const &inner_ur_pos = local_geo.my_right();
47 // outer up right corner
48 auto const outer_ur_pos = inner_ur_pos + full_skin;
49 // outer left down corner
50 auto const outer_ld_pos = inner_ld_pos - full_skin;
51 // convert spatial positions to grid positions
52 auto const inner_ld_grid_pos = params.calc_grid_pos(inner_ld_pos);
53 auto const inner_ur_grid_pos = params.calc_grid_pos(inner_ur_pos);
54 auto const outer_ld_grid_pos = params.calc_grid_pos(outer_ld_pos);
55 auto const outer_ur_grid_pos = params.calc_grid_pos(outer_ur_pos);
56
57 /* inner left down grid point (global index) */
58 for (i = 0; i < 3; i++)
59 in_ld[i] = static_cast<int>(std::ceil(inner_ld_grid_pos[i]));
60 /* inner up right grid point (global index) */
61 for (i = 0; i < 3; i++)
62 in_ur[i] = static_cast<int>(std::floor(inner_ur_grid_pos[i]));
63
64 /* correct roundoff errors at boundary */
65 for (i = 0; i < 3; i++) {
66 if (inner_ur_grid_pos[i] - in_ur[i] < ROUND_ERROR_PREC)
67 in_ur[i]--;
68 if (inner_ld_grid_pos[i] - in_ld[i] + 1. < ROUND_ERROR_PREC)
69 in_ld[i]--;
70 }
71 /* inner grid dimensions */
72 for (i = 0; i < 3; i++)
73 inner[i] = in_ur[i] - in_ld[i] + 1;
74 /* index of left down grid point in global mesh */
75 for (i = 0; i < 3; i++)
76 ld_ind[i] = static_cast<int>(std::ceil(outer_ld_grid_pos[i]));
77 /* left down margin */
78 for (i = 0; i < 3; i++)
79 margin[i * 2] = in_ld[i] - ld_ind[i];
80 /* up right grid point */
81 for (i = 0; i < 3; i++)
82 ind[i] = static_cast<int>(std::floor(outer_ur_grid_pos[i]));
83 /* correct roundoff errors at up right boundary */
84 for (i = 0; i < 3; i++)
85 if (outer_ur_grid_pos[i] - ind[i] == 0.)
86 ind[i]--;
87 /* up right margin */
88 for (i = 0; i < 3; i++)
89 margin[(i * 2) + 1] = ind[i] - in_ur[i];
90
91 /* grid dimension */
92 size = 1;
93 for (i = 0; i < 3; i++) {
94 dim[i] = ind[i] - ld_ind[i] + 1;
95 size *= dim[i];
96 }
97
98 /* reduce inner grid indices from global to local */
99 for (i = 0; i < 3; i++)
100 in_ld[i] = margin[i * 2];
101 for (i = 0; i < 3; i++)
102 in_ur[i] = margin[i * 2] + inner[i];
103
104 q_2_off = dim[2] - params.cao;
105 q_21_off = dim[2] * (dim[1] - params.cao);
106
107 n_halo_ld = {margin[0], margin[2], margin[4]};
108 n_halo_ur = {margin[1], margin[3], margin[5]};
112}
113
114#endif // defined(P3M) or defined(DP3M)
Vector implementation and trait types for boost qvm interoperability.
auto const & my_right() const
Right (top, back) corner of this nodes local box.
Definition LocalBox.hpp:47
auto const & my_left() const
Left (bottom, front) corner of this nodes local box.
Definition LocalBox.hpp:45
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.
Definition Vector.hpp:111
This file contains the defaults for ESPResSo.
#define ROUND_ERROR_PREC
Precision for capture of round off errors.
Definition config.hpp:66
VectorXi< 3 > Vector3i
Definition Vector.hpp:174
Common functions for dipolar and charge P3M.
static SteepestDescentParameters params
Currently active steepest descent instance.
Utils::Vector3i ur_no_halo
Utils::Vector3i ld_ind
index of lower left corner of the local mesh in the global mesh.
Utils::Vector3i dim
dimension (size) of local mesh including halo layers.
int size
number of local mesh points.
void calc_local_ca_mesh(P3MParameters const &params, LocalBox const &local_geo, double skin, double space_layer)
Calculate properties of the local FFT mesh for the charge assignment process.
Definition common.cpp:34
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 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::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.