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

Classes

struct  OccMatReadState
struct  SocCompactBlocks
struct  OccmatOutputCfg
struct  OccmatStepInfo
 Electronic-step metadata recorded in an occupation-matrix snapshot. More...

Typedefs

using OccMatData = std::vector<std::vector<std::vector<ModuleBase::matrix>>>
 nested occupation-matrix type used by DFT+U: occ_mat[iat][l][spin](m0, m1)

Enumerations

enum  OccmatSocLayout { SOC_LAYOUT_PAULI , SOC_LAYOUT_SPIN_BASIS_REAL }
 Storage layout of the real (2l+1)*npol matrix when nspin == 4. More...

Functions

OccmatSocLayout lcao_soc_layout (const int dft_plus_u)
bool is_ion_step_output_step (const int istep, const OccmatOutputCfg &cfg)
bool is_elec_snapshot_trigger (const int iter, const bool conv_esolver, const OccmatOutputCfg &cfg)
std::string gen_ion_step_occ_mat_filename (const std::string &out_dir, const int istep)
std::string find_first_existing_file (const std::string &dir, const std::vector< std::string > &candidates)
void local_occup_bcast (const UnitCell &ucell, OccupationMatrix &occ, const std::vector< int > &l_channel)
void prepare_ion_step_output (const std::string &global_out_dir, const int istep, const int iter, const OccmatOutputCfg &cfg)
void append_ion_step_snapshot (const Plus_U_Base &dftu, const UnitCell &ucell, const std::string &global_out_dir, const OccmatStepInfo &step, const bool conv_esolver, const bool occmat_ready, const OccmatOutputCfg &cfg, const OccmatSocLayout &soc_layout)
void write_latest_occmat (const Plus_U_Base &dftu, const UnitCell &ucell, const std::string &global_out_dir, const OccmatStepInfo &step, const OccmatOutputCfg &cfg, const OccmatSocLayout &soc_layout)
void read_occup_m (const UnitCell &ucell, OccupationMatrix &occ, const std::vector< int > &l_channel, const std::string &fn, int nspin, int npol, const OccmatSocLayout &soc_layout)
void write_occup_m (const Plus_U_Base &dftu, const UnitCell &ucell, std::ostream &ofs, const OccmatSocLayout &soc_layout)
void write_occup_eigenvalues (const Plus_U_Base &dftu, const UnitCell &ucell, std::ostream &ofs, const OccmatSocLayout &soc_layout)
 Append sorted occupation eigenvalues as restart-safe comment lines.
template<typename Device>
void accumulate_occ_one_k (const void *psi_in, const ModuleBase::matrix &wg_in, const UnitCell &cell, const int *isk, const int nspin, const std::vector< int > &l_channel, OccupationMatrix &occmat)
void cal_occ_pw (const void *psi_in, const ModuleBase::matrix &wg_in, const UnitCell &cell, Charge_Mixing *p_chgmix, const int *isk, const int kpar, const int nspin, const std::string &device, const std::vector< int > &l_channel, const std::vector< double > &u_current, const std::vector< int > &uterm_mat_index, OccupationMatrix &occmat, OccMatMixer *occ_mixer, std::vector< std::complex< double > > &uterm_mat, double &energy_u)
void iter_init_dftu_pw (const int iter, const int istep, Plus_U_Base &dftu, const void *psi, const ModuleBase::matrix &wg, const UnitCell &ucell, Charge_Mixing *p_chgmix, const int dft_plus_u, const int *isk, const int nspin, const int kpar)

Variables

const char *const read_occup_context = "DFTU_BASE::read_occup_m"

Detailed Description

Orchestration functions for DFT+U PW basis calculations.

These functions manage state (psi, OnsiteProjector, Charge_Mixing, etc.) and call the pure functions in dftu_pw_tools.h. They cannot be unit-tested directly because they depend on runtime objects.

Typedef Documentation

◆ OccMatData

using DFTU_BASE::OccMatData = std::vector<std::vector<std::vector<ModuleBase::matrix>>>

nested occupation-matrix type used by DFT+U: occ_mat[iat][l][spin](m0, m1)

Enumeration Type Documentation

◆ OccmatSocLayout

Storage layout of the real (2l+1)*npol matrix when nspin == 4.

Enumerator
SOC_LAYOUT_PAULI 

4 contiguous Pauli-component blocks [charge, sigma_x, sigma_y, sigma_z], each (2l+1)x(2l+1); used by PW and LCAO dft_plus_u=1

SOC_LAYOUT_SPIN_BASIS_REAL 

real symmetric matrix in spin basis (m + spin-polarization index); imaginary parts are not stored; used by LCAO dft_plus_u=2

Function Documentation

◆ accumulate_occ_one_k()

template<typename Device>
void DFTU_BASE::accumulate_occ_one_k ( const void * psi_in,
const ModuleBase::matrix & wg_in,
const UnitCell & cell,
const int * isk,
const int nspin,
const std::vector< int > & l_channel,
OccupationMatrix & occmat )

accumulate occ_mat from psi for all k-points (per-device template).

Explicitly instantiated for DEVICE_CPU (and DEVICE_GPU when available) in dftu_pw.cpp.

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

◆ append_ion_step_snapshot()

void DFTU_BASE::append_ion_step_snapshot ( const Plus_U_Base & dftu,
const UnitCell & ucell,
const std::string & global_out_dir,
const OccmatStepInfo & step,
bool conv_esolver,
bool occmat_ready,
const OccmatOutputCfg & cfg,
const OccmatSocLayout & soc_layout )

Append one electronic-step section to the per-ionic-step file.

The section records the electronic-step index, the configured charge- density convergence threshold (scf_thr) and the actual residual (drho) of the current electronic step, followed by the occupation matrices and per-atom magnetism. When occmat_ready is false, an "N/A" placeholder is recorded instead of the matrix body (the PW path has no matrix at istep 0 / iter 1 unless it was loaded from file). The caller invokes this function only after drho of the current electronic step is computed.

Parameters
dftuDFT+U object holding the occupation matrices
ucellunit cell
global_out_diroutput directory (including the trailing separator)
stepelectronic-step metadata and convergence values
conv_esolverwhether the electronic SCF is converged at this step
occmat_readywhether the occupation matrix of this step exists; false records an "N/A" placeholder instead of the matrix body
cfgfrequency configuration
soc_layoutstorage layout of the nspin == 4 occupation matrix
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cal_occ_pw()

void DFTU_BASE::cal_occ_pw ( const void * psi_in,
const ModuleBase::matrix & wg_in,
const UnitCell & cell,
Charge_Mixing * p_chgmix,
const int * isk,
const int kpar,
const int nspin,
const std::string & device,
const std::vector< int > & l_channel,
const std::vector< double > & u_current,
const std::vector< int > & uterm_mat_index,
OccupationMatrix & occmat,
OccMatMixer * occ_mixer,
std::vector< std::complex< double > > & uterm_mat,
double & energy_u )

calculate the local occupation number matrix for PW based wave functions.

This is the PW-basis entry point that:

  1. saves and zeroes the occupation matrix
  2. accumulates it from psi via accumulate_occ_one_k
  3. reduces across k-pools via reduce_occ_mat
  4. applies occupation-matrix mixing when enabled
  5. computes the effective potential and DFT+U energy

All state is passed explicitly so this function can be unit-tested without constructing a Plus_U_Base object.

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

◆ find_first_existing_file()

std::string DFTU_BASE::find_first_existing_file ( const std::string & dir,
const std::vector< std::string > & candidates )

Return the full path of the first candidate file that exists in dir. Returns an empty string if none of the candidates exist. Only the calling process probes the filesystem; callers must arrange MPI broadcast of the result if other ranks need it.

Here is the caller graph for this function:

◆ gen_ion_step_occ_mat_filename()

std::string DFTU_BASE::gen_ion_step_occ_mat_filename ( const std::string & out_dir,
int istep )

Build the name of the per-ionic-step occupation-matrix file.

Parameters
out_diroutput directory (including the trailing separator)
istepionic-step index, starting from 0
Returns
occ_matg{istep+1}.txt
Here is the caller graph for this function:

◆ is_elec_snapshot_trigger()

bool DFTU_BASE::is_elec_snapshot_trigger ( int iter,
bool conv_esolver,
const OccmatOutputCfg & cfg )

Tell whether the current electronic step is recorded inside the numbered file.

Parameters
iterelectronic-iteration index, starting from 1
conv_esolverwhether the electronic SCF is converged at this step
cfgfrequency configuration
Returns
true when iter % out_freq_elec == 0, iter == scf_nmax, or converged
Here is the caller graph for this function:

◆ is_ion_step_output_step()

bool DFTU_BASE::is_ion_step_output_step ( int istep,
const OccmatOutputCfg & cfg )

Tell whether the given ionic step produces a numbered file.

Parameters
istepionic-step index, starting from 0
cfgfrequency configuration
Returns
true when out_freq_ion > 0 and istep is an output ionic step
Here is the caller graph for this function:

◆ iter_init_dftu_pw()

void DFTU_BASE::iter_init_dftu_pw ( const int iter,
const int istep,
Plus_U_Base & dftu,
const void * psi,
const ModuleBase::matrix & wg,
const UnitCell & ucell,
Charge_Mixing * p_chgmix,
const int dft_plus_u,
const int * isk,
const int nspin,
const int kpar )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcao_soc_layout()

OccmatSocLayout DFTU_BASE::lcao_soc_layout ( const int dft_plus_u)
Here is the caller graph for this function:

◆ local_occup_bcast()

void DFTU_BASE::local_occup_bcast ( const UnitCell & ucell,
OccupationMatrix & occ,
const std::vector< int > & l_channel )

Broadcast the local occupation number matrices from rank 0 to all ranks.

Each occupation matrix is broadcast as one contiguous block (matrix::c stores nr * nc consecutive doubles) instead of element by element.

Broadcast the local occupation number matrices from rank 0 to all ranks.

Implemented in dftu_base_io.cpp (only available in MPI builds).

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

◆ prepare_ion_step_output()

void DFTU_BASE::prepare_ion_step_output ( const std::string & global_out_dir,
int istep,
int iter,
const OccmatOutputCfg & cfg )

Create (or truncate) the per-ionic-step file occ_matg{istep+1}.txt and write its header (rank 0 only).

At iter == 1 of an enabled output ionic step, truncates the file and writes its provenance header. Other calls are no-ops. Truncating here guarantees that a rerun can not append snapshots from a previous calculation.

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

◆ read_occup_m()

void DFTU_BASE::read_occup_m ( const UnitCell & ucell,
OccupationMatrix & occ,
const std::vector< int > & l_channel,
const std::string & fn,
int nspin,
int npol,
const OccmatSocLayout & soc_layout )

Read the local occupation number matrix from file (rank 0 only).

Only the current compact format written to occ_mat.txt is accepted. Legacy Atom=/L=/spin= layouts and malformed or incomplete matrices terminate the run with a diagnostic containing the filename and input line.

Parameters
soc_layoutstorage layout of the nspin == 4 occupation matrix; the PW path stores 4 contiguous Pauli blocks (b0, b1, b2, b3) and must reconstruct them from the (n_uu, Re(n_ud), Im(n_ud), n_dd) blocks written to the file; LCAO dft_plus_u=1 also uses Pauli blocks, while dft_plus_u=2 stores a real 2m x 2m spin-basis matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_latest_occmat()

void DFTU_BASE::write_latest_occmat ( const Plus_U_Base & dftu,
const UnitCell & ucell,
const std::string & global_out_dir,
const OccmatStepInfo & step,
const OccmatOutputCfg & cfg,
const OccmatSocLayout & soc_layout )

Overwrite occ_mat.txt with the occupation matrix of the current electronic step (rank 0 only).

occ_mat.txt is a single-section snapshot file: the same provenance header and compact layout as occ_matg{#}.txt, whose section header additionally carries the configured scf_thr and the actual drho of this step. Must be called at the iter_finish stage, after drho is computed; it is the entry file of init_chg=file and NSCF restarts. No-op when cfg.out_occ_mat is false.

Parameters
dftuDFT+U object holding the occupation matrices
ucellunit cell
global_out_diroutput directory (including the trailing separator)
stepelectronic-step metadata and convergence values
cfgoutput configuration; only cfg.out_occ_mat is consulted here
soc_layoutstorage layout of the nspin == 4 occupation matrix
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_occup_eigenvalues()

void DFTU_BASE::write_occup_eigenvalues ( const Plus_U_Base & dftu,
const UnitCell & ucell,
std::ostream & ofs,
const OccmatSocLayout & soc_layout )

Append sorted occupation eigenvalues as restart-safe comment lines.

Here is the caller graph for this function:

◆ write_occup_m()

void DFTU_BASE::write_occup_m ( const Plus_U_Base & dftu,
const UnitCell & ucell,
std::ostream & ofs,
const OccmatSocLayout & soc_layout )

Write local occupation matrices to the given stream.

Writes the compact snapshot layout accepted by read_occup_m(). The output includes per-atom magnetism, electron counts and the full matrix blocks. soc_layout tells how the nspin == 4 storage is arranged (PW and LCAO dft_plus_u=1 Pauli blocks, or LCAO dft_plus_u=2 real spin-basis matrix). Caller is responsible for opening/closing the stream.

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

Variable Documentation

◆ read_occup_context

const char* const DFTU_BASE::read_occup_context = "DFTU_BASE::read_occup_m"