Skip to content

Commit b5a5068

Browse files
authored
Fix: optimize lr_spectrum (#5805)
* update the broadening function in lr_spectrum * optimize transition analysis and fix norm bug
1 parent 35fe565 commit b5a5068

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void LR::ESolver_LR<T, TR>::after_all_runners(UnitCell& ucell)
568568
{
569569
spectrum.optical_absorption_method1(freq, input.abs_broadening);
570570
// =============================================== for test ====================================================
571-
// spectrum.optical_absorption_method2(freq, input.abs_broadening, spin_types[is]);
571+
// spectrum.optical_absorption_method2(freq, input.abs_broadening);
572572
// spectrum.test_transition_dipoles_velocity_ks(eig_ks.c);
573573
// spectrum.write_transition_dipole(PARAM.globalv.global_out_dir + "dipole_velocity_ks.dat");
574574
// =============================================== for test ====================================================

source/module_lr/lr_spectrum.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ template<> double LR::LR_Spectrum<double>::cal_mean_squared_dipole(ModuleBase::V
148148
}
149149
template<> double LR::LR_Spectrum<std::complex<double>>::cal_mean_squared_dipole(ModuleBase::Vector3<std::complex<double>> dipole)
150150
{
151-
return dipole.norm2().real() / 3.;
151+
// return dipole.norm2().real() / 3.; // ModuleBase::Vector3::norm2 calculates x*x + y*y + z*z, but here we need x*x.conj() + y*y.conj() + z*z.conj()
152+
return (std::norm(dipole.x) + std::norm(dipole.y) + std::norm(dipole.z)) / 3.;
152153
}
153154

154155
template<typename T>
@@ -217,12 +218,12 @@ void LR::LR_Spectrum<T>::transition_analysis(const std::string& spintype)
217218
ofs << std::setw(40) << spintype << std::endl;
218219
ofs << "==================================================================== " << std::endl;
219220
ofs << std::setw(8) << "State" << std::setw(30) << "Excitation Energy (Ry, eV)" <<
220-
std::setw(45) << "Transition dipole x, y, z (a.u.)" << std::setw(30) << "Oscillator strength(a.u.)" << std::endl;
221+
std::setw(90) << "Transition dipole x, y, z (a.u.)" << std::setw(30) << "Oscillator strength(a.u.)" << std::endl;
221222
ofs << "------------------------------------------------------------------------------------ " << std::endl;
222223
for (int istate = 0;istate < nstate;++istate)
223224
ofs << std::setw(8) << istate << std::setw(15) << std::setprecision(6) << eig[istate] << std::setw(15) << eig[istate] * ModuleBase::Ry_to_eV
224-
<< std::setw(15) << transition_dipole_[istate].x << std::setw(15) << transition_dipole_[istate].y << std::setw(15) << transition_dipole_[istate].z
225-
<< std::setw(30) << oscillator_strength_[istate] << std::endl;
225+
<< std::setprecision(4) << std::setw(30) << transition_dipole_[istate].x << std::setw(30) << transition_dipole_[istate].y << std::setw(30) << transition_dipole_[istate].z
226+
<< std::setprecision(6) << std::setw(30) << oscillator_strength_[istate] << std::endl;
226227
ofs << "------------------------------------------------------------------------------------ " << std::endl;
227228
ofs << std::setw(8) << "State" << std::setw(20) << "Occupied orbital"
228229
<< std::setw(20) << "Virtual orbital" << std::setw(30) << "Excitation amplitude"

source/module_lr/lr_spectrum_velocity.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ namespace LR
2323
return vR;
2424
}
2525

26-
inline double lorentz_delta(const double freq_diff, const double eta)
26+
inline double lorentz_delta(const double dfreq_au, const double eta_au)
2727
{
28-
return eta / (freq_diff * freq_diff + eta * eta) / M_PI;
28+
return eta_au / (dfreq_au * dfreq_au + eta_au * eta_au) / M_PI;
29+
}
30+
inline double gauss_delta(const double dfreq_au, const double eta_au)
31+
{
32+
const double c = eta_au / std::sqrt(2. * std::log(2.));
33+
return std::exp(-dfreq_au * dfreq_au / (2 * c * c)) / (std::sqrt(2 * M_PI) * c);
2934
}
3035

3136
template<typename T> inline ModuleBase::Vector3<T> convert_vector_to_vector3(const std::vector<std::complex<double>>& vec);
@@ -109,13 +114,13 @@ namespace LR
109114
// 4*pi^2/V * mean_squared_dipole *delta(w-Omega_S)
110115
std::ofstream ofs(PARAM.globalv.global_out_dir + "absorption.dat");
111116
if (GlobalV::MY_RANK == 0) { ofs << "Frequency (eV) | wave length(nm) | Absorption (a.u.)" << std::endl; }
112-
const double fac = 4 * M_PI * M_PI / ucell.omega * ModuleBase::e2 / this->nk; // e2: Ry to Hartree in the denominator
117+
const double fac = 4 * M_PI * M_PI / ucell.omega / this->nk;
113118
for (int f = 0;f < freq.size();++f)
114119
{
115120
double abs_value = 0.0;
116121
for (int i = 0;i < nstate;++i)
117122
{
118-
abs_value += this->mean_squared_transition_dipole_[i] * lorentz_delta((freq[f] - eig[i]), eta);
123+
abs_value += this->mean_squared_transition_dipole_[i] * lorentz_delta((freq[f] - eig[i]) / ModuleBase::e2, eta / ModuleBase::e2); // e2: Ry to Hartree
119124
}
120125
abs_value *= fac;
121126
if (GlobalV::MY_RANK == 0) { ofs << freq[f] * ModuleBase::Ry_to_eV << "\t" << 91.126664 / freq[f] << "\t" << abs_value << std::endl; }

0 commit comments

Comments
 (0)