ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
spar_hsr.h
Go to the documentation of this file.
1#ifndef SPARSE_FORMAT_HSR_H
2#define SPARSE_FORMAT_HSR_H
3
7
8#ifdef __EXX
9#include <RI/global/Tensor.h>
10#endif
11
12namespace sparse_format
13{
14#ifdef __MPI
15// Synchronize all processes' R coordinates,
16// otherwise HS_Arrays.all_R_coor would have different sizes on different processes,
17// causing MPI communication errors.
18void sync_all_R_coor(std::set<Abfs::Vector3_Order<int>>& all_R_coor, MPI_Comm comm);
19#endif
20
21template <typename T>
22std::set<Abfs::Vector3_Order<int>> get_R_range(const hamilt::HContainer<T>& hR)
23{
24 std::set<Abfs::Vector3_Order<int>> all_R_coor;
25 for (int iap = 0; iap < hR.size_atom_pairs(); ++iap)
26 {
27 const hamilt::AtomPair<T>& atom_pair = hR.get_atom_pair(iap);
28 for (int iR = 0; iR < atom_pair.get_R_size(); ++iR)
29 {
30 const auto& r_index = atom_pair.get_R_index(iR);
31 Abfs::Vector3_Order<int> dR(r_index.x, r_index.y, r_index.z);
32 all_R_coor.insert(dR);
33 }
34 }
35
36#ifdef __MPI
37 // Fix: Sync all_R_coor across processes
38 sparse_format::sync_all_R_coor(all_R_coor, MPI_COMM_WORLD);
39#endif
40
41 return all_R_coor;
42};
43
44template <typename TI, typename TO = TI>
46 const double& sparse_thr,
47 const hamilt::HContainer<TI>& hR,
48 std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, TO>>>& target);
49
50void clear_zero_elements(LCAO_HS_Arrays& HS_Arrays, const int& current_spin, const double& sparse_thr);
51
52void destroy_HS_R_sparse(LCAO_HS_Arrays& HS_Arrays);
53
54} // namespace sparse_format
55
56#endif
Definition abfs-vector3_order.h:16
Definition LCAO_HS_arrays.hpp:9
Definition parallel_orbitals.h:9
Definition atom_pair.h:42
ModuleBase::Vector3< int > get_R_index(const int &index) const
Definition atom_pair.cpp:795
size_t get_R_size() const
Definition atom_pair.h:288
Definition hcontainer.h:144
size_t size_atom_pairs() const
calculate number of AtomPairs for current R index
Definition hcontainer.cpp:601
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:378
Definition spar_dh.h:14
void destroy_HS_R_sparse(LCAO_HS_Arrays &HS_Arrays)
Definition spar_hsr.cpp:229
std::set< Abfs::Vector3_Order< int > > get_R_range(const hamilt::HContainer< T > &hR)
Definition spar_hsr.h:22
void clear_zero_elements(LCAO_HS_Arrays &HS_Arrays, const int &current_spin, const double &sparse_thr)
Definition spar_hsr.cpp:115
void sync_all_R_coor(std::set< Abfs::Vector3_Order< int > > &all_R_coor, MPI_Comm comm)
Definition spar_hsr.cpp:12
void cal_HContainer(const Parallel_Orbitals &pv, const double &sparse_thr, const hamilt::HContainer< TI > &hR, std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, TO > > > &target)
Definition spar_hsr.cpp:72