Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * OverlapOperator — the S operator of the generalized eigenproblem H c = ε S c,
5 * expressed purely in the plane-wave basis.
6 *
7 * When the basis is orthonormal, S = I and the eigenproblem is standard (zheev).
8 * When the basis carries an additional overlap, S becomes non-trivial and the
9 * eigenproblem is generalized (zhegv). This strategy isolates that difference so
10 * the Davidson and direct diagonalizers share a single, branch-free eigensolver
11 * path. Concrete operators inject whatever physical data they require through
12 * their constructors, keeping this interface free of any model-specific concepts.
13 */
14
15#include <complex>
16#include <vector>
17
19
21
22namespace q3 {
23
25 public:
26 virtual ~OverlapOperator() = default;
27
28 // Apply S to a single wavefunction: overlap_wavefunction = S · wavefunction.
29 virtual void apply(int number_of_plane_waves,
30 const Complex* wavefunction,
31 Complex* overlap_wavefunction) const = 0;
32
33 /**
34 * Apply S to multiple wavefunctions in batch.
35 * wavefunctions[vector_index * number_of_plane_waves + g] and
36 * overlap_wavefunctions[vector_index * number_of_plane_waves + g]. Default: calls per-vector
37 * apply() in a loop. Subclasses may override for efficiency.
38 */
39 virtual void apply_batch(int number_of_plane_waves,
40 int number_of_vectors,
41 const Complex* wavefunctions,
42 Complex* overlap_wavefunctions) const {
43 for (int vector_index = 0; vector_index < number_of_vectors; ++vector_index) {
44 apply(number_of_plane_waves,
45 wavefunctions + static_cast<size_t>(vector_index) * number_of_plane_waves,
46 overlap_wavefunctions +
47 static_cast<size_t>(vector_index) * number_of_plane_waves);
48 }
49 }
50
51 /**
52 * Returns true if S = I (norm-conserving case).
53 * When true, Davidson can skip S·ψ ZGEMM and S_sub construction.
54 */
55 [[nodiscard]] virtual bool is_identity() const {
56 return false;
57 }
58
59 /**
60 * Build the dense overlap matrix S (column-major, number_of_plane_waves ×
61 * number_of_plane_waves) used by the direct solver. An orthonormal basis
62 * leaves it empty (S = I is implicit in the standard solver).
63 */
64 virtual void build_dense_matrix(int number_of_plane_waves,
65 std::vector<Complex>& overlap_matrix) const = 0;
66};
67
68} // namespace q3
virtual void apply(int number_of_plane_waves, const Complex *wavefunction, Complex *overlap_wavefunction) const =0
virtual void build_dense_matrix(int number_of_plane_waves, std::vector< Complex > &overlap_matrix) const =0
virtual void apply_batch(int number_of_plane_waves, int number_of_vectors, const Complex *wavefunctions, Complex *overlap_wavefunctions) const
Definition init.hpp:39
virtual bool is_identity() const
Definition init.hpp:55
virtual ~OverlapOperator()=default
std::complex< double > Complex