Skip to content

Commit 0107eb5

Browse files
committed
change ucell in module_ri/ri_2d_comm.cpp
1 parent ea871f0 commit 0107eb5

File tree

14 files changed

+71
-50
lines changed

14 files changed

+71
-50
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// Peize Lin add 2022.09.13
2222

2323
template <typename Tdata>
24-
void sparse_format::cal_HR_exx(
24+
void sparse_format::cal_HR_exx(const UnitCell& ucell,
2525
const Parallel_Orbitals& pv,
2626
LCAO_HS_Arrays& HS_Arrays,
2727
const int& current_spin,
@@ -36,15 +36,15 @@ void sparse_format::cal_HR_exx(
3636
const Tdata frac = GlobalC::exx_info.info_global.hybrid_alpha;
3737

3838
std::map<int, std::array<double, 3>> atoms_pos;
39-
for (int iat = 0; iat < GlobalC::ucell.nat; ++iat) {
39+
for (int iat = 0; iat < ucell.nat; ++iat) {
4040
atoms_pos[iat] = RI_Util::Vector3_to_array3(
41-
GlobalC::ucell.atoms[GlobalC::ucell.iat2it[iat]]
42-
.tau[GlobalC::ucell.iat2ia[iat]]);
41+
ucell.atoms[ucell.iat2it[iat]]
42+
.tau[ucell.iat2ia[iat]]);
4343
}
4444
const std::array<std::array<double, 3>, 3> latvec
45-
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1), // too bad to use GlobalC here,
46-
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
47-
RI_Util::Vector3_to_array3(GlobalC::ucell.a3)};
45+
= {RI_Util::Vector3_to_array3(ucell.a1), // too bad to use GlobalC here,
46+
RI_Util::Vector3_to_array3(ucell.a2),
47+
RI_Util::Vector3_to_array3(ucell.a3)};
4848

4949
const std::array<int, 3> Rs_period = {nmp[0], nmp[1], nmp[2]};
5050

@@ -84,7 +84,7 @@ void sparse_format::cal_HR_exx(
8484

8585
for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0)
8686
{
87-
const int iwt0 = RI_2D_Comm::get_iwt(iat0, iw0, is0_b);
87+
const int iwt0 = RI_2D_Comm::get_iwt(ucell,iat0, iw0, is0_b);
8888
const int iwt0_local = pv.global2local_row(iwt0);
8989

9090
if (iwt0_local < 0)
@@ -94,7 +94,7 @@ void sparse_format::cal_HR_exx(
9494

9595
for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1)
9696
{
97-
const int iwt1 = RI_2D_Comm::get_iwt(iat1, iw1, is1_b);
97+
const int iwt1 = RI_2D_Comm::get_iwt(ucell,iat1, iw1, is1_b);
9898
const int iwt1_local = pv.global2local_col(iwt1);
9999

100100
if (iwt1_local < 0)

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
403403
// and calculate Cs, Vs
404404
Operator<TK>* exx = new OperatorEXX<OperatorLCAO<TK, TR>>(this->hsk,
405405
this->hR,
406+
ucell,
406407
*this->kv,
407408
Hexxd,
408409
Hexxc,

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class OperatorEXX<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
2828
public:
2929
OperatorEXX<OperatorLCAO<TK, TR>>(HS_Matrix_K<TK>* hsk_in,
3030
hamilt::HContainer<TR>* hR_in,
31+
const UnitCell& ucell,
3132
const K_Vectors& kv_in,
3233
std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd_in = nullptr,
3334
std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc_in = nullptr,
@@ -58,7 +59,9 @@ class OperatorEXX<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
5859
const int istep = 0; // the ion step
5960

6061
void add_loaded_Hexx(const int ik);
61-
62+
63+
const UnitCell& ucell;
64+
6265
const K_Vectors& kv;
6366

6467
// if k points has no shift, use cell_nearest to reduce the memory cost

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ namespace hamilt
4949
auto* pv = hR->get_paraV();
5050
auto Rs = RI_Util::get_Born_von_Karmen_cells(Rs_period);
5151
bool need_allocate = false;
52-
for (int iat0 = 0;iat0 < GlobalC::ucell.nat;++iat0)
52+
for (int iat0 = 0;iat0 < nat;++iat0)
5353
{
54-
for (int iat1 = 0;iat1 < GlobalC::ucell.nat;++iat1)
54+
for (int iat1 = 0;iat1 < nat;++iat1)
5555
{
5656
// complete the atom pairs that has orbitals in this processor but not in hR due to the adj_list
5757
// but adj_list is not enought for EXX, which is more nonlocal than Nonlocal
@@ -81,6 +81,7 @@ namespace hamilt
8181
template <typename TK, typename TR>
8282
OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
8383
HContainer<TR>*hR_in,
84+
const UnitCell& ucell_in,
8485
const K_Vectors& kv_in,
8586
std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd_in,
8687
std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc_in,
@@ -89,6 +90,7 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
8990
int* two_level_step_in,
9091
const bool restart_in)
9192
: OperatorLCAO<TK, TR>(hsk_in, kv_in.kvec_d, hR_in),
93+
ucell(ucell_in),
9294
kv(kv_in),
9395
Hexxd(Hexxd_in),
9496
Hexxc(Hexxc_in),
@@ -115,12 +117,12 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
115117
// Read HexxR in CSR format
116118
if (GlobalC::exx_info.info_ri.real_number)
117119
{
118-
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
120+
ModuleIO::read_Hexxs_csr(file_name_exx, ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
119121
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); }
120122
}
121123
else
122124
{
123-
ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
125+
ModuleIO::read_Hexxs_csr(file_name_exx, ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
124126
if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); }
125127
}
126128
}
@@ -154,19 +156,19 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
154156
{
155157
// set cell_nearest
156158
std::map<int, std::array<double, 3>> atoms_pos;
157-
for (int iat = 0; iat < GlobalC::ucell.nat; ++iat) {
159+
for (int iat = 0; iat < ucell.nat; ++iat) {
158160
atoms_pos[iat] = RI_Util::Vector3_to_array3(
159-
GlobalC::ucell.atoms[GlobalC::ucell.iat2it[iat]]
160-
.tau[GlobalC::ucell.iat2ia[iat]]);
161+
ucell.atoms[ucell.iat2it[iat]]
162+
.tau[ucell.iat2ia[iat]]);
161163
}
162164
const std::array<std::array<double, 3>, 3> latvec
163-
= { RI_Util::Vector3_to_array3(GlobalC::ucell.a1),
164-
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
165-
RI_Util::Vector3_to_array3(GlobalC::ucell.a3) };
165+
= { RI_Util::Vector3_to_array3(ucell.a1),
166+
RI_Util::Vector3_to_array3(ucell.a2),
167+
RI_Util::Vector3_to_array3(ucell.a3) };
166168
this->cell_nearest.init(atoms_pos, latvec, Rs_period);
167-
reallocate_hcontainer(GlobalC::ucell.nat, this->hR, Rs_period, &this->cell_nearest);
169+
reallocate_hcontainer(ucell.nat, this->hR, Rs_period, &this->cell_nearest);
168170
}
169-
else { reallocate_hcontainer(GlobalC::ucell.nat, this->hR, Rs_period); }
171+
else { reallocate_hcontainer(ucell.nat, this->hR, Rs_period); }
170172
}
171173

172174
if (this->restart)
@@ -216,10 +218,10 @@ OperatorEXX<OperatorLCAO<TK, TR>>::OperatorEXX(HS_Matrix_K<TK>* hsk_in,
216218
{
217219
// Read HexxR in CSR format
218220
if (GlobalC::exx_info.info_ri.real_number) {
219-
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
221+
ModuleIO::read_Hexxs_csr(restart_HR_path, ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd);
220222
}
221223
else {
222-
ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
224+
ModuleIO::read_Hexxs_csr(restart_HR_path, ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc);
223225
}
224226
}
225227
else
@@ -317,6 +319,7 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHk(int ik)
317319

318320
if (GlobalC::exx_info.info_ri.real_number) {
319321
RI_2D_Comm::add_Hexx(
322+
ucell,
320323
this->kv,
321324
ik,
322325
GlobalC::exx_info.info_global.hybrid_alpha,
@@ -325,6 +328,7 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHk(int ik)
325328
this->hsk->get_hk());
326329
} else {
327330
RI_2D_Comm::add_Hexx(
331+
ucell,
328332
this->kv,
329333
ik,
330334
GlobalC::exx_info.info_global.hybrid_alpha,

source/module_hamilt_lcao/hamilt_lcaodft/spar_exx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_HS_arrays.hpp"
1313
#include "module_basis/module_ao/parallel_orbitals.h"
14-
14+
#include "module_cell/unitcell.h"
1515
namespace sparse_format
1616
{
1717

1818
template <typename Tdata>
19-
void cal_HR_exx(
19+
void cal_HR_exx(const UnitCell& ucell,
2020
const Parallel_Orbitals& pv,
2121
LCAO_HS_Arrays& HS_Arrays,
2222
const int& current_spin,

source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "spar_exx.h"
88
#include "spar_u.h"
99

10-
void sparse_format::cal_HSR(const Parallel_Orbitals& pv,
10+
void sparse_format::cal_HSR(const UnitCell& ucell,
11+
const Parallel_Orbitals& pv,
1112
LCAO_HS_Arrays& HS_Arrays,
1213
Grid_Driver& grid,
1314
const int& current_spin,
@@ -99,7 +100,8 @@ void sparse_format::cal_HSR(const Parallel_Orbitals& pv,
99100
if (GlobalC::exx_info.info_global.cal_exx) {
100101
if (Hexxd && GlobalC::exx_info.info_ri.real_number)
101102
{
102-
sparse_format::cal_HR_exx(pv,
103+
sparse_format::cal_HR_exx(ucell,
104+
pv,
103105
HS_Arrays,
104106
current_spin,
105107
sparse_thr,
@@ -108,7 +110,8 @@ void sparse_format::cal_HSR(const Parallel_Orbitals& pv,
108110
}
109111
else if (Hexxc && !GlobalC::exx_info.info_ri.real_number)
110112
{
111-
sparse_format::cal_HR_exx(pv,
113+
sparse_format::cal_HR_exx(ucell,
114+
pv,
112115
HS_Arrays,
113116
current_spin,
114117
sparse_thr,

source/module_hamilt_lcao/hamilt_lcaodft/spar_hsr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
namespace sparse_format {
77
using TAC = std::pair<int, std::array<int, 3>>;
8-
void cal_HSR(const Parallel_Orbitals& pv,
8+
void cal_HSR(const UnitCell& ucell,
9+
const Parallel_Orbitals& pv,
910
LCAO_HS_Arrays& HS_Arrays,
1011
Grid_Driver& grid,
1112
const int& current_spin,

source/module_io/output_mat_sparse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void output_mat_sparse(const bool& out_mat_hsR,
4545
//! generate a file containing the Hamiltonian and S(overlap) matrices
4646
if (out_mat_hsR)
4747
{
48-
output_HSR(istep, v_eff, pv, HS_Arrays, grid, kv, p_ham);
48+
output_HSR(ucell,istep, v_eff, pv, HS_Arrays, grid, kv, p_ham);
4949
}
5050

5151
//! generate a file containing the kinetic energy matrix

source/module_io/write_HS_R.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
// The 'sparse_thr' is the accuracy of the sparse matrix.
1313
// If the absolute value of the matrix element is less than or equal to the
1414
// 'sparse_thr', it will be ignored.
15-
void ModuleIO::output_HSR(const int& istep,
15+
void ModuleIO::output_HSR(const UnitCell& ucell,
16+
const int& istep,
1617
const ModuleBase::matrix& v_eff,
1718
const Parallel_Orbitals& pv,
1819
LCAO_HS_Arrays& HS_Arrays,
@@ -37,7 +38,7 @@ void ModuleIO::output_HSR(const int& istep,
3738
if (nspin == 1 || nspin == 4) {
3839
const int spin_now = 0;
3940
// jingan add 2021-6-4, modify 2021-12-2
40-
sparse_format::cal_HSR(pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
41+
sparse_format::cal_HSR(ucell,pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
4142
#ifdef __EXX
4243
, Hexxd, Hexxc
4344
#endif
@@ -47,7 +48,7 @@ void ModuleIO::output_HSR(const int& istep,
4748
int spin_now = 1;
4849

4950
// save HR of spin down first (the current spin always be down)
50-
sparse_format::cal_HSR(pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
51+
sparse_format::cal_HSR(ucell,pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
5152
#ifdef __EXX
5253
, Hexxd, Hexxc
5354
#endif
@@ -61,7 +62,7 @@ void ModuleIO::output_HSR(const int& istep,
6162
spin_now = 0;
6263
}
6364

64-
sparse_format::cal_HSR(pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
65+
sparse_format::cal_HSR(ucell,pv, HS_Arrays, grid, spin_now, sparse_thr, kv.nmp, p_ham
6566
#ifdef __EXX
6667
, Hexxd, Hexxc
6768
#endif

source/module_io/write_HS_R.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace ModuleIO
1212
{
1313
using TAC = std::pair<int, std::array<int, 3>>;
14-
void output_HSR(const int& istep,
14+
void output_HSR(const UnitCell& ucell,
15+
const int& istep,
1516
const ModuleBase::matrix& v_eff,
1617
const Parallel_Orbitals& pv,
1718
LCAO_HS_Arrays& HS_Arrays,

0 commit comments

Comments
 (0)