JDFTx  1.1.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> Y;
30  std::vector<matrix> B;
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);
42 void randomize(ElecGradient& x);
43 
44 class ElecMinimizer : public Minimizable<ElecGradient>
45 {
46  Everything& e;
47  ElecVars& eVars;
48  ElecInfo& eInfo;
49  ElecGradient Kgrad;
50  double Knorm;
51 public:
53 
54  //Virtual functions from Minimizable:
55  void step(const ElecGradient& dir, double alpha);
56  double compute(ElecGradient* grad);
57  ElecGradient precondition(const ElecGradient& grad);
58  bool report(int iter);
59  void constrain(ElecGradient&);
60  double sync(double x) const;
61 };
62 
63 void bandMinimize(Everything& e);
64 void elecMinimize(Everything& e);
65 void elecFluidMinimize(Everything& e);
66 void convergeEmptyStates(Everything& e);
67 
68 #endif // JDFTX_ELECTRONIC_ELECMINIMIZER_H
void randomize(TptrCollection &x)
Initialize to normal random numbers:
Definition: ScalarFieldArray.h:157
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
Definition: ElecMinimizer.h:44
void init(const Everything &e)
initialize Y and B 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:45
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