ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
DFTU_LCAO Namespace Reference

Classes

struct  FoldingCtx
 Shared context for the folding helpers. Bundles the read-only parameters that every folding variant needs (npol, ks_solver, orbital cutoffs, unit cell, parallel-orbitals descriptor, and the grid driver) so the per-call signatures stay small. More...
class  DftuFsEnv
 Immutable shared environment for the DFT+U force/stress kernels. More...

Typedefs

using NlmTot = std::vector<std::vector<std::unordered_map<int, std::vector<double>>>>

Functions

std::vector< AdjacentAtomInfo > build_adjacent_atoms (const UnitCell *ucell, Plus_U_Base *dftu, const Grid_Driver *gridD, const std::vector< double > &orb_cutoff, const double onsite_radius)
 build the adjacent-atom lists for all Hubbard atoms.
NlmTot cal_nlm_all (const UnitCell &ucell, const Plus_U_Base &dftu, const TwoCenterIntegrator &intor, const std::vector< AdjacentAtomInfo > &adjs_all, const Parallel_Orbitals &pv)
 calculate the <phi|alpha^I> overlap values for all Hubbard atoms.
double calc_energy_u_collinear (const Plus_U_Base &dftu, int T, int iat, int l)
 Accumulate the DFT+U energy term (0.5 * U * (n - n^2)) for one (T, iat, l) channel in the collinear case (nspin=1 or 2). Returns the per-atom contribution to energy_u.
double calc_energy_u_noncollinear (const Plus_U_Base &dftu, int T, int iat, int l)
 Accumulate the DFT+U energy term for one (T, iat, l) channel in the noncollinear case (nspin=4). Returns the per-atom contribution to energy_u.
double calc_energy_dc_block (const Plus_U_Base &dftu, int T, int iat, int l, int nspin)
 Accumulate the double-counting correction energy_dc for one (T, iat, l) channel by summing onsite_pot * occ over the (m1, ipol1, m2, ipol2) grid. Dispatches on nspin to choose the spin loop count. Returns the per-atom contribution to energy_dc.
void cal_energy_correction (Plus_U_Base &dftu, const UnitCell &ucell, int nspin)
 DFT+U energy correction with the double-counting term subtracted.
bool is_adjacent_pair (const std::vector< double > &orb_cutoff, const UnitCell &ucell, const Grid_Driver &gd, int T1, int T2, const ModuleBase::Vector3< double > &tau1, const ModuleBase::Vector3< double > &tau2)
 Judge whether atom pair (T1,I1) and (T2,I2,tau2) are adjacent by direct orbital cutoff overlap or three-body bridging via a common nonlocal projector center T0.
int get_linear_index (const std::string &ks_solver, int mu, int nu, const Parallel_Orbitals &pv)
 Get the linear index of local matrix element (mu, nu) based on ks_solver (column-major or row-major).
void fold_dSR_gamma (const FoldingCtx &ctx, double *dsloc_x, double *dsloc_y, double *dsloc_z, double *dh_r, int dim1, int dim2, double *dSR_gamma)
 Fold the dSR matrix for gamma-only calculations. npol is the spin-polarization factor; orb_cutoff and ks_solver are forwarded to is_adjacent_pair and get_linear_index.
void folding_matrix_k (const FoldingCtx &ctx, ForceStressArrays &fsr, int ik, int dim1, int dim2, std::complex< double > *mat_k, const ModuleBase::Vector3< double > &kvec_d)
void folding_matrix_k_new (const std::string &ks_solver, bool gamma_only_local, int nspin, int ik, hamilt::Hamilt< std::complex< double > > *p_ham)
 new function of folding_S_matrix only for Hamiltonian now, for force and stress will be developed later use HContainer as input and output in mat_k
void cal_for_IJR_nao_r (const int &iat1, const int &iat2, const Parallel_Orbitals *pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const std::vector< double > &pot_onsite_in, const hamilt::BaseMatrix< double > **dmR_pointer, const int nspin, double *force1, double *force2)
 Compute DFT+U force contribution from a single atom pair (I,J,R) in real space.
template<typename T>
void accumulate_diag_force (const Parallel_Orbitals &pv, const UnitCell &ucell, const T *dm, const int dim, ModuleBase::matrix &force_dftu)
 Add the real part of diagonal local-block entries to one force component.
template<typename T>
void accumulate_diag_stress (const Parallel_Orbitals &pv, const T *dm, const int dim1, const int dim2, const double factor, ModuleBase::matrix &stress_dftu)
 Add the real part of diagonal local-block entries to one stress pair.
void cal_force_k (const DftuFsEnv &env, const int ik, const ModuleBase::Vector3< double > &kvec_d, const std::complex< double > *rho_pot_onsite, ModuleBase::matrix &force_dftu)
void cal_stress_k (const DftuFsEnv &env, const int ik, const ModuleBase::Vector3< double > &kvec_d, const std::complex< double > *rho_pot_onsite, ModuleBase::matrix &stress_dftu)
void cal_force_gamma (const DftuFsEnv &env, const double *rho_pot_onsite, ModuleBase::matrix &force_dftu)
void cal_stress_gamma (const DftuFsEnv &env, const double *rho_pot_onsite, ModuleBase::matrix &stress_dftu)
void force_stress (const DftuFsEnv &env, const bool cal_force, const bool cal_stress, std::vector< std::vector< double > > *dmk_d, std::vector< std::vector< std::complex< double > > > *dmk_c, ModuleBase::matrix &force_dftu, ModuleBase::matrix &stress_dftu, const K_Vectors &kv, const bool gamma_only_local)
 Top-level entry: drives force/stress from DFT+U.
void cal_fs_nao_r_impl (const UnitCell *ucell, Plus_U_Base *dftu, const TwoCenterIntegrator *intor, int nspin, const std::vector< AdjacentAtomInfo > &adjs_all, const std::vector< const hamilt::HContainer< double > * > &dmR, bool cal_force, bool cal_stress, ModuleBase::matrix &force, ModuleBase::matrix &stress)
 Non-template core of DFT+U force/stress in real space.
void cal_fs_nao_r (const UnitCell *ucell, Plus_U_Base *dftu, const TwoCenterIntegrator *intor, int nspin, const std::vector< AdjacentAtomInfo > &adjs_all, const std::vector< const hamilt::HContainer< double > * > &dmR, bool cal_force, bool cal_stress, ModuleBase::matrix &force, ModuleBase::matrix &stress)
 Calculate DFT+U force and stress in real space from explicit environment arguments (non-template overload).
void reduce_force_impl (ModuleBase::matrix &force, int nspin)
 Post-process force: MPI Allreduce and spin-degeneracy scaling.
void reduce_stress_impl (const UnitCell *ucell, const std::vector< double > &stress_tmp, ModuleBase::matrix &stress)
 Post-process stress: MPI Allreduce and renormalization to full 3x3 tensor from Voigt-like 6-component form.
void load_occ_from_file (const Plus_U_Base &dftu, const int iat0, const int target_L, const int nspin, const int current_spin, std::vector< double > &occ)
 load the flattened occupation matrix of one Hubbard atom from pre-read occ_mat data.
template<typename TR>
void cal_hr_ijr (const int iat1, const int iat2, const int npol, const Parallel_Orbitals &pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const std::vector< TR > &pot_onsite, TR *data_pointer)
 accumulate one real-space HR atom-pair block for DFT+U: HR += <psi_I|beta_m> * pot_onsite(m,m') * <beta_m'|psi_{J,R}>
void cal_occ_ijr (const int iat1, const int iat2, const int npol, const Parallel_Orbitals &pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const double *dm_pointer, std::vector< double > &occ)
 accumulate one atom-pair contribution to the DFT+U occupation matrix: occ_mm' += sum_R DMR(I,J,R) * <phi_0|alpha^I_m> * <alpha^J_m'|phi_R>
template<typename Body>
void for_adj_pair (const UnitCell &ucell, const int iat0, const AdjacentAtomInfo &adjs, const NlmTot &nlm_tot, Body &&body)
 walk all (ad1, ad2) adjacent-atom pairs of one Hubbard atom iat0 and invoke body for each pair that has a matching matrix block.
template<typename TR>
void accumulate_hr_for_iat0 (const UnitCell &ucell, hamilt::HContainer< TR > *hR, const NlmTot &nlm_tot, const int iat0, const AdjacentAtomInfo &adjs, const Parallel_Orbitals &pv, const std::vector< TR > &pot_onsite)
 accumulate the real-space HR contributions of one Hubbard atom (iat0) from the precomputed pot_onsite: HR(I,J,R) += <phi_I|chi_m> pot_onsite(m,m') <chi_m'|phi_{J,R}>
void compute_occ_from_dmr (const UnitCell &ucell, Plus_U_Base &dftu, const int iat0, const int target_L, const int current_spin, const int nspin, const AdjacentAtomInfo &adjs, const Parallel_Orbitals &pv, const NlmTot &nlm_tot, const hamilt::HContainer< double > &dmR_current, std::vector< double > &occ)
 compute the occupation matrix of one Hubbard atom (iat0) from the real-space density matrix: occ(m,m') = sum_R DMR(I,J,R) * <phi_0|chi_m(I)> * <chi_m'(J)|phi_R> then MPI-Allreduce it and store it into the Plus_U occupation matrix.
void cal_occ_mat_k (const Parallel_Orbitals *pv, const UnitCell &ucell, const std::vector< std::vector< std::complex< double > > > &dm_k, const K_Vectors &kv, const double &mixing_beta, hamilt::Hamilt< std::complex< double > > *p_ham, const bool gamma_only_local, Plus_U_Base &dftu, const std::string &ks_solver)
void cal_occ_mat_gamma (const Parallel_Orbitals *pv, const UnitCell &ucell, const std::vector< std::vector< double > > &dm_gamma, const double &mixing_beta, hamilt::Hamilt< double > *p_ham, Plus_U_Base &dftu)
template<typename T>
void cal_occ_mat (const Parallel_Orbitals *pv, const UnitCell &ucell, const std::vector< std::vector< T > > &dm, const K_Vectors &kv, const double &mixing_beta, hamilt::Hamilt< T > *p_ham, Plus_U_Base &dftu, const bool gamma_only_local, const int nspin, const std::string &ks_solver)
 Compute the occupation matrix occ(m,m') = sum_R DMR(I,J,R) * <phi_0|chi_m(I)> * <chi_m'(J)|phi_R> and delegate to the Plus_U member.
void cal_pot_onsite (const std::vector< double > &occ, const int m_size, const double u_value, double *pot_onsite, double &eu)
 On-site potential and Hubbard energy for one correlated shell: pot_onsite(m,m') = U_eff * (0.5 * delta_{m,m'} - occ(m,m')) EU = (U_eff / 2) * sum_{m,m'} occ(m,m') * (delta_{m,m'} - occ(m',m)).
template<typename TR>
void transfer_pot_onsite (const std::vector< double > &pot_onsite_tmp, std::vector< TR > &pot_onsite)
 transfer pot_onsite format from Pauli matrix storage to the target matrix-element type used by the Hamiltonian.
template<>
void transfer_pot_onsite< std::complex< double > > (const std::vector< double > &pot_onsite_tmp, std::vector< std::complex< double > > &pot_onsite)
double get_onsite_pot (const Plus_U_Base &dftu, const int T, const int iat, const int L, const int spin, const int m0, const int m1, const bool new_occ_mat)
 one-body effective onsite potential element for a given (m0,m1) pair.
template<typename T>
void cal_pot_onsite (const Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, const bool new_occ_mat, T *pot_onsite)
 Calculate onsite effective potential matrix in the local orbital basis.
template void cal_pot_onsite< double > (const Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, const bool new_occ_mat, double *pot_onsite)
template void cal_pot_onsite< std::complex< double > > (const Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, const bool new_occ_mat, std::complex< double > *pot_onsite)
template<typename T>
void cal_pot_uterm (Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, T *pot_uterm, const T *sk)
 Compute the LCAO-basis U-term effective potential matrix.
template void cal_pot_uterm< double > (Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, double *pot_uterm, const double *sk)
template void cal_pot_uterm< std::complex< double > > (Plus_U_Base &dftu, const UnitCell &ucell, const Parallel_Orbitals *pv, const int spin, std::complex< double > *pot_uterm, const std::complex< double > *sk)
void cal_str_IJR_nao_r (const int &iat1, const int &iat2, const Parallel_Orbitals *pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const std::vector< double > &pot_onsite_in, const hamilt::BaseMatrix< double > **dmR_pointer, const int nspin, const ModuleBase::Vector3< double > &dis1, const ModuleBase::Vector3< double > &dis2, double *stress)
 Compute DFT+U stress contribution from a single atom pair (I,J,R) in real space.
 TEST (GetLinearIndexTest, RowMajor)
 TEST (GetLinearIndexTest, ColumnMajor)

Typedef Documentation

◆ NlmTot

using DFTU_LCAO::NlmTot = std::vector<std::vector<std::unordered_map<int, std::vector<double>>>>

The <phi|alpha^I> overlap values for all [atoms][neighbors][orb_index(iw) in NAOs][m of target_l in Projectors]

Function Documentation

◆ accumulate_diag_force()

template<typename T>
void DFTU_LCAO::accumulate_diag_force ( const Parallel_Orbitals & pv,
const UnitCell & ucell,
const T * dm,
const int dim,
ModuleBase::matrix & force_dftu )

Add the real part of diagonal local-block entries to one force component.

Sums dm(ir, ic) over local block pairs whose global orbital indices coincide, attributing each entry to the atom owning the orbital along Cartesian component dim.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accumulate_diag_stress()

template<typename T>
void DFTU_LCAO::accumulate_diag_stress ( const Parallel_Orbitals & pv,
const T * dm,
const int dim1,
const int dim2,
const double factor,
ModuleBase::matrix & stress_dftu )

Add the real part of diagonal local-block entries to one stress pair.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accumulate_hr_for_iat0()

template<typename TR>
void DFTU_LCAO::accumulate_hr_for_iat0 ( const UnitCell & ucell,
hamilt::HContainer< TR > * hR,
const NlmTot & nlm_tot,
const int iat0,
const AdjacentAtomInfo & adjs,
const Parallel_Orbitals & pv,
const std::vector< TR > & pot_onsite )

accumulate the real-space HR contributions of one Hubbard atom (iat0) from the precomputed pot_onsite: HR(I,J,R) += <phi_I|chi_m> pot_onsite(m,m') <chi_m'|phi_{J,R}>

Template Parameters
TRreal-space Hamiltonian scalar type: double for NSPIN=1,2 and std::complex<double> for NSPIN=4
Parameters
ucell[in] unit cell (atom index maps, npol)
hR[in,out] real-space Hamiltonian container; matching atom-pair blocks are updated in place
nlm_tot[in] <phi|alpha^I> overlap table for all atoms
iat0[in] global atom index of the Hubbard atom
adjs[in] adjacent atom info of the Hubbard atom
pv[in] parallel-orbitals descriptor providing local index maps
pot_onsite[in] onsite potential matrix packed in npol*npol spin blocks
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_adjacent_atoms()

std::vector< AdjacentAtomInfo > DFTU_LCAO::build_adjacent_atoms ( const UnitCell * ucell,
Plus_U_Base * dftu,
const Grid_Driver * gridD,
const std::vector< double > & orb_cutoff,
const double onsite_radius )

build the adjacent-atom lists for all Hubbard atoms.

For every atom whose type carries a Hubbard-U channel, find its neighbor atoms within orb_cutoff + onsite_radius and filter the AdjacentAtomInfo accordingly.

Parameters
ucell[in] unit cell
dftu[in] DFT+U base object (per-type U channels)
gridD[in] grid driver for neighbor search
orb_cutoff[in] orbital cutoff radius per atom type
onsite_radius[in] onsite projector cutoff radius
Returns
one AdjacentAtomInfo per Hubbard atom, in atom order
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_energy_correction()

void DFTU_LCAO::cal_energy_correction ( Plus_U_Base & dftu,
const UnitCell & ucell,
int nspin )

DFT+U energy correction with the double-counting term subtracted.

DFT+U energy correction with the double-counting term subtracted: E = E_U - E_dc, with E_U = (U_eff / 2) * sum_{m,m'} occ(m,m') * (delta_{m,m'} - occ(m',m)) E_dc = sum_{m,m'} onsite_pot(m,m') * occ(m',m).

Computes energy_u from occ_mat and the onsite potential, then writes the result back to dftu via set_energy. The spin channel count is sourced by the caller from the input parameter to avoid a PARAM read here.

Parameters
dftuPlus_U_Base state (mutable: set_energy is called at the end)
ucellunit cell
nspinnumber of spin channels (1, 2, or 4); sourced by the caller from the input parameter to avoid a PARAM read here
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_for_IJR_nao_r()

void DFTU_LCAO::cal_for_IJR_nao_r ( const int & iat1,
const int & iat2,
const Parallel_Orbitals * pv,
const std::unordered_map< int, std::vector< double > > & nlm1_all,
const std::unordered_map< int, std::vector< double > > & nlm2_all,
const std::vector< double > & pot_onsite_in,
const hamilt::BaseMatrix< double > ** dmR_pointer,
const int nspin,
double * force1,
double * force2 )

Compute DFT+U force contribution from a single atom pair (I,J,R) in real space.

For a given on-site atom I with correlated orbital l, and a pair of basis atoms (J1, J2) separated by lattice vector R, the force contribution is:

F_{J1} += sum_{m,m'} V_U_{mm'}(I) * <phi_{mu,0}|chi_m(I)>

  • d<chi_m'(I)|phi_{nu,R}>/d tau_{J1} * DMR_{mu,nu}(J1,J2,R)

F_{J2} -= sum_{m,m'} V_U_{mm'}(I) * d<phi_{mu,0}|chi_m(I)>/d tau_{J2}

  • <chi_m'(I)|phi_{nu,R}> * DMR_{mu,nu}(J1,J2,R)

where mu runs over orbitals on J1, nu over orbitals on J2, and m,m' over the 2l+1 magnetic quantum numbers of the correlated orbital.

The two-center integrals <phi|chi> and their derivatives are pre-computed by TwoCenterIntegrator::snap() and stored in nlm_tot.

Parameters
iat1[in] global atom index of J1
iat2[in] global atom index of J2
pv[in] Parallel_Orbitals for basis index mapping
nlm1_all[in] pre-computed <phi|chi> and derivatives for atom J1
nlm2_all[in] pre-computed <phi|chi> and derivatives for atom J2
pot_onsite[in] flattened V_U matrix: [m1*m_size + m2 + is*m_size2]
dmR_pointer[in] pointer to DMR matrix blocks for each spin
nspin[in] number of spin channels (1, 2, or 4); the spinor polarization count is derived as npol = 2 for nspin=4 (non-collinear) and npol = 1 otherwise
force1[out] force accumulator for atom J1 (3 components)
force2[out] force accumulator for atom J2 (3 components)
Note
For nspin=1, the force is scaled by 2.0 at the caller level to account for spin degeneracy. For nspin=2, spin-up and spin-down are summed explicitly. For nspin=4 (non-collinear), the spinor structure is handled via npol=2 indexing.
Here is the call graph for this function:

◆ cal_force_gamma()

void DFTU_LCAO::cal_force_gamma ( const DftuFsEnv & env,
const double * rho_pot_onsite,
ModuleBase::matrix & force_dftu )
Here is the call graph for this function:

◆ cal_force_k()

void DFTU_LCAO::cal_force_k ( const DftuFsEnv & env,
const int ik,
const ModuleBase::Vector3< double > & kvec_d,
const std::complex< double > * rho_pot_onsite,
ModuleBase::matrix & force_dftu )
Here is the call graph for this function:

◆ cal_fs_nao_r()

void DFTU_LCAO::cal_fs_nao_r ( const UnitCell * ucell,
Plus_U_Base * dftu,
const TwoCenterIntegrator * intor,
int nspin,
const std::vector< AdjacentAtomInfo > & adjs_all,
const std::vector< const hamilt::HContainer< double > * > & dmR,
bool cal_force,
bool cal_stress,
ModuleBase::matrix & force,
ModuleBase::matrix & stress )

Calculate DFT+U force and stress in real space from explicit environment arguments (non-template overload).

This overload does not require a DFTU operator object; it is intended for callers that only need force/stress and already hold the required data.

Parameters
ucell[in] unit cell
dftu[in] DFT+U base object (occupation matrix, U values)
intor[in] two-center integrator for <phi|chi> and gradients
nspin[in] number of spin channels (1, 2, or 4)
adjs_all[in] adjacent atom info for all atoms with plus-U
dmR[in] density matrices in real space, size nspin
cal_force[in] whether to compute force
cal_stress[in] whether to compute stress
force[out] force matrix (nat, 3), accumulated
stress[out] stress matrix (3, 3), accumulated
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_fs_nao_r_impl()

void DFTU_LCAO::cal_fs_nao_r_impl ( const UnitCell * ucell,
Plus_U_Base * dftu,
const TwoCenterIntegrator * intor,
int nspin,
const std::vector< AdjacentAtomInfo > & adjs_all,
const std::vector< const hamilt::HContainer< double > * > & dmR,
bool cal_force,
bool cal_stress,
ModuleBase::matrix & force,
ModuleBase::matrix & stress )

Non-template core of DFT+U force/stress in real space.

All types are concrete and independent of the operator's k-point type (TK) and real-space type (TR). The template wrapper cal_fs_nao_r only validates the density matrix and forwards arguments here.

Note
Hard to unit-test: requires TwoCenterIntegrator (numerical orbital radial integration) to build nlm via build_nlm. The inner function acc_fs_pairs is directly testable with a mock nlm_tot; build_nlm is not.
Parameters
ucell[in] unit cell
dftu[in] DFT+U base object (occupation matrix, U values)
intor[in] two-center integrator for <phi|chi> and gradients
nspin[in] number of spin channels (1, 2, or 4)
adjs_all[in] adjacent atom info for all atoms with plus-U
dmR[in] density matrices in real space, size nspin
cal_force[in] whether to compute force
cal_stress[in] whether to compute stress
force[out] force matrix (nat, 3), accumulated
stress[out] stress matrix (3, 3), accumulated
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_hr_ijr()

template<typename TR>
void DFTU_LCAO::cal_hr_ijr ( const int iat1,
const int iat2,
const int npol,
const Parallel_Orbitals & pv,
const std::unordered_map< int, std::vector< double > > & nlm1_all,
const std::unordered_map< int, std::vector< double > > & nlm2_all,
const std::vector< TR > & pot_onsite,
TR * data_pointer )

accumulate one real-space HR atom-pair block for DFT+U: HR += <psi_I|beta_m> * pot_onsite(m,m') * <beta_m'|psi_{J,R}>

Template Parameters
TRreal-space Hamiltonian scalar type: double for NSPIN=1,2 and std::complex<double> for NSPIN=4
Parameters
iat1global atom index of the row atom I
iat2global atom index of the column atom J
npolnumber of polarizations: 1 for NSPIN=1,2 and 2 for the non-collinear case (NSPIN=4)
pvparallel-orbitals descriptor providing local index maps
nlm1_all<psi_I|beta_m> overlap values keyed by local row index
nlm2_all<beta_m'|psi_J> overlap values keyed by local column index
pot_onsiteonsite potential matrix packed in npol*npol spin blocks
data_pointerpointer to the local HR matrix block; updated in place
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_nlm_all()

NlmTot DFTU_LCAO::cal_nlm_all ( const UnitCell & ucell,
const Plus_U_Base & dftu,
const TwoCenterIntegrator & intor,
const std::vector< AdjacentAtomInfo > & adjs_all,
const Parallel_Orbitals & pv )

calculate the <phi|alpha^I> overlap values for all Hubbard atoms.

The result is indexed by global atom index (empty entries for non-Hubbard atoms) and reused in the HR/occupation accumulation.

Parameters
ucell[in] unit cell
dftu[in] DFT+U base object (per-type U channels)
intor[in] two-center integrator for <phi|chi_m>
adjs_all[in] adjacent atom info for all Hubbard atoms
pv[in] parallel-orbitals descriptor providing local index maps
Returns
the overlap table, one outer entry per atom (ucell->nat entries)
Here is the call graph for this function:

◆ cal_occ_ijr()

void DFTU_LCAO::cal_occ_ijr ( const int iat1,
const int iat2,
const int npol,
const Parallel_Orbitals & pv,
const std::unordered_map< int, std::vector< double > > & nlm1_all,
const std::unordered_map< int, std::vector< double > > & nlm2_all,
const double * dm_pointer,
std::vector< double > & occ )
inline

accumulate one atom-pair contribution to the DFT+U occupation matrix: occ_mm' += sum_R DMR(I,J,R) * <phi_0|alpha^I_m> * <alpha^J_m'|phi_R>

Parameters
iat1global atom index of the row atom I
iat2global atom index of the column atom J
npolnumber of polarizations: 1 for NSPIN=1,2 and 2 for the non-collinear case (NSPIN=4)
pvparallel-orbitals descriptor providing local index maps
nlm1_all<phi_0|alpha^I_m> overlap values keyed by local row index
nlm2_all<alpha^J_m'|phi_R> overlap values keyed by local column index
dm_pointerpointer to the local real-space DMR block of (I,J,R)
occoccupation matrix packed in npol*npol spin blocks; updated in place
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_occ_mat()

template<typename T>
void DFTU_LCAO::cal_occ_mat ( const Parallel_Orbitals * pv,
const UnitCell & ucell,
const std::vector< std::vector< T > > & dm,
const K_Vectors & kv,
const double & mixing_beta,
hamilt::Hamilt< T > * p_ham,
Plus_U_Base & dftu,
const bool gamma_only_local,
const int nspin,
const std::string & ks_solver )

Compute the occupation matrix occ(m,m') = sum_R DMR(I,J,R) * <phi_0|chi_m(I)> * <chi_m'(J)|phi_R> and delegate to the Plus_U member.

Parameters
pvparallel-orbitals descriptor that owns BLACS context and global<->local index maps; sourced by the caller from the same Parallel_Orbitals used to build the Hamiltonian and density matrix.
ks_solverKS solver name (e.g. "scalapack"); forwarded to the multi-k path for folding-matrix selection.
Here is the caller graph for this function:

◆ cal_occ_mat_gamma()

void DFTU_LCAO::cal_occ_mat_gamma ( const Parallel_Orbitals * pv,
const UnitCell & ucell,
const std::vector< std::vector< double > > & dm_gamma,
const double & mixing_beta,
hamilt::Hamilt< double > * p_ham,
Plus_U_Base & dftu )
Here is the call graph for this function:

◆ cal_occ_mat_k()

void DFTU_LCAO::cal_occ_mat_k ( const Parallel_Orbitals * pv,
const UnitCell & ucell,
const std::vector< std::vector< std::complex< double > > > & dm_k,
const K_Vectors & kv,
const double & mixing_beta,
hamilt::Hamilt< std::complex< double > > * p_ham,
const bool gamma_only_local,
Plus_U_Base & dftu,
const std::string & ks_solver )
Here is the call graph for this function:

◆ cal_pot_onsite() [1/2]

template<typename T>
void DFTU_LCAO::cal_pot_onsite ( const Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
const bool new_occ_mat,
T * pot_onsite )

Calculate onsite effective potential matrix in the local orbital basis.

Fills pot_onsite (length pv->nloc) with the onsite potential elements projected onto the local orbital indices.

Parameters
dftuPlus_U state
ucellunit cell
pvparallel orbitals descriptor
spinspin channel
new_occ_matif true use occ_mat, otherwise use occ_mat_save
pot_onsiteoutput buffer (length pv->nloc)
Here is the call graph for this function:

◆ cal_pot_onsite() [2/2]

void DFTU_LCAO::cal_pot_onsite ( const std::vector< double > & occ,
const int m_size,
const double u_value,
double * pot_onsite,
double & eu )

On-site potential and Hubbard energy for one correlated shell: pot_onsite(m,m') = U_eff * (0.5 * delta_{m,m'} - occ(m,m')) EU = (U_eff / 2) * sum_{m,m'} occ(m,m') * (delta_{m,m'} - occ(m',m)).

Non-template core extracted from DFTU_onsite<OperatorLCAO<TK,TR>>::cal_pot_onsite.

Parameters
occflattened occupation matrix, size m_size*m_size*spin_fold
m_sizenumber of magnetic quantum states (2*l+1)
u_valueeffective U parameter
pot_onsiteoutput potential, same size as occ
euoutput Hubbard energy contribution

On-site potential and Hubbard energy for one correlated shell: pot_onsite(m,m') = U_eff * (0.5 * delta_{m,m'} - occ(m,m')) EU = (U_eff / 2) * sum_{m,m'} occ(m,m') * (delta_{m,m'} - occ(m',m))

Here is the caller graph for this function:

◆ cal_pot_onsite< double >()

template void DFTU_LCAO::cal_pot_onsite< double > ( const Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
const bool new_occ_mat,
double * pot_onsite )
extern

◆ cal_pot_onsite< std::complex< double > >()

template void DFTU_LCAO::cal_pot_onsite< std::complex< double > > ( const Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
const bool new_occ_mat,
std::complex< double > * pot_onsite )
extern
Here is the call graph for this function:

◆ cal_pot_uterm()

template<typename T>
void DFTU_LCAO::cal_pot_uterm ( Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
T * pot_uterm,
const T * sk )

Compute the LCAO-basis U-term effective potential matrix.

DFT+U effective potential in the LCAO basis, with V = pot_onsite (the on-site Hubbard correction potential in the full basis) and S the overlap matrix. Returns the symmetrized k-space U-term potential: pot_uterm = (V*S + (V*S)^T) / 2

Template Parameters
Tmatrix element type (double or std::complex<double>)
Parameters
dftuPlus_U state
ucellunit cell
pvparallel orbitals descriptor
spinspin channel (isk[ik] from caller)
pot_utermoutput buffer (length pv->nloc)
skoverlap matrix in k-space (length pv->nloc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_pot_uterm< double >()

template void DFTU_LCAO::cal_pot_uterm< double > ( Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
double * pot_uterm,
const double * sk )
extern

◆ cal_pot_uterm< std::complex< double > >()

template void DFTU_LCAO::cal_pot_uterm< std::complex< double > > ( Plus_U_Base & dftu,
const UnitCell & ucell,
const Parallel_Orbitals * pv,
const int spin,
std::complex< double > * pot_uterm,
const std::complex< double > * sk )
extern
Here is the call graph for this function:

◆ cal_str_IJR_nao_r()

void DFTU_LCAO::cal_str_IJR_nao_r ( const int & iat1,
const int & iat2,
const Parallel_Orbitals * pv,
const std::unordered_map< int, std::vector< double > > & nlm1_all,
const std::unordered_map< int, std::vector< double > > & nlm2_all,
const std::vector< double > & pot_onsite_in,
const hamilt::BaseMatrix< double > ** dmR_pointer,
const int nspin,
const ModuleBase::Vector3< double > & dis1,
const ModuleBase::Vector3< double > & dis2,
double * stress )

Compute DFT+U stress contribution from a single atom pair (I,J,R) in real space.

The stress tensor component (alpha,beta) receives contributions from both the derivative of <phi|chi> with respect to the strain and the explicit R_beta factor:

sigma_{alpha,beta} += -(1/Omega) * sum_{m,m'} V_U_{mm'}(I) * DMR_{mu,nu}(J1,J2,R) * [ d<phi_{mu,0}|chi_m(I)>/d tau_{J1,alpha} * <chi_m'(I)|phi_{nu,R}> * R_{J1,beta}

  • <phi_{mu,0}|chi_m(I)> * d<chi_m'(I)|phi_{nu,R}>/d tau_{J2,alpha} * R_{J2,beta} ]

The strain derivative of the two-center integral is approximated by: d<phi|chi>/d epsilon_{alpha,beta} ~ d<phi|chi>/d tau_alpha * R_beta

Note
The stress is accumulated in Voigt notation (6 components: xx, xy, xz, yy, yz, zz) and symmetrized at the caller level. The final scaling by lat0/Omega is applied after MPI reduction.
Parameters
iat1[in] global atom index of J1
iat2[in] global atom index of J2
pv[in] Parallel_Orbitals for basis index mapping
nlm1_all[in] pre-computed <phi|chi> and derivatives for atom J1
nlm2_all[in] pre-computed <phi|chi> and derivatives for atom J2
pot_onsite[in] flattened V_U matrix
dmR_pointer[in] pointer to DMR matrix blocks for each spin
nspin[in] number of spin channels (1, 2, or 4); the spinor polarization count is derived as npol = 2 for nspin=4 (non-collinear) and npol = 1 otherwise
dis1[in] position vector of J1 relative to I
dis2[in] position vector of J2 relative to I
stress[out] stress accumulator (6 components in Voigt notation)
Here is the call graph for this function:

◆ cal_stress_gamma()

void DFTU_LCAO::cal_stress_gamma ( const DftuFsEnv & env,
const double * rho_pot_onsite,
ModuleBase::matrix & stress_dftu )
Here is the call graph for this function:

◆ cal_stress_k()

void DFTU_LCAO::cal_stress_k ( const DftuFsEnv & env,
const int ik,
const ModuleBase::Vector3< double > & kvec_d,
const std::complex< double > * rho_pot_onsite,
ModuleBase::matrix & stress_dftu )
Here is the call graph for this function:

◆ calc_energy_dc_block()

double DFTU_LCAO::calc_energy_dc_block ( const Plus_U_Base & dftu,
int T,
int iat,
int l,
int nspin )

Accumulate the double-counting correction energy_dc for one (T, iat, l) channel by summing onsite_pot * occ over the (m1, ipol1, m2, ipol2) grid. Dispatches on nspin to choose the spin loop count. Returns the per-atom contribution to energy_dc.

Accumulate the double-counting correction energy_dc for one (T, iat, l) channel: E_dc = sum_{m1,ipol1,m2,ipol2} onsite_pot(m1,ipol1;m2,ipol2) * occ(m2,ipol2;m1,ipol1) Returns the per-atom contribution to energy_dc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calc_energy_u_collinear()

double DFTU_LCAO::calc_energy_u_collinear ( const Plus_U_Base & dftu,
int T,
int iat,
int l )

Accumulate the DFT+U energy term (0.5 * U * (n - n^2)) for one (T, iat, l) channel in the collinear case (nspin=1 or 2). Returns the per-atom contribution to energy_u.

Accumulate the DFT+U energy term (U_eff / 2) * (n - n^2) for one (T, iat, l) channel in the collinear case (nspin=1 or 2). Returns the per-atom contribution to energy_u.

Here is the caller graph for this function:

◆ calc_energy_u_noncollinear()

double DFTU_LCAO::calc_energy_u_noncollinear ( const Plus_U_Base & dftu,
int T,
int iat,
int l )

Accumulate the DFT+U energy term for one (T, iat, l) channel in the noncollinear case (nspin=4). Returns the per-atom contribution to energy_u.

Here is the caller graph for this function:

◆ compute_occ_from_dmr()

void DFTU_LCAO::compute_occ_from_dmr ( const UnitCell & ucell,
Plus_U_Base & dftu,
const int iat0,
const int target_L,
const int current_spin,
const int nspin,
const AdjacentAtomInfo & adjs,
const Parallel_Orbitals & pv,
const NlmTot & nlm_tot,
const hamilt::HContainer< double > & dmR_current,
std::vector< double > & occ )
inline

compute the occupation matrix of one Hubbard atom (iat0) from the real-space density matrix: occ(m,m') = sum_R DMR(I,J,R) * <phi_0|chi_m(I)> * <chi_m'(J)|phi_R> then MPI-Allreduce it and store it into the Plus_U occupation matrix.

Parameters
ucell[in] unit cell (atom index maps, npol)
dftu[in,out] Plus_U state receiving the occupation matrix
iat0[in] global atom index of the Hubbard atom
target_L[in] angular momentum channel of the correlated shell
current_spin[in] active spin channel (0 for nspin=1/4)
nspin[in] number of spin components
adjs[in] adjacent atom info of the Hubbard atom
pv[in] parallel-orbitals descriptor providing local index maps
nlm_tot[in] <phi|alpha^I> overlap table for all atoms
dmR_current[in] real-space density matrix of the active spin
occ[out] flattened occupation matrix; overwritten
Here is the call graph for this function:

◆ fold_dSR_gamma()

void DFTU_LCAO::fold_dSR_gamma ( const FoldingCtx & ctx,
double * dsloc_x,
double * dsloc_y,
double * dsloc_z,
double * dh_r,
int dim1,
int dim2,
double * dSR_gamma )

Fold the dSR matrix for gamma-only calculations. npol is the spin-polarization factor; orb_cutoff and ks_solver are forwarded to is_adjacent_pair and get_linear_index.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ folding_matrix_k()

void DFTU_LCAO::folding_matrix_k ( const FoldingCtx & ctx,
ForceStressArrays & fsr,
int ik,
int dim1,
int dim2,
std::complex< double > * mat_k,
const ModuleBase::Vector3< double > & kvec_d )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ folding_matrix_k_new()

void DFTU_LCAO::folding_matrix_k_new ( const std::string & ks_solver,
bool gamma_only_local,
int nspin,
const int ik,
hamilt::Hamilt< std::complex< double > > * p_ham )

new function of folding_S_matrix only for Hamiltonian now, for force and stress will be developed later use HContainer as input and output in mat_k

Here is the call graph for this function:
Here is the caller graph for this function:

◆ for_adj_pair()

template<typename Body>
void DFTU_LCAO::for_adj_pair ( const UnitCell & ucell,
const int iat0,
const AdjacentAtomInfo & adjs,
const NlmTot & nlm_tot,
Body && body )
inline

walk all (ad1, ad2) adjacent-atom pairs of one Hubbard atom iat0 and invoke body for each pair that has a matching matrix block.

This is the common iteration skeleton shared by the HR accumulation (accumulate_hr_for_iat0), occupation-matrix computation (compute_occ_from_dmr), and the force/stress real-space implementation (cal_fs_nao_r_impl). The body receives (iat1, iat2, R_vector, nlm1, nlm2) and is responsible for the actual physics.

Parameters
ucell[in] unit cell (atom index maps)
iat0[in] global atom index of the Hubbard atom
adjs[in] adjacent atom info of the Hubbard atom
nlm_tot[in] <phi|alpha^I> overlap table for all atoms
body[in] callable with signature void(int iat1, int iat2, const ModuleBase::Vector3<int>& R_vector, const std::unordered_map<int, std::vector<double>>& nlm1, const std::unordered_map<int, std::vector<double>>& nlm2)
Here is the caller graph for this function:

◆ force_stress()

void DFTU_LCAO::force_stress ( const DftuFsEnv & env,
const bool cal_force,
const bool cal_stress,
std::vector< std::vector< double > > * dmk_d,
std::vector< std::vector< std::complex< double > > > * dmk_c,
ModuleBase::matrix & force_dftu,
ModuleBase::matrix & stress_dftu,
const K_Vectors & kv,
const bool gamma_only_local )

Top-level entry: drives force/stress from DFT+U.

Note
Hard to unit-test: requires DftuFsEnv which bundles Grid_Driver (neighbor search), Parallel_Orbitals (BLACS), ForceStressArrays (folded matrices), and TwoCenterIntegrator. The inner functions cal_force_k/gamma and cal_stress_k/gamma are testable with a mock DftuFsEnv.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_linear_index()

int DFTU_LCAO::get_linear_index ( const std::string & ks_solver,
const int mu,
const int nu,
const Parallel_Orbitals & pv )

Get the linear index of local matrix element (mu, nu) based on ks_solver (column-major or row-major).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_onsite_pot()

double DFTU_LCAO::get_onsite_pot ( const Plus_U_Base & dftu,
const int T,
const int iat,
const int L,
const int spin,
const int m0,
const int m1,
const bool new_occ_mat )

one-body effective onsite potential element for a given (m0,m1) pair.

Dispatches on UForm; only dud_fll (Dudarev simplified formalism with FLL double counting) is currently implemented, the other forms return 0.

Parameters
dftuPlus_U state providing U/J values and occupation matrices
Tatom type
iatglobal atom index
Langular momentum
spinspin channel
m0first magnetic quantum index (packed with polarization)
m1second magnetic quantum index (packed with polarization)
new_occ_matif true use occ_mat, otherwise use occ_mat_save
Returns
onsite potential matrix element
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_adjacent_pair()

bool DFTU_LCAO::is_adjacent_pair ( const std::vector< double > & orb_cutoff,
const UnitCell & ucell,
const Grid_Driver & gd,
int T1,
int T2,
const ModuleBase::Vector3< double > & tau1,
const ModuleBase::Vector3< double > & tau2 )

Judge whether atom pair (T1,I1) and (T2,I2,tau2) are adjacent by direct orbital cutoff overlap or three-body bridging via a common nonlocal projector center T0.

Parameters
orb_cutofforbital cutoff radii per atom type
Returns
true if the pair should be processed
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_occ_from_file()

void DFTU_LCAO::load_occ_from_file ( const Plus_U_Base & dftu,
const int iat0,
const int target_L,
const int nspin,
const int current_spin,
std::vector< double > & occ )
inline

load the flattened occupation matrix of one Hubbard atom from pre-read occ_mat data.

Parameters
dftuPlus_U state providing the stored occupation matrix
iat0global atom index of the Hubbard atom
target_Langular momentum channel of the correlated shell
nspinnumber of spin components
current_spinactive spin channel for nspin=2
occoutput flattened occupation matrix

◆ reduce_force_impl()

void DFTU_LCAO::reduce_force_impl ( ModuleBase::matrix & force,
int nspin )

Post-process force: MPI Allreduce and spin-degeneracy scaling.

Parameters
force[in,out] force matrix (nat, 3), reduced and scaled
nspin[in] number of spin channels (1, 2, or 4)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduce_stress_impl()

void DFTU_LCAO::reduce_stress_impl ( const UnitCell * ucell,
const std::vector< double > & stress_tmp,
ModuleBase::matrix & stress )

Post-process stress: MPI Allreduce and renormalization to full 3x3 tensor from Voigt-like 6-component form.

Parameters
ucell[in] unit cell (for lat0/omega)
stress_tmp[in] Voigt-like 6-component stress, reduced in-place
stress[out] full 3x3 stress tensor
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TEST() [1/2]

DFTU_LCAO::TEST ( GetLinearIndexTest ,
ColumnMajor  )
Here is the call graph for this function:

◆ TEST() [2/2]

DFTU_LCAO::TEST ( GetLinearIndexTest ,
RowMajor  )
Here is the call graph for this function:

◆ transfer_pot_onsite()

template<typename TR>
void DFTU_LCAO::transfer_pot_onsite ( const std::vector< double > & pot_onsite_tmp,
std::vector< TR > & pot_onsite )

transfer pot_onsite format from Pauli matrix storage to the target matrix-element type used by the Hamiltonian.

Generic overload performs an identity copy. The complex specialization converts Pauli blocks to spinor blocks for the non-collinear case.

Parameters
pot_onsite_tmpinput onsite potential in Pauli-block storage
pot_onsiteoutput onsite potential in target storage
Here is the caller graph for this function:

◆ transfer_pot_onsite< std::complex< double > >()

template<>
void DFTU_LCAO::transfer_pot_onsite< std::complex< double > > ( const std::vector< double > & pot_onsite_tmp,
std::vector< std::complex< double > > & pot_onsite )
inline
Here is the call graph for this function: