Skip to content

Commit 3afb499

Browse files
Refactor:remove GlobalC::ucell in module_ri (#5698)
* change ucell in module_exx/exx_lri_interface.hpp * change ucell in exx_lri/init * change ucell in exx_abfs-construct.cpp * change ucell in module_ri/exx_abfs-jle.cpp * change ucell in module_ri/exx_lip.hpp * change ucell in module_ri/exx_lri.hpp * change ucell in module_ri/exx_lir.hpp/cal_exx_elec * change ucell in module_ri/exx_lri.hpp * change ucell in module_ri/exx_opt-print.hpp * change ucell in module_ri/exx_opt.cpp * change ucell in module_ri/rpa_lri.cpp * change ucell in module_ri/rpa_lri_tool.cpp * change ucell in module_ri/ri_2d_comm.cpp * change ucell in module_ri/ri_2d_comm.cpp * change ucell in module_ri/rpa_lri.cpp * change ucell in module_ri/lri_cv_tools.cpp * change ucell in module_ri/matirx_orb11.cpp * change ucell in module_ri/matirx_orb21.cpp * change ucell in module_ri/matirx_orb2.cpp * change lat0 in Matrix.cpp * change ucell in Matrix.cpp * change ucell in module_ri/matirx_orb22,matirx_orb11.cpp * [pre-commit.ci lite] apply automatic fixes * update reference of lat0 in ri --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 2c109a0 commit 3afb499

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+680
-440
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
178178
// initialize 2-center radial tables for EXX-LRI
179179
if (GlobalC::exx_info.info_ri.real_number)
180180
{
181-
this->exx_lri_double->init(MPI_COMM_WORLD, this->kv, orb_);
181+
this->exx_lri_double->init(MPI_COMM_WORLD, ucell,this->kv, orb_);
182182
this->exd->exx_before_all_runners(this->kv, ucell, this->pv);
183183
}
184184
else
185185
{
186-
this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv, orb_);
186+
this->exx_lri_complex->init(MPI_COMM_WORLD, ucell,this->kv, orb_);
187187
this->exc->exx_before_all_runners(this->kv, ucell, this->pv);
188188
}
189189
}
@@ -623,13 +623,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
623623
if (GlobalC::exx_info.info_ri.real_number)
624624
{
625625
this->exd->exx_eachiterinit(istep,
626+
ucell,
626627
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
627628
this->kv,
628629
iter);
629630
}
630631
else
631632
{
632633
this->exc->exx_eachiterinit(istep,
634+
ucell,
633635
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
634636
this->kv,
635637
iter);
@@ -1052,7 +1054,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10521054
occ_number_ks(ik, inb) /= this->kv.wk[ik];
10531055
}
10541056
}
1055-
this->rdmft_solver.update_elec(occ_number_ks, *(this->psi));
1057+
this->rdmft_solver.update_elec(ucell,occ_number_ks, *(this->psi));
10561058

10571059
//! initialize the gradients of Etotal with respect to occupation numbers and wfc,
10581060
//! and set all elements to 0.
@@ -1074,10 +1076,11 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10741076
RPA_LRI<TK, double> rpa_lri_double(GlobalC::exx_info.info_ri);
10751077
rpa_lri_double.cal_postSCF_exx(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
10761078
MPI_COMM_WORLD,
1079+
ucell,
10771080
this->kv,
10781081
orb_);
10791082
rpa_lri_double.init(MPI_COMM_WORLD, this->kv, orb_.cutoffs());
1080-
rpa_lri_double.out_for_RPA(this->pv, *(this->psi), this->pelec);
1083+
rpa_lri_double.out_for_RPA(ucell,this->pv, *(this->psi), this->pelec);
10811084
}
10821085
#endif
10831086

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,25 +375,25 @@ void Force_Stress_LCAO<T>::getForceStress(const bool isforce,
375375
{
376376
if (GlobalC::exx_info.info_ri.real_number)
377377
{
378-
exx_lri_double.cal_exx_force();
378+
exx_lri_double.cal_exx_force(ucell.nat);
379379
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_lri_double.force_exx;
380380
}
381381
else
382382
{
383-
exx_lri_complex.cal_exx_force();
383+
exx_lri_complex.cal_exx_force(ucell.nat);
384384
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_lri_complex.force_exx;
385385
}
386386
}
387387
if (isstress)
388388
{
389389
if (GlobalC::exx_info.info_ri.real_number)
390390
{
391-
exx_lri_double.cal_exx_stress();
391+
exx_lri_double.cal_exx_stress(ucell.omega,ucell.lat0);
392392
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_lri_double.stress_exx;
393393
}
394394
else
395395
{
396-
exx_lri_complex.cal_exx_stress();
396+
exx_lri_complex.cal_exx_stress(ucell.omega,ucell.lat0);
397397
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * exx_lri_complex.stress_exx;
398398
}
399399
}

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

0 commit comments

Comments
 (0)