ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
hcontainer.h
Go to the documentation of this file.
1#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_MODULE_HCONTAINER_HCONTAINER_H
2#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_MODULE_HCONTAINER_HCONTAINER_H
3
4#include "atom_pair.h"
7
8#include <set>
9#include <vector>
10
11namespace hamilt
12{
13
142template <typename T>
144{
145 public:
146 // Destructor of class HContainer
147 ~HContainer();
148
149 HContainer();
150
156 HContainer(const HContainer<T>& HR_in, T* data_array = nullptr);
157
158 // copy assignment, not allowed
159 HContainer& operator=(const HContainer<T>& HR_in) = delete;
160
161 // move constructor
162 HContainer(HContainer<T>&& HR_in) noexcept;
163 // move assignment
164 HContainer& operator=(HContainer<T>&& HR_in) noexcept;
165
166 // simple constructor
167 HContainer(int natom);
168
169 // use unitcell to initialize atom_pairs
170 HContainer(const UnitCell& ucell_, const Parallel_Orbitals* paraV = nullptr);
171
178 HContainer(const Parallel_Orbitals* paraV, T* data_pointer = nullptr, const std::vector<int>* ijr_info = nullptr);
179
183 void set_paraV(const Parallel_Orbitals* paraV_in)
184 {
185 this->paraV = paraV_in;
186 for (auto& ap : atom_pairs) ap.set_paraV(paraV_in);
187 };
192 const Parallel_Orbitals* get_paraV() const { return this->paraV; };
193
203 void allocate(T* data_array = nullptr, bool if_zero = false);
204
208 void set_zero();
209
218 void insert_pair(const AtomPair<T>& atom_ij);
219
230 AtomPair<T>* find_pair(int i, int j) const;
231
238 BaseMatrix<T>* find_matrix(int i, int j, int rx, int ry, int rz);
239 const BaseMatrix<T>* find_matrix(int i, int j, int rx, int ry, int rz) const;
240 BaseMatrix<T>* find_matrix(int i, int j, const ModuleBase::Vector3<int>& R_index);
241 const BaseMatrix<T>* find_matrix(int i, int j, const ModuleBase::Vector3<int>& R_index) const;
242
248 int find_matrix_offset(int i, int j, int rx, int ry, int rz) const;
249 int find_matrix_offset(int i, int j, const ModuleBase::Vector3<int>& R_index) const;
250
257 AtomPair<T>& get_atom_pair(int i, int j) const;
265 AtomPair<T>& get_atom_pair(int index) const;
266
280 // T& operator()(int atom_i, int atom_j, int rx_in, int ry_in, int rz_in, int mu, int nu) const;
281
285 void add(const HContainer<T>& other);
286
287 // save atom-pair pointers into this->tmp_atom_pairs for selected R index
296 bool fix_R(int rx_in, int ry_in, int rz_in) const;
297
302 void unfix_R() const;
303
320 void fix_gamma();
321
322 // interface for call a R loop for HContainer
323 // it can return a new R-index with (rx,ry,rz) for each loop
324 // if index==0, a new loop of R will be initialized
335 void loop_R(const size_t& index, int& rx, int& ry, int& rz) const;
336
340 size_t size_R_loop() const;
341
342
351 int find_R(const int& rx_in, const int& ry_in, const int& rz_in) const;
352 int find_R(const ModuleBase::Vector3<int>& R_in) const;
353
357 size_t size_atom_pairs() const;
358
366 T* data(int i, int j) const;
367
376 T* data(int i, int j, int* R) const;
377
381 int get_current_R() const;
382
386 bool is_gamma_only() const;
387
391 size_t get_memory_size() const;
392
398 size_t get_nnr() const
399 {
400 size_t sum = 0;
401 for (int iap = 0; iap < this->atom_pairs.size(); ++iap)
402 {
403 sum += this->atom_pairs[iap].get_R_size() * this->atom_pairs[iap].get_size();
404 }
405 return sum;
406 }
407
412 std::vector<int> get_ijr_info() const;
413
420 void insert_ijrs(const std::vector<int>* ijrs);
421
428 void insert_ijrs(const std::vector<int>* ijrs, const UnitCell& ucell, const int npol=1);
429
433 T* get_wrapper() const
434 {
435 return this->wrapper_pointer;
436 }
437
442 void shape_synchron(const HContainer<T>& other);
443
448 const std::vector<std::vector<int>>& get_sparse_ap() const
449 {
450 return sparse_ap;
451 }
452
457 const std::vector<std::vector<int>>& get_sparse_ap_index() const
458 {
459 return sparse_ap_index;
460 }
461
466 int get_nbasis() const
467 {
468 return paraV->get_global_row_size();
469 }
470
471 private:
472 // i-j atom pairs, sorted by matrix of (atom_i, atom_j)
473 std::vector<AtomPair<T>> atom_pairs;
474
475 // sparse table for (atom_i, atom_j)->index of atom_pairs
476 std::vector<std::vector<int>> sparse_ap;
477 std::vector<std::vector<int>> sparse_ap_index;
478
482 mutable std::vector<const AtomPair<T>*> tmp_atom_pairs;
483 // it contains 3 index of cell, size of R_index is three times of values.
484 mutable std::vector<ModuleBase::Vector3<int>> tmp_R_index;
485 // current index of R in tmp_atom_pairs, -1 means not initialized
486 mutable int current_R = -1;
487
488 bool gamma_only = false;
489
496 T* wrapper_pointer = nullptr;
497 bool allocated = false;
498
502 const Parallel_Orbitals* paraV = nullptr;
503
504 // int multiple = 1;
505 // int current_multiple = 0;
506};
507
508} // namespace hamilt
509
510#endif
3 elements vector
Definition vector3.h:22
int get_global_row_size() const
number of global rows
Definition parallel_2d.cpp:13
Definition parallel_orbitals.h:9
Definition unitcell.h:16
Definition atom_pair.h:42
Definition base_matrix.h:20
Definition hcontainer.h:144
void loop_R(const size_t &index, int &rx, int &ry, int &rz) const
interface for call a R loop for HContainer it can return a new R-index with (rx,ry,...
Definition hcontainer.cpp:558
HContainer()
Definition hcontainer.cpp:20
void fix_gamma()
restrict R indexes of all atom-pair to 0, 0, 0 add BaseMatrix<T> with non-zero R index to this->atom_...
Definition hcontainer.cpp:462
void unfix_R() const
set current_R to -1, which means R is not fixed clear this->tmp_atom_pairs
Definition hcontainer.cpp:453
std::vector< AtomPair< T > > atom_pairs
Definition hcontainer.h:473
std::vector< int > get_ijr_info() const
get infomation of IJR pairs in HContainer the return vector format is {size_I, I1,...
Definition hcontainer.cpp:762
size_t get_nnr() const
calculate total size of data in HContainer, named nnr inherited from history all AtomPairs and BaseMa...
Definition hcontainer.h:398
HContainer & operator=(const HContainer< T > &HR_in)=delete
void insert_pair(const AtomPair< T > &atom_ij)
a AtomPair object can be inserted into HContainer, two steps: 1, find AtomPair with atom index atom_i...
Definition hcontainer.cpp:624
bool fix_R(int rx_in, int ry_in, int rz_in) const
save atom-pair pointers into this->tmp_atom_pairs for selected R index
Definition hcontainer.cpp:417
T * wrapper_pointer
if wrapper_pointer is not nullptr, this HContainer is a wrapper there is only one case that "wrapper_...
Definition hcontainer.h:496
T * data(int i, int j) const
get data pointer of AtomPair with index of I, J
Definition hcontainer.cpp:592
bool is_gamma_only() const
judge if gamma_only
Definition hcontainer.cpp:689
size_t size_atom_pairs() const
calculate number of AtomPairs for current R index
Definition hcontainer.cpp:576
int get_current_R() const
get current_R
Definition hcontainer.cpp:682
int get_nbasis() const
get number of basis in each H matrix
Definition hcontainer.h:466
BaseMatrix< T > * find_matrix(int i, int j, int rx, int ry, int rz)
find BaseMatrix with atom index atom_i and atom_j and R index (rx, ry, rz) This interface can be used...
Definition hcontainer.cpp:261
int find_R(const int &rx_in, const int &ry_in, const int &rz_in) const
find index of R in tmp_R_index, used when current_R is fixed
Definition hcontainer.cpp:485
int current_R
Definition hcontainer.h:486
bool allocated
Definition hcontainer.h:497
const std::vector< std::vector< int > > & get_sparse_ap() const
get sparse_ap
Definition hcontainer.h:448
size_t size_R_loop() const
calculate number of R index which has counted AtomPairs
Definition hcontainer.cpp:523
bool gamma_only
Definition hcontainer.h:488
void insert_ijrs(const std::vector< int > *ijrs)
use infomation of IJ pairs to expand HContainer the input vector format is {size_IJ_pairs,...
Definition hcontainer.cpp:792
std::vector< const AtomPair< T > * > tmp_atom_pairs
temporary atom-pair lists to loop selected R index
Definition hcontainer.h:482
void set_paraV(const Parallel_Orbitals *paraV_in)
set parallel orbital pointer to check parallel information
Definition hcontainer.h:183
~HContainer()
Definition hcontainer.cpp:11
size_t get_memory_size() const
get total memory bites of HContainer
Definition hcontainer.cpp:696
void shape_synchron(const HContainer< T > &other)
synchronization of atom-pairs for read-in HContainer new <IJR> pair from read-in HContainer will be i...
Definition hcontainer.cpp:722
void allocate(T *data_array=nullptr, bool if_zero=false)
allocate memory for all <IJR> matrix if data_array is not nullptr, use memory after data_array for ea...
Definition hcontainer.cpp:175
void set_zero()
set values of all <IJR> matrix to zero
Definition hcontainer.cpp:210
std::vector< std::vector< int > > sparse_ap_index
Definition hcontainer.h:477
std::vector< ModuleBase::Vector3< int > > tmp_R_index
Definition hcontainer.h:484
AtomPair< T > & get_atom_pair(int i, int j) const
return a reference of AtomPair with index of atom I and J in atom_pairs
Definition hcontainer.cpp:353
T * get_wrapper() const
return the wrapper_pointer
Definition hcontainer.h:433
int find_matrix_offset(int i, int j, int rx, int ry, int rz) const
find the offset of BaseMatrix with atom index atom_i and atom_j and R index (rx, ry,...
Definition hcontainer.cpp:324
const Parallel_Orbitals * get_paraV() const
get parallel orbital pointer to check parallel information
Definition hcontainer.h:192
const std::vector< std::vector< int > > & get_sparse_ap_index() const
get sparse_ap_index
Definition hcontainer.h:457
const Parallel_Orbitals * paraV
pointer of Parallel_Orbitals, which is used to get atom-pair information
Definition hcontainer.h:502
std::vector< std::vector< int > > sparse_ap
Definition hcontainer.h:476
AtomPair< T > * find_pair(int i, int j) const
find AtomPair with atom index atom_i and atom_j This interface can be used to find AtomPair,...
Definition hcontainer.cpp:219
void add(const HContainer< T > &other)
operator() for accessing value with indexes this interface is not implemented now,...
Definition hcontainer.cpp:407
#define T
Definition exp.cpp:237
Definition hamilt.h:12