Loading...
Searching...
No Matches
diagnostic_error.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * WannierDiagnosticError — a failure of the Wannier construction that a
5 * driver can act on: the prose a person reads, the WannierDiagnostic a driver
6 * routes on, and -- for a disentanglement out of iterations -- the spreads it
7 * reached, as numbers.
8 *
9 * A DiagnosticError, so the utility prints the code -- and the spreads, when
10 * there are any -- on lines of their own after the prose without knowing
11 * that it was this method that failed; the code and the spreads as values
12 * are there for the catch that knows to ask.
13 */
14
15#include <stdexcept>
16#include <string>
17#include <utility>
18#include <vector>
19
24
25namespace q3 {
26
28 public:
30 const std::string& message,
31 std::vector<Real> spreads_bohr_squared = {})
32 : DiagnosticError(message)
33 , diagnostic_(diagnostic)
34 , spreads_bohr_squared_(std::move(spreads_bohr_squared)) {}
35
36 [[nodiscard]] WannierDiagnostic diagnostic() const {
37 return diagnostic_;
38 }
39
40 /**
41 * For disentanglement_unconverged: the last gauge-invariant spreads the
42 * iteration reached, oldest first, in bohr squared -- the numbers the
43 * retry ladder loosens its tolerance from. Empty for every other code.
44 */
45 [[nodiscard]] const std::vector<Real>& spreads_bohr_squared() const {
46 return spreads_bohr_squared_;
47 }
48
49 /// The spreads as "a, b, c" with six decimals each, the form the prose names them in.
50 [[nodiscard]] std::string spreads_text() const {
51 return ConvergenceWindow::history_text(spreads_bohr_squared_);
52 }
53
54 /// `diagnostic: <code>`, and the spreads on a line of their own when there are any.
55 [[nodiscard]] std::vector<std::string> diagnostic_lines() const override {
56 std::vector<std::string> lines{"diagnostic: " + wannier_diagnostic_name(diagnostic_)};
57 if (!spreads_bohr_squared_.empty()) {
58 lines.push_back("diagnostic_spreads_bohr_squared: " + spreads_text());
59 }
60 return lines;
61 }
62
63 private:
64 WannierDiagnostic diagnostic_;
65 std::vector<Real> spreads_bohr_squared_;
66};
67
68} // namespace q3
static std::string history_text(const std::vector< Real > &values)
std::vector< std::string > diagnostic_lines() const override
diagnostic: <code>, and the spreads on a line of their own when there are any.
std::string spreads_text() const
The spreads as "a, b, c" with six decimals each, the form the prose names them in.
WannierDiagnosticError(WannierDiagnostic diagnostic, const std::string &message, std::vector< Real > spreads_bohr_squared={})
WannierDiagnostic diagnostic() const
const std::vector< Real > & spreads_bohr_squared() const
std::string wannier_diagnostic_name(WannierDiagnostic diagnostic)
The enumerator's own spelling, which is what the diagnostic: line prints.
WannierDiagnostic