Skip to content

Commit 0bd6719

Browse files
committed
Fix: moadd method string passed in Solver::solve() and delete useless header in esolver.h
1 parent 6887565 commit 0bd6719

File tree

10 files changed

+67
-41
lines changed

10 files changed

+67
-41
lines changed

source/module_esolver/esolver.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#include "../src_pw/energy.h"
77
#include "../module_base/matrix.h"
88
//--------------temporary----------------------------
9-
#include "src_lcao/record_adj.h"
10-
#include "src_lcao/local_orbital_charge.h"
11-
#include "src_lcao/local_orbital_wfc.h"
12-
#include "src_lcao/LCAO_hamilt.h"
139
#include "module_psi/psi.h"
1410

1511
namespace ModuleESolver
@@ -25,6 +21,7 @@ namespace ModuleESolver
2521

2622
virtual ~ESolver()
2723
{
24+
//--------------temporary----------------------------
2825
if(this->psi != nullptr)
2926
{
3027
delete psi;
@@ -41,9 +38,6 @@ namespace ModuleESolver
4138

4239
virtual void Run(int istep, UnitCell_pseudo& cell) = 0;
4340

44-
// this is the interface of non-self-consistant calculation
45-
virtual void nscf() {};
46-
4741
//Deal with exx and other calculation than scf/md/relax:
4842
// such as nscf, istate-charge or envelope
4943
virtual void othercalculation(const int istep) {};
@@ -61,6 +55,10 @@ namespace ModuleESolver
6155
virtual int getniter() { return 0; }
6256
string classname;
6357

58+
//--------------temporary----------------------------
59+
// this is the interface of non-self-consistant calculation
60+
virtual void nscf() {};
61+
6462
//wavefunction coefficients
6563
psi::Psi<std::complex<double>>* psi=nullptr;
6664
};

source/module_esolver/esolver_ks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "module_hsolver/hsolver.h"
77
#include "module_hamilt/hamilt.h"
88
#include "module_elecstate/elecstate.h"
9-
#include "module_psi/psi.h"
109
// #include "estates.h"
1110
// #include "h2e.h"
1211
namespace ModuleESolver

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ namespace ModuleESolver
4646
classname = "ESolver_KS_PW";
4747
basisname = "PW";
4848
}
49+
ESolver_KS_PW::~ESolver_KS_PW()
50+
{
51+
if(this->pelec!=nullptr)
52+
{
53+
delete this->pelec;
54+
}
55+
if(this->phami!=nullptr)
56+
{
57+
delete this->phami;
58+
}
59+
if(this->phsol!=nullptr)
60+
{
61+
delete this->phsol;
62+
}
63+
}
4964

5065
void ESolver_KS_PW::Init(Input& inp, UnitCell_pseudo& ucell)
5166
{
@@ -188,23 +203,7 @@ namespace ModuleESolver
188203

189204
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT BASIS");
190205

191-
192-
193-
}
194-
195-
void ESolver_KS_PW::beforescf(int istep)
196-
{
197-
//calculate ewald energy
198-
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::pw);
199-
//Symmetry_rho should be moved to Init()
200-
Symmetry_rho srho;
201-
for (int is = 0; is < GlobalV::NSPIN; is++)
202-
{
203-
srho.begin(is, GlobalC::CHR, GlobalC::pw, GlobalC::Pgrid, GlobalC::symm);
204-
}
205206
//init Psi, HSolver, ElecState, Hamilt
206-
hsolver::DiagoIterAssist::PW_DIAG_NMAX = GlobalV::PW_DIAG_NMAX;
207-
hsolver::DiagoIterAssist::PW_DIAG_THR = GlobalV::PW_DIAG_THR;
208207
const PW_Basis* pbas = &(GlobalC::pw);
209208
if(this->phsol != nullptr)
210209
{
@@ -217,7 +216,6 @@ namespace ModuleESolver
217216
else
218217
{
219218
this->phsol = new hsolver::HSolverPW(pbas);
220-
this->phsol->method = GlobalV::KS_SOLVER;
221219
}
222220
if(this->pelec != nullptr)
223221
{
@@ -243,6 +241,19 @@ namespace ModuleESolver
243241
{
244242
this->phami = new hamilt::HamiltPW(&(GlobalC::hm.hpw));
245243
}
244+
245+
}
246+
247+
void ESolver_KS_PW::beforescf(int istep)
248+
{
249+
//calculate ewald energy
250+
H_Ewald_pw::compute_ewald(GlobalC::ucell, GlobalC::pw);
251+
//Symmetry_rho should be moved to Init()
252+
Symmetry_rho srho;
253+
for (int is = 0; is < GlobalV::NSPIN; is++)
254+
{
255+
srho.begin(is, GlobalC::CHR, GlobalC::pw, GlobalC::Pgrid, GlobalC::symm);
256+
}
246257
}
247258

248259
void ESolver_KS_PW::eachiterinit(const int istep, const int iter)
@@ -293,7 +304,8 @@ namespace ModuleESolver
293304
}
294305

295306
hsolver::DiagoIterAssist::PW_DIAG_THR = ethr;
296-
this->phsol->solve(this->phami, this->psi[0], this->pelec);
307+
hsolver::DiagoIterAssist::PW_DIAG_NMAX = GlobalV::PW_DIAG_NMAX;
308+
this->phsol->solve(this->phami, this->psi[0], this->pelec, GlobalV::KS_SOLVER);
297309

298310
// transform energy for print
299311
GlobalC::en.eband = this->pelec->eband;
@@ -670,7 +682,7 @@ namespace ModuleESolver
670682
{
671683
hsolver::DiagoIterAssist::need_subspace = false;
672684
hsolver::DiagoIterAssist::PW_DIAG_THR = ethr;
673-
this->phsol->solve(this->phami, this->psi[0], this->pelec, true);
685+
this->phsol->solve(this->phami, this->psi[0], this->pelec, GlobalV::KS_SOLVER, true);
674686
}
675687
else
676688
{

source/module_esolver/esolver_ks_pw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace ModuleESolver
1414
{
1515
public:
1616
ESolver_KS_PW();
17+
~ESolver_KS_PW();
1718
void Init(Input& inp, UnitCell_pseudo& cell) override;
1819
void cal_Energy(energy& en) override;
1920
void cal_Force(ModuleBase::matrix& force) override;

source/module_hsolver/hsolver.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,25 @@ class HSolver
2626
Input &in )=0;*/
2727

2828
// solve Hamiltonian to electronic density in ElecState
29-
virtual void solve(hamilt::Hamilt* phm, psi::Psi<std::complex<double>>& ppsi, elecstate::ElecState* pes, const bool skip_charge=false)
29+
virtual void solve
30+
(
31+
hamilt::Hamilt* phm,
32+
psi::Psi<std::complex<double>>& ppsi,
33+
elecstate::ElecState* pes,
34+
const std::string method,
35+
const bool skip_charge=false
36+
)
3037
{
3138
return;
3239
}
33-
virtual void solve(hamilt::Hamilt* phm, psi::Psi<double>& ppsi, elecstate::ElecState* pes, const bool skip_charge=false)
40+
virtual void solve
41+
(
42+
hamilt::Hamilt* phm,
43+
psi::Psi<double>& ppsi,
44+
elecstate::ElecState* pes,
45+
const std::string method,
46+
const bool skip_charge=false
47+
)
3448
{
3549
return;
3650
}

source/module_hsolver/hsolver_lcao.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ namespace hsolver
77
{
88

99
template <typename T>
10-
void HSolverLCAO::solveTemplate(hamilt::Hamilt* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, const bool skip_charge)
10+
void HSolverLCAO::solveTemplate(hamilt::Hamilt* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge)
1111
{
1212
// select the method of diagonalization
13+
this->method = method_in;
1314
if (this->method == "genelpa")
1415
{
1516
if (pdiagh != nullptr)
@@ -79,13 +80,13 @@ void HSolverLCAO::solveTemplate(hamilt::Hamilt* pHamilt, psi::Psi<T>& psi, elecs
7980
int HSolverLCAO::out_mat_hs = 0;
8081
int HSolverLCAO::out_mat_hsR = 0;
8182

82-
void HSolverLCAO::solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const bool skip_charge)
83+
void HSolverLCAO::solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge)
8384
{
84-
this->solveTemplate(pHamilt, psi, pes, skip_charge);
85+
this->solveTemplate(pHamilt, psi, pes, method, skip_charge);
8586
}
86-
void HSolverLCAO::solve(hamilt::Hamilt* pHamilt, psi::Psi<double>& psi, elecstate::ElecState* pes, const bool skip_charge)
87+
void HSolverLCAO::solve(hamilt::Hamilt* pHamilt, psi::Psi<double>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge)
8788
{
88-
this->solveTemplate(pHamilt, psi, pes, skip_charge);
89+
this->solveTemplate(pHamilt, psi, pes, method, skip_charge);
8990
}
9091

9192
void HSolverLCAO::hamiltSolvePsiK(hamilt::Hamilt* hm, psi::Psi<std::complex<double>>& psi, double* eigenvalue)

source/module_hsolver/hsolver_lcao.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class HSolverLCAO : public HSolver
1717
void update(//Input &in
1818
) override;*/
1919

20-
void solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const bool skip_charge) override;
20+
void solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge) override;
2121

22-
void solve(hamilt::Hamilt* pHamilt, psi::Psi<double>& psi, elecstate::ElecState* pes, const bool skip_charge) override;
22+
void solve(hamilt::Hamilt* pHamilt, psi::Psi<double>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge) override;
2323

2424
static int out_mat_hs; // mohan add 2010-09-02
2525
static int out_mat_hsR; // LiuXh add 2019-07-16
@@ -28,7 +28,7 @@ class HSolverLCAO : public HSolver
2828
void hamiltSolvePsiK(hamilt::Hamilt* hm, psi::Psi<std::complex<double>>& psi, double* eigenvalue);
2929
void hamiltSolvePsiK(hamilt::Hamilt* hm, psi::Psi<double>& psi, double* eigenvalue);
3030

31-
template <typename T> void solveTemplate(hamilt::Hamilt* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, const bool skip_charge);
31+
template <typename T> void solveTemplate(hamilt::Hamilt* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge);
3232
/*void solveTemplate(
3333
hamilt::Hamilt* pHamilt,
3434
psi::Psi<std::complex<double>>& psi,

source/module_hsolver/hsolver_pw.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ void HSolverPW::update()
2020
return;
2121
}*/
2222

23-
void HSolverPW::solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const bool skip_charge)
23+
void HSolverPW::solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge)
2424
{
2525
// prepare for the precondition of diagonalization
2626
this->precondition.resize(psi.get_nbasis());
2727

2828
// select the method of diagonalization
29+
this->method = method_in;
2930
if (this->method == "cg")
3031
{
3132
if(pdiagh!=nullptr)

source/module_hsolver/hsolver_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HSolverPW : public HSolver
2424
void update(//Input &in
2525
) override;*/
2626

27-
void solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const bool skip_charge) override;
27+
void solve(hamilt::Hamilt* pHamilt, psi::Psi<std::complex<double>>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge) override;
2828

2929
private:
3030
void hamiltSolvePsiK(hamilt::Hamilt* hm, psi::Psi<std::complex<double>>& psi, double* eigenvalue);

source/src_pw/wavefunc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ psi::Psi<std::complex<double>>* wavefunc::allocate(const int nks)
114114
ModuleBase::Memory::record("wavefunc","wanf2",GlobalV::NLOCAL*(prefactor*npwx),"complexmatrix") << std::endl;
115115
}
116116
std::cout << " MEMORY FOR PSI (MB) : " <<
117-
ModuleBase::Memory::record("wavefunc","evc",GlobalV::NBANDS*(prefactor*npwx),"complexmatrix") << std::endl;
117+
ModuleBase::Memory::record("wavefunc","psi",GlobalV::NBANDS*(prefactor*npwx),"complexmatrix") << std::endl;
118118
}
119119
else if(GlobalV::BASIS_TYPE!="pw")
120120
{
@@ -141,7 +141,7 @@ psi::Psi<std::complex<double>>* wavefunc::allocate(const int nks)
141141
psi_out = new psi::Psi<std::complex<double>>(nks2, GlobalV::NBANDS, npwx * GlobalV::NPOL, GlobalC::kv.ngk.data());
142142

143143
std::cout << " MEMORY FOR PSI (MB) : " <<
144-
ModuleBase::Memory::record("wavefunc","evc",nks2*GlobalV::NBANDS*(prefactor*npwx),"complexmatrix") << std::endl;
144+
ModuleBase::Memory::record("wavefunc","psi",nks2*GlobalV::NBANDS*(prefactor*npwx),"complexmatrix") << std::endl;
145145
}
146146
return psi_out;
147147
}

0 commit comments

Comments
 (0)