JDFTx  1.2.0
IonicMinimizer.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_IONICMINIMIZER_H
21 #define JDFTX_ELECTRONIC_IONICMINIMIZER_H
22 
23 #include <electronic/common.h>
24 #include <electronic/RadialFunction.h>
25 #include <core/Minimize.h>
26 #include <core/vector3.h>
27 #include <core/matrix3.h>
28 #include <vector>
29 
31 struct IonicGradient : std::vector< std::vector< vector3<> > >
32 {
33  void init(const IonInfo&);
34  void print(const Everything&, FILE*, const char* prefix="force") const;
35 
36  IonicGradient& operator*=(double);
37  IonicGradient& operator+=(const IonicGradient&);
38 
39  IonicGradient operator*(double) const;
40  IonicGradient operator+(const IonicGradient&) const;
41  IonicGradient operator-(const IonicGradient&) const;
42 };
43 
44 void axpy(double alpha, const IonicGradient& x, IonicGradient& y);
45 double dot(const IonicGradient& x, const IonicGradient& y);
47 void randomize(IonicGradient& x);
48 
49 IonicGradient operator*(const matrix3<>&, const IonicGradient&);
50 
51 
52 class IonicMinimizer : public Minimizable<IonicGradient>
53 { Everything& e;
54 
55 public:
57  //Virtual functions from Minimizable:
58  void step(const IonicGradient& dir, double alpha);
59  double compute(IonicGradient* grad, IonicGradient* Kgrad);
60  bool report(int iter);
61  void constrain(IonicGradient&);
62  static const double maxAtomTestDisplacement; //maximum allowed atom displacement in test step
63  static const double maxWfnsDragDisplacement; //maximum atom displacement for which wavefunction drag is allowed
64  double safeStepSize(const IonicGradient& dir) const; //enforces IonicMinimizer::maxAtomTestDisplacement on test step size
65  double sync(double x) const;
66 
67  double minimize(const MinimizeParams& params);
68 private:
69  bool populationAnalysisPending;
70  bool skipWfnsDrag;
71 };
72 
73 #endif // JDFTX_ELECTRONIC_IONICMINIMIZER_H
void randomize(TptrCollection &x)
Initialize to normal random numbers:
Definition: ScalarFieldArray.h:154
Definition: IonInfo.h:46
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
Parameters to control the minimization algorithm.
Definition: MinimizeParams.h:29
Tptr clone(const Tptr &X)
Clone (NOTE: operator= is by reference for the ScalarField classes)
Definition: Operators.h:111
Definition: IonicMinimizer.h:52
Definition: Everything.h:41
Nonlinear minimization templates.
void init(const IonInfo &)
initialize to zeroes with the correct species and atom numbers for iInfo
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
Object to hold all the forces.
Definition: IonicMinimizer.h:31