Skip to content

Commit 9cc7f89

Browse files
authored
Refactor: remove nscf() (#5455)
* Refactor: remove nscf() * move calculate_weight() out of psi2rho() * update PW_DIAG_NMAX for nscf
1 parent 2a40059 commit 9cc7f89

33 files changed

+223
-705
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,8 @@ OBJS_ESOLVER=esolver.o\
245245
esolver_of.o\
246246
esolver_of_tool.o\
247247
esolver_of_interface.o\
248-
pw_fun.o\
249248
pw_init_after_vc.o\
250249
pw_init_globalc.o\
251-
pw_nscf.o\
252250
pw_others.o\
253251

254252
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
@@ -259,7 +257,6 @@ OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
259257
set_matrix_grid.o\
260258
lcao_before_scf.o\
261259
lcao_gets.o\
262-
lcao_nscf.o\
263260
lcao_others.o\
264261
lcao_init_after_vc.o\
265262
lcao_fun.o\

source/driver_run.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ void Driver::driver_run() {
6262
{
6363
Run_MD::md_line(GlobalC::ucell, p_esolver, PARAM);
6464
}
65-
else if (cal_type == "scf" || cal_type == "relax" || cal_type == "cell-relax")
65+
else if (cal_type == "scf" || cal_type == "relax" || cal_type == "cell-relax" || cal_type == "nscf")
6666
{
6767
Relax_Driver rl_driver;
6868
rl_driver.relax_driver(p_esolver);
6969
}
7070
else
7171
{
7272
//! supported "other" functions:
73-
//! nscf(PW,LCAO),
7473
//! get_pchg(LCAO),
7574
//! test_memory(PW,LCAO),
7675
//! test_neighbour(LCAO),

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "elecstate_lcao.h"
22

3-
#include <vector>
4-
53
#include "cal_dm.h"
64
#include "module_base/timer.h"
75
#include "module_elecstate/module_dm/cal_dm_psi.h"
@@ -11,6 +9,8 @@
119
#include "module_hamilt_pw/hamilt_pwdft/global.h"
1210
#include "module_parameter/parameter.h"
1311

12+
#include <vector>
13+
1414
namespace elecstate
1515
{
1616

@@ -21,34 +21,31 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
2121
ModuleBase::TITLE("ElecStateLCAO", "psiToRho");
2222
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
2323

24-
this->calculate_weights();
25-
26-
// the calculations of dm, and dm -> rho are, technically, two separate
27-
// functionalities, as we cannot rule out the possibility that we may have a
28-
// dm from other sources, such as read from file. However, since we are not
29-
// separating them now, I opt to add a flag to control how dm is obtained as
30-
// of now
31-
if (!PARAM.inp.dm_to_rho)
32-
{
33-
this->calEBand();
34-
35-
ModuleBase::GlobalFunc::NOTE("Calculate the density matrix.");
36-
37-
// this part for calculating DMK in 2d-block format, not used for charge
38-
// now
39-
// psi::Psi<std::complex<double>> dm_k_2d();
40-
41-
if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver == "scalapack_gvx" || PARAM.inp.ks_solver == "lapack"
42-
|| PARAM.inp.ks_solver == "cusolver" || PARAM.inp.ks_solver == "cusolvermp"
43-
|| PARAM.inp.ks_solver == "cg_in_lcao") // Peize Lin test 2019-05-15
44-
{
45-
elecstate::cal_dm_psi(this->DM->get_paraV_pointer(),
46-
this->wg,
47-
psi,
48-
*(this->DM));
49-
this->DM->cal_DMR();
50-
}
51-
}
24+
// // the calculations of dm, and dm -> rho are, technically, two separate
25+
// // functionalities, as we cannot rule out the possibility that we may have a
26+
// // dm from other sources, such as read from file. However, since we are not
27+
// // separating them now, I opt to add a flag to control how dm is obtained as
28+
// // of now
29+
// if (!PARAM.inp.dm_to_rho)
30+
// {
31+
// ModuleBase::GlobalFunc::NOTE("Calculate the density matrix.");
32+
33+
// // this part for calculating DMK in 2d-block format, not used for charge
34+
// // now
35+
// // psi::Psi<std::complex<double>> dm_k_2d();
36+
37+
// if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver ==
38+
// "scalapack_gvx" || PARAM.inp.ks_solver == "lapack"
39+
// || PARAM.inp.ks_solver == "cusolver" || PARAM.inp.ks_solver == "cusolvermp"
40+
// || PARAM.inp.ks_solver == "cg_in_lcao") // Peize Lin test 2019-05-15
41+
// {
42+
// elecstate::cal_dm_psi(this->DM->get_paraV_pointer(),
43+
// this->wg,
44+
// psi,
45+
// *(this->DM));
46+
// this->DM->cal_DMR();
47+
// }
48+
// }
5249

5350
for (int is = 0; is < PARAM.inp.nspin; is++)
5451
{
@@ -83,23 +80,6 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
8380
ModuleBase::TITLE("ElecStateLCAO", "psiToRho");
8481
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
8582

86-
this->calculate_weights();
87-
this->calEBand();
88-
89-
if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver == "scalapack_gvx" || PARAM.inp.ks_solver == "lapack"
90-
|| PARAM.inp.ks_solver == "cusolver" || PARAM.inp.ks_solver == "cusolvermp" || PARAM.inp.ks_solver == "cg_in_lcao")
91-
{
92-
ModuleBase::timer::tick("ElecStateLCAO", "cal_dm_2d");
93-
94-
// get DMK in 2d-block format
95-
elecstate::cal_dm_psi(this->DM->get_paraV_pointer(),
96-
this->wg,
97-
psi,
98-
*(this->DM));
99-
this->DM->cal_DMR();
100-
ModuleBase::timer::tick("ElecStateLCAO", "cal_dm_2d");
101-
}
102-
10383
for (int is = 0; is < PARAM.inp.nspin; is++)
10484
{
10585
ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is],

source/module_elecstate/elecstate_lcao.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class ElecStateLCAO : public ElecState
7474
void dmToRho(std::vector<TK*> pexsi_DM, std::vector<TK*> pexsi_EDM);
7575
#endif
7676

77+
DensityMatrix<TK, double>* DM = nullptr;
78+
7779
protected:
7880
// calculate electronic charge density on grid points or density matrix in real space
7981
// the consequence charge density rho saved into rho_out, preparing for charge mixing.
@@ -85,7 +87,6 @@ class ElecStateLCAO : public ElecState
8587

8688
Gint_Gamma* gint_gamma = nullptr; // mohan add 2024-04-01
8789
Gint_k* gint_k = nullptr; // mohan add 2024-04-01
88-
DensityMatrix<TK, double>* DM = nullptr;
8990
};
9091

9192
template <typename TK>

source/module_elecstate/elecstate_pw.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
8989
ModuleBase::timer::tick("ElecStatePW", "psiToRho");
9090

9191
this->init_rho_data();
92-
this->calculate_weights();
93-
94-
this->calEBand();
9592

9693
for(int is=0; is<PARAM.inp.nspin; is++)
9794
{

source/module_elecstate/elecstate_pw_sdft.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ void ElecStatePW_SDFT<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
1717

1818
if (GlobalV::MY_STOGROUP == 0)
1919
{
20-
this->calEBand();
21-
2220
for (int is = 0; is < nspin; is++)
2321
{
2422
setmem_var_op()(this->ctx, this->rho[is], 0, this->charge->nrxx);

source/module_esolver/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ list(APPEND objects
1010
esolver_of.cpp
1111
esolver_of_interface.cpp
1212
esolver_of_tool.cpp
13-
pw_fun.cpp
1413
pw_init_after_vc.cpp
1514
pw_init_globalc.cpp
16-
pw_nscf.cpp
1715
pw_others.cpp
1816
)
1917
if(ENABLE_LCAO)
@@ -26,7 +24,6 @@ if(ENABLE_LCAO)
2624
dftu_cal_occup_m.cpp
2725
lcao_before_scf.cpp
2826
lcao_gets.cpp
29-
lcao_nscf.cpp
3027
lcao_others.cpp
3128
lcao_init_after_vc.cpp
3229
lcao_fun.cpp

source/module_esolver/esolver_fp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ namespace ModuleESolver
5252
//! Electorn charge density
5353
Charge chr;
5454

55-
//! Non-Self-Consistant Filed (NSCF) calculations
56-
virtual void nscf(){};
57-
5855
//! Structure factors that used with plane-wave basis set
5956
Structure_Factor sf;
6057

source/module_esolver/esolver_ks.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void ESolver_KS<T, Device>::hamilt2density(const int istep, const int iter, cons
402402

403403
drho = p_chgmix->get_drho(pelec->charge, PARAM.inp.nelec);
404404
hsolver_error = 0.0;
405-
if (iter == 1)
405+
if (iter == 1 && PARAM.inp.calculation != "nscf")
406406
{
407407
hsolver_error
408408
= hsolver::cal_hsolve_error(PARAM.inp.basis_type, PARAM.inp.esolver_type, diag_ethr, PARAM.inp.nelec);
@@ -472,13 +472,10 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
472472

473473
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT SCF");
474474

475+
// 4) SCF iterations
475476
this->conv_esolver = false;
476477
this->niter = this->maxniter;
477-
478-
// 4) SCF iterations
479478
this->diag_ethr = PARAM.inp.pw_diag_thr;
480-
481-
std::cout << " * * * * * *\n << Start SCF iteration." << std::endl;
482479
for (int iter = 1; iter <= this->maxniter; ++iter)
483480
{
484481
// 6) initialization of SCF iterations
@@ -500,7 +497,6 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
500497
break;
501498
}
502499
} // end scf iterations
503-
std::cout << " >> Leave SCF iteration.\n * * * * * *" << std::endl;
504500

505501
// 15) after scf
506502
ModuleBase::timer::tick(this->classname, "after_scf");
@@ -632,7 +628,7 @@ void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
632628

633629
// If drho < hsolver_error in the first iter or drho < scf_thr, we
634630
// do not change rho.
635-
if (drho < hsolver_error || this->conv_esolver)
631+
if (drho < hsolver_error || this->conv_esolver || PARAM.inp.calculation == "nscf")
636632
{
637633
if (drho < hsolver_error)
638634
{

source/module_esolver/esolver_ks.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class ESolver_KS : public ESolver_FP
4949
// calculate electron density from a specific Hamiltonian with ethr
5050
virtual void hamilt2density_single(const int istep, const int iter, const double ethr);
5151

52-
// calculate electron states from a specific Hamiltonian
53-
virtual void hamilt2estates(const double ethr) {};
54-
5552
// calculate electron density from a specific Hamiltonian
5653
void hamilt2density(const int istep, const int iter, const double ethr);
5754

0 commit comments

Comments
 (0)