Basis.h 6.17 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
// Basis.h
Francois Gygi committed
16 17 18 19 20 21 22 23
//
////////////////////////////////////////////////////////////////////////////////

#ifndef BASIS_H
#define BASIS_H

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

26 27 28 29 30 31
#ifdef USE_MPI
#include <mpi.h>
#else
  typedef int MPI_Comm;
#endif

Francois Gygi committed
32 33 34
class Basis
{
  private:
35

36 37
  MPI_Comm comm_;
  int npes_, mype_;
Francois Gygi committed
38 39 40 41 42

  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
43 44
  int idxmin_[3];         // minimum index in each direction
  int idxmax_[3];         // maximum index in each direction
Francois Gygi committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  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]
65
  int np_[3];                 // cache for the function np
Francois Gygi committed
66 67 68 69 70 71
  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);
72

Francois Gygi committed
73
  public:
74

75 76 77
  MPI_Comm comm(void) const;     // MPI_Comm on which Basis is defined
  int mype(void) const { return mype_; }
  int npes(void) const { return npes_; }
Francois Gygi committed
78

79
  const UnitCell& cell() const;  // cell dimensions
Francois Gygi committed
80 81 82
  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
83
  bool fits_in_grid(int np0, int np1, int np2) const;
Francois Gygi committed
84
  bool factorizable(int n) const;// check if n is factorizable with low factors
Francois Gygi committed
85 86 87 88
  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)
89

Francois Gygi committed
90 91 92 93 94
  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
95

Francois Gygi committed
96 97 98
  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
99

Francois Gygi committed
100 101 102 103 104 105 106 107 108 109
  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
110
  int rod_size(int irod) const;
Francois Gygi committed
111 112
  int rod_size(int ipe, int irod) const;

113 114
  // local position of first elem. of rod irod
  int rod_first(int irod) const;
Francois Gygi committed
115
  int rod_first(int ipe, int irod) const;
116

Francois Gygi committed
117 118 119 120
  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
121
  double kpgi(int i) const;  // inverse norm of k+g vectors kpgi[i]
Francois Gygi committed
122 123 124
  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
125
  double kpg2i(int i) const; // inverse square norm of k+g kpg2i[i]
Francois Gygi committed
126
  double gx(int i) const;    // g vectors gx[i+localsize*j],j=0,1,2
Francois Gygi committed
127
  double kpgx(int i) const;  // k+g vectors kpgx[i+localsize*j],j=0,1,2
128

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

Francois Gygi committed
131 132 133 134
  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
135
  const double* kpgi_ptr(void) const;
Francois Gygi committed
136 137 138
  const double* g2_ptr(void) const;
  const double* kpg2_ptr(void) const;
  const double* g2i_ptr(void) const;
Francois Gygi committed
139
  const double* kpg2i_ptr(void) const;
Francois Gygi committed
140
  const double* gx_ptr(int j) const;
Francois Gygi committed
141
  const double* kpgx_ptr(int j) const;
142

Francois Gygi committed
143 144 145
  double memsize(void) const;
  double localmemsize(void) const;

146
  Basis(MPI_Comm comm, D3vector kpoint);
Francois Gygi committed
147
  //Basis(const Basis &b);
Francois Gygi committed
148
  ~Basis(void);
149

Francois Gygi committed
150
  bool resize(const UnitCell& cell, const UnitCell& refcell, double ecut);
151
  void print(std::ostream& os);
Francois Gygi committed
152
};
153
std::ostream& operator << ( std::ostream& os, Basis& b );
Francois Gygi committed
154
#endif