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

The First-Principles (FP) Energy Solver Class. More...

Classes

class  ESolver_OF
class  ESolver
class  ESolver_DFPT_PW
class  ESolver_DM2rho
class  ESolver_DoubleXC
class  esolver_forcefields
class  ESolver_FP
class  ESolver_GetS
class  ESolver_KS
class  ESolver_LR
 Forward declaration for the linear-response solver. More...
class  ESolver_KS_LCAO
 Kohn-Sham energy solver using the LCAO basis. More...
class  ESolver_KS_LCAO_TDDFT
 Real-time TDDFT energy solver using the LCAO basis. More...
class  ESolver_KS_LIP
class  ESolver_KS_PW
class  ESolver_KS_PW_TDDFT
class  ESolver_BSE
struct  LRRuntime
class  ESolver_OF_TDDFT
class  ESolver_SDFT_PW

Typedefs

template<typename T>
using Real = typename GetTypeReal<T>::type

Functions

std::string determine_type (const Input_para &inp)
 Determine the ESolver type string from input parameters.
ESolver * init_esolver (const Input_para &inp)
 Determine and initialize an ESolver based on input information.
template<typename TK>
void init_deltaspin_lcao (const UnitCell &ucell, const Input_para &inp, void *pv, const K_Vectors &kv, void *p_hamilt, void *psi, void *dm, void *pelec)
 Initialize the SpinConstrain singleton with all input parameters.
template<typename TK>
void cal_mi_lcao_wrapper (const int iter, const Input_para &inp)
 Wrapper: calculate magnetic moments for current SCF iteration.
template<typename TK>
bool run_deltaspin_lambda_loop_lcao (const int iter, const double drho, const Input_para &inp, std::ostream &ofs_running)
 Wrapper: run the lambda optimization loop.
template void init_deltaspin_lcao< double > (const UnitCell &ucell, const Input_para &inp, void *pv, const K_Vectors &kv, void *p_hamilt, void *psi, void *dm, void *pelec)
 Template instantiations for both spin types.
template void init_deltaspin_lcao< std::complex< double > > (const UnitCell &ucell, const Input_para &inp, void *pv, const K_Vectors &kv, void *p_hamilt, void *psi, void *dm, void *pelec)
template void cal_mi_lcao_wrapper< double > (const int iter, const Input_para &inp)
template void cal_mi_lcao_wrapper< std::complex< double > > (const int iter, const Input_para &inp)
template bool run_deltaspin_lambda_loop_lcao< double > (const int iter, const double drho, const Input_para &inp, std::ostream &ofs_running)
template bool run_deltaspin_lambda_loop_lcao< std::complex< double > > (const int iter, const double drho, const Input_para &inp, std::ostream &ofs_running)
void init_dftu_lcao (int dft_plus_u, void *dftu, const UnitCell &ucell, double **rho, const int nrxx, const LCAO_Orbitals *orb)
 Initialize DFT+U for LCAO method in iter_init.
template<typename TK>
void finish_dftu_lcao (const bool conv_esolver, int dft_plus_u, void *dftu, const UnitCell &ucell, const std::vector< std::vector< TK > > &dm_vec, const K_Vectors &kv, const double mixing_beta, void *hamilt_lcao, int nspin, const bool gamma_only_local)
 Finish DFT+U calculation for LCAO method in iter_finish.
template void finish_dftu_lcao< double > (const bool conv_esolver, int dft_plus_u, void *dftu, const UnitCell &ucell, const std::vector< std::vector< double > > &dm_vec, const K_Vectors &kv, const double mixing_beta, void *hamilt_lcao, int nspin, const bool gamma_only_local)
 Template instantiation.
template void finish_dftu_lcao< std::complex< double > > (const bool conv_esolver, int dft_plus_u, void *dftu, const UnitCell &ucell, const std::vector< std::vector< std::complex< double > > > &dm_vec, const K_Vectors &kv, const double mixing_beta, void *hamilt_lcao, int nspin, const bool gamma_only_local)

Detailed Description

The First-Principles (FP) Energy Solver Class.

This class represents components that needed in first-principles energy solver, such as the plane wave basis, the structure factors, and the k points.

Typedef Documentation

◆ Real

template<typename T>
using ModuleESolver::Real = typename GetTypeReal<T>::type

Function Documentation

◆ cal_mi_lcao_wrapper()

template<typename TK>
void ModuleESolver::cal_mi_lcao_wrapper ( const int iter,
const Input_para & inp )

Wrapper: calculate magnetic moments for current SCF iteration.

Calculate magnetic moments for DeltaSpin in LCAO method.

If DeltaSpin is enabled, calls SpinConstrain::cal_mi_lcao(). The moments are stored in Mi_ and can be retrieved via get_target_mag().

This function calculates the magnetic moments for each atom in the DeltaSpin method.

Parameters
iterCurrent iteration number
inpInput parameters
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_mi_lcao_wrapper< double >()

template void ModuleESolver::cal_mi_lcao_wrapper< double > ( const int iter,
const Input_para & inp )

◆ cal_mi_lcao_wrapper< std::complex< double > >()

template void ModuleESolver::cal_mi_lcao_wrapper< std::complex< double > > ( const int iter,
const Input_para & inp )
Here is the call graph for this function:

◆ determine_type()

std::string ModuleESolver::determine_type ( const Input_para & inp)

Determine the ESolver type string from input parameters.

The type is decided based on inp.basis_type and inp.esolver_type, together with device/precision hints written to the running log.

Parameters
[in]inpInput parameters used to determine the ESolver type.
Returns
[out] std::string The type label consumed by init_esolver().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_dftu_lcao()

template<typename TK>
void ModuleESolver::finish_dftu_lcao ( const bool conv_esolver,
int dft_plus_u,
void * dftu,
const UnitCell & ucell,
const std::vector< std::vector< TK > > & dm_vec,
const K_Vectors & kv,
const double mixing_beta,
void * hamilt_lcao,
int nspin,
const bool gamma_only_local )

Finish DFT+U calculation for LCAO method in iter_finish.

This function handles the DFT+U finalization during the SCF iteration. It calculates the occupation matrix and energy correction if needed.

Parameters
conv_esolverWhether ESolver has converged
dft_plus_uDFT+U mode (0=disabled, 1=old, 2=new)
dftuDFT+U object
ucellUnit cell
dm_vecDensity matrix vector
kvK-vectors
mixing_betaMixing beta parameter
hamilt_lcaoHamiltonian LCAO object
nspinNumber of spin channels (1, 2, or 4)
gamma_only_localWhether only the Gamma point is used for LCAO

old DFT+U method calculates energy correction in esolver, new DFT+U method calculates energy in Hamiltonian

use the converged occupation matrix for next MD/Relax SCF calculation

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

◆ finish_dftu_lcao< double >()

template void ModuleESolver::finish_dftu_lcao< double > ( const bool conv_esolver,
int dft_plus_u,
void * dftu,
const UnitCell & ucell,
const std::vector< std::vector< double > > & dm_vec,
const K_Vectors & kv,
const double mixing_beta,
void * hamilt_lcao,
int nspin,
const bool gamma_only_local )

Template instantiation.

◆ finish_dftu_lcao< std::complex< double > >()

template void ModuleESolver::finish_dftu_lcao< std::complex< double > > ( const bool conv_esolver,
int dft_plus_u,
void * dftu,
const UnitCell & ucell,
const std::vector< std::vector< std::complex< double > > > & dm_vec,
const K_Vectors & kv,
const double mixing_beta,
void * hamilt_lcao,
int nspin,
const bool gamma_only_local )
Here is the call graph for this function:

◆ init_deltaspin_lcao()

template<typename TK>
void ModuleESolver::init_deltaspin_lcao ( const UnitCell & ucell,
const Input_para & inp,
void * pv,
const K_Vectors & kv,
void * p_hamilt,
void * psi,
void * dm,
void * pelec )

Initialize the SpinConstrain singleton with all input parameters.

Initialize DeltaSpin for LCAO method.

Called once at the start of a DeltaSpin calculation. Checks sc_mag_switch first; if disabled, returns immediately without any action.

Conditional compilation
The density matrix pointer (dm) is only available when __LCAO is defined. For non-LCAO builds (PW-only), init_sc() is called without the dm parameter.

This function initializes the DeltaSpin calculation by setting up the SpinConstrain object with input parameters.

Parameters
ucellUnit cell
inpInput parameters
pvParallel orbitals
kvK-vectors
p_hamiltPointer to Hamiltonian
psiPointer to wave functions
dmDensity matrix
pelecPointer to electronic state
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_deltaspin_lcao< double >()

template void ModuleESolver::init_deltaspin_lcao< double > ( const UnitCell & ucell,
const Input_para & inp,
void * pv,
const K_Vectors & kv,
void * p_hamilt,
void * psi,
void * dm,
void * pelec )

Template instantiations for both spin types.

◆ init_deltaspin_lcao< std::complex< double > >()

template void ModuleESolver::init_deltaspin_lcao< std::complex< double > > ( const UnitCell & ucell,
const Input_para & inp,
void * pv,
const K_Vectors & kv,
void * p_hamilt,
void * psi,
void * dm,
void * pelec )
Here is the call graph for this function:

◆ init_dftu_lcao()

void ModuleESolver::init_dftu_lcao ( int dft_plus_u,
void * dftu,
const UnitCell & ucell,
double ** rho,
const int nrxx,
const LCAO_Orbitals * orb )

Initialize DFT+U for LCAO method in iter_init.

This function handles the DFT+U initialization during the SCF iteration. It calculates Slater integrals if the Yukawa potential is used. The DMR needed by DFT+U is read directly from the solver-owned DensityMatrix via the DFTU Hamiltonian operator, so it is not passed in here.

Parameters
dft_plus_uDFT+U mode (0=disabled, 1=old, 2=new)
dftuDFT+U object
ucellUnit cell
rhoCharge density
nrxxNumber of real space grid points
orbNumerical atomic orbitals; used for Slater integrals when the Yukawa potential is enabled. May be nullptr when no LCAO orbital data is available (e.g. PW-only DFT+U paths).

Calculate U and J if Yukawa potential is used

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

◆ init_esolver()

ESolver * ModuleESolver::init_esolver ( const Input_para & inp)

Determine and initialize an ESolver based on input information.

This function determines the type of ESolver to create based on input information and initializes the corresponding ESolver child class. It supports various ESolver types including ksdft_pw, ksdft_lcao, ksdft_lcao_tddft, sdft_pw, ofdft, lj_pot, and dp_pot.

Parameters
[in]inpInput parameters used to select and configure the ESolver.
Returns
[out] A pointer to the newly created ESolver object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_deltaspin_lambda_loop_lcao()

template<typename TK>
bool ModuleESolver::run_deltaspin_lambda_loop_lcao ( const int iter,
const double drho,
const Input_para & inp,
std::ostream & ofs_running )

Wrapper: run the lambda optimization loop.

Run DeltaSpin lambda loop for LCAO method.

Decision logic for when to run the lambda loop:

Case 1: NOT converged AND charge density is close enough (drho < sc_scf_thr) -> Run lambda loop, mark as converged, skip_solve = true Rationale: The charge density is stable enough to optimize lambda. The lambda loop does its own diagonalization, so skip the outer solve.

Case 2: Already converged -> Still run lambda loop (to refine for the current charge density) -> skip_solve = true Rationale: Even if converged, the charge density may have changed slightly, requiring lambda refinement.

Case 3: NOT converged AND charge density is NOT close enough (drho >= sc_scf_thr) -> Do nothing, skip_solve = false Rationale: The charge density is still changing significantly, so optimizing lambda would be premature. Wait for SCF to stabilize first.

Parameters
iterCurrent SCF iteration number
drhoCharge density convergence criterion (max|drho|)
inpInput parameters
Returns
true if the ESolver should skip the Hamiltonian solve

This function handles the lambda loop optimization for the DeltaSpin method in LCAO calculations. It determines whether to skip the Hamiltonian solve based on the convergence status of magnetic moments.

Parameters
iterCurrent iteration number
drhoCharge density convergence criterion
inpInput parameters
Returns
bool Whether to skip the Hamiltonian solve

Charge density is stable enough: optimize lambda for the first time

Already converged: refine lambda for the current charge density

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

◆ run_deltaspin_lambda_loop_lcao< double >()

template bool ModuleESolver::run_deltaspin_lambda_loop_lcao< double > ( const int iter,
const double drho,
const Input_para & inp,
std::ostream & ofs_running )

◆ run_deltaspin_lambda_loop_lcao< std::complex< double > >()

template bool ModuleESolver::run_deltaspin_lambda_loop_lcao< std::complex< double > > ( const int iter,
const double drho,
const Input_para & inp,
std::ostream & ofs_running )
Here is the call graph for this function: