Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * NormConservingPlanewaveEffectivePotentialCalculator — extends the base
5 * effective potential calculator to include the nonlinear core correction (NLCC)
6 * core charge density in the exchange-correlation density.
7 *
8 * For pseudopotentials without NLCC, the core charge density vector is empty
9 * and this class behaves identically to the base class.
10 */
11
12#include <vector>
13
19
20namespace q3 {
21
24 public:
26 const PlanewaveBasis& planewave_basis,
27 const Crystal& crystal_structure,
28 const XCFunctional& exchange_correlation,
29 const execution::PlanewaveExecutionPolicy& execution_policy,
30 const std::vector<Complex>& core_charge_density_g)
32 planewave_basis, crystal_structure, exchange_correlation, execution_policy)
33 , core_charge_density_g_(core_charge_density_g) {}
34
35 protected:
36 /**
37 * Build the XC density including the NLCC core charge.
38 * Adds the core charge density (split equally among spin channels) to the
39 * valence charge density, in both real and reciprocal space.
40 * Caches the real-space core charge density to avoid redundant FFTs.
41 */
43 const std::vector<std::vector<Real>>& charge_density_real,
44 int number_of_spin_components,
45 std::vector<std::vector<Real>>& exchange_correlation_density,
46 std::vector<std::vector<Complex>>& exchange_correlation_density_g) const override {
47 int number_of_g_vectors = planewave_basis_.number_of_g_vectors();
48 int local_grid_points = planewave_basis_.fft_rho().local_grid_points();
49
50 exchange_correlation_density.assign(number_of_spin_components,
51 std::vector<Real>(local_grid_points));
52 exchange_correlation_density_g.assign(number_of_spin_components,
53 std::vector<Complex>(number_of_g_vectors));
54
55 // Cache the real-space core charge density (constant throughout SCF)
56 if (!core_charge_density_g_.empty() && cached_core_charge_density_real_.empty()) {
57 planewave_basis_.rho_g_to_r(core_charge_density_g_, cached_core_charge_density_real_);
58 }
59
60 for (int spin_index = 0; spin_index < number_of_spin_components; ++spin_index) {
61 for (int grid_index = 0; grid_index < local_grid_points; ++grid_index) {
62 exchange_correlation_density[spin_index][grid_index] =
63 charge_density_real[spin_index][grid_index];
64 }
65 if (!cached_core_charge_density_real_.empty()) {
66 for (int grid_index = 0; grid_index < local_grid_points; ++grid_index) {
67 exchange_correlation_density[spin_index][grid_index] +=
68 cached_core_charge_density_real_[grid_index] / number_of_spin_components;
69 }
70 }
71
72 planewave_basis_.rho_r_to_g(charge_density_real[spin_index],
73 exchange_correlation_density_g[spin_index]);
74 for (int g_vector_index = 0;
75 g_vector_index < static_cast<int>(core_charge_density_g_.size());
76 ++g_vector_index) {
77 exchange_correlation_density_g[spin_index][g_vector_index] +=
78 core_charge_density_g_[g_vector_index] /
79 static_cast<Real>(number_of_spin_components);
80 }
81 }
82 }
83
84 private:
85 const std::vector<Complex>& core_charge_density_g_;
86 mutable std::vector<Real> cached_core_charge_density_real_;
87};
88
89} // namespace q3
virtual int local_grid_points() const =0
void build_exchange_correlation_density(const std::vector< std::vector< Real > > &charge_density_real, int number_of_spin_components, std::vector< std::vector< Real > > &exchange_correlation_density, std::vector< std::vector< Complex > > &exchange_correlation_density_g) const override
Definition init.hpp:42
NormConservingPlanewaveEffectivePotentialCalculator(const PlanewaveBasis &planewave_basis, const Crystal &crystal_structure, const XCFunctional &exchange_correlation, const execution::PlanewaveExecutionPolicy &execution_policy, const std::vector< Complex > &core_charge_density_g)
Definition init.hpp:25
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
const PlanewaveBasis & planewave_basis_
Definition init.hpp:112
Abstract base class for XC functionals.
Definition init.hpp:23
double Real