Skip to content

Commit 8d68606

Browse files
authored
Merge branch 'develop' into fix/pchg_wfc
2 parents 2ca3d6c + fac9330 commit 8d68606

100 files changed

Lines changed: 1504 additions & 1248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
272272
cal_dm_psi.o\
273273
cal_edm_tddft.o\
274274

275-
OBJS_ESOLVER=esolver.o\
275+
OBJS_ESOLVER=esolver_factory.o\
276276
esolver_ks.o\
277277
esolver_fp.o\
278278
esolver_ks_pw.o\

source/source_esolver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
list(APPEND objects
2-
esolver.cpp
2+
esolver_factory.cpp
33
esolver_ks.cpp
44
esolver_fp.cpp
55
esolver_ks_pw.cpp

source/source_esolver/esolver.h

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

5151
std::string classname;
52-
};
5352

54-
/**
55-
* @brief A subrutine called in init_esolver()
56-
* This function returns type of ESolver
57-
* Based on PARAM.inp.basis_type and PARAM.inp.esolver_type
58-
* @return [out] std::string The type of ESolver
59-
*/
60-
std::string determine_type();
61-
62-
/**
63-
* @brief Determine and initialize an ESolver based on input information.
64-
*
65-
* This function determines the type of ESolver to create based on input information and initializes
66-
* the corresponding ESolver child class. It supports various ESolver types including ksdft_pw,
67-
* ksdft_lcao, ksdft_lcao_tddft, sdft_pw, ofdft, lj_pot, and dp_pot.
68-
*
69-
* @return [out] A pointer to an ESolver object that will be initialized.
70-
*/
71-
ESolver* init_esolver(const Input_para& inp);
53+
protected:
54+
/// Bound in before_all_runners; members use inp_->xxx instead of PARAM.inp.xxx
55+
const Input_para* inp_ = nullptr;
56+
};
7257

7358
} // namespace ModuleESolver
7459

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: 33 additions & 31 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;
@@ -151,17 +151,18 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
151151
&this->dftu,
152152
this->deepks,
153153
istep,
154-
this->exx_nao);
154+
this->exx_nao,
155+
this->exx_info_);
155156
}
156157

157-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
158+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
158159
elecstate::init_scf(ucell,
159160
this->Pgrid,
160161
this->sf.strucFac,
161162
this->locpp.numeric,
162163
istep,
163164
PARAM.globalv.global_out_dir,
164-
PARAM.inp,
165+
*this->inp_,
165166
this->pelec_base);
166167
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
167168

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

186-
bool output_iter = PARAM.inp.deepks_out_labels > 0 && PARAM.inp.deepks_out_freq_elec
187-
&& (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);
188189

189190
if (output_iter)
190191
{
191192
// save output charge density (density after diagnonalization)
192-
for (int is = 0; is < PARAM.inp.nspin; is++)
193+
for (int is = 0; is < this->inp_->nspin; is++)
193194
{
194195
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
195196
if (XC_Functional::get_ked_flag())
@@ -220,7 +221,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
220221
// This will change the result of out_hsk
221222
// The original result of out_hsk is H of input density, but this change H to that of output density
222223
// When converged, these two should be close
223-
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)
224225
{
225226
// update real space Hamiltonian
226227
this->p_hamilt->refresh();
@@ -255,7 +256,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
255256

256257
// ---------- prepare for base ----------
257258
// set as base functional Temporarily
258-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
259+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
259260

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

283284
#ifdef __MLALGO
284-
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);
285286
LCAO_deepks_io::save_npy_e(pelec_base->f_en.etot, file_ebase, GlobalV::MY_RANK);
286287
#endif
287288

288289
// ---------- h_base ----------
289-
if (PARAM.inp.deepks_v_delta > 0)
290+
if (this->inp_->deepks_v_delta > 0)
290291
{
291-
if (PARAM.inp.vl_in_h)
292+
if (this->inp_->vl_in_h)
292293
{
293294
// update real space Hamiltonian
294295
this->p_hamilt_base->refresh();
@@ -307,13 +308,13 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
307308
std::vector<TH> h_tot(nks);
308309
DeePKS_domain::get_h_tot<TK, TH, TR>(this->pv, p_ham_deepks_base, h_tot, PARAM.globalv.nlocal, nks, 'H');
309310

310-
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);
311312
LCAO_deepks_io::save_npy_h<TK, TH>(h_tot, file_htot, PARAM.globalv.nlocal, nks, GlobalV::MY_RANK);
312313
#endif
313314
}
314315

315316
// ---------- o_base ----------
316-
if (PARAM.inp.deepks_bandgap > 0)
317+
if (this->inp_->deepks_bandgap > 0)
317318
{
318319
// obase isn't implemented yet
319320
// don't need to solve p_hamilt_base
@@ -324,17 +325,17 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
324325
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
325326
}
326327
// ---------- prepare for f_base ----------
327-
else if (PARAM.inp.cal_force && conv_esolver)
328+
else if (this->inp_->cal_force && conv_esolver)
328329
{
329330
// vnew must be updated for force_scc() even if not output_iter
330331
// set as base functional Temporarily
331-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
332+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
332333
this->pelec_base->cal_converged();
333334
// restore to original xc
334335
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
335336
}
336337

337-
if (PARAM.inp.cal_force)
338+
if (this->inp_->cal_force)
338339
{
339340
if (!conv_esolver)
340341
{
@@ -344,7 +345,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
344345
else
345346
{
346347
// copy charge
347-
for (int is = 0; is < PARAM.inp.nspin; is++)
348+
for (int is = 0; is < this->inp_->nspin; is++)
348349
{
349350
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
350351
if (XC_Functional::get_ked_flag())
@@ -388,16 +389,16 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
388389
Force_Stress_LCAO<TK> fsl(this->RA, ucell.nat);
389390

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

393394
this->deepks.dpks_out_type = "base"; // for deepks method
394395

395396
fsl.getForceStress(ucell,
396397
this->get_vdw_result(),
397-
PARAM.inp.cal_force,
398-
PARAM.inp.cal_stress,
399-
PARAM.inp.test_force,
400-
PARAM.inp.test_stress,
398+
this->inp_->cal_force,
399+
this->inp_->cal_stress,
400+
this->inp_->test_force,
401+
this->inp_->test_stress,
401402
this->gd,
402403
this->pv,
403404
this->pelec_base,
@@ -415,7 +416,8 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
415416
this->dftu,
416417
this->deepks,
417418
this->exx_nao,
418-
&ucell.symm);
419+
&ucell.symm,
420+
this->exx_info_);
419421

420422
// restore to original xc
421423
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);

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)