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

#include <chg_mix.h>

Collaboration diagram for Charge_Mixing:

Public Member Functions

 Charge_Mixing ()
 ~Charge_Mixing ()
void set_mixing (const MixingConfig &cfg, ModulePW::PW_Basis *rhopw_in, ModulePW::PW_Basis *rhodpw_in, double &omega_in, double &tpiba_in)
 Set all private mixing parameters from an aggregated config.
void close_kerker_gg0 ()
void init_mixing ()
 initialize mixing, including constructing mixing and allocating memory for mixing data
void mix_rho (Charge *chr)
 charge mixing
void allocate_mixing_uom (int size_uom)
 allocate memory of uom_mdata
void mix_uom (std::vector< double > &uom_in, std::vector< double > &uom_save_in)
 DFT+U occupation matrix mixing.
void mix_reset ()
 reset mixing, actually we only call init_mixing() to reset mixing instead of this function
void reset_scf_history (int iter_limit)
 Reset restart counters and residual history for an independently limited SCF trial.
void restart_for_new_model (const int iter)
 restart mixing after the potential model changed during the SCF (SCCS delayed start)
const std::string & get_mixing_mode () const
double get_mixing_beta () const
int get_mixing_ndim () const
Base_Mixing::Mixing * get_mixing () const
Base_Mixing::Mixing_Data & get_dmr_mdata ()
 mutable access to the real-space density-matrix mixing history
Base_Mixing::Mixing_Data & get_rho_mdata ()
 mutable access to the charge-density mixing history
Base_Mixing::Mixing_Data & get_tau_mdata ()
 mutable access to the kinetic-energy-density mixing history
const MixingConfig & get_mixing_config () const
 read-only access to the aggregated mixing config set by set_mixing()
void set_mixing_config (const MixingConfig &cfg)
 replace the aggregated mixing config without re-running set_mixing()
bool if_scf_oscillate (const int iteration, const double drho, const int iternum_used, const double threshold)

Public Attributes

int mixing_restart_step = 0
 which step to restart mixing during SCF
int mixing_restart_count = 0
 the number of restart mixing during SCF
int mixing_restart_last = 0
 the label of mixing restart step

Private Member Functions

void mix_rho_recip (Charge *chr)
 charge mixing for reciprocal space
void mix_rho_real (Charge *chr)
 charge mixing for real space

Private Attributes

std::unique_ptr< Base_Mixing::Mixing > mixing
 Mixing object for charge and kinetic energy.
Base_Mixing::Mixing_Data rho_mdata
 Mixing data for charge density.
Base_Mixing::Mixing_Data tau_mdata
 Mixing data for kinetic energy density.
Base_Mixing::Mixing_Data dmr_mdata
 Mixing data for real space density matrix.
Base_Mixing::Mixing_Data uom_mdata
 Mixing data for DFT+U occupation matrix.
std::unique_ptr< Base_Mixing::Plain_Mixing > mixing_highf
 The high_frequency part is mixed by plain mixing method.
MixingConfig cfg_
 aggregated mixing config, also holds nspin/scf_thr_type/double_grid
double * omega = nullptr
 omega for non-linear core correction
double * tpiba = nullptr
 2*pi/beta for non-linear core correction
std::vector< double > _drho_history
 Residual history for oscillation detection, sized to the active SCF limit.
ModulePW::PW_Basis * rhopw = nullptr
 smooth grid
ModulePW::PW_Basis * rhodpw = nullptr
 dense grid, same as rhopw for ncpp.
bool kerker_disabled_ = false

Constructor & Destructor Documentation

◆ Charge_Mixing()

Charge_Mixing::Charge_Mixing ( )

Charge_Mixing class This class is used to mix charge density, kinetic energy density and real-space density matrix This Charge_Mixing class offers the following interfaces:

  1. set_mixing() to set all private mixing parameters
  2. init_mixing() to initialize mixing, including allocating memory for mixing data and reset mixing
  3. mix_rho() to mix charge density Real-space density matrix mixing is implemented by the stateless module_charge::init_mixing_dmr/mix_dmr functions in chg_dmr.h; this class only owns the mixing history buffer, exposed through get_dmr_mdata(). how to use it: you can (re)start a mixing by calling set_mixing() and init_mixing() before calling mix_rho()

◆ ~Charge_Mixing()

Charge_Mixing::~Charge_Mixing ( )

Member Function Documentation

◆ allocate_mixing_uom()

void Charge_Mixing::allocate_mixing_uom ( int size_uom)

allocate memory of uom_mdata

Parameters
uom_sizesize of DFT+U occupation matrix
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_kerker_gg0()

void Charge_Mixing::close_kerker_gg0 ( )
inline

Disable Kerker screening for subsequent mix_rho calls. Used by the non-separate-loop EXX path (exx_lri_interface.cpp) after EXX convergence: Kerker damping fights the DM update there. The Kerker kernels read cfg_ (immutable INPUT snapshot), so the disable flag must live on Charge_Mixing itself rather than mutating cfg_.

Here is the caller graph for this function:

◆ get_dmr_mdata()

Base_Mixing::Mixing_Data & Charge_Mixing::get_dmr_mdata ( )
inline

mutable access to the real-space density-matrix mixing history

The history buffer is owned by Charge_Mixing and driven by the stateless module_charge::init_mixing_dmr/mix_dmr functions in chg_dmr.h.

Here is the caller graph for this function:

◆ get_mixing()

Base_Mixing::Mixing * Charge_Mixing::get_mixing ( ) const
inline
Here is the caller graph for this function:

◆ get_mixing_beta()

double Charge_Mixing::get_mixing_beta ( ) const
inline
Here is the caller graph for this function:

◆ get_mixing_config()

const MixingConfig & Charge_Mixing::get_mixing_config ( ) const
inline

read-only access to the aggregated mixing config set by set_mixing()

Here is the caller graph for this function:

◆ get_mixing_mode()

const std::string & Charge_Mixing::get_mixing_mode ( ) const
inline
Here is the caller graph for this function:

◆ get_mixing_ndim()

int Charge_Mixing::get_mixing_ndim ( ) const
inline
Here is the caller graph for this function:

◆ get_rho_mdata()

Base_Mixing::Mixing_Data & Charge_Mixing::get_rho_mdata ( )
inline

mutable access to the charge-density mixing history

Same ownership story as get_dmr_mdata(): the buffer belongs to Charge_Mixing but is driven through Base_Mixing::Mixing, so callers that reset or inspect the history need a handle on it.

Here is the caller graph for this function:

◆ get_tau_mdata()

Base_Mixing::Mixing_Data & Charge_Mixing::get_tau_mdata ( )
inline

mutable access to the kinetic-energy-density mixing history

Here is the caller graph for this function:

◆ if_scf_oscillate()

bool Charge_Mixing::if_scf_oscillate ( const int iteration,
const double drho,
const int iternum_used,
const double threshold )

Fail fast when set_mixing was skipped: cfg_.scf_nmax is otherwise an indeterminate value, which would resize the history to zero and then write out of bounds (heap corruption instead of a clear error).

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

◆ init_mixing()

void Charge_Mixing::init_mixing ( )

initialize mixing, including constructing mixing and allocating memory for mixing data

this function should be called at eachiterinit()

Fail fast when set_mixing was skipped: the grid sizes below would otherwise dereference a null pointer.

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

◆ mix_reset()

void Charge_Mixing::mix_reset ( )

reset mixing, actually we only call init_mixing() to reset mixing instead of this function

Here is the caller graph for this function:

◆ mix_rho()

void Charge_Mixing::mix_rho ( Charge * chr)

charge mixing

Parameters
chrpointer of Charge object

Fail fast on invalid arguments and a skipped set_mixing: the body dereferences these pointers unconditionally below.

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

◆ mix_rho_real()

void Charge_Mixing::mix_rho_real ( Charge * chr)
private

charge mixing for real space

Parameters
chrpointer of Charge object
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mix_rho_recip()

void Charge_Mixing::mix_rho_recip ( Charge * chr)
private

charge mixing for reciprocal space

Parameters
chrpointer of Charge object
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mix_uom()

void Charge_Mixing::mix_uom ( std::vector< double > & uom_in,
std::vector< double > & uom_save_in )

DFT+U occupation matrix mixing.

Parameters
uom_inoutput occupation matrix
uom_save_ininput occupation matrix
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_scf_history()

void Charge_Mixing::reset_scf_history ( int iter_limit)

Reset restart counters and residual history for an independently limited SCF trial.

Here is the caller graph for this function:

◆ restart_for_new_model()

void Charge_Mixing::restart_for_new_model ( const int iter)

restart mixing after the potential model changed during the SCF (SCCS delayed start)

The drho of earlier iterations belongs to the old model, so the window of if_scf_oscillate also restarts at iteration iter, as after a mixing restart.

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

◆ set_mixing()

void Charge_Mixing::set_mixing ( const MixingConfig & cfg,
ModulePW::PW_Basis * rhopw_in,
ModulePW::PW_Basis * rhodpw_in,
double & omega_in,
double & tpiba_in )

Set all private mixing parameters from an aggregated config.

Parameters
cfgmixing parameters and runtime globals (nspin, scf_thr_type, double_grid)
rhopw_insmooth grid
rhodpw_indense grid when double grid is used, otherwise same as rhopw
omega_inomega for non-linear core correction
tpiba_in2*pi/beta for non-linear core correction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_mixing_config()

void Charge_Mixing::set_mixing_config ( const MixingConfig & cfg)
inline

replace the aggregated mixing config without re-running set_mixing()

set_mixing() both stores the config and rebuilds the mixing objects. This setter is for callers that need to update the snapshot alone - typically because a derived runtime global (nspin, domag, ...) changed after the mixing objects were already built - and must not disturb the mixing history. Pair it with get_mixing_config() to amend individual fields.

Here is the caller graph for this function:

Member Data Documentation

◆ _drho_history

std::vector<double> Charge_Mixing::_drho_history
private

Residual history for oscillation detection, sized to the active SCF limit.

◆ cfg_

MixingConfig Charge_Mixing::cfg_
private

aggregated mixing config, also holds nspin/scf_thr_type/double_grid

◆ dmr_mdata

Base_Mixing::Mixing_Data Charge_Mixing::dmr_mdata
private

Mixing data for real space density matrix.

◆ kerker_disabled_

bool Charge_Mixing::kerker_disabled_ = false
private

Runtime override set by close_kerker_gg0(): short-circuits the Kerker screening lambdas in mix_rho_recip/mix_rho_real so the non-separate-loop EXX path can disable Kerker after convergence. Lives here, not in MixingConfig, because cfg_ is an immutable INPUT snapshot consumed by the stateless Kerker kernels.

◆ mixing

std::unique_ptr<Base_Mixing::Mixing> Charge_Mixing::mixing
private

Mixing object for charge and kinetic energy.

◆ mixing_highf

std::unique_ptr<Base_Mixing::Plain_Mixing> Charge_Mixing::mixing_highf
private

The high_frequency part is mixed by plain mixing method.

◆ mixing_restart_count

int Charge_Mixing::mixing_restart_count = 0

the number of restart mixing during SCF

◆ mixing_restart_last

int Charge_Mixing::mixing_restart_last = 0

the label of mixing restart step

◆ mixing_restart_step

int Charge_Mixing::mixing_restart_step = 0

which step to restart mixing during SCF

◆ omega

double* Charge_Mixing::omega = nullptr
private

omega for non-linear core correction

◆ rho_mdata

Base_Mixing::Mixing_Data Charge_Mixing::rho_mdata
private

Mixing data for charge density.

◆ rhodpw

ModulePW::PW_Basis* Charge_Mixing::rhodpw = nullptr
private

dense grid, same as rhopw for ncpp.

◆ rhopw

ModulePW::PW_Basis* Charge_Mixing::rhopw = nullptr
private

smooth grid

◆ tau_mdata

Base_Mixing::Mixing_Data Charge_Mixing::tau_mdata
private

Mixing data for kinetic energy density.

◆ tpiba

double* Charge_Mixing::tpiba = nullptr
private

2*pi/beta for non-linear core correction

◆ uom_mdata

Base_Mixing::Mixing_Data Charge_Mixing::uom_mdata
private

Mixing data for DFT+U occupation matrix.


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