|
ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
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" |
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.
| 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)
Storage layout of the real (2l+1)*npol matrix when nspin == 4.
| 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.
| 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.
| dftu | DFT+U object holding the occupation matrices |
| ucell | unit cell |
| global_out_dir | output directory (including the trailing separator) |
| step | electronic-step metadata and convergence values |
| conv_esolver | whether the electronic SCF is converged at this step |
| occmat_ready | whether the occupation matrix of this step exists; false records an "N/A" placeholder instead of the matrix body |
| cfg | frequency configuration |
| soc_layout | storage layout of the nspin == 4 occupation matrix |
| 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:
All state is passed explicitly so this function can be unit-tested without constructing a Plus_U_Base object.
| 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.
| 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.
| out_dir | output directory (including the trailing separator) |
| istep | ionic-step index, starting from 0 |
| 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.
| iter | electronic-iteration index, starting from 1 |
| conv_esolver | whether the electronic SCF is converged at this step |
| cfg | frequency configuration |
| bool DFTU_BASE::is_ion_step_output_step | ( | int | istep, |
| const OccmatOutputCfg & | cfg ) |
Tell whether the given ionic step produces a numbered file.
| istep | ionic-step index, starting from 0 |
| cfg | frequency configuration |
| 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 ) |
| OccmatSocLayout DFTU_BASE::lcao_soc_layout | ( | const int | dft_plus_u | ) |
| 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).
| 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.
| 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.
| soc_layout | storage 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. |
| 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.
| dftu | DFT+U object holding the occupation matrices |
| ucell | unit cell |
| global_out_dir | output directory (including the trailing separator) |
| step | electronic-step metadata and convergence values |
| cfg | output configuration; only cfg.out_occ_mat is consulted here |
| soc_layout | storage layout of the nspin == 4 occupation matrix |
| 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.
| 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.
| const char* const DFTU_BASE::read_occup_context = "DFTU_BASE::read_occup_m" |