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

Classes

struct  ShiftRealComplex
 map a real/complex type to the opposite one ShiftRealComplex<double>::type = std::complex<double> ShiftRealComplex<std::complex<double>>::type = double More...
struct  ShiftRealComplex< double >
struct  ShiftRealComplex< std::complex< double > >
class  DensityMatrix
 DensityMatrix Class <TK,TR> = <double,double> for Gamma-only calculation <TK,TR> = <std::complex<double>,double> for multi-k calculation. More...
struct  DmrBlock
 geometry of one atom-pair sub-block within the global DMK matrix row0/col0: global index of the block's top-left element in the 2D block-cyclic DMK nrows/ncols: orbital dimensions of the two atoms More...
class  Setup_DM
struct  Init_DM_Config

Functions

template<typename TK, typename TR_in, typename TR_out>
void cal_dmr (const DensityMatrix< TK, TR_in > &dm, std::vector< hamilt::HContainer< TR_out > * > &dmR_out, const int ik_in)
template<typename TK, typename TR_in, typename TR_out>
void cal_dmr_td (DensityMatrix< TK, TR_in > &dm, std::vector< hamilt::HContainer< TR_out > * > &dmR_out, const std::map< ModuleBase::Vector3< int >, std::complex< double > > &phase_hybrid, const ModuleBase::Vector3< double > At, const int ik_in)
template<typename TK, typename TR_in, typename TR_out>
void cal_dmr_full (const DensityMatrix< TK, TR_in > &dm, hamilt::HContainer< TR_out > *dmR_out, const int ik_in)
template<typename TK, typename TR_in, typename TR_out>
void accumulate_dmr (const DensityMatrix< TK, TR_in > &dm, std::vector< hamilt::HContainer< TR_out > * > &dmR_out, const std::map< ModuleBase::Vector3< int >, std::complex< double > > &phase_hybrid, const int ik_in, const char *func_name)
 shared inner loop of cal_dmr / cal_dmr_td: for each spin channel, zero the DMR HContainer and accumulate kphase * DMK into DMR blocks. Pass an empty phase_hybrid map for the non-TD (cal_dmr) case.
template<typename TR>
void exp_mul_dmk (const std::complex< double > kphase, const std::vector< std::complex< double > > &dmk_row, TR *dmr_mat)
template<typename TR>
void xyz_to_updown (const std::complex< double > spin_block[4], const int icol, const int spin_stride[4], TR *dmr_mat)
DmrBlock get_dmr_block (const Parallel_Orbitals *pv, const int iat1, const int iat2)
 extract the block geometry for atom pair (iat1, iat2) from the parallel orbitals layout
template<typename TK, typename TR>
void build_kphase (hamilt::AtomPair< TR > &atom_pair, const std::vector< ModuleBase::Vector3< double > > &kvec_d, const int nk, const std::map< ModuleBase::Vector3< int >, std::complex< double > > &phase_hybrid, std::vector< std::vector< TK > > &kphase_vec, std::vector< TR * > &dmr_mats)
 precompute k-phase factors e^{ikR} and collect DMR block pointers for one atom pair
template<typename TK>
void transpose_dmk_block (const TK *dmk_col_major, const int ld_hk, const DmrBlock &block, TK *dmk_row)
 transpose a col-major DMK sub-block into row-major order
template<typename TK, typename TR>
void add_dmr_real (const DensityMatrix< TK, TR > &dm, const DmrBlock &block, const int ik_begin, const std::vector< std::vector< TK > > &kphase_vec, const int ld_hk, const int ik_in, std::vector< TR * > &dmr_mats)
 nspin=1/2: accumulate Re(kphase * DMK) into DMR blocks
template<typename TK, typename TR>
void add_dmr_soc (const DensityMatrix< TK, TR > &dm, const DmrBlock &block, const int ik_begin, const std::vector< std::vector< TK > > &kphase_vec, const int ld_hk, const int ik_in, const int col_stride, std::vector< TR * > &dmr_mats)
 nspin==4 (SOC): accumulate k-phase * DMK into a per-R complex buffer, then transform 2x2 spin blocks from (upup, updown, downup, downdown) to (rho_0, rho_x, rho_y, rho_z) via xyz_to_updown.
void dm_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const psi::Psi< double > &wfc, DensityMatrix< double, double > &DM)
 Calculate the k-point density matrix from wavefunctions for the Gamma-only case.
template<typename TR>
void dm_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const psi::Psi< std::complex< double > > &wfc, DensityMatrix< std::complex< double >, TR > &DM)
 Calculate the k-point density matrix from wavefunctions for the multi-k case.
void dmk_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const int ik, const psi::Psi< double > &wfc, double *dmk_out)
 Calculate one k-point block of the density matrix (Gamma-only case).
void dmk_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const int ik, const psi::Psi< std::complex< double > > &wfc, std::complex< double > *dmk_out)
 Calculate one k-point block of the density matrix (multi-k case).
template void dm_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const psi::Psi< std::complex< double > > &wfc, module_dm::DensityMatrix< std::complex< double >, std::complex< double > > &DM)
template void dm_from_psi (const Parallel_Orbitals *ParaV, const ModuleBase::matrix &wg, const psi::Psi< std::complex< double > > &wfc, module_dm::DensityMatrix< std::complex< double >, double > &DM)
template<typename TK>
void init_dm (UnitCell &ucell, elecstate::ElecState *pelec, Setup_DM< TK > &dmat, psi::Psi< TK > *psi, Charge &chr, const Parallel_Orbitals &pv, const int iter, const int exx_two_level_step, const Init_DM_Config &cfg)
template<>
void exp_mul_dmk< double > (const std::complex< double > kphase, const std::vector< std::complex< double > > &dmk_row, double *dmr_mat)
template<>
void exp_mul_dmk< std::complex< double > > (const std::complex< double > kphase, const std::vector< std::complex< double > > &dmk_row, std::complex< double > *dmr_mat)
template<>
void xyz_to_updown< double > (const std::complex< double > spin_block[4], const int icol, const int spin_stride[4], double *dmr_mat)
template<>
void xyz_to_updown< std::complex< double > > (const std::complex< double > spin_block[4], const int icol, const int spin_stride[4], std::complex< double > *dmr_mat)
template void build_kphase< std::complex< double >, double > (hamilt::AtomPair< double > &, const std::vector< ModuleBase::Vector3< double > > &, const int, const std::map< ModuleBase::Vector3< int >, std::complex< double > > &, std::vector< std::vector< std::complex< double > > > &, std::vector< double * > &)
template void transpose_dmk_block< std::complex< double > > (const std::complex< double > *, const int, const DmrBlock &, std::complex< double > *)
template void add_dmr_real< std::complex< double >, double > (const DensityMatrix< std::complex< double >, double > &, const DmrBlock &, const int, const std::vector< std::vector< std::complex< double > > > &, const int, const int, std::vector< double * > &)
template void add_dmr_soc< std::complex< double >, double > (const DensityMatrix< std::complex< double >, double > &, const DmrBlock &, const int, const std::vector< std::vector< std::complex< double > > > &, const int, const int, const int, std::vector< double * > &)
template void accumulate_dmr< std::complex< double >, double, double > (const DensityMatrix< std::complex< double >, double > &, std::vector< hamilt::HContainer< double > * > &, const std::map< ModuleBase::Vector3< int >, std::complex< double > > &, const int, const char *)
void edm_tddft (const Parallel_Blkcyclic &layout, const ModuleBase::MatrixBlock< std::complex< double > > &h_mat, const ModuleBase::MatrixBlock< std::complex< double > > &s_mat, std::complex< double > *dmk, ModuleBase::ComplexMatrix &edmk)
template<typename Device>
void edm_tddft_lapack (const Parallel_Blkcyclic &layout, const ModuleBase::MatrixBlock< std::complex< double > > &h_mat, const ModuleBase::MatrixBlock< std::complex< double > > &s_mat, std::complex< double > *dmk, ModuleBase::ComplexMatrix &edmk)
template void edm_tddft_lapack< base_device::DEVICE_CPU > (const Parallel_Blkcyclic &layout, const ModuleBase::MatrixBlock< std::complex< double > > &h_mat, const ModuleBase::MatrixBlock< std::complex< double > > &s_mat, std::complex< double > *dmk, ModuleBase::ComplexMatrix &edmk)

Function Documentation

◆ accumulate_dmr()

template<typename TK, typename TR_in, typename TR_out>
void module_dm::accumulate_dmr ( const DensityMatrix< TK, TR_in > & dm,
std::vector< hamilt::HContainer< TR_out > * > & dmR_out,
const std::map< ModuleBase::Vector3< int >, std::complex< double > > & phase_hybrid,
const int ik_in,
const char * func_name )
extern

shared inner loop of cal_dmr / cal_dmr_td: for each spin channel, zero the DMR HContainer and accumulate kphase * DMK into DMR blocks. Pass an empty phase_hybrid map for the non-TD (cal_dmr) case.

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

◆ accumulate_dmr< std::complex< double >, double, double >()

template void module_dm::accumulate_dmr< std::complex< double >, double, double > ( const DensityMatrix< std::complex< double >, double > & ,
std::vector< hamilt::HContainer< double > * > & ,
const std::map< ModuleBase::Vector3< int >, std::complex< double > > & ,
const int ,
const char *  )
Here is the call graph for this function:

◆ add_dmr_real()

template<typename TK, typename TR>
void module_dm::add_dmr_real ( const DensityMatrix< TK, TR > & dm,
const DmrBlock & block,
const int ik_begin,
const std::vector< std::vector< TK > > & kphase_vec,
const int ld_hk,
const int ik_in,
std::vector< TR * > & dmr_mats )
extern

nspin=1/2: accumulate Re(kphase * DMK) into DMR blocks

Formula: DMR_ij(R) += Re[ e^{ik·R} * DMK_ij(k) ] If ik_in >= 0, only that k-point contributes; if ik_in < 0, sum over all k-points.

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

◆ add_dmr_real< std::complex< double >, double >()

template void module_dm::add_dmr_real< std::complex< double >, double > ( const DensityMatrix< std::complex< double >, double > & ,
const DmrBlock & ,
const int ,
const std::vector< std::vector< std::complex< double > > > & ,
const int ,
const int ,
std::vector< double * > &  )
Here is the call graph for this function:

◆ add_dmr_soc()

template<typename TK, typename TR>
void module_dm::add_dmr_soc ( const DensityMatrix< TK, TR > & dm,
const DmrBlock & block,
const int ik_begin,
const std::vector< std::vector< TK > > & kphase_vec,
const int ld_hk,
const int ik_in,
const int col_stride,
std::vector< TR * > & dmr_mats )
extern

nspin==4 (SOC): accumulate k-phase * DMK into a per-R complex buffer, then transform 2x2 spin blocks from (upup, updown, downup, downdown) to (rho_0, rho_x, rho_y, rho_z) via xyz_to_updown.

Formula: S_ij(R) = sum_k e^{ik·R} * DMK_ij(k) rho_0 = rho_upup + rho_downdown rho_x = rho_updown + rho_downup rho_y = Im(rho_updown) - Im(rho_downup) (sign for conjugated stored DM) rho_z = rho_upup - rho_downdown Each orbital corresponds to a 2x2 spin block, so rows/cols step by 2. If ik_in >= 0, only that k-point contributes; if ik_in < 0, sum over all k-points.

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

◆ add_dmr_soc< std::complex< double >, double >()

template void module_dm::add_dmr_soc< std::complex< double >, double > ( const DensityMatrix< std::complex< double >, double > & ,
const DmrBlock & ,
const int ,
const std::vector< std::vector< std::complex< double > > > & ,
const int ,
const int ,
const int ,
std::vector< double * > &  )
Here is the call graph for this function:

◆ build_kphase()

template<typename TK, typename TR>
void module_dm::build_kphase ( hamilt::AtomPair< TR > & atom_pair,
const std::vector< ModuleBase::Vector3< double > > & kvec_d,
const int nk,
const std::map< ModuleBase::Vector3< int >, std::complex< double > > & phase_hybrid,
std::vector< std::vector< TK > > & kphase_vec,
std::vector< TR * > & dmr_mats )
extern

precompute k-phase factors e^{ikR} and collect DMR block pointers for one atom pair

Parameters
atom_pairthe atom pair whose R-vectors and matrices are used
kvec_ddirect coordinates of k-points
nknumber of k-points
phase_hybridadditional hybrid-gauge phase per R (empty map = no extra phase)
kphase_vecoutput: kphase_vec[ik][iR]
dmr_matsoutput: dmr_mats[iR] points to the DMR block for R-vector iR
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_kphase< std::complex< double >, double >()

template void module_dm::build_kphase< std::complex< double >, double > ( hamilt::AtomPair< double > & ,
const std::vector< ModuleBase::Vector3< double > > & ,
const int ,
const std::map< ModuleBase::Vector3< int >, std::complex< double > > & ,
std::vector< std::vector< std::complex< double > > > & ,
std::vector< double * > &  )
Here is the call graph for this function:

◆ cal_dmr()

template<typename TK, typename TR_in, typename TR_out>
void module_dm::cal_dmr ( const DensityMatrix< TK, TR_in > & dm,
std::vector< hamilt::HContainer< TR_out > * > & dmR_out,
const int ik_in )
extern
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_dmr_full()

template<typename TK, typename TR_in, typename TR_out>
void module_dm::cal_dmr_full ( const DensityMatrix< TK, TR_in > & dm,
hamilt::HContainer< TR_out > * dmR_out,
const int ik_in )
extern
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_dmr_td()

template<typename TK, typename TR_in, typename TR_out>
void module_dm::cal_dmr_td ( DensityMatrix< TK, TR_in > & dm,
std::vector< hamilt::HContainer< TR_out > * > & dmR_out,
const std::map< ModuleBase::Vector3< int >, std::complex< double > > & phase_hybrid,
const ModuleBase::Vector3< double > At,
const int ik_in )
extern
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_from_psi() [1/4]

void module_dm::dm_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const psi::Psi< double > & wfc,
DensityMatrix< double, double > & DM )

Calculate the k-point density matrix from wavefunctions for the Gamma-only case.

For every k-point block of the wavefunction this computes dmk(iw1, iw2) = sum_ib wg(ik, ib) * wfc(ib, iw1) * wfc(ib, iw2), i.e. the wavefunction weights are real so no conjugation is needed.

Parameters
ParaV2D block-cyclic distribution descriptor of the orbitals
wgband weights, wg(ik, ib_global) for the global band index
wfcwavefunction coefficients, shape (nk, nbands_local, nbasis_local)
DMoutput density matrix, one block per k-point
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_from_psi() [2/4]

template<typename TR>
void module_dm::dm_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const psi::Psi< std::complex< double > > & wfc,
DensityMatrix< std::complex< double >, TR > & DM )

Calculate the k-point density matrix from wavefunctions for the multi-k case.

For every k-point block of the wavefunction this computes dmk(iw1, iw2) = sum_ib wg(ik, ib) * conj(wfc(ib, iw1)) * wfc(ib, iw2). The conjugation is applied to the FIRST basis index ("conj-first" storage): the stored block is the transpose of the physical one-body density matrix P = C diag(wg) C^H. cal_dmr(), SOC magnetization and Mulliken analysis all rely on this convention, see dm_tools.cpp and unittests/test_soc_magnetization_roundtrip.cpp.

Template Parameters
TRreal type of the real-space density matrix of DM
Parameters
ParaV2D block-cyclic distribution descriptor of the orbitals
wgband weights, wg(ik, ib_global) for the global band index
wfcwavefunction coefficients, shape (nk, nbands_local, nbasis_local)
DMoutput density matrix, one block per k-point
Here is the call graph for this function:

◆ dm_from_psi() [3/4]

template void module_dm::dm_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const psi::Psi< std::complex< double > > & wfc,
module_dm::DensityMatrix< std::complex< double >, double > & DM )

◆ dm_from_psi() [4/4]

template void module_dm::dm_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const psi::Psi< std::complex< double > > & wfc,
module_dm::DensityMatrix< std::complex< double >, std::complex< double > > & DM )

◆ dmk_from_psi() [1/2]

void module_dm::dmk_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const int ik,
const psi::Psi< double > & wfc,
double * dmk_out )

Calculate one k-point block of the density matrix (Gamma-only case).

Single-k-point worker behind dm_from_psi(); exposed for callers that own the output storage themselves. The conjugation/weighting contract is the same as dm_from_psi(), the caller only provides the output slot.

Parameters
ParaV2D block-cyclic distribution descriptor of the orbitals
wgband weights, wg(ik, ib_global) for the global band index
ikk-point index of the block to calculate
wfcwavefunction coefficients
dmk_outoutput block, distributed according to ParaV->desc (serial builds: a dense nbasis_local x nbasis_local column-major matrix)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dmk_from_psi() [2/2]

void module_dm::dmk_from_psi ( const Parallel_Orbitals * ParaV,
const ModuleBase::matrix & wg,
const int ik,
const psi::Psi< std::complex< double > > & wfc,
std::complex< double > * dmk_out )

Calculate one k-point block of the density matrix (multi-k case).

Single-k-point worker behind dm_from_psi(), using the conj-first convention dmk(iw1, iw2) = sum_ib wg(ik, ib) * conj(wfc(ib, iw1)) * wfc(ib, iw2).

Parameters
ParaV2D block-cyclic distribution descriptor of the orbitals
wgband weights, wg(ik, ib_global) for the global band index
ikk-point index of the block to calculate
wfcwavefunction coefficients
dmk_outoutput block, distributed according to ParaV->desc (serial builds: a dense nbasis_local x nbasis_local column-major matrix)
Here is the call graph for this function:

◆ edm_tddft()

void module_dm::edm_tddft ( const Parallel_Blkcyclic & layout,
const ModuleBase::MatrixBlock< std::complex< double > > & h_mat,
const ModuleBase::MatrixBlock< std::complex< double > > & s_mat,
std::complex< double > * dmk,
ModuleBase::ComplexMatrix & edmk )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ edm_tddft_lapack()

template<typename Device>
void module_dm::edm_tddft_lapack ( const Parallel_Blkcyclic & layout,
const ModuleBase::MatrixBlock< std::complex< double > > & h_mat,
const ModuleBase::MatrixBlock< std::complex< double > > & s_mat,
std::complex< double > * dmk,
ModuleBase::ComplexMatrix & edmk )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ edm_tddft_lapack< base_device::DEVICE_CPU >()

template void module_dm::edm_tddft_lapack< base_device::DEVICE_CPU > ( const Parallel_Blkcyclic & layout,
const ModuleBase::MatrixBlock< std::complex< double > > & h_mat,
const ModuleBase::MatrixBlock< std::complex< double > > & s_mat,
std::complex< double > * dmk,
ModuleBase::ComplexMatrix & edmk )

◆ exp_mul_dmk()

template<typename TR>
void module_dm::exp_mul_dmk ( const std::complex< double > kphase,
const std::vector< std::complex< double > > & dmk_row,
TR * dmr_mat )
extern
Here is the caller graph for this function:

◆ exp_mul_dmk< double >()

template<>
void module_dm::exp_mul_dmk< double > ( const std::complex< double > kphase,
const std::vector< std::complex< double > > & dmk_row,
double * dmr_mat )

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

template<>
void module_dm::exp_mul_dmk< std::complex< double > > ( const std::complex< double > kphase,
const std::vector< std::complex< double > > & dmk_row,
std::complex< double > * dmr_mat )
Here is the call graph for this function:

◆ get_dmr_block()

DmrBlock module_dm::get_dmr_block ( const Parallel_Orbitals * pv,
const int iat1,
const int iat2 )

extract the block geometry for atom pair (iat1, iat2) from the parallel orbitals layout

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

◆ init_dm()

template<typename TK>
void module_dm::init_dm ( UnitCell & ucell,
elecstate::ElecState * pelec,
module_dm::Setup_DM< TK > & dmat,
psi::Psi< TK > * psi,
Charge & chr,
const Parallel_Orbitals & pv,
const int iter,
const int exx_two_level_step,
const Init_DM_Config & cfg )

update the potentials by using new electron charge density

compute the correction energy for metals

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

◆ transpose_dmk_block()

template<typename TK>
void module_dm::transpose_dmk_block ( const TK * dmk_col_major,
const int ld_hk,
const DmrBlock & block,
TK * dmk_row )
extern

transpose a col-major DMK sub-block into row-major order

Here is the caller graph for this function:

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

template void module_dm::transpose_dmk_block< std::complex< double > > ( const std::complex< double > * ,
const int ,
const DmrBlock & ,
std::complex< double > *  )
Here is the call graph for this function:

◆ xyz_to_updown()

template<typename TR>
void module_dm::xyz_to_updown ( const std::complex< double > spin_block[4],
const int icol,
const int spin_stride[4],
TR * dmr_mat )
extern
Here is the caller graph for this function:

◆ xyz_to_updown< double >()

template<>
void module_dm::xyz_to_updown< double > ( const std::complex< double > spin_block[4],
const int icol,
const int spin_stride[4],
double * dmr_mat )
Here is the caller graph for this function:

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

template<>
void module_dm::xyz_to_updown< std::complex< double > > ( const std::complex< double > spin_block[4],
const int icol,
const int spin_stride[4],
std::complex< double > * dmr_mat )
Here is the call graph for this function: