Loading...
Searching...
No Matches
q3::PlanewaveKohnShamSCFIterator Class Referenceabstract

#include <init.hpp>

+ Inheritance diagram for q3::PlanewaveKohnShamSCFIterator:

Public Member Functions

 PlanewaveKohnShamSCFIterator (KohnShamSCFIteratorConfig config)
 
 ~PlanewaveKohnShamSCFIterator () override=default
 
Real eigenvalue (int kpoint_index, int band_index) const
 
Matrix< Real > eigenvalues () const
 
const execution::PlanewaveExecutionPolicy & execution_policy () const
 
const std::vector< std::vector< int > > & g_vector_indices () const
 
const std::vector< int > & g_vector_indices (int kpoint_index) const
 
Matrix< Real > global_eigenvalues () const
 
const std::vector< std::vector< Real > > & kinetic_energy_squared () const
 
const KPointsGrid & kpoint_grid () const
 
void load_quantum_system (const PlanewaveKohnShamQuantumSystem &system)
 
bool loaded_charge_density_fits_grid () const
 
const std::optional< Magnetization > & magnetization () const
 
int number_of_bands () const override
 
Real number_of_electrons () const override
 
int number_of_kpoint_states () const override
 
int number_of_occupied_bands_per_spin () const
 
const std::vector< int > & number_of_plane_waves () const
 
int number_of_plane_waves (int kpoint_index) const
 
Real occupation (int kpoint_index, int band_index) const
 
const PlanewaveBasis & planewave_basis () const
 
void preload_charge_density ()
 
void preload_single_particle_states ()
 
const PlanewaveKohnShamQuantumSystem & quantum_system () const
 
virtual void release_scf_workspace ()
 
virtual NormConservingPlanewaveKohnShamSCFState result () const =0
 
void scale_loaded_charge_density_to_electron_count ()
 Rescale the loaded density so it integrates to this system's electron count.
 
void set_diagonalizer (std::unique_ptr< PlanewaveDiagonalizer > diagonalizer)
 
void set_owned_execution_policy (std::unique_ptr< execution::PlanewaveExecutionPolicy > policy)
 
void set_owned_kpoint_grid (KPointsGrid kpoint_grid)
 Transfer ownership of a KPointsGrid into this iterator.
 
Real spin_degeneracy () const
 
Complex wavefunction (int kpoint_index, int band_index, int g_vector_index) const
 
- Public Member Functions inherited from q3::KohnShamSCFIterator
 KohnShamSCFIterator (KohnShamSCFIteratorConfig config)
 
 ~KohnShamSCFIterator () override=default
 
const std::vector< Real > & charge_density_for_spin (int spin_index) const
 
const std::vector< Complex > & charge_density_g () const
 
const std::vector< Real > & charge_density_real () const
 
Crystal & crystal_structure () const
 
virtual const KohnShamEnergies & energies () const =0
 
virtual KohnShamEnergies & energies_mutable ()=0
 
const XCFunctional & exchange_correlation () const
 
const std::vector< Complex > & exchange_correlation_potential_g () const
 
void load_charge_density (std::vector< std::vector< Real > > charge_density)
 
void load_effective_potential (std::vector< std::vector< Real > > effective_potential)
 
void offer_starting_charge_density (std::vector< std::vector< Real > > charge_density)
 
const std::vector< Real > & potential_for_spin (int spin_index) const
 
const std::vector< Real > & real_space_potential () const
 
const std::vector< ScfIterationRecord > & scf_history () const
 
Real total_energy () const override
 
const std::vector< Complex > & total_potential_g () const
 
- Public Member Functions inherited from q3::SCFIterator
 SCFIterator (SCFIteratorConfig config)
 
virtual ~SCFIterator ()=default
 
bool is_converged () const
 
int iteration () const
 
int number_of_spin_components () const
 
void run ()
 
void set_convergence_threshold (Real threshold)
 Set the SCF convergence threshold (in Ry).
 
void set_maximum_iterations (int maximum_iterations)
 Set the maximum number of SCF iterations.
 
void set_owned_crystal (Crystal crystal)
 Transfer ownership of a Crystal into this iterator.
 
const std::vector< Real > & total_energy_history_in_ry () const
 
virtual void write_checkpoints (const std::string &output_directory, const std::string &prefix) const
 

Protected Member Functions

void allocate_electronic_states ()
 
void build_kpoint_plane_wave_data ()
 
Real compute_delta_escf_correction () const override
 
Real compute_density_residual (const std::vector< std::vector< Real > > &input_density_for_mixing) const override
 
Real compute_double_counting_correction () const override
 
virtual void compute_effective_potential_from_density ()=0
 
void compute_energy_components () override
 
Real compute_local_residual_between (const std::vector< std::vector< Real > > &density_in, const std::vector< std::vector< Real > > &density_out) const
 
Real compute_number_of_electrons () const
 
Real compute_residual_between (const std::vector< std::vector< Real > > &density_in, const std::vector< std::vector< Real > > &density_out) const
 
void construct_density_from_states () override
 
virtual const std::vector< Complex > & core_charge_density_g () const =0
 
Real effective_charge_density_energy_cutoff () const
 
Real hartree_metric_prefactor () const
 
void initialize_representation () override
 
void initiate_mixer () override
 
std::vector< std::vector< Real > > input_density_for_mixing () const override
 
virtual const std::vector< Complex > & local_ionic_potential_g () const =0
 
void log_representation_summary () const
 
Real magnetization_metric_weight () const
 
void mix_density (const std::vector< std::vector< Real > > &input_density_for_mixing) override
 
virtual void on_charge_density_initialized ()
 
const PlanewaveKohnShamEnergies & planewave_energies () const
 
PlanewaveKohnShamEnergies & planewave_energies_mutable ()
 
void report_convergence_details () override
 
void report_first_iteration_details () override
 
int resolve_number_of_bands () const
 
void restore_density_at_convergence () override
 
void set_diagonalization_tolerance (int iteration) override
 
void set_diagonalizer_tolerance (Real tolerance) override
 
void snapshot_output_density () override
 
void symmetrize_density () override
 
void update_effective_potential () override
 
void update_occupations () override
 
void warn_if_total_charge_deviates () const
 
- Protected Member Functions inherited from q3::KohnShamSCFIterator
const KohnShamSCFIteratorConfig & config () const
 
Real diagonalization_threshold () const
 
void finalize () override
 
void initialize () override
 Base implementation prints the SCF banner. Children call SCFIterator::initialize() last.
 
virtual void initialize_charge_density ()=0
 
virtual void initialize_single_particle_states ()=0
 
bool is_iteration_converged () const override
 
void log_iteration_energy (Real delta_energy)
 Single source of truth for the per-iteration energy/convergence log line.
 
void perform_iteration () override
 
virtual void prepare_hamiltonian ()
 
void report_convergence () override
 
void report_iteration () override
 
void report_non_convergence () override
 
virtual void solve_single_particle_states ()=0
 
virtual void synchronize_smooth_density_from_mixed ()
 
- Protected Member Functions inherited from q3::SCFIterator
virtual void iterate ()
 Main iteration loop.
 
virtual void report ()
 Report convergence or non-convergence after iterate() finishes.
 

Protected Attributes

std::vector< Real > cached_local_ionic_potential_real_
 Cached real-space ionic local potential (constant during SCF, avoids repeated FFTs).
 
std::unique_ptr< PlanewaveChargeDensityAccumulator > charge_density_accumulator_
 Accumulates real-space charge density from wavefunctions each SCF iteration.
 
Real charge_density_energy_cutoff_ = 0.0
 
std::vector< std::vector< Real > > convergence_output_density_
 Converged output density snapshot, restored once self-consistency is reached.
 
PlanewaveChargeDensitySymmetrizer density_symmetrizer_
 
std::string diagonalization_method_ = "davidson"
 
std::unique_ptr< PlanewaveDiagonalizer > diagonalizer_
 
std::unique_ptr< PlanewaveKohnShamEnergyCalculator > energy_calculator_
 Computes band energy and smearing entropy from the occupied Kohn-Sham states.
 
execution::PlanewaveExecutionPolicy * execution_policy_ = nullptr
 
PlanewaveFermiEnergyCalculator fermi_energy_calculator_
 
const KPointsGrid * kpoint_grid_ = nullptr
 
std::optional< Magnetization > magnetization_
 Set by report_convergence_details(); see magnetization() above.
 
std::optional< int > nscf_override_maximum_iterations_
 
std::optional< Real > nscf_override_tolerance_
 
int number_of_bands_ {0}
 
Real number_of_electrons_ {0.0}
 
int number_of_smooth_g_vectors_ {0}
 
std::unique_ptr< execution::PlanewaveExecutionPolicy > owned_execution_policy_
 
PlanewaveBasis planewave_basis_
 
PlanewaveKohnShamQuantumSystem quantum_system_
 
bool replicated_plane_wave_fallback_active_ = false
 
bool report_unconverged_bands_ = false
 
Real wavefunction_energy_cutoff_ = 30.0
 
- Protected Attributes inherited from q3::KohnShamSCFIterator
std::vector< Complex > charge_density_g_
 
std::vector< std::vector< Real > > charge_density_real_
 
Real density_residual_ {0.0}
 
Real diagonalizer_tolerance_ {0.0}
 
std::unique_ptr< XCFunctional > exchange_correlation_
 
std::vector< Complex > exchange_correlation_potential_g_
 
bool first_iteration_rediag_done_ {false}
 
bool has_preloaded_charge_density_ {false}
 
bool has_preloaded_effective_potential_ {false}
 
std::unique_ptr< Mixer > mixer_
 
bool preloaded_charge_density_is_a_starting_guess_ {false}
 Set by offer_starting_charge_density(): a density that need not fit.
 
std::vector< std::vector< Real > > real_space_potential_
 
std::vector< ScfIterationRecord > scf_history_
 
std::unique_ptr< SmearingScheme > smearing_scheme_
 
Real total_energy_previous_ {0.0}
 
std::vector< Complex > total_potential_g_
 
std::vector< std::vector< Complex > > total_potential_g_by_spin_
 
- Protected Attributes inherited from q3::SCFIterator
Real convergence_threshold_
 
Crystal * crystal_structure_
 
bool is_converged_ {false}
 
int iteration_ {0}
 
int maximum_iterations_
 

Additional Inherited Members

- Public Attributes inherited from q3::KohnShamSCFIterator
KohnShamSCFIteratorConfig config_
 
std::string exchange_correlation_functional_
 
int methfessel_paxton_order_
 
Real mixing_beta_
 
int mixing_history_size_
 
std::string mixing_mode_
 
std::string mixing_preconditioning_
 
Real mixing_q0_
 
std::string smearing_
 
Real smearing_width_
 

Detailed Description

Definition at line 52 of file init.hpp.

Constructor & Destructor Documentation

◆ PlanewaveKohnShamSCFIterator()

q3::PlanewaveKohnShamSCFIterator::PlanewaveKohnShamSCFIterator ( KohnShamSCFIteratorConfig  config)
inlineexplicit

◆ ~PlanewaveKohnShamSCFIterator()

q3::PlanewaveKohnShamSCFIterator::~PlanewaveKohnShamSCFIterator ( )
overridedefault

Member Function Documentation

◆ allocate_electronic_states()

void q3::PlanewaveKohnShamSCFIterator::allocate_electronic_states ( )
inlineprotected

◆ build_kpoint_plane_wave_data()

void q3::PlanewaveKohnShamSCFIterator::build_kpoint_plane_wave_data ( )
inlineprotected

Safety: if band parallelism gave any rank 0 plane waves at any k-point, fall back to replicated mode for ALL ranks in the pool. This prevents zero-dimension BLAS crashes and asymmetric MPI reductions.

The FFT grids were built during generate(), while the group was still distributed, so they are MPI grids whose transforms are collective across the band group. Disabling band distribution turns every group reduction into a no-op and leaves each rank holding a replicated copy of the coefficients – at which point ranks legitimately take different paths through Davidson while those collective transforms still expect every one of them. The first divergence blocks inside FFTW-MPI's transpose.

Rebuild the basis now that group_size() is 1, so the factory hands back serial grids each rank drives alone. This repeats the FFT planning generate() already did, which is the price of discovering the empty slab only after the grids exist.

Definition at line 1231 of file init.hpp.

References q3::execution::QuantumSystemExecutionPolicy::band_size(), q3::KohnShamSCFIterator::config_, q3::KohnShamSCFIterator::crystal_structure(), q3::execution::PlanewaveExecutionPolicy::disable_band_distribution(), effective_charge_density_energy_cutoff(), execution_policy_, q3::PlanewaveBasis::generate(), q3::PlanewaveBasis::initialize_kpoint_data(), q3::PlanewaveBasis::is_gamma_only(), kpoint_grid(), q3::PlanewaveBasis::kpoint_number_of_plane_waves(), planewave_basis_, q3::execution::PlanewaveExecutionPolicy::reduce_band_group_scalar_min(), replicated_plane_wave_fallback_active_, q3::KohnShamSCFIteratorConfig::use_deterministic_fft_planning, q3::KohnShamSCFIteratorConfig::use_exact_wavefunction_grid, q3::log::warn(), and wavefunction_energy_cutoff_.

Referenced by initialize_representation().

◆ compute_delta_escf_correction()

Real q3::PlanewaveKohnShamSCFIterator::compute_delta_escf_correction ( ) const
inlineoverrideprotectedvirtual

Compute the first-order energy correction for evaluating E_Hartree and E_XC at the mixed density instead of the output density.

delta_escf = -Σ_r (ρ_mixed(r) - ρ_out(r)) · V_Hxc^mixed(r) · (Ω/N)

Matches QE's SCF-correction term of the same name. Must be called AFTER update_effective_potential() has been applied to the mixed density and AFTER snapshot_output_density() has saved the output density.

Same slab decomposition as compute_double_counting_correction: partial real-space integral over local_grid_points, requires band-communicator reduction when multiple ranks share the pool.

After mixing, charge_density_real_ = rho_mixed convergence_output_density_ = rho_out (saved by snapshot_output_density()) real_space_potential_ = V_Hxc from rho_mixed (set by update_effective_potential())

Implements q3::KohnShamSCFIterator.

Definition at line 950 of file init.hpp.

References cached_local_ionic_potential_real_, q3::Crystal::cell_volume(), q3::KohnShamSCFIterator::charge_density_real_, convergence_output_density_, q3::KohnShamSCFIterator::crystal_structure(), execution_policy_, q3::PlanewaveBasis::fft_rho(), q3::FFTGrid::local_grid_points(), q3::SCFIterator::number_of_spin_components(), planewave_basis_, q3::KohnShamSCFIterator::real_space_potential_, q3::execution::PlanewaveExecutionPolicy::reduce_within_pool_scalar(), and q3::FFTGrid::total_grid_points().

◆ compute_density_residual()

Real q3::PlanewaveKohnShamSCFIterator::compute_density_residual ( const std::vector< std::vector< Real > > &  input_density_for_mixing) const
inlineoverrideprotectedvirtual

◆ compute_double_counting_correction()

Real q3::PlanewaveKohnShamSCFIterator::compute_double_counting_correction ( ) const
inlineoverrideprotectedvirtual

◆ compute_effective_potential_from_density()

virtual void q3::PlanewaveKohnShamSCFIterator::compute_effective_potential_from_density ( )
protectedpure virtual

Compute the effective potential from the current charge density. Must set charge_density_g_, real_space_potential_, total_potential_g_, exchange_correlation_potential_g_, and energy components (hartree, xc).

Implemented in q3::PlanewavePseudopotentialKohnShamSCFIterator.

Referenced by update_effective_potential().

◆ compute_energy_components()

void q3::PlanewaveKohnShamSCFIterator::compute_energy_components ( )
inlineoverrideprotectedvirtual

◆ compute_local_residual_between()

Real q3::PlanewaveKohnShamSCFIterator::compute_local_residual_between ( const std::vector< std::vector< Real > > &  density_in,
const std::vector< std::vector< Real > > &  density_out 
) const
inlineprotected

This rank's own (unsynchronized) Hartree-metric residual between two charge densities.

Uses only smooth G-vectors (up to number_of_smooth_g_vectors_), matching QE, which measures dr2 as the metric dot product of (ρ_out − ρ_in) over the smooth G-vector count only. Subclasses (e.g. ultrasoft) may call this with smooth-only densities to avoid augmentation contamination. Never branch on this value directly under k-point-pool MPI – go through compute_residual_between so all pools agree (see its docstring).

LSDA: measure the total density Δ(ρ↑+ρ↓) with the Hartree metric and the magnetization Δ(ρ↑−ρ↓) with a constant metric that INCLUDES G=0 (QE's density-dot-product convention). A per-channel Hartree metric would miss a uniform electron transfer between the spin channels — it lives purely in the magnetization's G=0 component — and report convergence while the moment is still relaxing.

Definition at line 856 of file init.hpp.

References q3::PlanewaveBasis::first_nonzero_g_index(), q3::PlanewaveBasis::g_vectors(), hartree_metric_prefactor(), q3::PlanewaveBasis::is_gamma_only(), magnetization_metric_weight(), q3::PlanewaveBasis::number_of_g_vectors(), number_of_smooth_g_vectors_, q3::SCFIterator::number_of_spin_components(), planewave_basis_, and q3::PlanewaveBasis::rho_r_to_g().

Referenced by compute_residual_between().

◆ compute_number_of_electrons()

Real q3::PlanewaveKohnShamSCFIterator::compute_number_of_electrons ( ) const
inlineprotected

total_charge follows QE's tot_charge convention: positive = electrons removed (cationic). The Ewald ion-ion sum and the Hartree G=0 skip are both keyed only to the ionic charge (see ewald_summation.hpp), so no separate compensating-background term is needed here – only the electron count itself changes.

Definition at line 1167 of file init.hpp.

References q3::KohnShamSCFIterator::config(), q3::KohnShamSCFIterator::crystal_structure(), q3::Crystal::number_of_atoms(), q3::KohnShamSCFIteratorConfig::total_charge, and q3::Crystal::valence_charge().

Referenced by initialize_representation().

◆ compute_residual_between()

Real q3::PlanewaveKohnShamSCFIterator::compute_residual_between ( const std::vector< std::vector< Real > > &  density_in,
const std::vector< std::vector< Real > > &  density_out 
) const
inlineprotected

Compute the Hartree-metric density residual between two charge densities, synchronized across k-point pools.

The raw residual (see compute_local_residual_between below) is computed independently on every rank from that rank's own rho_r_to_g transforms. FFTW plans are timing-selected per rank (FFTW_MEASURE), so bit-identical input densities yield bit-DIFFERENT residuals on different pool ranks – measured on a 4-pool Ni LSDA+smearing run: last-bit (~1e-15 relative) divergence already at iteration 1, amplified through the nonlinear mixing-history feedback to factors of 2-30x near convergence (the residual tends to zero while the per-rank noise it is measured against does not). This residual gates three branches that change the inter-pool collective call sequence: the SCF loop exit (is_iteration_converged), the skip-mixing early return, and the first-iteration re-diagonalization. If ranks decide those branches differently, their Fermi-bisection / charge-density-Allreduce / force-stress collectives pair up out of order across pools: MPI_ERR_TRUNCATE when the mismatched calls have different message sizes, silently corrupted totals when they happen to match. Reducing with MPI_MAX makes every rank branch on the same value and is conservative – the SCF stops only when the slowest pool's estimate has converged. (Within a pool no synchronization is needed: band ranks compute the residual from pool-collectively-transformed, replicated G-space data, so they already agree bitwise.)

Definition at line 836 of file init.hpp.

References compute_local_residual_between(), execution_policy_, q3::execution::PlanewaveExecutionPolicy::number_of_pools(), and q3::execution::PlanewaveExecutionPolicy::reduce_scalar_max().

Referenced by compute_density_residual().

◆ construct_density_from_states()

◆ core_charge_density_g()

virtual const std::vector< Complex > & q3::PlanewaveKohnShamSCFIterator::core_charge_density_g ( ) const
protectedpure virtual

Return the core charge density in reciprocal space.

Implemented in q3::PlanewavePseudopotentialKohnShamSCFIterator.

◆ effective_charge_density_energy_cutoff()

Real q3::PlanewaveKohnShamSCFIterator::effective_charge_density_energy_cutoff ( ) const
inlineprotected

◆ eigenvalue()

Real q3::PlanewaveKohnShamSCFIterator::eigenvalue ( int  kpoint_index,
int  band_index 
) const
inline

Access a single eigenvalue ε_{k,n} (Ry).

Definition at line 265 of file init.hpp.

References q3::PlanewaveKohnShamQuantumSystem::eigenvalue(), and quantum_system_.

◆ eigenvalues()

Matrix< Real > q3::PlanewaveKohnShamSCFIterator::eigenvalues ( ) const
inline

Access eigenvalues as a Matrix (for compatibility).

Definition at line 237 of file init.hpp.

References q3::PlanewaveKohnShamQuantumSystem::eigenvalues_matrix(), and quantum_system_.

Referenced by q3::assemble_global_eigenvalues_at_kpoints(), and global_eigenvalues().

◆ execution_policy()

◆ g_vector_indices() [1/2]

◆ g_vector_indices() [2/2]

const std::vector< int > & q3::PlanewaveKohnShamSCFIterator::g_vector_indices ( int  kpoint_index) const
inline

G-vector indices for a specific k-point.

Definition at line 308 of file init.hpp.

References q3::PlanewaveBasis::g_vector_indices_by_kpoint_index(), and planewave_basis_.

◆ global_eigenvalues()

Matrix< Real > q3::PlanewaveKohnShamSCFIterator::global_eigenvalues ( ) const
inline

The eigenvalues of every k-point state in the run, in global order (Ry).

eigenvalues() holds only this pool's k-point states. The rows here are spin-major over the global grid, as a serial run's are. Collective under MPI: every rank must call it.

Definition at line 248 of file init.hpp.

References q3::execution::PlanewaveExecutionPolicy::assemble_global_kpoint_state_data(), q3::Matrix< T >::cols(), eigenvalues(), execution_policy_, kpoint_grid(), number_of_bands(), q3::KPointsGrid::number_of_kpoints(), q3::SCFIterator::number_of_spin_components(), and q3::Matrix< T >::raw().

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::write_checkpoints().

◆ hartree_metric_prefactor()

Real q3::PlanewaveKohnShamSCFIterator::hartree_metric_prefactor ( ) const
inlineprotected

Hartree-metric prefactor e² · 4π / tpiba² · V/2. The per-G charge-channel metric weight is this divided by the dimensionless (miller-basis) |G|². Single source for both the mixer environment and the SCF dr2.

Definition at line 794 of file init.hpp.

References q3::Crystal::cell_volume(), q3::KohnShamSCFIterator::crystal_structure(), q3::constants::electron_charge_squared_rydberg, q3::constants::four_pi, and q3::Crystal::two_pi_over_lattice_parameter_squared().

Referenced by compute_local_residual_between(), and initiate_mixer().

◆ initialize_representation()

void q3::PlanewaveKohnShamSCFIterator::initialize_representation ( )
inlineoverrideprotectedvirtual

Detect gamma-only: single k-point at Γ = (0,0,0) with no shift. This enables half-sphere G-vector storage for ~2× speedup.

Under a shared pool the half sphere is rebuilt inside every transform from each G and its negative, so the FFT layout has to keep the two on one rank. The stick grid does; the slab grid it replaced did not, which is what used to force this off under MPI. The grid is asked once it exists, below, rather than assumed here.

K-points are already distributed by the factory (set_owned_kpoint_grid) and protected by the owned_kpoint_grid_.has_value() guard above.

Implements q3::KohnShamSCFIterator.

Reimplemented in q3::PlanewavePseudopotentialKohnShamSCFIterator.

Definition at line 452 of file init.hpp.

References allocate_electronic_states(), build_kpoint_plane_wave_data(), q3::PlanewaveChargeDensitySymmetrizer::build_shells(), charge_density_accumulator_, q3::KohnShamSCFIteratorConfig::charge_density_energy_cutoff, charge_density_energy_cutoff_, q3::FFTGrid::co_locates_mirrors(), q3::Crystal::compute_derived_quantities(), q3::compute_ewald(), compute_number_of_electrons(), q3::KohnShamSCFIterator::config(), q3::KohnShamSCFIterator::config_, q3::create_planewave_diagonalizer(), q3::KohnShamSCFIterator::crystal_structure(), density_symmetrizer_, q3::KohnShamSCFIteratorConfig::diagonalization_method, diagonalization_method_, diagonalizer_, q3::KohnShamSCFIteratorConfig::disable_symmetry, effective_charge_density_energy_cutoff(), energy_calculator_, q3::PlanewaveKohnShamEnergies::ewald_energy, execution_policy_, fermi_energy_calculator_, q3::PlanewaveBasis::fft_wave(), q3::PlanewaveBasis::generate(), q3::KPointsGrid::grid_dimensions(), q3::KPointsGrid::grid_shifts(), q3::log::info(), q3::ProfilingCounters::instance(), q3::KohnShamSCFIteratorConfig::kpoint_grid, kpoint_grid(), kpoint_grid_, q3::QuantumSystem< QuantumStateType >::load_quantum_system(), log_representation_summary(), q3::ProfilingCounters::log_resident_checkpoint(), q3::KohnShamSCFIteratorConfig::number_of_bands, number_of_bands_, number_of_electrons_, q3::SCFIterator::number_of_spin_components(), owned_execution_policy_, planewave_basis_, planewave_energies_mutable(), q3::QuantumSystem< QuantumStateType >::preloaded_quantum_system_, quantum_system_, resolve_number_of_bands(), q3::KohnShamSCFIterator::smearing_scheme_, q3::KohnShamSCFIteratorConfig::use_deterministic_fft_planning, q3::KohnShamSCFIteratorConfig::use_exact_wavefunction_grid, q3::KohnShamSCFIteratorConfig::wavefunction_energy_cutoff, and wavefunction_energy_cutoff_.

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::initialize_representation().

◆ initiate_mixer()

void q3::PlanewaveKohnShamSCFIterator::initiate_mixer ( )
inlineoverrideprotectedvirtual

Same metric definitions as the SCF dr2 (see hartree_metric_prefactor / magnetization_metric_weight) so mixer-internal norms and the SCF convergence check agree.

The residual preconditioner. |G|² is carried in bohr⁻² – the stored magnitude is in units of (2π/a)² – because every preconditioner compares it against a screening wavevector in those units.

Compute the number of smooth G-vectors for dual-grid mixing (QE convention). The smooth cutoff is 4*ecutwfc (the norm-conserving default density cutoff). G-vectors above this cutoff get simple linear mixing instead of Broyden, keeping noisy high-frequency augmentation artifacts out of the Broyden subspace.

Count G-vectors within the smooth cutoff G-vectors are sorted by magnitude, so we can stop when we exceed the cutoff

Zero metric weights for hard G-vectors so the Gram matrix and projections naturally use only smooth G-vectors, matching QE's density dot product, which is truncated at the smooth G-vector count.

Implements q3::KohnShamSCFIterator.

Definition at line 558 of file init.hpp.

References q3::MixerEnvironment::charge_metric_weights, q3::PreconditionerFactory::create(), q3::KohnShamSCFIterator::crystal_structure(), effective_charge_density_energy_cutoff(), execution_policy_, q3::PlanewaveBasis::first_nonzero_g_index(), q3::MixerEnvironment::first_nonzero_g_index, q3::PreconditionerEnvironment::first_nonzero_g_index, q3::PreconditionerEnvironment::g_squared, q3::PlanewaveBasis::g_vectors(), q3::MixerEnvironment::global_reduce, q3::PreconditionerEnvironment::global_reduce, hartree_metric_prefactor(), q3::log::info(), q3::PlanewaveBasis::is_gamma_only(), q3::MixerEnvironment::is_gamma_only, q3::MixerEnvironment::magnetization_metric_weight, magnetization_metric_weight(), q3::KohnShamSCFIterator::mixer_, q3::KohnShamSCFIterator::mixing_preconditioning_, q3::KohnShamSCFIterator::mixing_q0_, q3::PlanewaveBasis::number_of_g_vectors(), q3::MixerEnvironment::number_of_smooth_g_vectors, number_of_smooth_g_vectors_, planewave_basis_, q3::MixerEnvironment::preconditioner, q3::PreconditionerEnvironment::q0_squared, q3::execution::PlanewaveExecutionPolicy::reduce_within_pool_vector(), q3::PlanewaveBasis::rho_g_to_r(), q3::PlanewaveBasis::rho_r_to_g(), q3::MixerEnvironment::to_real_space, q3::PreconditionerEnvironment::to_real_space, q3::MixerEnvironment::to_reciprocal_space, q3::PreconditionerEnvironment::to_reciprocal_space, q3::Crystal::two_pi_over_lattice_parameter_squared(), and wavefunction_energy_cutoff_.

◆ input_density_for_mixing()

std::vector< std::vector< Real > > q3::PlanewaveKohnShamSCFIterator::input_density_for_mixing ( ) const
inlineoverrideprotectedvirtual

◆ kinetic_energy_squared()

const std::vector< std::vector< Real > > & q3::PlanewaveKohnShamSCFIterator::kinetic_energy_squared ( ) const
inline

◆ kpoint_grid()

◆ load_quantum_system()

void q3::PlanewaveKohnShamSCFIterator::load_quantum_system ( const PlanewaveKohnShamQuantumSystem &  system)
inline

Set the preloaded quantum system snapshot.

Definition at line 129 of file init.hpp.

References q3::QuantumSystem< QuantumStateType >::load_quantum_system(), and quantum_system_.

◆ loaded_charge_density_fits_grid()

bool q3::PlanewaveKohnShamSCFIterator::loaded_charge_density_fits_grid ( ) const
inline

Whether the loaded density has this run's spin components and this rank's share of its charge-density grid. Every rank of a run reads the same saved file, so the answer is the same on every rank: a whole grid fits ranks that each hold one, and no rank of a pool split into slabs.

Definition at line 153 of file init.hpp.

References q3::KohnShamSCFIterator::charge_density_real_, q3::PlanewaveBasis::fft_rho(), q3::FFTGrid::local_grid_points(), q3::SCFIterator::number_of_spin_components(), and planewave_basis_.

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::initialize_charge_density().

◆ local_ionic_potential_g()

virtual const std::vector< Complex > & q3::PlanewaveKohnShamSCFIterator::local_ionic_potential_g ( ) const
protectedpure virtual

Return the local ionic potential in reciprocal space.

Implemented in q3::PlanewavePseudopotentialKohnShamSCFIterator.

Referenced by update_effective_potential().

◆ log_representation_summary()

void q3::PlanewaveKohnShamSCFIterator::log_representation_summary ( ) const
inlineprotected

The irreducible count, not this pool's share. kpoint_grid() is the distributed grid, so with 8 pools a 60-k-point calculation reported 8 here – next to an "IBZ reduction ... -> 60 k-points" line two rows above, which made one of the two look wrong.

Derived from the same assembly the convergence report uses, with a one-value-per-state payload: its return size is the global state count, so this costs an Allreduce of a few dozen doubles once per run. The serial policy returns the input unchanged, which gives the local count – and in serial the local count IS the global one.

Each pool holds only its local k-points, so the local max may be less than the global max. Reduce across pools to get the true maximum.

Ranks per pool, not band_size(). The two agree for the reciprocal-space split, but band_size() is deliberately 1 once bands are distributed – reporting it there would claim one rank per pool on a run using four.

Definition at line 1285 of file init.hpp.

References q3::execution::PlanewaveExecutionPolicy::assemble_global_kpoint_state_data(), q3::execution::ExecutionPolicy::band_distribution_size(), q3::PlanewaveKohnShamSCFSetupSummary::band_group_size, q3::PlanewaveKohnShamSCFSetupSummary::bands_are_distributed, q3::Crystal::cell_volume(), q3::PlanewaveKohnShamSCFSetupSummary::cell_volume, q3::PlanewaveKohnShamSCFSetupSummary::charge_density_energy_cutoff, q3::KohnShamSCFIterator::config(), q3::KohnShamSCFIterator::crystal_structure(), q3::KohnShamSCFIteratorConfig::davidson_basis_expansion_factor, q3::PlanewaveKohnShamSCFSetupSummary::davidson_basis_expansion_factor, q3::PlanewaveKohnShamSCFSetupSummary::density_symmetrization_active, density_symmetrizer_, diagonalization_method_, diagonalizer_, q3::PlanewaveKohnShamSCFSetupSummary::diagonalizer_name, effective_charge_density_energy_cutoff(), q3::PlanewaveKohnShamSCFSetupSummary::ewald_energy, q3::PlanewaveKohnShamEnergies::ewald_energy, q3::KohnShamSCFIterator::exchange_correlation_, execution_policy_, q3::PlanewaveBasis::fft_rho(), q3::PlanewaveKohnShamSCFSetupSummary::fft_rho_grid_dimension_1, q3::PlanewaveKohnShamSCFSetupSummary::fft_rho_grid_dimension_2, q3::PlanewaveKohnShamSCFSetupSummary::fft_rho_grid_dimension_3, q3::PlanewaveBasis::fft_wave(), q3::PlanewaveKohnShamSCFSetupSummary::fft_wave_grid_dimension_1, q3::PlanewaveKohnShamSCFSetupSummary::fft_wave_grid_dimension_2, q3::PlanewaveKohnShamSCFSetupSummary::fft_wave_grid_dimension_3, q3::FFTGrid::grid_dimension_1(), q3::FFTGrid::grid_dimension_2(), q3::FFTGrid::grid_dimension_3(), q3::PlanewaveChargeDensitySymmetrizer::is_initialized(), kpoint_grid(), q3::PlanewaveBasis::kpoint_number_of_plane_waves(), q3::Crystal::lattice_parameter(), q3::PlanewaveKohnShamSCFSetupSummary::lattice_parameter, q3::PlanewaveKohnShamSCFSetupSummary::max_plane_waves_per_kpoint, q3::KohnShamSCFIterator::mixer_, q3::PlanewaveKohnShamSCFSetupSummary::mixer_name, q3::PlanewaveKohnShamSCFSetupSummary::mixing_beta, q3::KohnShamSCFIterator::mixing_beta_, q3::Crystal::number_of_atoms(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_atoms, q3::PlanewaveKohnShamSCFSetupSummary::number_of_bands, number_of_bands_, q3::PlanewaveKohnShamSCFSetupSummary::number_of_electrons, number_of_electrons_, q3::PlanewaveBasis::number_of_g_vectors(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_g_vectors, q3::PlanewaveKohnShamSCFSetupSummary::number_of_kpoint_pools, q3::KPointsGrid::number_of_kpoints(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_kpoints, q3::execution::PlanewaveExecutionPolicy::number_of_pools(), q3::execution::ExecutionPolicy::number_of_processes(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_processes, q3::PlanewaveChargeDensitySymmetrizer::number_of_shells(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_shells, q3::SCFIterator::number_of_spin_components(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_spin_components, q3::PlanewaveChargeDensitySymmetrizer::number_of_symmetry_operations(), q3::PlanewaveKohnShamSCFSetupSummary::number_of_symmetry_operations, planewave_basis_, planewave_energies(), q3::execution::PlanewaveExecutionPolicy::reduce_scalar_max(), q3::PlanewaveKohnShamSCFSetupSummary::replicated_plane_wave_fallback_active, replicated_plane_wave_fallback_active_, q3::PlanewaveKohnShamSCFReporter::report_setup_summary(), q3::PlanewaveKohnShamSCFSetupSummary::wavefunction_energy_cutoff, wavefunction_energy_cutoff_, and q3::PlanewaveKohnShamSCFSetupSummary::xc_functional_name.

Referenced by initialize_representation().

◆ magnetization()

const std::optional< Magnetization > & q3::PlanewaveKohnShamSCFIterator::magnetization ( ) const
inline

∫(ρ↑−ρ↓) and ∫|ρ↑−ρ↓| for this run, in Bohr magnetons.

Present only for a spin-polarized run that reached its convergence report, which is where they are integrated; empty elsewhere, so a consumer can tell "not a magnetic calculation" from "a moment that came out at zero" without asking which kind of run this was.

Definition at line 355 of file init.hpp.

References magnetization_.

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::initialize_representation().

◆ magnetization_metric_weight()

Real q3::PlanewaveKohnShamSCFIterator::magnetization_metric_weight ( ) const
inlineprotected

Flat metric weight for the magnetization channel: e² · 4π / (2π)² · V/2 (the constant prefactor of the spin-polarized term in QE's density dot product). Single source for both the mixer environment and the SCF dr2.

Definition at line 805 of file init.hpp.

References q3::Crystal::cell_volume(), q3::KohnShamSCFIterator::crystal_structure(), q3::constants::electron_charge_squared_rydberg, q3::constants::four_pi, and q3::constants::two_pi.

Referenced by compute_local_residual_between(), and initiate_mixer().

◆ mix_density()

void q3::PlanewaveKohnShamSCFIterator::mix_density ( const std::vector< std::vector< Real > > &  input_density_for_mixing)
inlineoverrideprotectedvirtual

◆ number_of_bands()

int q3::PlanewaveKohnShamSCFIterator::number_of_bands ( ) const
inlineoverridevirtual

Total number of bands (user-specified or auto-determined).

Implements q3::KohnShamSCFIterator.

Definition at line 315 of file init.hpp.

References number_of_bands_.

Referenced by global_eigenvalues().

◆ number_of_electrons()

Real q3::PlanewaveKohnShamSCFIterator::number_of_electrons ( ) const
inlineoverridevirtual

Total number of valence electrons from all atoms.

Implements q3::KohnShamSCFIterator.

Definition at line 322 of file init.hpp.

References number_of_electrons_.

Referenced by scale_loaded_charge_density_to_electron_count().

◆ number_of_kpoint_states()

◆ number_of_occupied_bands_per_spin()

int q3::PlanewaveKohnShamSCFIterator::number_of_occupied_bands_per_spin ( ) const
inline

Number of fully occupied bands per spin channel.

Definition at line 336 of file init.hpp.

References q3::PlanewaveKohnShamQuantumSystem::number_of_occupied_bands_per_spin(), and quantum_system_.

◆ number_of_plane_waves() [1/2]

◆ number_of_plane_waves() [2/2]

int q3::PlanewaveKohnShamSCFIterator::number_of_plane_waves ( int  kpoint_index) const
inline

Number of plane waves for a specific k-point.

Definition at line 301 of file init.hpp.

References q3::PlanewaveBasis::number_of_plane_waves_by_kpoint_index(), and planewave_basis_.

◆ occupation()

Real q3::PlanewaveKohnShamSCFIterator::occupation ( int  kpoint_index,
int  band_index 
) const
inline

◆ on_charge_density_initialized()

virtual void q3::PlanewaveKohnShamSCFIterator::on_charge_density_initialized ( )
inlineprotectedvirtual

Hook invoked once the initial atomic-superposition charge density is ready.

Default no-op. The ultrasoft subclass overrides it to initialise the smooth density and projector overlap storage.

Reimplemented in q3::PawPlanewavePseudopotentialKohnShamSCFIterator, and q3::UltrasoftPlanewavePseudopotentialKohnShamSCFIterator.

Definition at line 1159 of file init.hpp.

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::initialize_charge_density().

◆ planewave_basis()

const PlanewaveBasis & q3::PlanewaveKohnShamSCFIterator::planewave_basis ( ) const
inline

Access the plane-wave basis set.

Definition at line 216 of file init.hpp.

References planewave_basis_.

Referenced by q3::internal::build_wannier_interface_record().

◆ planewave_energies()

const PlanewaveKohnShamEnergies & q3::PlanewaveKohnShamSCFIterator::planewave_energies ( ) const
inlineprotected

◆ planewave_energies_mutable()

PlanewaveKohnShamEnergies & q3::PlanewaveKohnShamSCFIterator::planewave_energies_mutable ( )
inlineprotected

◆ preload_charge_density()

◆ preload_single_particle_states()

void q3::PlanewaveKohnShamSCFIterator::preload_single_particle_states ( )
inline

◆ quantum_system()

const PlanewaveKohnShamQuantumSystem & q3::PlanewaveKohnShamSCFIterator::quantum_system ( ) const
inline

Access the generic Kohn-Sham quantum system.

Definition at line 223 of file init.hpp.

References quantum_system_.

Referenced by q3::assemble_global_eigenvalues_at_kpoints(), q3::assemble_global_kpoint_state_blocks(), and q3::internal::build_wannier_interface_record().

◆ release_scf_workspace()

virtual void q3::PlanewaveKohnShamSCFIterator::release_scf_workspace ( )
inlinevirtual

Release what only the SCF needed, once it has converged: the solver's working basis and the mixing history. The forces and stress that follow work from the wavefunctions and density in the quantum system, and they allocate arrays of their own – on the 54-atom silicon cell at two ranks the forces stage set the run's peak 0.3 GiB above the SCF's, because the SCF's working set was still alive under it. A subclass adds the caches it owns. A later run() rebuilds everything on demand.

Reimplemented in q3::PlanewavePseudopotentialKohnShamSCFIterator.

Definition at line 109 of file init.hpp.

References diagonalizer_, q3::ProfilingCounters::instance(), q3::KohnShamSCFIterator::mixer_, and q3::ProfilingCounters::release_unused_heap().

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::release_scf_workspace().

◆ report_convergence_details()

void q3::PlanewaveKohnShamSCFIterator::report_convergence_details ( )
inlineoverrideprotectedvirtual

Representation-specific tail of the convergence report (eigenvalues, magnetization, final energy breakdown). Generic banner lives in report_convergence().

Kept here, where they are integrated for the report, rather than re-integrated for the results file: the density this reads is released with the rest of the SCF workspace before the flavor assembles its result, and a second integration somewhere else would be a second chance for the two to disagree – the same reason the SCF history is recorded at the line that prints it.

Report every irreducible k-point, not just this rank's pool share.

kpoint_grid() is the DISTRIBUTED grid, so with pools it holds only this pool's k-points – a 60-k-point calculation on 8 pools used to report 8, restart its labels at k_0 in each pool, and give no way to tell which of the 60 they were. The same fixed-width pack-and-gather the SCF flavor already uses to build results.json (see flavors/self_consistent_field.hpp) puts them back in global order, and it costs one Allreduce at the end of a converged run.

Layout per k-point state: number_of_bands_ eigenvalues followed by the three k-point coordinates. Weights are not needed for the report. assemble_global_kpoint_state_data() is spin-major over the global grid and returns the whole array on every rank; the serial policy hands the input straight back, so this path is not MPI-only.

The counters as the SCF leaves them, which is not what the entry point prints at exit: forces and stress add transforms of their own afterwards, so the two figures differ, and that difference is the reason to have this one at all.

The Davidson timing table is deliberately not dumped here. Nothing between this line and the entry point's closing dump touches the accumulator, so the two were byte-identical – the same table twice in one run.

Implements q3::KohnShamSCFIterator.

Definition at line 999 of file init.hpp.

References q3::PlanewaveKohnShamSCFConvergenceSummary::absolute_magnetization, q3::execution::PlanewaveExecutionPolicy::assemble_global_kpoint_state_data(), q3::Crystal::cell_volume(), q3::KohnShamSCFIterator::charge_density_real_, q3::KohnShamSCFIterator::crystal_structure(), q3::log::debug(), q3::PlanewaveKohnShamQuantumSystem::eigenvalue(), q3::PlanewaveKohnShamSCFConvergenceSummary::eigenvalues, q3::PlanewaveKohnShamSCFConvergenceSummary::energies, execution_policy_, q3::PlanewaveBasis::fft_rho(), q3::ProfilingCounters::instance(), kpoint_grid(), q3::PlanewaveKohnShamSCFConvergenceSummary::kpoints, magnetization_, q3::PlanewaveKohnShamSCFConvergenceSummary::number_of_bands, number_of_bands_, q3::PlanewaveKohnShamSCFConvergenceSummary::number_of_kpoint_pools, q3::KPointsGrid::number_of_kpoints(), q3::PlanewaveKohnShamSCFConvergenceSummary::number_of_kpoints, q3::execution::PlanewaveExecutionPolicy::number_of_pools(), q3::SCFIterator::number_of_spin_components(), q3::PlanewaveKohnShamSCFConvergenceSummary::number_of_spin_components, planewave_basis_, planewave_energies(), quantum_system_, q3::execution::PlanewaveExecutionPolicy::reduce_within_pool_scalar(), q3::PlanewaveKohnShamSCFReporter::report_convergence_summary(), q3::FFTGrid::total_grid_points(), and q3::PlanewaveKohnShamSCFConvergenceSummary::total_magnetization.

◆ report_first_iteration_details()

void q3::PlanewaveKohnShamSCFIterator::report_first_iteration_details ( )
inlineoverrideprotectedvirtual

◆ resolve_number_of_bands()

int q3::PlanewaveKohnShamSCFIterator::resolve_number_of_bands ( ) const
inlineprotected

Bands to solve for, when the input did not say.

Insulator: the occupied count plus four empty bands, which cost little and give the eigensolver room to converge the top of the valence manifold. Metal: 20% more than the occupied count, but never fewer than four extra — a partly filled band must be resolved well above the Fermi level or the smeared occupations are truncated and the total energy is wrong.

The 20% and the four-band floor are heuristics, and they are the same pair Quantum ESPRESSO uses, deliberately: for a metal the band count changes the total energy through the fractional occupations of the extra bands, so reproducing an upstream energy at the same input requires reproducing its band count. That equivalence is what the three LSDA cases in tests/validation/test_qe_energy_comparison.py check — they pass no band count to either code. The insulating branch deliberately differs (the upstream default adds no margin there); empty bands cannot move a fixed-occupation total, so nothing observable turns on it.

Definition at line 1202 of file init.hpp.

References number_of_bands_, number_of_electrons_, q3::KohnShamSCFIterator::smearing_, q3::KohnShamSCFIterator::smearing_width_, q3::math::tolerances::smearing_width_threshold, and q3::log::warn().

Referenced by initialize_representation().

◆ restore_density_at_convergence()

void q3::PlanewaveKohnShamSCFIterator::restore_density_at_convergence ( )
inlineoverrideprotectedvirtual

◆ result()

virtual NormConservingPlanewaveKohnShamSCFState q3::PlanewaveKohnShamSCFIterator::result ( ) const
pure virtual

Assemble and return a snapshot of the converged SCF state.

Returns a self-contained state carrying all converged data needed by post-SCF consumers (forces, stress, output writer, binary checkpoints).

Implemented in q3::PlanewavePseudopotentialKohnShamSCFIterator, and q3::UltrasoftPlanewavePseudopotentialKohnShamSCFIterator.

Referenced by q3::SelfConsistentFieldFlavor::run_calculation().

◆ scale_loaded_charge_density_to_electron_count()

void q3::PlanewaveKohnShamSCFIterator::scale_loaded_charge_density_to_electron_count ( )
inline

◆ set_diagonalization_tolerance()

void q3::PlanewaveKohnShamSCFIterator::set_diagonalization_tolerance ( int  iteration)
inlineoverrideprotectedvirtual

NSCF mode: use the tight override tolerance set by the NSCF flavor instead of the adaptive SCF scheme. The override was requested before run() (when diagonalizer_ was still null), so it is applied here on the first call, once the diagonalizer has been constructed.

Iteration 2+: tighten the eigenvalue threshold to stay an order of magnitude below the self-consistency error, per electron-state: tolerance <- min(tolerance, 0.1 * residual / max(1, electrons)) The min keeps the schedule monotone, so a transient rise in the residual cannot loosen a threshold that has already tightened; the max(1, ...) guard covers a cell with fewer than one electron. The 0.1 margin and the 1e-13 floor applied below are heuristics – the same pair Quantum ESPRESSO uses – and neither is observable in the converged result, which is fixed by convergence_threshold on the residual, not by this tolerance. Iteration 1's loose 1e-2 start is of the same kind: the atomic-superposition potential is far from self-consistent, so precision there is wasted.

Implements q3::KohnShamSCFIterator.

Definition at line 719 of file init.hpp.

References q3::KohnShamSCFIterator::density_residual_, q3::KohnShamSCFIterator::diagonalization_threshold(), diagonalizer_, q3::KohnShamSCFIterator::diagonalizer_tolerance_, q3::math::tolerances::initial_eigenvalue_tolerance, q3::SCFIterator::iteration(), nscf_override_maximum_iterations_, nscf_override_tolerance_, number_of_electrons_, and report_unconverged_bands_.

◆ set_diagonalizer()

void q3::PlanewaveKohnShamSCFIterator::set_diagonalizer ( std::unique_ptr< PlanewaveDiagonalizer >  diagonalizer)
inline

Inject an externally-constructed diagonalizer.

When set before run(), the iterator skips its internal create_planewave_diagonalizer() call and uses this one instead. Ownership is transferred to the iterator.

Definition at line 96 of file init.hpp.

References diagonalizer_.

◆ set_diagonalizer_tolerance()

void q3::PlanewaveKohnShamSCFIterator::set_diagonalizer_tolerance ( Real  tolerance)
inlineoverrideprotectedvirtual

◆ set_owned_execution_policy()

void q3::PlanewaveKohnShamSCFIterator::set_owned_execution_policy ( std::unique_ptr< execution::PlanewaveExecutionPolicy >  policy)
inline

Transfer ownership of an execution policy into this iterator.

After this call the iterator holds the policy for its lifetime and uses it for pool-level collective operations (charge-density reduction, scalar reduction).

Definition at line 84 of file init.hpp.

References execution_policy_, and owned_execution_policy_.

◆ set_owned_kpoint_grid()

void q3::PlanewaveKohnShamSCFIterator::set_owned_kpoint_grid ( KPointsGrid  kpoint_grid)
inline

Transfer ownership of a KPointsGrid into this iterator.

Definition at line 72 of file init.hpp.

References kpoint_grid(), and kpoint_grid_.

◆ snapshot_output_density()

void q3::PlanewaveKohnShamSCFIterator::snapshot_output_density ( )
inlineoverrideprotectedvirtual

◆ spin_degeneracy()

Real q3::PlanewaveKohnShamSCFIterator::spin_degeneracy ( ) const
inline

Spin degeneracy factor (2.0 for non-spin-polarized, 1.0 for LSDA).

Definition at line 343 of file init.hpp.

References quantum_system_, and q3::PlanewaveKohnShamQuantumSystem::spin_degeneracy().

◆ symmetrize_density()

void q3::PlanewaveKohnShamSCFIterator::symmetrize_density ( )
inlineoverrideprotectedvirtual

◆ update_effective_potential()

void q3::PlanewaveKohnShamSCFIterator::update_effective_potential ( )
inlineoverrideprotectedvirtual

Skip recomputation when V_eff was injected via load_effective_potential(). This path is taken by the NSCF flavor which loads V_eff from a v2 checkpoint.

Compute total_potential_g_ by FFT-ing the spin-averaged potential. This is required by prepare_hamiltonian() (critical for ultrasoft, harmless for NC).

Per-spin copies as well: a checkpoint stores only the average, but real_space_potential_ was loaded per channel, so the nonlocal D can still be built per channel rather than from the average it would otherwise fall back to.

Initialize the cached ionic local potential so that compute_double_counting_correction() does not crash when it is called after solve_single_particle_states(). In the SCF path this is populated lazily inside compute_effective_potential_from_density(), but that function is skipped for NSCF, leaving the cache empty.

Implements q3::KohnShamSCFIterator.

Definition at line 666 of file init.hpp.

References cached_local_ionic_potential_real_, compute_effective_potential_from_density(), q3::KohnShamSCFIterator::has_preloaded_effective_potential_, local_ionic_potential_g(), planewave_basis_, q3::KohnShamSCFIterator::real_space_potential_, q3::PlanewaveBasis::rho_g_to_r(), q3::PlanewaveBasis::rho_r_to_g(), q3::KohnShamSCFIterator::total_potential_g_, and q3::KohnShamSCFIterator::total_potential_g_by_spin_.

Referenced by q3::PlanewavePseudopotentialKohnShamSCFIterator::initialize_single_particle_states(), and preload_single_particle_states().

◆ update_occupations()

void q3::PlanewaveKohnShamSCFIterator::update_occupations ( )
inlineoverrideprotectedvirtual

◆ warn_if_total_charge_deviates()

void q3::PlanewaveKohnShamSCFIterator::warn_if_total_charge_deviates ( ) const
inlineprotected

Each rank holds the real-space planes of the density it owns: all of them unless reciprocal space is split within the pool, in which case the local sum is a fraction of the charge – about half on two ranks, which is what this used to report as a deviation. The sum is completed within the group before it is compared, so every rank must call this.

Definition at line 1374 of file init.hpp.

References q3::Crystal::cell_volume(), q3::KohnShamSCFIterator::charge_density_real_, q3::KohnShamSCFIterator::crystal_structure(), execution_policy_, q3::PlanewaveBasis::fft_rho(), q3::execution::ExecutionPolicy::is_root(), q3::FFTGrid::local_grid_points(), number_of_electrons_, q3::SCFIterator::number_of_spin_components(), planewave_basis_, q3::execution::ExecutionPolicy::reduce_within_group(), q3::FFTGrid::total_grid_points(), and q3::log::warn().

Referenced by q3::UltrasoftPlanewavePseudopotentialKohnShamSCFIterator::construct_density_from_states().

◆ wavefunction()

Complex q3::PlanewaveKohnShamSCFIterator::wavefunction ( int  kpoint_index,
int  band_index,
int  g_vector_index 
) const
inline

Access a single wavefunction coefficient Ψ_{k,n}(G).

Definition at line 230 of file init.hpp.

References quantum_system_, and q3::PlanewaveKohnShamQuantumSystem::wavefunction().

Member Data Documentation

◆ cached_local_ionic_potential_real_

std::vector<Real> q3::PlanewaveKohnShamSCFIterator::cached_local_ionic_potential_real_
protected

Cached real-space ionic local potential (constant during SCF, avoids repeated FFTs).

Definition at line 406 of file init.hpp.

Referenced by compute_delta_escf_correction(), compute_double_counting_correction(), and update_effective_potential().

◆ charge_density_accumulator_

std::unique_ptr<PlanewaveChargeDensityAccumulator> q3::PlanewaveKohnShamSCFIterator::charge_density_accumulator_
protected

Accumulates real-space charge density from wavefunctions each SCF iteration.

Definition at line 399 of file init.hpp.

Referenced by construct_density_from_states(), and initialize_representation().

◆ charge_density_energy_cutoff_

Real q3::PlanewaveKohnShamSCFIterator::charge_density_energy_cutoff_ = 0.0
protected

Definition at line 366 of file init.hpp.

Referenced by effective_charge_density_energy_cutoff(), and initialize_representation().

◆ convergence_output_density_

std::vector<std::vector<Real> > q3::PlanewaveKohnShamSCFIterator::convergence_output_density_
protected

Converged output density snapshot, restored once self-consistency is reached.

Definition at line 404 of file init.hpp.

Referenced by compute_delta_escf_correction(), restore_density_at_convergence(), and snapshot_output_density().

◆ density_symmetrizer_

◆ diagonalization_method_

std::string q3::PlanewaveKohnShamSCFIterator::diagonalization_method_ = "davidson"
protected

◆ diagonalizer_

◆ energy_calculator_

std::unique_ptr<PlanewaveKohnShamEnergyCalculator> q3::PlanewaveKohnShamSCFIterator::energy_calculator_
protected

Computes band energy and smearing entropy from the occupied Kohn-Sham states.

Definition at line 401 of file init.hpp.

Referenced by compute_energy_components(), and initialize_representation().

◆ execution_policy_

◆ fermi_energy_calculator_

PlanewaveFermiEnergyCalculator q3::PlanewaveKohnShamSCFIterator::fermi_energy_calculator_
protected

Definition at line 396 of file init.hpp.

Referenced by initialize_representation(), and update_occupations().

◆ kpoint_grid_

const KPointsGrid* q3::PlanewaveKohnShamSCFIterator::kpoint_grid_ = nullptr
protected

Definition at line 364 of file init.hpp.

Referenced by initialize_representation(), kpoint_grid(), and set_owned_kpoint_grid().

◆ magnetization_

std::optional<Magnetization> q3::PlanewaveKohnShamSCFIterator::magnetization_
protected

Set by report_convergence_details(); see magnetization() above.

Definition at line 361 of file init.hpp.

Referenced by magnetization(), and report_convergence_details().

◆ nscf_override_maximum_iterations_

std::optional<int> q3::PlanewaveKohnShamSCFIterator::nscf_override_maximum_iterations_
protected

The NSCF flavor's per-k-point Davidson cap, pending like the tolerance above and applied at the same point.

Definition at line 433 of file init.hpp.

Referenced by set_diagonalization_tolerance(), and q3::PlanewavePseudopotentialKohnShamSCFIterator::set_diagonalizer_maximum_iterations_for_nscf().

◆ nscf_override_tolerance_

std::optional<Real> q3::PlanewaveKohnShamSCFIterator::nscf_override_tolerance_
protected

When set (by set_diagonalizer_tolerance_for_nscf), overrides the initial loose tolerance on the first call to set_diagonalization_tolerance(). Stored as a pending value because the diagonalizer_ is not yet constructed when the NSCF flavor calls set_diagonalizer_tolerance_for_nscf() pre-run.

Definition at line 427 of file init.hpp.

Referenced by set_diagonalization_tolerance(), and q3::PlanewavePseudopotentialKohnShamSCFIterator::set_diagonalizer_tolerance_for_nscf().

◆ number_of_bands_

◆ number_of_electrons_

Real q3::PlanewaveKohnShamSCFIterator::number_of_electrons_ {0.0}
protected

◆ number_of_smooth_g_vectors_

int q3::PlanewaveKohnShamSCFIterator::number_of_smooth_g_vectors_ {0}
protected

Number of smooth G-vectors for density residual (matching QE's smooth-grid count). For dual-grid US/PAW calculations, this excludes hard G-vectors above 4*ecutwfc.

Definition at line 411 of file init.hpp.

Referenced by compute_local_residual_between(), and initiate_mixer().

◆ owned_execution_policy_

std::unique_ptr<execution::PlanewaveExecutionPolicy> q3::PlanewaveKohnShamSCFIterator::owned_execution_policy_
protected

Optional owned execution policy — transfers lifetime from the factory.

IMPORTANT: This member MUST be declared before planewave_basis_ and all other MPI-using members. C++ destroys members in reverse declaration order, so members declared AFTER this one are destroyed BEFORE it. The owned policy calls MPI_Finalize() in its destructor; planewave_basis_ contains MPIFFTGrid which calls fftw_destroy_plan (which internally frees MPI communicators) in its destructor. If planewave_basis_ were destroyed after MPI_Finalize, OpenMPI would report a fatal MPI_Comm_free-after-MPI_Finalize violation.

Definition at line 386 of file init.hpp.

Referenced by initialize_representation(), and set_owned_execution_policy().

◆ planewave_basis_

PlanewaveBasis q3::PlanewaveKohnShamSCFIterator::planewave_basis_
protected

◆ quantum_system_

◆ replicated_plane_wave_fallback_active_

bool q3::PlanewaveKohnShamSCFIterator::replicated_plane_wave_fallback_active_ = false
protected

Whether band distribution was abandoned during setup because some rank's FFT slab contained no plane waves. Reported in the setup summary, since it silently changes the parallel behaviour of the whole run.

Definition at line 1229 of file init.hpp.

Referenced by build_kpoint_plane_wave_data(), and log_representation_summary().

◆ report_unconverged_bands_

bool q3::PlanewaveKohnShamSCFIterator::report_unconverged_bands_ = false
protected

Set once the NSCF cap is applied: a single pass keeps whatever a solve leaves unconverged, so each such solve is counted and reported.

Definition at line 439 of file init.hpp.

Referenced by set_diagonalization_tolerance().

◆ wavefunction_energy_cutoff_

Real q3::PlanewaveKohnShamSCFIterator::wavefunction_energy_cutoff_ = 30.0
protected

The documentation for this class was generated from the following file: