SIRIUS 7.5.0
Electronic structure library and applications
check_gvec.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2019 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file check_gvec.hpp
21 *
22 * \brief Check G-vector symmetry.
23 */
24
25#ifndef __CHECK_GVEC_HPP__
26#define __CHECK_GVEC_HPP__
27
29
30namespace sirius {
31
32inline void check_gvec(fft::Gvec const& gvec__, Crystal_symmetry const& sym__)
33{
34 PROFILE("sirius::check_gvec");
35
36 #pragma omp parallel for
37 for (int isym = 0; isym < sym__.size(); isym++) {
38 auto sm = sym__[isym].spg_op.R;
39
40 for (int igloc = 0; igloc < gvec__.count(); igloc++) {
41 auto gv = gvec__.gvec<index_domain_t::local>(igloc);
42 /* apply symmetry operation to the G-vector */
43 auto gv_rot = dot(gv, sm);
44
45 //== /* check limits */
46 //== for (int x: {0, 1, 2}) {
47 //== auto limits = gvec__.fft_box().limits(x);
48 //== /* check boundaries */
49 //== if (gv_rot[x] < limits.first || gv_rot[x] > limits.second) {
50 //== std::stringstream s;
51 //== s << "rotated G-vector is outside of grid limits" << std::endl
52 //== << "original G-vector: " << gv << ", length: " << gvec__.cart(ig).length() << std::endl
53 //== << "rotation matrix: " << std::endl
54 //== << sm(0, 0) << " " << sm(0, 1) << " " << sm(0, 2) << std::endl
55 //== << sm(1, 0) << " " << sm(1, 1) << " " << sm(1, 2) << std::endl
56 //== << sm(2, 0) << " " << sm(2, 1) << " " << sm(2, 2) << std::endl
57 //== << "rotated G-vector: " << gv_rot << std::endl
58 //== << "limits: "
59 //== << gvec__.fft_box().limits(0).first << " " << gvec__.fft_box().limits(0).second << " "
60 //== << gvec__.fft_box().limits(1).first << " " << gvec__.fft_box().limits(1).second << " "
61 //== << gvec__.fft_box().limits(2).first << " " << gvec__.fft_box().limits(2).second;
62
63 //== TERMINATE(s);
64 //== }
65 //== }
66 int ig_rot = gvec__.index_by_gvec(gv_rot);
67 /* special case where -G is equal to G */
68 if (gvec__.reduced() && ig_rot < 0) {
69 gv_rot = gv_rot * (-1);
70 ig_rot = gvec__.index_by_gvec(gv_rot);
71 }
72 if (ig_rot < 0 || ig_rot >= gvec__.num_gvec()) {
73 std::stringstream s;
74 s << "rotated G-vector index is wrong" << std::endl
75 << "original G-vector: " << gv << std::endl
76 << "rotation matrix: " << std::endl
77 << sm << std::endl
78 << "rotated G-vector: " << gv_rot << std::endl
79 << "rotated G-vector index: " << ig_rot << std::endl
80 << "number of G-vectors: " << gvec__.num_gvec();
81 RTE_THROW(s);
82 }
83 }
84 }
85}
86
87inline void check_gvec(fft::Gvec_shells const& gvec_shells__, Crystal_symmetry const& sym__)
88{
89 /* check G-vector symmetries */
90 for (int igloc = 0; igloc < gvec_shells__.gvec_count_remapped(); igloc++) {
91 auto G = gvec_shells__.gvec_remapped(igloc);
92
93 for (int i = 0; i < sym__.size(); i++) {
94 auto& invRT = sym__[i].spg_op.invRT;
95 auto gv_rot = dot(invRT, G);
96
97 /* local index of a rotated G-vector */
98 int ig_rot = gvec_shells__.index_by_gvec(gv_rot);
99
100 if (ig_rot == -1) {
101 gv_rot = gv_rot * (-1);
102 ig_rot = gvec_shells__.index_by_gvec(gv_rot);
103 if (ig_rot == -1) {
104 std::stringstream s;
105 s << "Failed to find a rotated G-vector in the list" << std::endl
106 << " local index of original vector: " << igloc << std::endl
107 << " global index of G-shell: " << gvec_shells__.gvec_shell_remapped(igloc) << std::endl
108 << " original G-vector: " << G << std::endl
109 << " rotated G-vector: " << gv_rot;
110 RTE_THROW(s);
111 }
112 }
113 if (ig_rot >= gvec_shells__.gvec_count_remapped()) {
114 std::stringstream s;
115 s << "G-vector index is above the boundary";
116 RTE_THROW(s);
117 }
118 }
119 }
120}
121
122} // namespace
123
124#endif // __CHECK_GVEC_HPP__
Contains definition and partial implementation of sirius::Crystal_symmetry class.
Namespace of the SIRIUS library.
Definition: sirius.f90:5