|
26 | 26 | //-----stress------------------ |
27 | 27 | #include "../src_pw/stress_pw.h" |
28 | 28 | //--------------------------------------------------- |
| 29 | +#include "module_hsolver/hsolver_pw.h" |
| 30 | +#include "module_elecstate/elecstate_pw.h" |
| 31 | +#include "module_hamilt/hamilt_pw.h" |
| 32 | +#include "module_hsolver/diago_iter_assist.h" |
29 | 33 |
|
30 | 34 | namespace ModuleESolver |
31 | 35 | { |
@@ -190,6 +194,41 @@ void ESolver_KS_PW:: beforescf() |
190 | 194 | { |
191 | 195 | srho.begin(is, GlobalC::CHR,GlobalC::pw, GlobalC::Pgrid, GlobalC::symm); |
192 | 196 | } |
| 197 | + //init Psi, HSolver, ElecState, Hamilt |
| 198 | + hsolver::DiagoIterAssist::PW_DIAG_NMAX = GlobalV::PW_DIAG_NMAX; |
| 199 | + hsolver::DiagoIterAssist::PW_DIAG_THR = GlobalV::PW_DIAG_THR; |
| 200 | + const PW_Basis* pbas = &(GlobalC::pw); |
| 201 | + if(this->phsol == nullptr) |
| 202 | + { |
| 203 | + this->phsol = new hsolver::HSolverPW(pbas); |
| 204 | + } |
| 205 | + else if(this->phsol->classname != "HSolverPW") |
| 206 | + { |
| 207 | + delete[] this->phsol; |
| 208 | + this->phsol = new hsolver::HSolverPW(pbas); |
| 209 | + } |
| 210 | + this->phsol->method = GlobalV::KS_SOLVER; |
| 211 | + if(this->pelec == nullptr) |
| 212 | + { |
| 213 | + this->pelec = new elecstate::ElecStatePW( pbas, (Charge*)(&(GlobalC::CHR)), GlobalV::NBANDS); |
| 214 | + } |
| 215 | + else if(this->pelec->classname != "ElecStatePW") |
| 216 | + { |
| 217 | + delete[] this->pelec; |
| 218 | + this->pelec = new elecstate::ElecStatePW( pbas, (Charge*)(&(GlobalC::CHR)), GlobalV::NBANDS); |
| 219 | + } |
| 220 | + Hamilt_PW* hpw = &(GlobalC::hm.hpw); |
| 221 | + if(this->phami == nullptr) |
| 222 | + { |
| 223 | + this->phami = new hamilt::HamiltPW(hpw); |
| 224 | + } |
| 225 | + else if(this->phami->classname != "HamiltPW") |
| 226 | + { |
| 227 | + delete[] this->phami; |
| 228 | + this->phami = new hamilt::HamiltPW(hpw); |
| 229 | + } |
| 230 | + //initial psi |
| 231 | + GlobalC::wf.evc_transform_psi(); |
193 | 232 | } |
194 | 233 |
|
195 | 234 | void ESolver_KS_PW:: eachiterinit(const int iter) |
@@ -217,22 +256,37 @@ void ESolver_KS_PW:: eachiterinit(const int iter) |
217 | 256 | //Temporary, it should be replaced by hsolver later. |
218 | 257 | void ESolver_KS_PW:: hamilt2density(const int istep, const int iter, const double ethr) |
219 | 258 | { |
220 | | - GlobalV::PW_DIAG_THR = ethr; |
221 | | - this->c_bands(istep,iter); |
222 | | - |
223 | | - GlobalC::en.eband = 0.0; |
224 | | - GlobalC::en.demet = 0.0; |
225 | | - GlobalC::en.ef = 0.0; |
226 | | - GlobalC::en.ef_up = 0.0; |
227 | | - GlobalC::en.ef_dw = 0.0; |
| 259 | + if(this->phsol != nullptr) |
| 260 | + { |
| 261 | + // reset energy |
| 262 | + this->pelec->eband = 0.0; |
| 263 | + this->pelec->demet = 0.0; |
| 264 | + this->pelec->ef = 0.0; |
| 265 | + GlobalC::en.ef_up = 0.0; |
| 266 | + GlobalC::en.ef_dw = 0.0; |
| 267 | + // choose if psi should be diag in subspace |
| 268 | + // be careful that istep start from 0 and iter start from 1 |
| 269 | + if((istep==0||istep==1)&&iter==1) |
| 270 | + { |
| 271 | + hsolver::DiagoIterAssist::need_subspace = false; |
| 272 | + } |
| 273 | + else |
| 274 | + { |
| 275 | + hsolver::DiagoIterAssist::need_subspace = true; |
| 276 | + } |
228 | 277 |
|
229 | | - // calculate weights of each band. |
230 | | - Occupy::calculate_weights(); |
| 278 | + hsolver::DiagoIterAssist::PW_DIAG_THR = ethr; |
| 279 | + this->phsol->solve(this->phami, GlobalC::wf.psi[0], this->pelec); |
231 | 280 |
|
232 | | - // calculate new charge density according to |
233 | | - // new wave functions. |
234 | | - // calculate the new eband here. |
235 | | - GlobalC::CHR.sum_band(); |
| 281 | + // transform energy for print |
| 282 | + GlobalC::en.eband = this->pelec->eband; |
| 283 | + GlobalC::en.demet = this->pelec->demet; |
| 284 | + GlobalC::en.ef = this->pelec->ef; |
| 285 | + } |
| 286 | + else |
| 287 | + { |
| 288 | + ModuleBase::WARNING_QUIT("ESolver_KS_PW", "HSolver has not been initialed!"); |
| 289 | + } |
236 | 290 |
|
237 | 291 | // add exx |
238 | 292 | #ifdef __LCAO |
@@ -350,6 +404,17 @@ void ESolver_KS_PW:: eachiterfinish(const int iter, const bool conv_elec) |
350 | 404 |
|
351 | 405 | void ESolver_KS_PW::afterscf(const bool conv_elec) |
352 | 406 | { |
| 407 | + //temporary transform psi to evc |
| 408 | + // psi back to evc |
| 409 | + GlobalC::wf.psi_transform_evc(); |
| 410 | + for(int ik=0; ik<this->pelec->ekb.nr; ++ik) |
| 411 | + { |
| 412 | + for(int ib=0; ib<this->pelec->ekb.nc; ++ib) |
| 413 | + { |
| 414 | + GlobalC::wf.ekb[ik][ib] = this->pelec->ekb(ik, ib); |
| 415 | + GlobalC::wf.wg(ik, ib) = this->pelec->wg(ik, ib); |
| 416 | + } |
| 417 | + } |
353 | 418 | #ifdef __LCAO |
354 | 419 | if(GlobalC::chi0_hilbert.epsilon) // pengfei 2016-11-23 |
355 | 420 | { |
|
0 commit comments