ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Classes | Functions
OperatorForceStress Namespace Reference

Classes

struct  OrbitalQuantumNumbers
 Structure to hold orbital quantum numbers. More...
 

Functions

void finalize_force_stress (bool cal_force, bool cal_stress, const UnitCell *ucell, const std::vector< double > &stress_tmp, ModuleBase::matrix &force, ModuleBase::matrix &stress, double force_factor=2.0, double stress_factor=2.0)
 Finalize force and stress calculations with MPI reduction and post-processing.
 
void setup_step_trace (int npol, int col_size, std::vector< int > &step_trace)
 Setup step_trace array for handling npol (spin polarization)
 
OrbitalQuantumNumbers get_orbital_qn (const Atom &atom, int iw)
 Extract orbital quantum numbers from atom and orbital index.
 
template<typename T >
double get_real_part (const T &val)
 Helper function to extract real part from complex or real values.
 
template<>
double get_real_part< double > (const double &val)
 
void rearrange_stress_matrix (ModuleBase::matrix &stress)
 Rearrange stress from 6-component vector to 3x3 matrix format.
 
template<typename TK , typename TR , typename IntegralFunc , int ForceSign, int StressSign>
void cal_force_stress_2center (const bool cal_force, const bool cal_stress, const hamilt::HContainer< double > *dmR, const UnitCell *ucell, const Grid_Driver *gridD, const std::vector< double > &orb_cutoff, const Parallel_Orbitals *paraV, IntegralFunc &integral_calculator, ModuleBase::matrix &force, ModuleBase::matrix &stress)
 Template function for calculating force and stress from 2-center integrals.
 

Function Documentation

◆ cal_force_stress_2center()

template<typename TK , typename TR , typename IntegralFunc , int ForceSign, int StressSign>
void OperatorForceStress::cal_force_stress_2center ( const bool  cal_force,
const bool  cal_stress,
const hamilt::HContainer< double > *  dmR,
const UnitCell ucell,
const Grid_Driver gridD,
const std::vector< double > &  orb_cutoff,
const Parallel_Orbitals paraV,
IntegralFunc &  integral_calculator,
ModuleBase::matrix force,
ModuleBase::matrix stress 
)

Template function for calculating force and stress from 2-center integrals.

This template unifies the force/stress calculation pattern for operators that use 2-center integrals (e.g., overlap, kinetic energy). The sign conventions for force and stress are controlled by template parameters to avoid runtime overhead.

Template Parameters
TKType for k-space matrices (double or std::complex<double>)
TRType for real-space matrices (typically double)
IntegralFuncFunctor type for calculating integrals
ForceSignSign convention for force (+1 or -1)
StressSignSign convention for stress (+1 or -1)
Parameters
cal_forceWhether to calculate forces
cal_stressWhether to calculate stress
dmRDensity matrix in real space
ucellUnit cell containing atomic structure
gridDGrid driver for finding adjacent atoms
orb_cutoffOrbital cutoff radii for each atom type
paraVParallel orbital distribution information
integral_calculatorFunctor that calculates integral and its derivatives
forceOutput force matrix (natom x 3)
stressOutput stress matrix (3 x 3)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalize_force_stress()

void OperatorForceStress::finalize_force_stress ( bool  cal_force,
bool  cal_stress,
const UnitCell ucell,
const std::vector< double > &  stress_tmp,
ModuleBase::matrix force,
ModuleBase::matrix stress,
double  force_factor = 2.0,
double  stress_factor = 2.0 
)

Finalize force and stress calculations with MPI reduction and post-processing.

Performs:

  1. MPI reduction of force and stress across all processes
  2. Apply force_factor (typically 2.0 for Hermitian matrices)
  3. Apply stress weight (lat0/omega) and stress_factor
  4. Rearrange stress matrix to 3x3 format
Parameters
cal_forceWhether force calculation is enabled
cal_stressWhether stress calculation is enabled
ucellUnit cell containing lattice parameters
stress_tmpTemporary 6-component stress vector
forceForce matrix to finalize
stressStress matrix to finalize
force_factorMultiplicative factor for force (default: 2.0 for Hermitian)
stress_factorMultiplicative factor for stress (default: 2.0 for Hermitian)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_orbital_qn()

OrbitalQuantumNumbers OperatorForceStress::get_orbital_qn ( const Atom atom,
int  iw 
)
inline

Extract orbital quantum numbers from atom and orbital index.

Parameters
atomAtom object containing orbital information
iwOrbital index within the atom
Returns
OrbitalQuantumNumbers structure with L, N, m, M values
Here is the caller graph for this function:

◆ get_real_part()

template<typename T >
double OperatorForceStress::get_real_part ( const T val)
inline

Helper function to extract real part from complex or real values.

Template specialization handles both std::complex<T> and double types

◆ get_real_part< double >()

template<>
double OperatorForceStress::get_real_part< double > ( const double &  val)
inline

◆ rearrange_stress_matrix()

void OperatorForceStress::rearrange_stress_matrix ( ModuleBase::matrix stress)
inline

Rearrange stress from 6-component vector to 3x3 matrix format.

Input format: [xx, xy, xz, yy, yz, zz] Output format: 3x3 matrix with proper indexing

Parameters
stressMatrix to rearrange (must be at least 3x3)
Here is the caller graph for this function:

◆ setup_step_trace()

void OperatorForceStress::setup_step_trace ( int  npol,
int  col_size,
std::vector< int > &  step_trace 
)
inline

Setup step_trace array for handling npol (spin polarization)

For npol=1 (non-spin-polarized): step_trace = {0} For npol=2 (spin-polarized): step_trace = {0, 1, col_size, col_size+1}

Parameters
npolNumber of spin polarizations (1 or 2)
col_sizeNumber of columns in the density matrix block
step_traceOutput vector to store step trace values
Here is the caller graph for this function: