Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * PlanewaveDiagonalizer — planewave-specific eigenvalue solver interface.
5 *
6 * Extends the generic Diagonalizer with the planewave-specific solve()
7 * contract, cached KB projector management, and smooth potential cache
8 * invalidation. Concrete implementations (PlanewaveDirectDiagonalizer,
9 * PlanewaveDavidsonDiagonalizer) inherit from this class.
10 */
11
12#include <memory>
13#include <string>
14#include <vector>
15
22
23namespace q3 {
24
25// Planewave-specific abstract interface for eigenvalue solvers.
27 public:
28 ~PlanewaveDiagonalizer() override = default;
29
30 /**
31 * Solve the KS eigenvalue problem at one k-point.
32 * For NC-PP: H·ψ = ε·ψ (standard eigenvalue problem)
33 * For US-PP: H·ψ = ε·S·ψ (generalized eigenvalue problem)
34 */
35 virtual void
36 solve(int kpoint_index_state,
37 int kpoint_index,
38 int number_of_plane_waves,
39 int number_of_bands,
40 const std::vector<int>& g_vector_indices,
41 const std::vector<Real>& kinetic_energy_squared,
42 const std::vector<Real>& real_space_potential,
43 const Crystal& crystal_structure,
44 const KPointsGrid& kpoint_grid,
45 const PlanewaveBasis& planewave_basis,
46 const NormConservingPlanewaveKohnShamQuantumSystem& pseudopotential_quantum_system,
47 PlanewaveKohnShamQuantumSystem& quantum_system) = 0;
48
49 /**
50 * Set pre-computed KB projectors for a specific k-point.
51 * If set, the solver may use these instead of recomputing them.
52 * No-op by default; overridden by solvers that support caching.
53 */
54 virtual void set_cached_projectors(int /*kpoint_index*/,
55 const q3::Matrix<Complex>* /*projectors*/) {}
56
57 /**
58 * Size the iterative working basis, as a multiple of the band count.
59 *
60 * No-op for solvers that do not build one -- the direct diagonalizer forms
61 * the whole Hamiltonian and has no working basis to size.
62 */
63 virtual void set_basis_expansion_factor(int /*factor*/) {}
64
65 /**
66 * Cap the iterations one solve() may take before it returns what it has.
67 *
68 * No-op for solvers that are not iterative.
69 */
70 virtual void set_maximum_iterations(int /*maximum_iterations*/) {}
71
72 /**
73 * How many bands the last solve() returned without meeting its tolerance:
74 * zero when it converged, and always zero for a solver that is not
75 * iterative.
76 */
77 [[nodiscard]] virtual int number_of_unconverged_bands() const {
78 return 0;
79 }
80
81 /**
82 * Free the working arrays once nothing will call solve() again in this
83 * run: the eigenvectors live in the quantum system and survive, the
84 * working basis and its Hamiltonian image do not need to. A later solve()
85 * allocates afresh. No-op for solvers without a persistent workspace.
86 */
87 virtual void release_workspace() {}
88
89 /**
90 * Set pre-computed DFT+U (Hubbard) atomic-orbital projectors for a specific k-point.
91 * No-op by default; overridden by solvers that support DFT+U (v1: Davidson only).
92 */
93 virtual void set_cached_hubbard_projectors(int /*kpoint_index*/,
94 const q3::Matrix<Complex>* /*projectors*/) {}
95
96 /**
97 * Set the dense block-diagonal Hubbard D-matrix (see PlanewaveHamiltonianApplicator).
98 * No-op by default; overridden by solvers that support DFT+U (v1: Davidson only).
99 */
100 virtual void set_hubbard_d_matrix(const std::vector<Complex>* /*dense_d_matrix_column_major*/) {
101 }
102
103 /**
104 * Invalidate any cached smooth grid potential.
105 * Called by the SCF iterator when the effective potential changes.
106 * No-op by default; overridden by solvers that cache the smooth potential.
107 */
109};
110
111} // namespace q3
virtual int number_of_unconverged_bands() const
Definition init.hpp:77
virtual void invalidate_smooth_potential_cache()
Definition init.hpp:108
~PlanewaveDiagonalizer() override=default
virtual void set_hubbard_d_matrix(const std::vector< Complex > *)
Definition init.hpp:100
virtual void set_cached_projectors(int, const q3::Matrix< Complex > *)
Definition init.hpp:54
virtual void release_workspace()
Definition init.hpp:87
virtual void set_basis_expansion_factor(int)
Definition init.hpp:63
virtual void solve(int kpoint_index_state, int kpoint_index, int number_of_plane_waves, int number_of_bands, const std::vector< int > &g_vector_indices, const std::vector< Real > &kinetic_energy_squared, const std::vector< Real > &real_space_potential, const Crystal &crystal_structure, const KPointsGrid &kpoint_grid, const PlanewaveBasis &planewave_basis, const NormConservingPlanewaveKohnShamQuantumSystem &pseudopotential_quantum_system, PlanewaveKohnShamQuantumSystem &quantum_system)=0
virtual void set_cached_hubbard_projectors(int, const q3::Matrix< Complex > *)
Definition init.hpp:93
virtual void set_maximum_iterations(int)
Definition init.hpp:70