votca 2026-dev
Loading...
Searching...
No Matches
votca::xtp::ConvergenceAcc Class Reference

#include <convergenceacc.h>

Collaboration diagram for votca::xtp::ConvergenceAcc:

Classes

struct  options
struct  SpinDensity
 Spin-resolved density matrices returned for open-shell SCF updates. More...

Public Types

enum  KSmode { closed , open , fractional , restricted_open }
 Occupation model used when constructing density matrices. More...
using OrbitalHessian

Public Member Functions

void Configure (const ConvergenceAcc::options &opt)
void StartNewSCF ()
void setOrbitalHessian (const OrbitalHessian &hessian)
bool SecondOrderActive () const
void setLogger (Logger *log)
 Attach the logger used for convergence diagnostics.
void PrintConfigOptions () const
 Print the active convergence-acceleration settings to the logger.
bool isConverged () const
double getDeltaE () const
 Return the total-energy change between the two most recent SCF iterations.
void setOverlap (AOOverlap &S, double etol)
 Precompute overlap-dependent quantities used when solving the Fock matrix.
double getDIIsError () const
 Return the DIIS commutator norm from the latest iteration.
bool getUseMixing () const
bool HistoryIsAligned () const
Eigen::MatrixXd Iterate (const Eigen::MatrixXd &dmat, Eigen::MatrixXd &H, tools::EigenSystem &MOs, double totE)
tools::EigenSystem SolveFockmatrix (const Eigen::MatrixXd &H) const
 Solve the generalized eigenvalue problem for the current Fock matrix.
void Levelshift (Eigen::MatrixXd &H, const Eigen::MatrixXd &MOs_old) const
 Apply a virtual-space level shift in the molecular-orbital basis.
Eigen::MatrixXd DensityMatrix (const tools::EigenSystem &MOs) const
SpinDensity DensityMatrixSpinResolved (const tools::EigenSystem &MOs) const

Static Public Attributes

static constexpr double EnergyGradientScale = -4.0

Private Member Functions

Eigen::MatrixXd DensityMatrixGroundState (const Eigen::MatrixXd &MOs) const
Eigen::MatrixXd DensityMatrixGroundState_unres (const Eigen::MatrixXd &MOs) const
Eigen::MatrixXd DensityMatrixGroundState_frac (const tools::EigenSystem &MOs) const
 Construct a fractional-occupation density matrix from orbital occupations.
SpinDensity DensityMatrixGroundState_restricted_open (const Eigen::MatrixXd &MOs) const
bool SecondOrderAvailable () const
bool SecondOrderStalled () const
Eigen::MatrixXd SecondOrderStep (const Eigen::MatrixXd &dmat, const Eigen::MatrixXd &H, tools::EigenSystem &MOs, double totE)

Private Attributes

options opt_
OrbitalHessian orbital_hessian_
bool trah_active_ = false
bool trah_pending_ = false
bool trah_disabled_ = false
trah::TrustRadius trust_ {kInitialTrustRadius}
trah::StepOptions trah_options_
double trah_pre_energy_ = 0.0
double trah_predicted_ = 0.0
double trah_linear_ = 0.0
double trah_step_norm_ = 0.0
tools::EigenSystem trah_pre_MOs_
Eigen::MatrixXd trah_pre_H_
trah::Subspace trah_subspace_
bool last_rejected_ = false
Index consecutive_failures_ = 0
Index scf_iterations_ = 0
std::vector< double > error_history_
bool usedmixing_ = true
double diiserror_ = std::numeric_limits<double>::max()
Logger * log_
const AOOverlap * S_
Eigen::MatrixXd Sminusahalf
Eigen::MatrixXd removed_projector_
std::vector< Eigen::MatrixXd > mathist_
std::vector< Eigen::MatrixXd > dmatHist_
std::vector< double > errhist_
std::vector< double > totE_
bool have_best_ = false
double best_energy_ = 0.0
Eigen::MatrixXd best_dmat_
Eigen::MatrixXd best_H_
Index energy_resets_ = 0
Index iterations_since_reset_ = kResetCooldown
Index nocclevels_
ADIIS adiis_
DIIS diis_

Static Private Attributes

static constexpr double kInitialTrustRadius = 0.5
static constexpr double kMinTrustRadius = 3e-3
static constexpr double kDensityMismatchTolerance = 1e-8
static constexpr Index kMaxConsecutiveFailures = 5
static constexpr Index kAutoStartIteration = 50
static constexpr Index kTrailingWindow = 10
static constexpr double kMeanRatioTolerance = 1.125
static constexpr double kRemovedShift = 1e3
static constexpr Index kResetCooldown = 3
static constexpr Index kMaxEnergyResets = 5
static constexpr double kEnergyRiseForADIIS = 1e-4

Detailed Description

SCF convergence accelerator for Kohn-Sham iterations.

The class stores the Fock and density history needed for linear mixing, Pulay DIIS, and ADIIS, and provides the density construction matching the selected occupation model.

Definition at line 44 of file convergenceacc.h.

Member Typedef Documentation

◆ OrbitalHessian

Initial value:
std::function<Eigen::MatrixXd(
const tools::EigenSystem& MOs, const Eigen::MatrixXd& F,
const Eigen::MatrixXd& X)>

Closed-shell energy Hessian d^2E/dx dx (rotation layout of trah.h, x of the doubly occupied orbitals) at the orbitals MOs with AO Fock matrix F, applied to the columns of X. Set by DFTEngine; without it no second-order steps are taken.

Definition at line 162 of file convergenceacc.h.

Member Enumeration Documentation

◆ KSmode

Occupation model used when constructing density matrices.

Enumerator
closed 
open 
fractional 
restricted_open 

Definition at line 47 of file convergenceacc.h.

Member Function Documentation

◆ Configure()

void votca::xtp::ConvergenceAcc::Configure ( const ConvergenceAcc::options & opt)
inline

Store SCF acceleration settings and derive the number of occupied levels for the selected KS mode.

Definition at line 122 of file convergenceacc.h.

◆ DensityMatrix()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::DensityMatrix ( const tools::EigenSystem & MOs) const

Build the density matrix corresponding to the configured KS occupation model.

Definition at line 663 of file convergenceacc.cc.

◆ DensityMatrixGroundState()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::DensityMatrixGroundState ( const Eigen::MatrixXd & MOs) const
private

Construct a closed-shell ground-state density matrix from occupied orbitals.

Definition at line 538 of file convergenceacc.cc.

◆ DensityMatrixGroundState_frac()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::DensityMatrixGroundState_frac ( const tools::EigenSystem & MOs) const
private

Construct a fractional-occupation density matrix from orbital occupations.

Definition at line 572 of file convergenceacc.cc.

◆ DensityMatrixGroundState_restricted_open()

ConvergenceAcc::SpinDensity votca::xtp::ConvergenceAcc::DensityMatrixGroundState_restricted_open ( const Eigen::MatrixXd & MOs) const
private

Construct alpha and beta densities for a restricted open-shell determinant.

Definition at line 617 of file convergenceacc.cc.

◆ DensityMatrixGroundState_unres()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::DensityMatrixGroundState_unres ( const Eigen::MatrixXd & MOs) const
private

Construct a fully occupied unrestricted density matrix from the supplied orbitals.

Definition at line 550 of file convergenceacc.cc.

◆ DensityMatrixSpinResolved()

ConvergenceAcc::SpinDensity votca::xtp::ConvergenceAcc::DensityMatrixSpinResolved ( const tools::EigenSystem & MOs) const

Build separate alpha and beta density matrices for spin-resolved SCF modes.

Definition at line 646 of file convergenceacc.cc.

◆ getDeltaE()

double votca::xtp::ConvergenceAcc::getDeltaE ( ) const
inline

Return the total-energy change between the two most recent SCF iterations.

Definition at line 192 of file convergenceacc.h.

◆ getDIIsError()

double votca::xtp::ConvergenceAcc::getDIIsError ( ) const
inline

Return the DIIS commutator norm from the latest iteration.

Definition at line 208 of file convergenceacc.h.

◆ getUseMixing()

bool votca::xtp::ConvergenceAcc::getUseMixing ( ) const
inline

Report whether plain density mixing is currently used instead of extrapolation.

Definition at line 212 of file convergenceacc.h.

◆ HistoryIsAligned()

bool votca::xtp::ConvergenceAcc::HistoryIsAligned ( ) const

Definition at line 312 of file convergenceacc.cc.

◆ isConverged()

bool votca::xtp::ConvergenceAcc::isConverged ( ) const
inline

Check whether both the total-energy change and DIIS error are below their thresholds.

Definition at line 180 of file convergenceacc.h.

◆ Iterate()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::Iterate ( const Eigen::MatrixXd & dmat,
Eigen::MatrixXd & H,
tools::EigenSystem & MOs,
double totE )

Advance the SCF accelerator by one step and return the updated density matrix.

Definition at line 99 of file convergenceacc.cc.

◆ Levelshift()

void votca::xtp::ConvergenceAcc::Levelshift ( Eigen::MatrixXd & H,
const Eigen::MatrixXd & MOs_old ) const

Apply a virtual-space level shift in the molecular-orbital basis.

Definition at line 499 of file convergenceacc.cc.

◆ PrintConfigOptions()

void votca::xtp::ConvergenceAcc::PrintConfigOptions ( ) const

Print the active convergence-acceleration settings to the logger.

Definition at line 432 of file convergenceacc.cc.

◆ SecondOrderActive()

bool votca::xtp::ConvergenceAcc::SecondOrderActive ( ) const
inline

Definition at line 171 of file convergenceacc.h.

◆ SecondOrderAvailable()

bool votca::xtp::ConvergenceAcc::SecondOrderAvailable ( ) const
inlineprivate

Definition at line 256 of file convergenceacc.h.

◆ SecondOrderStalled()

bool votca::xtp::ConvergenceAcc::SecondOrderStalled ( ) const
private

Definition at line 332 of file convergenceacc.cc.

◆ SecondOrderStep()

Eigen::MatrixXd votca::xtp::ConvergenceAcc::SecondOrderStep ( const Eigen::MatrixXd & dmat,
const Eigen::MatrixXd & H,
tools::EigenSystem & MOs,
double totE )
private

Definition at line 355 of file convergenceacc.cc.

◆ setLogger()

void votca::xtp::ConvergenceAcc::setLogger ( Logger * log)
inline

Attach the logger used for convergence diagnostics.

Definition at line 173 of file convergenceacc.h.

◆ setOrbitalHessian()

void votca::xtp::ConvergenceAcc::setOrbitalHessian ( const OrbitalHessian & hessian)
inline

Definition at line 165 of file convergenceacc.h.

◆ setOverlap()

void votca::xtp::ConvergenceAcc::setOverlap ( AOOverlap & S,
double etol )

Precompute overlap-dependent quantities used when solving the Fock matrix.

Convergence acceleration for the SCF cycle.

The central residual is the AO-metric commutator R = F P S - S P F, which vanishes at self-consistency in a non-orthogonal basis. This file provides the orthogonalized residual, DIIS or ADIIS extrapolation, level shifting, and occupation-model-specific density construction.

Definition at line 41 of file convergenceacc.cc.

◆ SolveFockmatrix()

tools::EigenSystem votca::xtp::ConvergenceAcc::SolveFockmatrix ( const Eigen::MatrixXd & H) const

Solve the generalized eigenvalue problem for the current Fock matrix.

Definition at line 474 of file convergenceacc.cc.

◆ StartNewSCF()

void votca::xtp::ConvergenceAcc::StartNewSCF ( )
inline

Definition at line 143 of file convergenceacc.h.

Member Data Documentation

◆ adiis_

ADIIS votca::xtp::ConvergenceAcc::adiis_
private

Definition at line 333 of file convergenceacc.h.

◆ best_dmat_

Eigen::MatrixXd votca::xtp::ConvergenceAcc::best_dmat_
private

Definition at line 318 of file convergenceacc.h.

◆ best_energy_

double votca::xtp::ConvergenceAcc::best_energy_ = 0.0
private

Definition at line 317 of file convergenceacc.h.

◆ best_H_

Eigen::MatrixXd votca::xtp::ConvergenceAcc::best_H_
private

Definition at line 319 of file convergenceacc.h.

◆ consecutive_failures_

Index votca::xtp::ConvergenceAcc::consecutive_failures_ = 0
private

Definition at line 286 of file convergenceacc.h.

◆ diis_

DIIS votca::xtp::ConvergenceAcc::diis_
private

Definition at line 334 of file convergenceacc.h.

◆ diiserror_

double votca::xtp::ConvergenceAcc::diiserror_ = std::numeric_limits<double>::max()
private

Definition at line 295 of file convergenceacc.h.

◆ dmatHist_

std::vector<Eigen::MatrixXd> votca::xtp::ConvergenceAcc::dmatHist_
private

Definition at line 309 of file convergenceacc.h.

◆ energy_resets_

Index votca::xtp::ConvergenceAcc::energy_resets_ = 0
private

Definition at line 320 of file convergenceacc.h.

◆ EnergyGradientScale

double votca::xtp::ConvergenceAcc::EnergyGradientScale = -4.0
staticconstexpr

dE/dx_ia = EnergyGradientScale * F_ia for doubly occupied orbitals (C' = C exp(kappa), kappa_ia = x_ia, kappa_ai = -x_ia).

Definition at line 170 of file convergenceacc.h.

◆ errhist_

std::vector<double> votca::xtp::ConvergenceAcc::errhist_
private

Definition at line 310 of file convergenceacc.h.

◆ error_history_

std::vector<double> votca::xtp::ConvergenceAcc::error_history_
private

Definition at line 288 of file convergenceacc.h.

◆ have_best_

bool votca::xtp::ConvergenceAcc::have_best_ = false
private

Definition at line 316 of file convergenceacc.h.

◆ iterations_since_reset_

Index votca::xtp::ConvergenceAcc::iterations_since_reset_ = kResetCooldown
private

Definition at line 326 of file convergenceacc.h.

◆ kAutoStartIteration

Index votca::xtp::ConvergenceAcc::kAutoStartIteration = 50
staticconstexprprivate

Definition at line 290 of file convergenceacc.h.

◆ kDensityMismatchTolerance

double votca::xtp::ConvergenceAcc::kDensityMismatchTolerance = 1e-8
staticconstexprprivate

Definition at line 270 of file convergenceacc.h.

◆ kEnergyRiseForADIIS

double votca::xtp::ConvergenceAcc::kEnergyRiseForADIIS = 1e-4
staticconstexprprivate

Definition at line 330 of file convergenceacc.h.

◆ kInitialTrustRadius

double votca::xtp::ConvergenceAcc::kInitialTrustRadius = 0.5
staticconstexprprivate

Definition at line 268 of file convergenceacc.h.

◆ kMaxConsecutiveFailures

Index votca::xtp::ConvergenceAcc::kMaxConsecutiveFailures = 5
staticconstexprprivate

Definition at line 289 of file convergenceacc.h.

◆ kMaxEnergyResets

Index votca::xtp::ConvergenceAcc::kMaxEnergyResets = 5
staticconstexprprivate

Definition at line 325 of file convergenceacc.h.

◆ kMeanRatioTolerance

double votca::xtp::ConvergenceAcc::kMeanRatioTolerance = 1.125
staticconstexprprivate

Definition at line 292 of file convergenceacc.h.

◆ kMinTrustRadius

double votca::xtp::ConvergenceAcc::kMinTrustRadius = 3e-3
staticconstexprprivate

Definition at line 269 of file convergenceacc.h.

◆ kRemovedShift

double votca::xtp::ConvergenceAcc::kRemovedShift = 1e3
staticconstexprprivate

Definition at line 303 of file convergenceacc.h.

◆ kResetCooldown

Index votca::xtp::ConvergenceAcc::kResetCooldown = 3
staticconstexprprivate

Definition at line 324 of file convergenceacc.h.

◆ kTrailingWindow

Index votca::xtp::ConvergenceAcc::kTrailingWindow = 10
staticconstexprprivate

Definition at line 291 of file convergenceacc.h.

◆ last_rejected_

bool votca::xtp::ConvergenceAcc::last_rejected_ = false
private

Definition at line 281 of file convergenceacc.h.

◆ log_

Logger* votca::xtp::ConvergenceAcc::log_
private

Definition at line 296 of file convergenceacc.h.

◆ mathist_

std::vector<Eigen::MatrixXd> votca::xtp::ConvergenceAcc::mathist_
private

Definition at line 308 of file convergenceacc.h.

◆ nocclevels_

Index votca::xtp::ConvergenceAcc::nocclevels_
private

Definition at line 332 of file convergenceacc.h.

◆ opt_

options votca::xtp::ConvergenceAcc::opt_
private

Definition at line 237 of file convergenceacc.h.

◆ orbital_hessian_

OrbitalHessian votca::xtp::ConvergenceAcc::orbital_hessian_
private

Definition at line 264 of file convergenceacc.h.

◆ removed_projector_

Eigen::MatrixXd votca::xtp::ConvergenceAcc::removed_projector_
private

Definition at line 302 of file convergenceacc.h.

◆ S_

const AOOverlap* votca::xtp::ConvergenceAcc::S_
private

Definition at line 297 of file convergenceacc.h.

◆ scf_iterations_

Index votca::xtp::ConvergenceAcc::scf_iterations_ = 0
private

Definition at line 287 of file convergenceacc.h.

◆ Sminusahalf

Eigen::MatrixXd votca::xtp::ConvergenceAcc::Sminusahalf
private

Definition at line 299 of file convergenceacc.h.

◆ totE_

std::vector<double> votca::xtp::ConvergenceAcc::totE_
private

Definition at line 313 of file convergenceacc.h.

◆ trah_active_

bool votca::xtp::ConvergenceAcc::trah_active_ = false
private

Definition at line 265 of file convergenceacc.h.

◆ trah_disabled_

bool votca::xtp::ConvergenceAcc::trah_disabled_ = false
private

Definition at line 267 of file convergenceacc.h.

◆ trah_linear_

double votca::xtp::ConvergenceAcc::trah_linear_ = 0.0
private

Definition at line 275 of file convergenceacc.h.

◆ trah_options_

trah::StepOptions votca::xtp::ConvergenceAcc::trah_options_
private

Definition at line 272 of file convergenceacc.h.

◆ trah_pending_

bool votca::xtp::ConvergenceAcc::trah_pending_ = false
private

Definition at line 266 of file convergenceacc.h.

◆ trah_pre_energy_

double votca::xtp::ConvergenceAcc::trah_pre_energy_ = 0.0
private

Definition at line 273 of file convergenceacc.h.

◆ trah_pre_H_

Eigen::MatrixXd votca::xtp::ConvergenceAcc::trah_pre_H_
private

Definition at line 278 of file convergenceacc.h.

◆ trah_pre_MOs_

tools::EigenSystem votca::xtp::ConvergenceAcc::trah_pre_MOs_
private

Definition at line 277 of file convergenceacc.h.

◆ trah_predicted_

double votca::xtp::ConvergenceAcc::trah_predicted_ = 0.0
private

Definition at line 274 of file convergenceacc.h.

◆ trah_step_norm_

double votca::xtp::ConvergenceAcc::trah_step_norm_ = 0.0
private

Definition at line 276 of file convergenceacc.h.

◆ trah_subspace_

trah::Subspace votca::xtp::ConvergenceAcc::trah_subspace_
private

Definition at line 280 of file convergenceacc.h.

◆ trust_

trah::TrustRadius votca::xtp::ConvergenceAcc::trust_ {kInitialTrustRadius}
private

Definition at line 271 of file convergenceacc.h.

◆ usedmixing_

bool votca::xtp::ConvergenceAcc::usedmixing_ = true
private

Definition at line 294 of file convergenceacc.h.


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