1+ #include " lr_force.h"
2+ #include " cal_hs_grad.h"
3+ #include " pulay_force_hcontainer.h"
4+ #include " module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress.h" // only for gint terms
5+ #include " module_lr/utils/lr_util_hcontainer.h"
6+ namespace LR
7+ {
8+ template <typename TK>
9+ ModuleBase::matrix LR_Force<TK>::cal_force_overlap_edm(const elecstate::DensityMatrix<TK, double >& edm)
10+ {
11+ // const double* dS[3] = { dSloc_x, dSloc_y, dSloc_z };
12+ std::vector<hamilt::HContainer<double >> dS = cal_hs_grad (' S' , this ->ucell_ , this ->pv_ , this ->gd_ , this ->two_center_bundle_ );
13+ // test: output dS
14+ // std::cout << "dS in 3 directions:\n";
15+ // for (int i = 0;i < 3;++i) { LR_Util::print_HR(dS.at(i), this->ucell_.nat, "dS" + std::to_string(i)); }
16+ ModuleBase::matrix foverlap = PulayForceStress::cal_pulay_fs (edm, this ->ucell_ , dS, -1 .);
17+ if (PARAM.inp .test_force )
18+ {
19+ ModuleIO::print_force (GlobalV::ofs_running, this ->ucell_ , " OVERLAP FORCE (eV/Angstrom)" , foverlap, false );
20+ }
21+ return foverlap;
22+ }
23+
24+ template <typename TK>
25+ ModuleBase::matrix LR_Force<TK>::reproduce_force_gs(
26+ const elecstate::DensityMatrix<TK, double >& dm_gs,
27+ const elecstate::DensityMatrix<TK, double >& edm_gs)
28+ {
29+ this ->gint_ ->reset_DMRGint (PARAM.inp .nspin );
30+ // local + Hartree + xc term, including Hellmann-Feynman and Pulay
31+ ModuleBase::matrix f_gs_hf_pulay = cal_force_hamilt_gs_dm_relaxed_diff (dm_gs, dm_gs); // pw+vnl+t_dphi+vl_dphi
32+ // edm term
33+ ModuleBase::matrix f_nonortho = cal_force_overlap_edm (edm_gs); // overlap
34+ this ->gint_ ->reset_DMRGint (1 );
35+ return f_gs_hf_pulay + f_nonortho;
36+ }
37+
38+ template <typename TK>
39+ ModuleBase::matrix LR_Force<TK>::reproduce_force_gs_loc(
40+ const elecstate::DensityMatrix<TK, double >& dm_gs,
41+ const elecstate::Potential& pot_gs)
42+ {
43+ this ->gint_ ->reset_DMRGint (PARAM.inp .nspin );
44+ const Charge chr_gs = dm_to_charge (dm_gs);
45+ // local pp (Pulay) + Hartree + xc (grid integration)
46+ ModuleBase::matrix fvl_dphi (this ->ucell_ .nat , 3 );
47+ ModuleBase::matrix stress_tmp; // no use now, only for passing into interfaces
48+ PulayForceStress::cal_pulay_fs (dm_gs.get_DMR_vector ().size ()/* nspin*/ , fvl_dphi, stress_tmp,
49+ dm_gs, this ->ucell_ , &pot_gs, *this ->gint_ , true , false );
50+ this ->gint_ ->reset_DMRGint (1 );
51+ return fvl_dphi;
52+ }
53+
54+ template <typename TK>
55+ void LR_Force<TK>::cal_H2_sz_center4_grad_hxc(const std::vector<double >& orb_cutoffs)
56+ {
57+ GlobalV::ofs_running << " ==== Test H2_SZ_CENTER4_HXC (d_x(i) j | kl) ====" << std::endl;
58+ const std::vector<ModuleBase::Vector3<double >>& kvd_test = { ModuleBase::Vector3<double >(0.0 , 0.0 , 0.0 ) };
59+ auto init_dm_eff = [&, this ](const int i, const int j) -> elecstate::DensityMatrix<TK, double >
60+ {
61+ std::vector<TK> dm_2d (4 , 0.0 );
62+ std::cout<<" i<<1 + j =" << ((i<<1 ) + j) << std::endl;
63+ dm_2d[i*2 +j] = 1.0 ;
64+ elecstate::DensityMatrix<TK, double > dm (&this ->pv_ , 1 , kvd_test, 1 );
65+ dm.set_DMK_pointer (0 , dm_2d.data ());
66+ LR_Util::initialize_DMR (dm, this ->pv_ , this ->ucell_ , this ->gd_ , orb_cutoffs);
67+ dm.cal_DMR ();
68+ return dm;
69+ };
70+ ModuleBase::matrix stress_tmp; // dummy
71+ this ->gint_ ->reset_DMRGint (1 );
72+
73+ for (auto && i : { 0 , 1 })
74+ for (auto && j : { 0 , 1 })
75+ {
76+ elecstate::DensityMatrix<TK, double > dm_ij = init_dm_eff (i, j);
77+ LR_Util::print_DMR (dm_ij, ucell_.nat , " DMR_" + std::to_string (i) + std::to_string (j));
78+ for (auto && k : { 0 , 1 })
79+ for (auto && l : { 0 , 1 })
80+ {
81+ // 1. build dm(kl)
82+ elecstate::DensityMatrix<TK, double > dm_kl = init_dm_eff (k, l);
83+ // 2. build charge & potential
84+ elecstate::Potential pot_hxc_kl = dm_to_hxc_potential (dm_kl);
85+ // 3. cal force
86+ ModuleBase::matrix fvl_dphi (this ->ucell_ .nat , 3 );
87+ PulayForceStress::cal_pulay_fs (1 /* nspin*/ , fvl_dphi, stress_tmp,
88+ dm_ij, this ->ucell_ , &pot_hxc_kl, *this ->gint_ , true , false );
89+ ModuleIO::print_force (GlobalV::ofs_running, this ->ucell_ ,
90+ " H2_SZ_CENTER4_HXC_" + std::to_string (i) + std::to_string (j) + std::to_string (k) + std::to_string (l) + " FORCE (eV/Angstrom)" ,
91+ fvl_dphi, false );
92+ }
93+ }
94+ }
95+ }
96+
97+ template class LR ::LR_Force<double >;
98+ template class LR ::LR_Force<std::complex <double >>;
0 commit comments