Skip to content

Commit 88a3034

Browse files
committed
try to fix the input parameter; built successfully but failed when use_k_continuity = false
1 parent 539d494 commit 88a3034

File tree

5 files changed

+99
-40
lines changed

5 files changed

+99
-40
lines changed

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ void ESolver_KS_PW<T, Device>::hamilt2density_single(UnitCell& ucell,
556556
hsolver::DiagoIterAssist<T, Device>::SCF_ITER,
557557
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_NMAX,
558558
hsolver::DiagoIterAssist<T, Device>::PW_DIAG_THR,
559-
hsolver::DiagoIterAssist<T, Device>::need_subspace);
559+
hsolver::DiagoIterAssist<T, Device>::need_subspace,
560+
PARAM.inp.use_k_continuity);
560561

561562
hsolver_pw_obj.solve(this->p_hamilt,
562563
this->kspw_psi[0],

source/module_hsolver/hsolver_pw.cpp

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -280,62 +280,105 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
280280
std::vector<Real> eigenvalues(this->wfc_basis->nks * psi.get_nbands(), 0.0);
281281
ethr_band.resize(psi.get_nbands(), this->diag_thr);
282282

283-
// using k-point continuity
283+
// Initialize k-point continuity if enabled
284+
static int count = 0;
284285
if (use_k_continuity) {
285286
build_k_neighbors();
286287
}
287288

288-
static int count = 0;
289+
// Loop over k points for solve Hamiltonian to charge density
290+
if (use_k_continuity) {
291+
// K-point continuity case
292+
for (int i = 0; i < this->wfc_basis->nks; ++i)
293+
{
294+
const int ik = k_order[i];
295+
296+
// update H(k) for each k point
297+
pHamilt->updateHk(ik);
289298

290-
/// Loop over k points for solve Hamiltonian to charge density
291-
for (int i = 0; i < this->wfc_basis->nks; ++i)
292-
{
293-
const int ik = use_k_continuity ? k_order[i] : i;
294-
// ModuleBase::timer::tick("HsolverPW", "k_point: " + std::to_string(ik));
295-
/// update H(k) for each k point
296-
pHamilt->updateHk(ik);
299+
#ifdef USE_PAW
300+
this->paw_func_in_kloop(ik, tpiba);
301+
#endif
302+
303+
// update psi pointer for each k point
304+
psi.fix_k(ik);
305+
306+
// If using k-point continuity and not first k-point, propagate from parent
307+
if (ik > 0 && count == 0 && k_parent.find(ik) != k_parent.end()) {
308+
propagate_psi(psi, k_parent[ik], ik);
309+
}
310+
311+
// template add precondition calculating here
312+
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], Real(pes->pot->get_vl_of_0()));
313+
314+
// use smooth threshold for all iter methods
315+
if (PARAM.inp.diago_smooth_ethr == true)
316+
{
317+
this->cal_smooth_ethr(pes->klist->wk[ik],
318+
&pes->wg(ik, 0),
319+
DiagoIterAssist<T, Device>::PW_DIAG_THR,
320+
ethr_band);
321+
}
297322

298323
#ifdef USE_PAW
299-
this->paw_func_in_kloop(ik, tpiba);
324+
this->call_paw_cell_set_currentk(ik);
300325
#endif
301326

302-
/// update psi pointer for each k point
303-
psi.fix_k(ik);
327+
// solve eigenvector and eigenvalue for H(k)
328+
this->hamiltSolvePsiK(pHamilt, psi, precondition, eigenvalues.data() + ik * psi.get_nbands(), this->wfc_basis->nks);
304329

305-
// If using k-point continuity and not first k-point, propagate from parent
306-
if (use_k_continuity && ik > 0 && count == 0) {
307-
propagate_psi(psi, k_parent[ik], ik);
330+
if (skip_charge)
331+
{
332+
GlobalV::ofs_running << "Average iterative diagonalization steps for k-points " << ik
333+
<< " is: " << DiagoIterAssist<T, Device>::avg_iter
334+
<< " ; where current threshold is: " << this->diag_thr << " . " << std::endl;
335+
DiagoIterAssist<T, Device>::avg_iter = 0.0;
336+
}
308337
}
338+
}
339+
else {
340+
// Original code without k-point continuity
341+
for (int ik = 0; ik < this->wfc_basis->nks; ++ik)
342+
{
343+
// update H(k) for each k point
344+
pHamilt->updateHk(ik);
309345

310-
// template add precondition calculating here
311-
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], Real(pes->pot->get_vl_of_0()));
346+
#ifdef USE_PAW
347+
this->paw_func_in_kloop(ik, tpiba);
348+
#endif
312349

313-
// use smooth threshold for all iter methods
314-
if (PARAM.inp.diago_smooth_ethr == true)
315-
{
316-
this->cal_smooth_ethr(pes->klist->wk[ik],
317-
&pes->wg(ik, 0),
318-
DiagoIterAssist<T, Device>::PW_DIAG_THR,
319-
ethr_band);
320-
}
350+
// update psi pointer for each k point
351+
psi.fix_k(ik);
352+
353+
// template add precondition calculating here
354+
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], Real(pes->pot->get_vl_of_0()));
355+
356+
// use smooth threshold for all iter methods
357+
if (PARAM.inp.diago_smooth_ethr == true)
358+
{
359+
this->cal_smooth_ethr(pes->klist->wk[ik],
360+
&pes->wg(ik, 0),
361+
DiagoIterAssist<T, Device>::PW_DIAG_THR,
362+
ethr_band);
363+
}
321364

322365
#ifdef USE_PAW
323-
this->call_paw_cell_set_currentk(ik);
366+
this->call_paw_cell_set_currentk(ik);
324367
#endif
325368

326-
/// solve eigenvector and eigenvalue for H(k)
327-
this->hamiltSolvePsiK(pHamilt, psi, precondition, eigenvalues.data() + ik * psi.get_nbands(), this->wfc_basis->nks);
369+
// solve eigenvector and eigenvalue for H(k)
370+
this->hamiltSolvePsiK(pHamilt, psi, precondition, eigenvalues.data() + ik * psi.get_nbands(), this->wfc_basis->nks);
328371

329-
if (skip_charge)
330-
{
331-
GlobalV::ofs_running << "Average iterative diagonalization steps for k-points " << ik
332-
<< " is: " << DiagoIterAssist<T, Device>::avg_iter
333-
<< " ; where current threshold is: " << this->diag_thr << " . " << std::endl;
334-
DiagoIterAssist<T, Device>::avg_iter = 0.0;
372+
if (skip_charge)
373+
{
374+
GlobalV::ofs_running << "Average iterative diagonalization steps for k-points " << ik
375+
<< " is: " << DiagoIterAssist<T, Device>::avg_iter
376+
<< " ; where current threshold is: " << this->diag_thr << " . " << std::endl;
377+
DiagoIterAssist<T, Device>::avg_iter = 0.0;
378+
}
335379
}
336-
// ModuleBase::timer::tick("HsolverPW", "k_point: " + std::to_string(ik));
337-
/// calculate the contribution of Psi for charge density rho
338380
}
381+
339382
count++;
340383
// END Loop over k points
341384

source/module_hsolver/hsolver_pw.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ class HSolverPW
3535
const int scf_iter_in,
3636
const int diag_iter_max_in,
3737
const double diag_thr_in,
38-
const bool need_subspace_in)
38+
const bool need_subspace_in,
39+
const bool use_k_continuity_in = true)
3940
: wfc_basis(wfc_basis_in), calculation_type(calculation_type_in), basis_type(basis_type_in), method(method_in),
4041
use_paw(use_paw_in), use_uspp(use_uspp_in), nspin(nspin_in), scf_iter(scf_iter_in),
41-
diag_iter_max(diag_iter_max_in), diag_thr(diag_thr_in), need_subspace(need_subspace_in){};
42+
diag_iter_max(diag_iter_max_in), diag_thr(diag_thr_in), need_subspace(need_subspace_in),
43+
use_k_continuity(use_k_continuity_in) {};
4244

4345
/// @brief solve function for pw
4446
/// @param pHamilt interface to hamilt
@@ -85,6 +87,8 @@ class HSolverPW
8587

8688
const bool need_subspace; // for cg or dav_subspace
8789

90+
const bool use_k_continuity;
91+
8892
protected:
8993
Device* ctx = {};
9094

@@ -107,7 +111,6 @@ class HSolverPW
107111
#endif
108112

109113
// K-point continuity related members
110-
bool use_k_continuity = true;
111114
std::vector<int> k_order;
112115
std::unordered_map<int, int> k_parent;
113116
std::vector<ModuleBase::Vector3<double>> kvecs_c;

source/module_io/read_input_item_elec_stru.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ void ReadInput::item_elec_stru()
320320
read_sync_bool(input.diago_smooth_ethr);
321321
this->add_item(item);
322322
}
323+
{
324+
Input_Item item("use_k_continuity");
325+
item.annotation = "whether to use k-point continuity for initializing wave functions";
326+
read_sync_bool(input.use_k_continuity);
327+
item.check_value = [](const Input_Item& item, const Parameter& para) {
328+
if (para.input.basis_type != "pw") {
329+
GlobalV::ofs_warning << "use_k_continuity only works for PW basis" << std::endl;
330+
}
331+
};
332+
this->add_item(item);
333+
}
323334
{
324335
Input_Item item("pw_diag_ndim");
325336
item.annotation = "dimension of workspace for Davidson diagonalization";

source/module_parameter/input_parameter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct Input_para
8989
bool diago_smooth_ethr = false; ///< smooth ethr for iter methods
9090
int pw_diag_ndim = 4; ///< dimension of workspace for Davidson diagonalization
9191
int diago_cg_prec = 1; ///< mohan add 2012-03-31
92+
bool use_k_continuity = true; ///< whether to use k-point continuity for initializing wave functions
9293

9394
std::string smearing_method = "gauss"; ///< "gauss",
9495
///< "mp","methfessel-paxton"

0 commit comments

Comments
 (0)