Skip to content

Commit 1a49431

Browse files
authored
Delete update_pot() in ESolver (#6614)
* add update_pot in source_estate * split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter * fix bugs * update
1 parent 6f277a7 commit 1a49431

File tree

13 files changed

+58
-47
lines changed

13 files changed

+58
-47
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ OBJS_ELECSTAT=elecstate.o\
250250
read_pseudo.o\
251251
cal_wfc.o\
252252
setup_estate_pw.o\
253+
update_pot.o\
253254

254255
OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
255256
elecstate_lcao_cal_tau.o\

source/source_esolver/esolver_ks.cpp

Lines changed: 3 additions & 2 deletions
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, this->pelec, this->chr, 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;
@@ -432,7 +433,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
432433
#endif
433434

434435
// 4) Update potentials (should be done every SF iter)
435-
this->update_pot(ucell, istep, iter, conv_esolver);
436+
elecstate::update_pot(ucell, this->pelec, this->chr, conv_esolver);
436437

437438
// 5) calculate energies
438439
// 1 means Harris-Foulkes functional

source/source_esolver/esolver_ks.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class ESolver_KS : public ESolver_FP
4646
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
4747
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
4848

49-
//! <Temporary> It should be replaced by a function in Hamilt Class
50-
virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver){};
51-
5249
//! Hamiltonian
5350
hamilt::Hamilt<T, Device>* p_hamilt = nullptr;
5451

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_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>
5252

5353
virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override;
5454

55-
virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver) override;
56-
5755
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override;
5856

5957
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,19 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
337337
}
338338

339339
ESolver_KS_LCAO<std::complex<double>, TR>::iter_finish(ucell, istep, iter, conv_esolver);
340+
341+
this->save2(ucell, istep, iter, conv_esolver);
342+
340343
}
341344

342345
template <typename TR, typename Device>
343-
void ESolver_KS_LCAO_TDDFT<TR, Device>::update_pot(UnitCell& ucell,
346+
void ESolver_KS_LCAO_TDDFT<TR, Device>::save2(UnitCell& ucell,
344347
const int istep,
345348
const int iter,
346349
const bool conv_esolver)
347350
{
348351
// Calculate new potential according to new Charge Density
352+
/*
349353
if (!conv_esolver)
350354
{
351355
elecstate::cal_ux(ucell);
@@ -356,6 +360,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::update_pot(UnitCell& ucell,
356360
{
357361
this->pelec->cal_converged();
358362
}
363+
*/
359364

360365
const int nloc = this->pv.nloc;
361366
const int ncol_nbands = this->pv.ncol_bands;

source/source_esolver/esolver_ks_lcao_tddft.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, TR>
6464

6565
virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override;
6666

67-
virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver) override;
67+
// mohan change update_pot to save2, 2025-10-17
68+
void save2(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver);
6869

6970
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override;
7071

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 3 additions & 20 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,8 +326,8 @@ 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);
347-
exx_helper.iter_inc();
329+
elecstate::update_pot(ucell, this->pelec, this->chr, conv_esolver);
330+
exx_helper.iter_inc();
348331
}
349332
}
350333
}

source/source_esolver/esolver_ks_pw.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
4141

4242
virtual void iter_init(UnitCell& ucell, const int istep, const int iter) override;
4343

44-
virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver) override;
45-
4644
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override;
4745

4846
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;

source/source_esolver/rho_restart.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "rho_restart.h"
22

3+
/*
34
void ModuleESolver::rho_restart(const Input_para& inp,
45
const UnitCell& ucell,
56
const elecstate::ElecState& elec,
@@ -145,3 +146,4 @@ void ModuleESolver::rho_restart(const Input_para& inp,
145146
#endif
146147
147148
}
149+
*/

0 commit comments

Comments
 (0)