Skip to content

Commit 602ebe5

Browse files
authored
Fixed a bug in RT-TDDFT where the efield was not applied starting from the restart step (#5877)
1 parent 3f8fe4f commit 602ebe5

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

source/module_elecstate/potentials/H_TDDFT_pw.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace elecstate
1212
{
1313

1414
int H_TDDFT_pw::istep = -1;
15+
bool H_TDDFT_pw::is_initialized = false;
1516

1617
double H_TDDFT_pw::amp;
1718
double H_TDDFT_pw::bmod;
@@ -76,6 +77,21 @@ int H_TDDFT_pw::heavi_count;
7677
std::vector<double> H_TDDFT_pw::heavi_t0;
7778
std::vector<double> H_TDDFT_pw::heavi_amp; // Ry/bohr
7879

80+
void H_TDDFT_pw::current_step_info(const std::string& file_dir, int& istep)
81+
{
82+
std::stringstream ssc;
83+
ssc << file_dir << "Restart_md.dat";
84+
std::ifstream file(ssc.str().c_str());
85+
86+
if (!file)
87+
{
88+
ModuleBase::WARNING_QUIT("H_TDDFT_pw::current_step_info", "No Restart_md.dat!");
89+
}
90+
91+
file >> istep;
92+
file.close();
93+
}
94+
7995
void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo)
8096
{
8197
ModuleBase::TITLE("H_TDDFT_pw", "cal_fixed_v");

source/module_elecstate/potentials/H_TDDFT_pw.h

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define H_TDDFT_PW_H
33

44
#include "module_io/input_conv.h"
5+
#include "module_parameter/parameter.h" // PARAM.globalv.global_readin_dir, PARAM.inp.mdp.md_restart
56
#include "pot_base.h"
67

78
namespace elecstate
@@ -16,8 +17,25 @@ class H_TDDFT_pw : public PotBase
1617
this->fixed_mode = true;
1718

1819
this->rho_basis_ = rho_basis_in;
20+
21+
// If it is the first time to create an H_TDDFT_pw instance and is restart calculation,
22+
// initialize istep using current_step_info
23+
if (!is_initialized && PARAM.inp.mdp.md_restart)
24+
{
25+
int restart_istep = -1;
26+
std::string file_dir = PARAM.globalv.global_readin_dir;
27+
current_step_info(file_dir, restart_istep);
28+
29+
if (restart_istep >= 0)
30+
{
31+
H_TDDFT_pw::istep = restart_istep - 1; // Update istep
32+
}
33+
34+
is_initialized = true; // Mark as initialized, so that istep will not be initialized again
35+
}
1936
}
20-
~H_TDDFT_pw(){};
37+
38+
~H_TDDFT_pw() {};
2139

2240
void cal_fixed_v(double* vl_pseudo) override;
2341

@@ -42,17 +60,17 @@ class H_TDDFT_pw : public PotBase
4260
static int tstart;
4361
static int tend;
4462
static double dt;
45-
//cut dt for integral
63+
// cut dt for integral
4664
static double dt_int;
4765
static int istep_int;
4866

4967
// space domain parameters
5068

51-
//length gauge
69+
// length gauge
5270
static double lcut1;
5371
static double lcut2;
5472

55-
//velocity gauge, vector magnetic potential
73+
// velocity gauge, vector magnetic potential
5674
static ModuleBase::Vector3<double> At;
5775

5876
// time domain parameters
@@ -64,8 +82,8 @@ class H_TDDFT_pw : public PotBase
6482
static std::vector<double> gauss_sigma; // time(a.u.)
6583
static std::vector<double> gauss_t0;
6684
static std::vector<double> gauss_amp; // Ry/bohr
67-
//add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
68-
//must be even, thus would get odd number of points for simpson integral
85+
// add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
86+
// must be even, thus would get odd number of points for simpson integral
6987
static std::vector<int> gauss_ncut;
7088

7189
// trapezoid
@@ -76,7 +94,7 @@ class H_TDDFT_pw : public PotBase
7694
static std::vector<double> trape_t2;
7795
static std::vector<double> trape_t3;
7896
static std::vector<double> trape_amp; // Ry/bohr
79-
//add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
97+
// add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
8098
static std::vector<int> trape_ncut;
8199

82100
// Trigonometric
@@ -86,15 +104,15 @@ class H_TDDFT_pw : public PotBase
86104
static std::vector<double> trigo_phase1;
87105
static std::vector<double> trigo_phase2;
88106
static std::vector<double> trigo_amp; // Ry/bohr
89-
//add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
107+
// add for velocity gauge, recut dt into n pieces to make sure the integral is accurate Enough
90108
static std::vector<int> trigo_ncut;
91109

92110
// Heaviside
93111
static int heavi_count;
94112
static std::vector<double> heavi_t0;
95113
static std::vector<double> heavi_amp; // Ry/bohr
96114

97-
//update At for velocity gauge by intergral of E(t)dt
115+
// update At for velocity gauge by intergral of E(t)dt
98116
static void update_At();
99117

100118
private:
@@ -103,6 +121,7 @@ class H_TDDFT_pw : public PotBase
103121
// Vext will evolve by time, every time cal_fixed_v() is called, istep++
104122
//------------------------
105123
static int istep;
124+
static bool is_initialized; // static flag variable, used to ensure initialization only once
106125

107126
static double amp;
108127

@@ -111,9 +130,12 @@ class H_TDDFT_pw : public PotBase
111130

112131
const UnitCell* ucell_ = nullptr;
113132

133+
// Obtain the current MD step information, used for restart calculation
134+
void current_step_info(const std::string& file_dir, int& istep);
135+
114136
// potential of electric field in space domain : length gauge and velocity gauge
115-
void cal_v_space(std::vector<double> &vext_space, int direc);
116-
void cal_v_space_length(std::vector<double> &vext_space, int direc);
137+
void cal_v_space(std::vector<double>& vext_space, int direc);
138+
void cal_v_space_length(std::vector<double>& vext_space, int direc);
117139
double cal_v_space_length_potential(double i);
118140

119141
// potential of electric field in time domain : Gauss , trapezoid, trigonometric, heaviside, HHG
@@ -124,7 +146,7 @@ class H_TDDFT_pw : public PotBase
124146
static double cal_v_time_heaviside();
125147
// double cal_v_time_HHG();
126148

127-
//get ncut number for At integral
149+
// get ncut number for At integral
128150
static int check_ncut(int t_type);
129151

130152
void prepare(const ModuleBase::Matrix3& G, int& dir);

source/module_io/read_set_globalv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void ReadInput::set_globalv(Parameter& para)
2323
para.sys.global_matrix_dir = to_dir(para.sys.global_matrix_dir);
2424

2525
/// get the global readin directory
26-
para.sys.global_readin_dir = para.inp.read_file_dir + '/';
26+
para.sys.global_readin_dir = para.inp.read_file_dir;
2727
para.sys.global_readin_dir = to_dir(para.sys.global_readin_dir);
2828

2929
/// get the stru file for md restart case

0 commit comments

Comments
 (0)