Skip to content

Commit 1571b93

Browse files
author
abacus_fixer
committed
remove PARAM.inp in esolver
1 parent ff4b003 commit 1571b93

23 files changed

Lines changed: 469 additions & 453 deletions

source/source_esolver/esolver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class ESolver
4949
bool conv_esolver = true; // whether esolver is converged
5050

5151
std::string classname;
52+
53+
protected:
54+
/// Bound in before_all_runners; members use inp_->xxx instead of PARAM.inp.xxx
55+
const Input_para* inp_ = nullptr;
5256
};
5357

5458
} // namespace ModuleESolver

source/source_esolver/esolver_dfpt_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void ESolver_DFPT_PW::init_dfpt(UnitCell& ucell)
8686

8787
dfpt_ = new ModuleDFPT::DFPT_PW();
8888

89-
// dfpt_->init(ucell, *this->stp.psi, this->pelec->nelec, PARAM.inp.ecutwfc);
89+
// dfpt_->init(ucell, *this->stp.psi, this->pelec->nelec, this->inp_->ecutwfc);
9090

9191
dfpt_->set_parameters("dfpt.in");
9292

source/source_esolver/esolver_dm2rho.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell& basecell, const int istep)
5858
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(1)));
5959

6060
// if nspin=2, need extra reading
61-
if (PARAM.inp.nspin == 2)
61+
if (this->inp_->nspin == 2)
6262
{
6363
zipname = "output_DM1.npz";
6464
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(2)));
6565
}
6666

6767
// it's dangerous to design psiToRho function like this, mohan note 20251024
6868
// this->pelec->psiToRho(*this->psi);
69-
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
69+
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), this->inp_->nspin, &this->chr);
7070

71-
int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1;
71+
int nspin0 = this->inp_->nspin == 2 ? 2 : 1;
7272

7373
for (int is = 0; is < nspin0; is++)
7474
{
@@ -78,7 +78,7 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell& basecell, const int istep)
7878
ModuleIO::write_vdata_palgrid(this->Pgrid,
7979
this->chr.rho[is],
8080
is,
81-
PARAM.inp.nspin,
81+
this->inp_->nspin,
8282
istep,
8383
fn,
8484
this->pelec->eferm.get_efval(is),

source/source_esolver/esolver_double_xc.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(BaseCell& basecell, const Inpu
6464
int ncol = 0;
6565
if (PARAM.globalv.gamma_only_local)
6666
{
67-
nsk = PARAM.inp.nspin;
67+
nsk = this->inp_->nspin;
6868
ncol = this->pv.ncol_bands;
69-
if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver == "lapack"
70-
|| PARAM.inp.ks_solver == "pexsi" || PARAM.inp.ks_solver == "cusolver"
71-
|| PARAM.inp.ks_solver == "cusolvermp")
69+
if (this->inp_->ks_solver == "genelpa" || this->inp_->ks_solver == "elpa" || this->inp_->ks_solver == "lapack"
70+
|| this->inp_->ks_solver == "pexsi" || this->inp_->ks_solver == "cusolver"
71+
|| this->inp_->ks_solver == "cusolvermp")
7272
{
7373
ncol = this->pv.ncol;
7474
}
@@ -79,19 +79,19 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(BaseCell& basecell, const Inpu
7979
#ifdef __MPI
8080
ncol = this->pv.ncol_bands;
8181
#else
82-
ncol = PARAM.inp.nbands;
82+
ncol = this->inp_->nbands;
8383
#endif
8484
}
8585
this->psi_base = new psi::Psi<TK>(nsk, ncol, this->pv.nrow, this->kv.ngk, true);
8686
}
8787

8888
// 6) initialize the density matrix
89-
this->dmat_base.allocate_dm(&this->kv, &this->pv, PARAM.inp.nspin);
89+
this->dmat_base.allocate_dm(&this->kv, &this->pv, this->inp_->nspin);
9090

9191
// 10) inititlize the charge density
9292
this->chr_base.set_rhopw(this->pw_rhod); // mohan add 20251130
9393
const bool kin_den = this->chr_base.kin_density(); // mohan add 20251202
94-
this->chr_base.allocate(PARAM.inp.nspin, kin_den);
94+
this->chr_base.allocate(this->inp_->nspin, kin_den);
9595
this->chr_base.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv);
9696
this->chr_base.check_rho();
9797

@@ -127,7 +127,7 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
127127
//----------------------------------------------------------
128128
//! calculate ewald energy
129129
//----------------------------------------------------------
130-
if (!PARAM.inp.test_skip_ewald)
130+
if (!this->inp_->test_skip_ewald)
131131
{
132132
// this->pelec_base->f_en.ewald_energy = H_Ewald_pw::compute_ewald(ucell, this->pw_rhod, this->sf.strucFac);
133133
this->pelec_base->f_en.ewald_energy = this->pelec->f_en.ewald_energy;
@@ -155,14 +155,14 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
155155
this->exx_info_);
156156
}
157157

158-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
158+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
159159
elecstate::init_scf(ucell,
160160
this->Pgrid,
161161
this->sf.strucFac,
162162
this->locpp.numeric,
163163
istep,
164164
PARAM.globalv.global_out_dir,
165-
PARAM.inp,
165+
*this->inp_,
166166
this->pelec_base);
167167
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
168168

@@ -184,13 +184,13 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
184184
ModuleBase::TITLE("ESolver_DoubleXC", "iter_finish");
185185
ModuleBase::timer::start("ESolver_DoubleXC", "iter_finish");
186186

187-
bool output_iter = PARAM.inp.deepks_out_labels > 0 && PARAM.inp.deepks_out_freq_elec
188-
&& (iter % PARAM.inp.deepks_out_freq_elec == 0);
187+
bool output_iter = this->inp_->deepks_out_labels > 0 && this->inp_->deepks_out_freq_elec
188+
&& (iter % this->inp_->deepks_out_freq_elec == 0);
189189

190190
if (output_iter)
191191
{
192192
// save output charge density (density after diagnonalization)
193-
for (int is = 0; is < PARAM.inp.nspin; is++)
193+
for (int is = 0; is < this->inp_->nspin; is++)
194194
{
195195
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
196196
if (XC_Functional::get_ked_flag())
@@ -221,7 +221,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
221221
// This will change the result of out_hsk
222222
// The original result of out_hsk is H of input density, but this change H to that of output density
223223
// When converged, these two should be close
224-
if (PARAM.inp.deepks_v_delta > 0 && PARAM.inp.vl_in_h)
224+
if (this->inp_->deepks_v_delta > 0 && this->inp_->vl_in_h)
225225
{
226226
// update real space Hamiltonian
227227
this->p_hamilt->refresh();
@@ -256,7 +256,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
256256

257257
// ---------- prepare for base ----------
258258
// set as base functional Temporarily
259-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
259+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
260260

261261
// update pot of pelec_base according to chr_base
262262
if (!conv_esolver)
@@ -282,14 +282,14 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
282282
// std::endl;
283283

284284
#ifdef __MLALGO
285-
const std::string file_ebase = deepks_interface.get_filename("ebase", PARAM.inp.deepks_out_labels, iter);
285+
const std::string file_ebase = deepks_interface.get_filename("ebase", this->inp_->deepks_out_labels, iter);
286286
LCAO_deepks_io::save_npy_e(pelec_base->f_en.etot, file_ebase, GlobalV::MY_RANK);
287287
#endif
288288

289289
// ---------- h_base ----------
290-
if (PARAM.inp.deepks_v_delta > 0)
290+
if (this->inp_->deepks_v_delta > 0)
291291
{
292-
if (PARAM.inp.vl_in_h)
292+
if (this->inp_->vl_in_h)
293293
{
294294
// update real space Hamiltonian
295295
this->p_hamilt_base->refresh();
@@ -308,13 +308,13 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
308308
std::vector<TH> h_tot(nks);
309309
DeePKS_domain::get_h_tot<TK, TH, TR>(this->pv, p_ham_deepks_base, h_tot, PARAM.globalv.nlocal, nks, 'H');
310310

311-
const std::string file_htot = deepks_interface.get_filename("hbase", PARAM.inp.deepks_out_labels, iter);
311+
const std::string file_htot = deepks_interface.get_filename("hbase", this->inp_->deepks_out_labels, iter);
312312
LCAO_deepks_io::save_npy_h<TK, TH>(h_tot, file_htot, PARAM.globalv.nlocal, nks, GlobalV::MY_RANK);
313313
#endif
314314
}
315315

316316
// ---------- o_base ----------
317-
if (PARAM.inp.deepks_bandgap > 0)
317+
if (this->inp_->deepks_bandgap > 0)
318318
{
319319
// obase isn't implemented yet
320320
// don't need to solve p_hamilt_base
@@ -325,17 +325,17 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
325325
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
326326
}
327327
// ---------- prepare for f_base ----------
328-
else if (PARAM.inp.cal_force && conv_esolver)
328+
else if (this->inp_->cal_force && conv_esolver)
329329
{
330330
// vnew must be updated for force_scc() even if not output_iter
331331
// set as base functional Temporarily
332-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
332+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
333333
this->pelec_base->cal_converged();
334334
// restore to original xc
335335
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
336336
}
337337

338-
if (PARAM.inp.cal_force)
338+
if (this->inp_->cal_force)
339339
{
340340
if (!conv_esolver)
341341
{
@@ -345,7 +345,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
345345
else
346346
{
347347
// copy charge
348-
for (int is = 0; is < PARAM.inp.nspin; is++)
348+
for (int is = 0; is < this->inp_->nspin; is++)
349349
{
350350
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
351351
if (XC_Functional::get_ked_flag())
@@ -389,16 +389,16 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
389389
Force_Stress_LCAO<TK> fsl(this->RA, ucell.nat);
390390

391391
// set as base functional Temporarily
392-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
392+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
393393

394394
this->deepks.dpks_out_type = "base"; // for deepks method
395395

396396
fsl.getForceStress(ucell,
397397
this->get_vdw_result(),
398-
PARAM.inp.cal_force,
399-
PARAM.inp.cal_stress,
400-
PARAM.inp.test_force,
401-
PARAM.inp.test_stress,
398+
this->inp_->cal_force,
399+
this->inp_->cal_stress,
400+
this->inp_->test_force,
401+
this->inp_->test_stress,
402402
this->gd,
403403
this->pv,
404404
this->pelec_base,

source/source_esolver/esolver_dp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void ESolver_DP::before_all_runners(BaseCell& basecell, const Input_para& inp)
3434
basecell.require_kind(BaseCell::Kind::unit_cell, __FUNCTION__);
3535
UnitCell& ucell = static_cast<UnitCell&>(basecell);
3636

37+
this->inp_ = &inp;
38+
3739
dp_potential = 0;
3840
dp_force.create(ucell.nat, 3);
3941
dp_virial.create(3, 3);
@@ -163,7 +165,7 @@ void ESolver_DP::cal_stress(BaseCell& basecell, ModuleBase::matrix& stress)
163165

164166
// external stress
165167
double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
166-
double external_stress[3] = {PARAM.inp.press1, PARAM.inp.press2, PARAM.inp.press3};
168+
double external_stress[3] = {this->inp_->press1, this->inp_->press2, this->inp_->press3};
167169
for (int i = 0; i < 3; i++)
168170
{
169171
stress(i, i) -= external_stress[i] / unit_transform;

0 commit comments

Comments
 (0)