22#include " dftu_force.h"
33#include " dftu_folding.h"
44#include " dftu_lcao.h"
5+ #include " dftu_lcao_pots.h"
56#include " source_base/global_function.h"
67#include " source_base/module_external/scalapack_connector.h"
78#include " source_base/parallel_reduce.h"
9+ #include " source_io/module_parameter/parameter.h"
810#include " source_base/timer.h"
911
1012#include < complex>
1416namespace DFTU_LCAO {
1517
1618void force_stress (Plus_U& dftu,
19+ const bool cal_force,
20+ const bool cal_stress,
1721 const UnitCell& ucell,
1822 const Grid_Driver& gd,
1923 std::vector<std::vector<double >>* dmk_d,
@@ -23,7 +27,8 @@ void force_stress(Plus_U& dftu,
2327 ModuleBase::matrix& force_dftu,
2428 ModuleBase::matrix& stress_dftu,
2529 const K_Vectors& kv,
26- const int npol)
30+ const int npol,
31+ const bool gamma_only_local)
2732{
2833 ModuleBase::TITLE (" DFTU_LCAO" , " force_stress" );
2934 ModuleBase::timer::start (" DFTU_LCAO" , " force_stress" );
@@ -35,16 +40,16 @@ void force_stress(Plus_U& dftu,
3540 // fsr_dftu is created without allocation), we fail early with a clear
3641 // message instead of letting pdgemm_ dereference nullptr and crash.
3742 // See force_stress_lcao.cpp for the historical background.
38- if (dftu. is_gamma_only_local () )
43+ if (gamma_only_local )
3944 {
40- if (dftu. is_cal_force ()
45+ if (cal_force
4146 && (fsr.DSloc_x == nullptr || fsr.DSloc_y == nullptr || fsr.DSloc_z == nullptr ))
4247 {
4348 ModuleBase::WARNING_QUIT (" DFTU_LCAO::force_stress" ,
4449 " fsr.DSloc_x/y/z are nullptr in gamma_only path; the caller must allocate and fill them. "
4550 " See notes in source/source_lcao/force_stress_lcao.cpp." );
4651 }
47- if (dftu. is_cal_stress ()
52+ if (cal_stress
4853 && (fsr.DSloc_x == nullptr || fsr.DSloc_y == nullptr || fsr.DSloc_z == nullptr
4954 || fsr.DH_r == nullptr ))
5055 {
@@ -56,14 +61,14 @@ void force_stress(Plus_U& dftu,
5661 }
5762 else
5863 {
59- if (dftu. is_cal_force ()
64+ if (cal_force
6065 && (fsr.DSloc_Rx == nullptr || fsr.DSloc_Ry == nullptr || fsr.DSloc_Rz == nullptr ))
6166 {
6267 ModuleBase::WARNING_QUIT (" DFTU_LCAO::force_stress" ,
6368 " fsr.DSloc_Rx/Ry/Rz are nullptr in multik path; the caller must allocate and fill them. "
6469 " See notes in source/source_lcao/force_stress_lcao.cpp." );
6570 }
66- if (dftu. is_cal_stress ()
71+ if (cal_stress
6772 && (fsr.DSloc_Rx == nullptr || fsr.DSloc_Ry == nullptr || fsr.DSloc_Rz == nullptr
6873 || fsr.DH_r == nullptr ))
6974 {
@@ -79,26 +84,26 @@ void force_stress(Plus_U& dftu,
7984 // explicit ic * pv.nrow + ir indices. All ks_solvers accepted by INPUT
8085 // validation are column-major today; abort loudly instead of silently
8186 // producing wrong forces/stresses if that assumption ever changes.
82- if ((dftu. is_cal_force () || dftu. is_cal_stress () )
83- && !ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER (dftu. get_ks_solver () ))
87+ if ((cal_force || cal_stress )
88+ && !ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER (PARAM . inp . ks_solver ))
8489 {
8590 ModuleBase::WARNING_QUIT (" DFTU_LCAO::force_stress" ,
8691 " non column-major ks_solver is not supported for DFT+U force/stress; "
8792 " the folded matrix layout assumption would be violated" );
8893 }
8994
90- const int nlocal = dftu. get_nlocal ();
95+ const int nlocal = pv. get_global_row_size ();
9196
92- if (dftu. is_cal_force () )
97+ if (cal_force )
9398 {
9499 force_dftu.zero_out ();
95100 }
96- if (dftu. is_cal_stress () )
101+ if (cal_stress )
97102 {
98103 stress_dftu.zero_out ();
99104 }
100105
101- if (dftu. is_gamma_only_local () )
106+ if (gamma_only_local )
102107 {
103108 const char transN = ' N' ;
104109 const char transT = ' T' ;
@@ -115,7 +120,7 @@ void force_stress(Plus_U& dftu,
115120
116121 double * pot_onsite = new double [pv.nloc ];
117122
118- dftu. pot_onsite_real (spin, false , pot_onsite, npol);
123+ DFTU_LCAO:: pot_onsite_real (dftu, ucell, &pv, spin, false , pot_onsite, npol);
119124
120125#ifdef __MPI
121126 ScalapackConnector::gemm (transT, transN, nlocal, nlocal, nlocal,
@@ -127,18 +132,18 @@ void force_stress(Plus_U& dftu,
127132
128133 delete[] pot_onsite;
129134
130- if (dftu. is_cal_force () )
135+ if (cal_force )
131136 {
132- cal_force_gamma (dftu. get_nlocal (), dftu. get_npol () ,
137+ cal_force_gamma (nlocal, npol ,
133138 dftu.get_orbital_corr_vec (), dftu.get_iatlnmipol2iwt (),
134139 ucell, &rho_pot_onsite[0 ], pv,
135140 fsr.DSloc_x , fsr.DSloc_y , fsr.DSloc_z , force_dftu);
136141 }
137142
138- if (dftu. is_cal_stress () )
143+ if (cal_stress )
139144 {
140- cal_stress_gamma (dftu. get_nlocal (), dftu. get_npol () ,
141- dftu. get_ks_solver () , dftu.get_orb_cutoff (),
145+ cal_stress_gamma (nlocal, npol ,
146+ PARAM . inp . ks_solver , dftu.get_orb_cutoff (),
142147 ucell, pv, &gd,
143148 fsr.DSloc_x , fsr.DSloc_y , fsr.DSloc_z , fsr.DH_r ,
144149 &rho_pot_onsite[0 ], stress_dftu);
@@ -161,7 +166,7 @@ void force_stress(Plus_U& dftu,
161166
162167 std::complex <double >* pot_onsite = new std::complex <double >[pv.nloc ];
163168
164- dftu. pot_onsite_complex (spin, false , pot_onsite, npol);
169+ DFTU_LCAO:: pot_onsite_complex (dftu, ucell, &pv, spin, false , pot_onsite, npol);
165170
166171
167172#ifdef __MPI
@@ -173,28 +178,28 @@ void force_stress(Plus_U& dftu,
173178
174179 delete[] pot_onsite;
175180
176- if (dftu. is_cal_force () )
181+ if (cal_force )
177182 {
178- cal_force_k (dftu. get_nlocal (), dftu. get_npol () ,
179- dftu. get_ks_solver () , dftu.get_orb_cutoff (),
183+ cal_force_k (nlocal, npol ,
184+ PARAM . inp . ks_solver , dftu.get_orb_cutoff (),
180185 dftu.get_orbital_corr_vec (), dftu.get_iatlnmipol2iwt (),
181186 ucell, gd, fsr, pv, ik, &rho_pot_onsite[0 ], force_dftu, kv.kvec_d [ik]);
182187 }
183- if (dftu. is_cal_stress () )
188+ if (cal_stress )
184189 {
185- cal_stress_k (dftu. get_nlocal (), dftu. get_npol () ,
186- dftu. get_ks_solver () , dftu.get_orb_cutoff (),
190+ cal_stress_k (nlocal, npol ,
191+ PARAM . inp . ks_solver , dftu.get_orb_cutoff (),
187192 ucell, gd, fsr, pv, ik, &rho_pot_onsite[0 ], stress_dftu, kv.kvec_d [ik]);
188193 }
189194 } // ik
190195 }
191196
192- if (dftu. is_cal_force () )
197+ if (cal_force )
193198 {
194199 Parallel_Reduce::reduce_pool (force_dftu.c , force_dftu.nr * force_dftu.nc );
195200 }
196201
197- if (dftu. is_cal_stress () )
202+ if (cal_stress )
198203 {
199204 Parallel_Reduce::reduce_pool (stress_dftu.c , stress_dftu.nr * stress_dftu.nc );
200205
0 commit comments