31namespace pseudopotential {
33class upf :
public pseudopotential::anygrid {
36 upf(
bool uniform_grid) : pseudopotential::anygrid(uniform_grid) {}
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());
43 return dij_[
l * nchannels() * nchannels() +
i * nchannels() +
j];
46 bool has_qij_integrals()
const {
return !qij_.empty(); }
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());
56 return qij_[
l * nchannels() * nchannels() +
i * nchannels() +
j];
59 bool has_radial_augmentation()
const {
return !qfunc_.empty(); }
61 bool radial_augmentation_has_angular_channels()
const {
62 return has_radial_augmentation() && qfunc_with_l_;
65 int radial_augmentation_lmax()
const {
66 if (!has_radial_augmentation())
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_);
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];
85 int llocal()
const {
return llocal_; }
87 int nchannels()
const {
return nchannels_; }
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());
94 return dij_[
l * nchannels() * nchannels() +
i * nchannels() +
j];
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());
102 return qij_[
l * nchannels() * nchannels() +
i * nchannels() +
j];
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) *
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());
123 assert(
int(val.size()) == qfunc_mesh_size_);
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];
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_);
138 return (ltot * nprojectors() +
i) * nprojectors() +
j;
141 void extrapolate_first_point(std::vector<double> &function_)
const {
143 assert(function_.size() >= 4);
144 assert(grid_.size() >= 4);
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];
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);
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;