|
2 | 2 | #include "source_base/global_variable.h" |
3 | 3 | #include "source_base/parallel_comm.h" |
4 | 4 | #include "source_base/parallel_reduce.h" |
| 5 | +#include "makov_payne.h" |
5 | 6 | #include "source_hamilt/module_xc/xc_functional.h" |
| 7 | +#include "source_estate/module_pot/H_Hartree_pw.h" |
6 | 8 | #include "source_io/module_parameter/parameter.h" |
7 | 9 |
|
8 | 10 | #include <cmath> |
@@ -340,6 +342,34 @@ void ElecState::cal_energies(const int type) |
340 | 342 |
|
341 | 343 | this->f_en.e_local_pp = get_local_pp_energy(); |
342 | 344 |
|
| 345 | + if (PARAM.inp.assume_isolated == "makov-payne") |
| 346 | + { |
| 347 | + const UnitCell* ucell = this->pot->get_ucell(); |
| 348 | + if (ucell == nullptr || this->charge == nullptr || this->charge->rhopw == nullptr) |
| 349 | + { |
| 350 | + ModuleBase::WARNING_QUIT("ElecState::cal_energies", |
| 351 | + "Makov-Payne correction requires an initialized unit cell and charge density."); |
| 352 | + } |
| 353 | + std::vector<double> v_elecstat; |
| 354 | + const double* v_elecstat_ptr = nullptr; |
| 355 | + { |
| 356 | + ModuleBase::matrix vh(PARAM.inp.nspin, this->charge->rhopw->nrxx); |
| 357 | + vh = elecstate::H_Hartree_pw::v_hartree(*ucell, this->charge->rhopw, PARAM.inp.nspin, this->charge->rho); |
| 358 | + v_elecstat.assign(this->charge->rhopw->nrxx, 0.0); |
| 359 | + const double* v_fixed = this->pot->get_fixed_v(); |
| 360 | + for (int ir = 0; ir < this->charge->rhopw->nrxx; ++ir) |
| 361 | + { |
| 362 | + v_elecstat[ir] = vh(0, ir) + v_fixed[ir]; |
| 363 | + } |
| 364 | + v_elecstat_ptr = v_elecstat.data(); |
| 365 | + } |
| 366 | + this->f_en.correction_el = makov_payne_correction(*ucell, *this->charge, v_elecstat_ptr).total; |
| 367 | + } |
| 368 | + else |
| 369 | + { |
| 370 | + this->f_en.correction_el = 0.0; |
| 371 | + } |
| 372 | + |
343 | 373 | #ifdef __MLALGO |
344 | 374 | this->f_en.ml_exx = this->pot->get_ml_exx_energy(); |
345 | 375 | #endif |
|
0 commit comments