votca 2026-dev
Loading...
Searching...
No Matches
screening_update.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_SCREENING_UPDATE_H
22#define VOTCA_XTP_SCREENING_UPDATE_H
23
24// Standard includes
25#include <stdexcept>
26#include <string>
27
28// Local VOTCA includes
29#include "eigen.h"
30
31namespace votca {
32namespace xtp {
33
57 public:
58 enum class Mode { Every, Adaptive };
59 enum class Next { Continue, Rebuild, Converged };
60
61 static Mode Parse(const std::string& name) {
62 if (name == "every") {
63 return Mode::Every;
64 } else if (name == "adaptive") {
65 return Mode::Adaptive;
66 }
67 throw std::runtime_error("Unknown gw.screening_update '" + name +
68 "'; choices are every, adaptive");
69 }
70 static std::string Name(Mode mode) {
71 return (mode == Mode::Adaptive) ? "adaptive" : "every";
72 }
73
74 void Configure(Mode mode, double ratio, Index max_inner) {
75 mode_ = mode;
76 ratio_ = ratio;
77 max_inner_ = max_inner;
78 }
79 Mode mode() const { return mode_; }
80
82 void Built(const Eigen::VectorXd& energies) {
83 built_from_ = energies;
84 inner_ = 0;
85 ++builds_;
86 }
87 Index builds() const { return builds_; }
89 Index inner() const { return inner_; }
90
95 Next Decide(double residual, const Eigen::VectorXd& new_energies,
96 double limit, double* drift_out = nullptr) {
97 ++inner_;
98 const double step = residual;
99 const double drift = (new_energies - built_from_).cwiseAbs().maxCoeff();
100 if (drift_out != nullptr) {
101 *drift_out = drift;
102 }
103 if (mode_ == Mode::Every) {
104 return (step < limit) ? Next::Converged : Next::Rebuild;
105 }
106 if (step < limit) {
107 return (drift < limit) ? Next::Converged : Next::Rebuild;
108 }
109 if (step < ratio_ * drift || inner_ >= max_inner_) {
110 return Next::Rebuild;
111 }
112 return Next::Continue;
113 }
114
115 private:
117 double ratio_ = 0.25;
119 Eigen::VectorXd built_from_;
122};
123
124} // namespace xtp
125} // namespace votca
126
127#endif // VOTCA_XTP_SCREENING_UPDATE_H
When evGW rebuilds the screening W.
void Built(const Eigen::VectorXd &energies)
W has just been built from these energies.
void Configure(Mode mode, double ratio, Index max_inner)
static std::string Name(Mode mode)
Next Decide(double residual, const Eigen::VectorXd &new_energies, double limit, double *drift_out=nullptr)
static Mode Parse(const std::string &name)
Index inner() const
QP iterations since W was last built (before the current one).
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26