Skip to content

Commit 05d089c

Browse files
committed
change ucell in dftu_occup
1 parent 475bddd commit 05d089c

File tree

4 files changed

+72
-54
lines changed

4 files changed

+72
-54
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
881881
{
882882
const std::vector<std::vector<TK>>& tmp_dm
883883
= dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->get_DMK_vector();
884-
ModuleDFTU::dftu_cal_occup_m(iter, tmp_dm, this->kv, this->p_chgmix->get_mixing_beta(), this->p_hamilt);
884+
ModuleDFTU::dftu_cal_occup_m(iter, ucell,tmp_dm, this->kv, this->p_chgmix->get_mixing_beta(), this->p_hamilt);
885885
}
886886
GlobalC::dftu.cal_energy_correction(ucell,istep);
887887
}

source/module_hamilt_lcao/module_dftu/dftu.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void DFTU::init(UnitCell& cell, // unitcell class
185185
#endif
186186

187187
initialed_locale = true;
188-
this->copy_locale();
188+
this->copy_locale(cell);
189189
}
190190
else
191191
{
@@ -201,7 +201,7 @@ void DFTU::init(UnitCell& cell, // unitcell class
201201
}
202202
else
203203
{
204-
this->zero_locale();
204+
this->zero_locale(cell);
205205
}
206206
}
207207

@@ -423,22 +423,24 @@ const hamilt::HContainer<double>* DFTU::get_dmr(int ispin) const
423423
//! dftu occupation matrix for gamma only using dm(double)
424424
template <>
425425
void dftu_cal_occup_m(const int iter,
426+
const UnitCell& ucell,
426427
const std::vector<std::vector<double>>& dm,
427428
const K_Vectors& kv,
428429
const double& mixing_beta,
429430
hamilt::Hamilt<double>* p_ham)
430431
{
431-
GlobalC::dftu.cal_occup_m_gamma(iter, dm, mixing_beta, p_ham);
432+
GlobalC::dftu.cal_occup_m_gamma(iter, ucell ,dm, mixing_beta, p_ham);
432433
}
433434

434435
//! dftu occupation matrix for multiple k-points using dm(complex)
435436
template <>
436437
void dftu_cal_occup_m(const int iter,
438+
const UnitCell& ucell,
437439
const std::vector<std::vector<std::complex<double>>>& dm,
438440
const K_Vectors& kv,
439441
const double& mixing_beta,
440442
hamilt::Hamilt<std::complex<double>>* p_ham)
441443
{
442-
GlobalC::dftu.cal_occup_m_k(iter, dm, kv, mixing_beta, p_ham);
444+
GlobalC::dftu.cal_occup_m_k(iter,ucell, dm, kv, mixing_beta, p_ham);
443445
}
444446
} // namespace ModuleDFTU

source/module_hamilt_lcao/module_dftu/dftu.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,25 @@ class DFTU
8989
//=============================================================
9090
public:
9191
// calculate the local occupation number matrix
92-
void cal_occup_m_k(const int iter, const std::vector<std::vector<std::complex<double>>>& dm_k, const K_Vectors& kv, const double& mixing_beta, hamilt::Hamilt<std::complex<double>>* p_ham);
93-
void cal_occup_m_gamma(const int iter, const std::vector<std::vector<double>>& dm_gamma, const double& mixing_beta, hamilt::Hamilt<double>* p_ham);
92+
void cal_occup_m_k(const int iter,
93+
const UnitCell& ucell,
94+
const std::vector<std::vector<std::complex<double>>>& dm_k,
95+
const K_Vectors& kv,
96+
const double& mixing_beta,
97+
hamilt::Hamilt<std::complex<double>>* p_ham);
98+
void cal_occup_m_gamma(const int iter,
99+
const UnitCell& ucell,
100+
const std::vector<std::vector<double>>& dm_gamma,
101+
const double& mixing_beta,
102+
hamilt::Hamilt<double>* p_ham);
94103

95104
// dftu can be calculated only after locale has been initialed
96105
bool initialed_locale = false;
97106

98107
private:
99-
void copy_locale();
100-
void zero_locale();
101-
void mix_locale(const double& mixing_beta);
108+
void copy_locale(const UnitCell& ucell);
109+
void zero_locale(const UnitCell& ucell);
110+
void mix_locale(const UnitCell& ucell,const double& mixing_beta);
102111

103112
public:
104113
// local occupancy matrix of the correlated subspace
@@ -270,6 +279,7 @@ class DFTU
270279

271280
template <typename T>
272281
void dftu_cal_occup_m(const int iter,
282+
const UnitCell& ucell,
273283
const std::vector<std::vector<T>>& dm,
274284
const K_Vectors& kv,
275285
const double& mixing_beta,

source/module_hamilt_lcao/module_dftu/dftu_occup.cpp

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ extern "C"
2929

3030
namespace ModuleDFTU
3131
{
32-
void DFTU::copy_locale()
32+
void DFTU::copy_locale(const UnitCell& ucell)
3333
{
3434
ModuleBase::TITLE("DFTU", "copy_locale");
3535
ModuleBase::timer::tick("DFTU", "copy_locale");
3636

37-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
37+
for (int T = 0; T < ucell.ntype; T++)
3838
{
3939
if (orbital_corr[T] == -1)
4040
continue;
4141

42-
for (int I = 0; I < GlobalC::ucell.atoms[T].na; I++)
42+
for (int I = 0; I < ucell.atoms[T].na; I++)
4343
{
44-
const int iat = GlobalC::ucell.itia2iat(T, I);
44+
const int iat = ucell.itia2iat(T, I);
4545

46-
for (int l = 0; l < GlobalC::ucell.atoms[T].nwl + 1; l++)
46+
for (int l = 0; l < ucell.atoms[T].nwl + 1; l++)
4747
{
48-
const int N = GlobalC::ucell.atoms[T].l_nchi[l];
48+
const int N = ucell.atoms[T].l_nchi[l];
4949

5050
for (int n = 0; n < N; n++)
5151
{
@@ -65,22 +65,22 @@ void DFTU::copy_locale()
6565
ModuleBase::timer::tick("DFTU", "copy_locale");
6666
}
6767

68-
void DFTU::zero_locale()
68+
void DFTU::zero_locale(const UnitCell& ucell)
6969
{
7070
ModuleBase::TITLE("DFTU", "zero_locale");
7171
ModuleBase::timer::tick("DFTU", "zero_locale");
7272

73-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
73+
for (int T = 0; T < ucell.ntype; T++)
7474
{
7575
if (orbital_corr[T] == -1) continue;
7676

77-
for (int I = 0; I < GlobalC::ucell.atoms[T].na; I++)
77+
for (int I = 0; I < ucell.atoms[T].na; I++)
7878
{
79-
const int iat = GlobalC::ucell.itia2iat(T, I);
79+
const int iat = ucell.itia2iat(T, I);
8080

81-
for (int l = 0; l < GlobalC::ucell.atoms[T].nwl + 1; l++)
81+
for (int l = 0; l < ucell.atoms[T].nwl + 1; l++)
8282
{
83-
const int N = GlobalC::ucell.atoms[T].l_nchi[l];
83+
const int N = ucell.atoms[T].l_nchi[l];
8484

8585
for (int n = 0; n < N; n++)
8686
{
@@ -100,25 +100,26 @@ void DFTU::zero_locale()
100100
ModuleBase::timer::tick("DFTU", "zero_locale");
101101
}
102102

103-
void DFTU::mix_locale(const double& mixing_beta)
103+
void DFTU::mix_locale(const UnitCell& ucell,
104+
const double& mixing_beta)
104105
{
105106
ModuleBase::TITLE("DFTU", "mix_locale");
106107
ModuleBase::timer::tick("DFTU", "mix_locale");
107108

108109
double beta = mixing_beta;
109110

110-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
111+
for (int T = 0; T < ucell.ntype; T++)
111112
{
112113
if (orbital_corr[T] == -1)
113114
continue;
114115

115-
for (int I = 0; I < GlobalC::ucell.atoms[T].na; I++)
116+
for (int I = 0; I < ucell.atoms[T].na; I++)
116117
{
117-
const int iat = GlobalC::ucell.itia2iat(T, I);
118+
const int iat = ucell.itia2iat(T, I);
118119

119-
for (int l = 0; l < GlobalC::ucell.atoms[T].nwl + 1; l++)
120+
for (int l = 0; l < ucell.atoms[T].nwl + 1; l++)
120121
{
121-
const int N = GlobalC::ucell.atoms[T].l_nchi[l];
122+
const int N = ucell.atoms[T].l_nchi[l];
122123

123124
for (int n = 0; n < N; n++)
124125
{
@@ -139,16 +140,17 @@ void DFTU::mix_locale(const double& mixing_beta)
139140
}
140141

141142
void DFTU::cal_occup_m_k(const int iter,
142-
const std::vector<std::vector<std::complex<double>>>& dm_k,
143-
const K_Vectors& kv,
144-
const double& mixing_beta,
145-
hamilt::Hamilt<std::complex<double>>* p_ham)
143+
const UnitCell& ucell,
144+
const std::vector<std::vector<std::complex<double>>>& dm_k,
145+
const K_Vectors& kv,
146+
const double& mixing_beta,
147+
hamilt::Hamilt<std::complex<double>>* p_ham)
146148
{
147149
ModuleBase::TITLE("DFTU", "cal_occup_m_k");
148150
ModuleBase::timer::tick("DFTU", "cal_occup_m_k");
149151

150-
this->copy_locale();
151-
this->zero_locale();
152+
this->copy_locale(ucell);
153+
this->zero_locale(ucell);
152154

153155
//=================Part 1======================
154156
// call SCALAPACK routine to calculate the product of the S and density matrix
@@ -196,24 +198,24 @@ void DFTU::cal_occup_m_k(const int iter,
196198
#endif
197199

198200
const int spin = kv.isk[ik];
199-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
201+
for (int it = 0; it < ucell.ntype; it++)
200202
{
201-
const int NL = GlobalC::ucell.atoms[it].nwl + 1;
203+
const int NL = ucell.atoms[it].nwl + 1;
202204
const int LC = orbital_corr[it];
203205

204206
if (LC == -1)
205207
continue;
206208

207-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
209+
for (int ia = 0; ia < ucell.atoms[it].na; ia++)
208210
{
209-
const int iat = GlobalC::ucell.itia2iat(it, ia);
211+
const int iat = ucell.itia2iat(it, ia);
210212

211213
for (int l = 0; l < NL; l++)
212214
{
213215
if (l != orbital_corr[it])
214216
continue;
215217

216-
const int N = GlobalC::ucell.atoms[it].l_nchi[l];
218+
const int N = ucell.atoms[it].l_nchi[l];
217219

218220
for (int n = 0; n < N; n++)
219221
{
@@ -260,24 +262,24 @@ void DFTU::cal_occup_m_k(const int iter,
260262
} // end it
261263
} // ik
262264

263-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
265+
for (int it = 0; it < ucell.ntype; it++)
264266
{
265-
const int NL = GlobalC::ucell.atoms[it].nwl + 1;
267+
const int NL = ucell.atoms[it].nwl + 1;
266268
const int LC = orbital_corr[it];
267269

268270
if (LC == -1)
269271
continue;
270272

271-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
273+
for (int ia = 0; ia < ucell.atoms[it].na; ia++)
272274
{
273-
const int iat = GlobalC::ucell.itia2iat(it, ia);
275+
const int iat = ucell.itia2iat(it, ia);
274276

275277
for (int l = 0; l < NL; l++)
276278
{
277279
if (l != orbital_corr[it])
278280
continue;
279281

280-
const int N = GlobalC::ucell.atoms[it].l_nchi[l];
282+
const int N = ucell.atoms[it].l_nchi[l];
281283

282284
for (int n = 0; n < N; n++)
283285
{
@@ -346,20 +348,24 @@ void DFTU::cal_occup_m_k(const int iter,
346348

347349
if(mixing_dftu && initialed_locale)
348350
{
349-
this->mix_locale(mixing_beta);
351+
this->mix_locale(ucell,mixing_beta);
350352
}
351353

352354
this->initialed_locale = true;
353355
ModuleBase::timer::tick("DFTU", "cal_occup_m_k");
354356
return;
355357
}
356358

357-
void DFTU::cal_occup_m_gamma(const int iter, const std::vector<std::vector<double>> &dm_gamma, const double& mixing_beta, hamilt::Hamilt<double>* p_ham)
359+
void DFTU::cal_occup_m_gamma(const int iter,
360+
const UnitCell &ucell,
361+
const std::vector<std::vector<double>> &dm_gamma,
362+
const double& mixing_beta,
363+
hamilt::Hamilt<double>* p_ham)
358364
{
359365
ModuleBase::TITLE("DFTU", "cal_occup_m_gamma");
360366
ModuleBase::timer::tick("DFTU", "cal_occup_m_gamma");
361-
this->copy_locale();
362-
this->zero_locale();
367+
this->copy_locale(ucell);
368+
this->zero_locale(ucell);
363369

364370
//=================Part 1======================
365371
// call PBLAS routine to calculate the product of the S and density matrix
@@ -396,21 +402,21 @@ void DFTU::cal_occup_m_gamma(const int iter, const std::vector<std::vector<doubl
396402
this->paraV->desc);
397403
#endif
398404

399-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
405+
for (int it = 0; it < ucell.ntype; it++)
400406
{
401-
const int NL = GlobalC::ucell.atoms[it].nwl + 1;
407+
const int NL = ucell.atoms[it].nwl + 1;
402408
if (orbital_corr[it] == -1)
403409
continue;
404-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
410+
for (int ia = 0; ia < ucell.atoms[it].na; ia++)
405411
{
406-
const int iat = GlobalC::ucell.itia2iat(it, ia);
412+
const int iat = ucell.itia2iat(it, ia);
407413

408414
for (int l = 0; l < NL; l++)
409415
{
410416
if (l != orbital_corr[it])
411417
continue;
412418

413-
const int N = GlobalC::ucell.atoms[it].l_nchi[l];
419+
const int N = ucell.atoms[it].l_nchi[l];
414420

415421
for (int n = 0; n < N; n++)
416422
{
@@ -494,7 +500,7 @@ void DFTU::cal_occup_m_gamma(const int iter, const std::vector<std::vector<doubl
494500

495501
if(mixing_dftu && initialed_locale)
496502
{
497-
this->mix_locale(mixing_beta);
503+
this->mix_locale(ucell,mixing_beta);
498504
}
499505

500506
this->initialed_locale = true;

0 commit comments

Comments
 (0)