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(const UnitCell& ucell,
25 const Parallel_Orbitals& pv,
26 LCAO_HS_Arrays& HS_Arrays,
27 const int& current_spin,
28 const double& sparse_threshold,
29 const int (&nmp)[3],
30 const std::vector<std::map<int,
31 std::map<std::pair<int, std::array<int, 3>>,
32 RI::Tensor<Tdata>>>>& Hexxs) {
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 atoms_pos[iat] = RI_Util::Vector3_to_array3(
41 ucell.atoms[ucell.iat2it[iat]]
42 .tau[ucell.iat2ia[iat]]);
43 }
44 const std::array<std::array<double, 3>, 3> latvec
45 = {RI_Util::Vector3_to_array3(ucell.a1), // too bad to use GlobalC here,
48
49 const std::array<int, 3> Rs_period = {nmp[0], nmp[1], nmp[2]};
50
51 RI::Cell_Nearest<int, int, 3, double, 3> cell_nearest;
52 cell_nearest.init(atoms_pos, latvec, Rs_period);
53
54 const std::vector<int> is_list = (PARAM.inp.nspin != 4)
55 ? std::vector<int>{current_spin}
56 : std::vector<int>{0, 1, 2, 3};
57
58 for (const int is: is_list)
59 {
60 int is0_b = 0;
61 int is1_b = 0;
62 std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is);
63
64 if (Hexxs.empty())
65 {
66 break;
67 }
68
69 for (const auto& HexxA: Hexxs[is])
70 {
71 const int iat0 = HexxA.first;
72 for (const auto& HexxB: HexxA.second)
73 {
74 const int iat1 = HexxB.first.first;
75
77 cell_nearest.get_cell_nearest_discrete(iat0,
78 iat1,
79 HexxB.first.second));
80
81 HS_Arrays.all_R_coor.insert(R);
82
83 const RI::Tensor<Tdata>& Hexx = HexxB.second;
84
85 for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0)
86 {
87 const int iwt0 = RI_2D_Comm::get_iwt(ucell,iat0, iw0, is0_b);
88 const int iwt0_local = pv.global2local_row(iwt0);
89
90 if (iwt0_local < 0)
91 {
92 continue;
93 }
94
95 for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1)
96 {
97 const int iwt1 = RI_2D_Comm::get_iwt(ucell,iat1, iw1, is1_b);
98 const int iwt1_local = pv.global2local_col(iwt1);
99
100 if (iwt1_local < 0)
101 {
102 continue;
103 }
104
105 if (std::abs(Hexx(iw0, iw1)) > sparse_threshold)
106 {
107 if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
108 {
109 auto& HR_sparse_ptr
110 = HS_Arrays
111 .HR_sparse[current_spin][R][iwt0];
112 double& HR_sparse = HR_sparse_ptr[iwt1];
113 HR_sparse += RI::Global_Func::convert<double>(
114 frac * Hexx(iw0, iw1));
115 if (std::abs(HR_sparse) <= sparse_threshold)
116 {
117 HR_sparse_ptr.erase(iwt1);
118 }
119 }
120 else if (PARAM.inp.nspin == 4)
121 {
122 auto& HR_sparse_ptr
123 = HS_Arrays.HR_soc_sparse[R][iwt0];
124
125 std::complex<double>& HR_sparse
126 = HR_sparse_ptr[iwt1];
127
128 HR_sparse += RI::Global_Func::convert<
129 std::complex<double>>(frac * Hexx(iw0, iw1));
130
131 if (std::abs(HR_sparse) <= sparse_threshold)
132 {
133 HR_sparse_ptr.erase(iwt1);
134 }
135 }
136 else
137 {
138 throw std::invalid_argument(std::string(__FILE__) + " line "
139 + std::to_string(__LINE__));
140 }
141 }
142 }
143 }
144 }
145 }
146 }
147
148 ModuleBase::timer::tick("sparse_format", "cal_HR_exx");
149}
150#endif
151
152#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:57
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:16
int *& iat2it
Definition unitcell.h:47
Atom * atoms
Definition unitcell.h:18
int & nat
Definition unitcell.h:46
ModuleBase::Vector3< double > & a2
Definition unitcell.h:36
ModuleBase::Vector3< double > & a3
Definition unitcell.h:36
int *& iat2ia
Definition unitcell.h:48
ModuleBase::Vector3< double > & a1
Definition unitcell.h:36
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:84