Skip to content

Commit 80e64b2

Browse files
committed
restrict DM size within orb_rcut
1 parent e295015 commit 80e64b2

File tree

8 files changed

+55
-46
lines changed

8 files changed

+55
-46
lines changed

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ LR::ESolver_LR<T, TR>::ESolver_LR(ModuleESolver::ESolver_KS_LCAO<T, TR>&& ks_sol
219219
if (std::is_same<T, double>::value) { this->gint_g_ = std::move(ks_sol.GG); }
220220
else { this->gint_k_ = std::move(ks_sol.GK); }
221221
this->set_gint();
222+
this->gint_->reset_DMRGint(1);
222223

223224
// move pw basis
224225
delete this->pw_rho; // newed in ESolver_FP::ESolver_FP
@@ -349,7 +350,6 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
349350
PARAM.inp.test_atom_input);
350351
this->set_gint();
351352
this->gint_->gridt = &this->gt_;
352-
this->gint_->reset_DMRGint(1);
353353

354354
// (3) Periodic condition search for each grid.
355355
double dr_uniform = 0.001;
@@ -505,7 +505,7 @@ void LR::ESolver_LR<T, TR>::after_all_runners()
505505
//cal spectrum
506506
std::vector<double> freq(100);
507507
std::vector<double> abs_wavelen_range({ 20, 200 });//default range
508-
if (input.abs_wavelen_range.size() == 2 && std::abs(input.abs_wavelen_range[1] - input.abs_wavelen_range[0]) > 0.02)
508+
if (input.abs_wavelen_range.size() >= 2 && std::abs(input.abs_wavelen_range[1] - input.abs_wavelen_range[0]) > 0.02)
509509
{
510510
abs_wavelen_range = input.abs_wavelen_range;
511511
}
@@ -516,7 +516,8 @@ void LR::ESolver_LR<T, TR>::after_all_runners()
516516
for (int is = 0;is < this->X.size();++is)
517517
{
518518
LR_Spectrum<T> spectrum(nspin, this->nbasis, this->nocc, this->nvirt, this->gint_, *this->pw_rho, *this->psi_ks,
519-
this->ucell, this->kv, this->paraX_, this->paraC_, this->paraMat_,
519+
this->ucell, this->kv, GlobalC::GridD, this->orb_cutoff_,
520+
this->paraX_, this->paraC_, this->paraMat_,
520521
&this->pelec->ekb.c[is * nstates], this->X[is].template data<T>(), nstates, openshell);
521522
spectrum.transition_analysis(spin_types[is]);
522523
spectrum.optical_absorption(freq, input.abs_broadening, spin_types[is]);

source/module_lr/hamilt_casida.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ namespace LR
4646
if (ri_hartree_benchmark != "aims") { assert(aims_nbasis.empty()); }
4747
// always use nspin=1 for transition density matrix
4848
this->DM_trans = LR_Util::make_unique<elecstate::DensityMatrix<T, T>>(&pmat_in, 1, kv_in.kvec_d, nk);
49-
this->DM_trans->init_DMR(&gd_in, &ucell_in);
49+
LR_Util::initialize_DMR(*this->DM_trans, pmat_in, ucell_in, gd_in, orb_cutoff);
50+
// this->DM_trans->init_DMR(&gd_in, &ucell_in); // too large due to not restricted by orb_cutoff
5051

5152
// add the diag operator (the first one)
5253
this->ops = new OperatorLRDiag<T>(eig_ks.c, pX[0], nk, nocc[0], nvirt[0]);

source/module_lr/hamilt_ulr.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ namespace LR
4040
{
4141
ModuleBase::TITLE("HamiltULR", "HamiltULR");
4242
this->DM_trans = LR_Util::make_unique<elecstate::DensityMatrix<T, T>>(&pmat_in, 1, kv_in.kvec_d, nk);
43-
this->DM_trans->init_DMR(&gd_in, &ucell_in);
44-
45-
// how to change the index of eig_ks and psi_ks_In?
46-
// modify the interface of opetators to support different left- and right- spin-pairs
47-
43+
LR_Util::initialize_DMR(*this->DM_trans, pmat_in, ucell_in, gd_in, orb_cutoff);
44+
// this->DM_trans->init_DMR(&gd_in, &ucell_in); // too large due to not restricted by orb_cutoff
4845
this->ops.resize(4);
4946

5047
this->ops[0] = new OperatorLRDiag<T>(eig_ks.c, pX_in[0], nk, nocc[0], nvirt[0]);

source/module_lr/lr_spectrum.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ inline void check_sum_rule(const double& osc_tot)
2424
}
2525

2626
template<>
27-
void LR::LR_Spectrum<double>::oscillator_strength()
27+
void LR::LR_Spectrum<double>::oscillator_strength(Grid_Driver& gd, const std::vector<double>& orb_cutoff)
2828
{
2929
ModuleBase::TITLE("LR::LR_Spectrum", "oscillator_strength");
3030
std::vector<double>& osc = this->oscillator_strength_; // unit: Ry
3131
osc.resize(nstate, 0.0);
3232
double osc_tot = 0.0;
3333
elecstate::DensityMatrix<double, double> DM_trans(&this->pmat, 1, this->kv.kvec_d, this->nk);
34-
DM_trans.init_DMR(&GlobalC::GridD, &this->ucell);
34+
LR_Util::initialize_DMR(DM_trans, this->pmat, this->ucell, gd, orb_cutoff);
3535
this->transition_dipole_.resize(nstate, ModuleBase::Vector3<double>(0.0, 0.0, 0.0));
3636
for (int istate = 0;istate < nstate;++istate)
3737
{
@@ -80,16 +80,16 @@ void LR::LR_Spectrum<double>::oscillator_strength()
8080
}
8181

8282
template<>
83-
void LR::LR_Spectrum<std::complex<double>>::oscillator_strength()
83+
void LR::LR_Spectrum<std::complex<double>>::oscillator_strength(Grid_Driver& gd, const std::vector<double>& orb_cutoff)
8484
{
8585
ModuleBase::TITLE("LR::LR_Spectrum", "oscillator_strength");
8686
std::vector<double>& osc = this->oscillator_strength_; // unit: Ry
8787
osc.resize(nstate, 0.0);
8888
double osc_tot = 0.0;
8989
elecstate::DensityMatrix<std::complex<double>, std::complex<double>> DM_trans(&this->pmat, 1, this->kv.kvec_d, this->nk);
90-
DM_trans.init_DMR(&GlobalC::GridD, &this->ucell);
90+
LR_Util::initialize_DMR(DM_trans, this->pmat, this->ucell, gd, orb_cutoff);
9191
elecstate::DensityMatrix<std::complex<double>, double> DM_trans_real_imag(&this->pmat, 1, this->kv.kvec_d, this->nk);
92-
DM_trans_real_imag.init_DMR(&GlobalC::GridD, &this->ucell);
92+
LR_Util::initialize_DMR(DM_trans_real_imag, this->pmat, this->ucell, gd, orb_cutoff);
9393

9494
this->transition_dipole_.resize(nstate, ModuleBase::Vector3<std::complex<double>>(0.0, 0.0, 0.0));
9595
for (int istate = 0;istate < nstate;++istate)

source/module_lr/lr_spectrum.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace LR
1212
public:
1313
LR_Spectrum(const int& nspin_global, const int& naos, const std::vector<int>& nocc, const std::vector<int>& nvirt,
1414
typename TGint<T>::type* gint, const ModulePW::PW_Basis& rho_basis, psi::Psi<T>& psi_ks_in,
15-
const UnitCell& ucell, const K_Vectors& kv_in, const std::vector<Parallel_2D>& pX_in, const Parallel_2D& pc_in, const Parallel_Orbitals& pmat_in,
15+
const UnitCell& ucell, const K_Vectors& kv_in, Grid_Driver& gd, const std::vector<double>& orb_cutoff,
16+
const std::vector<Parallel_2D>& pX_in, const Parallel_2D& pc_in, const Parallel_Orbitals& pmat_in,
1617
const double* eig, const T* X, const int& nstate, const bool& openshell) :
1718
nspin_x(openshell ? 2 : 1), naos(naos), nocc(nocc), nvirt(nvirt), nk(kv_in.get_nks() / nspin_global),
1819
gint(gint), rho_basis(rho_basis), ucell(ucell), kv(kv_in),
@@ -22,15 +23,15 @@ namespace LR
2223
gdim(nk* std::inner_product(nocc.begin(), nocc.end(), nvirt.begin(), 0))
2324
{
2425
for (int is = 0;is < nspin_global;++is) { psi_ks.emplace_back(LR_Util::get_psi_spin(psi_ks_in, is, nk)); }
25-
this->oscillator_strength();
26+
this->oscillator_strength(gd, orb_cutoff);
2627
};
2728
/// @brief calculate the optical absorption spectrum
2829
void optical_absorption(const std::vector<double>& freq, const double eta, const std::string& spintype);
2930
/// @brief print out the transition dipole moment and the main contributions to the transition amplitude
3031
void transition_analysis(const std::string& spintype);
3132
private:
3233
/// $$2/3\Omega\sum_{ia\sigma} |\braket{\psi_{i}|\mathbf{r}|\psi_{a}} |^2\int \rho_{\alpha\beta}(\mathbf{r}) \mathbf{r} d\mathbf{r}$$
33-
void oscillator_strength();
34+
void oscillator_strength(Grid_Driver& gd, const std::vector<double>& orb_cutoff);
3435
const int nspin_x = 1; ///< 1 for singlet/triplet, 2 for updown(openshell)
3536
const int naos = 1;
3637
const std::vector<int>& nocc;

source/module_lr/operator_casida/operator_lr_hxc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace LR
9494
elecstate::DensityMatrix<std::complex<double>, double> DM_trans_real_imag(&pmat, 1, kv.kvec_d, kv.get_nks() / nspin);
9595
DM_trans_real_imag.init_DMR(*this->hR);
9696
hamilt::HContainer<double> HR_real_imag(GlobalC::ucell, &this->pmat);
97-
this->initialize_HR(HR_real_imag, ucell, gd);
97+
LR_Util::initialize_HR<std::complex<double>, double>(HR_real_imag, ucell, gd, orb_cutoff_);
9898

9999
auto dmR_to_hR = [&, this](const char& type) -> void
100100
{

source/module_lr/operator_casida/operator_lr_hxc.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ namespace LR
4040
this->cal_type = hamilt::calculation_type::lcao_gint;
4141
this->is_first_node = true;
4242
this->hR = std::unique_ptr<hamilt::HContainer<T>>(new hamilt::HContainer<T>(&pmat_in));
43-
this->initialize_HR(*this->hR, ucell_in, gd_in);
43+
LR_Util::initialize_HR<T, T>(*this->hR, ucell_in, gd_in, orb_cutoff);
44+
assert(&pmat_in == this->hR->get_paraV());
4445
};
4546
~OperatorLRHxc() { };
4647

@@ -49,33 +50,6 @@ namespace LR
4950
virtual void act(const int nbands, const int nbasis, const int npol, const T* psi_in, T* hpsi, const int ngk_ik = 0)const override;
5051

5152
private:
52-
template<typename TR> //T=double, TR=double; T=std::complex<double>, TR=std::complex<double>/double
53-
void initialize_HR(hamilt::HContainer<TR>& hR, const UnitCell& ucell, Grid_Driver& gd) const
54-
{
55-
for (int iat1 = 0; iat1 < ucell.nat; iat1++)
56-
{
57-
auto tau1 = ucell.get_tau(iat1);
58-
int T1, I1;
59-
ucell.iat2iait(iat1, &I1, &T1);
60-
AdjacentAtomInfo adjs;
61-
gd.Find_atom(ucell, tau1, T1, I1, &adjs);
62-
for (int ad = 0; ad < adjs.adj_num + 1; ++ad)
63-
{
64-
const int T2 = adjs.ntype[ad];
65-
const int I2 = adjs.natom[ad];
66-
int iat2 = this->ucell.itia2iat(T2, I2);
67-
if (pmat.get_row_size(iat1) <= 0 || pmat.get_col_size(iat2) <= 0) { continue; }
68-
const ModuleBase::Vector3<int>& R_index = adjs.box[ad];
69-
if (ucell.cal_dtau(iat1, iat2, R_index).norm() * this->ucell.lat0 >= orb_cutoff_[T1] + orb_cutoff_[T2]) { continue; }
70-
hamilt::AtomPair<TR> tmp(iat1, iat2, R_index.x, R_index.y, R_index.z, &pmat);
71-
hR.insert_pair(tmp);
72-
}
73-
}
74-
hR.allocate(nullptr, true);
75-
hR.set_paraV(&pmat);
76-
if (std::is_same<T, double>::value) { hR.fix_gamma(); }
77-
}
78-
7953
void grid_calculation(const int& nbands)const;
8054

8155
//global sizes

source/module_lr/utils/lr_util_hcontainer.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,39 @@ namespace LR_Util
4444
hamilt::HContainer<std::complex<double>>& HR,
4545
const int& nat,
4646
const char& type = 'R');
47+
48+
template<typename T, typename TR>
49+
void initialize_HR(hamilt::HContainer<TR>& hR, const UnitCell& ucell, Grid_Driver& gd, const std::vector<double>& orb_cutoff)
50+
{
51+
const auto& pmat = *hR.get_paraV();
52+
for (int iat1 = 0; iat1 < ucell.nat; iat1++)
53+
{
54+
auto tau1 = ucell.get_tau(iat1);
55+
int T1, I1;
56+
ucell.iat2iait(iat1, &I1, &T1);
57+
AdjacentAtomInfo adjs;
58+
gd.Find_atom(ucell, tau1, T1, I1, &adjs);
59+
for (int ad = 0; ad < adjs.adj_num + 1; ++ad)
60+
{
61+
const int T2 = adjs.ntype[ad];
62+
const int I2 = adjs.natom[ad];
63+
int iat2 = ucell.itia2iat(T2, I2);
64+
if (pmat.get_row_size(iat1) <= 0 || pmat.get_col_size(iat2) <= 0) { continue; }
65+
const ModuleBase::Vector3<int>& R_index = adjs.box[ad];
66+
if (ucell.cal_dtau(iat1, iat2, R_index).norm() * ucell.lat0 >= orb_cutoff[T1] + orb_cutoff[T2]) { continue; }
67+
hamilt::AtomPair<TR> tmp(iat1, iat2, R_index.x, R_index.y, R_index.z, &pmat);
68+
hR.insert_pair(tmp);
69+
}
70+
}
71+
hR.allocate(nullptr, true);
72+
// hR.set_paraV(&pmat);
73+
if (std::is_same<T, double>::value) { hR.fix_gamma(); }
74+
}
75+
template<typename T, typename TR>
76+
void initialize_DMR(elecstate::DensityMatrix<T, TR>& dm, const Parallel_Orbitals& pmat, const UnitCell& ucell, Grid_Driver& gd, const std::vector<double>& orb_cutoff)
77+
{
78+
hamilt::HContainer<TR> hR_tmp(&pmat);
79+
initialize_HR<T, TR>(hR_tmp, ucell, gd, orb_cutoff);
80+
dm.init_DMR(hR_tmp);
81+
}
4782
}

0 commit comments

Comments
 (0)