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
46protected:
47 int llocal() const { return llocal_; }
48
49 int nchannels() const { return nchannels_; }
50
51 double &d_ij(int l, int i, int j) {
52 assert(l >= 0 && l <= lmax_);
53 assert(i >= 0 && i <= nchannels());
54 assert(j >= 0 && j <= nchannels());
55
56 return dij_[l * nchannels() * nchannels() + i * nchannels() + j];
57 }
58
59 void extrapolate_first_point(std::vector<double> &function_) const {
60
61 assert(function_.size() >= 4);
62 assert(grid_.size() >= 4);
63
64 double x1 = grid_[1];
65 double x2 = grid_[2];
66 double x3 = grid_[3];
67 double f1 = function_[1];
68 double f2 = function_[2];
69 double f3 = function_[3];
70
71 // obtained from:
72 // 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
73
74 function_[0] = f1 * x2 * x3 * (x2 - x3) + f2 * x1 * x3 * (x3 - x1) +
75 f3 * x1 * x2 * (x1 - x2);
76 function_[0] /= (x1 - x2) * (x1 - x3) * (x2 - x3);
77 }
78
79 std::vector<double> dij_;
80 int llocal_;
81 int start_point_;
82 int nchannels_;
83};
84
85} // namespace pseudopotential
86
87#endif
real(real64) f3
Definition: pcm_eom.F90:200
real(real64) f2
Definition: pcm_eom.F90:200
real(real64) f1
Definition: pcm_eom.F90:200
ptrdiff_t l
Definition: operate_inc.c:12
ptrdiff_t i
Definition: operate_inc.c:12
ptrdiff_t j
Definition: operate_inc.c:12