Skip to content

Commit 9671f5e

Browse files
committed
Move the output functions in after_scf to ctrl_output_td
1 parent 37c03d1 commit 9671f5e

File tree

5 files changed

+213
-52
lines changed

5 files changed

+213
-52
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ OBJS_IO=input_conv.o\
560560
ctrl_iter_lcao.o\
561561
ctrl_output_fp.o\
562562
ctrl_output_pw.o\
563+
ctrl_output_td.o\
563564
para_json.o\
564565
abacusjson.o\
565566
general_info.o\

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "esolver_ks_lcao_tddft.h"
22

33
//----------------IO-----------------
4+
#include "source_io/ctrl_output_td.h"
45
#include "source_io/dipole_io.h"
56
#include "source_io/output_log.h"
67
#include "source_io/read_wfc_nao.h"
@@ -440,58 +441,20 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell, const int ist
440441
// Output energy for sub-loop (electronic step)
441442
std::cout << " Potential (Ry): " << std::setprecision(15) << this->pelec->f_en.etot << std::endl;
442443

443-
// (1) Write dipole information
444-
for (int is = 0; is < PARAM.inp.nspin; is++)
445-
{
446-
if (PARAM.inp.out_dipole == 1)
447-
{
448-
std::stringstream ss_dipole;
449-
ss_dipole << PARAM.globalv.global_out_dir << "dipole_s" << is + 1 << ".txt";
450-
ModuleIO::write_dipole(ucell, this->chr.rho_save[is], this->chr.rhopw, is, istep, ss_dipole.str());
451-
}
452-
}
453-
454-
// (2) Write current information
455-
elecstate::DensityMatrix<std::complex<double>, double>* tmp_DM
456-
= dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->get_DM();
457-
if (TD_info::out_current)
458-
{
459-
if (TD_info::out_current_k)
460-
{
461-
ModuleIO::write_current_eachk(ucell,
462-
istep,
463-
this->psi,
464-
this->pelec,
465-
this->kv,
466-
this->two_center_bundle_.overlap_orb.get(),
467-
tmp_DM->get_paraV_pointer(),
468-
this->orb_,
469-
this->velocity_mat,
470-
this->RA);
471-
}
472-
else
473-
{
474-
ModuleIO::write_current(ucell,
475-
istep,
476-
this->psi,
477-
this->pelec,
478-
this->kv,
479-
this->two_center_bundle_.overlap_orb.get(),
480-
tmp_DM->get_paraV_pointer(),
481-
this->orb_,
482-
this->velocity_mat,
483-
this->RA);
484-
}
485-
}
486-
487-
// (3) Output file for restart
488-
if (PARAM.inp.out_freq_ion > 0) // default value of out_freq_ion is 0
489-
{
490-
if (istep % PARAM.inp.out_freq_ion == 0)
491-
{
492-
td_p->out_restart_info(istep, elecstate::H_TDDFT_pw::At, elecstate::H_TDDFT_pw::At_laststep);
493-
}
494-
}
444+
ModuleIO::ctrl_output_td<TR>(
445+
ucell,
446+
this->chr.rho_save,
447+
this->chr.rhopw,
448+
istep,
449+
this->psi,
450+
this->pelec,
451+
this->kv,
452+
this->two_center_bundle_.overlap_orb.get(),
453+
dynamic_cast<const elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->get_DM()->get_paraV_pointer(),
454+
this->orb_,
455+
this->velocity_mat,
456+
this->RA,
457+
this->td_p);
495458

496459
ModuleBase::timer::tick(this->classname, "after_scf");
497460
}

source/source_io/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ list(APPEND objects
22
input_conv.cpp
33
ctrl_output_fp.cpp
44
ctrl_output_pw.cpp
5+
ctrl_output_td.cpp
56
bessel_basis.cpp
67
cal_test.cpp
78
cal_dos.cpp
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include "ctrl_output_td.h"
2+
3+
#include "source_base/parallel_global.h"
4+
#include "source_io/dipole_io.h"
5+
#include "source_io/module_parameter/parameter.h"
6+
#include "source_io/td_current_io.h"
7+
8+
namespace ModuleIO
9+
{
10+
11+
template <typename TR>
12+
void ctrl_output_td(const UnitCell& ucell,
13+
double** rho_save,
14+
const ModulePW::PW_Basis* rhopw,
15+
const int istep,
16+
const psi::Psi<std::complex<double>>* psi,
17+
const elecstate::ElecState* pelec,
18+
const K_Vectors& kv,
19+
const TwoCenterIntegrator* intor,
20+
const Parallel_Orbitals* pv,
21+
const LCAO_Orbitals& orb,
22+
const Velocity_op<TR>* velocity_mat,
23+
Record_adj& RA,
24+
TD_info* td_p)
25+
{
26+
ModuleBase::TITLE("ModuleIO", "ctrl_output_td");
27+
28+
// Original code commented out, might need reference later
29+
30+
// // (1) Write dipole information
31+
// for (int is = 0; is < PARAM.inp.nspin; is++)
32+
// {
33+
// if (PARAM.inp.out_dipole == 1)
34+
// {
35+
// std::stringstream ss_dipole;
36+
// ss_dipole << PARAM.globalv.global_out_dir << "dipole_s" << is + 1 << ".txt";
37+
// ModuleIO::write_dipole(ucell, this->chr.rho_save[is], this->chr.rhopw, is, istep, ss_dipole.str());
38+
// }
39+
// }
40+
41+
// // (2) Write current information
42+
// elecstate::DensityMatrix<std::complex<double>, double>* tmp_DM
43+
// = dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->get_DM();
44+
// if (TD_info::out_current)
45+
// {
46+
// if (TD_info::out_current_k)
47+
// {
48+
// ModuleIO::write_current_eachk(ucell,
49+
// istep,
50+
// this->psi,
51+
// this->pelec,
52+
// this->kv,
53+
// this->two_center_bundle_.overlap_orb.get(),
54+
// tmp_DM->get_paraV_pointer(),
55+
// this->orb_,
56+
// this->velocity_mat,
57+
// this->RA);
58+
// }
59+
// else
60+
// {
61+
// ModuleIO::write_current(ucell,
62+
// istep,
63+
// this->psi,
64+
// this->pelec,
65+
// this->kv,
66+
// this->two_center_bundle_.overlap_orb.get(),
67+
// tmp_DM->get_paraV_pointer(),
68+
// this->orb_,
69+
// this->velocity_mat,
70+
// this->RA);
71+
// }
72+
// }
73+
74+
// // (3) Output file for restart
75+
// if (PARAM.inp.out_freq_ion > 0) // default value of out_freq_ion is 0
76+
// {
77+
// if (istep % PARAM.inp.out_freq_ion == 0)
78+
// {
79+
// td_p->out_restart_info(istep, elecstate::H_TDDFT_pw::At, elecstate::H_TDDFT_pw::At_laststep);
80+
// }
81+
// }
82+
83+
// (1) Write dipole information
84+
for (int is = 0; is < PARAM.inp.nspin; ++is)
85+
{
86+
if (PARAM.inp.out_dipole == 1)
87+
{
88+
std::stringstream ss_dipole;
89+
ss_dipole << PARAM.globalv.global_out_dir << "dipole_s" << is + 1 << ".txt";
90+
ModuleIO::write_dipole(ucell, rho_save[is], rhopw, is, istep, ss_dipole.str());
91+
}
92+
}
93+
94+
// (2) Write current information
95+
const elecstate::ElecStateLCAO<std::complex<double>>* pelec_lcao
96+
= dynamic_cast<const elecstate::ElecStateLCAO<std::complex<double>>*>(pelec);
97+
98+
if (!pelec_lcao)
99+
{
100+
ModuleBase::WARNING_QUIT("ModuleIO::ctrl_output_td", "Failed to cast ElecState to ElecStateLCAO");
101+
}
102+
103+
if (TD_info::out_current)
104+
{
105+
if (TD_info::out_current_k)
106+
{
107+
ModuleIO::write_current_eachk<TR>(ucell, istep, psi, pelec, kv, intor, pv, orb, velocity_mat, RA);
108+
}
109+
else
110+
{
111+
ModuleIO::write_current<TR>(ucell, istep, psi, pelec, kv, intor, pv, orb, velocity_mat, RA);
112+
}
113+
}
114+
115+
// (3) Output file for restart
116+
if (PARAM.inp.out_freq_ion > 0) // default value of out_freq_ion is 0
117+
{
118+
if (istep % PARAM.inp.out_freq_ion == 0)
119+
{
120+
if (td_p != nullptr)
121+
{
122+
td_p->out_restart_info(istep, elecstate::H_TDDFT_pw::At, elecstate::H_TDDFT_pw::At_laststep);
123+
}
124+
else
125+
{
126+
ModuleBase::WARNING_QUIT("ModuleIO::ctrl_output_td",
127+
"TD_info pointer is null, cannot output restart info.");
128+
}
129+
}
130+
}
131+
}
132+
133+
template void ctrl_output_td<double>(const UnitCell&,
134+
double**,
135+
const ModulePW::PW_Basis*,
136+
const int,
137+
const psi::Psi<std::complex<double>>*,
138+
const elecstate::ElecState*,
139+
const K_Vectors&,
140+
const TwoCenterIntegrator*,
141+
const Parallel_Orbitals*,
142+
const LCAO_Orbitals&,
143+
const Velocity_op<double>*,
144+
Record_adj&,
145+
TD_info*);
146+
147+
template void ctrl_output_td<std::complex<double>>(const UnitCell&,
148+
double**,
149+
const ModulePW::PW_Basis*,
150+
const int,
151+
const psi::Psi<std::complex<double>>*,
152+
const elecstate::ElecState*,
153+
const K_Vectors&,
154+
const TwoCenterIntegrator*,
155+
const Parallel_Orbitals*,
156+
const LCAO_Orbitals&,
157+
const Velocity_op<std::complex<double>>*,
158+
Record_adj&,
159+
TD_info*);
160+
161+
} // namespace ModuleIO

source/source_io/ctrl_output_td.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef CTRL_OUTPUT_TD_H
2+
#define CTRL_OUTPUT_TD_H
3+
4+
#include "source_basis/module_ao/ORB_read.h"
5+
#include "source_basis/module_ao/parallel_orbitals.h"
6+
#include "source_basis/module_nao/two_center_bundle.h"
7+
#include "source_cell/unitcell.h"
8+
#include "source_estate/elecstate_lcao.h"
9+
#include "source_estate/module_pot/H_TDDFT_pw.h"
10+
#include "source_lcao/module_rt/td_info.h"
11+
#include "source_lcao/module_rt/velocity_op.h"
12+
#include "source_lcao/record_adj.h"
13+
#include "source_psi/psi.h"
14+
15+
namespace ModuleIO
16+
{
17+
18+
template <typename TR>
19+
void ctrl_output_td(const UnitCell& ucell,
20+
double** rho_save,
21+
const ModulePW::PW_Basis* rhopw,
22+
const int istep,
23+
const psi::Psi<std::complex<double>>* psi,
24+
const elecstate::ElecState* pelec,
25+
const K_Vectors& kv,
26+
const TwoCenterIntegrator* intor,
27+
const Parallel_Orbitals* pv,
28+
const LCAO_Orbitals& orb,
29+
const Velocity_op<TR>* velocity_mat,
30+
Record_adj& RA,
31+
TD_info* td_p);
32+
33+
} // namespace ModuleIO
34+
35+
#endif // CTRL_OUTPUT_TD_H

0 commit comments

Comments
 (0)