Skip to content

Commit 9f0f689

Browse files
committed
will delete pelec->charge in near future, we just directly use chr defined in esolver_fp
1 parent b10c6b8 commit 9f0f689

12 files changed

+81
-81
lines changed

source/module_esolver/esolver_fp.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
155155
double* data = nullptr;
156156
if (PARAM.inp.dm_to_rho)
157157
{
158-
data = this->chr->rho[is];
159-
this->pw_rhod->real2recip(this->chr->rho[is], this->chr->rhog[is]);
158+
data = this->chr.rho[is];
159+
this->pw_rhod->real2recip(this->chr.rho[is], this->chr.rhog[is]);
160160
}
161161
else
162162
{
163-
data = this->chr->rho_save[is];
164-
this->pw_rhod->real2recip(this->chr->rho_save[is], this->chr->rhog_save[is]);
163+
data = this->chr.rho_save[is];
164+
this->pw_rhod->real2recip(this->chr.rho_save[is], this->chr.rhog_save[is]);
165165
}
166166
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
167167
ModuleIO::write_vdata_palgrid(Pgrid,
@@ -178,7 +178,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
178178
{
179179
fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube";
180180
ModuleIO::write_vdata_palgrid(Pgrid,
181-
this->chr->kin_r_save[is],
181+
this->chr.kin_r_save[is],
182182
is,
183183
PARAM.inp.nspin,
184184
istep,
@@ -219,7 +219,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
219219
fn,
220220
istep,
221221
this->pw_rhod,
222-
this->chr,
222+
&this->chr,
223223
&(ucell),
224224
this->pelec->pot->get_fixed_v(),
225225
this->solvent);
@@ -228,11 +228,11 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
228228
// 6) write ELF
229229
if (PARAM.inp.out_elf[0] > 0)
230230
{
231-
this->chr->cal_elf = true;
231+
this->chr.cal_elf = true;
232232
Symmetry_rho srho;
233233
for (int is = 0; is < PARAM.inp.nspin; is++)
234234
{
235-
srho.begin(is, *(this->chr), this->pw_rhod, ucell.symm);
235+
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
236236
}
237237

238238
std::string out_dir =PARAM.globalv.global_out_dir;
@@ -244,8 +244,8 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
244244
out_dir,
245245
istep,
246246
PARAM.inp.nspin,
247-
this->chr->rho,
248-
this->chr->kin_r,
247+
this->chr.rho,
248+
this->chr.kin_r,
249249
this->pw_rhod,
250250
this->Pgrid,
251251
&(ucell),
@@ -294,7 +294,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
294294
this->CE.update_all_dis(ucell);
295295
this->CE.extrapolate_charge(&(this->Pgrid),
296296
ucell,
297-
this->chr,
297+
&this->chr,
298298
&(this->sf),
299299
GlobalV::ofs_running,
300300
GlobalV::ofs_warning);
@@ -329,7 +329,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
329329
std::stringstream ss;
330330
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube";
331331
ModuleIO::write_vdata_palgrid(this->Pgrid,
332-
this->chr->rho[is],
332+
this->chr.rho[is],
333333
is,
334334
PARAM.inp.nspin,
335335
istep,
@@ -370,8 +370,8 @@ void ESolver_FP::iter_finish(UnitCell& ucell, const int istep, int& iter, bool&
370370
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || conv_esolver)
371371
{
372372
std::complex<double>** rhog_tot
373-
= (PARAM.inp.dm_to_rho) ? this->chr->rhog : this->chr->rhog_save;
374-
double** rhor_tot = (PARAM.inp.dm_to_rho) ? this->chr->rho : this->chr->rho_save;
373+
= (PARAM.inp.dm_to_rho) ? this->chr.rhog : this->chr.rhog_save;
374+
double** rhor_tot = (PARAM.inp.dm_to_rho) ? this->chr.rho : this->chr.rho_save;
375375
for (int is = 0; is < PARAM.inp.nspin; is++)
376376
{
377377
this->pw_rhod->real2recip(rhor_tot[is], rhog_tot[is]);
@@ -388,12 +388,12 @@ void ESolver_FP::iter_finish(UnitCell& ucell, const int istep, int& iter, bool&
388388

389389
if (XC_Functional::get_ked_flag())
390390
{
391-
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->chr->ngmc, {0.0, 0.0});
391+
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->chr.ngmc, {0.0, 0.0});
392392
std::vector<std::complex<double>*> kin_g;
393393
for (int is = 0; is < PARAM.inp.nspin; is++)
394394
{
395-
kin_g.push_back(kin_g_space.data() + is * this->chr->ngmc);
396-
this->pw_rhod->real2recip(this->chr->kin_r_save[is], kin_g[is]);
395+
kin_g.push_back(kin_g_space.data() + is * this->chr.ngmc);
396+
this->pw_rhod->real2recip(this->chr.kin_r_save[is], kin_g[is]);
397397
}
398398
ModuleIO::write_rhog(PARAM.globalv.global_out_dir + PARAM.inp.suffix + "-TAU-DENSITY.restart",
399399
PARAM.globalv.gamma_only_pw || PARAM.globalv.gamma_only_local,

source/module_esolver/esolver_ks.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void ESolver_KS<T, Device>::hamilt2density(UnitCell& ucell, const int istep, con
368368
// double drho = this->estate.caldr2();
369369
// EState should be used after it is constructed.
370370

371-
drho = p_chgmix->get_drho(pelec->charge, PARAM.inp.nelec);
371+
drho = p_chgmix->get_drho(&this->chr, PARAM.inp.nelec);
372372
hsolver_error = 0.0;
373373
if (iter == 1 && PARAM.inp.calculation != "nscf")
374374
{
@@ -390,7 +390,7 @@ void ESolver_KS<T, Device>::hamilt2density(UnitCell& ucell, const int istep, con
390390

391391
this->hamilt2density_single(ucell, istep, iter, diag_ethr);
392392

393-
drho = p_chgmix->get_drho(pelec->charge, PARAM.inp.nelec);
393+
drho = p_chgmix->get_drho(&this->chr, PARAM.inp.nelec);
394394

395395
hsolver_error = hsolver::cal_hsolve_error(PARAM.inp.basis_type,
396396
PARAM.inp.esolver_type,
@@ -522,7 +522,7 @@ void ESolver_KS<T, Device>::iter_init(UnitCell& ucell, const int istep, const in
522522
}
523523

524524
// 1) save input rho
525-
this->pelec->charge->save_rho_before_sum_band();
525+
this->chr.save_rho_before_sum_band();
526526
}
527527

528528
template <typename T, typename Device>
@@ -552,9 +552,9 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
552552

553553
// compute magnetization, only for LSDA(spin==2)
554554
ucell.magnet.compute_magnetization(ucell.omega,
555-
this->pelec->charge->nrxx,
556-
this->pelec->charge->nxyz,
557-
this->pelec->charge->rho,
555+
this->chr.nrxx,
556+
this->chr.nxyz,
557+
this->chr.rho,
558558
this->pelec->nelec_spin.data());
559559

560560
if (PARAM.globalv.ks_run)
@@ -629,11 +629,11 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
629629
}
630630
else
631631
{
632-
p_chgmix->mix_rho(pelec->charge); // update chr->rho by mixing
632+
p_chgmix->mix_rho(&this->chr); // update chr->rho by mixing
633633
}
634634
if (PARAM.inp.scf_thr_type == 2)
635635
{
636-
pelec->charge->renormalize_rho(); // renormalize rho in R-space would
636+
this->chr.renormalize_rho(); // renormalize rho in R-space would
637637
// induce a error in K-space
638638
}
639639
//----------charge mixing done-----------
@@ -645,7 +645,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
645645

646646
// be careful! conv_esolver is bool, not double !! Maybe a bug 20250302 by mohan
647647
MPI_Bcast(&conv_esolver, 1, MPI_DOUBLE, 0, BP_WORLD);
648-
MPI_Bcast(pelec->charge->rho[0], this->pw_rhod->nrxx, MPI_DOUBLE, 0, BP_WORLD);
648+
MPI_Bcast(this->chr.rho[0], this->pw_rhod->nrxx, MPI_DOUBLE, 0, BP_WORLD);
649649
#endif
650650

651651
// update potential
@@ -677,7 +677,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
677677
double dkin = 0.0; // for meta-GGA
678678
if (XC_Functional::get_ked_flag())
679679
{
680-
dkin = p_chgmix->get_dkin(pelec->charge, PARAM.inp.nelec);
680+
dkin = p_chgmix->get_dkin(&this->chr, PARAM.inp.nelec);
681681
}
682682

683683

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
193193
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
194194

195195
// 8) inititlize the charge density
196-
this->pelec->charge->allocate(PARAM.inp.nspin);
196+
this->chr.allocate(PARAM.inp.nspin);
197197
this->pelec->omega = ucell.omega;
198198

199199
// 9) initialize the potential
@@ -469,7 +469,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
469469
*this->pw_rho,
470470
*this->pw_rhod,
471471
this->locpp.vloc,
472-
*this->pelec->charge,
472+
this->chr,
473473
this->GG,
474474
this->GK,
475475
this->kv,
@@ -497,7 +497,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
497497
*this->pw_rho,
498498
*this->pw_rhod,
499499
this->locpp.vloc,
500-
*this->pelec->charge,
500+
this->chr,
501501
this->GG,
502502
this->GK,
503503
this->kv,
@@ -628,7 +628,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
628628
elecstate::cal_ux(ucell);
629629

630630
//! update the potentials by using new electron charge density
631-
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
631+
this->pelec->pot->update_from_charge(&this->chr, &ucell);
632632

633633
//! compute the correction energy for metals
634634
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
@@ -665,7 +665,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
665665
GlobalC::dftu.set_dmr(dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM());
666666
}
667667
// Calculate U and J if Yukawa potential is used
668-
GlobalC::dftu.cal_slater_UJ(ucell, this->pelec->charge->rho, this->pw_rho->nrxx);
668+
GlobalC::dftu.cal_slater_UJ(ucell, this->chr.rho, this->pw_rho->nrxx);
669669
}
670670

671671
#ifdef __DEEPKS
@@ -763,7 +763,7 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep,
763763
Symmetry_rho srho;
764764
for (int is = 0; is < PARAM.inp.nspin; is++)
765765
{
766-
srho.begin(is, *(this->pelec->charge), this->pw_rho, ucell.symm);
766+
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
767767
}
768768

769769
// 12) calculate delta energy
@@ -783,7 +783,7 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const
783783
if (!conv_esolver)
784784
{
785785
elecstate::cal_ux(ucell);
786-
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
786+
this->pelec->pot->update_from_charge(&this->chr, &ucell);
787787
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
788788
}
789789
else
@@ -866,7 +866,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
866866
{
867867
for (int is = 0; is < PARAM.inp.nspin; ++is)
868868
{
869-
GlobalC::restart.save_disk("charge", is, this->pelec->charge->nrxx, this->pelec->charge->rho[is]);
869+
GlobalC::restart.save_disk("charge", is, this->chr.nrxx, this->chr.rho[is]);
870870
}
871871
}
872872

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void ESolver_KS_LCAO_TDDFT<Device>::hamilt2density_single(UnitCell& ucell,
154154
Symmetry_rho srho;
155155
for (int is = 0; is < PARAM.inp.nspin; is++)
156156
{
157-
srho.begin(is, *(pelec->charge), pw_rho, ucell.symm);
157+
srho.begin(is, this->chr, pw_rho, ucell.symm);
158158
}
159159
}
160160

@@ -206,7 +206,7 @@ void ESolver_KS_LCAO_TDDFT<Device>::update_pot(UnitCell& ucell,
206206
if (!conv_esolver)
207207
{
208208
elecstate::cal_ux(ucell);
209-
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
209+
this->pelec->pot->update_from_charge(&this->chr, &ucell);
210210
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
211211
}
212212
else
@@ -365,8 +365,8 @@ void ESolver_KS_LCAO_TDDFT<Device>::after_scf(UnitCell& ucell, const int istep,
365365
std::stringstream ss_dipole;
366366
ss_dipole << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_DIPOLE";
367367
ModuleIO::write_dipole(ucell,
368-
pelec->charge->rho_save[is],
369-
pelec->charge->rhopw,
368+
this->chr.rho_save[is],
369+
this->chr.rhopw,
370370
is,
371371
istep,
372372
ss_dipole.str());

source/module_esolver/esolver_ks_lcaopw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace ModuleESolver
163163
Symmetry_rho srho;
164164
for (int is = 0; is < PARAM.inp.nspin; is++)
165165
{
166-
srho.begin(is, *(this->pelec->charge), this->pw_rhod, ucell.symm);
166+
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
167167
}
168168

169169
// deband is calculated from "output" charge density calculated
@@ -255,7 +255,7 @@ namespace ModuleESolver
255255
*this->pw_rho,
256256
*this->pw_rhod,
257257
this->locpp.vloc,
258-
*this->pelec->charge,
258+
this->chr,
259259
this->kv,
260260
this->pelec->wg
261261
#ifdef __EXX

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void ESolver_KS_PW<T, Device>::before_all_runners(UnitCell& ucell, const Input_p
164164
}
165165

166166
//! 4) inititlize the charge density.
167-
this->pelec->charge->allocate(PARAM.inp.nspin);
167+
this->chr.allocate(PARAM.inp.nspin);
168168

169169
//! 5) set the cell volume variable in pelec
170170
this->pelec->omega = ucell.omega;
@@ -266,7 +266,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
266266
Symmetry_rho srho;
267267
for (int is = 0; is < PARAM.inp.nspin; is++)
268268
{
269-
srho.begin(is, *(this->pelec->charge), this->pw_rhod, ucell.symm);
269+
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
270270
}
271271

272272
//----------------------------------------------------------
@@ -470,7 +470,7 @@ void ESolver_KS_PW<T, Device>::hamilt2density_single(UnitCell& ucell,
470470
Symmetry_rho srho;
471471
for (int is = 0; is < PARAM.inp.nspin; is++)
472472
{
473-
srho.begin(is, *(this->pelec->charge), this->pw_rhod, ucell.symm);
473+
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
474474
}
475475

476476
// deband is calculated from "output" charge density calculated
@@ -488,7 +488,7 @@ void ESolver_KS_PW<T, Device>::update_pot(UnitCell& ucell, const int istep, cons
488488
if (!conv_esolver)
489489
{
490490
elecstate::cal_ux(ucell);
491-
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
491+
this->pelec->pot->update_from_charge(&this->chr, &ucell);
492492
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
493493
#ifdef __MPI
494494
MPI_Bcast(&(this->pelec->f_en.descf), 1, MPI_DOUBLE, 0, BP_WORLD);
@@ -605,7 +605,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
605605
this->kv.wk,
606606
this->pw_big->bz,
607607
this->pw_big->nbz,
608-
this->pelec->charge->ngmc,
608+
this->chr.ngmc,
609609
&ucell,
610610
this->psi,
611611
this->pw_rhod,
@@ -876,10 +876,10 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
876876
// generate training data for ML-KEDF
877877
if (PARAM.inp.of_ml_gene_data == 1)
878878
{
879-
this->pelec->pot->update_from_charge(this->pelec->charge, &ucell);
879+
this->pelec->pot->update_from_charge(this->chr, &ucell);
880880

881881
ML_data ml_data;
882-
ml_data.set_para(this->pelec->charge->nrxx,
882+
ml_data.set_para(this->chr.nrxx,
883883
PARAM.inp.nelec,
884884
PARAM.inp.of_tf_weight,
885885
PARAM.inp.of_vw_weight,

0 commit comments

Comments
 (0)