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 <cassert>
10#include <complex>
11#include <tuple>
12#include <vector>
13
14class AtomBasisView; // Defined in source/source_base/atom_basis_view.h
15
16namespace hamilt
17{
18
42
43template <typename T>
45{
46 public:
47 // Constructor of class AtomPair
48 // Only for 2d-block MPI parallel case
49 // This constructor used for initialize a atom-pair local Hamiltonian with only center cell
50 // which is used for constructing HK (k space Hamiltonian) objects, (gamma_only case)
52 const int &atom_i_, // atomic index of atom i, used to identify atom
53 const int &atom_j_, // atomic index of atom j, used to identify atom
54 const Parallel_Orbitals *paraV_, // information for 2d-block parallel
55 T *existed_matrix = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
56 );
57 // Constructor of class AtomPair
58 // Only for 2d-block MPI parallel case
59 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
60 // which is used for constructing HR (real space Hamiltonian) objects.
62 const int &atom_i_, // atomic index of atom i, used to identify atom
63 const int &atom_j_, // atomic index of atom j, used to identify atom
64 const int &rx, // x coordinate of cell
65 const int &ry, // y coordinate of cell
66 const int &rz, // z coordinate of cell
67 const Parallel_Orbitals *paraV_, // information for 2d-block parallel
68 T *existed_array = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
69 );
70 // Constructor of class AtomPair
71 // Only for 2d-block MPI parallel case
72 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
73 // which is used for constructing HR (real space Hamiltonian) objects.
75 const int &atom_i_, // atomic index of atom i, used to identify atom
76 const int &atom_j_, // atomic index of atom j, used to identify atom
77 const ModuleBase::Vector3<int> &R_index, // xyz coordinates of cell
78 const Parallel_Orbitals *paraV_, // information for 2d-block parallel
79 T *existed_array = nullptr // if nullptr, new memory will be allocated, otherwise this class is a data wrapper
80 );
82 const int &atom_i,
83 const int &atom_j,
84 const AtomBasisView &rows,
85 const AtomBasisView &cols,
86 T *existed_matrix);
88 const int &atom_i,
89 const int &atom_j,
91 const AtomBasisView &rows,
92 const AtomBasisView &cols,
93 T *existed_matrix);
94 // This constructor used for initialize a atom-pair local Hamiltonian with only center cell
95 // which is used for constructing HK (k space Hamiltonian) objects, (gamma_only case)
97 const int &atom_i, // atomic index of atom i, used to identify atom
98 const int &atom_j, // atomic index of atom j, used to identify atom
99 const int *row_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom i
100 const int *col_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom j
101 const int &natom,
102 T *existed_matrix = nullptr);
103
104 // This constructor used for initialize a atom-pair local Hamiltonian with non-zero cell indexes,
105 // which is used for constructing HR (real space Hamiltonian) objects.
106 AtomPair(
107 const int &atom_i, // atomic index of atom i, used to identify atom
108 const int &atom_j, // atomic index of atom j, used to identify atom
109 const int &rx, // x coordinate of cell
110 const int &ry, // y coordinate of cell
111 const int &rz, // z coordinate of cell
112 const int *row_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom i
113 const int *col_atom_begin, // array, contains starting indexes in Hamiltonian matrix of atom j
114 const int &natom,
115 T *existed_matrix = nullptr);
116
117 // copy constructor
118 AtomPair(const AtomPair<T> &other, T *data_pointer = nullptr);
119 // move constructor
120 AtomPair(AtomPair &&other) noexcept;
121
122 // simple constructor, only set atom_i and atom_j
123 AtomPair(
124 const int &atom_i_, // atomic index of atom i, used to identify atom
125 const int &atom_j_ // atomic index of atom j, used to identify atom
126 );
127 // Destructor of class AtomPair
128 ~AtomPair();
129
133 void allocate(T *data_array = nullptr, bool if_zero = false);
134
138 void set_zero();
139
143 int get_begin_row() const { return this->row_ap; }
144 int get_begin_col() const { return this->col_ap; }
145
149 int get_col_size() const;
153 int get_row_size() const;
157 int get_atom_i() const;
158 int get_atom_j() const;
162 void set_size(const int &col_size_in, const int &row_size_in);
167 int get_size() const { return this->col_size * this->row_size; }
168
173 const Parallel_Orbitals *get_paraV() const;
174
178 void set_paraV(const Parallel_Orbitals *paraV_in) { this->paraV = paraV_in; };
179
181 bool identify(const AtomPair<T> &other) const;
182 bool identify(const int &atom_i_, const int &atom_j_) const;
183
196 BaseMatrix<T> &get_HR_values(int rx_in, int ry_in, int rz_in);
197 const BaseMatrix<T> &get_HR_values(int rx_in, int ry_in, int rz_in) const;
198
207 BaseMatrix<T> &get_HR_values(const int &index) const;
208
209 // interface for get (rx, ry, rz) of index-th R-index in this->R_index, the return should be
210 // ModuleBase::Vector3<int>
211 ModuleBase::Vector3<int> get_R_index(const int &index) const;
212 // interface for search (rx, ry, rz) in this->R_index, if found, return index, else return -1
213 int find_R(const int &rx_in, const int &ry_in, const int &rz_in) const;
214 int find_R(const ModuleBase::Vector3<int> &R_in) const;
215 // interface for search (rx, ry, rz) in this->R_index, if found, return BaseMatrix<T>* of this->values[index]
216 const BaseMatrix<T> *find_matrix(const int &rx_in, const int &ry_in, const int &rz_in) const;
217 BaseMatrix<T> *find_matrix(const int &rx_in, const int &ry_in, const int &rz_in);
218 const BaseMatrix<T> *find_matrix(const ModuleBase::Vector3<int> &R_in) const;
220
229 T &get_value(const int R_index, const int &i) const;
230
240 T &get_value(const int R_index, const int &row, const int &col) const;
241
249 std::tuple<std::vector<int>, T *> get_matrix_values(int ir) const;
250
255 T *get_pointer(int ir) const;
256
257 // add another BaseMatrix<T> to this->values with specific R index.
258 void convert_add(
259 const BaseMatrix<T> &target,
260 int rx_in,
261 int ry_in,
262 int rz_in);
268 void merge(const AtomPair<T> &other, bool skip_R = false);
269
274 void merge_to_gamma();
275
289 void add_to_matrix(
290 const int R_index,
291 std::complex<T> *hk,
292 const int ld_hk,
293 const std::complex<T> &kphase,
294 const int hk_type = 0) const;
295
307 void add_to_matrix(
308 const int R_index,
309 T *hk,
310 const int ld_hk,
311 const T &kphase,
312 const int hk_type = 0) const;
313
314 void add_from_matrix(
315 const std::complex<T> *hk,
316 const int ld_hk,
317 const std::complex<T> &kphase,
318 const int hk_type = 0);
319
320 void add_from_matrix(
321 const T *hk,
322 const int ld_hk,
323 const T &kphase,
324 const int hk_type = 0);
325
336 void add_from_matrix(
337 const int R_index,
338 const std::complex<T> *hk,
339 const int ld_hk,
340 const std::complex<T> &kphase,
341 const int hk_type = 0);
342
354 void add_from_matrix(
355 const int R_index,
356 const T *hk,
357 const int ld_hk,
358 const T &kphase,
359 const int hk_type = 0);
360
370 void add_to_array(const int R_index, std::complex<T> *target_array, const std::complex<T> &kphase) const;
380 void add_to_array(const int R_index, T *target_array, const T &kphase) const;
381
382 // comparation function, used for sorting
383 bool operator<(const AtomPair &other) const;
384
385 // The copy assignment operator
386 AtomPair &operator=(const AtomPair &other);
387 // move assignment operator
388 AtomPair &operator=(AtomPair &&other) noexcept;
389
390 // interface for getting the size of this->R_index
391 size_t get_R_size() const
392 {
393#ifdef __DEBUG
394 assert(this->R_index.size() == this->values.size());
395 // assert(this->R_index.size() % 3 == 0);
396#endif
397 return this->R_index.size();
398 }
399
403 size_t get_memory_size() const;
404
405 private:
406 // it contains 3 index of cell, size of R_index is three times of values.
407 std::vector<ModuleBase::Vector3<int>> R_index;
408
409 // it contains containers for accessing matrix of this atom-pair
410 std::vector<BaseMatrix<T>> values;
411
412 // only for 2d-block
413 const Parallel_Orbitals *paraV = nullptr;
414
415 // index for identifying atom I and J for this atom-pair
416 int atom_i = -1;
417 int atom_j = -1;
418 // start index of row for this Atom-Pair
419 int row_ap = -1;
420 // start index of col for this Atom-pair
421 int col_ap = -1;
422 int row_size = 0;
423 int col_size = 0;
424};
425
426} // namespace hamilt
427
428#endif
Atom-local basis entries derived from basis indexing and distribution.
Definition atom_basis_view.h:16
3 elements vector
Definition vector3.h:21
Definition parallel_orbitals.h:16
Definition atom_pair.h:45
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:451
int atom_i
Definition atom_pair.h:416
void merge(const AtomPair< T > &other, bool skip_R=false)
merge another AtomPair to this AtomPair
Definition atom_pair.cpp:572
const Parallel_Orbitals * get_paraV() const
get Parallel_Orbitals pointer of this AtomPair for checking 2d-block parallel
Definition atom_pair.cpp:389
bool operator<(const AtomPair &other) const
Definition atom_pair.cpp:331
AtomPair(const int &atom_i_, const int &atom_j_, const Parallel_Orbitals *paraV_, T *existed_matrix=nullptr)
Definition atom_pair.cpp:22
const Parallel_Orbitals * paraV
Definition atom_pair.h:413
int get_size() const
get size = col_size * row_size
Definition atom_pair.h:167
const BaseMatrix< T > * find_matrix(const int &rx_in, const int &ry_in, const int &rz_in) const
Definition atom_pair.cpp:499
int get_col_size() const
get col_size for this AtomPair
Definition atom_pair.cpp:349
ModuleBase::Vector3< int > get_R_index(const int &index) const
Definition atom_pair.cpp:908
int row_size
Definition atom_pair.h:422
int col_ap
Definition atom_pair.h:421
int col_size
Definition atom_pair.h:423
bool identify(const AtomPair< T > &other) const
use atom_i and atom_j to identify the atom-pair
Definition atom_pair.cpp:396
AtomPair & operator=(const AtomPair &other)
Definition atom_pair.cpp:283
void set_size(const int &col_size_in, const int &row_size_in)
set col_size and row_size
Definition atom_pair.cpp:377
std::vector< BaseMatrix< T > > values
Definition atom_pair.h:410
T * get_pointer(int ir) const
get pointer of value from a submatrix
Definition atom_pair.cpp:950
size_t get_R_size() const
Definition atom_pair.h:391
void allocate(T *data_array=nullptr, bool if_zero=false)
allocate memory for all the BaseMatrix
Definition atom_pair.cpp:252
int find_R(const int &rx_in, const int &ry_in, const int &rz_in) const
Definition atom_pair.cpp:424
int get_row_size() const
get row_size for this AtomPair
Definition atom_pair.cpp:356
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:610
int get_atom_j() const
Definition atom_pair.cpp:370
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:636
T & get_value(const int R_index, const int &i) const
Get value at position i in the matrix values[R_index]. Thread-safe version: explicitly pass R_index.
Definition atom_pair.cpp:924
int get_begin_col() const
Definition atom_pair.h:144
void add_to_array(const int R_index, std::complex< T > *target_array, const std::complex< T > &kphase) const
Add this->value[R_index] * kphase to an array. Thread-safe version: explicitly pass R_index....
Definition atom_pair.cpp:890
void set_zero()
set values in every BaseMatrix to zero
Definition atom_pair.cpp:273
int atom_j
Definition atom_pair.h:417
int get_atom_i() const
get atom_i and atom_j for this AtomPair
Definition atom_pair.cpp:363
std::vector< ModuleBase::Vector3< int > > R_index
Definition atom_pair.h:407
void add_to_matrix(const int R_index, std::complex< T > *hk, const int ld_hk, const std::complex< T > &kphase, const int hk_type=0) const
Add this->value[R_index] * kphase as a block matrix of hk. Thread-safe version: explicitly pass R_ind...
Definition atom_pair.cpp:798
std::tuple< std::vector< int >, T * > get_matrix_values(int ir) const
get values of this->values[ir] for a whole matrix
Definition atom_pair.cpp:900
void set_paraV(const Parallel_Orbitals *paraV_in)
set Parallel_Orbitals pointer of this AtomPair for checking 2d-block parallel
Definition atom_pair.h:178
~AtomPair()
Definition atom_pair.cpp:16
void convert_add(const BaseMatrix< T > &target, int rx_in, int ry_in, int rz_in)
Definition atom_pair.cpp:557
int row_ap
Definition atom_pair.h:419
size_t get_memory_size() const
get total memory size of AtomPair
Definition atom_pair.cpp:961
int get_begin_row() const
get begin index of this AtomPair
Definition atom_pair.h:143
Definition base_matrix.h:20
#define T
Definition exp.cpp:237
Definition wf_op.cpp:6