ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
phi_operator.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5#include <utility>
7#include "big_grid.h"
8
9namespace ModuleGint
10{
11
20{
21 public:
23
24 // constructor
25 PhiOperator()=default;
26
27 // set the big grid that the phiOperator is associated with
28 void set_bgrid(std::shared_ptr<const BigGrid> biggrid);
29
30 // getter
31 int get_rows() const {return rows_;}
32 int get_cols() const {return cols_;}
33
34 // get phi of the big grid
35 // the dimension of phi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw)
36 template<typename T>
37 void set_phi(T* phi) const;
38
39 // get phi and the gradient of phi of the big grid
40 // the dimension of phi and dphi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw)
41 // if you do not need phi, you can set phi to nullptr.
42 void set_phi_dphi(double* phi, double* dphi_x, double* dphi_y, double* dphi_z) const;
43
44 // get the hessian of the wave function values of the big grid
45 // the dimension of ddphi is num_mgrids * (\sum_{i=0}^{atoms_->size()} atoms_[i]->nw)
46 void set_ddphi(
47 double* ddphi_xx, double* ddphi_xy, double* ddphi_xz,
48 double* ddphi_yy, double* ddphi_yz, double* ddphi_zz) const;
49
50 // phi_dm(ir,iwt_2) = \sum_{iwt_1} phi(ir,iwt_1) * dm(iwt_1,iwt_2)
51 template<typename T>
52 void phi_mul_dm(
53 const T*const phi, // phi(ir,iwt)
54 const HContainer<T>& dm, // dm(iwt_1,iwt_2)
55 const bool is_symm,
56 T*const phi_dm) const; // phi_dm(ir,iwt)
57
58 // result(ir,iwt) = phi(ir,iwt) * vl(ir)
59 template<typename T>
60 void phi_mul_vldr3(
61 const T*const vl, // vl(ir)
62 const T dr3,
63 const T*const phi, // phi(ir,iwt)
64 T*const result) const; // result(ir,iwt)
65
66 // hr(iwt_i,iwt_j) = \sum_{ir} phi_i(ir,iwt_i) * phi_i(ir,iwt_j)
67 // this is a thread-safe function
68 template<typename T>
69 void phi_mul_phi(
70 const T*const phi_i, // phi_i(ir,iwt)
71 const T*const phi_j, // phi_j(ir,iwt)
72 HContainer<T>& hr, // hr(iwt_i,iwt_j)
73 const Triangular_Matrix triangular_matrix) const;
74
75 // rho(ir) = \sum_{iwt} \phi_i(ir,iwt) * \phi_j(ir,iwt)
76 template<typename T>
77 void phi_dot_phi(
78 const T*const phi_i, // phi_i(ir,iwt)
79 const T*const phi_j, // phi_j(ir,iwt)
80 T*const rho) const; // rho(ir)
81
82 void phi_dot_dphi(
83 const double* phi,
84 const double* dphi_x,
85 const double* dphi_y,
86 const double* dphi_z,
87 ModuleBase::matrix *fvl) const;
88
89 void phi_dot_dphi_r(
90 const double* phi,
91 const double* dphi_x,
92 const double* dphi_y,
93 const double* dphi_z,
94 ModuleBase::matrix *svl) const;
95
96 void cal_env_gamma(
97 const double* phi,
98 const double* wfc,
99 const vector<int>& trace_lo,
100 double* rho) const;
101
102 void cal_env_k(
103 const double* phi,
104 const std::complex<double>* wfc,
105 const vector<int>& trace_lo,
106 const int ik,
107 const int nspin,
108 const int npol,
109 const int lgd,
110 const std::vector<Vec3d>& kvec_c,
111 const std::vector<Vec3d>& kvec_d,
112 double* rho) const;
113
114 private:
116
117 // get the index of the first and the last meshgrid that both atom a and atom b affect
118 // Note that atom_pair_start_end_idx_ only stores the cases where a <= b, so this function is needed to retrieve the value
119 const std::pair<int, int>& get_atom_pair_start_end_idx_(int a, int b) const
120 {
121 int x = std::min(a, b);
122 int y = std::abs(a - b);
123 return atom_pair_start_end_idx_[(2 * biggrid_->get_atoms_num() - x + 1) * x / 2 + y];
124 }
125
126 bool is_atom_on_mgrid(int atom_idx, int mgrid_idx) const
127 {
128 return is_atom_on_mgrid_[atom_idx * rows_ + mgrid_idx];
129 }
130
131 // the row number of the phi matrix
132 // rows_ = biggrid_->get_mgrids_num()
133 int rows_;
134
135 // the column number of the phi matrix
136 // cols_ = biggrid_->get_phi_len()
137 int cols_;
138
139 // the local index of the meshgrids
140 std::vector<int> meshgrids_local_idx_;
141
142 // the big grid that the phi matrix is associated with
143 std::shared_ptr<const BigGrid> biggrid_;
144
145 // the relative coordinates of the atoms and the meshgrids
146 // atoms_relative_coords_[i][j] is the relative coordinate of the jth meshgrid and the ith atom
147 std::vector<std::vector<Vec3d>> atoms_relative_coords_;
148
149 // record whether the atom affects the meshgrid
150 // is_atom_on_mgrid_[i * rows_ + j] = true if the ith atom affects jhe ith meshgrid, otherwise false
151 std::vector<bool> is_atom_on_mgrid_;
152
153 // the start index of the phi of each atom
154 std::vector<int> atoms_startidx_;
155
156 // the length of phi of each atom
157 // atoms_phi_len_[i] = biggrid_->get_atom(i)->get_nw()
158 // TODO: remove it
159 std::vector<int> atoms_phi_len_;
160
161 // This data structure is used to store the index of the first and last meshgrid affected by each atom pair
162 std::vector<std::pair<int, int>> atom_pair_start_end_idx_;
163};
164
165}
166
167#include "phi_operator.hpp"
Definition matrix.h:19
The class phiOperator is used to perform operations on the wave function matrix phi,...
Definition phi_operator.h:20
int get_rows() const
Definition phi_operator.h:31
bool is_atom_on_mgrid(int atom_idx, int mgrid_idx) const
Definition phi_operator.h:126
int get_cols() const
Definition phi_operator.h:32
void phi_dot_dphi_r(const double *phi, const double *dphi_x, const double *dphi_y, const double *dphi_z, ModuleBase::matrix *svl) const
Definition phi_operator.cpp:98
void cal_env_gamma(const double *phi, const double *wfc, const vector< int > &trace_lo, double *rho) const
Definition phi_operator.cpp:133
void phi_dot_dphi(const double *phi, const double *dphi_x, const double *dphi_y, const double *dphi_z, ModuleBase::matrix *fvl) const
Definition phi_operator.cpp:68
void phi_mul_phi(const T *const phi_i, const T *const phi_j, HContainer< T > &hr, const Triangular_Matrix triangular_matrix) const
Definition phi_operator.hpp:109
std::vector< bool > is_atom_on_mgrid_
Definition phi_operator.h:151
void set_phi_dphi(double *phi, double *dphi_x, double *dphi_y, double *dphi_z) const
Definition phi_operator.cpp:35
void phi_mul_vldr3(const T *const vl, const T dr3, const T *const phi, T *const result) const
Definition phi_operator.hpp:88
void phi_dot_phi(const T *const phi_i, const T *const phi_j, T *const rho) const
Definition phi_operator.hpp:176
std::shared_ptr< const BigGrid > biggrid_
Definition phi_operator.h:143
std::vector< std::vector< Vec3d > > atoms_relative_coords_
Definition phi_operator.h:147
const std::pair< int, int > & get_atom_pair_start_end_idx_(int a, int b) const
Definition phi_operator.h:119
std::vector< int > meshgrids_local_idx_
Definition phi_operator.h:140
void init_atom_pair_start_end_idx_()
Definition phi_operator.cpp:217
std::vector< int > atoms_phi_len_
Definition phi_operator.h:159
Triangular_Matrix
Definition phi_operator.h:22
void set_ddphi(double *ddphi_xx, double *ddphi_xy, double *ddphi_xz, double *ddphi_yy, double *ddphi_yz, double *ddphi_zz) const
Definition phi_operator.cpp:51
void cal_env_k(const double *phi, const std::complex< double > *wfc, const vector< int > &trace_lo, const int ik, const int nspin, const int npol, const int lgd, const std::vector< Vec3d > &kvec_c, const std::vector< Vec3d > &kvec_d, double *rho) const
Definition phi_operator.cpp:160
void set_bgrid(std::shared_ptr< const BigGrid > biggrid)
Definition phi_operator.cpp:8
std::vector< int > atoms_startidx_
Definition phi_operator.h:154
void set_phi(T *phi) const
Definition phi_operator.hpp:11
std::vector< std::pair< int, int > > atom_pair_start_end_idx_
Definition phi_operator.h:162
int rows_
Definition phi_operator.h:133
void phi_mul_dm(const T *const phi, const HContainer< T > &dm, const bool is_symm, T *const phi_dm) const
Definition phi_operator.hpp:23
int cols_
Definition phi_operator.h:137
Definition hcontainer.h:144
#define T
Definition exp.cpp:237
Definition batch_biggrid.cpp:4