@@ -266,39 +266,44 @@ std::vector<ModuleBase::matrix> LR::ESolver_LR<T, TR>::cal_force(const int ispin
266266 }
267267
268268 ModuleBase::matrix force_hxc_dmtrans = lr_force.cal_force_hxc_dmtrans (dm_trans_real, *this ->pot [ispin]);
269- std::cout << " Force (Hxc-DMTrans term) of state " << istate << " : " << std::endl;
270- LR_Util::print_value (force_hxc_dmtrans. c , ucell. nat , 3 );
269+ if (PARAM. inp . test_force )
270+ ModuleIO::print_force (GlobalV::ofs_running, this -> ucell , " HXC DMTRANS FORCE (eV/Angstrom) " , force_hxc_dmtrans, false );
271271
272272 const elecstate::DensityMatrix<T, double >& dm_gs = this ->cal_dm_gs ();
273273 ModuleBase::matrix force_hamiltgs_relaxed_diff = lr_force.cal_force_hamilt_gs_dm_relaxed_diff (relaxed_diff_dm_real, dm_gs, /* with_ewald=*/ false );
274- std::cout << " Force (GS-(T+Z) term) of state " << istate << " : " << std::endl;
275- LR_Util::print_value (force_hamiltgs_relaxed_diff. c , ucell. nat , 3 );
274+ if (PARAM. inp . test_force )
275+ ModuleIO::print_force (GlobalV::ofs_running, this -> ucell , " H_GS-(T+Z) FORCE (without EXX) (eV/Angstrom) " , force_hamiltgs_relaxed_diff, false );
276276
277277 ModuleBase::matrix force_overlap_edm = lr_force.cal_force_overlap_edm (edm_real); // "-" sign has been included in the force factor
278- std::cout << " Force (Overlap-EDM term) of state " << istate << " : " << std::endl;
279- LR_Util::print_value (force_overlap_edm. c , ucell. nat , 3 );
278+ if (PARAM. inp . test_force )
279+ ModuleIO::print_force (GlobalV::ofs_running, this -> ucell , " OVERLAP-EDM FORCE (eV/Angstrom) " , force_overlap_edm, false );
280280
281281#ifdef __EXX
282282 const double & alpha = this ->exx_info .info_global .hybrid_alpha ;
283283
284- const auto & Ds_trans = get_exx_Ds_spin1 (dm_trans, this ->ucell , this ->kv , this ->paraMat_ );
285- ModuleBase::matrix force_exx_dmtrans = lr_force.cal_force_exx_dm_trans (Ds_trans, alpha);
286- std::cout << " Force (EXX-DMTrans term) of state " << istate << " : " << std::endl;
287- LR_Util::print_value (force_exx_dmtrans.c , ucell.nat , 3 );
288-
289- const auto & Ds_gs = get_exx_Ds_gs (dm_gs, this ->ucell , this ->kv , this ->paraMat_ , this ->nspin );
290- const auto & Ds_relaxed_diff = get_exx_Ds_spin1 (relaxed_diff_dm, this ->ucell , this ->kv , this ->paraMat_ );
291- ModuleBase::matrix force_exx_gs_diff = lr_force.cal_force_exx_gs_dm_relaxed_diff (Ds_gs, Ds_relaxed_diff, alpha);
292- std::cout << " Force (EXX-GS-(T+Z) term) of state " << istate << " : " << std::endl;
293- LR_Util::print_value (force_exx_gs_diff.c , ucell.nat , 3 );
284+ if (LR::exx_kernel_list ().count (xc_kernel))
285+ {
286+ const auto & Ds_trans = get_exx_Ds_spin1 (dm_trans, this ->ucell , this ->kv , this ->paraMat_ );
287+ ModuleBase::matrix force_exx_dmtrans = lr_force.cal_force_exx_dm_trans (Ds_trans, alpha);
288+ if (PARAM.inp .test_force )
289+ ModuleIO::print_force (GlobalV::ofs_running, this ->ucell , " EXX DMTRANS FORCE (eV/Angstrom)" , force_exx_dmtrans, false );
290+ force_hxc_dmtrans += force_exx_dmtrans;
294291
295- // add exx force to the corresponding terms
296- force_hxc_dmtrans += force_exx_dmtrans;
297- force_hamiltgs_relaxed_diff += force_exx_gs_diff;
292+ }
293+ if (LR::exx_kernel_list ().count (PARAM.inp .dft_functional ))
294+ {
295+ const auto & Ds_gs = get_exx_Ds_gs (dm_gs, this ->ucell , this ->kv , this ->paraMat_ , this ->nspin );
296+ const auto & Ds_relaxed_diff = get_exx_Ds_spin1 (relaxed_diff_dm, this ->ucell , this ->kv , this ->paraMat_ );
297+ ModuleBase::matrix force_exx_gs_diff = lr_force.cal_force_exx_gs_dm_relaxed_diff (Ds_gs, Ds_relaxed_diff, alpha);
298+ if (PARAM.inp .test_force )
299+ ModuleIO::print_force (GlobalV::ofs_running, this ->ucell , " EXX GS-(T+Z) FORCE (eV/Angstrom)" , force_exx_gs_diff, false );
300+ force_hamiltgs_relaxed_diff += force_exx_gs_diff;
301+ }
298302#endif
299303 forces[istate] = force_hxc_dmtrans + force_hamiltgs_relaxed_diff + force_overlap_edm;
300304 }
301305 ModuleBase::timer::tick (" ESolver_LR" , " cal_force" );
306+ // total force
302307 print_force (forces, std::cout);
303308 print_force (forces, GlobalV::ofs_running);
304309 return forces;
0 commit comments