JDFTx  1.2.0
ElecMinimizer.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 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_ELECMINIMIZER_H
21 #define JDFTX_ELECTRONIC_ELECMINIMIZER_H
22 
23 #include <electronic/common.h>
24 #include <electronic/ColumnBundle.h>
25 #include <electronic/matrix.h>
26 #include <core/Minimize.h>
27 
29 { std::vector<ColumnBundle> C;
30  std::vector<matrix> Haux;
31  const ElecInfo* eInfo;
32 
33  void init(const Everything& e);
34 
35  ElecGradient& operator*=(double alpha);
36 };
37 
38 //Functions required for minimize
39 void axpy(double alpha, const ElecGradient& x, ElecGradient& y);
40 double dot(const ElecGradient& x, const ElecGradient& y, double* auxContrib=0);
42 void randomize(ElecGradient& x);
43 
44 class ElecMinimizer : public Minimizable<ElecGradient>
45 {
46 public:
48 
49  //Virtual functions from Minimizable:
50  void step(const ElecGradient& dir, double alpha);
51  double compute(ElecGradient* grad, ElecGradient* Kgrad);
52  bool report(int iter);
53  void constrain(ElecGradient&);
54  double sync(double x) const;
55 
56 private:
57  Everything& e;
58  ElecVars& eVars;
59  ElecInfo& eInfo;
60  std::vector<matrix> KgradHaux;
61  std::vector<matrix> rotPrev;
62  bool rotExists;
63  std::shared_ptr<struct SubspaceRotationAdjust> sra;
64 };
65 
66 void bandMinimize(Everything& e);
67 void elecMinimize(Everything& e);
68 void elecFluidMinimize(Everything& e);
69 void convergeEmptyStates(Everything& e);
70 
71 #endif // JDFTX_ELECTRONIC_ELECMINIMIZER_H
void randomize(TptrCollection &x)
Initialize to normal random numbers:
Definition: ScalarFieldArray.h:154
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
Definition: ElecMinimizer.h:44
void init(const Everything &e)
initialize C and Haux with the correct sizes for everything
ElecGradient & operator*=(double alpha)
scalar multiply
Tptr clone(const Tptr &X)
Clone (NOTE: operator= is by reference for the ScalarField classes)
Definition: Operators.h:111
Definition: ElecMinimizer.h:28
Definition: Everything.h:41
Definition: ElecVars.h:30
Nonlinear minimization templates.
Definition: ElecInfo.h:49
Definition: Minimize.h:46
void axpy(double alpha, const Tptr &X, Tptr &Y)
Generic axpy for complex data types (Note: null pointers are treated as zero)
Definition: Operators.h:158