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
2 changes: 1 addition & 1 deletion source/source_estate/module_pot/H_TDDFT_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool H_TDDFT_pw::is_initialized = false;
double H_TDDFT_pw::amp;

// Used for calculating electric field force on ions, summing over directions
vector<double> H_TDDFT_pw::global_vext_time = {0.0, 0.0, 0.0};
std::vector<double> H_TDDFT_pw::global_vext_time = {0.0, 0.0, 0.0};

int H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge

Expand Down
4 changes: 3 additions & 1 deletion source/source_estate/module_pot/H_TDDFT_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "pot_base.h"
#include "source_io/module_parameter/parameter.h"

#include <vector>

namespace elecstate
{

Expand Down Expand Up @@ -120,7 +122,7 @@ class H_TDDFT_pw : public PotBase
static bool is_initialized; // static flag variable, used to ensure initialization only once

static double amp;
static vector<double> global_vext_time;
static std::vector<double> global_vext_time;

const UnitCell* ucell_ = nullptr;

Expand Down
220 changes: 134 additions & 86 deletions source/source_io/module_current/td_current_io_comm.cpp

Large diffs are not rendered by default.

89 changes: 49 additions & 40 deletions source/source_lcao/module_operator_lcao/op_exx_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

#ifdef __EXX

#include <RI/global/Tensor.h>
#include <RI/ri/Cell_Nearest.h>
#include "operator_lcao.h"
#include "source_cell/klist.h"
#include "source_hamilt/module_xc/exx_info.h"

#include <RI/global/Tensor.h>
#include <RI/ri/Cell_Nearest.h>

namespace hamilt
{

Expand All @@ -21,13 +22,19 @@ class OperatorEXX : public T
};

#endif
enum Add_Hexx_Type { R, k };
enum Add_Hexx_Type
{
R,
k
};
template <typename TK, typename TR>
class OperatorEXX<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
{
using TAC = std::pair<int, std::array<int, 3>>;
public:
OperatorEXX<OperatorLCAO<TK, TR>>(HS_Matrix_K<TK>* hsk_in,

public:
OperatorEXX<OperatorLCAO<TK, TR>>(
HS_Matrix_K<TK>* hsk_in,
hamilt::HContainer<TR>* hR_in,
const UnitCell& ucell,
const K_Vectors& kv_in,
Expand All @@ -42,36 +49,37 @@ class OperatorEXX<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
virtual void contributeHR() override;

private:
Add_Hexx_Type add_hexx_type = Add_Hexx_Type::R;
int current_spin = 0;
bool HR_fixed_done = false;

std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd = nullptr;
std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc = nullptr;

/// @brief the step of the outer loop.
/// nullptr: no dependence on the number of two_level_step, contributeHk will do enerything normally.
/// 0: the first outer loop. If restart, contributeHk will directly add Hexx to Hloc. else, do nothing.
/// >0: not the first outer loop. contributeHk will do enerything normally.
int* two_level_step = nullptr;
/// @brief if restart, read and save Hexx, and directly use it during the first outer loop.
bool restart = false;

const int istep = 0; // the ion step

void add_loaded_Hexx(const int ik);

const UnitCell& ucell;

const K_Vectors& kv;

// if k points has no shift, use cell_nearest to reduce the memory cost
RI::Cell_Nearest<int, int, 3, double, 3> cell_nearest;
bool use_cell_nearest = true;

/// @brief Hexxk for all k-points, only for the 1st scf loop ofrestart load
std::vector<std::vector<double>> Hexxd_k_load;
std::vector<std::vector<std::complex<double>>> Hexxc_k_load;
Add_Hexx_Type add_hexx_type = Add_Hexx_Type::R;
int current_spin = 0;
bool HR_fixed_done = false;
bool initial_gga_done = false; // Taoni Bao add 2026-05-18, to fix RT-TDDFT EXX missing problem in the evolution

std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd = nullptr;
std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc = nullptr;

/// @brief the step of the outer loop.
/// nullptr: no dependence on the number of two_level_step, contributeHk will do enerything normally.
/// 0: the first outer loop. If restart, contributeHk will directly add Hexx to Hloc. else, do nothing.
/// >0: not the first outer loop. contributeHk will do enerything normally.
int* two_level_step = nullptr;
/// @brief if restart, read and save Hexx, and directly use it during the first outer loop.
bool restart = false;

const int istep = 0; // the ion step

void add_loaded_Hexx(const int ik);

const UnitCell& ucell;

const K_Vectors& kv;

// if k points has no shift, use cell_nearest to reduce the memory cost
RI::Cell_Nearest<int, int, 3, double, 3> cell_nearest;
bool use_cell_nearest = true;

/// @brief Hexxk for all k-points, only for the 1st scf loop ofrestart load
std::vector<std::vector<double>> Hexxd_k_load;
std::vector<std::vector<std::complex<double>>> Hexxc_k_load;
};

using TAC = std::pair<int, std::array<int, 3>>;
Expand All @@ -81,14 +89,15 @@ RI::Cell_Nearest<int, int, 3, double, 3> init_cell_nearest(const UnitCell& ucell
// allocate according to the read-in HexxR, used in nscf
template <typename Tdata, typename TR>
void reallocate_hcontainer(const std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& Hexxs,
HContainer<TR>* hR,
const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr);
HContainer<TR>* hR,
const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr);

/// allocate according to BvK cells, used in scf
template <typename TR>
void reallocate_hcontainer(const int nat, HContainer<TR>* hR,
const std::array<int, 3>& Rs_period,
const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr);
void reallocate_hcontainer(const int nat,
HContainer<TR>* hR,
const std::array<int, 3>& Rs_period,
const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr);

} // namespace hamilt
#endif // __EXX
Expand Down
10 changes: 9 additions & 1 deletion source/source_lcao/module_operator_lcao/op_exx_lcao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,22 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHk(int ik)
// 2. For the first ionic step:
else if (this->istep == 0)
{
// If EXX is once turned on (two_level_step > 0), let OperatorEXX remember this
if (this->two_level_step != nullptr && *this->two_level_step > 0)
{
this->initial_gga_done = true;
}

// Check if we are in the pre-convergence stage of the two-level SCF (i.e., the pure GGA loop)
bool in_gga_pre_loop = (this->two_level_step != nullptr && *this->two_level_step == 0);

// Check if a high-quality initial guess is missing
bool lacks_good_guess = (!this->restart);

// If in the pre-convergence loop and lacking a good initial guess, skip adding the EXX contribution
if (in_gga_pre_loop && lacks_good_guess)
// Taoni Bao add 2026-05-18, only skip EXX if initial GGA loop is not done
// Fix RT-TDDFT EXX missing problem in the evolution
if (in_gga_pre_loop && lacks_good_guess && !this->initial_gga_done)
{
return; // In the non-EXX loop, skip adding EXX contribution
}
Expand Down
12 changes: 6 additions & 6 deletions tests/08_EXX/14_NO_TDDFT_PBE0/current_tot.txt.ref
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 -2.4064298950993433e-19 2.4067857486819294e-19 2.4048227372973307e-19
2 1.3583754132510189e-08 -1.3583754049585592e-08 2.4306592013239020e-06
3 3.8454029971142809e-08 -3.8454029713369349e-08 7.2734897464115248e-06
4 4.3394109439952714e-08 -4.3394109112344272e-08 9.6350822407378473e-06
5 2.6144935011100098e-08 -2.6144935077756982e-08 9.4987415747287647e-06
6 6.1114518547755749e-10 -6.1114527641090651e-10 9.2969143096824206e-06
1 -2.4064812749552146e-19 2.4058918971736318e-19 2.4056235004085640e-19
2 1.3401891378677289e-08 -1.3401891246959429e-08 2.4369369671292067e-06
3 3.9314244407525817e-08 -3.9314246669204259e-08 7.3211566892522424e-06
4 4.7934170184878929e-08 -4.7934175958037426e-08 9.7956029317437335e-06
5 3.4376283041277918e-08 -3.4376284895741181e-08 9.8560550504479175e-06
6 5.9843794461236954e-09 -5.9843813295237610e-09 9.9145073758045465e-06
4 changes: 2 additions & 2 deletions tests/08_EXX/14_NO_TDDFT_PBE0/result.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
etotref -170.67031862
etotperatomref -85.33515931
etotref -203.7710904354790
etotperatomref -101.8855452177
CompareCurrent_pass 0
totaltimeref 16.38
Loading