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

Mixing of the DFT+U on-site occupation matrix. More...

#include <occ_mixer.h>

Collaboration diagram for OccMatMixer:

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ OccMatMixer()

OccMatMixer::OccMatMixer ( )
default

◆ ~OccMatMixer()

OccMatMixer::~OccMatMixer ( )
default

Member Function Documentation

◆ begin_iter()

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.

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

◆ collect()

void OccMatMixer::collect ( const OccupationMatrix & occmat)

Flatten the freshly-computed occupation matrix into uom_.

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

◆ flat_size()

int OccMatMixer::flat_size ( ) const
inline

Total flat-buffer size (== Charge_Mixing::allocate_mixing_uom argument).

Here is the caller graph for this function:

◆ init()

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.

Parameters
cellunit cell (borrowed, must outlive this object)
l_channelper-type correlated-l table (borrowed)
flat_indexper-atom offset table, i.e. uterm_mat_index (borrowed)
nspinspin channels (1, 2 or 4)
total_sizetotal flat-buffer size (== uterm_mat.size())
Here is the caller graph for this function:

◆ mix_plain()

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.

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

◆ seed_save()

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.

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

◆ uom()

std::vector< double > & OccMatMixer::uom ( )
inline

Mutable access to the new / mixed flat buffer (fed to mix_uom).

Here is the caller graph for this function:

◆ uom_save()

std::vector< double > & OccMatMixer::uom_save ( )
inline

Mutable access to the previous flat buffer (fed to mix_uom).

Here is the caller graph for this function:

◆ write_back()

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.

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

Member Data Documentation

◆ cell_

const UnitCell* OccMatMixer::cell_ = nullptr
private

borrowed unit cell

◆ index_

const std::vector<int>* OccMatMixer::index_ = nullptr
private

borrowed uterm_mat_index

◆ l_channel_

const std::vector<int>* OccMatMixer::l_channel_ = nullptr
private

borrowed l_channel table

◆ nspin_

int OccMatMixer::nspin_ = 0
private

◆ uom_

std::vector<double> OccMatMixer::uom_
private

new / mixed flat occupation matrix

◆ uom_save_

std::vector<double> OccMatMixer::uom_save_
private

previous flat occupation matrix


The documentation for this class was generated from the following files: