Skip to content

Commit 242184c

Browse files
committed
add update_pot in source_estate
1 parent 6f277a7 commit 242184c

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

source/source_esolver/esolver_ks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "source_io/json_output/init_info.h"
2424
#include "source_io/json_output/output_info.h"
2525

26+
#include "source_estate/update_pot.h" // mohan add 20251016
2627

2728
namespace ModuleESolver
2829
{
@@ -374,7 +375,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
374375
if (this->scf_ene_thr > 0.0)
375376
{
376377
// calculate energy of output charge density
377-
this->update_pot(ucell, istep, iter, conv_esolver);
378+
elecstate::update_pot(ucell, istep, iter, conv_esolver);
378379
this->pelec->cal_energies(2); // 2 means Kohn-Sham functional
379380
// now, etot_old is the energy of input density, while etot is the energy of output density
380381
this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old;

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,6 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
446446
this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell);
447447
}
448448

449-
template <typename TK, typename TR>
450-
void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
451-
{
452-
ModuleBase::TITLE("ESolver_KS_LCAO", "update_pot");
453-
454-
if (!conv_esolver)
455-
{
456-
elecstate::cal_ux(ucell);
457-
this->pelec->pot->update_from_charge(&this->chr, &ucell);
458-
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
459-
}
460-
else
461-
{
462-
this->pelec->cal_converged();
463-
}
464-
}
465449

466450
template <typename TK, typename TR>
467451
void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "source_estate/setup_estate_pw.h" // mohan add 20251005
2929
#include "source_io/ctrl_output_pw.h" // mohan add 20250927
3030
#include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
31+
#include "source_estate/update_pot.h" // mohan add 20251016
3132

3233
namespace ModuleESolver
3334
{
@@ -268,24 +269,6 @@ void ESolver_KS_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, const int iste
268269
ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2rho_single");
269270
}
270271

271-
// Temporary, it should be rewritten with Hamilt class.
272-
template <typename T, typename Device>
273-
void ESolver_KS_PW<T, Device>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
274-
{
275-
if (!conv_esolver)
276-
{
277-
elecstate::cal_ux(ucell);
278-
this->pelec->pot->update_from_charge(&this->chr, &ucell);
279-
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
280-
#ifdef __MPI
281-
MPI_Bcast(&(this->pelec->f_en.descf), 1, MPI_DOUBLE, 0, BP_WORLD);
282-
#endif
283-
}
284-
else
285-
{
286-
this->pelec->cal_converged();
287-
}
288-
}
289272

290273
template <typename T, typename Device>
291274
void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)
@@ -343,7 +326,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
343326
<< std::endl;
344327
exx_helper.op_exx->first_iter = false;
345328
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
346-
update_pot(ucell, istep, iter, conv_esolver);
329+
elecstate::update_pot(ucell, istep, iter, conv_esolver);
347330
exx_helper.iter_inc();
348331
}
349332
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "source_estate/update_pot.h"
2+
3+
void elecstate::update_pot(UnitCell& ucell, // unitcell
4+
elecstate::ElecState* &pelec, // pointer of electrons
5+
Charge &chr) // charge density
6+
{
7+
if (!conv_esolver)
8+
{
9+
elecstate::cal_ux(ucell);
10+
pelec->pot->update_from_charge(&chr, &ucell);
11+
pelec->f_en.descf = pelec->cal_delta_escf();
12+
#ifdef __MPI
13+
MPI_Bcast(&(pelec->f_en.descf), 1, MPI_DOUBLE, 0, BP_WORLD);
14+
#endif
15+
}
16+
else
17+
{
18+
pelec->cal_converged();
19+
}
20+
}

source/source_estate/update_pot.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef UPDATE_POT_H
2+
#define UPDATE_POT_H
3+
4+
#include "source_cell/unitcell.h"
5+
#include "source_estate/elecstate.h"
6+
7+
namespace elecstate
8+
{
9+
10+
void update_pot(UnitCell& ucell, // unitcell
11+
elecstate::ElecState* &pelec, // pointer of electrons
12+
Charge &chr); // charge density
13+
}
14+
15+
16+
#endif

0 commit comments

Comments
 (0)