11#include " pot_hxc_lrtd.h"
2- #include " module_elecstate/potentials/pot_base.h"
32#include " module_parameter/parameter.h"
43#include " module_elecstate/potentials/H_Hartree_pw.h"
54#include " module_base/timer.h"
65#include " module_hamilt_general/module_xc/xc_functional.h"
76#include < set>
87#include " module_lr/utils/lr_util.h"
98#include " module_lr/utils/lr_util_xc.hpp"
10- #include " module_io/cube_io.h"
119#include " module_hamilt_pw/hamilt_pwdft/global.h" // tmp, for pgrid
1210#define FXC_PARA_TYPE const double * const rho, ModuleBase::matrix& v_eff, const std::vector<int >& ispin_op = { 0 ,0 }
1311namespace LR
1412{
1513 // constructor for exchange-correlation kernel
16- PotHxcLR::PotHxcLR (const std::string& xc_kernel, const ModulePW::PW_Basis* rho_basis, const UnitCell* ucell,
17- const Charge* chg_gs/* ground state*/ , const Parallel_Grid& pgrid,
14+ PotHxcLR::PotHxcLR (const std::string& xc_kernel, const ModulePW::PW_Basis& rho_basis, const UnitCell& ucell,
15+ const Charge& chg_gs/* ground state*/ , const Parallel_Grid& pgrid,
1816 const SpinType& st, const std::vector<std::string>& lr_init_xc_kernel)
19- :xc_kernel_(xc_kernel), tpiba_(ucell->tpiba), spin_type_(st),
20- xc_kernel_components_ (*rho_basis)
17+ :xc_kernel_(xc_kernel), tpiba_(ucell.tpiba), spin_type_(st), rho_basis_(rho_basis), nrxx_(chg_gs.nrxx),
18+ nspin_ (PARAM.inp.nspin == 1 || (PARAM.inp.nspin == 4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z) ? 1 : 2),
19+ pot_hartree_(LR_Util::make_unique<elecstate::PotHartree>(&rho_basis)),
20+ xc_kernel_components_(rho_basis, ucell, chg_gs, pgrid, nspin_, xc_kernel, lr_init_xc_kernel), // call XC_Functional::set_func_type and libxc
21+ xc_type_(XCType(XC_Functional::get_func_type()))
2122 {
22- this ->rho_basis_ = rho_basis;
23- this ->nrxx = chg_gs->nrxx ;
24- this ->nspin = (PARAM.inp .nspin == 1 || (PARAM.inp .nspin == 4 && !PARAM.globalv .domag && !PARAM.globalv .domag_z )) ? 1 : 2 ;
25-
26- this ->pot_hartree = LR_Util::make_unique<elecstate::PotHartree>(this ->rho_basis_ );
27-
28- const std::set<std::string> local_xc = { " lda" , " pwlda" , " pbe" , " hse" };
29- if (local_xc.find (this ->xc_kernel_ ) != local_xc.end ())
30- {
31- XC_Functional::set_xc_type (this ->xc_kernel_ ); // for hse, (1-alpha) and omega are set here
32- this ->xc_type_ = XCType (XC_Functional::get_func_type ());
33- this ->set_integral_func (this ->spin_type_ , this ->xc_type_ );
34-
35- if (lr_init_xc_kernel[0 ] == " file" )
36- {
37- const std::set<std::string> lda_xc = { " lda" , " pwlda" };
38- assert (lda_xc.count (this ->xc_kernel_ ));
39- const int n_component = (1 == nspin) ? 1 : 3 ; // spin components of fxc: (uu, ud=du, dd) when nspin=2
40- this ->xc_kernel_components_ .v2rho2 .resize (n_component * nrxx);
41- // read fxc adn add to xc_kernel_components
42- assert (lr_init_xc_kernel.size () >= n_component + 1 );
43- for (int is = 0 ;is < n_component;++is)
44- {
45- double ef = 0.0 ;
46- int prenspin = 1 ;
47- std::vector<double > v2rho2_tmp (nrxx);
48- ModuleIO::read_vdata_palgrid (pgrid, GlobalV::MY_RANK, GlobalV::ofs_running, lr_init_xc_kernel[is + 1 ],
49- v2rho2_tmp.data (), ucell->nat );
50- for (int ir = 0 ;ir < nrxx;++ir) { xc_kernel_components_.v2rho2 [ir * n_component + is] = v2rho2_tmp[ir]; }
51- }
52- return ;
53- }
54-
55- #ifdef USE_LIBXC
56- if (lr_init_xc_kernel[0 ] == " from_chg_file" )
57- {
58- assert (lr_init_xc_kernel.size () >= 2 );
59- double ** rho_for_fxc;
60- LR_Util::_allocate_2order_nested_ptr (rho_for_fxc, nspin, nrxx);
61- double ef = 0.0 ;
62- int prenspin = 1 ;
63- for (int is = 0 ;is < nspin;++is)
64- {
65- const std::string file = lr_init_xc_kernel[lr_init_xc_kernel.size () > nspin ? 1 + is : 1 ];
66- ModuleIO::read_vdata_palgrid (pgrid, GlobalV::MY_RANK, GlobalV::ofs_running, file,
67- rho_for_fxc[is], ucell->nat );
68- }
69- this ->xc_kernel_components_ .f_xc_libxc (nspin, ucell->omega , ucell->tpiba , rho_for_fxc, chg_gs->rho_core );
70- LR_Util::_deallocate_2order_nested_ptr (rho_for_fxc, nspin);
71- }
72- else { this ->xc_kernel_components_ .f_xc_libxc (nspin, ucell->omega , ucell->tpiba , chg_gs->rho , chg_gs->rho_core ); }
73- #else
74- ModuleBase::WARNING_QUIT (" KernelXC" , " to calculate xc-kernel in LR-TDDFT, compile with LIBXC" );
75- #endif
76- }
23+ if (std::set<std::string>({ " lda" , " pwlda" , " pbe" , " hse" }).count (xc_kernel)) { this ->set_integral_func (this ->spin_type_ , this ->xc_type_ ); }
7724 }
7825
79- void PotHxcLR::cal_v_eff (double ** rho, const UnitCell* ucell, ModuleBase::matrix& v_eff, const std::vector<int >& ispin_op)
26+ void PotHxcLR::cal_v_eff (double ** rho, const UnitCell& ucell, ModuleBase::matrix& v_eff, const std::vector<int >& ispin_op)
8027 {
8128 ModuleBase::TITLE (" PotHxcLR" , " cal_v_eff" );
8229 ModuleBase::timer::tick (" PotHxcLR" , " cal_v_eff" );
@@ -86,10 +33,10 @@ namespace LR
8633 switch (this ->spin_type_ )
8734 {
8835 case SpinType::S1: case SpinType::S2_updown:
89- v_eff += elecstate::H_Hartree_pw::v_hartree (* ucell, const_cast <ModulePW::PW_Basis*>(this ->rho_basis_ ), 1 , rho);
36+ v_eff += elecstate::H_Hartree_pw::v_hartree (ucell, const_cast <ModulePW::PW_Basis*>(& this ->rho_basis_ ), 1 , rho);
9037 break ;
9138 case SpinType::S2_singlet:
92- v_eff += 2 * elecstate::H_Hartree_pw::v_hartree (* ucell, const_cast <ModulePW::PW_Basis*>(this ->rho_basis_ ), 1 , rho);
39+ v_eff += 2 * elecstate::H_Hartree_pw::v_hartree (ucell, const_cast <ModulePW::PW_Basis*>(& this ->rho_basis_ ), 1 , rho);
9340 break ;
9441 default :
9542 break ;
@@ -171,7 +118,7 @@ namespace LR
171118 // std::cout << std::endl;};
172119
173120 std::vector<ModuleBase::Vector3<double >> drho (nrxx); // transition density gradient
174- LR_Util::grad (rho, drho.data (), *( this ->rho_basis_ ) , this ->tpiba_ );
121+ LR_Util::grad (rho, drho.data (), this ->rho_basis_ , this ->tpiba_ );
175122
176123 std::vector<double > vxc_tmp (nrxx, 0.0 );
177124
@@ -183,7 +130,7 @@ namespace LR
183130 + fxc.v2sigma2_4drho .at (ir) * (fxc.drho_gs .at (ir) * drho.at (ir))
184131 + drho.at (ir) * fxc.vsigma .at (ir) * 2 .);
185132 }
186- XC_Functional::grad_dot (e_drho.data (), vxc_tmp.data (), this ->rho_basis_ , this ->tpiba_ );
133+ XC_Functional::grad_dot (e_drho.data (), vxc_tmp.data (), & this ->rho_basis_ , this ->tpiba_ );
187134
188135 // 2. $f^{\rho\rho}\rho_1+2f^{\rho\sigma}\nabla\rho\cdot\nabla\rho_1$
189136 for (int ir = 0 ;ir < nrxx;++ir)
0 commit comments