ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
LCAO_hamilt.hpp
Go to the documentation of this file.
2
3#ifndef LCAO_HAMILT_HPP
4#define LCAO_HAMILT_HPP
5
8#include "source_base/timer.h"
11
12#include <RI/global/Global_Func-2.h>
13#include <RI/ri/Cell_Nearest.h>
14#include <array>
15#include <map>
16#include <stdexcept>
17#include <string>
18#include <vector>
19
20#ifdef __EXX
21// Peize Lin add 2022.09.13
22
23template <typename Tdata>
24void sparse_format::cal_HR_exx(
25 const UnitCell& ucell,
26 const Parallel_Orbitals& pv,
27 LCAO_HS_Arrays& HS_Arrays,
28 const int& current_spin,
29 const double& sparse_threshold,
30 const int (&nmp)[3],
31 const std::vector<std::map<int, std::map<std::pair<int, std::array<int, 3>>, RI::Tensor<Tdata>>>>& Hexxs)
32{
33 ModuleBase::TITLE("sparse_format", "cal_HR_exx");
34 ModuleBase::timer::tick("sparse_format", "cal_HR_exx");
35
37
38 std::map<int, std::array<double, 3>> atoms_pos;
39 for (int iat = 0; iat < ucell.nat; ++iat)
40 {
41 atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]);
42 }
43 const std::array<std::array<double, 3>, 3> latvec
44 = {RI_Util::Vector3_to_array3(ucell.a1), // too bad to use GlobalC here,
47
48 const std::array<int, 3> Rs_period = {nmp[0], nmp[1], nmp[2]};
49
50 RI::Cell_Nearest<int, int, 3, double, 3> cell_nearest;
51 cell_nearest.init(atoms_pos, latvec, Rs_period);
52
53 const std::vector<int> is_list
54 = (PARAM.inp.nspin != 4) ? std::vector<int>{current_spin} : std::vector<int>{0, 1, 2, 3};
55
56 for (const int is: is_list)
57 {
58 int is0_b = 0;
59 int is1_b = 0;
60 std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is);
61
62 if (Hexxs.empty())
63 {
64 break;
65 }
66
67 for (const auto& HexxA: Hexxs[is])
68 {
69 const int iat0 = HexxA.first;
70 for (const auto& HexxB: HexxA.second)
71 {
72 const int iat1 = HexxB.first.first;
73
75 cell_nearest.get_cell_nearest_discrete(iat0, iat1, HexxB.first.second));
76
77 HS_Arrays.all_R_coor.insert(R);
78
79 const RI::Tensor<Tdata>& Hexx = HexxB.second;
80
81 for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0)
82 {
83 const int iwt0 = RI_2D_Comm::get_iwt(ucell, iat0, iw0, is0_b);
84 const int iwt0_local = pv.global2local_row(iwt0);
85
86 if (iwt0_local < 0)
87 {
88 continue;
89 }
90
91 for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1)
92 {
93 const int iwt1 = RI_2D_Comm::get_iwt(ucell, iat1, iw1, is1_b);
94 const int iwt1_local = pv.global2local_col(iwt1);
95
96 if (iwt1_local < 0)
97 {
98 continue;
99 }
100
101 if (std::abs(Hexx(iw0, iw1)) > sparse_threshold)
102 {
103 if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
104 {
105 auto& HR_sparse_ptr = HS_Arrays.HR_sparse[current_spin][R][iwt0];
106 double& HR_sparse = HR_sparse_ptr[iwt1];
107 HR_sparse += RI::Global_Func::convert<double>(frac * Hexx(iw0, iw1));
108 if (std::abs(HR_sparse) <= sparse_threshold)
109 {
110 HR_sparse_ptr.erase(iwt1);
111 }
112 }
113 else if (PARAM.inp.nspin == 4)
114 {
115 auto& HR_sparse_ptr = HS_Arrays.HR_soc_sparse[R][iwt0];
116
117 std::complex<double>& HR_sparse = HR_sparse_ptr[iwt1];
118
119 HR_sparse += RI::Global_Func::convert<std::complex<double>>(frac * Hexx(iw0, iw1));
120
121 if (std::abs(HR_sparse) <= sparse_threshold)
122 {
123 HR_sparse_ptr.erase(iwt1);
124 }
125 }
126 else
127 {
128 throw std::invalid_argument(std::string(__FILE__) + " line "
129 + std::to_string(__LINE__));
130 }
131 }
132 }
133 }
134 }
135 }
136 }
137
138 ModuleBase::timer::tick("sparse_format", "cal_HR_exx");
139}
140#endif
141
142#endif
Definition abfs-vector3_order.h:16
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:36
Definition LCAO_HS_arrays.hpp:9
std::set< Abfs::Vector3_Order< int > > all_R_coor
Definition LCAO_HS_arrays.hpp:71
std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, double > > > HR_sparse[2]
Definition LCAO_HS_arrays.hpp:29
std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, std::complex< double > > > > HR_soc_sparse
Definition LCAO_HS_arrays.hpp:50
static void tick(const std::string &class_name_in, const std::string &name_in)
Use twice at a time: the first time, set start_flag to false; the second time, calculate the time dur...
Definition timer.cpp:66
int global2local_col(const int igc) const
get the local index of a global index (col)
Definition parallel_2d.h:51
int global2local_row(const int igr) const
get the local index of a global index (row)
Definition parallel_2d.h:45
Definition parallel_orbitals.h:9
const Input_para & inp
Definition parameter.h:26
Definition unitcell.h:17
int *& iat2it
Definition unitcell.h:49
Atom * atoms
Definition unitcell.h:19
int & nat
Definition unitcell.h:48
ModuleBase::Vector3< double > & a2
Definition unitcell.h:38
ModuleBase::Vector3< double > & a3
Definition unitcell.h:38
int *& iat2ia
Definition unitcell.h:50
ModuleBase::Vector3< double > & a1
Definition unitcell.h:38
Exx_Info exx_info
Definition test_xc.cpp:29
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
std::tuple< int, int > split_is_block(const int is_b)
Definition RI_2D_Comm.hpp:201
int get_iwt(const UnitCell &ucell, const int iat, const int iw_b, const int is_b)
Definition RI_2D_Comm.hpp:216
std::array< Tcell, 3 > Vector3_to_array3(const ModuleBase::Vector3< Tcell > &v)
Definition RI_Util.h:32
ModuleBase::Vector3< Tcell > array3_to_Vector3(const std::array< Tcell, 3 > &v)
Definition RI_Util.h:38
Parameter PARAM
Definition parameter.cpp:3
double hybrid_alpha
Definition exx_info.h:31
Exx_Info_Global info_global
Definition exx_info.h:38
int nspin
LDA ; LSDA ; non-linear spin.
Definition input_parameter.h:85