Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * IsolatedSystemCorrectionCalculator — abstract interface for isolated-system
5 * (finite-size electrostatic) correction schemes.
6 *
7 * A charged or dipolar system computed in periodic boundary conditions
8 * carries a spurious electrostatic interaction with its own periodic images;
9 * a correction scheme estimates and removes it from the total energy after
10 * SCF convergence. Concrete schemes (Makov-Payne and Martyna-Tuckerman
11 * today; point-countercharge and slab/ESM-style corrections are the natural
12 * future additions, mirroring QE's assume_isolated options) implement this
13 * interface and are selected by name through
14 * create_isolated_system_correction_calculator() (factory.hpp), so
15 * orchestrators never branch on the scheme themselves -- "none" resolves to
16 * NullIsolatedSystemCorrectionCalculator (null.hpp), which reports "nothing
17 * applied", removing the need for any if/else at the call sites.
18 *
19 * The result is deliberately scheme-agnostic: a list of labeled additive
20 * energy terms rather than fixed fields, because the breakdown differs per
21 * scheme (Makov-Payne has a monopole and a dipole+quadrupole term;
22 * Martyna-Tuckerman reports a single reciprocal-space term, see
23 * MartynaTuckermanCorrectionCalculator -- its docstring also explains why
24 * this is the post-SCF evaluation of MT, distinct from QE's self-consistent
25 * assume_isolated='m-t'). Every term already carries the sign such that
26 * corrected_total_energy = total_energy + sum(terms).
27 */
28
29#include <string>
30#include <utility>
31#include <vector>
32
35
36namespace q3 {
37
38/**
39 * Outcome of one correction scheme's evaluation.
40 *
41 * `applied` is false only for the Null scheme ("none"); reporting code keys
42 * off it to decide whether to emit anything. `terms_in_ry` are the labeled
43 * additive contributions (labels are snake_case and become the
44 * `<label>_ry` keys in results.json).
45 */
47 bool applied = false;
48 std::string method = "none";
49 std::vector<std::pair<std::string, Real>> terms_in_ry;
50
51 [[nodiscard]] Real total_in_ry() const {
52 Real total = 0.0;
53 for (const auto& [label, value] : terms_in_ry) {
54 total += value;
55 }
56 return total;
57 }
58};
59
61 public:
63
64 /**
65 * Evaluate the correction on a converged SCF state. Schemes that have
66 * geometric preconditions (Makov-Payne: cubic lattice) throw
67 * std::runtime_error before touching any density data when violated.
68 */
69 [[nodiscard]] virtual IsolatedSystemCorrectionResult
71
72 /// Scheme name as accepted by the input ("none", "makov-payne", ...).
73 [[nodiscard]] virtual std::string name() const = 0;
74};
75
76} // namespace q3
virtual std::string name() const =0
Scheme name as accepted by the input ("none", "makov-payne", ...).
virtual IsolatedSystemCorrectionResult compute(const NormConservingPlanewaveKohnShamSCFState &scf_state) const =0
virtual ~IsolatedSystemCorrectionCalculator()=default
double Real
std::vector< std::pair< std::string, Real > > terms_in_ry
Definition init.hpp:49