n2p2 - A neural network potential package
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
26Kvector::Kvector() : k (Vec3D()),
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 // Compute k-grid (only half sphere because of symmetry)
61 for (int i = 0; i <= n[0]; ++i)
62 {
63 int sj = -n[1];
64 if (i == 0) sj = 0;
65 for (int j = sj; j <= n[1]; ++j)
66 {
67 int sk = -n[2];
68 if (i == 0 && j == 0) sk = 0;
69 for (int k = sk; k <= n[2]; ++k)
70 {
71 if (i == 0 && j == 0 && k == 0) continue;
72 Vec3D kv = i * kbox[0] + j * kbox[1] + k * kbox[2];
73 double knorm2 = kv.norm2();
74 if (kv.norm2() < kCut * kCut)
75 {
76 kvectors.push_back(kv);
77 kvectors.back().knorm2 = knorm2; // TODO: Really necessary?
78 kvectors.back().coeff = exp(-0.5 * eta * eta * knorm2)
79 * 2.0 * pre / knorm2;
80 }
81 }
82 }
83 }
84}
85
86void KspaceGrid::calculatePbcCopies(double cutoffRadius)
87{
88 Vec3D axb;
89 Vec3D axc;
90 Vec3D bxc;
91
92 axb = kbox[0].cross(kbox[1]).normalize();
93 axc = kbox[0].cross(kbox[2]).normalize();
94 bxc = kbox[1].cross(kbox[2]).normalize();
95
96 double proja = fabs(kbox[0] * bxc);
97 double projb = fabs(kbox[1] * axc);
98 double projc = fabs(kbox[2] * axb);
99
100 n[0] = 0;
101 n[1] = 0;
102 n[2] = 0;
103 while (n[0] * proja <= cutoffRadius) n[0]++;
104 while (n[1] * projb <= cutoffRadius) n[1]++;
105 while (n[2] * projc <= cutoffRadius) n[2]++;
106
107 return;
108}
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:61
double pre
Ewald sum prefactor .
Definition: Kspace.h:55
Vec3D kbox[3]
Reciprocal box vectors.
Definition: Kspace.h:59
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:47
void calculatePbcCopies(double cutoffRadius)
Compute box copies in each direction.
Definition: Kspace.cpp:86
double volume
Volume of real box.
Definition: Kspace.h:53
double kCut
Cutoff in reciprocal space.
Definition: Kspace.h:49
int n[3]
Required box copies in each box vector direction.
Definition: Kspace.h:57
Kvector()
Constructor.
Definition: Kspace.cpp:26
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 & normalize()
Normalize vector, norm equals 1.0 afterwards.
Definition: Vec3D.h:309
Vec3D cross(Vec3D const &v) const
Cross product, argument vector is second in product.
Definition: Vec3D.h:319