Skip to content

Commit 7edc682

Browse files
authored
Optimize RT-TDDFT dipole output (#6393)
1 parent 14ae255 commit 7edc682

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-38
lines changed

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
331331
<< std::setw(12) << this->pelec->wg(ik, ib) << std::endl;
332332
}
333333
}
334+
GlobalV::ofs_running << std::endl;
334335
}
335336

336337
ESolver_KS_LCAO<std::complex<double>, TR>::iter_finish(ucell, istep, iter, conv_esolver);

source/source_io/dipole_io.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef DIPOLE_IO_H
22
#define DIPOLE_IO_H
33

4-
#include <string>
5-
64
#include "source_basis/module_pw/pw_basis.h"
75

6+
#include <string>
7+
88
namespace ModuleIO
99
{
1010
void write_dipole(const UnitCell& ucell,
@@ -13,10 +13,9 @@ void write_dipole(const UnitCell& ucell,
1313
const int& is,
1414
const int& istep,
1515
const std::string& fn,
16-
const int& precision = 11,
17-
const bool for_plot = false);
16+
const int& precision = 11);
1817

19-
double prepare(const UnitCell &cell, int &dir);
18+
double prepare(const UnitCell& cell, int& dir);
2019

2120
} // namespace ModuleIO
2221

source/source_io/write_dipole.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "source_base/parallel_reduce.h"
22
#include "source_estate/module_charge/charge.h"
3+
#include "source_io/dipole_io.h"
34
#include "source_lcao/module_rt/evolve_elec.h"
45
#include "source_pw/module_pwdft/global.h"
5-
#include "source_io/dipole_io.h"
66

77
// fuxiang add 2017-03-15
88
void ModuleIO::write_dipole(const UnitCell& ucell,
@@ -11,8 +11,7 @@ void ModuleIO::write_dipole(const UnitCell& ucell,
1111
const int& is,
1212
const int& istep,
1313
const std::string& fn,
14-
const int& precision,
15-
const bool for_plot)
14+
const int& precision)
1615
{
1716
ModuleBase::TITLE("ModuleIO", "write_dipole");
1817

@@ -51,9 +50,9 @@ void ModuleIO::write_dipole(const UnitCell& ucell,
5150
int index = i * rhopw->ny * rhopw->nz + j * rhopw->nz + k;
5251
double rho_val = rho_save[index];
5352

54-
dipole_elec_x += rho_val * i * lat_factor_x;
55-
dipole_elec_y += rho_val * j * lat_factor_y;
56-
dipole_elec_z += rho_val * k * lat_factor_z;
53+
dipole_elec_x -= rho_val * i * lat_factor_x;
54+
dipole_elec_y -= rho_val * j * lat_factor_y;
55+
dipole_elec_z -= rho_val * k * lat_factor_z;
5756
}
5857
}
5958
}
@@ -79,9 +78,9 @@ void ModuleIO::write_dipole(const UnitCell& ucell,
7978
double y = (double)j / rhopw->ny;
8079
double z = (double)k / rhopw->nz;
8180

82-
dipole_elec[0] += rho_save[ir] * x;
83-
dipole_elec[1] += rho_save[ir] * y;
84-
dipole_elec[2] += rho_save[ir] * z;
81+
dipole_elec[0] -= rho_save[ir] * x;
82+
dipole_elec[1] -= rho_save[ir] * y;
83+
dipole_elec[2] -= rho_save[ir] * z;
8584
}
8685

8786
Parallel_Reduce::reduce_pool(dipole_elec[0]);
@@ -92,12 +91,12 @@ void ModuleIO::write_dipole(const UnitCell& ucell,
9291
dipole_elec[i] *= ucell.lat0 / bmod[i] * ucell.omega / rhopw->nxyz;
9392
}
9493

95-
std::cout << std::setprecision(15) << "dipole_elec_x: " << dipole_elec[0] << std::endl;
96-
std::cout << std::setprecision(15) << "dipole_elec_y: " << dipole_elec[1] << std::endl;
97-
std::cout << std::setprecision(15) << "dipole_elec_z: " << dipole_elec[2] << std::endl;
94+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Electronic dipole moment P_elec_x(t)", dipole_elec[0]);
95+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Electronic dipole moment P_elec_y(t)", dipole_elec[1]);
96+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Electronic dipole moment P_elec_z(t)", dipole_elec[2]);
9897

99-
ofs << std::setprecision(8) << istep << " " << dipole_elec[0] << " " << dipole_elec[1] << " " << dipole_elec[2]
100-
<< std::endl;
98+
ofs << std::setprecision(precision) << istep << " " << dipole_elec[0] << " " << dipole_elec[1] << " "
99+
<< dipole_elec[2] << std::endl;
101100

102101
double dipole_ion[3] = {0.0};
103102
double dipole_sum = 0.0;
@@ -116,20 +115,23 @@ void ModuleIO::write_dipole(const UnitCell& ucell,
116115
dipole_ion[i] *= ucell.lat0 / bmod[i]; //* ModuleBase::FOUR_PI / ucell.omega;
117116
}
118117

119-
std::cout << std::setprecision(8) << "dipole_ion_x: " << dipole_ion[0] << std::endl;
120-
std::cout << std::setprecision(8) << "dipole_ion_y: " << dipole_ion[1] << std::endl;
121-
std::cout << std::setprecision(8) << "dipole_ion_z: " << dipole_ion[2] << std::endl;
118+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Ionic dipole moment P_ion_x(t)", dipole_ion[0]);
119+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Ionic dipole moment P_ion_y(t)", dipole_ion[1]);
120+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Ionic dipole moment P_ion_z(t)", dipole_ion[2]);
122121

123122
double dipole[3] = {0.0};
124123
for (int i = 0; i < 3; ++i)
125124
{
126-
dipole[i] = dipole_ion[i] - dipole_elec[i];
125+
dipole[i] = dipole_ion[i] + dipole_elec[i];
127126
}
128-
std::cout << std::setprecision(8) << "dipole_x: " << dipole[0] << std::endl;
129-
std::cout << std::setprecision(8) << "dipole_y: " << dipole[1] << std::endl;
130-
std::cout << std::setprecision(8) << "dipole_z: " << dipole[2] << std::endl;
127+
128+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Total dipole moment P_tot_x(t)", dipole[0]);
129+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Total dipole moment P_tot_y(t)", dipole[1]);
130+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Total dipole moment P_tot_z(t)", dipole[2]);
131+
131132
dipole_sum = sqrt(dipole[0] * dipole[0] + dipole[1] * dipole[1] + dipole[2] * dipole[2]);
132-
std::cout << std::setprecision(8) << "dipole_sum: " << dipole_sum << std::endl;
133+
134+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Total dipole moment norm |P_tot(t)|", dipole_sum);
133135

134136
#endif
135137

source/source_lcao/module_rt/evolve_psi.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
#include "band_energy.h"
44
#include "middle_hamilt.h"
5+
#include "norm_psi.h"
6+
#include "propagator.h"
7+
#include "solve_propagation.h"
58
#include "source_base/lapack_connector.h"
69
#include "source_base/module_container/ATen/kernels/blas.h" // cuBLAS handle
710
#include "source_base/module_container/ATen/kernels/lapack.h" // cuSOLVER handle
811
#include "source_base/scalapack_connector.h"
912
#include "source_esolver/esolver_ks_lcao_tddft.h" // use gatherMatrix
13+
#include "source_io/module_parameter/parameter.h"
1014
#include "source_lcao/hamilt_lcao.h"
1115
#include "source_pw/module_pwdft/global.h"
12-
#include "source_io/module_parameter/parameter.h"
13-
#include "norm_psi.h"
14-
#include "propagator.h"
1516
#include "upsi.h"
16-
#include "solve_propagation.h"
1717

1818
#include <complex>
1919

@@ -34,10 +34,10 @@ void evolve_psi(const int nband,
3434
const int print_matrix)
3535
{
3636
ModuleBase::TITLE("Evolve_psi", "evolve_psi");
37-
ofs_running << " Evolving electronic wave functions begins" << std::endl;
37+
// ofs_running << " Evolving electronic wave functions begins" << std::endl;
3838

3939
time_t time_start = time(nullptr);
40-
ofs_running << " Start Time : " << ctime(&time_start);
40+
// ofs_running << " Start Time : " << ctime(&time_start);
4141

4242
#ifdef __MPI
4343

@@ -120,7 +120,7 @@ void evolve_psi(const int nband,
120120
time_t time_end = time(nullptr);
121121
ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end);
122122

123-
ofs_running << " Evolving electronic wave functions ends" << std::endl;
123+
// ofs_running << " Evolving electronic wave functions ends" << std::endl;
124124

125125
return;
126126
}
@@ -155,11 +155,11 @@ void evolve_psi_tensor(const int nband,
155155
ct::kernels::createGpuBlasHandle();
156156
#endif // __CUDA
157157

158-
ofs_running << " evolve_psi_tensor::start " << std::endl;
158+
// ofs_running << " evolve_psi_tensor::start " << std::endl;
159159

160160
ModuleBase::TITLE("Evolve_psi", "evolve_psi");
161161
time_t time_start = time(nullptr);
162-
ofs_running << " Start Time : " << ctime(&time_start);
162+
// ofs_running << " Start Time : " << ctime(&time_start);
163163

164164
#ifdef __MPI
165165

@@ -305,7 +305,7 @@ void evolve_psi_tensor(const int nband,
305305
time_t time_end = time(nullptr);
306306
ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end);
307307

308-
ofs_running << " evolve_psi_tensor::end " << std::endl;
308+
// ofs_running << " evolve_psi_tensor::end " << std::endl;
309309

310310
#if ((defined __CUDA) /* || (defined __ROCM) */)
311311
// Destroy cuBLAS & cuSOLVER handle

source/source_lcao/module_rt/velocity_op.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void Velocity_op<TR>::initialize_vcomm_r(const Grid_Driver* GridD, const Paralle
4040
ModuleBase::timer::tick("Velocity_op", "initialize_vcomm_r");
4141
if(!init_done)
4242
{
43-
std::cout << "init_r_overlap_nonlocal" <<std::endl;
4443
r_calculator.init_nonlocal(*ucell, *paraV, orb_);
4544
init_done = true;
4645
}

0 commit comments

Comments
 (0)