|
ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
Mixing of the DFT+U on-site occupation matrix. More...
#include <occ_mixer.h>
Public Member Functions | |
| OccMatMixer ()=default | |
| ~OccMatMixer ()=default | |
| void | init (const UnitCell *cell, const std::vector< int > *l_channel, const std::vector< int > *flat_index, int nspin, int total_size) |
| Allocate the flat buffers and bind the layout table. | |
| void | seed_save (const OccupationMatrix &occmat) |
| Seed uom_save from an occupation matrix loaded from file. | |
| void | begin_iter (OccupationMatrix &occmat) |
| Begin an SCF iteration: flatten the saved occ into uom_save_. | |
| void | collect (const OccupationMatrix &occmat) |
| Flatten the freshly-computed occupation matrix into uom_. | |
| void | write_back (OccupationMatrix &occmat) |
| Write the (already mixed) uom_ buffer back into the occupation matrix. Called after the caller has run Charge_Mixing::mix_uom. | |
| void | mix_plain (OccupationMatrix &occmat, double beta) |
| Plain linear mixing for the nested-matrix (LCAO) path: occ = beta * occ + (1 - beta) * occ_save. | |
| int | flat_size () const |
| Total flat-buffer size (== Charge_Mixing::allocate_mixing_uom argument). | |
| std::vector< double > & | uom () |
| Mutable access to the new / mixed flat buffer (fed to mix_uom). | |
| std::vector< double > & | uom_save () |
| Mutable access to the previous flat buffer (fed to mix_uom). | |
Private Attributes | |
| std::vector< double > | uom_ |
| new / mixed flat occupation matrix | |
| std::vector< double > | uom_save_ |
| previous flat occupation matrix | |
| const std::vector< int > * | index_ = nullptr |
| borrowed uterm_mat_index | |
| const UnitCell * | cell_ = nullptr |
| borrowed unit cell | |
| const std::vector< int > * | l_channel_ = nullptr |
| borrowed l_channel table | |
| int | nspin_ = 0 |
Mixing of the DFT+U on-site occupation matrix.
Owns the flattened occupation-matrix buffers used by the charge-mixing machinery (PW path) and the plain linear mixing kernel (LCAO path).
The flat layout reuses the uterm_mat_index offset table: for nspin=2 the buffer is split into [all_up | all_dn] halves; for nspin=1/4 a single block per atom is used. Serialization to/from the nested OccupationMatrix is delegated to OccupationMatrix::{write_to_flat, read_from_flat, write_save_to_flat}.
An OccMatMixer instance exists only when mixing is enabled, so its presence doubles as the "mixing on" flag (no mutable workflow switch).
This class deliberately does NOT call Charge_Mixing itself; it only owns the flat buffers and exposes them via uom()/uom_save(). The caller (the PW driver, which already links charge_mixing) feeds these buffers to Charge_Mixing::mix_uom and then calls write_back(). Keeping Charge_Mixing out of this translation unit avoids dragging the planewave/xc dependency chain into lightweight unit tests.
|
default |
|
default |
| void OccMatMixer::begin_iter | ( | OccupationMatrix & | occmat | ) |
Begin an SCF iteration: flatten the saved occ into uom_save_.
The caller must already have snapshotted occ into occ_save via OccupationMatrix::copy_to_save; this only flattens that snapshot into uom_save_ for the mixing history.
| void OccMatMixer::collect | ( | const OccupationMatrix & | occmat | ) |
Flatten the freshly-computed occupation matrix into uom_.
|
inline |
Total flat-buffer size (== Charge_Mixing::allocate_mixing_uom argument).
| void OccMatMixer::init | ( | const UnitCell * | cell, |
| const std::vector< int > * | l_channel, | ||
| const std::vector< int > * | flat_index, | ||
| int | nspin, | ||
| int | total_size ) |
Allocate the flat buffers and bind the layout table.
| cell | unit cell (borrowed, must outlive this object) |
| l_channel | per-type correlated-l table (borrowed) |
| flat_index | per-atom offset table, i.e. uterm_mat_index (borrowed) |
| nspin | spin channels (1, 2 or 4) |
| total_size | total flat-buffer size (== uterm_mat.size()) |
| void OccMatMixer::mix_plain | ( | OccupationMatrix & | occmat, |
| double | beta ) |
Plain linear mixing for the nested-matrix (LCAO) path: occ = beta * occ + (1 - beta) * occ_save.
Operates directly on the nested OccupationMatrix blocks; the flat buffers are not used. Replaces the duplicated LCAO k/gamma call sites.
| void OccMatMixer::seed_save | ( | const OccupationMatrix & | occmat | ) |
Seed uom_save from an occupation matrix loaded from file.
Used when init_occ_mat != 0 (restart from dm_onsite_ini.txt) so that the first mixing step has a meaningful "previous" matrix.
|
inline |
Mutable access to the new / mixed flat buffer (fed to mix_uom).
|
inline |
Mutable access to the previous flat buffer (fed to mix_uom).
| void OccMatMixer::write_back | ( | OccupationMatrix & | occmat | ) |
Write the (already mixed) uom_ buffer back into the occupation matrix. Called after the caller has run Charge_Mixing::mix_uom.
|
private |
borrowed unit cell
|
private |
borrowed uterm_mat_index
|
private |
borrowed l_channel table
|
private |
|
private |
new / mixed flat occupation matrix
|
private |
previous flat occupation matrix