EnergyFunctional.h 3.93 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22 23
// EnergyFunctional.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef ENERGYFUNCTIONAL_H
#define ENERGYFUNCTIONAL_H

#include <complex>
#include <vector>
24
#include <valarray>
Francois Gygi committed
25 26 27
#include <map>
#include <string>
#include "StructureFactor.h"
28
#include "ElectricEnthalpy.h"
Francois Gygi committed
29 30
#include "Timer.h"

31
class D3vector;
Francois Gygi committed
32 33 34 35
class Sample;
class Basis;
class AtomSet;
class Wavefunction;
36
class ChargeDensity;
Francois Gygi committed
37 38
class UnitCell;
class FourierTransform;
Francois Gygi committed
39
class XCOperator;
Francois Gygi committed
40
class NonLocalPotential;
41
class ConfinementPotential;
Francois Gygi committed
42

43
typedef std::map<std::string,Timer> TimerMap;
Francois Gygi committed
44 45 46 47

class EnergyFunctional
{
  private:
48

Francois Gygi committed
49
  Sample& s_;
50
  ChargeDensity& cd_;
Francois Gygi committed
51 52
  Basis* vbasis_;
  FourierTransform *vft;
53
  std::vector<FourierTransform*> ft;
Francois Gygi committed
54
  StructureFactor sf;
Francois Gygi committed
55
  XCOperator* xco;
56
  ElectricEnthalpy* el_enth_;
Francois Gygi committed
57
  std::vector<std::vector<NonLocalPotential*> > nlp;    // nlp[ispin][ikp]
58
  std::vector<ConfinementPotential*> cfp; // cfp[ikp]
59

60 61
  std::vector<std::vector<double> > vps, dvps, rhops, rhocore_sp_g;
  std::vector<double> rhocore_r;
62
  std::vector<std::complex<double> > tmp_r, vion_local_g,
63
    dvion_local_g, vxc_g, vlocal_g, rhopst, rhogt, rhoelg, vtemp, rhocore_g;
64

65
  std::vector<std::vector<double> > tau0, fion_esr;
Francois Gygi committed
66
  std::vector<std::vector<double> > fext;
67 68
  std::vector<double> zv_, rcps_;
  std::vector<int> na_;
Francois Gygi committed
69
  int nsp_;
70
  double ekin_, econf_, eps_, enl_, ehart_, ehart_e_, ehart_ep_, ehart_p_,
Francois Gygi committed
71
         ecoul_, exc_, esr_, eself_, ets_, eexf_, eext_, etotal_;
72
  double dxc_;
73
  double epv_, eefield_, enthalpy_;
74
  std::valarray<double> sigma_ekin,sigma_econf,sigma_eps,sigma_ehart,sigma_exc,
75
    sigma_enl, sigma_esr, sigma;
Francois Gygi committed
76

77 78
  bool core_charge_;

Francois Gygi committed
79 80
  public:

81
  std::vector<std::vector<double> > v_r;
82
  std::vector<std::vector<double> > vxc_r;
Francois Gygi committed
83
  mutable TimerMap tmap;
84

Francois Gygi committed
85
  double energy(bool compute_hpsi, Wavefunction& dwf,
86 87
    bool compute_forces, std::vector<std::vector<double> >& fion,
    bool compute_stress, std::valarray<double>& sigma);
88

Francois Gygi committed
89 90
  double etotal(void) const { return etotal_; }
  double ekin(void) const { return ekin_; }
91
  double econf(void) const { return econf_; }
Francois Gygi committed
92 93 94
  double eps(void) const { return eps_; }
  double enl(void) const { return enl_; }
  double ehart(void) const { return ehart_; }
95 96 97
  double ehart_e(void) const { return ehart_e_; }
  double ehart_ep(void) const { return ehart_ep_; }
  double ehart_p(void) const { return ehart_p_; }
Francois Gygi committed
98 99
  double ecoul(void) const { return ecoul_; }
  double exc(void) const { return exc_; }
100
  double dxc(void) const { return dxc_; }
Francois Gygi committed
101 102
  double esr(void) const { return esr_; }
  double eself(void) const { return eself_; }
103
  double ets(void) const { return ets_; }
Francois Gygi committed
104
  double eexf(void) const { return eexf_; }
105
  double eefield(void) const { return eefield_; }
106 107
  double epv(void) const { return epv_; }
  double enthalpy(void) const { return enthalpy_; }
Francois Gygi committed
108
  double eext(void) const { return eext_; }
109 110

  ElectricEnthalpy* el_enth() { return el_enth_; }
111

112
  const ConfinementPotential *confpot(int ikp) const { return cfp[ikp]; }
113

114
  void update_vhxc(bool compute_stress, bool update_vh, bool update_vxc);
115
  // update both vh and vxc
116 117 118 119
  void update_vhxc(bool compute_stress)
  {
    update_vhxc(compute_stress, true, true);
  }
120

Francois Gygi committed
121 122
  void atoms_moved(void);
  void cell_moved(void);
123

124
  void print(std::ostream& os) const;
Francois Gygi committed
125

126
  EnergyFunctional(Sample& s, ChargeDensity& cd);
Francois Gygi committed
127 128
  ~EnergyFunctional();
};
129
std::ostream& operator << ( std::ostream& os, const EnergyFunctional& e );
Francois Gygi committed
130
#endif