ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
atom_pair.h
Go to the documentation of this file.
1#ifndef ATOM_PAIR_H
2#define ATOM_PAIR_H
3
4// #include "source_cell/atom_spec.h"
5#include "base_matrix.h"
8
9#include <vector>
10#include <complex>
11#include <tuple>
12#include <cassert>
13
14namespace hamilt
15{
40template <typename T>
42{
43 public:
44 // Constructor of class AtomPair
45 // Only for 2d-block MPI parallel case
46 // This constructor used for initialize a atom-pair local Hamiltonian with only center cell
47 // which is used for constructing HK (k space Hamiltonian) objects, (gamma_only case)
48 AtomPair(const int& atom_i_, // atomic index of atom i, used to identify atom
49 const int& atom_j_, // atomic index of atom j, used to identify atom
50 const Parallel_Orbitals* paraV_, // information for 2d-block parallel
51 T* existed_matrix
52 = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
53 );
54 // Constructor of class AtomPair
55 // Only for 2d-block MPI parallel case
56 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
57 // which is used for constructing HR (real space Hamiltonian) objects.
58 AtomPair(const int& atom_i_, // atomic index of atom i, used to identify atom
59 const int& atom_j_, // atomic index of atom j, used to identify atom
60 const int& rx, // x coordinate of cell
61 const int& ry, // y coordinate of cell
62 const int& rz, // z coordinate of cell
63 const Parallel_Orbitals* paraV_, // information for 2d-block parallel
64 T* existed_array
65 = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
66 );
67 // Constructor of class AtomPair
68 // Only for 2d-block MPI parallel case
69 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
70 // which is used for constructing HR (real space Hamiltonian) objects.
71 AtomPair(const int& atom_i_, // atomic index of atom i, used to identify atom
72 const int& atom_j_, // atomic index of atom j, used to identify atom
73 const ModuleBase::Vector3<int>& R_index, // xyz coordinates of cell
74 const Parallel_Orbitals* paraV_, // information for 2d-block parallel
75 T* existed_array
76 = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
77 );
78 // This constructor used for initialize a atom-pair local Hamiltonian with only center cell
79 // which is used for constructing HK (k space Hamiltonian) objects, (gamma_only case)
80 AtomPair(const int& atom_i, // atomic index of atom i, used to identify atom
81 const int& atom_j, // atomic index of atom j, used to identify atom
82 const int* row_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom i
83 const int* col_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom j
84 const int& natom,
85 T* existed_matrix = nullptr);
86
87 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
88 // which is used for constructing HR (real space Hamiltonian) objects.
89 AtomPair(const int& atom_i, // atomic index of atom i, used to identify atom
90 const int& atom_j, // atomic index of atom j, used to identify atom
91 const int& rx, // x coordinate of cell
92 const int& ry, // y coordinate of cell
93 const int& rz, // z coordinate of cell
94 const int* row_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom i
95 const int* col_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom j
96 const int& natom,
97 T* existed_matrix = nullptr);
98
99 // copy constructor
100 AtomPair(const AtomPair<T>& other, T* data_pointer = nullptr);
101 // move constructor
102 AtomPair(AtomPair&& other) noexcept;
103
104 // simple constructor, only set atom_i and atom_j
105 AtomPair(const int& atom_i_, // atomic index of atom i, used to identify atom
106 const int& atom_j_ // atomic index of atom j, used to identify atom
107 );
108 // Destructor of class AtomPair
109 ~AtomPair();
110
114 void allocate(T* data_array = nullptr, bool if_zero = false);
115
119 void set_zero();
120
124 int get_begin_row() const { return this->row_ap; }
125 int get_begin_col() const { return this->col_ap; }
126
130 int get_col_size() const;
134 int get_row_size() const;
138 int get_atom_i() const;
139 int get_atom_j() const;
143 void set_size(const int& col_size_in, const int& row_size_in);
148 int get_size() const {return this->col_size * this->row_size;}
149
154 const Parallel_Orbitals* get_paraV() const;
155
159 void set_paraV(const Parallel_Orbitals* paraV_in) { this->paraV = paraV_in; };
160
162 bool identify(const AtomPair<T>& other) const;
163 bool identify(const int& atom_i_, const int& atom_j_) const;
164
177 BaseMatrix<T>& get_HR_values(int rx_in, int ry_in, int rz_in);
178 const BaseMatrix<T>& get_HR_values(int rx_in, int ry_in, int rz_in) const;
179
188 BaseMatrix<T>& get_HR_values(const int& index) const;
189
190 // interface for get (rx, ry, rz) of index-th R-index in this->R_index, the return should be ModuleBase::Vector3<int>
191 ModuleBase::Vector3<int> get_R_index(const int& index) const;
192 // interface for get (rx, ry, rz) of current_R, the return should be ModuleBase::Vector3<int>
194 // interface for search (rx, ry, rz) in this->R_index, if found, current_R would be set to index
195 int find_R(const int& rx_in, const int& ry_in, const int& rz_in) const;
196 int find_R(const ModuleBase::Vector3<int>& R_in) const;
197 // interface for search (rx, ry, rz) in this->R_index, if found, current_R would be set to index
198 // and return BaseMatrix<T>* of this->values[index]
199 const BaseMatrix<T>* find_matrix(const int& rx_in, const int& ry_in, const int& rz_in) const;
200 BaseMatrix<T>* find_matrix(const int& rx_in, const int& ry_in, const int& rz_in);
201 const BaseMatrix<T>* find_matrix(const ModuleBase::Vector3<int>& R_in) const;
203
204 // this interface will call get_value in this->values
205 // these four interface can be used only when R-index has been choosed (current_R >= 0)
206 T& get_value(const int& i) const;
207 T& get_value(const int& row, const int& col) const;
208
216 std::tuple<std::vector<int>, T*> get_matrix_values(int ir = -1) const;
217
221 T* get_pointer(int ir=-1) const;
222
223 // add another BaseMatrix<T> to this->values with specific R index.
224 void convert_add(const BaseMatrix<T>& target, int rx_in, int ry_in, int rz_in);
230 void merge(const AtomPair<T>& other, bool skip_R = false);
231
236 void merge_to_gamma();
237
250 void add_to_matrix(std::complex<T>* hk,
251 const int ld_hk,
252 const std::complex<T>& kphase,
253 const int hk_type = 0) const;
254
259 void add_to_matrix(T* hk, const int ld_hk, const T& kphase, const int hk_type = 0) const;
260
261 void add_from_matrix(const std::complex<T>* hk,
262 const int ld_hk,
263 const std::complex<T>& kphase,
264 const int hk_type = 0);
265
266 void add_from_matrix(const T* hk, const int ld_hk, const T& kphase, const int hk_type = 0);
267
272 void add_to_array(std::complex<T>* target_array, const std::complex<T>& kphase) const;
277 void add_to_array(T* target_array, const T& kphase) const;
278
279 // comparation function, used for sorting
280 bool operator<(const AtomPair& other) const;
281
282 // The copy assignment operator
283 AtomPair& operator=(const AtomPair& other);
284 // move assignment operator
285 AtomPair& operator=(AtomPair&& other) noexcept;
286
287 // interface for getting the size of this->R_index
288 size_t get_R_size() const
289 {
290#ifdef __DEBUG
291 assert(this->R_index.size() == this->values.size());
292 // assert(this->R_index.size() % 3 == 0);
293#endif
294 return this->R_index.size();
295 }
296
300 size_t get_memory_size() const;
301
302 private:
303 // it contains 3 index of cell, size of R_index is three times of values.
304 std::vector<ModuleBase::Vector3<int>> R_index;
305
306 // it contains containers for accessing matrix of this atom-pair
307 std::vector<BaseMatrix<T>> values;
308
309 // only for 2d-block
310 const Parallel_Orbitals* paraV = nullptr;
311
312 // the default R index is (0, 0, 0)
313 // if current_R > 0, it means R index has been fixed
314 // if current_R == 0, it means R index refers to the first cell
315 // if current_R == 0 with gamma_only, it means R index refers to the center cell
316 // !!!!!!!!!!! BE CAREFUL, current_R IS NOT THREADING-SAFE !!!!!!!!!!!!!!!!!!!!!
317 mutable int current_R = 0;
318
319 // index for identifying atom I and J for this atom-pair
320 int atom_i = -1;
321 int atom_j = -1;
322 // start index of row for this Atom-Pair
323 int row_ap = -1;
324 // start index of col for this Atom-pair
325 int col_ap = -1;
326 int row_size = 0;
327 int col_size = 0;
328};
329
330} // namespace hamilt
331
332#endif
3 elements vector
Definition vector3.h:22
Definition parallel_orbitals.h:9
Definition atom_pair.h:42
BaseMatrix< T > & get_HR_values(int rx_in, int ry_in, int rz_in)
get target BaseMatrix of target cell for const AtomPair, it will return a const BaseMatrix<T> object,...
Definition atom_pair.cpp:393
int atom_i
Definition atom_pair.h:320
void merge(const AtomPair< T > &other, bool skip_R=false)
merge another AtomPair to this AtomPair
Definition atom_pair.cpp:538
T * get_pointer(int ir=-1) const
get pointer of value from a submatrix
Definition atom_pair.cpp:844
const Parallel_Orbitals * get_paraV() const
get Parallel_Orbitals pointer of this AtomPair for checking 2d-block parallel
Definition atom_pair.cpp:358
int current_R
Definition atom_pair.h:317
bool operator<(const AtomPair &other) const
Definition atom_pair.cpp:300
const Parallel_Orbitals * paraV
Definition atom_pair.h:310
int get_size() const
get size = col_size * row_size
Definition atom_pair.h:148
void add_to_matrix(std::complex< T > *hk, const int ld_hk, const std::complex< T > &kphase, const int hk_type=0) const
Add this->value[current_R] * kphase as a block matrix of hk.
Definition atom_pair.cpp:603
const BaseMatrix< T > * find_matrix(const int &rx_in, const int &ry_in, const int &rz_in) const
Definition atom_pair.cpp:471
int get_col_size() const
get col_size for this AtomPair
Definition atom_pair.cpp:318
int row_size
Definition atom_pair.h:326
int col_ap
Definition atom_pair.h:325
int col_size
Definition atom_pair.h:327
bool identify(const AtomPair< T > &other) const
use atom_i and atom_j to identify the atom-pair
Definition atom_pair.cpp:365
AtomPair & operator=(const AtomPair &other)
Definition atom_pair.cpp:243
T & get_value(const int &i) const
Definition atom_pair.cpp:818
void set_size(const int &col_size_in, const int &row_size_in)
set col_size and row_size
Definition atom_pair.cpp:346
std::vector< BaseMatrix< T > > values
Definition atom_pair.h:307
size_t get_R_size() const
Definition atom_pair.h:288
void allocate(T *data_array=nullptr, bool if_zero=false)
allocate memory for all the BaseMatrix
Definition atom_pair.cpp:212
int find_R(const int &rx_in, const int &ry_in, const int &rz_in) const
Definition atom_pair.cpp:441
int get_row_size() const
get row_size for this AtomPair
Definition atom_pair.cpp:325
std::tuple< std::vector< int >, T * > get_matrix_values(int ir=-1) const
get values of this->values[ir] for a whole matrix
Definition atom_pair.cpp:787
void merge_to_gamma()
merge all values in this AtomPair to one BaseMatrix with R-index (0, 0, 0) in this case,...
Definition atom_pair.cpp:575
int get_atom_j() const
Definition atom_pair.cpp:339
void add_from_matrix(const std::complex< T > *hk, const int ld_hk, const std::complex< T > &kphase, const int hk_type=0)
Definition atom_pair.cpp:684
int get_begin_col() const
Definition atom_pair.h:125
void set_zero()
set values in every BaseMatrix to zero
Definition atom_pair.cpp:233
int atom_j
Definition atom_pair.h:321
void add_to_array(std::complex< T > *target_array, const std::complex< T > &kphase) const
Add this->value[current_R] * kphase to an array. T = double or float.
Definition atom_pair.cpp:777
int get_atom_i() const
get atom_i and atom_j for this AtomPair
Definition atom_pair.cpp:332
std::vector< ModuleBase::Vector3< int > > R_index
Definition atom_pair.h:304
ModuleBase::Vector3< int > get_R_index() const
Definition atom_pair.cpp:810
void set_paraV(const Parallel_Orbitals *paraV_in)
set Parallel_Orbitals pointer of this AtomPair for checking 2d-block parallel
Definition atom_pair.h:159
~AtomPair()
Definition atom_pair.cpp:15
void convert_add(const BaseMatrix< T > &target, int rx_in, int ry_in, int rz_in)
Definition atom_pair.cpp:527
int row_ap
Definition atom_pair.h:323
size_t get_memory_size() const
get total memory size of AtomPair
Definition atom_pair.cpp:859
int get_begin_row() const
get begin index of this AtomPair
Definition atom_pair.h:124
Definition base_matrix.h:20
#define T
Definition exp.cpp:237
Definition hamilt.h:12