Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * PlanewaveEffectivePotential — planewave representation of the effective potential.
5 *
6 * Stores the total effective potential in real and reciprocal space, plus
7 * XC-specific reciprocal-space data and optional kinetic potential (meta-GGA).
8 *
9 * This is the canonical Layer 3 representation of the effective KS potential.
10 * The Layer 4 calculator populates this class rather than using a raw struct.
11 */
12
13#include <vector>
14
20
21namespace q3 {
22
23/// Type aliases for potential storage
24using SpinResolvedPotentialGrid = std::vector<std::vector<Real>>;
25using PotentialReciprocalCoefficients = std::vector<Complex>;
26
27/// Planewave effective potential — stores V(r) on FFT grid.
29 : public EffectivePotential,
30 public FFTransformable<SpinResolvedPotentialGrid, PotentialReciprocalCoefficients> {
31 public:
34 : basis_(&basis) {
36 int grid_points = basis.fft_rho().total_grid_points();
38 for (int spin_index = 0; spin_index < number_of_spin_components; spin_index++) {
39 real_space_data_[spin_index].assign(grid_points, 0.0);
40 }
41 int number_of_g_vectors = basis.number_of_g_vectors();
42 reciprocal_space_data_.resize(number_of_g_vectors, Complex(0.0, 0.0));
43 exchange_correlation_reciprocal_space_data_.resize(number_of_g_vectors, Complex(0.0, 0.0));
44 }
45
46 // ─── Spin-resolved access ───────────────────────────────────
47 std::vector<Real>& real_space_by_spin_index(int spin_index) {
48 return real_space_data_[spin_index];
49 }
50 [[nodiscard]] const std::vector<Real>& real_space_by_spin_index(int spin_index) const {
51 return real_space_data_[spin_index];
52 }
53
54 // ─── FFT transforms ────────────────────────────────────────
55 void to_reciprocal_space() override {
56 // FFT total potential to G-space
59 } else {
60 // For spin-polarized, FFT total (sum of spin channels)
61 int grid_points = basis_->fft_rho().total_grid_points();
62 std::vector<Real> total_potential(grid_points, 0.0);
63 for (int spin_index = 0; spin_index < number_of_spin_components_; spin_index++) {
64 for (int grid_point_index = 0; grid_point_index < grid_points; grid_point_index++) {
65 total_potential[grid_point_index] +=
66 real_space_data_[spin_index][grid_point_index];
67 }
68 }
69 basis_->rho_r_to_g(total_potential, reciprocal_space_data_);
70 }
71 }
72 void to_real_space() override {
75 }
76 }
77
78 // ─── XC reciprocal space ───────────────────────────────────
80 return exchange_correlation_reciprocal_space_data_;
81 }
82 [[nodiscard]] const std::vector<Complex>& exchange_correlation_reciprocal_space_data() const {
83 return exchange_correlation_reciprocal_space_data_;
84 }
85
86 // ─── Kinetic potential (meta-GGA) ──────────────────────────
87 std::vector<std::vector<Real>>& kinetic_potential_data() {
88 return kinetic_potential_data_;
89 }
90 [[nodiscard]] const std::vector<std::vector<Real>>& kinetic_potential_data() const {
91 return kinetic_potential_data_;
92 }
94 int grid_points = basis_ ? basis_->fft_rho().total_grid_points() : 0;
95 kinetic_potential_data_.resize(number_of_spin_components_);
96 for (int spin_index = 0; spin_index < number_of_spin_components_; spin_index++) {
97 kinetic_potential_data_[spin_index].assign(grid_points, 0.0);
98 }
99 }
100
101 // ─── Energy results (populated by calculator) ──────────────
105
106 // ─── Charge density G-space (set by calculator) ────────────
107 std::vector<Complex>& charge_density_reciprocal() {
108 return charge_density_reciprocal_;
109 }
110 [[nodiscard]] const std::vector<Complex>& charge_density_reciprocal() const {
111 return charge_density_reciprocal_;
112 }
113
114 // ─── Basis access ──────────────────────────────────────────
115 [[nodiscard]] const PlanewaveBasis& basis() const {
116 return *basis_;
117 }
118 [[nodiscard]] int grid_size() const {
119 return basis_ ? basis_->fft_rho().total_grid_points() : 0;
120 }
121
122 // ─── Logging ───────────────────────────────────────────────
123 void log_summary() const {
124 log::info(" Effective potential summary:");
125 log::info(" grid points = {}", grid_size());
126 log::info(" spin components = {}", number_of_spin_components_);
127 log::info(" Hartree energy = {:.9f} Ry", hartree_energy);
128 log::info(" XC energy = {:.9f} Ry", exchange_correlation_energy);
129 }
130
131 private:
132 const PlanewaveBasis* basis_ = nullptr;
133 std::vector<Complex> exchange_correlation_reciprocal_space_data_;
134 std::vector<std::vector<Real>> kinetic_potential_data_;
135 std::vector<Complex> charge_density_reciprocal_;
136};
137
138} // namespace q3
Abstract effective potential — the self-consistent field acting on electrons.
virtual int total_grid_points() const =0
int number_of_g_vectors() const
Definition init.hpp:145
void rho_g_to_r(const std::vector< Complex > &charge_density_g_space, std::vector< Real > &charge_density_real_space) const
Definition init.hpp:328
void rho_r_to_g(const std::vector< Real > &charge_density_real_space, std::vector< Complex > &charge_density_g_space) const
Definition init.hpp:334
FFTGrid & fft_rho()
Definition init.hpp:286
Planewave effective potential — stores V(r) on FFT grid.
Definition init.hpp:30
PlanewaveEffectivePotential(const PlanewaveBasis &basis, int number_of_spin_components)
Definition init.hpp:33
void to_real_space() override
Definition init.hpp:72
void to_reciprocal_space() override
Definition init.hpp:55
std::vector< Real > & real_space_by_spin_index(int spin_index)
Definition init.hpp:47
const PlanewaveBasis & basis() const
Definition init.hpp:115
const std::vector< Real > & real_space_by_spin_index(int spin_index) const
Definition init.hpp:50
const std::vector< std::vector< Real > > & kinetic_potential_data() const
Definition init.hpp:90
std::vector< std::vector< Real > > & kinetic_potential_data()
Definition init.hpp:87
std::vector< Complex > & exchange_correlation_reciprocal_space_data()
Definition init.hpp:79
const std::vector< Complex > & charge_density_reciprocal() const
Definition init.hpp:110
const std::vector< Complex > & exchange_correlation_reciprocal_space_data() const
Definition init.hpp:82
std::vector< Complex > & charge_density_reciprocal()
Definition init.hpp:107
void info(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:183
std::vector< Complex > PotentialReciprocalCoefficients
Definition init.hpp:25
double Real
std::vector< std::vector< Real > > SpinResolvedPotentialGrid
Type aliases for potential storage.
Definition init.hpp:24
std::complex< double > Complex