Loading [MathJax]/extensions/TeX/AMSsymbols.js
n2p2 - A neural network potential package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Kspace.cpp
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17
18#include "Kspace.h"
19#include <iostream>
20#include <fstream>
21
22using namespace std;
23using namespace nnp;
24
25
27 knorm2(0.0 ),
28 coeff (0.0 )
29{
30}
31
33 knorm2(v.norm()),
34 coeff (0.0 )
35{
36}
37
39 kCut (0.0),
40 volume(0.0),
41 pre (0.0)
42{
43}
44
45void KspaceGrid::setup(Vec3D box[3], EwaldSetup& ewaldSetup)
46{
47 volume = fabs(box[0] * (box[1].cross(box[2])));
48 pre = 2.0 * M_PI / volume;
49
50 kbox[0] = pre * box[1].cross(box[2]);
51 kbox[1] = pre * box[2].cross(box[0]);
52 kbox[2] = pre * box[0].cross(box[1]);
53
54 eta = ewaldSetup.params.eta;
55 kCut = ewaldSetup.params.kCut;
56
57 // Compute box copies required in each direction.
59
60 double halfSphere = 1; // TODO
61 if (halfSphere)
62 {
63 // Compute k-grid (only half sphere because of symmetry).
64 for (int i = 0; i <= n[0]; ++i)
65 {
66 int sj = -n[1];
67 if (i == 0) sj = 0;
68 for (int j = sj; j <= n[1]; ++j)
69 {
70 int sk = -n[2];
71 if (i == 0 && j == 0) sk = 0;
72 for (int k = sk; k <= n[2]; ++k)
73 {
74 if (i == 0 && j == 0 && k == 0) continue;
75 Vec3D kv = i * kbox[0] + j * kbox[1] + k * kbox[2];
76 double knorm2 = kv.norm2();
77 if (kv.norm2() < kCut * kCut)
78 {
79 //fprintf(stderr, "sqk = %24.16E\n", kv.norm());
80 kvectors.push_back(kv);
81 kvectors.back().knorm2 = knorm2; // TODO: Necessary?
82 kvectors.back().coeff = exp(-0.5 * eta * eta * knorm2)
83 * 2.0 * pre / knorm2;
84 }
85 }
86 }
87 }
88 }
89 else
90 {
91 // Compute full k-grid.
92 for (int i = -n[0]; i <= n[0]; ++i)
93 {
94 for (int j = -n[1]; j <= n[1]; ++j)
95 {
96 for (int k = -n[2]; k <= n[2]; ++k)
97 {
98 if (i == 0 && j == 0 && k == 0) continue;
99 Vec3D kv = i * kbox[0] + j * kbox[1] + k * kbox[2];
100 double knorm2 = kv.norm2();
101 if (kv.norm2() < kCut * kCut)
102 {
103 kvectors.push_back(kv);
104 kvectors.back().knorm2 = knorm2; // TODO: Necessary?
105 kvectors.back().coeff = exp(-0.5 * eta * eta * knorm2)
106 * 2.0 * pre / knorm2;
107 }
108 }
109 }
110 }
111 }
112}
113
114void KspaceGrid::calculatePbcCopies(double cutoffRadius)
115{
116 Vec3D axb;
117 Vec3D axc;
118 Vec3D bxc;
119
120 axb = kbox[0].cross(kbox[1]).normalize();
121 axc = kbox[0].cross(kbox[2]).normalize();
122 bxc = kbox[1].cross(kbox[2]).normalize();
123
124 double proja = fabs(kbox[0] * bxc);
125 double projb = fabs(kbox[1] * axc);
126 double projc = fabs(kbox[2] * axb);
127
128 n[0] = 0;
129 n[1] = 0;
130 n[2] = 0;
131 while (n[0] * proja <= cutoffRadius) n[0]++;
132 while (n[1] * projb <= cutoffRadius) n[1]++;
133 while (n[2] * projc <= cutoffRadius) n[2]++;
134
135 return;
136}
Setup data for Ewald summation.
Definition EwaldSetup.h:37
EwaldParameters params
Definition EwaldSetup.h:39
std::vector< Kvector > kvectors
Vector containing all k-vectors.
Definition Kspace.h:70
double pre
Ewald sum prefactor .
Definition Kspace.h:64
Vec3D kbox[3]
Reciprocal box vectors.
Definition Kspace.h:68
void setup(Vec3D box[3], EwaldSetup &ewaldSetup)
Set up reciprocal box vectors and eta.
Definition Kspace.cpp:45
KspaceGrid()
Constructor.
Definition Kspace.cpp:38
double eta
Ewald summation eta parameter.
Definition Kspace.h:56
void calculatePbcCopies(double cutoffRadius)
Compute box copies in each direction.
Definition Kspace.cpp:114
double volume
Volume of real box.
Definition Kspace.h:62
double kCut
Cutoff in reciprocal space.
Definition Kspace.h:58
int n[3]
Required box copies in each box vector direction.
Definition Kspace.h:66
Vec3D k
A single k-vector (as Vec3D).
Definition Kspace.h:38
Kvector()
Constructor.
Definition Kspace.cpp:26
double coeff
Precomputed coefficient for Ewald summation.
Definition Kspace.h:42
double knorm2
Square of norm of k-vector.
Definition Kspace.h:40
Definition Atom.h:29
double eta
Width of the gaussian screening charges.
Definition IEwaldTrunc.h:40
double kCut
Cutoff in reciprocal space.
Definition IEwaldTrunc.h:44
Vector in 3 dimensional real space.
Definition Vec3D.h:30
double norm2() const
Calculate square of norm of vector.
Definition Vec3D.h:299
Vec3D cross(Vec3D const &v) const
Cross product, argument vector is second in product.
Definition Vec3D.h:319