Octopus
upf.hpp
Go to the documentation of this file.
1#ifndef PSEUDO_UPF_HPP
2#define PSEUDO_UPF_HPP
3
4/*
5 Copyright (C) 2018 Xavier Andrade
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#include <cassert>
23#include <cmath>
24#include <fstream>
25#include <iostream>
26#include <sstream>
27#include <vector>
28
29#include "anygrid.hpp"
30
31namespace pseudopotential {
32
33class upf : public pseudopotential::anygrid {
34
35public:
36 upf(bool uniform_grid) : pseudopotential::anygrid(uniform_grid) {}
37
38 double d_ij(int l, int i, int j) const {
39 assert(l >= 0 && l <= lmax_);
40 assert(i >= 0 && i < nchannels());
41 assert(j >= 0 && j < nchannels());
42
43 return dij_[l * nchannels() * nchannels() + i * nchannels() + j];
44 }
45
46 bool has_qij_integrals() const { return !qij_.empty(); }
47
48 double q_ij(int l, int i, int j) const {
49 assert(l >= 0 && l <= lmax_);
50 assert(i >= 0 && i < nchannels());
51 assert(j >= 0 && j < nchannels());
52
53 if (qij_.empty())
54 return 0.0;
55
56 return qij_[l * nchannels() * nchannels() + i * nchannels() + j];
57 }
58
59 bool has_radial_augmentation() const { return !qfunc_.empty(); }
60
61 bool radial_augmentation_has_angular_channels() const {
62 return has_radial_augmentation() && qfunc_with_l_;
63 }
64
65 int radial_augmentation_lmax() const {
66 if (!has_radial_augmentation())
67 return -1;
68
69 return qfunc_lmax_;
70 }
71
72 void radial_augmentation(int i, int j, int ltot,
73 std::vector<double> &val) const {
74 assert(i >= 0 && i < nprojectors());
75 assert(j >= 0 && j < nprojectors());
76 assert(ltot >= 0 && ltot <= qfunc_lmax_);
77
78 val.resize(qfunc_mesh_size_);
79 int offset = qfunc_index(i, j, ltot) * qfunc_mesh_size_;
80 for (int ip = 0; ip < qfunc_mesh_size_; ip++)
81 val[ip] = qfunc_[offset + ip];
82 }
83
84protected:
85 int llocal() const { return llocal_; }
86
87 int nchannels() const { return nchannels_; }
88
89 double &d_ij(int l, int i, int j) {
90 assert(l >= 0 && l <= lmax_);
91 assert(i >= 0 && i < nchannels());
92 assert(j >= 0 && j < nchannels());
93
94 return dij_[l * nchannels() * nchannels() + i * nchannels() + j];
95 }
96
97 double &q_ij(int l, int i, int j) {
98 assert(l >= 0 && l <= lmax_);
99 assert(i >= 0 && i < nchannels());
100 assert(j >= 0 && j < nchannels());
101
102 return qij_[l * nchannels() * nchannels() + i * nchannels() + j];
103 }
104
105 void initialize_radial_augmentation(bool with_l, int lmax_aug) {
106 assert(lmax_aug >= 0);
107 qfunc_with_l_ = with_l;
108 qfunc_lmax_ = lmax_aug;
109 qfunc_mesh_size_ = mesh_size();
110 qfunc_.assign(nprojectors() * nprojectors() * (qfunc_lmax_ + 1) *
111 qfunc_mesh_size_,
112 0.0);
113 }
114
115 void set_radial_augmentation(int i, int j, int ltot,
116 std::vector<double> val) {
117 assert(i >= 0 && i < nprojectors());
118 assert(j >= 0 && j < nprojectors());
119 assert(ltot >= 0 && ltot <= qfunc_lmax_);
120 assert(val.size() == grid_.size());
121
122 interpolate(val);
123 assert(int(val.size()) == qfunc_mesh_size_);
124
125 int offset_ij = qfunc_index(i, j, ltot) * qfunc_mesh_size_;
126 int offset_ji = qfunc_index(j, i, ltot) * qfunc_mesh_size_;
127 for (int ip = 0; ip < qfunc_mesh_size_; ip++) {
128 qfunc_[offset_ij + ip] = val[ip];
129 qfunc_[offset_ji + ip] = val[ip];
130 }
131 }
132
133 int qfunc_index(int i, int j, int ltot) const {
134 assert(i >= 0 && i < nprojectors());
135 assert(j >= 0 && j < nprojectors());
136 assert(ltot >= 0 && ltot <= qfunc_lmax_);
137
138 return (ltot * nprojectors() + i) * nprojectors() + j;
139 }
140
141 void extrapolate_first_point(std::vector<double> &function_) const {
142
143 assert(function_.size() >= 4);
144 assert(grid_.size() >= 4);
145
146 double x1 = grid_[1];
147 double x2 = grid_[2];
148 double x3 = grid_[3];
149 double f1 = function_[1];
150 double f2 = function_[2];
151 double f3 = function_[3];
152
153 // obtained from:
154 // http://www.wolframalpha.com/input/?i=solve+%7Bb*x1%5E2+%2B+c*x1+%2B+d+%3D%3D+f1,++b*x2%5E2+%2B+c*x2+%2B+d+%3D%3D+f2,+b*x3%5E2+%2B+c*x3+%2B+d+%3D%3D+f3+%7D++for+b,+c,+d
155
156 function_[0] = f1 * x2 * x3 * (x2 - x3) + f2 * x1 * x3 * (x3 - x1) +
157 f3 * x1 * x2 * (x1 - x2);
158 function_[0] /= (x1 - x2) * (x1 - x3) * (x2 - x3);
159 }
160
161 std::vector<double> dij_;
162 std::vector<double> qij_;
163 std::vector<double> qfunc_;
164 bool qfunc_with_l_ = false;
165 int qfunc_lmax_ = -1;
166 int qfunc_mesh_size_ = 0;
167 int llocal_;
168 int start_point_;
169 int nchannels_;
170};
171
172} // namespace pseudopotential
173
174#endif
real(real64) f3
Definition: pcm_eom.F90:179
real(real64) f2
Definition: pcm_eom.F90:179
real(real64) f1
Definition: pcm_eom.F90:179
ptrdiff_t l
ptrdiff_t i
ptrdiff_t j