Skip to content

Commit 089cd55

Browse files
committed
separate H from dF/dC or dK/dC
1 parent 90d508c commit 089cd55

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

source/module_lr/Grad/esolver_lr_grad.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ std::vector<ModuleBase::matrix> LR::ESolver_LR<T, TR>::cal_force(const int ispin
128128
// seems because those two are classes having constructors
129129
// but `cal_edm_from_XZ_istate` here is a functions
130130
std::weak_ptr<PotHxcLR> pot_weak = this->pot[ispin];
131+
std::weak_ptr<PotHxcLR> pot_hxc_gs_weak = this->pot_hxc_gs;
131132
#ifdef __EXX
132133
std::weak_ptr<Exx_LRI<T>> exx_lri_weak = this->exx_lri;
133134
#endif
@@ -141,7 +142,8 @@ std::vector<ModuleBase::matrix> LR::ESolver_LR<T, TR>::cal_force(const int ispin
141142
#ifdef __EXX
142143
exx_lri_weak, this->exx_info.info_global.hybrid_alpha,
143144
#endif
144-
this->gint_, pot_weak, this->kv, this->gd, this->paraX_, this->paraC_, this->paraMat_,
145+
this->gint_, pot_weak, pot_hxc_gs_weak,
146+
this->kv, this->gd, this->paraX_, this->paraC_, this->paraMat_,
145147
has_local_xc(this->xc_kernel));
146148
elecstate::DensityMatrix<T, double> edm_real = LR_Util::build_dm_from_dmk<T, double>(edm_k,
147149
this->paraMat_, this->nk, this->kv.kvec_d, this->ucell, this->gd, this->orb_cutoff_);

source/module_lr/Grad/multipliers/cal_edm_from_multipliers.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ namespace LR
102102
// 2. edm of Z : $\sum_i \sum_a c_a epsilon_i Z_{ai} c_i
103103
std::vector<T> epsi_Z(px.get_local_size());
104104
multiply_eig_onto_vec(Z, eig_ks, px, epsi_Z.data());
105-
const std::vector<ct::Tensor> cZc = cal_dm_trans_pblas(Z, px, c, pc, naos, nocc, nvirt, pmat);
105+
std::vector<ct::Tensor> cZc = cal_dm_trans_pblas(Z, px, c, pc, naos, nocc, nvirt, pmat);
106+
std::for_each(cZc.begin(), cZc.end(), [&](ct::Tensor& s) { LR_Util::matsym(s.data<T>(), naos, pmat); });
106107

107108
//3. c * K_cvcx * c
108-
const std::vector<ct::Tensor> cKc = cal_dm_trans_pblas(K_cvcx, px, c, pc, naos, nocc, nvirt, pmat, (T)2.0);
109-
LR_Util::matsym(cKc[0].data<T>(), naos, pmat);
109+
std::vector<ct::Tensor> cKc = cal_dm_trans_pblas(K_cvcx, px, c, pc, naos, nocc, nvirt, pmat, (T)2.0);
110+
std::for_each(cKc.begin(), cKc.end(), [&](ct::Tensor& s) { LR_Util::matsym(s.data<T>(), naos, pmat); });
110111

111112
// 4. $\sum_i (\Omega + \epsilon_i) \sum_{ab} C_{\mu a} X_{ia} C_{\nu b} X_{ib}$
112113
const std::vector<ct::Tensor> edm = cal_edm_term4(X, eig_ext_istate, eig_ks, c, px, pc, pmat);
@@ -145,6 +146,7 @@ namespace LR
145146
#endif
146147
typename TGint<T>::type* gint,
147148
std::weak_ptr<PotHxcLR> pot,
149+
std::weak_ptr<PotHxcLR> pot_hxc_gs,
148150
const K_Vectors& kv,
149151
const Grid_Driver& gd,
150152
const std::vector<Parallel_2D>& px,
@@ -162,7 +164,7 @@ namespace LR
162164
#ifdef __EXX
163165
exx_lri, exx_alpha,
164166
#endif
165-
gint, pot, kv, px, pc, p_occ_occ, pmat, has_local_xc);
167+
gint, pot_hxc_gs, kv, px, pc, p_occ_occ, pmat, has_local_xc);
166168
std::cout << "W: " << std::endl;
167169
LR_Util::print_value(W.data(), nk, p_occ_occ[0].get_col_size(), p_occ_occ[0].get_row_size());
168170

source/module_lr/Grad/multipliers/cal_multiplier_w_from_z.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace LR
3636
{
3737
const int ga = px.local2global_row(la);
3838
const double weight = eig_ext_istate - eig_ks[eigks_start_k + nocc + ga];
39+
std::cout << "la=" << la << ", ks-eig=" << eig_ks[eigks_start_k + nocc + ga] << ", weight=" << weight << ", X2=" << X[x_start_k + la] << std::endl;
3940
for (int li = 0;li < px.get_col_size();++li)
4041
{
4142
const int idx = li * px.get_row_size() + la;

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,11 @@ void LR::ESolver_LR<T, TR>::set_X_initial_guess()
669669
template<typename T, typename TR>
670670
void LR::ESolver_LR<T, TR>::init_pot(const Charge& chg_gs)
671671
{
672+
using ST = PotHxcLR::SpinType;
672673
this->pot.resize(nspin, nullptr);
673674
if (this->input.ri_hartree_benchmark != "none") { return; } //no need to initialize potential for Hxc kernel in the RI-benchmark routine
674675
switch (nspin)
675676
{
676-
using ST = PotHxcLR::SpinType;
677677
case 1:
678678
this->pot[0] = std::make_shared<PotHxcLR>(xc_kernel, *this->pw_rho, ucell, chg_gs, Pgrid, ST::S1, input.lr_init_xc_kernel);
679679
break;
@@ -685,7 +685,12 @@ void LR::ESolver_LR<T, TR>::init_pot(const Charge& chg_gs)
685685
throw std::invalid_argument("ESolver_LR: nspin must be 1 or 2");
686686
}
687687
// ground-state potentials are needed for calculating the excited state force
688-
if (PARAM.inp.cal_force) { this->init_pot_groundstate(chg_gs); }
688+
if (PARAM.inp.cal_force)
689+
{
690+
this->init_pot_groundstate(chg_gs);
691+
const std::string xc_kernel_gs = LR_Util::tolower(input.dft_functional);
692+
this->pot_hxc_gs = std::make_shared<PotHxcLR>(xc_kernel_gs, *this->pw_rho, ucell, chg_gs, Pgrid, ST::S1, input.lr_init_xc_kernel);
693+
}
689694
}
690695

691696
template<typename T, typename TR>

source/module_lr/esolver_lrtd_lcao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace LR
7272
double etxc_gs = 0.;
7373
double vtxc_gs = 0.;
7474
ModuleBase::matrix wg_ks; /// occupation number of ground state
75+
std::shared_ptr<PotHxcLR> pot_hxc_gs; /// used in lr-grad, in the ground-state Hxc gradient term coming from dF/dC
7576

7677
/// @brief Excited state wavefunction (locc, lvirt are local size of nocc and nvirt in each process)
7778
/// size of X: [neq][{nstate, nloc_per_band}], namely:

0 commit comments

Comments
 (0)