SlaterDet.h 3.76 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 25 26 27
// SlaterDet.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef SLATERDET_H
#define SLATERDET_H

class FourierTransform;
#include "Context.h"
#include "Basis.h"
#include "Matrix.h"

#include "D3vector.h"
Francois Gygi committed
28
#include <iosfwd>
Francois Gygi committed
29 30 31
#include "Timer.h"
#include <string>
#include <map>
32 33

class SharedFilePtr;
Francois Gygi committed
34

35
typedef std::map<std::string,Timer> TimerMap;
Francois Gygi committed
36 37 38 39 40 41

class SlaterDet
{
  private:

  const Context& ctxt_;
42
  MPI_Comm my_col_comm_;
43
  Basis* basis_;
Francois Gygi committed
44
  ComplexMatrix c_;
45 46
  std::vector<double> occ_;
  std::vector<double> eig_;
47

Francois Gygi committed
48 49 50 51
  void byteswap_double(size_t n, double* x);
  double fermi(double e, double mu, double fermitemp);

  public:
52

Francois Gygi committed
53 54 55 56 57 58
  mutable TimerMap tmap;

  SlaterDet(const Context& ctxt, D3vector kpoint);
  SlaterDet(const SlaterDet& rhs);
  ~SlaterDet();
  const Context& context(void) const { return ctxt_; }
59 60
  const Basis& basis(void) const { return *basis_; }
  const D3vector kpoint(void) const { return basis_->kpoint(); }
Francois Gygi committed
61 62
  const ComplexMatrix& c(void) const { return c_; }
  ComplexMatrix& c(void) { return c_; }
63 64
  const std::vector<double>& occ(void) const { return occ_; }
  const std::vector<double>& eig(void) const { return eig_; }
Francois Gygi committed
65 66 67 68 69
  int nst(void) const { return c_.n(); }
  int nstloc(void) const { return c_.nloc(); }
  void resize(const UnitCell& cell, const UnitCell& refcell,
              double ecut, int nst);
  void compute_density(FourierTransform& ft, double weight, double* rho) const;
Francois Gygi committed
70
  void rs_mul_add(FourierTransform& ft, const double* v, SlaterDet& sdp) const;
Francois Gygi committed
71 72
  void randomize(double amplitude);
  void cleanup(void);
Francois Gygi committed
73
  void init(void);
Francois Gygi committed
74
  void gram(void);
Francois Gygi committed
75
  void riccati(const SlaterDet& sd);
76 77 78
  void lowdin(void);
  void align(const SlaterDet& sd);
  void ortho_align(const SlaterDet& sd);
Francois Gygi committed
79
  std::complex<double> dot(const SlaterDet& sd) const;
80
  double total_charge(void) const;
Francois Gygi committed
81 82 83
  void update_occ(int nel, int nspin);
  void update_occ(int nspin, double mu, double temp);
  double eig(int i) const { return eig_[i]; };
84 85
  const double* eig_ptr(void) const { return &eig_[0]; }
  const double* eig_ptr(int i) const { return &eig_[i]; }
Francois Gygi committed
86
  double occ(int i) const { return occ_[i]; };
87 88
  const double* occ_ptr(void) const { return &occ_[0]; }
  const double* occ_ptr(int i) const { return &occ_[i]; }
89
  void set_occ(std::vector<double>& occ)
Francois Gygi committed
90
    { assert(occ_.size()==occ.size()); occ_ = occ; }
91
  void set_eig(std::vector<double>& eig)
Francois Gygi committed
92
    { assert(eig_.size()==eig.size()); eig_ = eig; }
93
  void set_eig(std::valarray<double>& eig)
94
    { assert(eig_.size()==eig.size());
Francois Gygi committed
95 96 97
      for ( int i = 0; i < eig.size(); i++ )
        eig_[i] = eig[i];
    }
98 99
  double entropy(int nspin) const;
  double ortho_error(void) const;
Francois Gygi committed
100 101 102
  double memsize(void) const;
  double localmemsize(void) const;
  SlaterDet& operator=(SlaterDet& rhs);
Francois Gygi committed
103
  void print(std::ostream& os, std::string encoding, double weight, int ispin,
104
    int nspin) const;
105
  void write(SharedFilePtr& fh, std::string encoding, double weight, int ispin,
106 107
    int nspin) const;
  void info(std::ostream& os) const;
108 109
  double empty_row_error(void);
  double g0_imag_error(void);
Francois Gygi committed
110
};
111
std::ostream& operator << ( std::ostream& os, SlaterDet& sd );
112 113 114 115

class SlaterDetException
{
  public:
116 117
  std::string msg;
  SlaterDetException(std::string s) : msg(s) {}
118
};
Francois Gygi committed
119
#endif