|
6 | 6 | #include "module_hamilt_general/module_xc/xc_functional.h" |
7 | 7 | #include <set> |
8 | 8 | #include "module_lr/utils/lr_util.h" |
9 | | - |
| 9 | +#include "module_io/cube_io.h" |
| 10 | +#include "module_hamilt_pw/hamilt_pwdft/global.h" // tmp, for pgrid |
10 | 11 | #define FXC_PARA_TYPE const double* const rho, ModuleBase::matrix& v_eff, const std::vector<int>& ispin_op = { 0,0 } |
11 | 12 | namespace LR |
12 | 13 | { |
13 | 14 | // constructor for exchange-correlation kernel |
14 | 15 | PotHxcLR::PotHxcLR(const std::string& xc_kernel_in, const ModulePW::PW_Basis* rho_basis_in, const UnitCell* ucell_in, |
15 | | - const Charge* chg_gs/*ground state*/, const SpinType& st_in) |
16 | | - :xc_kernel(xc_kernel_in), tpiba_(ucell_in->tpiba), spin_type_(st_in) |
| 16 | + const Charge* chg_gs/*ground state*/, const Parallel_Grid& pgrid, |
| 17 | + const SpinType& st_in, const std::vector<std::string>& init_fxc) |
| 18 | + :xc_kernel(xc_kernel_in), tpiba_(ucell_in->tpiba), spin_type_(st_in), |
| 19 | + xc_kernel_components_(*rho_basis_in) |
17 | 20 | { |
18 | 21 | this->rho_basis_ = rho_basis_in; |
19 | 22 | this->nrxx = chg_gs->nrxx; |
20 | 23 | this->nspin = (PARAM.inp.nspin == 1 || (PARAM.inp.nspin == 4 && !PARAM.globalv.domag && !PARAM.globalv.domag_z)) ? 1 : 2; |
21 | 24 |
|
22 | 25 | this->pot_hartree = LR_Util::make_unique<elecstate::PotHartree>(this->rho_basis_); |
| 26 | + |
23 | 27 | std::set<std::string> local_xc = { "lda", "pbe", "hse" }; |
24 | 28 | if (local_xc.find(this->xc_kernel) != local_xc.end()) |
25 | 29 | { |
26 | 30 | XC_Functional::set_xc_type(this->xc_kernel); // for hse, (1-alpha) and omega are set here |
27 | 31 | this->xc_type_ = XCType(XC_Functional::get_func_type()); |
28 | | -#ifdef USE_LIBXC |
29 | 32 | this->set_integral_func(this->spin_type_, this->xc_type_); |
30 | | - this->xc_kernel_components_.f_xc_libxc(nspin, ucell_in->omega, ucell_in->tpiba, chg_gs); |
| 33 | + |
| 34 | + if (init_fxc[0] == "file_fxc") |
| 35 | + { |
| 36 | + assert(this->xc_kernel == "lda"); |
| 37 | + const int spinsize = (1 == nspin) ? 1 : 3; |
| 38 | + std::vector<double> v2rho2(spinsize * nrxx); |
| 39 | + // read fxc adn add to xc_kernel_components |
| 40 | + assert(init_fxc.size() >= spinsize + 1); |
| 41 | + for (int is = 0;is < spinsize;++is) |
| 42 | + { |
| 43 | + double ef = 0.0; |
| 44 | + int prenspin = 1; |
| 45 | + std::vector<double> v2rho2_tmp(nrxx); |
| 46 | + ModuleIO::read_vdata_palgrid(GlobalC::Pgrid, GlobalV::MY_RANK, GlobalV::ofs_running, init_fxc[is + 1], |
| 47 | + v2rho2_tmp.data(), ucell_in->nat); |
| 48 | + for (int ir = 0;ir < nrxx;++ir) { v2rho2[ir * spinsize + is] = v2rho2_tmp[ir]; } |
| 49 | + } |
| 50 | + this->xc_kernel_components_.set_kernel("v2rho2", std::move(v2rho2)); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | +#ifdef USE_LIBXC |
| 55 | + if (init_fxc[0] == "file_chg") |
| 56 | + { |
| 57 | + assert(init_fxc.size() >= 2); |
| 58 | + double** rho_for_fxc; |
| 59 | + LR_Util::new_p2(rho_for_fxc, nspin, nrxx); |
| 60 | + double ef = 0.0; |
| 61 | + int prenspin = 1; |
| 62 | + for (int is = 0;is < nspin;++is) |
| 63 | + { |
| 64 | + const std::string file = init_fxc[init_fxc.size() > nspin ? 1 + is : 1]; |
| 65 | + ModuleIO::read_vdata_palgrid(pgrid, GlobalV::MY_RANK, GlobalV::ofs_running, file, |
| 66 | + rho_for_fxc[is], ucell_in->nat); |
| 67 | + } |
| 68 | + this->xc_kernel_components_.f_xc_libxc(nspin, ucell_in->omega, ucell_in->tpiba, rho_for_fxc, chg_gs->rho_core); |
| 69 | + LR_Util::delete_p2(rho_for_fxc, nspin); |
| 70 | + } |
| 71 | + else { this->xc_kernel_components_.f_xc_libxc(nspin, ucell_in->omega, ucell_in->tpiba, chg_gs->rho, chg_gs->rho_core); } |
31 | 72 | #else |
32 | 73 | ModuleBase::WARNING_QUIT("KernelXC", "to calculate xc-kernel in LR-TDDFT, compile with LIBXC"); |
33 | 74 | #endif |
@@ -63,7 +104,6 @@ namespace LR |
63 | 104 | ModuleBase::timer::tick("PotHxcLR", "cal_v_eff"); |
64 | 105 | } |
65 | 106 |
|
66 | | -#ifdef USE_LIBXC |
67 | 107 | void PotHxcLR::set_integral_func(const SpinType& s, const XCType& xc) |
68 | 108 | { |
69 | 109 | auto& funcs = this->kernel_to_potential_; |
@@ -168,5 +208,4 @@ namespace LR |
168 | 208 | + " unfinished in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); |
169 | 209 | } |
170 | 210 | } |
171 | | -#endif |
172 | 211 | } // namespace LR |
0 commit comments