Skip to content

Commit 7f1aa92

Browse files
author
dyzheng
committed
Fix: comments in PR
1 parent 11e3369 commit 7f1aa92

File tree

13 files changed

+33
-48
lines changed

13 files changed

+33
-48
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
- [pw\_diag\_thr](#pw_diag_thr)
4040
- [pw\_diag\_nmax](#pw_diag_nmax)
4141
- [pw\_diag\_ndim](#pw_diag_ndim)
42-
- [diago\_full\_acc](#diago_full_acc)
4342
- [erf\_ecut](#erf_ecut)
4443
- [fft\_mode](#fft_mode)
4544
- [erf\_height](#erf_height)
@@ -779,12 +778,6 @@ These variables are used to control the plane wave related parameters.
779778
- **Description**: Only useful when you use `ks_solver = dav` or `ks_solver = dav_subspace`. It indicates dimension of workspace(number of wavefunction packets, at least 2 needed) for the Davidson method. A larger value may yield a smaller number of iterations in the algorithm but uses more memory and more CPU time in subspace diagonalization.
780779
- **Default**: 4
781780

782-
### diago_full_acc
783-
784-
- **Type**: bool
785-
- **Description**: Only useful when you use `ks_solver = dav_subspace`. If `TRUE`, all the empty states are diagonalized at the same level of accuracy of the occupied ones. Otherwise the empty states are diagonalized using a larger threshold (10-5) (this should not affect total energy, forces, and other ground-state properties).
786-
- **Default**: false
787-
788781
### erf_ecut
789782

790783
- **Type**: Real
@@ -925,7 +918,7 @@ calculations.
925918
- **cg**: cg method.
926919
- **bpcg**: bpcg method, which is a block-parallel Conjugate Gradient (CG) method, typically exhibits higher acceleration in a GPU environment.
927920
- **dav**: the Davidson algorithm.
928-
- **dav_subspace**: subspace Davidson algorithm
921+
- **dav_subspace**: Davidson algorithm without orthogonalization operation, this method is the most recommended for efficiency. `pw_diag_ndim` can be set to 2 for this method.
929922

930923
For atomic orbitals basis,
931924

examples/lr-tddft/lcao_Si2/INPUT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ out_alllog 1
3737

3838
nvirt 19
3939
abs_wavelen_range 100 175
40-
#diago_full_acc 1

source/module_elecstate/potentials/pot_local.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
namespace elecstate
99
{
1010

11-
double PotLocal::vl_of_0 = 0.0;
12-
1311
//==========================================================
1412
// This routine computes the local potential in real space
1513
//==========================================================
@@ -31,7 +29,11 @@ void PotLocal::cal_fixed_v(double *vl_pseudo // store the local pseudopotential
3129
}
3230
}
3331

34-
PotLocal::vl_of_0 = vg[0].real();
32+
/// save the V_local at G=0
33+
if(this->rho_basis_->npw > 0)
34+
{
35+
*vl_of_0_ = vg[0].real();
36+
}
3537

3638
// recip2real should be a const function, but now it isn't
3739
// a dangerous usage appears here, which should be fix in the future.

source/module_elecstate/potentials/pot_local.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class PotLocal : public PotBase
1212
public:
1313
PotLocal(const ModuleBase::matrix* vloc_in, // local pseduopotentials
1414
const ModuleBase::ComplexMatrix* sf_in,
15-
const ModulePW::PW_Basis* rho_basis_in)
16-
: vloc_(vloc_in), sf_(sf_in)
15+
const ModulePW::PW_Basis* rho_basis_in,
16+
double& vl_of_0)
17+
: vloc_(vloc_in), sf_(sf_in), vl_of_0_(&vl_of_0)
1718
{
1819
assert(this->vloc_->nr == this->sf_->nr);
1920
this->rho_basis_ = rho_basis_in;
@@ -24,14 +25,10 @@ class PotLocal : public PotBase
2425

2526
void cal_fixed_v(double* vl_pseudo) override;
2627

27-
/// @brief get the value of vloc at G=0;
28-
/// @return vl(0)
29-
static double get_vl_of_0() { return vl_of_0; }
30-
3128
private:
3229

3330
/// @brief save the value of vloc at G=0; this is a static member because there is only one vl(0) for all instances
34-
static double vl_of_0;
31+
double* vl_of_0_ = nullptr;
3532

3633
// std::vector<double> vltot;
3734

source/module_elecstate/potentials/potential_new.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ class Potential : public PotBase
169169
return this->v_effective_fixed.data();
170170
}
171171

172+
173+
/// @brief get the value of vloc at G=0;
174+
/// @return vl(0)
175+
double get_vl_of_0() const
176+
{
177+
return this->vl_of_0;
178+
}
179+
172180
private:
173181
void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override;
174182
void cal_fixed_v(double* vl_pseudo) override;
@@ -196,6 +204,8 @@ class Potential : public PotBase
196204
double* etxc_ = nullptr;
197205
double* vtxc_ = nullptr;
198206

207+
double vl_of_0 = 0.0;
208+
199209
std::vector<PotBase*> components;
200210

201211
const UnitCell* ucell_ = nullptr;

source/module_elecstate/potentials/potential_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PotBase* Potential::get_pot_type(const std::string& pot_type)
2727
{
2828
if(!PARAM.inp.use_paw)
2929
{
30-
return new PotLocal(this->vloc_, &(this->structure_factors_->strucFac), this->rho_basis_);
30+
return new PotLocal(this->vloc_, &(this->structure_factors_->strucFac), this->rho_basis_, this->vl_of_0);
3131
}
3232
else
3333
{

source/module_hsolver/hsolver_pw.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "module_hsolver/diago_dav_subspace.h"
1616
#include "module_hsolver/diago_david.h"
1717
#include "module_hsolver/diago_iter_assist.h"
18-
#include "module_elecstate/potentials/pot_local.h"
1918

2019
#include <algorithm>
2120
#include <vector>
@@ -212,19 +211,23 @@ void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi, elecst
212211
template <typename T, typename Device>
213212
void HSolverPW<T, Device>::cal_ethr_band(const double& wk, const double* wg, const double& ethr, std::vector<double>& ethrs)
214213
{
214+
// threshold for classifying occupied and unoccupied bands
215+
const double occ_threshold = 1e-2;
216+
// diagonalization threshold limitation for unoccupied bands
217+
const double ethr_limit = 1e-5;
215218
if(wk > 0.0)
216219
{
217220
// Note: the idea of threshold for unoccupied bands (1e-5) comes from QE
218221
// In ABACUS, We applied a smoothing process to this truncation to avoid abrupt changes in energy errors between different bands.
219-
const double ethr_unocc = std::max(1e-5, ethr);
222+
const double ethr_unocc = std::max(ethr_limit, ethr);
220223
for (int i = 0; i < ethrs.size(); i++)
221224
{
222225
double band_weight = wg[i] / wk;
223-
if (band_weight > 1e-2)
226+
if (band_weight > occ_threshold)
224227
{
225228
ethrs[i] = ethr;
226229
}
227-
else if(band_weight > 1e-5)
230+
else if(band_weight > ethr_limit)
228231
{// similar energy difference for different bands when band_weight in range [1e-5, 1e-2]
229232
ethrs[i] = std::min(ethr_unocc, ethr / band_weight);
230233
}
@@ -283,7 +286,7 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
283286
this->updatePsiK(pHamilt, psi, ik);
284287

285288
// template add precondition calculating here
286-
update_precondition(precondition, ik, this->wfc_basis->npwk[ik]);
289+
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], Real(pes->pot->get_vl_of_0()));
287290

288291
// only dav_subspace method used smooth threshold for all bands now,
289292
// for other methods, this trick can be added in the future to accelerate calculation without accuracy loss.
@@ -589,7 +592,7 @@ void HSolverPW<T, Device>::hamiltSolvePsiK(hamilt::Hamilt<T, Device>* hm,
589592
}
590593

591594
template <typename T, typename Device>
592-
void HSolverPW<T, Device>::update_precondition(std::vector<Real>& h_diag, const int ik, const int npw)
595+
void HSolverPW<T, Device>::update_precondition(std::vector<Real>& h_diag, const int ik, const int npw, const Real vl_of_0)
593596
{
594597
h_diag.assign(h_diag.size(), 1.0);
595598
int precondition_type = 2;
@@ -616,7 +619,7 @@ void HSolverPW<T, Device>::update_precondition(std::vector<Real>& h_diag, const
616619

617620
if (this->method == "dav_subspace")
618621
{
619-
h_diag[ig] = g2kin + Real(elecstate::PotLocal::get_vl_of_0());
622+
h_diag[ig] = g2kin + vl_of_0;
620623
}
621624
else
622625
{

source/module_hsolver/hsolver_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class HSolverPW
6363
void updatePsiK(hamilt::Hamilt<T, Device>* pHamilt, psi::Psi<T, Device>& psi, const int ik);
6464

6565
// calculate the precondition array for diagonalization in PW base
66-
void update_precondition(std::vector<Real>& h_diag, const int ik, const int npw);
66+
void update_precondition(std::vector<Real>& h_diag, const int ik, const int npw, const Real vl_of_0);
6767

6868
void output_iterInfo();
6969

source/module_hsolver/hsolver_pw_sdft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void HSolverPW_SDFT::solve(hamilt::Hamilt<std::complex<double>>* pHamilt,
4444
{
4545
this->updatePsiK(pHamilt, psi, ik);
4646
// template add precondition calculating here
47-
update_precondition(precondition, ik, this->wfc_basis->npwk[ik]);
47+
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], pes->pot->get_vl_of_0());
4848
/// solve eigenvector and eigenvalue for H(k)
4949
double* p_eigenvalues = &(pes->ekb(ik, 0));
5050
this->hamiltSolvePsiK(pHamilt, psi, precondition, p_eigenvalues);

source/module_hsolver/test/hsolver_supplementary_mock.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include "module_elecstate/elecstate.h"
3-
#include "module_elecstate/potentials/pot_local.h"
43

54
namespace elecstate
65
{
@@ -58,8 +57,6 @@ void ElecState::init_ks(Charge* chg_in, // pointer for class Charge
5857
return;
5958
}
6059

61-
double PotLocal::vl_of_0 = 0.0;
62-
6360
} // namespace elecstate
6461

6562

0 commit comments

Comments
 (0)