Basis.h 5.58 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
//  Basis.h
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
6
// $Id: Basis.h,v 1.9 2008-03-05 04:04:48 fgygi Exp $
Francois Gygi committed
7 8 9 10 11 12

#ifndef BASIS_H
#define BASIS_H

#include "D3vector.h"
#include "UnitCell.h"
Francois Gygi committed
13 14
#include "Context.h"
#include <vector>
Francois Gygi committed
15 16 17 18 19 20

class Context;

class Basis
{
  private:
21

Francois Gygi committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  Context ctxt_;
  int nprow_, myrow_;

  UnitCell cell_;         // cell dimensions
  UnitCell refcell_;      // reference cell dimensions
  D3vector kpoint_;       // k-point in units of b0,b1,b2
  double ecut_;           // energy cutoff of wavefunctions in Rydberg
  int idxmin_[3];          // minimum index in each direction
  int idxmax_[3];          // maximum index in each direction
  int size_;              // basis size
  int nrods_;             // total number of rods
  std::vector<int> localsize_; // localsize_[ipe]
  int maxlocalsize_, minlocalsize_;
  std::vector<int> nrod_loc_;
  std::vector<std::vector<int> > rod_h_;
  std::vector<std::vector<int> > rod_k_;
  std::vector<std::vector<int> > rod_lmin_;
  std::vector<std::vector<int> > rod_size_;
  std::vector<std::vector<int> > rod_first_;

  std::vector<int>    idx_;   // 3-d index of vectors idx[i*3+j]
  std::vector<double> g_;     // norm of g vectors g[localsize]
  std::vector<double> kpg_;   // norm of g vectors g[localsize]
  std::vector<double> gi_;    // inverse norm of g vectors gi[localsize]
  std::vector<double> kpgi_;  // inverse norm of k+g vectors kpgi[localsize]
  std::vector<double> g2_;    // 2-norm of g vectors g2[localsize]
  std::vector<double> kpg2_;  // 2-norm of g vectors g2[localsize]
  std::vector<double> g2i_;   // inverse square norm of g vec g2i[localsize]
  std::vector<double> kpg2i_; // inverse square norm of k+g vec kpg2i[localsize]
  int np_[3];            // cache for the function np
  std::vector<double> gx_;    // g vec components gx[j*localsize+i], j=0,1,2
  std::vector<double> kpgx_;  // k+g vec components kpgx[j*localsize+i], j=0,1,2
  std::vector<int> isort_loc; // index array to access locally sorted vectors
                         // kpg2_[isort_loc[i]] < kpg2_[isort_loc[j]] if i < j
  bool real_;            // true if k=0
  void update_g(void);
58

Francois Gygi committed
59
  public:
60

Francois Gygi committed
61 62 63 64 65 66
  const Context& context(void) const; // context on which Basis is defined

  const UnitCell& cell() const;   // cell dimensions
  const UnitCell& refcell() const;// reference cell dimensions
  const D3vector kpoint() const; // k-point in units of b0,b1,b2
  int np(int i) const;           // good size of FFT grid in direction i
Francois Gygi committed
67
  bool factorizable(int n) const;// check if n is factorizable with low factors
Francois Gygi committed
68 69 70 71
  int idxmin(int i) const;       // smallest index in direction i
  int idxmax(int i) const;       // largest index in direction i
  double ecut() const;           // energy cutoff in Hartree
  bool real() const;             // return true if kpoint == (0,0,0)
72

Francois Gygi committed
73 74 75 76 77
  int size() const;              // total number of g vectors
  int localsize() const;         // local number of g vectors on current process
  int localsize(int ipe) const;  // local number of g vectors on process ipe
  int maxlocalsize() const;      // largest local size
  int minlocalsize() const;      // smallest local size
78

Francois Gygi committed
79 80 81
  int nrods() const;             // total number of rods
  int nrod_loc() const;          // local number of rods on current process
  int nrod_loc(int ipe) const;   // local number of rods on process ipe
82

Francois Gygi committed
83 84 85 86 87 88 89 90 91 92
  int rod_h(int irod) const;     // h-position of rod irod on current process
  int rod_h(int ipe, int irod) const; // h-position of rod irod on process ipe

  int rod_k(int irod) const;     // k-position of rod irod on current process
  int rod_k(int ipe, int irod) const; // k-position of rod irod on process ipe

  int rod_lmin(int irod) const;  // lmin-position of rod irod on current process
  int rod_lmin(int ipe, int irod) const; // lmin-pos. of rod irod on process ipe

  // size of rod irod
93
  int rod_size(int irod) const;
Francois Gygi committed
94 95
  int rod_size(int ipe, int irod) const;

96 97
  // local position of first elem. of rod irod
  int rod_first(int irod) const;
Francois Gygi committed
98
  int rod_first(int ipe, int irod) const;
99

Francois Gygi committed
100 101 102 103
  int    idx(int i) const;   // integer indices of vectors idx[i*3+j]
  double g(int i) const;     // norm of g vectors g[i]
  double kpg(int i) const;   // norm of k+g vectors kpg[i]
  double gi(int i) const;    // inverse norm of g vectors gi[i]
Francois Gygi committed
104
  double kpgi(int i) const;  // inverse norm of k+g vectors kpgi[i]
Francois Gygi committed
105 106 107
  double g2(int i) const;    // 2-norm of g vectors g2[i]
  double kpg2(int i) const;  // 2-norm of k+g vectors kpg[i]
  double g2i(int i) const;   // inverse square norm of g g2i[i]
Francois Gygi committed
108
  double kpg2i(int i) const; // inverse square norm of k+g kpg2i[i]
Francois Gygi committed
109
  double gx(int i) const;    // g vectors gx[i+localsize*j],j=0,1,2
Francois Gygi committed
110
  double kpgx(int i) const;  // k+g vectors kpgx[i+localsize*j],j=0,1,2
111

Francois Gygi committed
112
  int isort(int i) const;    // index of vectors locally sorted by norm
113

Francois Gygi committed
114 115 116 117
  const int*    idx_ptr(void) const;
  const double* g_ptr(void) const;
  const double* kpg_ptr(void) const;
  const double* gi_ptr(void) const;
Francois Gygi committed
118
  const double* kpgi_ptr(void) const;
Francois Gygi committed
119 120 121
  const double* g2_ptr(void) const;
  const double* kpg2_ptr(void) const;
  const double* g2i_ptr(void) const;
Francois Gygi committed
122
  const double* kpg2i_ptr(void) const;
Francois Gygi committed
123
  const double* gx_ptr(int j) const;
Francois Gygi committed
124
  const double* kpgx_ptr(int j) const;
125

Francois Gygi committed
126 127 128 129
  double memsize(void) const;
  double localmemsize(void) const;

  Basis(const Context &ctxt, D3vector kpoint);
Francois Gygi committed
130
  //Basis(const Basis &b);
Francois Gygi committed
131
  ~Basis(void);
132

Francois Gygi committed
133
  bool resize(const UnitCell& cell, const UnitCell& refcell, double ecut);
134
  void print(std::ostream& os);
Francois Gygi committed
135
};
136
std::ostream& operator << ( std::ostream& os, Basis& b );
Francois Gygi committed
137
#endif