Skip to content

Commit 8a60cd6

Browse files
committed
Merge branch 'develop' of github.com:deepmodeling/abacus-develop into develop
2 parents 4e728be + a261d7a commit 8a60cd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+769
-624
lines changed

source/module_elecstate/test/updaterhok_pw_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ TEST_F(EState,RhoPW)
299299
GlobalC::CHR.allocate(GlobalV::NSPIN, GlobalC::pw.nrxx, GlobalC::pw.ngmc);
300300
// GlobalC::pot.allocate(GlobalC::pw.nrxx);
301301
// we need to supply NBANDS here
302-
GlobalC::wf.allocate(GlobalC::kv.nks);
302+
psi::Psi<std::complex<double>>* psi = GlobalC::wf.allocate(GlobalC::kv.nks);
303303
// std::cout<<"npwx "<<GlobalC::wf.npwx<<std::endl;
304304
GlobalC::UFFT.allocate();
305305

306306
//====== read wavefunction ==========================================
307307
std::stringstream ssw;
308308
ssw <<GlobalV::global_out_dir<< "WAVEFUNC";
309309
// we need to supply out_wfc_pw here
310-
read_wfc2(ssw.str(), GlobalC::wf.psi[0], GlobalC::pw.gcar);
310+
read_wfc2(ssw.str(), psi[0], GlobalC::pw.gcar);
311311

312312
// copy data from old wf.evc to new evc(an object of Psi)
313313
evc.resize(GlobalC::kv.nks,GlobalV::NBANDS,GlobalC::wf.npwx);
@@ -316,9 +316,10 @@ TEST_F(EState,RhoPW)
316316
{
317317
for(int j=0;j<GlobalC::wf.npwx;j++)
318318
{
319-
evc(i,j)=GlobalC::wf.psi[0](i,j);
319+
evc(i,j) = psi[0](i,j);
320320
}
321321
}
322+
delete psi;
322323
// using class ElecStatePW to calculate rho
323324
elecstate::MockElecStatePW* kk;
324325
kk = new elecstate::MockElecStatePW(&GlobalC::pw,&GlobalC::CHR,GlobalV::NBANDS);

source/module_elecstate/test/updaterhok_pw_test.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,17 @@ void Use_FFT::allocate()
132132
return;
133133
}
134134

135-
void wavefunc::allocate(const int nks)
135+
psi::Psi<complex<double>>* wavefunc::allocate(const int nks)
136136
{
137137
this->npwx = GlobalC::pw.setupIndGk(this->igk, GlobalC::kv.ngk);
138138
this->wg.create(nks,GlobalV::NBANDS);
139139
this->ekb = new double*[nks];
140-
this->psi = new psi::Psi<std::complex<double>>(nks, GlobalV::NBANDS,npwx, nullptr);
140+
psi::Psi<std::complex<double>>* psi = new psi::Psi<std::complex<double>>(nks, GlobalV::NBANDS,npwx, nullptr);
141141
for (int ik=0;ik<nks;ik++)
142142
{
143143
this->ekb[ik] = new double[GlobalV::NBANDS];
144144
}
145-
return;
145+
return psi;
146146
}
147147

148148
bool Charge::read_rho(const int &is, const std::string &fn, double* rho) //add by dwan

source/module_esolver/esolver.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "../module_cell/unitcell_pseudo.h"
66
#include "../src_pw/energy.h"
77
#include "../module_base/matrix.h"
8+
//--------------temporary----------------------------
9+
#include "module_psi/psi.h"
810

911
namespace ModuleESolver
1012
{
@@ -16,7 +18,15 @@ namespace ModuleESolver
1618
ESolver() {
1719
classname = "ESolver";
1820
}
19-
virtual ~ESolver() {};
21+
22+
virtual ~ESolver()
23+
{
24+
//--------------temporary----------------------------
25+
if(this->psi != nullptr)
26+
{
27+
delete psi;
28+
}
29+
}
2030

2131
//virtual void Init(Input_EnSolver &inp, matrix &lattice_v)=0
2232
virtual void Init(Input& inp, UnitCell_pseudo& cell) = 0;
@@ -44,6 +54,13 @@ namespace ModuleESolver
4454
//get iterstep used in current scf
4555
virtual int getniter() { return 0; }
4656
string classname;
57+
58+
//--------------temporary----------------------------
59+
// this is the interface of non-self-consistant calculation
60+
virtual void nscf() {};
61+
62+
//wavefunction coefficients
63+
psi::Psi<std::complex<double>>* psi=nullptr;
4764
};
4865

4966
void init_esolver(ESolver*& p_esolver, const string use_esol);

source/module_esolver/esolver_ks.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ namespace ModuleESolver
2828

2929
// calculate electron density from a specific Hamiltonian
3030
virtual void hamilt2density(const int istep, const int iter, const double ethr);
31-
// get
31+
32+
// calculate electron states from a specific Hamiltonian
33+
virtual void hamilt2estates(const double ethr){};
34+
35+
// get current step of Ionic simulation
3236
virtual int getniter() override;
3337

3438
protected:

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#endif
2727
#include "../src_pw/H_Ewald_pw.h"
2828

29+
#include "module_hamilt/hamilt_lcao.h"
30+
#include "module_elecstate/elecstate_lcao.h"
31+
#include "module_hsolver/hsolver_lcao.h"
32+
2933
namespace ModuleESolver
3034
{
3135

@@ -188,6 +192,75 @@ namespace ModuleESolver
188192
srho.begin(is, GlobalC::CHR, GlobalC::pw, GlobalC::Pgrid, GlobalC::symm);
189193
}
190194

195+
//init Psi, HSolver, ElecState, Hamilt
196+
if(this->phsol != nullptr)
197+
{
198+
if(this->phsol->classname != "HSolverLCAO")
199+
{
200+
delete this->phsol;
201+
this->phsol = nullptr;
202+
}
203+
}
204+
else
205+
{
206+
this->phsol = new hsolver::HSolverLCAO();
207+
this->phsol->method = GlobalV::KS_SOLVER;
208+
}
209+
if(this->pelec != nullptr)
210+
{
211+
if(this->pelec->classname != "ElecStateLCAO")
212+
{
213+
delete this->pelec;
214+
this->pelec = nullptr;
215+
}
216+
}
217+
else
218+
{
219+
this->pelec = new elecstate::ElecStateLCAO(
220+
(Charge*)(&(GlobalC::CHR)),
221+
&(GlobalC::kv),
222+
GlobalC::kv.nks,
223+
GlobalV::NBANDS,
224+
&(this->LOC),
225+
&(this->UHM),
226+
&(this->LOWF));
227+
}
228+
if(this->phami != nullptr)
229+
{
230+
if(this->phami->classname != "HamiltLCAO")
231+
{
232+
delete this->phami;
233+
this->phami = nullptr;
234+
}
235+
}
236+
else
237+
{
238+
// three cases for hamilt class
239+
if(GlobalV::GAMMA_ONLY_LOCAL)
240+
{
241+
this->phami = new hamilt::HamiltLCAO<double, double>(
242+
&(this->UHM.GG),
243+
&(this->UHM.genH),
244+
&(this->LM) );
245+
}
246+
// non-collinear spin case would not use the second template now,
247+
// would add this feature in the future
248+
/*else if(GlobalV::NSPIN==4)
249+
{
250+
this->phami = new hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>(
251+
&(this->UHM.GK),
252+
&(this->UHM.genH),
253+
&(this->LM) );
254+
}*/
255+
else
256+
{
257+
this->phami = new hamilt::HamiltLCAO<std::complex<double>, double>(
258+
&(this->UHM.GK),
259+
&(this->UHM.genH),
260+
&(this->LM) );
261+
}
262+
}
263+
191264
ModuleBase::timer::tick("ESolver_KS_LCAO", "beforescf");
192265
return;
193266
}

0 commit comments

Comments
 (0)