JDFTx  1.2.0
NonlinearPCM.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman, Kendra Letchworth Weaver, Deniz Gunceler
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 
21 #ifndef JDFTX_ELECTRONIC_NONLINEARPCM_H
22 #define JDFTX_ELECTRONIC_NONLINEARPCM_H
23 
24 #include <fluid/PCM.h>
25 #include <core/VectorField.h>
26 #include <core/Minimize.h>
27 #include <core/Pulay.h>
28 
29 namespace NonlinearPCMeval { struct Screening; struct Dielectric; } //Forward declaration of helper classes
30 
32 
33 
34 class NonlinearPCM : public PCM, public Minimizable<ScalarFieldMuEps>, public Pulay<ScalarFieldTilde>
35 {
36 public:
38 
40  NonlinearPCM(const Everything& e, const FluidSolverParams& params);
41  virtual ~NonlinearPCM();
42 
43  bool prefersGummel() const { return true; }
44 
45  void loadState(const char* filename);
46  void saveState(const char* filename) const;
47  void dumpDensities(const char* filenamePattern) const;
48  void minimizeFluid();
49 
51  double operator()(const ScalarFieldMuEps& state, ScalarFieldMuEps& Adiel_state, ScalarFieldTilde* Adiel_rhoExplicitTilde=0, ScalarFieldTilde* Adiel_nCavityTilde=0, bool electricOnly=false) const;
52 
53  // Interface for Minimizable:
54  void step(const ScalarFieldMuEps& dir, double alpha);
55  double compute(ScalarFieldMuEps* grad, ScalarFieldMuEps* Kgrad);
56 
57 protected:
58  void set_internal(const ScalarFieldTilde& rhoExplicitTilde, const ScalarFieldTilde& nCavityTilde);
59  double get_Adiel_and_grad_internal(ScalarFieldTilde& Adiel_rhoExplicitTilde, ScalarFieldTilde& Adiel_nCavityTilde, IonicGradient* extraForces, bool electricOnly) const;
60 
61 private:
62  double pMol, ionNbulk, ionZ;
63  NonlinearPCMeval::Screening* screeningEval;
64  NonlinearPCMeval::Dielectric* dielectricEval;
65  RadialFunctionG preconditioner;
66  std::shared_ptr<RealKernel> metric;
67  RadialFunctionG gLookup, xLookup;
68  std::shared_ptr<class LinearPCM> linearPCM;
69 
70 protected:
71  //Interface for Pulay<ScalarFieldTilde>
72  double cycle(double dEprev, std::vector<double>& extraValues);
73  void axpy(double alpha, const ScalarFieldTilde& X, ScalarFieldTilde& Y) const { ::axpy(alpha, X, Y); }
74  double dot(const ScalarFieldTilde& X, const ScalarFieldTilde& Y) const { return ::dot(X, Y); }
75  size_t variableSize() const { return gInfo.nG * sizeof(complex); }
76  void readVariable(ScalarFieldTilde& X, FILE* fp) const;
77  void writeVariable(const ScalarFieldTilde& X, FILE* fp) const;
78  ScalarFieldTilde getVariable() const;
79  void setVariable(const ScalarFieldTilde&);
80  ScalarFieldTilde precondition(const ScalarFieldTilde&) const;
81  ScalarFieldTilde applyMetric(const ScalarFieldTilde&) const;
82 private:
83  void phiToState(bool setState);
84 };
85 
86 #endif // JDFTX_ELECTRONIC_NONLINEARPCM_H
Pulay mixing to optimize self-consistent field optimization .
Definition: Pulay.h:35
Helper class for dielectric portion of NonlinearPCM.
Definition: PCM_internal.h:351
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
size_t variableSize() const
Number of bytes per variable.
Definition: NonlinearPCM.h:75
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
void axpy(double alpha, const ScalarFieldTilde &X, ScalarFieldTilde &Y) const
Scaled accumulate on variable.
Definition: NonlinearPCM.h:73
Pulay mixing algorithm template.
Helper class for ionic screening portion of NonlinearPCM.
Definition: PCM_internal.h:175
bool prefersGummel() const
Specify whether fluid prefers a gummel loop (true) or is minimized each time (false) ...
Definition: NonlinearPCM.h:43
ScalarFieldMuEps state
State of the solver = the total electrostatic potential.
Definition: NonlinearPCM.h:37
double dot(const ScalarFieldTilde &X, const ScalarFieldTilde &Y) const
Euclidean dot product. Metric applied separately for efficiency.
Definition: NonlinearPCM.h:74
Definition: NonlinearPCM.h:34
G-space radial function stored on a uniform grid (of |G|)
Definition: RadialFunction.h:28
Generic multiplet of data arrays (and specialized to triplets for vector fields in real/reciprocal sp...
Definition: Everything.h:41
Base class for all PCMs.
Definition: PCM.h:29
Nonlinear minimization templates.
Definition: NonlinearPCM.h:29
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49
Definition: Minimize.h:46
Extra parameters for fluids:
Definition: FluidSolverParams.h:93
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