JDFTx  1.2.0
RadialSchrodinger.h
1 /*-------------------------------------------------------------------
2 Copyright 2012 Ravishankar Sundararaman
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #ifndef JDFTX_ELECTRONIC_RADIALSCHRODINGER_H
21 #define JDFTX_ELECTRONIC_RADIALSCHRODINGER_H
22 
23 #include <electronic/RadialFunction.h>
24 #include <electronic/matrix.h>
25 #include <core/Minimize.h>
26 #include <core/scalar.h>
27 #include <cstring>
28 #include <vector>
29 #include <map>
30 
33 {
34 public:
37  RadialSchrodinger(const std::vector<double>& rArr, const std::vector<double>& drArr,
38  const std::vector<double>& V, double Z, size_t iMatch=0.);
39 
42  std::vector< std::vector<double> > getFillings(double nElectrons,
43  std::vector< std::vector<double> >* Eptr=0);
44 
46  struct Outputs
47  {
48  std::vector<double>* n;
49  std::vector<double>* Dn;
50  std::vector<double>* tau;
51  std::vector< std::vector< std::vector<complex> > >* z;
52  std::vector< std::vector<double> >* E;
53 
54  Outputs(std::vector<double>* n=0, std::vector<double>* Dn=0, std::vector<double>* tau=0,
55  std::vector< std::vector< std::vector<complex> > >* z=0, std::vector< std::vector<double> >* E=0)
56  : n(n), Dn(Dn), tau(tau), z(z), E(E) {}
57  };
58 
60  double compute(const std::vector< std::vector<double> >& F, Outputs outputs);
61 
62 private:
63  const std::vector<double>& rArr;
64  const std::vector<double>& drArr;
65  std::vector<double> Vsub;
66  double Z;
67  size_t iMatch;
68 
69  std::vector< std::map<int,double> > nodesEmin, nodesEmax;
70  std::vector< std::map<double,double> > cachedEerr;
71  std::vector< std::map<int,double> > cachedE;
72 
76  inline complex schEqn(double r, int iSub, complex z, int l, double E) const
77  { double rInv = r ? 1./r : 0.;
78  double V = Vsub[iSub] - Z*rInv;
79  return complex(z.imag(), 2*(z.real()*(V-E) - z.imag()*(l+1)*rInv));
80  }
81 
90  int solveSchEqn(int l, double E, complex* zSave=0);
91 
97  void locateNodeCount(int l, int nNodes);
98 
100  double getEerr(int l, double E);
101 
103  double findE(int l, double Elo, double Ehi, double tol);
104 
106  double getEig(int l, int nNodes, complex* zEvec=0);
107 };
108 
109 
111 class InvertKS : public Minimizable<diagMatrix>
112 {
113 public:
115  InvertKS(const RadialFunctionR& nTarget);
116  RadialFunctionR getTau();
117 
118  //Functions for Minimizable interface:
119  void step(const diagMatrix& dV, double alpha);
120  double compute(diagMatrix* E_V);
121  diagMatrix precondition(const diagMatrix& grad);
122 
123 private:
124  diagMatrix V;
125  double nElectrons;
126  const std::vector<double> &r, &dr, &n0;
127  std::vector<double> n;
128  std::vector< std::vector<double> > F;
129 };
130 
131 #endif // JDFTX_ELECTRONIC_RADIALSCHRODINGER_H
std::vector< double > * Dn
density gradient (radial direction, others 0 by symmetry)
Definition: RadialSchrodinger.h:49
Real diagonal matrix.
Definition: matrix.h:31
RadialSchrodinger(const std::vector< double > &rArr, const std::vector< double > &drArr, const std::vector< double > &V, double Z, size_t iMatch=0.)
std::vector< double > * n
electron density
Definition: RadialSchrodinger.h:48
std::vector< std::vector< double > > getFillings(double nElectrons, std::vector< std::vector< double > > *Eptr=0)
A function on a non-uniform real-space radial grid.
Definition: RadialFunction.h:101
Invert Kohn-Sham equations to get effective potential for a given electron density.
Definition: RadialSchrodinger.h:111
Nonlinear minimization templates.
Radial schrodinger equation solver (non-interacting eigen-problem for an atom)
Definition: RadialSchrodinger.h:32
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49
Definition: Minimize.h:46
double compute(const std::vector< std::vector< double > > &F, Outputs outputs)
Compute total non-interacting energy of atom, given its fillings, and collect any optional outputs...
std::vector< double > * tau
kinetic energy density
Definition: RadialSchrodinger.h:50
Optional outputs from compute: retrieve all non-null quantities.
Definition: RadialSchrodinger.h:46
std::vector< std::vector< std::vector< complex > > > * z
eigenfunctions indexed by l and nNodes. Each z = (u, u&#39;) (See schEqn)
Definition: RadialSchrodinger.h:51
std::vector< std::vector< double > > * E
eigenvalues indexed by l and nNodes
Definition: RadialSchrodinger.h:52