JDFTx  1.2.0
LatticeMinimizer.h
1 /*-------------------------------------------------------------------
2 Copyright 2012 Deniz Gunceler, 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_LATTICEMINIMIZER_H
21 #define JDFTX_ELECTRONIC_LATTICEMINIMIZER_H
22 
23 #include <electronic/common.h>
24 #include <core/Minimize.h>
25 #include <core/matrix3.h>
26 
27 //Functions required by Minimizable<matrix3<>>
28 void axpy(double alpha, const matrix3<>& x, matrix3<>& y);
29 double dot(const matrix3<>& x, const matrix3<>& y);
30 matrix3<> clone(const matrix3<>& x);
31 void randomize(matrix3<>& x);
32 
33 class LatticeMinimizer : public Minimizable<matrix3<>>
34 {
35 public:
37 
38  //Virtual functions from Minimizable:
39  void step(const matrix3<>& dir, double alpha);
40  double compute(matrix3<>* grad, matrix3<>* Kgrad);
41  bool report(int iter);
42  void constrain(matrix3<>&);
43  double safeStepSize(const matrix3<>& dir) const;
44  double sync(double x) const;
45 
47  std::vector<double> calculateStress();
48 
51  std::vector<matrix3<>> strainBasis;
52 
54  void restore();
55 
56 private:
57  Everything& e;
58  matrix3<> Rorig;
59  matrix3<> strain;
60  bool skipWfnsDrag;
61 
62  double h;
63  double centralDifference(matrix3<> direction);
64 
67  static void updateLatticeDependent(Everything& e, bool ignoreElectronic=false);
68 
69  friend class IonDynamics;
70 };
71 
72 #endif // JDFTX_ELECTRONIC_LATTICEMINIMIZER_H
Definition: IonDynamics.h:30
void randomize(TptrCollection &x)
Initialize to normal random numbers:
Definition: ScalarFieldArray.h:154
std::vector< matrix3<> > strainBasis
Definition: LatticeMinimizer.h:51
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
double safeStepSize(const matrix3<> &dir) const
Override to return maximum safe step size along a given direction. Steps can be arbitrarily large by ...
Definition: LatticeMinimizer.h:33
void step(const matrix3<> &dir, double alpha)
Move the state in parameter space along direction dir with scale alpha.
Tptr clone(const Tptr &X)
Clone (NOTE: operator= is by reference for the ScalarField classes)
Definition: Operators.h:111
void restore()
Restores the lattice to the original state (i.e. strain=0)
void constrain(matrix3<> &)
Constrain search directions to the space of free directions for minimize.
Definition: Everything.h:41
Nonlinear minimization templates.
double compute(matrix3<> *grad, matrix3<> *Kgrad)
Returns the objective function at the current state and store the gradient in grad and preconditioned...
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
std::vector< double > calculateStress()
Calculates the stresses along the strain directions.
bool report(int iter)
double sync(double x) const
All processes minimize together; make sure scalars are in sync to round-off error.