Skip to content

Commit 674d89e

Browse files
committed
change ucell in dftu_io
1 parent 9f5fa63 commit 674d89e

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
885885
}
886886
GlobalC::dftu.cal_energy_correction(ucell,istep);
887887
}
888-
GlobalC::dftu.output();
888+
GlobalC::dftu.output(ucell);
889889
}
890890

891891
// (7) for deepks, calculate delta_e

source/module_hamilt_lcao/module_dftu/dftu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ void DFTU::init(UnitCell& cell, // unitcell class
179179
{
180180
std::stringstream sst;
181181
sst << "initial_onsite.dm";
182-
this->read_occup_m(sst.str());
182+
this->read_occup_m(cell,sst.str());
183183
#ifdef __MPI
184-
this->local_occup_bcast();
184+
this->local_occup_bcast(cell);
185185
#endif
186186

187187
initialed_locale = true;
@@ -193,9 +193,9 @@ void DFTU::init(UnitCell& cell, // unitcell class
193193
{
194194
std::stringstream sst;
195195
sst << PARAM.globalv.global_out_dir << "onsite.dm";
196-
this->read_occup_m(sst.str());
196+
this->read_occup_m(cell,sst.str());
197197
#ifdef __MPI
198-
this->local_occup_bcast();
198+
this->local_occup_bcast(cell);
199199
#endif
200200
initialed_locale = true;
201201
}

source/module_hamilt_lcao/module_dftu/dftu.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ class DFTU
230230
// For reading/writing/broadcasting/copying relevant data structures
231231
//=============================================================
232232
public:
233-
void output();
233+
void output(const UnitCell& ucell);
234234

235235
private:
236-
void write_occup_m(std::ofstream& ofs, bool diag=false);
237-
void read_occup_m(const std::string& fn);
238-
void local_occup_bcast();
236+
void write_occup_m(const UnitCell& ucell,
237+
std::ofstream& ofs,
238+
bool diag=false);
239+
void read_occup_m(const UnitCell& ucell,
240+
const std::string& fn);
241+
void local_occup_bcast(const UnitCell& ucell);
239242

240243
//=============================================================
241244
// In dftu_yukawa.cpp

source/module_hamilt_lcao/module_dftu/dftu_io.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
namespace ModuleDFTU
77
{
88

9-
void DFTU::output()
9+
void DFTU::output(const UnitCell &ucell)
1010
{
1111
ModuleBase::TITLE("DFTU", "output");
1212

1313
GlobalV::ofs_running << "//=========================L(S)DA+U===========================//" << std::endl;
1414

15-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
15+
for (int T = 0; T < ucell.ntype; T++)
1616
{
17-
const int NL = GlobalC::ucell.atoms[T].nwl + 1;
17+
const int NL = ucell.atoms[T].nwl + 1;
1818

1919
for (int L = 0; L < NL; L++)
2020
{
21-
const int N = GlobalC::ucell.atoms[T].l_nchi[L];
21+
const int N = ucell.atoms[T].l_nchi[L];
2222

2323
if (L >= orbital_corr[T] && orbital_corr[T] != -1)
2424
{
@@ -50,7 +50,7 @@ void DFTU::output()
5050
}
5151

5252
GlobalV::ofs_running << "Local occupation matrices" << std::endl;
53-
this->write_occup_m(GlobalV::ofs_running, true);
53+
this->write_occup_m(ucell,GlobalV::ofs_running, true);
5454
GlobalV::ofs_running << "//=======================================================//" << std::endl;
5555

5656
//Write onsite.dm
@@ -64,7 +64,7 @@ void DFTU::output()
6464
std::cout << "DFTU::write_occup_m. Can't create file onsite.dm!" << std::endl;
6565
exit(0);
6666
}
67-
this->write_occup_m(ofdftu);
67+
this->write_occup_m(ucell,ofdftu);
6868
ofdftu.close();
6969

7070
return;
@@ -73,24 +73,26 @@ void DFTU::output()
7373
// define the function calculate the eigenvalues of a matrix
7474
std::vector<double> CalculateEigenvalues(std::vector<std::vector<double>>& A, int n);
7575

76-
void DFTU::write_occup_m(std::ofstream &ofs, bool diag)
76+
void DFTU::write_occup_m(const UnitCell& ucell,
77+
std::ofstream &ofs,
78+
bool diag)
7779
{
7880
ModuleBase::TITLE("DFTU", "write_occup_m");
7981

8082
if(GlobalV::MY_RANK != 0) { return;
8183
}
8284

83-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
85+
for (int T = 0; T < ucell.ntype; T++)
8486
{
8587
if (orbital_corr[T] == -1) {
8688
continue;
8789
}
88-
const int NL = GlobalC::ucell.atoms[T].nwl + 1;
90+
const int NL = ucell.atoms[T].nwl + 1;
8991
const int LC = orbital_corr[T];
9092

91-
for (int I = 0; I < GlobalC::ucell.atoms[T].na; I++)
93+
for (int I = 0; I < ucell.atoms[T].na; I++)
9294
{
93-
const int iat = GlobalC::ucell.itia2iat(T, I);
95+
const int iat = ucell.itia2iat(T, I);
9496
ofs << "atoms"
9597
<< " " << iat << std::endl;
9698

@@ -100,7 +102,7 @@ void DFTU::write_occup_m(std::ofstream &ofs, bool diag)
100102
continue;
101103
}
102104

103-
const int N = GlobalC::ucell.atoms[T].l_nchi[l];
105+
const int N = ucell.atoms[T].l_nchi[l];
104106
ofs << "L"
105107
<< " " << l << std::endl;
106108

@@ -220,7 +222,8 @@ void DFTU::write_occup_m(std::ofstream &ofs, bool diag)
220222
return;
221223
}
222224

223-
void DFTU::read_occup_m(const std::string &fn)
225+
void DFTU::read_occup_m(const UnitCell& ucell,
226+
const std::string &fn)
224227
{
225228
ModuleBase::TITLE("DFTU", "read_occup_m");
226229

@@ -270,8 +273,8 @@ void DFTU::read_occup_m(const std::string &fn)
270273
ifdftu >> iat;
271274
ifdftu.ignore(150, '\n');
272275

273-
T = GlobalC::ucell.iat2it[iat];
274-
const int NL = GlobalC::ucell.atoms[T].nwl + 1;
276+
T = ucell.iat2it[iat];
277+
const int NL = ucell.atoms[T].nwl + 1;
275278
const int LC = orbital_corr[T];
276279

277280
for (int l = 0; l < NL; l++)
@@ -287,7 +290,7 @@ void DFTU::read_occup_m(const std::string &fn)
287290
ifdftu >> L;
288291
ifdftu.ignore(150, '\n');
289292

290-
const int N = GlobalC::ucell.atoms[T].l_nchi[L];
293+
const int N = ucell.atoms[T].l_nchi[L];
291294
for (int n = 0; n < N; n++)
292295
{
293296
// if(!Yukawa && n!=0) continue;
@@ -384,28 +387,28 @@ void DFTU::read_occup_m(const std::string &fn)
384387
return;
385388
}
386389

387-
void DFTU::local_occup_bcast()
390+
void DFTU::local_occup_bcast(const UnitCell& ucell)
388391
{
389392
ModuleBase::TITLE("DFTU", "local_occup_bcast");
390393

391-
for (int T = 0; T < GlobalC::ucell.ntype; T++)
394+
for (int T = 0; T < ucell.ntype; T++)
392395
{
393396
if (orbital_corr[T] == -1) {
394397
continue;
395398
}
396399

397-
for (int I = 0; I < GlobalC::ucell.atoms[T].na; I++)
400+
for (int I = 0; I < ucell.atoms[T].na; I++)
398401
{
399-
const int iat = GlobalC::ucell.itia2iat(T, I);
402+
const int iat = ucell.itia2iat(T, I);
400403
const int L = orbital_corr[T];
401404

402-
for (int l = 0; l <= GlobalC::ucell.atoms[T].nwl; l++)
405+
for (int l = 0; l <= ucell.atoms[T].nwl; l++)
403406
{
404407
if (l != orbital_corr[T]) {
405408
continue;
406409
}
407410

408-
for (int n = 0; n < GlobalC::ucell.atoms[T].l_nchi[l]; n++)
411+
for (int n = 0; n < ucell.atoms[T].l_nchi[l]; n++)
409412
{
410413
// if(!Yukawa && n!=0) continue;
411414
if (n != 0) {

0 commit comments

Comments
 (0)