|
ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
#include <deltaspin_state.h>
Public Member Functions | |
| void | set_atomCounts (const std::map< int, int > &atomCounts_in) |
| set element index to atom index map | |
| const std::map< int, int > & | get_atomCounts () const |
| get element index to atom index map | |
| void | set_orbitalCounts (const std::map< int, int > &orbitalCounts_in) |
| set element index to orbital index map | |
| const std::map< int, int > & | get_orbitalCounts () const |
| get element index to orbital index map | |
| void | set_lnchiCounts (const std::map< int, std::map< int, int > > &lnchiCounts_in) |
| set lnchiCounts | |
| const std::map< int, std::map< int, int > > & | get_lnchiCounts () const |
| get lnchiCounts | |
| void | set_sc_lambda () |
| set sc_lambda from ScData (parsed from STRU file) | |
| void | set_sc_lambda (const ModuleBase::Vector3< double > *lambda_in, int nat_in) |
| set sc_lambda from variable | |
| void | set_target_mag () |
| set target_mag from ScData (parsed from STRU file) | |
| void | set_target_mag (const ModuleBase::Vector3< double > *target_mag_in, int nat_in) |
| set target_mag from variable | |
| void | set_target_mag (const std::vector< ModuleBase::Vector3< double > > &target_mag_in) |
| set target magnetic moment | |
| void | set_constrain () |
| set constrain from ScData | |
| void | set_constrain (const ModuleBase::Vector3< int > *constrain_in, int nat_in) |
| set constrain from variable | |
| const std::vector< ModuleBase::Vector3< double > > & | get_sc_lambda () const |
| get sc_lambda | |
| std::vector< ModuleBase::Vector3< double > > & | get_lambda () |
| get mutable sc_lambda | |
| const std::vector< ModuleBase::Vector3< double > > & | get_target_mag () const |
| get target_mag | |
| const std::vector< ModuleBase::Vector3< int > > & | get_constrain () const |
| get constrain | |
| int | get_nat () const |
| get nat | |
| int | get_ntype () const |
| get ntype | |
| void | check_atomCounts () const |
| check atomCounts | |
| int | get_iat (int itype, int atom_index) const |
| get iat | |
| void | set_nspin (int nspin) |
| set nspin | |
| int | get_nspin () const |
| get nspin | |
| void | set_npol (int npol) |
| set npol | |
| int | get_npol () const |
| get npol | |
| void | zero_Mi () |
| zero atomic magnetic moment | |
| double | get_decay_grad (int itype) const |
| get decay_grad (root process only: reads ScDecayGrad from json) | |
| void | set_decay_grad () |
| set decay_grad (zero-initialize per element type) | |
| const std::vector< double > & | get_decay_grad () const |
| get decay_grad | |
| void | set_decay_grad (const double *decay_grad_in, int ntype_in) |
| set decay_grad from variable | |
| void | set_sc_drop_thr (double sc_drop_thr_in) |
| set decay grad switch | |
| void | set_input_parameters (double sc_thr_in, int nsc_in, int nsc_min_in, double alpha_trial_in, double sccut_in, double sc_drop_thr_in) |
| set input parameters | |
| double | get_sc_thr () const |
| get sc_thr | |
| double | get_current_sc_thr () const |
| get current adaptive sc threshold (max(initial_rms * sc_drop_thr_, sc_thr_)) | |
| int | get_nsc () const |
| get nsc | |
| int | get_nsc_min () const |
| get nsc_min | |
| double | get_alpha_trial () const |
| get alpha_trial | |
| double | get_sccut () const |
| get sccut | |
| double | get_sc_drop_thr () const |
| get sc_drop_thr | |
| const std::vector< ModuleBase::Vector3< double > > & | get_mi () const |
| get computed magnetic moments Mi per atom | |
| std::vector< ModuleBase::Vector3< double > > & | get_mi () |
| get mutable computed magnetic moments Mi per atom | |
| const std::vector< std::string > & | get_atomLabels () const |
| get human-readable atom labels ("Fe_0", "Fe_1", ...) for table printing | |
| int | get_nw () const |
| Total number of orbitals across all constrained atoms. | |
| int | get_iwt (int itype, int iat, int orbital_index) const |
| Convert (itype, iat, iw) to global orbital index. | |
| void | set_mag_converged (bool is_Mi_converged_in) |
| Set magnetic moment convergence flag. | |
| bool | mag_converged () const |
| Get magnetic moment convergence flag. | |
| double | cal_escon () |
| Calculate the spin constraint energy contribution: E_scon = -sum(lambda_i . Mi_i). | |
| double | get_escon () const |
| Get the cached constraint energy from the last cal_escon() call (Ry). | |
Public Attributes | |
| std::vector< ModuleBase::Vector3< double > > | target_mag_ |
| Target magnetic moments (uB) per atom. | |
| std::vector< ModuleBase::Vector3< int > > | constrain_ |
| Per-atom/component constraint flags: 0=free, 1=constrained. | |
| std::vector< std::string > | atomLabels_ |
| Human-readable labels: "Fe_0", "Fe_1", etc. | |
| int | nspin_ = 0 |
| Spin type: 2=collinear, 4=non-collinear. | |
| int | npol_ = 1 |
| Number of spinor components: 1 for nspin=2, 2 for nspin=4. | |
| double | sc_thr_ = 0.0 |
| Convergence threshold for RMS(Mi - M_target) in uB. | |
| double | sc_drop_thr_ = 1e-3 |
| Fraction of initial RMS for adaptive threshold. | |
| double | current_sc_thr_ = 0.0 |
| Adaptive threshold: max(initial_rms * sc_drop_thr_, sc_thr_). | |
| double | alpha_trial_ = 0.0 |
| Initial trial step size (Ry/uB^2), adaptively adjusted during loop. | |
| double | restrict_current_ = 0.0 |
| Maximum allowed lambda change per step (Ry/uB). | |
| int | nsc_ = 0 |
| Maximum number of inner lambda optimization steps. | |
| int | nsc_min_ = 0 |
| Minimum steps before early exit checks (gradient decay). | |
| double | escon_ = 0.0 |
| Cached constraint energy from last cal_escon() call (Ry). | |
| bool | is_Mi_converged = false |
| Has the magnetic moment converged in the current SCF iteration? | |
| bool | direction_only_ = false |
| If true, only optimize spin direction. | |
| double | tpiba = 0.0 |
| 2*pi/a lattice constant scaling factor, saved from UnitCell | |
Private Attributes | |
| std::vector< ModuleBase::Vector3< double > > | lambda_ |
| Lagrange multipliers (Ry/uB) per atom, 3 components. | |
| std::vector< ModuleBase::Vector3< double > > | Mi_ |
| Current computed magnetic moments (uB) per atom. | |
| std::map< int, std::vector< ScAtomData > > | ScData |
| Raw constraint data indexed by element type (itype). | |
| std::map< int, double > | ScDecayGrad |
| Gradient decay thresholds (uB^2/eV) per element type. | |
| std::vector< double > | decay_grad_ |
| Gradient decay thresholds converted to uB^2/Ry, per element type. | |
| std::map< int, int > | atomCounts |
| Number of atoms per element type: {itype -> nat_itype}. | |
| std::map< int, int > | orbitalCounts |
| Number of orbitals per element type: {itype -> nw_itype}. | |
| std::map< int, std::map< int, int > > | lnchiCounts |
| {itype -> {L -> nchi}}: angular momentum channels | |
| double spinconstrain::ScState::cal_escon | ( | ) |
Calculate the spin constraint energy contribution: E_scon = -sum(lambda_i . Mi_i).
Calculate the spin constraint energy: E_scon = -sum_i (lambda_i . Mi_i).
The constraint energy is the Lagrange multiplier term in the constrained DFT functional: E'[rho] = E_DFT[rho] - sum_i lambda_i . (Mi_i - M_target_i)
| void spinconstrain::ScState::check_atomCounts | ( | ) | const |
check atomCounts
Validate atom count data integrity.
Checks that atomCounts has been properly initialized and contains valid data. Called before any operation that depends on atom indexing.
| double spinconstrain::ScState::get_alpha_trial | ( | ) | const |
get alpha_trial
| const std::map< int, int > & spinconstrain::ScState::get_atomCounts | ( | ) | const |
get element index to atom index map
| const std::vector< std::string > & spinconstrain::ScState::get_atomLabels | ( | ) | const |
get human-readable atom labels ("Fe_0", "Fe_1", ...) for table printing
get human-readable atom labels for table printing
| const std::vector< ModuleBase::Vector3< int > > & spinconstrain::ScState::get_constrain | ( | ) | const |
get constrain
get_constrain
| double spinconstrain::ScState::get_current_sc_thr | ( | ) | const |
get current adaptive sc threshold (max(initial_rms * sc_drop_thr_, sc_thr_))
get current adaptive sc threshold
| const std::vector< double > & spinconstrain::ScState::get_decay_grad | ( | ) | const |
get decay_grad
| double spinconstrain::ScState::get_decay_grad | ( | int | itype | ) | const |
get decay_grad (root process only: reads ScDecayGrad from json)
get grad_decay this function can only be called by the root process because only root process reads the ScDecayGrad from json file
| double spinconstrain::ScState::get_escon | ( | ) | const |
Get the cached constraint energy from the last cal_escon() call (Ry).
| int spinconstrain::ScState::get_iat | ( | int | itype, |
| int | atom_index ) const |
get iat
Convert (element_type, local_atom_index) to global atom index.
Atoms in ABACUS are organized by element type. Within each type, atoms are indexed locally (0, 1, ..., nat_itype-1). This function maps to the global index that runs across all atoms (0, 1, ..., nat-1).
Example: If type 0 has 2 Fe atoms and type 1 has 3 O atoms: get_iat(0, 0) -> 0 (Fe_0) get_iat(0, 1) -> 1 (Fe_1) get_iat(1, 0) -> 2 (O_0) get_iat(1, 1) -> 3 (O_1) get_iat(1, 2) -> 4 (O_2)
| itype | Element type index (0 to ntype-1) |
| atom_index | Local index within the element type |
| int spinconstrain::ScState::get_iwt | ( | int | itype, |
| int | iat, | ||
| int | orbital_index ) const |
Convert (itype, iat, iw) to global orbital index.
Convert (itype, local_atom_index, orbital_index) to global orbital index.
The global orbital index is used to access elements in distributed matrices (ScaLAPACK format). The mapping is: iwt = sum_{t < itype} orbitalCounts[t] + iat * orbitalCounts[itype] + orbital_index where iat = get_iat(itype, local_atom_index).
|
inline |
get mutable sc_lambda
| const std::map< int, std::map< int, int > > & spinconstrain::ScState::get_lnchiCounts | ( | ) | const |
get lnchiCounts
|
inline |
get mutable computed magnetic moments Mi per atom
| const std::vector< ModuleBase::Vector3< double > > & spinconstrain::ScState::get_mi | ( | ) | const |
get computed magnetic moments Mi per atom
| int spinconstrain::ScState::get_nat | ( | ) | const |
get nat
Get total number of atoms across all element types.
| int spinconstrain::ScState::get_npol | ( | ) | const |
get npol
| int spinconstrain::ScState::get_nsc | ( | ) | const |
get nsc
| int spinconstrain::ScState::get_nsc_min | ( | ) | const |
get nsc_min
| int spinconstrain::ScState::get_nspin | ( | ) | const |
get nspin
| int spinconstrain::ScState::get_ntype | ( | ) | const |
get ntype
Get number of element types.
| int spinconstrain::ScState::get_nw | ( | ) | const |
Total number of orbitals across all constrained atoms.
| const std::map< int, int > & spinconstrain::ScState::get_orbitalCounts | ( | ) | const |
get element index to orbital index map
| double spinconstrain::ScState::get_sc_drop_thr | ( | ) | const |
get sc_drop_thr
| const std::vector< ModuleBase::Vector3< double > > & spinconstrain::ScState::get_sc_lambda | ( | ) | const |
get sc_lambda
| double spinconstrain::ScState::get_sc_thr | ( | ) | const |
get sc_thr
| double spinconstrain::ScState::get_sccut | ( | ) | const |
get sccut
| const std::vector< ModuleBase::Vector3< double > > & spinconstrain::ScState::get_target_mag | ( | ) | const |
get target_mag
|
inline |
Get magnetic moment convergence flag.
| void spinconstrain::ScState::set_atomCounts | ( | const std::map< int, int > & | atomCounts_in | ) |
set element index to atom index map
| void spinconstrain::ScState::set_constrain | ( | ) |
set constrain from ScData
Set constraint flags from ScData.
The constrain array determines which components of each atom's magnetic moment are actively constrained:
Default is all zeros (no constraints). Components with constrain=0 are excluded from the lambda optimization and RMS error calculation.
| void spinconstrain::ScState::set_constrain | ( | const ModuleBase::Vector3< int > * | constrain_in, |
| int | nat_in ) |
set constrain from variable
| void spinconstrain::ScState::set_decay_grad | ( | ) |
set decay_grad (zero-initialize per element type)
set grad_decy
| void spinconstrain::ScState::set_decay_grad | ( | const double * | decay_grad_in, |
| int | ntype_in ) |
set decay_grad from variable
set grad_decy from variable
| void spinconstrain::ScState::set_input_parameters | ( | double | sc_thr_in, |
| int | nsc_in, | ||
| int | nsc_min_in, | ||
| double | alpha_trial_in, | ||
| double | sccut_in, | ||
| double | sc_drop_thr_in ) |
set input parameters
| void spinconstrain::ScState::set_lnchiCounts | ( | const std::map< int, std::map< int, int > > & | lnchiCounts_in | ) |
set lnchiCounts
|
inline |
Set magnetic moment convergence flag.
| void spinconstrain::ScState::set_npol | ( | int | npol | ) |
set npol
| void spinconstrain::ScState::set_nspin | ( | int | nspin | ) |
set nspin
| void spinconstrain::ScState::set_orbitalCounts | ( | const std::map< int, int > & | orbitalCounts_in | ) |
set element index to orbital index map
| void spinconstrain::ScState::set_sc_drop_thr | ( | double | sc_drop_thr_in | ) |
set decay grad switch
set sc_drop_thr
| void spinconstrain::ScState::set_sc_lambda | ( | ) |
set sc_lambda from ScData (parsed from STRU file)
| void spinconstrain::ScState::set_sc_lambda | ( | const ModuleBase::Vector3< double > * | lambda_in, |
| int | nat_in ) |
set sc_lambda from variable
| void spinconstrain::ScState::set_target_mag | ( | ) |
set target_mag from ScData (parsed from STRU file)
Set target magnetic moments from ScData (parsed from STRU file).
Supports two specification modes:
Near-zero components (< 1e-14) are explicitly set to 0.0 to avoid floating-point noise in constraint checks.
| void spinconstrain::ScState::set_target_mag | ( | const ModuleBase::Vector3< double > * | target_mag_in, |
| int | nat_in ) |
set target_mag from variable
| void spinconstrain::ScState::set_target_mag | ( | const std::vector< ModuleBase::Vector3< double > > & | target_mag_in | ) |
set target magnetic moment
| void spinconstrain::ScState::zero_Mi | ( | ) |
zero atomic magnetic moment
Reset all atomic magnetic moments to zero. Called before each Mi calculation.
| double spinconstrain::ScState::alpha_trial_ = 0.0 |
Initial trial step size (Ry/uB^2), adaptively adjusted during loop.
|
private |
Number of atoms per element type: {itype -> nat_itype}.
| std::vector<std::string> spinconstrain::ScState::atomLabels_ |
Human-readable labels: "Fe_0", "Fe_1", etc.
| std::vector<ModuleBase::Vector3<int> > spinconstrain::ScState::constrain_ |
Per-atom/component constraint flags: 0=free, 1=constrained.
| double spinconstrain::ScState::current_sc_thr_ = 0.0 |
Adaptive threshold: max(initial_rms * sc_drop_thr_, sc_thr_).
|
private |
Gradient decay thresholds converted to uB^2/Ry, per element type.
| bool spinconstrain::ScState::direction_only_ = false |
If true, only optimize spin direction.
| double spinconstrain::ScState::escon_ = 0.0 |
Cached constraint energy from last cal_escon() call (Ry).
| bool spinconstrain::ScState::is_Mi_converged = false |
Has the magnetic moment converged in the current SCF iteration?
|
private |
Lagrange multipliers (Ry/uB) per atom, 3 components.
|
private |
{itype -> {L -> nchi}}: angular momentum channels
|
private |
Current computed magnetic moments (uB) per atom.
| int spinconstrain::ScState::npol_ = 1 |
Number of spinor components: 1 for nspin=2, 2 for nspin=4.
| int spinconstrain::ScState::nsc_ = 0 |
Maximum number of inner lambda optimization steps.
| int spinconstrain::ScState::nsc_min_ = 0 |
Minimum steps before early exit checks (gradient decay).
| int spinconstrain::ScState::nspin_ = 0 |
Spin type: 2=collinear, 4=non-collinear.
|
private |
Number of orbitals per element type: {itype -> nw_itype}.
| double spinconstrain::ScState::restrict_current_ = 0.0 |
Maximum allowed lambda change per step (Ry/uB).
| double spinconstrain::ScState::sc_drop_thr_ = 1e-3 |
Fraction of initial RMS for adaptive threshold.
| double spinconstrain::ScState::sc_thr_ = 0.0 |
Convergence threshold for RMS(Mi - M_target) in uB.
|
private |
Raw constraint data indexed by element type (itype).
|
private |
Gradient decay thresholds (uB^2/eV) per element type.
| std::vector<ModuleBase::Vector3<double> > spinconstrain::ScState::target_mag_ |
| double spinconstrain::ScState::tpiba = 0.0 |
2*pi/a lattice constant scaling factor, saved from UnitCell