Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ OBJS_ELECSTAT=elecstate.o\
read_pseudo.o\
cal_wfc.o\
setup_estate_pw.o\
update_pot.o\

OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
elecstate_lcao_cal_tau.o\
Expand Down
5 changes: 3 additions & 2 deletions source/source_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "source_io/json_output/init_info.h"
#include "source_io/json_output/output_info.h"

#include "source_estate/update_pot.h" // mohan add 20251016

namespace ModuleESolver
{
Expand Down Expand Up @@ -374,7 +375,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
if (this->scf_ene_thr > 0.0)
{
// calculate energy of output charge density
this->update_pot(ucell, istep, iter, conv_esolver);
elecstate::update_pot(ucell, this->pelec, this->chr, conv_esolver);
this->pelec->cal_energies(2); // 2 means Kohn-Sham functional
// now, etot_old is the energy of input density, while etot is the energy of output density
this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old;
Expand Down Expand Up @@ -432,7 +433,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
#endif

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

// 5) calculate energies
// 1 means Harris-Foulkes functional
Expand Down
3 changes: 0 additions & 3 deletions source/source_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class ESolver_KS : public ESolver_FP
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;

//! <Temporary> It should be replaced by a function in Hamilt Class
virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver){};

//! Hamiltonian
hamilt::Hamilt<T, Device>* p_hamilt = nullptr;

Expand Down
16 changes: 0 additions & 16 deletions source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,6 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell);
}

template <typename TK, typename TR>
void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "update_pot");

if (!conv_esolver)
{
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(&this->chr, &ucell);
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
}
else
{
this->pelec->cal_converged();
}
}

template <typename TK, typename TR>
void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)
Expand Down
2 changes: 0 additions & 2 deletions source/source_esolver/esolver_ks_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>

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

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

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

virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
Expand Down
6 changes: 5 additions & 1 deletion source/source_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,19 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
GlobalV::ofs_running << std::endl;
}

this->save2(ucell, istep, iter, conv_esolver);

ESolver_KS_LCAO<std::complex<double>, TR>::iter_finish(ucell, istep, iter, conv_esolver);
}

template <typename TR, typename Device>
void ESolver_KS_LCAO_TDDFT<TR, Device>::update_pot(UnitCell& ucell,
void ESolver_KS_LCAO_TDDFT<TR, Device>::save2(UnitCell& ucell,
const int istep,
const int iter,
const bool conv_esolver)
{
// Calculate new potential according to new Charge Density
/*
if (!conv_esolver)
{
elecstate::cal_ux(ucell);
Expand All @@ -356,6 +359,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::update_pot(UnitCell& ucell,
{
this->pelec->cal_converged();
}
*/

const int nloc = this->pv.nloc;
const int ncol_nbands = this->pv.ncol_bands;
Expand Down
3 changes: 2 additions & 1 deletion source/source_esolver/esolver_ks_lcao_tddft.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, TR>

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

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

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

Expand Down
23 changes: 3 additions & 20 deletions source/source_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "source_estate/setup_estate_pw.h" // mohan add 20251005
#include "source_io/ctrl_output_pw.h" // mohan add 20250927
#include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
#include "source_estate/update_pot.h" // mohan add 20251016

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

// Temporary, it should be rewritten with Hamilt class.
template <typename T, typename Device>
void ESolver_KS_PW<T, Device>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
{
if (!conv_esolver)
{
elecstate::cal_ux(ucell);
this->pelec->pot->update_from_charge(&this->chr, &ucell);
this->pelec->f_en.descf = this->pelec->cal_delta_escf();
#ifdef __MPI
MPI_Bcast(&(this->pelec->f_en.descf), 1, MPI_DOUBLE, 0, BP_WORLD);
#endif
}
else
{
this->pelec->cal_converged();
}
}

template <typename T, typename Device>
void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)
Expand Down Expand Up @@ -343,8 +326,8 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
<< std::endl;
exx_helper.op_exx->first_iter = false;
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
update_pot(ucell, istep, iter, conv_esolver);
exx_helper.iter_inc();
elecstate::update_pot(ucell, this->pelec, this->chr, conv_esolver);
exx_helper.iter_inc();
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions source/source_esolver/esolver_ks_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>

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

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

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

virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
Expand Down
2 changes: 2 additions & 0 deletions source/source_esolver/rho_restart.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "rho_restart.h"

/*
void ModuleESolver::rho_restart(const Input_para& inp,
const UnitCell& ucell,
const elecstate::ElecState& elec,
Expand Down Expand Up @@ -145,3 +146,4 @@ void ModuleESolver::rho_restart(const Input_para& inp,
#endif
}
*/
1 change: 1 addition & 0 deletions source/source_estate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ list(APPEND objects
read_pseudo.cpp
cal_wfc.cpp
setup_estate_pw.cpp
update_pot.cpp
)

if(ENABLE_LCAO)
Expand Down
23 changes: 23 additions & 0 deletions source/source_estate/update_pot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "source_estate/update_pot.h"
#include "source_estate/cal_ux.h"

void elecstate::update_pot(UnitCell& ucell, // unitcell
elecstate::ElecState* &pelec, // pointer of electrons
const Charge &chr,
const bool conv_esolver
) // charge density
{
if (!conv_esolver)
{
elecstate::cal_ux(ucell);
pelec->pot->update_from_charge(&chr, &ucell);
pelec->f_en.descf = pelec->cal_delta_escf();
#ifdef __MPI
MPI_Bcast(&(pelec->f_en.descf), 1, MPI_DOUBLE, 0, BP_WORLD);
#endif
}
else
{
pelec->cal_converged();
}
}
17 changes: 17 additions & 0 deletions source/source_estate/update_pot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef UPDATE_POT_H
#define UPDATE_POT_H

#include "source_cell/unitcell.h"
#include "source_estate/elecstate.h"

namespace elecstate
{

void update_pot(UnitCell& ucell, // unitcell
elecstate::ElecState* &pelec, // pointer of electrons
const Charge &chr,
const bool conv_esolver); // charge density
}


#endif
Loading