Skip to content

Commit 10c4d9c

Browse files
committed
delete omega in pelec, remove some deepks codes to setup_deepks.cpp
1 parent 5130f4b commit 10c4d9c

File tree

11 files changed

+40
-27
lines changed

11 files changed

+40
-27
lines changed

source/source_esolver/esolver_double_xc.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(UnitCell& ucell, const Input_p
9090

9191
// 10) inititlize the charge density
9292
this->chr_base.allocate(PARAM.inp.nspin);
93-
this->pelec_base->omega = ucell.omega;
9493

9594
// 11) initialize the potential
9695
if (this->pelec_base->pot == nullptr)
@@ -116,7 +115,6 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
116115

117116
ESolver_KS_LCAO<TK,TR>::before_scf(ucell, istep);
118117

119-
this->pelec_base->omega = ucell.omega;
120118
//----------------------------------------------------------
121119
//! calculate D2 or D3 vdW
122120
//----------------------------------------------------------

source/source_esolver/esolver_fp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
108108
this->locpp.init_vloc(ucell, this->pw_rhod);
109109
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
110110

111-
this->pelec->omega = ucell.omega;
112-
113111
// perform symmetry analysis
114112
if (ModuleSymmetry::Symmetry::symm_flag == 1)
115113
{

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
110110

111111
// 11) init charge density
112112
this->chr.allocate(inp.nspin);
113-
this->pelec->omega = ucell.omega;
114113

115114
// 12) init potentials
116115
if (this->pelec->pot == nullptr)
@@ -565,15 +564,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
565564
}
566565

567566
// 2) for deepks, calculate delta_e, output labels during electronic steps
568-
#ifdef __MLALGO
569-
if (PARAM.inp.deepks_scf)
570-
{
571-
this->deepks.ld.dpks_cal_e_delta_band(dm_vec, this->kv.get_nks());
572-
DeePKS_domain::update_dmr(this->kv.kvec_d, dm_vec, ucell, orb_, this->pv, this->gd, this->deepks.ld.dm_r);
573-
estate->f_en.edeepks_scf = this->deepks.ld.E_delta - this->deepks.ld.e_delta_band;
574-
estate->f_en.edeepks_delta = this->deepks.ld.E_delta;
575-
}
576-
#endif
567+
this->deepks.delta_e(this->kv, this->pv, this->gd, dm_vec, PARAM.inp);
577568

578569
// 3) for delta spin
579570
if (PARAM.inp.sc_mag_switch)

source/source_esolver/esolver_of.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
273273
{
274274
// Here we initialize rho to be uniform,
275275
// because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements.
276-
this->chr.rho[is][ibs] = this->nelec_[is] / this->pelec->omega;
276+
this->chr.rho[is][ibs] = this->nelec_[is] / ucell.omega;
277277
this->pphi_[is][ibs] = sqrt(this->chr.rho[is][ibs]);
278278
}
279279
}
@@ -587,7 +587,7 @@ void ESolver_OF::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
587587
{
588588
ModuleBase::matrix kinetic_stress_;
589589
kinetic_stress_.create(3, 3);
590-
this->kedf_manager_->get_stress(this->pelec->omega,
590+
this->kedf_manager_->get_stress(ucell.omega,
591591
this->chr.rho,
592592
this->pphi_,
593593
this->pw_rho,

source/source_esolver/esolver_of_tool.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void ESolver_OF::init_elecstate(UnitCell& ucell)
2222
this->pelec = new elecstate::ElecState((Charge*)(&chr), this->pw_rho, pw_big);
2323
this->chr.allocate(PARAM.inp.nspin);
2424
}
25-
this->pelec->omega = ucell.omega;
2625

2726
delete this->pelec->pot;
2827
this->pelec->pot = new elecstate::Potential(this->pw_rhod,

source/source_estate/elecstate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class ElecState
114114
std::string classname = "elecstate";
115115

116116
int iter = 0; ///< scf iteration
117-
double omega = 0.0; ///< volume
118117
Potential* pot = nullptr; ///< pointer to potential
119118
Charge* charge = nullptr; ///< pointer to charge density
120119
const K_Vectors* klist = nullptr; ///< pointer to k points lists

source/source_estate/elecstate_energy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ double ElecState::cal_delta_eband(const UnitCell& ucell) const
174174
deband0 = deband_aux;
175175
#endif
176176

177-
deband0 *= this->omega / this->charge->rhopw->nxyz;
177+
deband0 *= ucell.omega / this->charge->rhopw->nxyz;
178178

179179
// \int rho(r) v_{exx}(r) dr = 2 E_{exx}[rho]
180180
deband0 -= 2 * this->f_en.exx; // Peize Lin add 2017-10-16
@@ -246,7 +246,7 @@ double ElecState::cal_delta_escf() const
246246

247247
assert(this->charge->rhopw->nxyz > 0);
248248

249-
descf *= this->omega / this->charge->rhopw->nxyz;
249+
descf *= this->charge->rhopw->omega / this->charge->rhopw->nxyz;
250250
return descf;
251251
}
252252

source/source_estate/magnetism.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ void Magnetism::compute_mag(const double& omega,
2323
const double* const * rho,
2424
double* nelec_spin)
2525
{
26+
assert(omega>0.0);
2627
assert(nxyz>0);
2728

29+
const double fac = omega / nxyz;
30+
2831
if (PARAM.inp.nspin==2)
2932
{
3033
this->tot_mag = 0.00;
@@ -40,8 +43,8 @@ void Magnetism::compute_mag(const double& omega,
4043
Parallel_Reduce::reduce_pool(this->tot_mag);
4144
Parallel_Reduce::reduce_pool(this->abs_mag);
4245
#endif
43-
this->tot_mag *= omega / nxyz;
44-
this->abs_mag *= omega / nxyz;
46+
this->tot_mag *= fac;
47+
this->abs_mag *= fac;
4548

4649
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",this->tot_mag);
4750
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag);
@@ -82,15 +85,15 @@ void Magnetism::compute_mag(const double& omega,
8285
#endif
8386
for(int i=0;i<3;i++)
8487
{
85-
this->tot_mag_nc[i] *= omega/ nxyz;
88+
this->tot_mag_nc[i] *= fac;
8689
// mohan add 2025-06-21
8790
if( std::abs(this->tot_mag_nc[i]) < 1.0e-16)
8891
{
8992
this->tot_mag_nc[i] = 0.0;
9093
}
9194
}
9295

93-
this->abs_mag *= omega/ nxyz;
96+
this->abs_mag *= fac;
9497

9598
// mohan update 2025-06-21
9699
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",

source/source_estate/setup_estate_pw.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ void elecstate::setup_estate_pw(UnitCell& ucell, // unitcell
3939
}
4040
}
4141

42-
//! Set the cell volume variable in pelec
43-
pelec->omega = ucell.omega;
44-
4542
//! Inititlize the charge density.
4643
chr.allocate(inp.nspin);
4744

source/source_lcao/setup_deepks.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ void Setup_DeePKS<TK>::before_runner(const UnitCell& ucell, // unitcell
6161
#endif
6262
}
6363

64+
template <typename TK>
65+
void Setup_DeePKS<TK>::delta_e(
66+
const K_Vectors &kv,
67+
const Parallel_Orbitals &pv, // parallel orbitals
68+
const Grid_Driver &gd,
69+
const std::vector<std::vector<TK>>& dm_vec,
70+
const Input_para &inp)
71+
{
72+
#ifdef __MLALGO
73+
if (inp.deepks_scf)
74+
{
75+
this->ld.dpks_cal_e_delta_band(dm_vec, kv.get_nks());
76+
DeePKS_domain::update_dmr(kv.kvec_d, dm_vec, ucell, orb_, pv, gd, this->ld.dm_r);
77+
estate->f_en.edeepks_scf = this->ld.E_delta - this->ld.e_delta_band;
78+
estate->f_en.edeepks_delta = this->ld.E_delta;
79+
}
80+
#endif
81+
}
82+
83+
6484

6585
template <typename TK>
6686
void Setup_DeePKS<TK>::write_forces(

0 commit comments

Comments
 (0)