ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ModuleESolver::ESolver_OF Class Reference

#include <opt_test_tools.h>

Inheritance diagram for ModuleESolver::ESolver_OF:
Collaboration diagram for ModuleESolver::ESolver_OF:

Public Member Functions

 ESolver_OF ()
 
 ~ESolver_OF ()
 
double func (double *x)
 
void dfuncdx (double *x, double *gradient)
 
double dfuncdstp (double *x, double *p)
 
 ESolver_OF ()
 
 ~ESolver_OF ()
 
virtual void before_all_runners (UnitCell &ucell, const Input_para &inp) override
 Initialize of the first-principels energy solver.
 
virtual void runner (UnitCell &ucell, const int istep) override
 run energy solver
 
virtual void after_all_runners (UnitCell &ucell) override
 Output the FINAL_ETOT.
 
virtual double cal_energy () override
 Calculate the total energy. NOTE THIS FUNCTION SHOULD BE CALLEDD AFTER POTENTIAL HAS BEEN UPDATED.
 
virtual void cal_force (UnitCell &ucell, ModuleBase::matrix &force) override
 Calculate the force.
 
virtual void cal_stress (UnitCell &ucell, ModuleBase::matrix &stress) override
 Calculate the stress.
 
- 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 (UnitCell &ucell, const int istep)
 

Public Attributes

double * x
 
- Public Attributes inherited from ModuleESolver::ESolver
bool conv_esolver = true
 
std::string classname
 

Protected Member Functions

void before_opt (const int istep, UnitCell &ucell)
 Prepare to optimize the charge density, update elecstate, kedf, and opts if needed calculate ewald energy, initialize the rho, phi, theta.
 
void update_potential (UnitCell &ucell)
 Get dL/dphi = dL/drho * drho/dphi = (dE/drho - mu) * 2 * phi, as well as normdLdphi = sqrt{<dL/dphi|dL/dphi>}.
 
void optimize (UnitCell &ucell)
 Get the optimization direction (this->pdirection_) and the step length (this->theta)
 
void update_rho ()
 Update the charge density and "wavefunction" (phi) after one step of optimization phi = cos(theta) * phi + sin(theta) * direction, rho = phi^2.
 
bool check_exit (bool &conv_esolver)
 Check convergence, return ture if converge or iter >= max_iter_, and print the necessary information.
 
void after_opt (const int istep, UnitCell &ucell, const bool conv_esolver)
 After optimization, output the charge density, effective potential, ..., if needed.
 
void init_elecstate (UnitCell &ucell)
 Initialize this->pelec, as well as this->pelec->pot.
 
void allocate_array ()
 Allocate the arrays, as well as this->psi_ and this->ptemp_rho_.
 
void cal_potential_wrapper (double *ptemp_phi, double *rdLdphi)
 
void cal_potential (double *ptemp_phi, double *rdLdphi, UnitCell &ucell)
 Get dL/dphi = dL/drho * drho/dphi = (dE/drho - mu) * 2 * ptemp_phi and store it in rdLdphi.
 
void cal_dEdtheta (double **ptemp_phi, Charge *temp_rho, UnitCell &ucell, double *ptheta, double *rdEdtheta)
 Calculate dE/dTheta and store it in rdEdtheta. dE/dTheta = <dE / dtemp_phi | dtemp_phi / dTheta> = <dE / dtemp_phi | - sin(theta) * phi + cos(theta) * direction>
 
double cal_mu (double *pphi, double *pdEdphi, double nelec)
 Calculate the chemical potential mu. mu = <dE/dphi|phi> / (2 * nelec)
 
void adjust_direction ()
 Rotate and renormalize the direction |d>, make it orthogonal to phi (<d|phi> = 0), and <d|d> = nelec.
 
void check_direction (double *dEdtheta, double **ptemp_phi, UnitCell &ucell)
 Make sure that dEdtheta<0 at theta = 0, preparing to call the line search.
 
void test_direction (double *dEdtheta, double **ptemp_phi, UnitCell &ucell)
 ONLY used for test. Check the validity of KEDF.
 
void print_info (const bool conv_esolver)
 Print nessecary information to the screen, and write the components of the total energy into running_log.
 
double inner_product (double *pa, double *pb, int length, double dV=1)
 
void init_opt ()
 [Interface to opt] Initialize the opts
 
void get_direction (UnitCell &ucell)
 [Interface to opt] Call optimization methods to get the optimization direction
 
void get_step_length (double *dEdtheta, double **ptemp_phi, UnitCell &ucell)
 [Interface to opt] Call line search to find the best step length
 
- Protected Member Functions inherited from ModuleESolver::ESolver_FP
virtual void before_scf (UnitCell &ucell, const int istep)
 
virtual void after_scf (UnitCell &ucell, const int istep, const bool conv_esolver)
 
virtual void iter_finish (UnitCell &ucell, const int istep, int &iter, bool &conv_esolver)
 

Protected Attributes

KEDF_Managerkedf_manager_ = nullptr
 
ModuleBase::Opt_CGopt_cg_ = nullptr
 
ModuleBase::Opt_TNopt_tn_ = nullptr
 
ModuleBase::Opt_DCsrchopt_dcsrch_ = nullptr
 
ModuleBase::Opt_CGopt_cg_mag_ = nullptr
 
std::string of_kinetic_ = "wt"
 
std::string of_method_ = "tn"
 
std::string of_conv_ = "energy"
 
double of_tole_ = 2e-6
 
double of_tolp_ = 1e-5
 
int max_iter_ = 50
 
double dV_ = 0
 
double * nelec_ = nullptr
 
int iter_ = 0
 
double ** pdirect_ = nullptr
 
std::complex< double > ** precip_dir_ = nullptr
 
double * theta_ = nullptr
 
double ** pdEdphi_ = nullptr
 
double ** pdLdphi_ = nullptr
 
double ** pphi_ = nullptr
 
char * task_ = nullptr
 
int tn_spin_flag_ = -1
 
int max_dcsrch_ = 200
 
int flag_ = -1
 
Chargeptemp_rho_ = nullptr
 
psi::Psi< double > * psi_ = nullptr
 
double energy_llast_ = 0
 
double energy_last_ = 0
 
double energy_current_ = 0
 
double normdLdphi_llast_ = 100
 
double normdLdphi_last_ = 100
 
double normdLdphi_ = 100.
 
std::function< void(double *, double *)> bound_cal_potential_
 
- Protected Attributes inherited from ModuleESolver::ESolver_FP
elecstate::ElecStatepelec = 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_Basispw_rho
 
ModulePW::PW_Basispw_rhod
 
ModulePW::PW_Basis_Bigpw_big
 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
 
Charge_Extra CE
 charge extrapolation method
 
surchem solvent
 solvent model
 
bool pw_rho_flag = false
 flag for pw_rho, 0: not initialized, 1: initialized
 
double iter_time
 the start time of scf iteration
 

Constructor & Destructor Documentation

◆ ESolver_OF() [1/2]

ModuleESolver::ESolver_OF::ESolver_OF ( )
inline

◆ ~ESolver_OF() [1/2]

ModuleESolver::ESolver_OF::~ESolver_OF ( )
inline

◆ ESolver_OF() [2/2]

ModuleESolver::ESolver_OF::ESolver_OF ( )

◆ ~ESolver_OF() [2/2]

ModuleESolver::ESolver_OF::~ESolver_OF ( )

Member Function Documentation

◆ adjust_direction()

void ModuleESolver::ESolver_OF::adjust_direction ( void  )
protected

Rotate and renormalize the direction |d>, make it orthogonal to phi (<d|phi> = 0), and <d|d> = nelec.

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

◆ after_all_runners()

void ModuleESolver::ESolver_OF::after_all_runners ( UnitCell ucell)
overridevirtual

Output the FINAL_ETOT.

Reimplemented from ModuleESolver::ESolver_FP.

Here is the call graph for this function:

◆ after_opt()

void ModuleESolver::ESolver_OF::after_opt ( const int  istep,
UnitCell ucell,
const bool  conv_esolver 
)
protected

After optimization, output the charge density, effective potential, ..., if needed.

Parameters
istep
ucell
Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocate_array()

void ModuleESolver::ESolver_OF::allocate_array ( )
protected

Allocate the arrays, as well as this->psi_ and this->ptemp_rho_.

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

◆ before_all_runners()

void ModuleESolver::ESolver_OF::before_all_runners ( UnitCell ucell,
const Input_para inp 
)
overridevirtual

Initialize of the first-principels energy solver.

read pseudopotentials

Reimplemented from ModuleESolver::ESolver_FP.

Here is the call graph for this function:

◆ before_opt()

void ModuleESolver::ESolver_OF::before_opt ( const int  istep,
UnitCell ucell 
)
protected

Prepare to optimize the charge density, update elecstate, kedf, and opts if needed calculate ewald energy, initialize the rho, phi, theta.

Parameters
istep
ucell

1) call before_scf() of ESolver_FP

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

◆ cal_dEdtheta()

void ModuleESolver::ESolver_OF::cal_dEdtheta ( double **  ptemp_phi,
Charge temp_rho,
UnitCell ucell,
double *  ptheta,
double *  rdEdtheta 
)
protected

Calculate dE/dTheta and store it in rdEdtheta. dE/dTheta = <dE / dtemp_phi | dtemp_phi / dTheta> = <dE / dtemp_phi | - sin(theta) * phi + cos(theta) * direction>

Parameters
[in]ptemp_phi
[in]temp_rho
[in]ucell
[in]ptheta
[out]rdEdthetadE/dTheta
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_energy()

double ModuleESolver::ESolver_OF::cal_energy ( )
overridevirtual

Calculate the total energy. NOTE THIS FUNCTION SHOULD BE CALLEDD AFTER POTENTIAL HAS BEEN UPDATED.

Returns
total energy

Implements ModuleESolver::ESolver.

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

◆ cal_force()

void ModuleESolver::ESolver_OF::cal_force ( UnitCell ucell,
ModuleBase::matrix force 
)
overridevirtual

Calculate the force.

Parameters
[out]force

Implements ModuleESolver::ESolver.

Here is the call graph for this function:

◆ cal_mu()

double ModuleESolver::ESolver_OF::cal_mu ( double *  pphi,
double *  pdEdphi,
double  nelec 
)
protected

Calculate the chemical potential mu. mu = <dE/dphi|phi> / (2 * nelec)

Parameters
pphi
pdEdphi
nelec
Returns
mu
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_potential()

void ModuleESolver::ESolver_OF::cal_potential ( double *  ptemp_phi,
double *  rdLdphi,
UnitCell ucell 
)
protected

Get dL/dphi = dL/drho * drho/dphi = (dE/drho - mu) * 2 * ptemp_phi and store it in rdLdphi.

Parameters
[in]ptemp_phiphi
[out]rdLdphidL/dphi
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_potential_wrapper()

void ModuleESolver::ESolver_OF::cal_potential_wrapper ( double *  ptemp_phi,
double *  rdLdphi 
)
protected
Here is the caller graph for this function:

◆ cal_stress()

void ModuleESolver::ESolver_OF::cal_stress ( UnitCell ucell,
ModuleBase::matrix stress 
)
overridevirtual

Calculate the stress.

Parameters
[out]stress

Implements ModuleESolver::ESolver.

Here is the call graph for this function:

◆ check_direction()

void ModuleESolver::ESolver_OF::check_direction ( double *  dEdtheta,
double **  ptemp_phi,
UnitCell ucell 
)
protected

Make sure that dEdtheta<0 at theta = 0, preparing to call the line search.

Parameters
dEdtheta
ptemp_phi
ucell
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_exit()

bool ModuleESolver::ESolver_OF::check_exit ( bool &  conv_esolver)
protected

Check convergence, return ture if converge or iter >= max_iter_, and print the necessary information.

Returns
exit or not
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dfuncdstp()

double ModuleESolver::ESolver_OF::dfuncdstp ( double *  x,
double *  p 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dfuncdx()

void ModuleESolver::ESolver_OF::dfuncdx ( double *  x,
double *  gradient 
)
Here is the caller graph for this function:

◆ func()

double ModuleESolver::ESolver_OF::func ( double *  x)
Here is the caller graph for this function:

◆ get_direction()

void ModuleESolver::ESolver_OF::get_direction ( UnitCell ucell)
protected

[Interface to opt] Call optimization methods to get the optimization direction

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

◆ get_step_length()

void ModuleESolver::ESolver_OF::get_step_length ( double *  dEdtheta,
double **  ptemp_phi,
UnitCell ucell 
)
protected

[Interface to opt] Call line search to find the best step length

Parameters
dEdthetad E / d theta
ptemp_phi
ucell
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_elecstate()

void ModuleESolver::ESolver_OF::init_elecstate ( UnitCell ucell)
protected

Initialize this->pelec, as well as this->pelec->pot.

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

◆ init_opt()

void ModuleESolver::ESolver_OF::init_opt ( )
protected

[Interface to opt] Initialize the opts

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

◆ inner_product()

double ModuleESolver::ESolver_OF::inner_product ( double *  pa,
double *  pb,
int  length,
double  dV = 1 
)
inlineprotected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ optimize()

void ModuleESolver::ESolver_OF::optimize ( UnitCell ucell)
protected

Get the optimization direction (this->pdirection_) and the step length (this->theta)

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

◆ print_info()

void ModuleESolver::ESolver_OF::print_info ( const bool  conv_esolver)
protected

Print nessecary information to the screen, and write the components of the total energy into running_log.

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

◆ runner()

void ModuleESolver::ESolver_OF::runner ( UnitCell cell,
const int  istep 
)
overridevirtual

run energy solver

Implements ModuleESolver::ESolver.

Reimplemented in ModuleESolver::ESolver_OF_TDDFT.

Here is the call graph for this function:

◆ test_direction()

void ModuleESolver::ESolver_OF::test_direction ( double *  dEdtheta,
double **  ptemp_phi,
UnitCell ucell 
)
protected

ONLY used for test. Check the validity of KEDF.

Parameters
dEdtheta
ptemp_phi
ucell
Here is the call graph for this function:

◆ update_potential()

void ModuleESolver::ESolver_OF::update_potential ( UnitCell ucell)
protected

Get dL/dphi = dL/drho * drho/dphi = (dE/drho - mu) * 2 * phi, as well as normdLdphi = sqrt{<dL/dphi|dL/dphi>}.

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

◆ update_rho()

void ModuleESolver::ESolver_OF::update_rho ( )
protected

Update the charge density and "wavefunction" (phi) after one step of optimization phi = cos(theta) * phi + sin(theta) * direction, rho = phi^2.

Here is the caller graph for this function:

Member Data Documentation

◆ bound_cal_potential_

std::function<void(double*, double*)> ModuleESolver::ESolver_OF::bound_cal_potential_
protected

◆ dV_

double ModuleESolver::ESolver_OF::dV_ = 0
protected

◆ energy_current_

double ModuleESolver::ESolver_OF::energy_current_ = 0
protected

◆ energy_last_

double ModuleESolver::ESolver_OF::energy_last_ = 0
protected

◆ energy_llast_

double ModuleESolver::ESolver_OF::energy_llast_ = 0
protected

◆ flag_

int ModuleESolver::ESolver_OF::flag_ = -1
protected

◆ iter_

int ModuleESolver::ESolver_OF::iter_ = 0
protected

◆ kedf_manager_

KEDF_Manager* ModuleESolver::ESolver_OF::kedf_manager_ = nullptr
protected

◆ max_dcsrch_

int ModuleESolver::ESolver_OF::max_dcsrch_ = 200
protected

◆ max_iter_

int ModuleESolver::ESolver_OF::max_iter_ = 50
protected

◆ nelec_

double* ModuleESolver::ESolver_OF::nelec_ = nullptr
protected

◆ normdLdphi_

double ModuleESolver::ESolver_OF::normdLdphi_ = 100.
protected

◆ normdLdphi_last_

double ModuleESolver::ESolver_OF::normdLdphi_last_ = 100
protected

◆ normdLdphi_llast_

double ModuleESolver::ESolver_OF::normdLdphi_llast_ = 100
protected

◆ of_conv_

std::string ModuleESolver::ESolver_OF::of_conv_ = "energy"
protected

◆ of_kinetic_

std::string ModuleESolver::ESolver_OF::of_kinetic_ = "wt"
protected

◆ of_method_

std::string ModuleESolver::ESolver_OF::of_method_ = "tn"
protected

◆ of_tole_

double ModuleESolver::ESolver_OF::of_tole_ = 2e-6
protected

◆ of_tolp_

double ModuleESolver::ESolver_OF::of_tolp_ = 1e-5
protected

◆ opt_cg_

ModuleBase::Opt_CG* ModuleESolver::ESolver_OF::opt_cg_ = nullptr
protected

◆ opt_cg_mag_

ModuleBase::Opt_CG* ModuleESolver::ESolver_OF::opt_cg_mag_ = nullptr
protected

◆ opt_dcsrch_

ModuleBase::Opt_DCsrch* ModuleESolver::ESolver_OF::opt_dcsrch_ = nullptr
protected

◆ opt_tn_

ModuleBase::Opt_TN* ModuleESolver::ESolver_OF::opt_tn_ = nullptr
protected

◆ pdEdphi_

double** ModuleESolver::ESolver_OF::pdEdphi_ = nullptr
protected

◆ pdirect_

double** ModuleESolver::ESolver_OF::pdirect_ = nullptr
protected

◆ pdLdphi_

double** ModuleESolver::ESolver_OF::pdLdphi_ = nullptr
protected

◆ pphi_

double** ModuleESolver::ESolver_OF::pphi_ = nullptr
protected

◆ precip_dir_

std::complex<double>** ModuleESolver::ESolver_OF::precip_dir_ = nullptr
protected

◆ psi_

psi::Psi<double>* ModuleESolver::ESolver_OF::psi_ = nullptr
protected

◆ ptemp_rho_

Charge* ModuleESolver::ESolver_OF::ptemp_rho_ = nullptr
protected

◆ task_

char* ModuleESolver::ESolver_OF::task_ = nullptr
protected

◆ theta_

double* ModuleESolver::ESolver_OF::theta_ = nullptr
protected

◆ tn_spin_flag_

int ModuleESolver::ESolver_OF::tn_spin_flag_ = -1
protected

◆ x

double* ModuleESolver::ESolver_OF::x

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