ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
operator_force_stress_utils.h
Go to the documentation of this file.
1#ifndef OPERATOR_FORCE_STRESS_UTILS_H
2#define OPERATOR_FORCE_STRESS_UTILS_H
3
6#include <vector>
7
8namespace OperatorForceStress {
9
20inline void setup_step_trace(int npol, int col_size, std::vector<int>& step_trace)
21{
22 step_trace.resize(npol * npol, 0);
23 if (npol == 2)
24 {
25 step_trace[1] = 1;
26 step_trace[2] = col_size;
27 step_trace[3] = col_size + 1;
28 }
29}
30
35{
36 int L;
37 int N;
38 int m;
39 int M;
40};
41
49inline OrbitalQuantumNumbers get_orbital_qn(const Atom& atom, int iw)
50{
52 qn.L = atom.iw2l[iw];
53 qn.N = atom.iw2n[iw];
54 qn.m = atom.iw2m[iw];
55 qn.M = (qn.m % 2 == 0) ? -qn.m / 2 : (qn.m + 1) / 2;
56 return qn;
57}
58
64template <typename T>
65inline double get_real_part(const T& val)
66{
67 return val.real();
68}
69
70template <>
71inline double get_real_part<double>(const double& val)
72{
73 return val;
74}
75
85{
86 stress.c[8] = stress.c[5]; // stress(2,2)
87 stress.c[7] = stress.c[4]; // stress(2,1)
88 stress.c[6] = stress.c[2]; // stress(2,0)
89 stress.c[5] = stress.c[4]; // stress(1,2)
90 stress.c[4] = stress.c[3]; // stress(1,1)
91 stress.c[3] = stress.c[1]; // stress(1,0)
92}
93
113 bool cal_force,
114 bool cal_stress,
115 const UnitCell* ucell,
116 const std::vector<double>& stress_tmp,
117 ModuleBase::matrix& force,
118 ModuleBase::matrix& stress,
119 double force_factor = 2.0,
120 double stress_factor = 2.0);
121
122} // namespace OperatorForceStress
123
124#endif // OPERATOR_FORCE_STRESS_UTILS_H
Definition atom_spec.h:6
std::vector< int > iw2m
Definition atom_spec.h:17
std::vector< int > iw2l
Definition atom_spec.h:19
std::vector< int > iw2n
Definition atom_spec.h:18
Definition matrix.h:18
double * c
Definition matrix.h:24
Definition unitcell.h:15
#define T
Definition exp.cpp:237
Definition operator_force_stress_utils.cpp:4
void setup_step_trace(int npol, int col_size, std::vector< int > &step_trace)
Setup step_trace array for handling npol (spin polarization)
Definition operator_force_stress_utils.h:20
double get_real_part(const T &val)
Helper function to extract real part from complex or real values.
Definition operator_force_stress_utils.h:65
OrbitalQuantumNumbers get_orbital_qn(const Atom &atom, int iw)
Extract orbital quantum numbers from atom and orbital index.
Definition operator_force_stress_utils.h:49
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, double stress_factor)
Finalize force and stress calculations with MPI reduction and post-processing.
Definition operator_force_stress_utils.cpp:6
void rearrange_stress_matrix(ModuleBase::matrix &stress)
Rearrange stress from 6-component vector to 3x3 matrix format.
Definition operator_force_stress_utils.h:84
double get_real_part< double >(const double &val)
Definition operator_force_stress_utils.h:71
Structure to hold orbital quantum numbers.
Definition operator_force_stress_utils.h:35
int N
Principal quantum number.
Definition operator_force_stress_utils.h:37
int m
Magnetic quantum number (internal indexing)
Definition operator_force_stress_utils.h:38
int M
Magnetic quantum number (standard convention)
Definition operator_force_stress_utils.h:39
int L
Angular momentum quantum number.
Definition operator_force_stress_utils.h:36