Wavefunction.h 4.31 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 24
// Wavefunction.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef WAVEFUNCTION_H
#define WAVEFUNCTION_H

#include "D3vector.h"
#include "UnitCell.h"
#include <vector>
Francois Gygi committed
25
#include <complex>
Francois Gygi committed
26

27
class SharedFilePtr;
Francois Gygi committed
28 29 30 31 32 33 34 35
class SlaterDet;
class Context;

class Wavefunction
{
  private:

  const Context& ctxt_;
36

Francois Gygi committed
37 38 39 40
  int nel_;           // number of electrons
  int nempty_;        // number of empty states
  int nspin_;         // number of spins (1 or 2)
  int deltaspin_;     // number of spin excitations
41

Francois Gygi committed
42
  int nrowmax_;       // maximum number of rows of a spincontext
43

Francois Gygi committed
44 45 46
  UnitCell cell_ ;    // unit cell
  UnitCell refcell_ ; // reference cell
  double   ecut_ ;    // energy cutoff
47

48 49
  std::vector<double>    weight_;  // weight[ikp]
  std::vector<D3vector>  kpoint_;  // kpoint[ikp]
50

Francois Gygi committed
51 52 53 54
  std::vector<int> nst_;  // nst_[ispin]
  const Context* spincontext_;   // context used for spin reductions
  const Context* kpcontext_;     // context used for kp reductions
  const Context* sdcontext_;     // context of local SlaterDet instances
55
  std::vector<std::vector<SlaterDet*> > sd_; // local SlaterDets sd_[ispin][ikp]
56

57 58
  void create_contexts();
  void allocate(); // allocate SlaterDet's
Francois Gygi committed
59 60 61
  void deallocate();
  void compute_nst();
  void resize(); // resize SlaterDets if ecut,cell,refcell,or nst have changed
62

Francois Gygi committed
63
  public:
64

Francois Gygi committed
65 66 67 68
  Wavefunction(const Context& ctxt);
  Wavefunction(const Wavefunction& wf);
  ~Wavefunction();
  Wavefunction& operator=(const Wavefunction& wf);
69

Francois Gygi committed
70 71 72 73 74 75 76
  const Context& context(void) const { return ctxt_; }
  const UnitCell& cell(void) const { return cell_; }
  const UnitCell& refcell(void) const { return refcell_; }
  const D3vector kpoint(int ikp) const { return kpoint_[ikp]; }
  double weight(int ikp) const { return weight_[ikp]; }
  double ecut(void) const { return ecut_; }
  SlaterDet* sd(int ispin, int ikp) const { return sd_[ispin][ikp]; }
Francois Gygi committed
77 78 79 80

  const Context* spincontext(void) const { return spincontext_; }
  const Context* kpcontext(void) const { return kpcontext_; }
  const Context* sdcontext(void) const { return sdcontext_; }
Francois Gygi committed
81 82 83 84 85 86 87 88
  int nkp(void) const;            // number of k points
  int nel(void) const;            // total number of electrons
  int nst(int ispin) const;       // number of states of spin ispin
  int nst(void) const;            // number of states
  int nempty(void) const;         // number of empty states
  int nspin(void) const;          // number of spins
  int deltaspin(void) const;      // number of spin excitations
  int nrowmax(void) const { return nrowmax_; }
89

Francois Gygi committed
90 91 92 93
  double spin(void) const;        // total spin

  void resize(const UnitCell& cell, const UnitCell& refcell, double ecut);
  void resize(double ec) { resize(cell_,refcell_,ec); }
Francois Gygi committed
94
  void init(void); // initialize with lowest plane waves
95
  void clear(void); // initialize with zero
Francois Gygi committed
96
  void reset(void); // reset to single kpoint, ecut=0
Francois Gygi committed
97 98 99 100 101 102 103
  void set_nel(int nel);
  void set_nempty(int nempty);
  void set_nspin(int nspin);
  void set_deltaspin(int deltaspin);
  void set_nrowmax(int n);
  void add_kpoint(D3vector kpoint, double weight);
  void del_kpoint(D3vector kpoint);
104
  void move_kpoint(D3vector kpoint, D3vector new_kpoint);
Francois Gygi committed
105 106

  void randomize(double amplitude);
107

Francois Gygi committed
108 109 110 111
  void update_occ(double fermitemp);
  double entropy(void) const; // dimensionless entropy
  void gram(void);
  void riccati(Wavefunction& wf);
Francois Gygi committed
112 113
  void align(Wavefunction& wf);
  void diag(Wavefunction& dwf, bool eigvec);
114

Francois Gygi committed
115
  std::complex<double> dot(const Wavefunction& wf) const;
116

117
  void print(std::ostream& os, std::string encoding, std::string tag) const;
118
  void write(SharedFilePtr& fh, std::string encoding, std::string tag) const;
119
  void info(std::ostream& os, std::string tag) const;
120 121

  friend class WavefunctionHandler;
Francois Gygi committed
122
};
123
std::ostream& operator << ( std::ostream& os, const Wavefunction& wf );
Francois Gygi committed
124
#endif