1#ifndef OPERATOR_FS_UTILS_HPP
2#define OPERATOR_FS_UTILS_HPP
41template <
typename TK,
typename TR,
typename IntegralFunc,
int ForceSign,
int StressSign>
44 const bool cal_stress,
48 const std::vector<double>& orb_cutoff,
51 IntegralFunc& integral_calculator,
56 std::vector<double> stress_tmp(6, 0);
66 std::vector<double> stress_local(6, 0);
69 #pragma omp for schedule(dynamic)
70 for (
int iat1 = 0; iat1 < ucell->
nat; iat1++)
72 auto tau1 = ucell->
get_tau(iat1);
84 gridD->
Find_atom(*ucell, tau1, T1, I1, &adjs);
86 for (
int ad = 0; ad < adjs.
adj_num + 1; ++ad)
88 const int T2 = adjs.
ntype[ad];
89 const int I2 = adjs.
natom[ad];
90 const int iat2 = ucell->
itia2iat(T2, I2);
95 if (dtau.
norm() * ucell->
lat0 >= orb_cutoff[T1] + orb_cutoff[T2])
102 if (dm_matrix ==
nullptr)
108 double* force_tmp1 = (cal_force) ? &force_local(iat1, 0) :
nullptr;
109 double* force_tmp2 = (cal_force) ? &force_local(iat2, 0) :
nullptr;
119 const double* dm_pointer = dm_matrix->
get_pointer();
120 double olm[4] = {0, 0, 0, 0};
123 const int ncol = cols.
nloc();
124 const int ncol_stride = ncol + 1;
125 std::vector<int> step_trace(npol * npol, 0);
129 step_trace[2] = ncol;
130 step_trace[3] = ncol_stride;
134 for (
int iw1l = 0; iw1l < rows.
nloc(); iw1l += npol)
136 const int iw1 = rows[iw1l] / npol;
137 const int L1 = atom1.
iw2l[iw1];
138 const int N1 = atom1.
iw2n[iw1];
139 const int m1 = atom1.
iw2m[iw1];
140 const int M1 = (m1 % 2 == 0) ? -m1 / 2 : (m1 + 1) / 2;
142 for (
int iw2l = 0; iw2l < ncol; iw2l += npol)
144 const int iw2 = cols[iw2l] / npol;
145 const int L2 = atom2.
iw2l[iw2];
146 const int N2 = atom2.
iw2n[iw2];
147 const int m2 = atom2.
iw2m[iw2];
148 const int M2 = (m2 % 2 == 0) ? -m2 / 2 : (m2 + 1) / 2;
151 integral_calculator(T1, L1, N1, M1, T2, L2, N2, M2, dtau, olm);
154 const double dm_current = dm_pointer[0];
160 for (
int i = 0; i < 3; i++)
162 force_tmp1[i] += ForceSign * dm_current * olm[i + 1];
163 force_tmp2[i] -= ForceSign * dm_current * olm[i + 1];
170 stress_local[0] += StressSign * dm_current * olm[1] * dtau.
x;
171 stress_local[1] += StressSign * dm_current * olm[1] * dtau.
y;
172 stress_local[2] += StressSign * dm_current * olm[1] * dtau.
z;
173 stress_local[3] += StressSign * dm_current * olm[2] * dtau.
y;
174 stress_local[4] += StressSign * dm_current * olm[2] * dtau.
z;
175 stress_local[5] += StressSign * dm_current * olm[3] * dtau.
z;
180 dm_pointer += (npol - 1) * ncol;
189 force += force_local;
193 for (
int i = 0; i < 6; i++)
195 stress_tmp[i] += stress_local[i];
Struct of array for packing the Adjacent atom information.
Definition sltk_grid_driver.h:21
int adj_num
number of adjacent atoms
Definition sltk_grid_driver.h:30
std::vector< ModuleBase::Vector3< int > > box
box indices of adjacent atoms
Definition sltk_grid_driver.h:34
std::vector< int > ntype
types of adjacent atoms
Definition sltk_grid_driver.h:31
std::vector< int > natom
indices of adjacent atoms
Definition sltk_grid_driver.h:32
Atom-local basis entries derived from basis indexing and distribution.
Definition atom_basis_view.h:16
bool empty() const
Definition atom_basis_view.h:30
int nloc() const
Definition atom_basis_view.h:25
static AtomBasisView cols(const BasisFlattenedIndexing &basis, const Parallel_Blkcyclic &layout, int iat)
Definition atom_basis_view.cpp:72
static AtomBasisView rows(const BasisFlattenedIndexing &basis, const Parallel_Blkcyclic &layout, int iat)
Definition atom_basis_view.cpp:65
Atom class for storing atom information.
Definition atom_spec.h:14
std::vector< int > iw2m
use iw to find m
Definition atom_spec.h:31
std::vector< int > iw2l
use iw to find L
Definition atom_spec.h:33
std::vector< int > iw2n
use iw to find n
Definition atom_spec.h:32
Canonical atom-major flattening of the LCAO basis hierarchy.
Definition basis_flattened_indexing.h:40
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
void Find_atom(const UnitCell &ucell, const int ntype, const int nnumber, AdjacentAtomInfo *adjs=nullptr) const
Find adjacent atoms for a given atom.
Definition sltk_grid_driver.cpp:24
3 elements vector
Definition vector3.h:21
T x
Definition vector3.h:23
T norm(void) const
Get the norm of a Vector3.
Definition vector3.h:213
T y
Definition vector3.h:24
T z
Definition vector3.h:25
void zero_out(void)
Definition matrix.cpp:312
int nr
Definition matrix.h:19
int nc
Definition matrix.h:20
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Provide the basic information about unitcell.
Definition unitcell.h:16
Atom * atoms
Definition unitcell.h:165
const int & get_npol() const
Get npol.
Definition unitcell.h:66
const ModuleBase::Vector3< double > & get_tau(const int &iat) const
Get tau for atom iat.
Definition unitcell.h:104
double & lat0
Definition unitcell.h:135
ModuleBase::IntArray itia2iat
(it, ia)==>iat, the index in nat (add 2009-3-2 by mohan)
Definition unitcell.h:160
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
const ModuleBase::Vector3< double > cal_dtau(const int &iat1, const int &iat2, const ModuleBase::Vector3< int > &R) const
Calculate vector between two atoms with R cell.
Definition unitcell.h:110
bool iat2iait(const Tiat iat, Tiait *ia, Tiait *it) const
Indexing tools for ia and it.
Definition unitcell.h:79
Definition base_matrix.h:20
T * get_pointer() const
get pointer of value from a submatrix
Definition base_matrix.h:86
Definition hcontainer.h:147
BaseMatrix< T > * find_matrix(int i, int j, int rx, int ry, int rz)
find BaseMatrix with atom index atom_i and atom_j and R index (rx, ry, rz) This interface can be used...
Definition hcontainer.cpp:426
Definition operator_fs_utils.cpp:4
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 BasisFlattenedIndexing &basis, const Parallel_Blkcyclic &layout, IntegralFunc &integral_calculator, ModuleBase::matrix &force, ModuleBase::matrix &stress)
Template function for calculating force and stress from 2-center integrals.
Definition operator_fs_utils.hpp:42
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_fs_utils.cpp:6
Grid_Driver class for neighbor search interface.