ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
force_funcs.h
Go to the documentation of this file.
1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_FORCE_FUNCS_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_FORCE_FUNCS_H
8
9// This file extracts out some terms from the ground state force code
10// to calculate the excited state force with a different density matrix.
11template<typename T>
13{
14public:
16 const Charge& chr,
17 const ModulePW::PW_Basis& rhopw,
18 const pseudopot_cell_vl& locpp,
19 const Structure_Factor& sf,
20 const int nspin,
21 const bool test_force,
22 std::ofstream& ofs_running,
23 const bool with_ewald = true,
24 const elecstate::ElecState* pelec = nullptr)
25 {
26 if (nspin == 4)
27 {
28 throw std::runtime_error("ForcePWTerms: nspin=4 is not supported.");
29 }
30 ModuleBase::TITLE("Force_Stress_LCAO", "cal_force_pw");
31 Forces<T> f_pw(ucell.nat);
32 ModuleBase::matrix fvl_dvl(ucell.nat, 3);
33 ModuleBase::matrix fewalds(ucell.nat, 3);
34 ModuleBase::matrix fcc(ucell.nat, 3);
35 ModuleBase::matrix fscc(ucell.nat, 3);
36 //--------------------------------------------------------
37 // local pseudopotential force:
38 // use charge density; plane wave; local pseudopotential;
39 //--------------------------------------------------------
40 f_pw.cal_force_loc(ucell, fvl_dvl, &rhopw, locpp.vloc, &chr);
41 //--------------------------------------------------------
42 // ewald force: use plane wave only.
43 //--------------------------------------------------------
44 if (with_ewald)
45 {
46 f_pw.cal_force_ew(ucell, fewalds, &rhopw, &sf);
47 }
48 //--------------------------------------------------------
49 // force due to core correlation.
50 //--------------------------------------------------------
51 UnitCell& ucell_noconst = const_cast<UnitCell&>(ucell);
52 // domag/domag_z/gga_grad only matter for the noncollinear (nspin=4) case, which the
53 // throw-guard above already excludes, so they are passed as fixed, inert defaults
54 // here instead of reading the corresponding global flags.
55 f_pw.cal_force_cc(fcc, &rhopw, &chr, locpp.numeric, ucell_noconst,
56 nspin, /*domag=*/false, /*domag_z=*/false, /*gga_grad=*/0);
57 //--------------------------------------------------------
58 // force due to self-consistent charge (invalid in from-scratch LR case)
59 //--------------------------------------------------------
60 if (pelec)
61 {
62 f_pw.cal_force_scc(fscc, &rhopw, pelec->vnew, pelec->vnew_exist, locpp.numeric, ucell);
63 }
64 if (test_force)
65 {
66 ModuleIO::print_force(ofs_running, ucell, "VL_dVL FORCE (eV/Angstrom)", fvl_dvl, false);
67 ModuleIO::print_force(ofs_running, ucell, "EWALD FORCE (eV/Angstrom)", fewalds, false);
68 ModuleIO::print_force(ofs_running, ucell, "NLCC FORCE (eV/Angstrom)", fcc, false);
69 ModuleIO::print_force(ofs_running, ucell, "SCC FORCE (eV/Angstrom)", fscc, false);
70 }
71 return fvl_dvl + fewalds + fcc + fscc;
72 }
73};
74
75// calculate force and stress for Nonlocal part
76// nspin = 2 or 4 will not be used in the current excited state force calculation
77// for nspin = 1 or 2
78template<typename TK>
80 const UnitCell& ucell,
81 const std::vector<ModuleBase::Vector3<double>>& kvec_d,
82 const Grid_Driver& gd,
83 const TwoCenterBundle& two_center_bundle,
85{
86 ModuleBase::TITLE("Force_Stress_LCAO", "cal_force_nonlocal_dvnl");
87 std::vector<double> orb_cutoffs(ucell.ntype);
88 for (int it = 0; it < ucell.ntype; ++it)
89 {
90 orb_cutoffs[it] = ucell.atoms[it].Rcut;
91 }
92
94 kvec_d,
95 nullptr,
96 &ucell,
97 orb_cutoffs,
98 &gd,
99 two_center_bundle.overlap_orb_beta.get());
100 const int nspin = dm.get_dmr_vec().size();
101 if(nspin==2)
102 {
103 const_cast<module_dm::DensityMatrix<TK, double>*>(&dm)->switch_dmr(1); //spin-up + spin-down
104 }
105 const hamilt::HContainer<double>* dmr = dm.get_dmr_ptr(1);
106 ModuleBase::matrix fvnl(ucell.nat, 3);
107 ModuleBase::matrix svnl; // no use now, only for passing into interfaces
108 tmp_nonlocal.cal_force_stress(/*force*/true, /*stress*/false, dmr, fvnl, svnl);
109 if (nspin == 2)
110 {
111 const_cast<module_dm::DensityMatrix<TK, double>*>(&dm)->switch_dmr(0);
112 }
113 return fvnl;
114}
115// calculate force and stress for Nonlocal part (Hellmann-Feynman term)
116// for nspin = 4
117template<typename TK>
119 UnitCell ucell,
120 const std::vector<ModuleBase::Vector3<double>>& kvec_d,
121 const Grid_Driver& gd,
122 const TwoCenterBundle& two_center_bundle,
123 const module_dm::DensityMatrix<TK, std::complex<double>>& dm)
124{
125 ModuleBase::TITLE("Force_Stress_LCAO", "cal_force_nonlocal_dvnl");
126
127 std::vector<double> orb_cutoffs(ucell.ntype);
128 for (int it = 0; it < ucell.ntype; ++it)
129 {
130 orb_cutoffs[it] = ucell.atoms[it].Rcut;
131 }
132
133 hamilt::Nonlocal<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>> tmp_nonlocal(
134 nullptr,
135 kvec_d,
136 nullptr,
137 &ucell,
138 orb_cutoffs,
139 &gd,
140 two_center_bundle.overlap_orb_beta.get());
141
142 hamilt::HContainer<std::complex<double>> tmp_dmr(dm.get_dmr_ptr(1)->get_paraV());
143 std::vector<int> ijrs = dm.get_dmr_ptr(1)->get_ijr_info();
144 tmp_dmr.insert_ijrs(&ijrs);
145 tmp_dmr.allocate();
146 dm.cal_DMR_full(&tmp_dmr);
147 ModuleBase::matrix fvnl(ucell.nat, 3);
148 ModuleBase::matrix svnl; // no use now, only for passing into interfaces
149 tmp_nonlocal.cal_force_stress(/*force*/true, /*stress*/false, &tmp_dmr, fvnl, svnl);
150 return fvnl;
151}
152#endif // ABACUS_SOURCE_LCAO_MODULE_LR_FORCE_FUNCS_H
double Rcut
cut-off radius (pengfei Li 16-2-29)
Definition atom_spec.h:47
Definition charge.h:24
Definition force_funcs.h:13
ModuleBase::matrix operator()(const UnitCell &ucell, const Charge &chr, const ModulePW::PW_Basis &rhopw, const pseudopot_cell_vl &locpp, const Structure_Factor &sf, const int nspin, const bool test_force, std::ofstream &ofs_running, const bool with_ewald=true, const elecstate::ElecState *pelec=nullptr)
Definition force_funcs.h:15
Definition force_pw.h:33
void cal_force_cc(ModuleBase::matrix &forcecc, const ModulePW::PW_Basis *const rho_basis, const Charge *const chr, const bool *numeric, UnitCell &ucell_in, const int nspin, const bool domag, const bool domag_z, const int gga_grad)
Definition force_pw_cc.cpp:28
void cal_force_scc(ModuleBase::matrix &forcescc, const ModulePW::PW_Basis *const rho_basis, const ModuleBase::matrix &v_current, const bool vnew_exist, const bool *numeric, const UnitCell &ucell_in)
Definition force_pw_scc.cpp:22
void cal_force_ew(const UnitCell &ucell, ModuleBase::matrix &forceion, const ModulePW::PW_Basis *const rho_basis, const Structure_Factor *p_sf)
Definition force_pw.cpp:430
void cal_force_loc(const UnitCell &ucell, ModuleBase::matrix &forcelc, const ModulePW::PW_Basis *const rho_basis, const ModuleBase::matrix &vloc, const Charge *const chr)
Definition force_pw.cpp:290
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
3 elements vector
Definition vector3.h:21
Definition matrix.h:15
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Definition stru_fac.h:10
Definition two_center_bundle.h:11
std::unique_ptr< TwoCenterIntegrator > overlap_orb_beta
Definition two_center_bundle.h:46
Provide the basic information about unitcell.
Definition unitcell.h:16
int ntype
number of atom species in UnitCell
Definition unitcell.h:154
Atom * atoms
Definition unitcell.h:165
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
Definition elecstate.h:20
Definition hcontainer.h:147
void insert_ijrs(const std::vector< int > *ijrs)
use infomation of IJ pairs to expand HContainer the input vector format is {size_IJ_pairs,...
Definition hcontainer.cpp:1107
void allocate(T *data_array=nullptr, bool if_zero=false)
allocate memory for all <IJR> matrix if data_array is not nullptr, use memory after data_array for ea...
Definition hcontainer.cpp:324
Definition nonlocal.h:27
DensityMatrix Class <TK,TR> = <double,double> for Gamma-only calculation <TK,TR> = <std::complex<doub...
Definition density_matrix.h:172
const std::vector< hamilt::HContainer< TR > * > & get_dmr_vec() const
get pointer vector of DMR
Definition density_matrix.h:301
hamilt::HContainer< TR > * get_dmr_ptr(const int ispin) const
get pointer of DMR
Definition dm_getter.cpp:19
Definition vl_pw.h:13
bool * numeric
Definition vl_pw.h:42
ModuleBase::matrix vloc
Definition vl_pw.h:41
ModuleBase::matrix cal_force_nonlocal(const UnitCell &ucell, const std::vector< ModuleBase::Vector3< double > > &kvec_d, const Grid_Driver &gd, const TwoCenterBundle &two_center_bundle, const module_dm::DensityMatrix< TK, double > &dm)
Definition force_funcs.h:79
ModuleBase::matrix cal_force_nonlocal_dvnl(UnitCell ucell, const std::vector< ModuleBase::Vector3< double > > &kvec_d, const Grid_Driver &gd, const TwoCenterBundle &two_center_bundle, const module_dm::DensityMatrix< TK, std::complex< double > > &dm)
Definition force_funcs.h:118
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
void print_force(std::ofstream &ofs_running, const UnitCell &cell, const std::string &name, const ModuleBase::matrix &force, bool ry)
output atomic forces
Definition output_log.cpp:230