8#ifndef VOTCA_XTP_GW_UKS_H
9#define VOTCA_XTP_GW_UKS_H
12#include <unordered_set>
96 const Eigen::MatrixXd& vxc_alpha,
const Eigen::MatrixXd& vxc_beta,
97 const Eigen::VectorXd& dft_energies_alpha,
98 const Eigen::VectorXd& dft_energies_beta);
104 const Eigen::MatrixXd& beta) {
134 std::pair<double, double>
operator()(
double frequency)
const {
135 std::pair<double, double> result;
136 result.first =
value(frequency, EvalStage::Other);
137 result.second =
deriv(frequency);
145 if (!insert_result.second) {
146 ++
stats_.sigma_repeat_calls;
148 ++
stats_.sigma_unique_frequencies;
152 auto cached =
cache_.find(key);
153 if (cached !=
cache_.end()) {
154 return cached->second;
162 void Prefetch(
const std::vector<double>& frequencies)
const {
163 std::vector<double> todo;
164 for (
double f : frequencies) {
172 const Eigen::VectorXd values =
sigma_c_func_.CalcCorrelationDiagElements(
174 Eigen::Map<const Eigen::VectorXd>(todo.data(),
Index(todo.size())));
175 for (std::size_t i = 0; i < todo.size(); ++i) {
184 double deriv(
double frequency)
const {
195 std::uint64_t key = 0;
196 static_assert(
sizeof(double) ==
sizeof(std::uint64_t),
197 "Unexpected double size");
198 std::memcpy(&key, &x,
sizeof(
double));
204 case EvalStage::Scan:
205 ++
stats_.sigma_scan_calls;
207 case EvalStage::Refine:
208 ++
stats_.sigma_refine_calls;
210 case EvalStage::Derivative:
211 ++
stats_.sigma_derivative_calls;
213 case EvalStage::Other:
215 ++
stats_.sigma_other_calls;
225 mutable std::unordered_map<std::uint64_t, double>
cache_;
231 const Eigen::MatrixXd&
Vxc(
Spin spin)
const;
234 const Eigen::MatrixXd&
SigmaX(
Spin spin)
const;
235 const Eigen::MatrixXd&
SigmaC(
Spin spin)
const;
247 const Eigen::VectorXd& qp_diag_energies)
const;
248 Eigen::VectorXd
SolveQP(
Spin spin,
const Eigen::VectorXd& frequencies)
const;
263 const std::vector<QPRootCandidate>& roots,
264 double chosen)
const {
266 if (gw_level <
Index(list.size())) {
267 list[std::size_t(gw_level)] =
274 double frequency0,
Index gw_level,
275 QPStats* stats =
nullptr)
const;
278 Spin spin,
double intercept0,
double frequency0,
Index gw_level,
279 double left_limit,
double right_limit,
bool allow_rejected_return =
true,
280 QPStats* stats =
nullptr)
const;
283 Spin spin,
double intercept0,
double frequency0,
Index gw_level,
284 double left_limit,
double right_limit,
bool allow_rejected_return =
true,
285 QPStats* stats =
nullptr)
const;
288 Spin spin,
double intercept0,
double frequency0,
Index gw_level,
289 double left_limit,
double right_limit,
bool allow_rejected_return =
true,
290 QPStats* stats =
nullptr)
const;
293 double frequency0,
Index gw_level,
294 QPStats* stats =
nullptr)
const;
299 QPStats* stats =
nullptr)
const;
301 bool Converged(
const Eigen::VectorXd& e1,
const Eigen::VectorXd& e2,
302 double epsilon)
const;
305 double lowerbound,
double f_lowerbound,
double upperbound,
306 double f_upperbound,
const QPFunc& f,
double reference)
const;
void CountSigmaStage(EvalStage stage) const
std::pair< double, double > operator()(double frequency) const
std::unordered_set< std::uint64_t > seen_frequencies_
double sigma(double frequency, EvalStage stage=EvalStage::Other) const
const QPStats & GetStats() const
double deriv(double frequency) const
double value(double frequency, EvalStage stage=EvalStage::Other) const
static std::uint64_t FrequencyKey(double x)
void Prefetch(const std::vector< double > &frequencies) const
QPFunc(Index gw_level, const Sigma_base_UKS &sigma, double offset)
const Sigma_base_UKS & sigma_c_func_
std::unordered_map< std::uint64_t, double > cache_
boost::optional< double > SolveQP_Grid_Windowed(Spin spin, double intercept0, double frequency0, Index gw_level, double left_limit, double right_limit, bool allow_rejected_return=true, QPStats *stats=nullptr) const
Index TrackedLocalSolves() const
void PrintCompetingRoots(Spin spin, Log::Level level) const
TCMatrix_gwbse_spin & Mmn_
Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > DiagonalizeQPHamiltonianAlpha() const
Index ScreeningBuilds() const
bool Converged(const Eigen::VectorXd &e1, const Eigen::VectorXd &e2, double epsilon) const
Eigen::MatrixXd core_exchange_alpha_
void PrintQP_Energies(Spin spin, const Eigen::VectorXd &qp_diag_energies) const
Eigen::MatrixXd & SigmaC(Spin spin)
const Eigen::VectorXd & DftEnergies(Spin spin) const
std::unique_ptr< Sigma_base_UKS > sigma_alpha_
boost::optional< double > SolveQP_Linearisation(Spin spin, double intercept0, double frequency0, Index gw_level, QPStats *stats=nullptr) const
std::string LevelLabel(Spin spin, Index level) const
Eigen::VectorXd tracked_Z_[2]
Eigen::MatrixXd Sigma_x_alpha_
std::unique_ptr< Sigma_base_UKS > sigma_beta_
boost::optional< double > SolveQP_Grid_Windowed_Adaptive(Spin spin, double intercept0, double frequency0, Index gw_level, double left_limit, double right_limit, bool allow_rejected_return=true, QPStats *stats=nullptr) const
boost::optional< double > SolveQP_Grid(Spin spin, double intercept0, double frequency0, Index gw_level, QPStats *stats=nullptr) const
Eigen::MatrixXd Sigma_c_beta_
Eigen::MatrixXd & SigmaX(Spin spin)
Eigen::VectorXd getGWAResultsAlpha() const
boost::optional< QPRootCandidate > RefineQPInterval(double lowerbound, double f_lowerbound, double upperbound, double f_upperbound, const QPFunc &f, double reference) const
const Eigen::MatrixXd & vxc_alpha_
Eigen::VectorXd ScissorShift_DFTlevel(const Eigen::VectorXd &dft_energies, Index homo) const
const Eigen::VectorXd & RPAInputEnergiesAlpha() const
Index tracked_local_total_
qp_solver::WindowDiagnostics QPWindowDiagnostics
const char * OccupationTag(Spin spin, Index level) const
Eigen::MatrixXd core_exchange_beta_
Sigma_base_UKS & SigmaEvaluator(Spin spin)
Eigen::VectorXd SolveQP(Spin spin, const Eigen::VectorXd &frequencies) const
const Eigen::VectorXd & RPAInputEnergiesBeta() const
Eigen::MatrixXd getHQPBeta() const
void PrintGWA_Energies(Spin spin) const
Eigen::VectorXd tracked_change_[2]
Eigen::VectorXd getGWAResultsBeta() const
Eigen::MatrixXd getHQPAlpha() const
Eigen::MatrixXd Sigma_x_beta_
const char * SpinName(Spin spin) const
GW_UKS(Logger &log, TCMatrix_gwbse_spin &Mmn, const Eigen::MatrixXd &vxc_alpha, const Eigen::MatrixXd &vxc_beta, const Eigen::VectorXd &dft_energies_alpha, const Eigen::VectorXd &dft_energies_beta)
const Eigen::VectorXd & dft_energies_alpha_
double CalcSpinHomoLumoShift(const Eigen::VectorXd &frequencies, Spin spin) const
boost::optional< double > SolveQP_Grid_Windowed_Dense(Spin spin, double intercept0, double frequency0, Index gw_level, double left_limit, double right_limit, bool allow_rejected_return=true, QPStats *stats=nullptr) const
const Eigen::MatrixXd & vxc_beta_
const Eigen::VectorXd & dft_energies_beta_
qp_solver::EvalStage EvalStage
void setCoreExchange(const Eigen::MatrixXd &alpha, const Eigen::MatrixXd &beta)
Frozen-core exchange per spin, see GW::setCoreExchange.
qp_solver::RootCandidate QPRootCandidate
Index QPIterations() const
Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > DiagonalizeQPHamiltonianBeta() const
Eigen::MatrixXd Sigma_c_alpha_
const Eigen::MatrixXd & Vxc(Spin spin) const
std::vector< qp_solver::CompetingRoots > competing_roots_[2]
void configure(const options &opt)
void RecordCompetingRoots(Spin spin, Index gw_level, const std::vector< QPRootCandidate > &roots, double chosen) const
void CalculateGWPerturbation()
boost::optional< double > SolveQP_FixedPoint(Spin spin, double intercept0, double frequency0, Index gw_level, QPStats *stats=nullptr) const
Index Homo(Spin spin) const
Eigen::VectorXd tracked_root_[2]
Logger is used for thread-safe output of messages.
Unrestricted RPA helper for spin-resolved GW screening.
CompetingRoots CheckCompetingRoots(const std::vector< RootCandidate > &roots, double chosen)
Provides a means for comparing floating point numbers.
Index qp_adaptive_shell_count
std::string screening_update
double qp_virtual_min_energy
double screening_update_ratio
std::string quadrature_scheme
OutOfWindowShift out_of_window_shift
Index screening_update_max_inner
double qp_full_window_half_width
std::string qp_grid_search_mode
std::string sigma_integration
Index g_sc_max_iterations
std::string qp_root_finder
Index gw_sc_max_iterations
double qp_adaptive_shell_width
How the RPA energies of levels outside the GW window are shifted.