Skip to content

Commit 8355d80

Browse files
committed
fix RHS of Z-eq
1 parent 0551689 commit 8355d80

File tree

8 files changed

+25
-12
lines changed

8 files changed

+25
-12
lines changed

source/module_hamilt_general/operator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ enum class calculation_type
2727
lcao_dftu,
2828
lcao_sc_lambda,
2929
lcao_tddft_velocity,
30+
lr_dmtrans_vo,
31+
lr_dmdiff_vo
3032
};
3133

3234
// Basic class for operator module,

source/module_lr/Grad/force/lr_force.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ namespace LR
3232
const Charge chr_diff_relaxed = dm_to_charge(relax_diff_dm);
3333

3434
// 1. local pp (Hellmann-Feynman)(fvl_dvl) + ewald + core correction (+ self-consistent charge)
35-
ModuleBase::matrix f_pw = ForcePWTerms<double>()(this->ucell_, chr_diff_relaxed, this->rhopw_, this->locpp_, this->sf_, with_ewald);
35+
ModuleBase::matrix f_pw = PARAM.inp.vl_in_h ?
36+
ForcePWTerms<double>()(this->ucell_, chr_diff_relaxed, this->rhopw_, this->locpp_, this->sf_, with_ewald) :
37+
ModuleBase::matrix(this->ucell_.nat, 3);
3638

3739
// 2. nonlocal pp (Hellmann-Feynman + Pulay)
3840
ModuleBase::matrix fvnl = cal_force_nonlocal(this->ucell_, this->kvec_d_, this->gd_, this->two_center_bundle_, relax_diff_dm);

source/module_lr/Grad/multipliers/hamilt_zeq_left.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace LR
4646
// 1. $2\sum_bX_{ib}K_{ab}[D^X]-2\sum_jX_{ja}K_{ij}[D^X]$
4747
this->ops = new OperatorLRDiag<T>(eig_ks.c, pX[0], kv.get_nks() / nspin, nocc[0], nvirt[0]);
4848
// 2. $H_{ia}[D^Z]$, equals to $2K_{ab}[D^Z]$ when $D^Z$ is symmetrized
49-
OperatorLRHxc<T>* op_hz = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
49+
hamilt::Operator<T>* op_hz = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
5050
*this->DM_trans, gint, pot_hxc_gs, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
5151
{ 0 }, 2.0, ATYPE::CC_vo);
5252
this->ops->add(op_hz);

source/module_lr/Grad/multipliers/hamilt_zeq_right.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ namespace LR
5151
*this->DM_trans, gint, pot, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
5252
{ 0 }, -2.0, ATYPE::CXC);
5353
// 2. $H_{ia}[T]$, equals to $2K_{ab}[T]$ when $T$ is symmetrized
54-
OperatorLRHxc<T>* op_ht = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
54+
hamilt::Operator<T>* op_ht = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
5555
*this->DM_diff, gint, pot_hxc_gs, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
56-
{ 0 }, T(-2.0), ATYPE::CC_vo);
56+
{ 0 }, T(-2.0), ATYPE::CC_vo, hamilt::calculation_type::lr_dmdiff_vo);
5757
this->ops->add(op_ht);
5858
// 3. $2\sum_{jb,kc} g^{xc}_{ia, jb, kc}X_{jb}X_{kc}$
5959
this->pot_grad = std::make_shared<PotGradXCLR>(pot.lock()->xc_kernel_components, pot.lock()->get_rho_basis(), ucell, pot.lock()->nrxx);
60-
OperatorLRHxc<T>* op_gxc = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
60+
// !!op_gxc has some bug
61+
hamilt::Operator<T>* op_gxc = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks,
6162
*this->DM_trans, gint, this->pot_grad, ucell, orb_cutoff, gd, kv, pX, pc, pmat,
62-
{ 0 }, T(-2.0), ATYPE::CC_vo);
63+
{ 0 }, T(-2.0), ATYPE::CC_vo, hamilt::calculation_type::lr_dmtrans_vo);
64+
assert(op_gxc != nullptr);
65+
std::cout << "op_gxc=" << op_ht << std::endl;
6366
this->ops->add(op_gxc);
6467
// // test: op_ht only
6568
// delete this->ops;
@@ -87,8 +90,10 @@ namespace LR
8790
const auto psi_ks_is = LR_Util::get_psi_spin(psi_ks, is, this->nk);
8891
#ifdef __MPI
8992
std::vector<ct::Tensor> dm_diff_2d = cal_dm_diff_pblas(X, this->pX[is], psi_ks_is, pc, naos, nocc[is], nvirt[is], pmat);
93+
for (auto& t : dm_diff_2d) LR_Util::matsym(t.data<T>(), naos, pmat);
9094
#else
9195
std::vector<ct::Tensor> dm_diff_2d = cal_dm_diff_blas(X, psi_ks_is, naos, nocc[is], nvirt[is]);
96+
for (auto& t : dm_diff_2d) LR_Util::matsym(t.data<T>(), naos);
9297
#endif
9398
for (int ik = 0;ik < this->nk;++ik) { this->DM_diff->set_DMK_pointer(ik, dm_diff_2d[ik].data<T>()); }
9499
// std::cout << "difference density matrix" << std::endl;
@@ -103,7 +108,7 @@ namespace LR
103108
for (int ib = 0;ib < nband;++ib)
104109
{
105110
const int offset = ib * ld_psi;
106-
// this->cal_dm_trans(0, psi + offset); // transition density matrix, only for test
111+
this->cal_dm_trans(0, psi + offset); // transition density matrix, only for test
107112
this->cal_dm_diff(0, psi + offset); // difference density matrix
108113
hamilt::Operator<T>* node(this->ops);
109114
while (node != nullptr)

source/module_lr/Grad/multipliers/zeq_solver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace LR
100100
#endif
101101
gint, pot, pot_hxc_gs, kv, px, pc, pmat, spin_type);
102102
ModuleBase::timer::tick("Z_vector", "Z_vector_R");
103-
ops_R.hPsi(X, R.data<T>(), nk * px[0].get_local_size(), nstates); // act each operators on X
103+
ops_R.hPsi(X, R.data<T>(), nloc_per_band, nstates); // act each operators on X
104104
ModuleBase::timer::tick("Z_vector", "Z_vector_R");
105105

106106
// 2. the left-hand side of Z-vector equation

source/module_lr/hamilt_casida.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace LR
9494
else
9595
#endif
9696
{
97-
OperatorLRHxc<T>* lr_hxc = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks_in,
97+
hamilt::Operator<T>* lr_hxc = new OperatorLRHxc<T>(nspin, naos, nocc, nvirt, psi_ks_in,
9898
*this->DM_trans, gint_in, pot_in, ucell_in, orb_cutoff, gd_in, kv_in, pX_in, pc_in, pmat_in);
9999
this->ops->add(lr_hxc);
100100
}

source/module_lr/operator_casida/operator_lr_hxc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ namespace LR
3939
const Parallel_Orbitals& pmat_in,
4040
const std::vector<int>& ispin_ks = { 0 },
4141
const T factor_in = (T)1.0,
42-
const MO_TO_AO_TYPE dm_pq_in = MO_TO_AO_TYPE::CC_vo)
43-
: nspin(nspin), naos(naos), nocc(nocc), nvirt(nvirt), nk(kv_in.get_nks() / nspin), psi_ks(psi_ks_in),
42+
const MO_TO_AO_TYPE dm_pq_in = MO_TO_AO_TYPE::CC_vo,
43+
const hamilt::calculation_type cal_type_in = hamilt::calculation_type::lcao_gint)
44+
: nspin(nspin), naos(naos), nocc(nocc), nvirt(nvirt), nk(kv_in.get_nks() / nspin), psi_ks(psi_ks_in),
4445
DM_trans(DM_trans_in), gint(gint_in), pot(pot_in), ucell(ucell_in), orb_cutoff_(orb_cutoff), gd(gd_in),
4546
kv(kv_in), pX(pX_in), pc(pc_in), pmat(pmat_in), ispin_ks(ispin_ks),
4647
factor_(factor_in), dm_pq_(dm_pq_in)
4748
{
4849
ModuleBase::TITLE("OperatorLRHxc", "OperatorLRHxc");
49-
this->cal_type = hamilt::calculation_type::lcao_gint;
50+
this->cal_type = cal_type_in;
5051
this->is_first_node = true;
5152
this->hR = std::unique_ptr<hamilt::HContainer<T>>(new hamilt::HContainer<T>(&pmat_in));
5253
LR_Util::initialize_HR<T, T>(*this->hR, ucell_in, gd_in, orb_cutoff);

source/module_lr/utils/lr_util_hcontainer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ATen/core/tensor.h>
77
#include "module_parameter/parameter.h"
88
#include "module_io/single_R_io.h"
9+
#include "module_lr/utils/lr_util.h"
910
namespace LR_Util
1011
{
1112
template <typename T>
@@ -186,6 +187,8 @@ namespace LR_Util
186187
initialize_DMR(dm, pmat, ucell, gd, orb_cutoff);
187188
for (int ik = 0; ik < nk; ++ik)
188189
{
190+
// symmetrize
191+
LR_Util::matsym(dmk[ik].data<TK>(), pmat.get_global_row_size(), pmat);
189192
dm.set_DMK_pointer(ik, dmk[ik].data<TK>());
190193
}
191194
if (cal_dmr) { dm.cal_DMR(); }

0 commit comments

Comments
 (0)