1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2016 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // ExternalPotential.h
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 #ifndef EXTERNALPOTENTIAL_H
19 #define EXTERNALPOTENTIAL_H
20 
21 #include <vector>
22 #include <string>
23 #include "Sample.h"
24 #include "ChargeDensity.h"
25 
26 class Sample;
27 
28 class ExternalPotential
29 {
30   private:
31 
32   Sample& s_;
33   int n_[3];               // real space grid size in 3 dimensions
34                            // read from cube file in cube file mode,
35                            // otherwise must be given in constructor
36   double ecut_;
37   double magnitude_;       // the magnitude of external potential, defined as
38                            // the average of its largest 0.1% (absolute) values
39   double amplitude_;       // overall scaling factor of external potential
40   vector<double> vext_r_;  // vext in real space
41   std::string filename_;   // file name for external potential
42   std::string fmt_;        // file format: "cube" or "xml"
43 
44   public:
45 
46   ExternalPotential(Sample& s, std::string name, std::string fmt="xml"):
s_(s)47     s_(s), filename_(name), ecut_(0.0), amplitude_(1.0), magnitude_(0.0),
48     fmt_(fmt)
49   {
50     assert( fmt_ == "cube" || fmt_ == "xml" );
51   }
~ExternalPotential()52   ~ExternalPotential() {}
53 
n(int i)54   int n(int i) const { return n_[i]; }
ecut(void)55   double ecut(void) const { return ecut_; }
magnitude(void)56   double magnitude(void) const { return magnitude_; }
amplitude(void)57   double amplitude(void) const { return amplitude_; }
filename(void)58   std::string filename(void) const { return filename_; }
v(size_t i)59   double v(size_t i) const { return amplitude_ * vext_r_[i]; }
60   void update(const ChargeDensity& cd);
set_amplitude(double a)61   void set_amplitude(double a) { amplitude_ = a; }
reverse(void)62   void reverse(void) {amplitude_ *= -1; }
63   double compute_eext(const ChargeDensity& cd);
64 };
65 #endif
66