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 HCONTAINER_H
2#define HCONTAINER_H
3
4#include "atom_pair.h"
7
8#include <set>
9#include <vector>
10
11class BasisFlattenedIndexing; // Defined in source/source_base/basis_flattened_indexing.h
12class Parallel_Blkcyclic; // Defined in source/source_base/parallel_blkcyc.h
13
14namespace hamilt
15{
16
145template <typename T>
147{
148 public:
149 // Destructor of class HContainer
150 ~HContainer();
151
152 HContainer();
153
159 HContainer(const HContainer<T> &HR_in, T *data_array = nullptr);
160
161 // copy assignment, not allowed
162 HContainer &operator=(const HContainer<T> &HR_in) = delete;
163
164 // move constructor
165 HContainer(HContainer<T> &&HR_in) noexcept;
166 // move assignment
167 HContainer &operator=(HContainer<T> &&HR_in) noexcept;
168
169 // simple constructor
170 HContainer(int natom);
171
172 // use unitcell to initialize atom_pairs
173 HContainer(const UnitCell &ucell_, const Parallel_Orbitals *paraV = nullptr);
174
181 HContainer(const Parallel_Orbitals *paraV, T *data_pointer = nullptr, const std::vector<int> *ijr_info = nullptr);
182
183 HContainer(const BasisFlattenedIndexing &basis, const Parallel_Blkcyclic &layout);
184
185 HContainer(const BasisFlattenedIndexing &basis, const Parallel_Blkcyclic &layout, T *data_pointer);
186
188 const BasisFlattenedIndexing &basis,
189 const Parallel_Blkcyclic &layout,
190 T *data_pointer,
191 const std::vector<int> *ijr_info);
192
196 void set_paraV(const Parallel_Orbitals *paraV_in)
197 {
198 this->paraV = paraV_in;
199 this->basis_index = nullptr;
200 this->matrix_dist = nullptr;
201 for (auto &ap : atom_pairs)
202 {
203 ap.set_paraV(paraV_in);
204 }
205 };
206
210 const Parallel_Orbitals *get_paraV() const { return this->paraV; };
211
221 void allocate(T *data_array = nullptr, bool if_zero = false);
222
226 void set_zero();
227
236 void insert_pair(const AtomPair<T> &atom_ij);
237
238 void insert_pair(const int iat1, const int iat2);
239 void insert_pair(const int iat1, const int iat2, const ModuleBase::Vector3<int> &R_index);
240
251 AtomPair<T> *find_pair(int i, int j) const;
252
260 int i,
261 int j,
262 int rx,
263 int ry,
264 int rz);
266 int i,
267 int j,
268 int rx,
269 int ry,
270 int rz) const;
271 BaseMatrix<T> *find_matrix(int i, int j, const ModuleBase::Vector3<int> &R_index);
272 const BaseMatrix<T> *find_matrix(int i, int j, const ModuleBase::Vector3<int> &R_index) const;
273
280 int i,
281 int j,
282 int rx,
283 int ry,
284 int rz) const;
285 int find_matrix_offset(int i, int j, const ModuleBase::Vector3<int> &R_index) const;
286
293 AtomPair<T> &get_atom_pair(int i, int j) const;
301 AtomPair<T> &get_atom_pair(int index) const;
302
316 // T& operator()(int atom_i, int atom_j, int rx_in, int ry_in, int rz_in, int mu, int nu) const;
317
321 void add(const HContainer<T> &other);
322
330 void add_value_intersection(const HContainer<T> &other, T factor = T(1));
331
339 void add_value_union(const HContainer<T> &other, T factor = T(1));
340
341 // save atom-pair pointers into this->tmp_atom_pairs for selected R index
350 bool fix_R(int rx_in, int ry_in, int rz_in) const;
351
356 void unfix_R() const;
357
374 void fix_gamma();
375
376 // interface for call a R loop for HContainer
377 // it can return a new R-index with (rx,ry,rz) for each loop
378 // if index==0, a new loop of R will be initialized
389 void loop_R(
390 const size_t &index,
391 int &rx,
392 int &ry,
393 int &rz) const;
394
398 size_t size_R_loop() const;
399
408 int find_R(const int &rx_in, const int &ry_in, const int &rz_in) const;
409 int find_R(const ModuleBase::Vector3<int> &R_in) const;
410
414 size_t size_atom_pairs() const;
415
423 T *data(int i, int j) const;
424
433 T *data(int i, int j, int *R) const;
434
438 int get_current_R() const;
439
443 bool is_gamma_only() const;
444
448 size_t get_memory_size() const;
449
455 size_t get_nnr() const
456 {
457 size_t sum = 0;
458 for (int iap = 0; iap < this->atom_pairs.size(); ++iap)
459 {
460 sum += this->atom_pairs[iap].get_R_size() * this->atom_pairs[iap].get_size();
461 }
462 return sum;
463 }
464
469 std::vector<int> get_ijr_info() const;
470
477 void insert_ijrs(const std::vector<int> *ijrs);
478
485 void insert_ijrs(const std::vector<int> *ijrs, const UnitCell &ucell, const int npol = 1);
486
490 T *get_wrapper() const { return this->wrapper_pointer; }
491
496 void shape_synchron(const HContainer<T> &other);
497
502 const std::vector<std::vector<int>> &get_sparse_ap() const { return sparse_ap; }
503
508 const std::vector<std::vector<int>> &get_sparse_ap_index() const { return sparse_ap_index; }
509
514 int get_nbasis() const;
515
516 private:
517 // i-j atom pairs, sorted by matrix of (atom_i, atom_j)
518 std::vector<AtomPair<T>> atom_pairs;
519
520 // sparse table for (atom_i, atom_j)->index of atom_pairs
521 std::vector<std::vector<int>> sparse_ap;
522 std::vector<std::vector<int>> sparse_ap_index;
523
524 // record allocated memory size
525 size_t allocated_size = 0;
526
530 mutable std::vector<const AtomPair<T> *> tmp_atom_pairs;
531 // it contains 3 index of cell, size of R_index is three times of values.
532 mutable std::vector<ModuleBase::Vector3<int>> tmp_R_index;
533 // current index of R in tmp_atom_pairs, -1 means not initialized
534 mutable int current_R = -1;
535
536 bool gamma_only = false;
537
544 T *wrapper_pointer = nullptr;
545 bool allocated = false;
546
550 const Parallel_Orbitals *paraV = nullptr;
551
554
555 bool same_layout(const HContainer<T> &other) const;
556 bool same_layout(const AtomPair<T> &atom_ij) const;
557
558 // int multiple = 1;
559 // int current_multiple = 0;
560};
561
562} // namespace hamilt
563
564#endif
Canonical atom-major flattening of the LCAO basis hierarchy.
Definition basis_flattened_indexing.h:40
3 elements vector
Definition vector3.h:21
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Definition parallel_orbitals.h:16
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition atom_pair.h:45
Definition base_matrix.h:20
Definition hcontainer.h:147
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:810
HContainer()
Definition hcontainer.cpp:30
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:715
void unfix_R() const
set current_R to -1, which means R is not fixed clear this->tmp_atom_pairs
Definition hcontainer.cpp:706
std::vector< AtomPair< T > > atom_pairs
Definition hcontainer.h:518
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:1077
size_t get_nnr() const
calculate total size of data in HContainer, named nnr inherited from history all AtomPairs and BaseMa...
Definition hcontainer.h:455
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:880
const BasisFlattenedIndexing * basis_index
Definition hcontainer.h:552
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:670
T * wrapper_pointer
if wrapper_pointer is not nullptr, this HContainer is a wrapper there is only one case that "wrapper_...
Definition hcontainer.h:544
T * data(int i, int j) const
get data pointer of AtomPair with index of I, J
Definition hcontainer.cpp:848
bool is_gamma_only() const
judge if gamma_only
Definition hcontainer.cpp:1005
size_t size_atom_pairs() const
calculate number of AtomPairs for current R index
Definition hcontainer.cpp:832
int get_current_R() const
get current_R
Definition hcontainer.cpp:998
int get_nbasis() const
get number of basis in each H matrix
Definition hcontainer.cpp:281
size_t allocated_size
Definition hcontainer.h:525
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:426
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:738
int current_R
Definition hcontainer.h:534
bool allocated
Definition hcontainer.h:545
const std::vector< std::vector< int > > & get_sparse_ap() const
get sparse_ap
Definition hcontainer.h:502
size_t size_R_loop() const
calculate number of R index which has counted AtomPairs
Definition hcontainer.cpp:775
const Parallel_Blkcyclic * matrix_dist
Definition hcontainer.h:553
bool same_layout(const HContainer< T > &other) const
Definition hcontainer.cpp:291
bool gamma_only
Definition hcontainer.h:536
void add_value_intersection(const HContainer< T > &other, T factor=T(1))
value-add over the SHARED sparsity only: for every (atom_i, atom_j, R) BaseMatrix present in BOTH con...
Definition hcontainer.cpp:594
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:1107
void set_paraV(const Parallel_Orbitals *paraV_in)
set parallel orbital pointer to check parallel information
Definition hcontainer.h:196
void add_value_union(const HContainer< T > &other, T factor=T(1))
value-add over the UNION sparsity: for every (atom_i, atom_j, R) BaseMatrix of other,...
Definition hcontainer.cpp:634
~HContainer()
Definition hcontainer.cpp:17
size_t get_memory_size() const
get total memory bites of HContainer
Definition hcontainer.cpp:1012
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:1038
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:324
void set_zero()
set values of all <IJR> matrix to zero
Definition hcontainer.cpp:369
std::vector< std::vector< int > > sparse_ap_index
Definition hcontainer.h:522
std::vector< ModuleBase::Vector3< int > > tmp_R_index
Definition hcontainer.h:532
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:528
T * get_wrapper() const
return the wrapper_pointer
Definition hcontainer.h:490
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:494
const Parallel_Orbitals * get_paraV() const
get parallel orbital pointer to check parallel information
Definition hcontainer.h:210
const std::vector< std::vector< int > > & get_sparse_ap_index() const
get sparse_ap_index
Definition hcontainer.h:508
const Parallel_Orbitals * paraV
pointer of Parallel_Orbitals, which is used to get atom-pair information
Definition hcontainer.h:550
std::vector< std::vector< int > > sparse_ap
Definition hcontainer.h:521
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:378
std::vector< const AtomPair< T > * > tmp_atom_pairs
temporary atom-pair lists to loop selected R index
Definition hcontainer.h:530
void add(const HContainer< T > &other)
operator() for accessing value with indexes this interface is not implemented now,...
Definition hcontainer.cpp:583
#define T
Definition exp.cpp:237
Definition wf_op.cpp:6