Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
core_charge_density_table.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * CoreChargeDensityTable — tabulated core charge density on a uniform q-grid.
5 *
6 * Pre-computes ρ_core(q) for each species on the same uniform q-grid used by
7 * BetaFunctionTable, enabling O(1) interpolation instead of O(N_radial)
8 * Simpson integration per q-point. This eliminates a significant bottleneck
9 * in stress tensor core-correction calculations.
10 */
11
12#include <cmath>
13#include <vector>
14
20
21namespace q3 {
22
24 public:
26
27 /**
28 * Initialize the table by evaluating ρ_core(q) on a uniform q-grid for each species.
29 */
31 const PseudopotentialSet& pseudopotential_set,
32 const std::vector<int>& mesh_sizes,
33 int number_of_species_types) {
34 q_grid_ = q_grid;
35 std::vector<Real> q_point_values = q_grid_.q_point_values();
36
37 table_.resize(number_of_species_types);
38 has_core_charge_.resize(number_of_species_types, false);
39 for (int type_index = 0; type_index < number_of_species_types; type_index++) {
40 const auto& pseudopotential = pseudopotential_set[type_index];
41 if (!pseudopotential.has_nonlinear_core_correction) {
42 table_[type_index].resize(q_grid_);
43 continue;
44 }
45 has_core_charge_[type_index] = true;
46 table_[type_index].resize(q_grid_);
47 for (int q_index = 0; q_index < q_grid_.number_of_q_points; q_index++) {
48 table_[type_index][q_index] = calculate_core_charge_density_at_q(
49 pseudopotential, mesh_sizes[type_index], q_point_values[q_index]);
50 }
51 }
52 }
53
54 /**
55 * Interpolate ρ_core(q) for a given species at arbitrary q value.
56 */
57 [[nodiscard]] Real interpolate(int species_type_index, Real q_value) const {
58 if (!has_core_charge_[species_type_index]) {
59 return 0.0;
60 }
61 return table_[species_type_index].interpolate(q_value);
62 }
63
64 /**
65 * Interpolate the derivative dρ_core/dq for a given species at arbitrary q value.
66 */
67 [[nodiscard]] Real interpolate_derivative(int species_type_index, Real q_value) const {
68 if (!has_core_charge_[species_type_index]) {
69 return 0.0;
70 }
71 return table_[species_type_index].interpolate_derivative(q_value);
72 }
73
74 [[nodiscard]] const UniformQGrid& q_grid() const {
75 return q_grid_;
76 }
77
78 [[nodiscard]] bool has_core_charge_for_species(int species_type_index) const {
79 return has_core_charge_[species_type_index];
80 }
81
82 private:
83 UniformQGrid q_grid_;
84 std::vector<UniformQGridTable> table_;
85 std::vector<bool> has_core_charge_;
86};
87
88} // namespace q3
bool has_core_charge_for_species(int species_type_index) const
const UniformQGrid & q_grid() const
Real interpolate(int species_type_index, Real q_value) const
Real interpolate_derivative(int species_type_index, Real q_value) const
void initialize(const UniformQGrid &q_grid, const PseudopotentialSet &pseudopotential_set, const std::vector< int > &mesh_sizes, int number_of_species_types)
Real calculate_core_charge_density_at_q(const Pseudopotential &pseudopotential, int mesh_size, Real q_value)
double Real
std::vector< Real > q_point_values() const