Skip to content

Commit 549a85a

Browse files
authored
Refactor the rt-TDDFT integrate tests (#6157)
* update integrate tests of rt-TDDFT * delete a useless gauss test in rt-TDDFT, which has been coverged by current test * update Autotest.sh, delete useless screen output information * refactor some output information * update Autotest.sh
1 parent fcadc37 commit 549a85a

File tree

80 files changed

+220
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+220
-229
lines changed

source/module_elecstate/module_pot/H_TDDFT_pw.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo)
114114
{
115115
return;
116116
}
117-
std::cout << "calculate electric potential" << std::endl;
117+
//std::cout << "calculate electric potential" << std::endl;
118118

119119
ModuleBase::timer::tick("H_TDDFT_pw", "cal_fixed_v");
120120

@@ -280,7 +280,7 @@ int H_TDDFT_pw::check_ncut(int t_type)
280280

281281
void H_TDDFT_pw::update_At()
282282
{
283-
std::cout << "calculate electric potential" << std::endl;
283+
//std::cout << "calculate electric potential" << std::endl;
284284
// time evolve
285285
H_TDDFT_pw::istep++;
286286

@@ -289,6 +289,9 @@ void H_TDDFT_pw::update_At()
289289
{
290290
return;
291291
}
292+
293+
ModuleBase::timer::tick("H_TDDFT_pw", "update_At");
294+
292295
int count = 0;
293296
gauss_count = 0;
294297
trape_count = 0;
@@ -346,6 +349,8 @@ void H_TDDFT_pw::update_At()
346349
// total count++
347350
count++;
348351
}
352+
353+
ModuleBase::timer::tick("H_TDDFT_pw", "update_At");
349354
return;
350355
}
351356

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ void TDEkinetic<OperatorLCAO<TK, TR>>::init_td()
241241
// calculate At in cartesian coorinates.
242242
td_velocity.cal_cart_At(elecstate::H_TDDFT_pw::At);
243243
this->cart_At = td_velocity.cart_At;
244-
std::cout << "cart_At: " << cart_At[0] << " " << cart_At[1] << " " << cart_At[2] << std::endl;
244+
245+
// mohan update 2025-04-20
246+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Cartesian vector potential Ax(t)", cart_At[0]);
247+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Cartesian vector potential Ax(t)", cart_At[1]);
248+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Cartesian vector potential Ax(t)", cart_At[2]);
245249
}
246250

247251
template <typename TK, typename TR>

source/module_hamilt_lcao/module_tddft/snap_psibeta_half_tddft.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ void snap_psibeta_half_tddft(const LCAO_Orbitals& orb,
163163
const ModuleBase::Vector3<double> r_coor = r_ridial[ir] * r_angular_tmp;
164164
const ModuleBase::Vector3<double> tmp_r_coor = r_coor + dRa;
165165
const double tmp_r_coor_norm = tmp_r_coor.norm();
166-
if (tmp_r_coor_norm > Rcut1) {
166+
if (tmp_r_coor_norm > Rcut1)
167+
{
167168
continue;
168169
}
169170

@@ -181,12 +182,13 @@ void snap_psibeta_half_tddft(const LCAO_Orbitals& orb,
181182
const std::complex<double> exp_iAr = std::exp(ModuleBase::IMAG_UNIT * phase);
182183

183184
const ModuleBase::Vector3<double> tmp_r_coor_r_commu = r_coor + R0;
184-
const double temp_interpolation_value = ModuleBase::PolyInt::Polynomial_Interpolation(psi_1, mesh_r1, dk_1, tmp_r_coor_norm);
185+
const double interp_v = ModuleBase::PolyInt::Polynomial_Interpolation(psi_1,
186+
mesh_r1, dk_1, tmp_r_coor_norm);
187+
185188
for (int m0 = 0; m0 < 2 * L0 + 1; m0++)
186189
{
187190
std::complex<double> temp = exp_iAr * rly0[L0 * L0 + m0] * rly1[L1 * L1 + m1]
188-
* temp_interpolation_value
189-
* weights_angular;
191+
* interp_v * weights_angular;
190192
result_angular[m0] += temp;
191193

192194
if (calc_r)
@@ -199,7 +201,9 @@ void snap_psibeta_half_tddft(const LCAO_Orbitals& orb,
199201
}
200202

201203
int index_tmp = index;
202-
const double temp = ModuleBase::PolyInt::Polynomial_Interpolation(beta_r, mesh_r0, dk_0, r_ridial[ir]) * r_ridial[ir] * weights_ridial[ir];
204+
const double temp = ModuleBase::PolyInt::Polynomial_Interpolation(beta_r,
205+
mesh_r0, dk_0, r_ridial[ir]) * r_ridial[ir] * weights_ridial[ir];
206+
203207
if (!calc_r)
204208
{
205209
for (int m0 = 0; m0 < 2 * L0 + 1; m0++)

source/module_io/td_current_io.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ void ModuleIO::write_current(const UnitCell& ucell,
128128
const LCAO_Orbitals& orb,
129129
Record_adj& ra)
130130
{
131-
132131
ModuleBase::TITLE("ModuleIO", "write_current");
133132
ModuleBase::timer::tick("ModuleIO", "write_current");
133+
134134
TD_current* cal_current = nullptr;
135135
std::vector<hamilt::HContainer<std::complex<double>>*> current_term = {nullptr, nullptr, nullptr};
136+
136137
if (!TD_Velocity::tddft_velocity)
137138
{
138139
cal_current = new TD_current(&ucell, &gd, pv, orb, intor);
@@ -156,11 +157,16 @@ void ModuleIO::write_current(const UnitCell& ucell,
156157
}
157158

158159
// construct a DensityMatrix object
159-
// Since the function cal_dm_psi do not suport DMR in complex type, I replace it with two DMR in double type. Should
160-
// be refactored in the future.
161-
const int nspin_dm = std::map<int, int>({ {1,1},{2,2},{4,1} })[PARAM.inp.nspin];
160+
// Since the function cal_dm_psi do not suport DMR in complex type,
161+
// I replace it with two DMR in double type.
162+
// Should be refactored in the future.
163+
164+
const int nspin0 = PARAM.inp.nspin;
165+
const int nspin_dm = std::map<int, int>({ {1,1},{2,2},{4,1} })[nspin0];
166+
162167
elecstate::DensityMatrix<std::complex<double>, double> DM_real(pv, nspin_dm, kv.kvec_d, kv.get_nks() / nspin_dm);
163168
elecstate::DensityMatrix<std::complex<double>, double> DM_imag(pv, nspin_dm, kv.kvec_d, kv.get_nks() / nspin_dm);
169+
164170
// calculate DMK
165171
elecstate::cal_dm_psi(DM_real.get_paraV_pointer(), pelec->wg, psi[0], DM_real);
166172

@@ -169,19 +175,21 @@ void ModuleIO::write_current(const UnitCell& ucell,
169175
DM_imag.init_DMR(ra, &ucell);
170176

171177
int nks = DM_real.get_DMK_nks();
172-
if (PARAM.inp.nspin == 2)
178+
if (nspin0 == 2)
173179
{
174180
nks /= 2;
175181
}
182+
176183
double current_total[3] = {0.0, 0.0, 0.0};
177-
for (int is = 1; is <= PARAM.inp.nspin; ++is)
184+
for (int is = 1; is <= nspin0; ++is)
178185
{
179186
for (int ik = 0; ik < nks; ++ik)
180187
{
181-
cal_tmp_DM(DM_real, DM_imag, ik, PARAM.inp.nspin, is);
188+
cal_tmp_DM(DM_real, DM_imag, ik, nspin0, is);
182189
// check later
183190
double current_ik[3] = {0.0, 0.0, 0.0};
184191
int total_irr = 0;
192+
185193
#ifdef _OPENMP
186194
#pragma omp parallel
187195
{
@@ -223,26 +231,29 @@ void ModuleIO::write_current(const UnitCell& ucell,
223231
double Rx = ra.info[iat][cb][0];
224232
double Ry = ra.info[iat][cb][1];
225233
double Rz = ra.info[iat][cb][2];
226-
// std::cout<< "iat1: " << iat1 << " iat2: " << iat2 << " Rx: " << Rx << " Ry: " << Ry << " Rz:
227-
// " << Rz << std::endl;
234+
228235
// get BaseMatrix
229236
hamilt::BaseMatrix<double>* tmp_matrix_real
230237
= DM_real.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
231238
hamilt::BaseMatrix<double>* tmp_matrix_imag
232239
= DM_imag.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
240+
233241
// refactor
234242
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvx
235243
= current_term[0]->find_matrix(iat1, iat2, Rx, Ry, Rz);
236244
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvy
237245
= current_term[1]->find_matrix(iat1, iat2, Rx, Ry, Rz);
238246
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvz
239247
= current_term[2]->find_matrix(iat1, iat2, Rx, Ry, Rz);
248+
240249
if (tmp_matrix_real == nullptr)
241250
{
242251
continue;
243252
}
253+
244254
int row_ap = pv->atom_begin_row[iat1];
245255
int col_ap = pv->atom_begin_col[iat2];
256+
246257
// get DMR
247258
for (int mu = 0; mu < pv->get_row_size(iat1); ++mu)
248259
{
@@ -287,6 +298,7 @@ void ModuleIO::write_current(const UnitCell& ucell,
287298
{
288299
current_total[i] += current_ik[i];
289300
}
301+
290302
// MPI_Reduce(local_current_ik, current_ik, 3, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
291303
if (GlobalV::MY_RANK == 0 && TD_Velocity::out_current_k)
292304
{

tests/integrate/1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
601_NO_KP_TDDFT
2+
601_NO_TDDFT
3+
601_NO_TDDFT_CH
4+
601_NO_TDDFT_CO
5+
601_NO_TDDFT_CO_occ
6+
601_NO_TDDFT_current
7+
601_NO_TDDFT_DIR
8+
601_NO_TDDFT_EDM
9+
601_NO_TDDFT_ETRS
10+
601_NO_TDDFT_GAUS
11+
601_NO_TDDFT_HEAV
12+
601_NO_TDDFT_HHG
13+
601_NO_TDDFT_O3
14+
601_NO_TDDFT_restart
15+
601_NO_TDDFT_Taylor
16+
601_NO_TDDFT_TRAP
17+
601_NO_TDDFT_TRI
18+
601_NO_TDDFT_vel_H2
19+
601_NO_TDDFT_vel_Si

tests/integrate/601_NO_TDDFT_H2_kpoint/INPUT renamed to tests/integrate/601_NO_KP_TDDFT/INPUT

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
INPUT_PARAMETERS
22
#Parameters (General)
3-
suffix autotest
4-
pseudo_dir ../../PP_ORB
5-
orbital_dir ../../PP_ORB
3+
suffix autotest
4+
pseudo_dir ../../PP_ORB
5+
orbital_dir ../../PP_ORB
66

77
nbands 5
88
calculation md
@@ -22,13 +22,13 @@ mixing_beta 0.7
2222
mixing_gg0 0.0
2323
scf_thr 1.0e-6
2424

25-
cal_stress 1
25+
cal_stress 1
2626
stress_thr 1e-6
27-
cal_force 1
27+
cal_force 1
2828
force_thr_ev 1.0e-3
2929

30-
md_type nve
30+
md_type nve
3131
md_dt 0.05
32-
init_vel 1
33-
ocp 1
34-
ocp_set 1*0.5 1*0.5 3*0 1*0.5 1*0.5 3*0
32+
init_vel 1
33+
ocp 1
34+
ocp_set 1*0.5 1*0.5 3*0 1*0.5 1*0.5 3*0
File renamed without changes.
File renamed without changes.

tests/integrate/601_NO_TDDFT_H2/INPUT renamed to tests/integrate/601_NO_TDDFT/INPUT

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cal_force 1
2828
force_thr_ev 1.0e-3
2929

3030
md_type nve
31-
md_dt 0.05
32-
init_vel 1
31+
md_dt 0.05
32+
init_vel 1
3333
ocp 1
34-
ocp_set 1*1 1*1 3*0
34+
ocp_set 1*1 1*1 3*0

0 commit comments

Comments
 (0)