Skip to content

Commit c611100

Browse files
authored
Refactor:Remove GlobalC::ucell (#5737)
* change ucell in force_stress.cpp * change ucell in force.cpp * change ucell in stress_func_cc.cpp * change ucell in rdmft_pot.cpp * change ucell in state_rmdft.cpp * change dftu_tools of ucell * remove GlobalC::ucell
1 parent f0ff82b commit c611100

File tree

23 files changed

+129
-110
lines changed

23 files changed

+129
-110
lines changed

source/driver.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ void Driver::init()
4343
// (4) close all of the running logs
4444
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog,PARAM.inp.calculation);
4545

46-
// (5) output the json file
47-
// Json::create_Json(&GlobalC::ucell.symm,GlobalC::ucell.atoms,&INPUT);
48-
Json::create_Json(&GlobalC::ucell, PARAM);
4946
}
5047

5148
void Driver::print_start_info()
@@ -180,7 +177,7 @@ void Driver::atomic_world()
180177
//--------------------------------------------------
181178

182179
// where the actual stuff is done
183-
this->driver_run(GlobalC::ucell);
180+
this->driver_run();
184181

185182
ModuleBase::timer::finish(GlobalV::ofs_running);
186183
ModuleBase::Memory::print_all(GlobalV::ofs_running);

source/driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Driver
3636
void atomic_world();
3737

3838
// the actual calculations
39-
void driver_run(UnitCell& ucell);
39+
void driver_run();
4040
};
4141

4242
#endif

source/driver_run.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
* the configuration-changing subroutine takes force and stress and updates the
2525
* configuration
2626
*/
27-
void Driver::driver_run(UnitCell& ucell)
27+
void Driver::driver_run()
2828
{
2929
ModuleBase::TITLE("Driver", "driver_line");
3030
ModuleBase::timer::tick("Driver", "driver_line");
3131

3232
//! 1: setup cell and atom information
33-
3433
// this warning should not be here, mohan 2024-05-22
3534
#ifndef __LCAO
3635
if (PARAM.inp.basis_type == "lcao_in_pw" || PARAM.inp.basis_type == "lcao") {
@@ -40,6 +39,13 @@ void Driver::driver_run(UnitCell& ucell)
4039
#endif
4140

4241
// the life of ucell should begin here, mohan 2024-05-12
42+
UnitCell ucell;
43+
ucell.setup(PARAM.inp.latname,
44+
PARAM.inp.ntype,
45+
PARAM.inp.lmaxmax,
46+
PARAM.inp.init_vel,
47+
PARAM.inp.fixed_axes);
48+
4349
ucell.setup_cell(PARAM.globalv.global_in_stru, GlobalV::ofs_running);
4450
Check_Atomic_Stru::check_atomic_stru(ucell, PARAM.inp.min_dist_coef);
4551

@@ -86,6 +92,8 @@ void Driver::driver_run(UnitCell& ucell)
8692

8793
ModuleESolver::clean_esolver(p_esolver);
8894

95+
//! 6: output the json file
96+
Json::create_Json(&ucell, PARAM);
8997
ModuleBase::timer::tick("Driver", "driver_line");
9098
return;
9199
}

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
302302

303303
Force_Stress_LCAO<TK> fsl(this->RA, ucell.nat);
304304

305-
fsl.getForceStress(PARAM.inp.cal_force,
305+
fsl.getForceStress(ucell,
306+
PARAM.inp.cal_force,
306307
PARAM.inp.cal_stress,
307308
PARAM.inp.test_force,
308309
PARAM.inp.test_stress,
309-
ucell,
310310
this->gd,
311311
this->pv,
312312
this->pelec,

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Force_Stress_LCAO<T>::~Force_Stress_LCAO()
3131
{
3232
}
3333
template <typename T>
34-
void Force_Stress_LCAO<T>::getForceStress(const bool isforce,
34+
void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
35+
const bool isforce,
3536
const bool isstress,
3637
const bool istestf,
3738
const bool istests,
38-
const UnitCell& ucell,
3939
const Grid_Driver& gd,
4040
Parallel_Orbitals& pv,
4141
const elecstate::ElecState* pelec,
@@ -830,7 +830,7 @@ void Force_Stress_LCAO<T>::getForceStress(const bool isforce,
830830

831831
// local pseudopotential, ewald, core correction, scc terms in force
832832
template <typename T>
833-
void Force_Stress_LCAO<T>::calForcePwPart(const UnitCell& ucell,
833+
void Force_Stress_LCAO<T>::calForcePwPart(UnitCell& ucell,
834834
ModuleBase::matrix& fvl_dvl,
835835
ModuleBase::matrix& fewalds,
836836
ModuleBase::matrix& fcc,
@@ -857,7 +857,7 @@ void Force_Stress_LCAO<T>::calForcePwPart(const UnitCell& ucell,
857857
//--------------------------------------------------------
858858
// force due to core correlation.
859859
//--------------------------------------------------------
860-
f_pw.cal_force_cc(fcc, rhopw, chr, nlpp.numeric, GlobalC::ucell);
860+
f_pw.cal_force_cc(fcc, rhopw, chr, nlpp.numeric, ucell);
861861
//--------------------------------------------------------
862862
// force due to self-consistent charge.
863863
//--------------------------------------------------------
@@ -975,7 +975,7 @@ void Force_Stress_LCAO<std::complex<double>>::integral_part(const bool isGammaOn
975975

976976
// vlocal, hartree, ewald, core correction, exchange-correlation terms in stress
977977
template <typename T>
978-
void Force_Stress_LCAO<T>::calStressPwPart(const UnitCell& ucell,
978+
void Force_Stress_LCAO<T>::calStressPwPart(UnitCell& ucell,
979979
ModuleBase::matrix& sigmadvl,
980980
ModuleBase::matrix& sigmahar,
981981
ModuleBase::matrix& sigmaewa,
@@ -1007,7 +1007,7 @@ void Force_Stress_LCAO<T>::calStressPwPart(const UnitCell& ucell,
10071007
//--------------------------------------------------------
10081008
// stress due to core correlation.
10091009
//--------------------------------------------------------
1010-
sc_pw.stress_cc(sigmacc, rhopw, &sf, 0, nlpp.numeric, chr);
1010+
sc_pw.stress_cc(sigmacc, rhopw, ucell, &sf, 0, nlpp.numeric, chr);
10111011

10121012
//--------------------------------------------------------
10131013
// stress due to self-consistent charge.

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class Force_Stress_LCAO
2929
Force_Stress_LCAO(Record_adj& ra, const int nat_in);
3030
~Force_Stress_LCAO();
3131

32-
void getForceStress(const bool isforce,
32+
void getForceStress(UnitCell& ucell,
33+
const bool isforce,
3334
const bool isstress,
3435
const bool istestf,
3536
const bool istests,
36-
const UnitCell& ucell,
3737
const Grid_Driver& gd,
3838
Parallel_Orbitals& pv,
3939
const elecstate::ElecState* pelec,
@@ -66,7 +66,7 @@ class Force_Stress_LCAO
6666
ModuleBase::matrix& fcs,
6767
ModuleSymmetry::Symmetry* symm);
6868

69-
void calForcePwPart(const UnitCell& ucell,
69+
void calForcePwPart(UnitCell& ucell,
7070
ModuleBase::matrix& fvl_dvl,
7171
ModuleBase::matrix& fewalds,
7272
ModuleBase::matrix& fcc,
@@ -105,7 +105,7 @@ class Force_Stress_LCAO
105105
const Parallel_Orbitals& pv,
106106
const K_Vectors& kv);
107107

108-
void calStressPwPart(const UnitCell& ucell,
108+
void calStressPwPart(UnitCell& ucell,
109109
ModuleBase::matrix& sigmadvl,
110110
ModuleBase::matrix& sigmahar,
111111
ModuleBase::matrix& sigmaewa,

source/module_hamilt_lcao/module_dftu/dftu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void DFTU::init(UnitCell& cell, // unitcell class
5959
{
6060
orb_cutoff_ = orb->cutoffs();
6161
}
62+
ucell = &cell;
6263
#endif
6364

6465
// needs reconstructions in future

source/module_hamilt_lcao/module_dftu/dftu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class DFTU
300300
void set_dmr(const elecstate::DensityMatrix<std::complex<double>, double>* dm_in_dftu_cd);
301301

302302
private:
303+
const UnitCell* ucell = nullptr;
303304
const elecstate::DensityMatrix<double, double>* dm_in_dftu_d = nullptr;
304305
const elecstate::DensityMatrix<std::complex<double>, double>* dm_in_dftu_cd = nullptr;
305306
#endif

source/module_hamilt_lcao/module_dftu/dftu_tools.cpp

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,51 @@ void DFTU::cal_VU_pot_mat_complex(const int spin, const bool newlocale, std::com
1212
ModuleBase::TITLE("DFTU", "cal_VU_pot_mat_complex");
1313
ModuleBase::GlobalFunc::ZEROS(VU, this->paraV->nloc);
1414

15-
for (int it = 0; it < GlobalC::ucell.ntype; ++it)
15+
for (int it = 0; it < this->ucell->ntype; ++it)
1616
{
17-
if (PARAM.inp.orbital_corr[it] == -1) {
17+
if (PARAM.inp.orbital_corr[it] == -1)
18+
{
1819
continue;
19-
}
20-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
20+
}
21+
for (int ia = 0; ia < this->ucell->atoms[it].na; ia++)
2122
{
22-
const int iat = GlobalC::ucell.itia2iat(it, ia);
23-
for (int L = 0; L <= GlobalC::ucell.atoms[it].nwl; L++)
23+
const int iat = this->ucell->itia2iat(it, ia);
24+
for (int L = 0; L <= this->ucell->atoms[it].nwl; L++)
2425
{
25-
if (L != PARAM.inp.orbital_corr[it]) {
26+
if (L != PARAM.inp.orbital_corr[it])
27+
{
2628
continue;
27-
}
29+
}
2830

29-
for (int n = 0; n < GlobalC::ucell.atoms[it].l_nchi[L]; n++)
31+
for (int n = 0; n < this->ucell->atoms[it].l_nchi[L]; n++)
3032
{
31-
if (n != 0) {
33+
if (n != 0)
34+
{
3235
continue;
33-
}
36+
}
3437

3538
for (int m1 = 0; m1 < 2 * L + 1; m1++)
3639
{
3740
for (int ipol1 = 0; ipol1 < PARAM.globalv.npol; ipol1++)
3841
{
3942
const int mu = this->paraV->global2local_row(this->iatlnmipol2iwt[iat][L][n][m1][ipol1]);
40-
if (mu < 0) {
43+
if (mu < 0)
44+
{
4145
continue;
42-
}
46+
}
4347

4448
for (int m2 = 0; m2 < 2 * L + 1; m2++)
4549
{
4650
for (int ipol2 = 0; ipol2 < PARAM.globalv.npol; ipol2++)
4751
{
4852
const int nu
4953
= this->paraV->global2local_col(this->iatlnmipol2iwt[iat][L][n][m2][ipol2]);
50-
if (nu < 0) {
54+
if (nu < 0)
55+
{
5156
continue;
52-
}
53-
57+
}
5458
int m1_all = m1 + (2 * L + 1) * ipol1;
5559
int m2_all = m2 + (2 * L + 1) * ipol2;
56-
5760
double val = get_onebody_eff_pot(it, iat, L, n, spin, m1_all, m2_all, newlocale);
5861
VU[nu * this->paraV->nrow + mu] = std::complex<double>(val, 0.0);
5962
} // ipol2
@@ -73,43 +76,47 @@ void DFTU::cal_VU_pot_mat_real(const int spin, const bool newlocale, double* VU)
7376
ModuleBase::TITLE("DFTU", "cal_VU_pot_mat_real");
7477
ModuleBase::GlobalFunc::ZEROS(VU, this->paraV->nloc);
7578

76-
for (int it = 0; it < GlobalC::ucell.ntype; ++it)
79+
for (int it = 0; it < this->ucell->ntype; ++it)
7780
{
78-
if (PARAM.inp.orbital_corr[it] == -1) {
81+
if (PARAM.inp.orbital_corr[it] == -1)
82+
{
7983
continue;
80-
}
81-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
84+
}
85+
for (int ia = 0; ia < this->ucell->atoms[it].na; ia++)
8286
{
83-
const int iat = GlobalC::ucell.itia2iat(it, ia);
84-
for (int L = 0; L <= GlobalC::ucell.atoms[it].nwl; L++)
87+
const int iat = this->ucell->itia2iat(it, ia);
88+
for (int L = 0; L <= this->ucell->atoms[it].nwl; L++)
8589
{
86-
if (L != PARAM.inp.orbital_corr[it]) {
90+
if (L != PARAM.inp.orbital_corr[it])
91+
{
8792
continue;
88-
}
93+
}
8994

90-
for (int n = 0; n < GlobalC::ucell.atoms[it].l_nchi[L]; n++)
95+
for (int n = 0; n < this->ucell->atoms[it].l_nchi[L]; n++)
9196
{
92-
if (n != 0) {
97+
if (n != 0)
98+
{
9399
continue;
94-
}
95-
100+
}
96101
for (int m1 = 0; m1 < 2 * L + 1; m1++)
97102
{
98103
for (int ipol1 = 0; ipol1 < PARAM.globalv.npol; ipol1++)
99104
{
100105
const int mu = this->paraV->global2local_row(this->iatlnmipol2iwt[iat][L][n][m1][ipol1]);
101-
if (mu < 0) {
106+
if (mu < 0)
107+
{
102108
continue;
103-
}
109+
}
104110
for (int m2 = 0; m2 < 2 * L + 1; m2++)
105111
{
106112
for (int ipol2 = 0; ipol2 < PARAM.globalv.npol; ipol2++)
107113
{
108114
const int nu
109115
= this->paraV->global2local_col(this->iatlnmipol2iwt[iat][L][n][m2][ipol2]);
110-
if (nu < 0) {
116+
if (nu < 0)
117+
{
111118
continue;
112-
}
119+
}
113120

114121
int m1_all = m1 + (2 * L + 1) * ipol1;
115122
int m2_all = m2 + (2 * L + 1) * ipol2;
@@ -157,20 +164,21 @@ double DFTU::get_onebody_eff_pot(const int T,
157164
{
158165
if (Yukawa)
159166
{
160-
if (m0 == m1) {
167+
if (m0 == m1)
168+
{
161169
VU = (this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N])
162170
* (0.5 - this->locale[iat][L][N][spin](m0, m1));
163171
} else {
164172
VU = -(this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) * this->locale[iat][L][N][spin](m0, m1);
165-
}
173+
}
166174
}
167175
else
168176
{
169177
if (m0 == m1) {
170178
VU = (this->U[T]) * (0.5 - this->locale[iat][L][N][spin](m0, m1));
171179
} else {
172180
VU = -(this->U[T]) * this->locale[iat][L][N][spin](m0, m1);
173-
}
181+
}
174182
}
175183
}
176184
else
@@ -183,15 +191,15 @@ double DFTU::get_onebody_eff_pot(const int T,
183191
} else {
184192
VU = -(this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N])
185193
* this->locale_save[iat][L][N][spin](m0, m1);
186-
}
194+
}
187195
}
188196
else
189197
{
190198
if (m0 == m1) {
191199
VU = (this->U[T]) * (0.5 - this->locale_save[iat][L][N][spin](m0, m1));
192200
} else {
193201
VU = -(this->U[T]) * this->locale_save[iat][L][N][spin](m0, m1);
194-
}
202+
}
195203
}
196204
}
197205

source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void OF_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot,
7979
stress_loc(ucell,sigmaloc, this->rhopw, locpp.vloc, p_sf, true, pelec->charge);
8080

8181
// nlcc
82-
stress_cc(sigmaxcc, this->rhopw, p_sf, true, locpp.numeric, pelec->charge);
82+
stress_cc(sigmaxcc, this->rhopw, ucell, p_sf, true, locpp.numeric, pelec->charge);
8383

8484
// vdw term
8585
stress_vdw(sigmavdw, ucell);

0 commit comments

Comments
 (0)