ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
ModuleESolver::ESolver_KS Class Reference

#include <esolver_ks.h>

Inheritance diagram for ModuleESolver::ESolver_KS:
Collaboration diagram for ModuleESolver::ESolver_KS:

Public Member Functions

 ESolver_KS ()
 Constructor.
virtual ~ESolver_KS ()
 Deconstructor.
virtual void before_all_runners (BaseCell &basecell, const Input_para &inp) override
 Initialize of the first-principels energy solver.
virtual void runner (BaseCell &basecell, const int istep) override
 run energy solver
virtual void after_all_runners (BaseCell &basecell) override
 perform post processing calculations
Public Member Functions inherited from ModuleESolver::ESolver_FP
 ESolver_FP ()
virtual ~ESolver_FP ()
Public Member Functions inherited from ModuleESolver::ESolver
 ESolver ()
virtual ~ESolver ()
virtual void others (BaseCell &, const int)
virtual double cal_energy ()=0
 calculate total energy of a given system
virtual void cal_force (BaseCell &cell, ModuleBase::matrix &force)=0
 calcualte forces for the atoms in the given cell
virtual void cal_stress (BaseCell &cell, ModuleBase::matrix &stress)=0
 calcualte stress of given cell

Protected Types

enum class  DensityStage { standard , predictor }
 Select whether the density is an endpoint predictor or an SCF iterate. More...

Protected Member Functions

virtual int scf_iter_limit (const int istep) const
 Maximum SCF iterations for the current electronic step.
bool scf_loop (UnitCell &ucell, int istep, int iter_limit)
 Run SCF iterations without preparing or committing a physical endpoint.
void record_iteration (const UnitCell &ucell, double duration)
 Record an accepted iteration in JSON without changing its convergence status.
void write_iter_bands ()
 Write current band expectations when iterative band output is requested.
virtual DensityStage density_stage (const int istep, const int iter) const
 Identify mandatory predictor stages before mixing and convergence checks.
virtual void before_scf (UnitCell &ucell, const int istep) override
 Something to do before SCF iterations.
virtual void iter_init (UnitCell &ucell, const int istep, const int iter)
 Something to do before hamilt2rho function in each iter loop.
virtual bool defer_iter_output (const int istep) const
 Whether KS iterations defer output until the final state is accepted.
virtual void iter_finish (UnitCell &ucell, const int istep, int &iter, bool &conv_esolver) override
 Something to do after hamilt2rho function in each iter loop.
virtual void hamilt2rho_single (UnitCell &ucell, const int istep, const int iter, const double ethr)
void hamilt2rho (UnitCell &ucell, const int istep, const int iter, const double ethr)
virtual std::string diag_policy (const int istep) const
 Select the diagonalization threshold and error-control policy for the current stage.
virtual void after_scf (UnitCell &ucell, const int istep, const bool conv_esolver) override
 Something to do after SCF iterations when SCF is converged or comes to the max iter step.
Protected Member Functions inherited from ModuleESolver::ESolver_FP
const vdw::VdwResult * get_vdw_result () const

Protected Attributes

hamilt::HamiltBase * p_hamilt = nullptr
 Hamiltonian (base class pointer, actual type determined at runtime).
ModulePW::PW_Basis_K * pw_wfc = nullptr
 PW for wave functions, only used in KSDFT, not in OFDFT.
Charge_Mixing * p_chgmix = nullptr
 Charge mixing method.
pseudopot_cell_vnl ppcell
 nonlocal pseudopotentials
std::unique_ptr< Plus_U_Base > dftu_
std::string basisname
double esolver_KS_ne = 0.0
 esolver_ks_lcao.cpp
double diag_ethr
 number of electrons
double scf_thr
 the threshold for diagonalization
double scf_ene_thr
 scf density threshold
double drho
 scf energy threshold
double hsolver_error
 the difference between rho_in (before HSolver) and rho_out (After HSolver)
double ds_rms_ = -1.0
int maxniter
int niter
 maximum iter steps for scf
bool oscillate_esolver = false
 iter steps actually used in scf
bool scf_nmax_flag = false
bool scf_rerun_ = false
General_Exx_Info general_exx_info_
 General EXX info owned by ESolver, initialized from input parameters.
Protected Attributes inherited from ModuleESolver::ESolver_FP
std::unique_ptr< const vdw::VdwResult > vdw_result_
 vdW correction evaluated once for the current ionic configuration.
elecstate::ElecState * pelec = nullptr
 These pointers will be deleted in the free_pointers() function every ion step.
K_Vectors kv
 K points in Brillouin zone.
Charge chr
 Electorn charge density.
ModulePW::PW_Basis * pw_rho = nullptr
ModulePW::PW_Basis * pw_rhod = nullptr
ModulePW::PW_Basis_Big * pw_big = nullptr
 dense grid for USPP
Parallel_Grid Pgrid
 parallel for rho grid
Structure_Factor sf
 Structure factors that used with plane-wave basis set.
pseudopot_cell_vl locpp
 local pseudopotentials
module_charge::Charge_Extra CE
 charge extrapolation method
surchem solvent
 solvent model
bool pw_rho_flag = false
 flag for pw_rho, 0: not initialized, 1: initialized
ModuleBase::TimePoint iter_time
 the start time of scf iteration
Protected Attributes inherited from ModuleESolver::ESolver
const Input_para * inp_ = nullptr
 Bound in before_all_runners; members use inp_->xxx instead of PARAM.inp.xxx.

Additional Inherited Members

Public Attributes inherited from ModuleESolver::ESolver
bool conv_esolver = true
std::string classname

Member Enumeration Documentation

◆ DensityStage

enum class ModuleESolver::ESolver_KS::DensityStage
strongprotected

Select whether the density is an endpoint predictor or an SCF iterate.

Enumerator
standard 
predictor 

Constructor & Destructor Documentation

◆ ESolver_KS()

ModuleESolver::ESolver_KS::ESolver_KS ( )

Constructor.

◆ ~ESolver_KS()

ModuleESolver::ESolver_KS::~ESolver_KS ( )
virtual

Deconstructor.

Here is the call graph for this function:

Member Function Documentation

◆ after_all_runners()

void ModuleESolver::ESolver_KS::after_all_runners ( BaseCell & cell)
overridevirtual

perform post processing calculations

Reimplemented from ModuleESolver::ESolver_FP.

Reimplemented in ModuleESolver::ESolver_DFPT_PW, ModuleESolver::ESolver_DM2rho< TK, TR >, ModuleESolver::ESolver_GetS, ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LIP< T >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, and ModuleESolver::ESolver_SDFT_PW< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ after_scf()

void ModuleESolver::ESolver_KS::after_scf ( UnitCell & ucell,
const int istep,
const bool conv_esolver )
overrideprotectedvirtual

Something to do after SCF iterations when SCF is converged or comes to the max iter step.

Reimplemented from ModuleESolver::ESolver_FP.

Reimplemented in ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LCAO_TDDFT< TR, Device >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >, and ModuleESolver::ESolver_SDFT_PW< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ before_all_runners()

void ModuleESolver::ESolver_KS::before_all_runners ( BaseCell & basecell,
const Input_para & inp )
overridevirtual

Initialize of the first-principels energy solver.

1) setup "before_all_runniers" in ESolver_FP

2) initialize General_Exx_Info from input parameters

3) setup some parameters

3) setup charge mixing

4) setup plane wave for electronic wave functions

5) read in charge density, mohan add 2025-11-28 Inititlize the charge density.

1) read pseudopotentials

2) setup pw_rho, pw_rhod, pw_big, sf, and read_pseudopotentials

3) setup structure factors

4) init charge extrapolation

5) symmetry analysis should be performed every time the cell is changed

7) setup k points in the Brillouin zone according to symmetry.

8) print information

9) parallel of FFT grid

10) calculate the structure factor

11) initialize the charge density, we need to first set xc_type,

Reimplemented from ModuleESolver::ESolver_FP.

Reimplemented in ModuleESolver::ESolver_DFPT_PW, ModuleESolver::ESolver_DM2rho< TK, TR >, ModuleESolver::ESolver_DoubleXC< TK, TR >, ModuleESolver::ESolver_GetS, ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LCAO_TDDFT< TR, Device >, ModuleESolver::ESolver_KS_LIP< T >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >, and ModuleESolver::ESolver_SDFT_PW< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ before_scf()

void ModuleESolver::ESolver_KS::before_scf ( UnitCell & ucell,
const int istep )
overrideprotectedvirtual

Something to do before SCF iterations.

Reimplemented from ModuleESolver::ESolver_FP.

Reimplemented in ModuleESolver::ESolver_DoubleXC< TK, TR >, ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LIP< T >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >, and ModuleESolver::ESolver_SDFT_PW< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ defer_iter_output()

bool ModuleESolver::ESolver_KS::defer_iter_output ( const int istep) const
protectedvirtual

Whether KS iterations defer output until the final state is accepted.

Reimplemented in ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the caller graph for this function:

◆ density_stage()

ESolver_KS::DensityStage ModuleESolver::ESolver_KS::density_stage ( const int istep,
const int iter ) const
protectedvirtual

Identify mandatory predictor stages before mixing and convergence checks.

Reimplemented in ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the caller graph for this function:

◆ diag_policy()

std::string ModuleESolver::ESolver_KS::diag_policy ( const int istep) const
protectedvirtual

Select the diagonalization threshold and error-control policy for the current stage.

This policy does not change the requested solver type.

Reimplemented in ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the caller graph for this function:

◆ hamilt2rho()

void ModuleESolver::ESolver_KS::hamilt2rho ( UnitCell & ucell,
const int istep,
const int iter,
const double ethr )
protected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hamilt2rho_single()

void ModuleESolver::ESolver_KS::hamilt2rho_single ( UnitCell & ucell,
const int istep,
const int iter,
const double ethr )
protectedvirtual

◆ iter_finish()

void ModuleESolver::ESolver_KS::iter_finish ( UnitCell & ucell,
const int istep,
int & iter,
bool & conv_esolver )
overrideprotectedvirtual

Something to do after hamilt2rho function in each iter loop.

Reimplemented from ModuleESolver::ESolver_FP.

Reimplemented in ModuleESolver::ESolver_DoubleXC< TK, TR >, ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LIP< T >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, and ModuleESolver::ESolver_SDFT_PW< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iter_init()

void ModuleESolver::ESolver_KS::iter_init ( UnitCell & ucell,
const int istep,
const int iter )
protectedvirtual

Something to do before hamilt2rho function in each iter loop.

Reimplemented in ModuleESolver::ESolver_KS_LCAO< TK, TR >, ModuleESolver::ESolver_KS_LCAO< std::complex< double >, TR >, ModuleESolver::ESolver_KS_LIP< T >, ModuleESolver::ESolver_KS_PW< T, Device >, ModuleESolver::ESolver_KS_PW< std::complex< double >, base_device::DEVICE_CPU >, ModuleESolver::ESolver_KS_PW< T, base_device::DEVICE_CPU >, and ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ record_iteration()

void ModuleESolver::ESolver_KS::record_iteration ( const UnitCell & ucell,
double duration )
protected

Record an accepted iteration in JSON without changing its convergence status.

Here is the caller graph for this function:

◆ runner()

void ModuleESolver::ESolver_KS::runner ( BaseCell & cell,
const int istep )
overridevirtual

run energy solver

Implements ModuleESolver::ESolver.

Reimplemented in ModuleESolver::ESolver_DFPT_PW, ModuleESolver::ESolver_DM2rho< TK, TR >, ModuleESolver::ESolver_GetS, ModuleESolver::ESolver_KS_LCAO_TDDFT< TR, Device >, and ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scf_iter_limit()

int ModuleESolver::ESolver_KS::scf_iter_limit ( const int istep) const
protectedvirtual

Maximum SCF iterations for the current electronic step.

Reimplemented in ModuleESolver::ESolver_KS_LCAO_TDDFT< TR, Device >, and ModuleESolver::ESolver_KS_PW_TDDFT< T, Device >.

Here is the caller graph for this function:

◆ scf_loop()

bool ModuleESolver::ESolver_KS::scf_loop ( UnitCell & ucell,
int istep,
int iter_limit )
protected

Run SCF iterations without preparing or committing a physical endpoint.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_iter_bands()

void ModuleESolver::ESolver_KS::write_iter_bands ( )
protected

Write current band expectations when iterative band output is requested.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ basisname

std::string ModuleESolver::ESolver_KS::basisname
protected

◆ dftu_

std::unique_ptr<Plus_U_Base> ModuleESolver::ESolver_KS::dftu_
protected

DFT+U method (PW and LCAO both news Plus_U_Base). Owned by ESolver_KS via unique_ptr; released automatically in ~ESolver_KS.

◆ diag_ethr

double ModuleESolver::ESolver_KS::diag_ethr
protected

number of electrons

◆ drho

double ModuleESolver::ESolver_KS::drho
protected

scf energy threshold

◆ ds_rms_

double ModuleESolver::ESolver_KS::ds_rms_ = -1.0
protected

the error of HSolver DeltaSpin RMS from the most recent lambda optimization loop; -1.0 means no DeltaSpin. Set by ESolver_KS_LCAO after run_lambda_loop, read by ESolver_KS::iter_finish when calling print_etot.

◆ esolver_KS_ne

double ModuleESolver::ESolver_KS::esolver_KS_ne = 0.0
protected

◆ general_exx_info_

General_Exx_Info ModuleESolver::ESolver_KS::general_exx_info_
protected

General EXX info owned by ESolver, initialized from input parameters.

◆ hsolver_error

double ModuleESolver::ESolver_KS::hsolver_error
protected

the difference between rho_in (before HSolver) and rho_out (After HSolver)

◆ maxniter

int ModuleESolver::ESolver_KS::maxniter
protected

◆ niter

int ModuleESolver::ESolver_KS::niter
protected

maximum iter steps for scf

◆ oscillate_esolver

bool ModuleESolver::ESolver_KS::oscillate_esolver = false
protected

iter steps actually used in scf

◆ p_chgmix

Charge_Mixing* ModuleESolver::ESolver_KS::p_chgmix = nullptr
protected

Charge mixing method.

◆ p_hamilt

hamilt::HamiltBase* ModuleESolver::ESolver_KS::p_hamilt = nullptr
protected

Hamiltonian (base class pointer, actual type determined at runtime).

◆ ppcell

pseudopot_cell_vnl ModuleESolver::ESolver_KS::ppcell
protected

nonlocal pseudopotentials

◆ pw_wfc

ModulePW::PW_Basis_K* ModuleESolver::ESolver_KS::pw_wfc = nullptr
protected

PW for wave functions, only used in KSDFT, not in OFDFT.

◆ scf_ene_thr

double ModuleESolver::ESolver_KS::scf_ene_thr
protected

scf density threshold

◆ scf_nmax_flag

bool ModuleESolver::ESolver_KS::scf_nmax_flag = false
protected

◆ scf_rerun_

bool ModuleESolver::ESolver_KS::scf_rerun_ = false
protected

Set by a subclass (e.g. ESolver_KS_PW via EXX) to request a fresh SCF rerun from iter=1 after the current electronic iteration. ESolver_KS:: runner watches this flag at the bottom of each loop body and, when set, clears it and restarts the SCF loop with iter=1. This replaces the historical "iter=0 restart signal" trick that wrote 0 into the iter reference, which crashed DFT+U occupation-matrix writers that validate iter>=1.

◆ scf_thr

double ModuleESolver::ESolver_KS::scf_thr
protected

the threshold for diagonalization


The documentation for this class was generated from the following files: