ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
common.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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) || defined(DP3M)
25
26#include "common.hpp"
27
28#include "LocalBox.hpp"
29
30#include <utils/Vector.hpp>
31#include <utils/constants.hpp>
32#include <utils/math/sqr.hpp>
33
34#include <cmath>
35#include <stdexcept>
36
37double p3m_analytic_cotangent_sum(int n, double mesh_i, int cao) {
38 auto const c =
39 Utils::sqr(std::cos(Utils::pi() * mesh_i * static_cast<double>(n)));
40
41 switch (cao) {
42 case 1: {
43 return 1.0;
44 }
45 case 2: {
46 return (1.0 + c * 2.0) / 3.0;
47 }
48 case 3: {
49 return (2.0 + c * (11.0 + c * 2.0)) / 15.0;
50 }
51 case 4: {
52 return (17.0 + c * (180.0 + c * (114.0 + c * 4.0))) / 315.0;
53 }
54 case 5: {
55 return (62.0 + c * (1072.0 + c * (1452.0 + c * (247.0 + c * 2.0)))) /
56 2835.0;
57 }
58 case 6: {
59 return (1382.0 +
60 c * (35396.0 +
61 c * (83021.0 + c * (34096.0 + c * (2026.0 + c * 4.0))))) /
62 155925.0;
63 }
64 case 7: {
65 return (21844.0 +
66 c * (776661.0 +
67 c * (2801040.0 +
68 c * (2123860.0 +
69 c * (349500.0 + c * (8166.0 + c * 4.0)))))) /
70 6081075.0;
71 }
72 default: {
73 throw std::logic_error("Invalid value cao=" + std::to_string(cao));
74 }
75 }
76}
77
79 LocalBox const &local_geo, double skin,
80 double space_layer) {
81 int i;
82 int ind[3];
83 // total skin size
84 auto const full_skin = Utils::Vector3d{params.cao_cut} +
86 Utils::Vector3d{0., 0., space_layer};
87 // inner left down corner
88 auto const &inner_ld_pos = local_geo.my_left();
89 // inner up right corner
90 auto const &inner_ur_pos = local_geo.my_right();
91 // outer up right corner
92 auto const outer_ur_pos = inner_ur_pos + full_skin;
93 // outer left down corner
94 auto const outer_ld_pos = inner_ld_pos - full_skin;
95 // convert spatial positions to grid positions
96 auto const inner_ld_grid_pos = params.calc_grid_pos(inner_ld_pos);
97 auto const inner_ur_grid_pos = params.calc_grid_pos(inner_ur_pos);
98 auto const outer_ld_grid_pos = params.calc_grid_pos(outer_ld_pos);
99 auto const outer_ur_grid_pos = params.calc_grid_pos(outer_ur_pos);
100
101 /* inner left down grid point (global index) */
102 for (i = 0; i < 3; i++)
103 in_ld[i] = static_cast<int>(std::ceil(inner_ld_grid_pos[i]));
104 /* inner up right grid point (global index) */
105 for (i = 0; i < 3; i++)
106 in_ur[i] = static_cast<int>(std::floor(inner_ur_grid_pos[i]));
107
108 /* correct roundoff errors at boundary */
109 for (i = 0; i < 3; i++) {
110 if (inner_ur_grid_pos[i] - in_ur[i] < ROUND_ERROR_PREC)
111 in_ur[i]--;
112 if (inner_ld_grid_pos[i] - in_ld[i] + 1. < ROUND_ERROR_PREC)
113 in_ld[i]--;
114 }
115 /* inner grid dimensions */
116 for (i = 0; i < 3; i++)
117 inner[i] = in_ur[i] - in_ld[i] + 1;
118 /* index of left down grid point in global mesh */
119 for (i = 0; i < 3; i++)
120 ld_ind[i] = static_cast<int>(std::ceil(outer_ld_grid_pos[i]));
121 /* left down margin */
122 for (i = 0; i < 3; i++)
123 margin[i * 2] = in_ld[i] - ld_ind[i];
124 /* up right grid point */
125 for (i = 0; i < 3; i++)
126 ind[i] = static_cast<int>(std::floor(outer_ur_grid_pos[i]));
127 /* correct roundoff errors at up right boundary */
128 for (i = 0; i < 3; i++)
129 if (outer_ur_grid_pos[i] - ind[i] == 0.)
130 ind[i]--;
131 /* up right margin */
132 for (i = 0; i < 3; i++)
133 margin[(i * 2) + 1] = ind[i] - in_ur[i];
134
135 /* grid dimension */
136 size = 1;
137 for (i = 0; i < 3; i++) {
138 dim[i] = ind[i] - ld_ind[i] + 1;
139 size *= dim[i];
140 }
141
142 /* reduce inner grid indices from global to local */
143 for (i = 0; i < 3; i++)
144 in_ld[i] = margin[i * 2];
145 for (i = 0; i < 3; i++)
146 in_ur[i] = margin[i * 2] + inner[i];
147
148 q_2_off = dim[2] - params.cao;
149 q_21_off = dim[2] * (dim[1] - params.cao);
150}
151
152#endif /* defined(P3M) || 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 Vector< T, N > broadcast(T const &s)
Create a vector that has all entries set to one value.
Definition Vector.hpp:110
double p3m_analytic_cotangent_sum(int n, double mesh_i, int cao)
One of the aliasing sums used to compute k-space errors.
Definition common.cpp:37
Common functions for dipolar and charge P3M.
This file contains the defaults for ESPResSo.
#define ROUND_ERROR_PREC
Precision for capture of round off errors.
Definition config.hpp:66
DEVICE_QUALIFIER constexpr T pi()
Ratio of diameter and circumference of a circle.
Definition constants.hpp:36
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:26
static SteepestDescentParameters params
Currently active steepest descent instance.
Utils::Vector3i dim
dimension (size) of local mesh.
Definition common.hpp:186
int in_ur[3]
inner up right grid point + (1,1,1)
Definition common.hpp:199
int size
number of local mesh points.
Definition common.hpp:188
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:78
int in_ld[3]
inner left down grid point
Definition common.hpp:197
int margin[6]
number of margin mesh points.
Definition common.hpp:201
int q_2_off
offset between mesh lines of the last dimension
Definition common.hpp:205
int inner[3]
dimension of mesh inside node domain.
Definition common.hpp:195
int ld_ind[3]
index of lower left corner of the local mesh in the global mesh.
Definition common.hpp:191
int q_21_off
offset between mesh lines of the two last dimensions
Definition common.hpp:207
Structure to hold P3M parameters and some dependent variables.
Definition common.hpp:67