Skip to content

Commit 445c55f

Browse files
kluonjuCopilotmohanchen
authored
Electrostatic correction of Makov-Payne type (#7354)
* Rename Makov-Payne energy term * Fix elecstate energy unit test link dependencies * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
1 parent e518b3f commit 445c55f

11 files changed

Lines changed: 464 additions & 5 deletions

File tree

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ OBJS_ELECSTAT=elecstate.o\
234234
elecstate_pw.o\
235235
elecstate_pw_sdft.o\
236236
elecstate_pw_cal_tau.o\
237+
makov_payne.o\
237238
elecstate_op.o\
238239
efield.o\
239240
gatefield.o\

source/source_estate/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ list(APPEND objects
99
elecstate_pw.cpp
1010
elecstate_pw_sdft.cpp
1111
elecstate_pw_cal_tau.cpp
12+
makov_payne.cpp
1213
module_pot/gatefield.cpp
1314
module_pot/efield.cpp
1415
module_pot/H_Hartree_pw.cpp

source/source_estate/elecstate_energy.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include "source_base/global_variable.h"
33
#include "source_base/parallel_comm.h"
44
#include "source_base/parallel_reduce.h"
5+
#include "makov_payne.h"
56
#include "source_hamilt/module_xc/xc_functional.h"
7+
#include "source_estate/module_pot/H_Hartree_pw.h"
68
#include "source_io/module_parameter/parameter.h"
79

810
#include <cmath>
@@ -340,6 +342,34 @@ void ElecState::cal_energies(const int type)
340342

341343
this->f_en.e_local_pp = get_local_pp_energy();
342344

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+
343373
#ifdef __MLALGO
344374
this->f_en.ml_exx = this->pot->get_ml_exx_energy();
345375
#endif

source/source_estate/fp_energy.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ namespace elecstate
1616
double fenergy::calculate_etot()
1717
{
1818
etot = eband + deband + (etxc - etxcc) + ewald_energy + hartree_energy + demet + descf + exx + efield
19-
+ gatefield + evdw + esol_el + esol_cav + edftu + edeepks_scf + escon + ml_exx;
19+
+ gatefield + evdw + correction_el + esol_el + esol_cav + edftu + edeepks_scf + escon + ml_exx;
2020
return etot;
2121
}
2222

2323
/// @brief calculate etot_harris
2424
double fenergy::calculate_harris()
2525
{
2626
etot_harris = eband + deband_harris + (etxc - etxcc) + ewald_energy + hartree_energy + demet + descf + exx
27-
+ efield + gatefield + evdw + esol_el + esol_cav + edftu + edeepks_scf + escon + ml_exx;
27+
+ efield + gatefield + evdw + correction_el + esol_el + esol_cav + edftu + edeepks_scf + escon + ml_exx;
2828
return etot_harris;
2929
}
3030

3131
/// @brief set all energies to zero
3232
void fenergy::clear_all()
3333
{
3434
etot = etot_old = eband = deband = etxc = etxcc = vtxc = ewald_energy = hartree_energy = demet = descf = exx
35-
= efield = gatefield = evdw = etot_harris = deband_harris = esol_el = esol_cav = edftu = edeepks_scf = escon
35+
= efield = gatefield = evdw = correction_el = etot_harris = deband_harris = esol_el = esol_cav = edftu = edeepks_scf = escon
3636
= ml_exx = 0.0;
3737
}
3838

@@ -53,6 +53,7 @@ void fenergy::print_all() const
5353
std::cout << " efiled=" << efield << std::endl;
5454
std::cout << " gatefiled=" << gatefield << std::endl;
5555
std::cout << " evdw=" << evdw << std::endl;
56+
std::cout << " correction_el=" << correction_el << std::endl;
5657
std::cout << " esol_el=" << esol_el << std::endl;
5758
std::cout << " esol_cav=" << esol_cav << std::endl;
5859
std::cout << " edftu=" << edftu << std::endl;

source/source_estate/fp_energy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct fenergy
3434
double efield = 0.0; ///< dipole potential in surface calculations
3535
double gatefield = 0.0; ///< correction energy for gatefield
3636
double evdw = 0.0; ///< the vdw energy
37+
double correction_el = 0.0; ///< electrostatic isolated-cell correction
3738

3839
double etot_harris = 0.0; ///< total energy of harris functional
3940
double deband_harris = 0.0; ///< correction for harris energy

0 commit comments

Comments
 (0)