Skip to content

Commit 2e60ec1

Browse files
committed
Refactor: remove nscf()
1 parent c03c879 commit 2e60ec1

File tree

20 files changed

+124
-638
lines changed

20 files changed

+124
-638
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_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: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

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

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "esolver_ks_lcao.h"
22

3+
#include "module_base/formatter.h"
34
#include "module_base/global_variable.h"
45
#include "module_base/tool_title.h"
6+
#include "module_io/berryphase.h"
57
#include "module_io/cube_io.h"
68
#include "module_io/dos_nao.h"
79
#include "module_io/nscf_band.h"
@@ -10,6 +12,8 @@
1012
#include "module_io/output_mulliken.h"
1113
#include "module_io/output_sk.h"
1214
#include "module_io/to_qo.h"
15+
#include "module_io/to_wannier90_lcao.h"
16+
#include "module_io/to_wannier90_lcao_in_pw.h"
1317
#include "module_io/write_HS.h"
1418
#include "module_io/write_eband_terms.hpp"
1519
#include "module_io/write_elecstat_pot.h"
@@ -1192,6 +1196,53 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
11921196

11931197
delete ekinetic;
11941198
}
1199+
1200+
// add by jingan in 2018.11.7
1201+
if (PARAM.inp.calculation == "nscf" && PARAM.inp.towannier90)
1202+
{
1203+
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Wave function to Wannier90");
1204+
if (PARAM.inp.wannier_method == 1)
1205+
{
1206+
toWannier90_LCAO_IN_PW myWannier(PARAM.inp.out_wannier_mmn,
1207+
PARAM.inp.out_wannier_amn,
1208+
PARAM.inp.out_wannier_unk,
1209+
PARAM.inp.out_wannier_eig,
1210+
PARAM.inp.out_wannier_wvfn_formatted,
1211+
PARAM.inp.nnkpfile,
1212+
PARAM.inp.wannier_spin);
1213+
1214+
myWannier
1215+
.calculate(this->pelec->ekb, this->pw_wfc, this->pw_big, this->sf, this->kv, this->psi, &(this->pv));
1216+
}
1217+
else if (PARAM.inp.wannier_method == 2)
1218+
{
1219+
toWannier90_LCAO myWannier(PARAM.inp.out_wannier_mmn,
1220+
PARAM.inp.out_wannier_amn,
1221+
PARAM.inp.out_wannier_unk,
1222+
PARAM.inp.out_wannier_eig,
1223+
PARAM.inp.out_wannier_wvfn_formatted,
1224+
PARAM.inp.nnkpfile,
1225+
PARAM.inp.wannier_spin,
1226+
orb_);
1227+
1228+
myWannier.calculate(this->pelec->ekb, this->kv, *(this->psi), &(this->pv));
1229+
}
1230+
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Wave function to Wannier90");
1231+
}
1232+
1233+
// add by jingan
1234+
if (PARAM.inp.calculation == "nscf" && berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != 1)
1235+
{
1236+
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Berry phase calculation");
1237+
berryphase bp(&(this->pv));
1238+
bp.lcao_init(this->kv,
1239+
this->GridT,
1240+
orb_); // additional step before calling
1241+
// macroscopic_polarization (why capitalize
1242+
// the function name?)
1243+
bp.Macroscopic_polarization(this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
1244+
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Berry phase calculation");
1245+
}
11951246
}
11961247

11971248
//------------------------------------------------------------------------------

source/module_esolver/esolver_ks_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
3939

4040
void after_all_runners() override;
4141

42-
void nscf() override;
43-
4442
void get_S();
4543

4644
void cal_mag(const int istep, const bool print = false);

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#include "esolver_ks_pw.h"
22

3-
#include "module_base/global_variable.h"
4-
#include "module_hamilt_pw/hamilt_pwdft/elecond.h"
5-
#include "module_io/input_conv.h"
6-
#include "module_io/nscf_band.h"
7-
#include "module_io/output_log.h"
8-
#include "module_io/write_dos_pw.h"
9-
#include "module_io/write_istate_info.h"
10-
#include "module_io/write_wfc_pw.h"
11-
123
#include <iostream>
134

145
//--------------temporary----------------------------
@@ -22,10 +13,13 @@
2213
//-----stress------------------
2314
#include "module_hamilt_pw/hamilt_pwdft/stress_pw.h"
2415
//---------------------------------------------------
16+
#include "module_base/formatter.h"
17+
#include "module_base/global_variable.h"
2518
#include "module_base/memory.h"
2619
#include "module_base/module_device/device.h"
2720
#include "module_elecstate/elecstate_pw.h"
2821
#include "module_hamilt_general/module_vdw/vdw.h"
22+
#include "module_hamilt_pw/hamilt_pwdft/elecond.h"
2923
#include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h"
3024
#include "module_hsolver/diago_iter_assist.h"
3125
#include "module_hsolver/hsolver_pw.h"
@@ -34,17 +28,22 @@
3428
#include "module_io/berryphase.h"
3529
#include "module_io/cube_io.h"
3630
#include "module_io/get_pchg_pw.h"
31+
#include "module_io/input_conv.h"
32+
#include "module_io/nscf_band.h"
3733
#include "module_io/numerical_basis.h"
3834
#include "module_io/numerical_descriptor.h"
35+
#include "module_io/output_log.h"
3936
#include "module_io/to_wannier90_pw.h"
4037
#include "module_io/winput.h"
38+
#include "module_io/write_dos_pw.h"
4139
#include "module_io/write_elecstat_pot.h"
40+
#include "module_io/write_istate_info.h"
41+
#include "module_io/write_wfc_pw.h"
4242
#include "module_io/write_wfc_r.h"
4343
#include "module_parameter/parameter.h"
4444
#ifdef USE_PAW
4545
#include "module_cell/module_paw/paw_cell.h"
4646
#endif
47-
#include "module_base/formatter.h"
4847

4948
#include <ATen/kernels/blas.h>
5049
#include <ATen/kernels/lapack.h>
@@ -113,6 +112,21 @@ ESolver_KS_PW<T, Device>::~ESolver_KS_PW()
113112
delete this->p_wf_init;
114113
}
115114

115+
template <typename T, typename Device>
116+
void ESolver_KS_PW<T, Device>::allocate_hamilt()
117+
{
118+
this->p_hamilt = new hamilt::HamiltPW<T, Device>(this->pelec->pot, this->pw_wfc, &this->kv);
119+
}
120+
template <typename T, typename Device>
121+
void ESolver_KS_PW<T, Device>::deallocate_hamilt()
122+
{
123+
if (this->p_hamilt != nullptr)
124+
{
125+
delete reinterpret_cast<hamilt::HamiltPW<T, Device>*>(this->p_hamilt);
126+
this->p_hamilt = nullptr;
127+
}
128+
}
129+
116130
template <typename T, typename Device>
117131
void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCell& ucell)
118132
{
@@ -526,6 +540,31 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
526540
PARAM.globalv.global_out_dir,
527541
PARAM.inp.if_separate_k);
528542
}
543+
544+
//! 6) calculate Wannier functions
545+
if (PARAM.inp.calculation == "nscf" && PARAM.inp.towannier90)
546+
{
547+
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Wannier functions calculation");
548+
toWannier90_PW wan(PARAM.inp.out_wannier_mmn,
549+
PARAM.inp.out_wannier_amn,
550+
PARAM.inp.out_wannier_unk,
551+
PARAM.inp.out_wannier_eig,
552+
PARAM.inp.out_wannier_wvfn_formatted,
553+
PARAM.inp.nnkpfile,
554+
PARAM.inp.wannier_spin);
555+
556+
wan.calculate(this->pelec->ekb, this->pw_wfc, this->pw_big, this->kv, this->psi);
557+
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Wannier functions calculation");
558+
}
559+
560+
//! 7) calculate Berry phase polarization
561+
if (PARAM.inp.calculation == "nscf" && berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != 1)
562+
{
563+
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Berry phase polarization");
564+
berryphase bp;
565+
bp.Macroscopic_polarization(this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
566+
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Berry phase polarization");
567+
}
529568
}
530569

531570
template <typename T, typename Device>

source/module_esolver/esolver_ks_pw.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
3333

3434
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
3535

36-
virtual void hamilt2estates(const double ethr) override;
37-
38-
virtual void nscf() override;
39-
4036
void after_all_runners() override;
4137

4238
protected:

0 commit comments

Comments
 (0)