Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/source_io/module_ctrl/ctrl_output_td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void ctrl_output_td(const UnitCell& ucell,
}
else if (TD_info::out_current == 2)
{
ModuleIO::write_current(ucell, grid, istep, psi, pelec, kv, pv, orb, td_p, p_hamilt->getSR(), p_hamilt->getHR(), exx_nao, exx_info);
const hamilt::HContainer<TR>* sR = p_hamilt->getSR();
const std::vector<hamilt::HContainer<TR>*> spin_hR = p_hamilt->getHR_vector();
Comment thread
memii-x marked this conversation as resolved.
Resolved
ModuleIO::write_current(ucell, grid, istep, psi, pelec, kv, pv, orb, td_p, sR, spin_hR, exx_nao, exx_info);
}
#endif // __LCAO
}
Expand Down
6 changes: 3 additions & 3 deletions source/source_io/module_current/td_current_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void write_current(
const LCAO_Orbitals& orb,
TD_info* td_p,
const hamilt::HContainer<TR>* sR,
const hamilt::HContainer<TR>* hR,
const std::vector<hamilt::HContainer<TR>*>& spin_hR,
const Exx_NAO<std::complex<double>>& exx_nao,
const Exx_Info& exx_info
);
Expand Down Expand Up @@ -95,7 +95,7 @@ void cal_velocity_basis_k(const UnitCell& ucell,
const K_Vectors& kv,
const ModuleBase::Vector3<hamilt::HContainer<double>*>& rR,
const hamilt::HContainer<TR>& sR,
const hamilt::HContainer<std::complex<double>>& hR,
const std::vector<const hamilt::HContainer<std::complex<double>>*>& spin_hR,
std::vector<ModuleBase::Vector3<std::complex<double>*>>& velocity_basis_k);

void cal_velocity_matrix(const psi::Psi<std::complex<double>>* psi,
Expand All @@ -111,7 +111,7 @@ void cal_current_comm_k(const UnitCell& ucell,
const K_Vectors& kv,
TD_info* td_p,
const hamilt::HContainer<TR>& sR,
const hamilt::HContainer<std::complex<double>>& hR,
const std::vector<const hamilt::HContainer<std::complex<double>>*>& spin_hR,
const psi::Psi<std::complex<double>>* psi,
const elecstate::ElecState* pelec,
std::vector<ModuleBase::Vector3<double>>& current_k);
Expand Down
34 changes: 22 additions & 12 deletions source/source_io/module_current/td_current_io_comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "source_lcao/module_rt/td_folding.h"
#include "source_lcao/module_rt/td_info.h"
#include "td_current_io.h"
#include <memory>
#include <utility>
#ifdef __EXX
#include "source_lcao/module_operator_lcao/op_exx_lcao.h"
#include "source_lcao/module_ri/exx_lri.h"
Expand Down Expand Up @@ -257,7 +259,7 @@ void ModuleIO::cal_velocity_basis_k(const UnitCell& ucell,
const K_Vectors& kv,
const ModuleBase::Vector3<hamilt::HContainer<double>*>& rR,
const hamilt::HContainer<TR>& sR,
const hamilt::HContainer<std::complex<double>>& hR,
const std::vector<const hamilt::HContainer<std::complex<double>>*>& spin_hR,
std::vector<ModuleBase::Vector3<std::complex<double>*>>& velocity_basis_k)
{
ModuleBase::TITLE("ModuleIO", "cal_velocity_basis_k");
Expand All @@ -284,6 +286,7 @@ void ModuleIO::cal_velocity_basis_k(const UnitCell& ucell,

for (size_t ik = 0; ik != kv.get_nks(); ++ik)
{
const hamilt::HContainer<std::complex<double>>& hR = *spin_hR[kv.isk[ik]];
// set H(k), S(k)
// 1.1 set H(k)
ModuleBase::GlobalFunc::ZEROS(hk, pv->para_2d().size());
Expand Down Expand Up @@ -615,7 +618,7 @@ void ModuleIO::cal_current_comm_k(const UnitCell& ucell,
const K_Vectors& kv,
TD_info* td_p,
const hamilt::HContainer<TR>& sR,
const hamilt::HContainer<std::complex<double>>& hR,
const std::vector<const hamilt::HContainer<std::complex<double>>*>& spin_hR,
const psi::Psi<std::complex<double>>* psi,
const elecstate::ElecState* pelec,
std::vector<ModuleBase::Vector3<double>>& current_k)
Expand All @@ -642,9 +645,9 @@ void ModuleIO::cal_current_comm_k(const UnitCell& ucell,
}
}
// set rR
set_rR_from_hR(ucell, GridD, orb, pv, td_p->r_calculator, &hR, rR);
set_rR_from_hR(ucell, GridD, orb, pv, td_p->r_calculator, spin_hR.front(), rR);
// set velocity_basis_k
cal_velocity_basis_k(ucell, td_p, orb, pv, kv, rR, sR, hR, velocity_basis_k);
cal_velocity_basis_k(ucell, td_p, orb, pv, kv, rR, sR, spin_hR, velocity_basis_k);
// set velocity_k
cal_velocity_matrix(psi, pv, kv, velocity_basis_k, velocity_k);

Expand Down Expand Up @@ -689,7 +692,7 @@ void ModuleIO::write_current(const UnitCell& ucell,
const LCAO_Orbitals& orb,
TD_info* td_p,
const hamilt::HContainer<TR>* sR,
const hamilt::HContainer<TR>* hR,
const std::vector<hamilt::HContainer<TR>*>& spin_hR,
const Exx_NAO<std::complex<double>>& exx_nao,
const Exx_Info& exx_info)
{
Expand All @@ -700,12 +703,19 @@ void ModuleIO::write_current(const UnitCell& ucell,
double omega = ucell.omega;

std::vector<ModuleBase::Vector3<double>> current_k;
hamilt::HContainer<std::complex<double>>* full_hR;
full_hR = new hamilt::HContainer<std::complex<double>>(pv);
std::vector<std::unique_ptr<hamilt::HContainer<std::complex<double>>>> full_hR;
std::vector<const hamilt::HContainer<std::complex<double>>*> current_hR;
for (const hamilt::HContainer<TR>* hR : spin_hR)
{
std::unique_ptr<hamilt::HContainer<std::complex<double>>> matrix(
new hamilt::HContainer<std::complex<double>>(pv));
hamilt::HContainer<std::complex<double>>* matrix_ptr = matrix.get();
sum_HR(ucell, *pv, kv, hR, matrix_ptr, exx_nao, exx_info, *td_p);
current_hR.push_back(matrix_ptr);
full_hR.push_back(std::move(matrix));
}
current_k.resize(kv.get_nks());
sum_HR(ucell, *pv, kv, hR, full_hR, exx_nao, exx_info, *td_p);
cal_current_comm_k(ucell, GridD, orb, pv, kv, td_p, *sR, *full_hR, psi, pelec, current_k);
delete full_hR;
cal_current_comm_k(ucell, GridD, orb, pv, kv, td_p, *sR, current_hR, psi, pelec, current_k);

int nspin0 = 1;
if (PARAM.inp.nspin == 2)
Expand Down Expand Up @@ -772,7 +782,7 @@ template void ModuleIO::write_current<double>(const UnitCell& ucell,
const LCAO_Orbitals& orb,
TD_info* td_p,
const hamilt::HContainer<double>* sR,
const hamilt::HContainer<double>* hR,
const std::vector<hamilt::HContainer<double>*>& spin_hR,
const Exx_NAO<std::complex<double>>& exx_nao,
const Exx_Info& exx_info);

Expand All @@ -786,7 +796,7 @@ template void ModuleIO::write_current<std::complex<double>>(const UnitCell& ucel
const LCAO_Orbitals& orb,
TD_info* td_p,
const hamilt::HContainer<std::complex<double>>* sR,
const hamilt::HContainer<std::complex<double>>* hR,
const std::vector<hamilt::HContainer<std::complex<double>>*>& spin_hR,
const Exx_NAO<std::complex<double>>& exx_nao,
const Exx_Info& exx_info);
#endif //__LCAO
4 changes: 4 additions & 0 deletions source/source_lcao/hamilt_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ std::vector<HContainer<TR>*> HamiltLCAO<TK, TR>::getHR_vector()
TR* down_data = up_data + nnr;
this->hr_spin_up_.reset(new HContainer<TR>(*this->hR, up_data));
this->hr_spin_dn_.reset(new HContainer<TR>(*this->hR, down_data));
if (!this->vl_in_h)
{
return {this->hR.get(), this->hR.get()};
}
return {this->hr_spin_up_.get(), this->hr_spin_dn_.get()};
}
else
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/hamilt_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class HamiltLCAO : public Hamilt<TK>
std::vector<TR>& getHRS2() { return this->hRS2; }

/// Get HR as a vector of HContainer pointers (one per spin).
/// For nspin=2, returns pointers to internally managed per-spin wrappers over hRS2.
/// For nspin=2, vl_in_h=0 shares the active H(R), matching updateHk.
/// Returned pointers are owned by this class; caller must NOT delete them.
std::vector<HContainer<TR>*> getHR_vector();

Expand Down
1 change: 1 addition & 0 deletions tests/08_RI/CASES_CPU.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rpa_scf_gamma
rpa_scf_shrink_multik
rt_tddft_pbe0_gamma
rt_tddft_hse_spin2
rt_tddft_hse_current_spin2_up
bse_lr_multik
nscf_hse_multik

Expand Down
46 changes: 46 additions & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
INPUT_PARAMETERS
calculation md
esolver_type tddft
md_type nve
estep_per_md 2
td_dt 0.005
md_tfirst 0
td_vext 1 # add time-dependent external potential
td_vext_dire 3 # direction along z
td_stype 2 # 2: hybrid gauge
td_ttype 3 # Heaviside type potential
td_tstart 1 # the step electric field starts
td_tend 10 # the step electric field ends
td_heavi_t0 3
td_heavi_amp 0.05
pseudo_dir ../../PP_ORB
orbital_dir ../../PP_ORB
basis_type lcao
gamma_only 0
ecutwfc 5
ks_solver scalapack_gvx
mixing_type broyden
mixing_beta 0.7
mixing_gg0 0.0
dft_functional hse
exx_singularity_correction limits
symmetry -1
suffix autotest
fixed_atoms 1
cal_force 0
dump_force 0
scf_thr 1e-6
scf_nmax 150
md_restartfreq 1
out_wfc_lcao 0
out_app_flag 0
out_freq_td 1
out_efield 0
out_vecpot 0
out_current 2
md_nstep 1
nspin 2
exx_real_number 0
out_current_k 1
nbands 8
nupdown 2
4 changes: 4 additions & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/KPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
K_POINTS
0
Gamma
2 1 1 0 0 0
1 change: 1 addition & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed-ion Si HSE/hybrid-gauge commutator current with collinear spin polarization.
22 changes: 22 additions & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/STRU
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ATOMIC_SPECIES
Si 28.085 Si_dojo_nsoc.upf

NUMERICAL_ORBITAL
Si_dojo_6au_sz.orb

LATTICE_CONSTANT
10.2 // add lattice constant

LATTICE_VECTORS
0.0 0.5 0.5
0.5 0.0 0.5
0.5 0.5 0.0

ATOMIC_POSITIONS
Cartesian //Cartesian or Direct coordinate.

Si // Element type
1.0 // magnetism
2 // number of atoms
0.00 0.00 0.00 0 0 0
0.25 0.25 0.25 0 0 0
3 changes: 3 additions & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 -4.089080634814e-19 4.090305385391e-19 4.090942654256e-19
2 -3.550737228392e-07 3.550678480581e-07 1.373779434519e-06
3 6.311340786252e-07 -6.311437488938e-07 1.015098378634e-05
4 changes: 4 additions & 0 deletions tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
etotref -190.6136471104446
etotperatomref -95.3068235552
CompareCurrent_pass 0
totaltimeref 1
17 changes: 15 additions & 2 deletions tests/integrate/validation_tools/props_tddft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ run_tddft_props() {
if ! test -z "$out_current" && [ $out_current ]; then
current1ref=current_tot.txt.ref
current1cal=OUT.autotest/current_tot.txt
if [ "$out_current" == 2 ]; then
current1cal=OUT.autotest/current_tot_comm.txt
fi
local current_tol=1e-10
if [ -f threshold ]; then
local configured_tol
Expand All @@ -32,8 +35,18 @@ run_tddft_props() {
current_tol=$configured_tol
fi
fi
python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol"
echo "CompareCurrent_pass $?" >>$props_result_file
local current_status=1
if [ -f "$current1ref" ] && [ -f "$current1cal" ]; then
local reference_rows
local current_rows
reference_rows=$(awk 'NF { count++ } END { print count+0 }' "$current1ref")
current_rows=$(awk 'NF { count++ } END { print count+0 }' "$current1cal")
if [ "$reference_rows" -gt 0 ] && [ "$current_rows" -ge "$reference_rows" ]; then
python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol"
current_status=$?
fi
fi
echo "CompareCurrent_pass $current_status" >>$props_result_file
fi

#--------------------------------------------
Expand Down
Loading