Skip to content

Commit d5fd3fe

Browse files
committed
Add a new parameter out_freq_td
1 parent 4e67212 commit d5fd3fe

23 files changed

Lines changed: 550 additions & 483 deletions

docs/advanced/input_files/input-main.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
- [cell\_factor](#cell_factor)
136136
- [Output Variables](#variables-related-to-output-information)
137137
- [out\_freq\_ion](#out_freq_ion)
138+
- [out\_freq\_td](#out_freq_td)
138139
- [out\_freq\_elec](#out_freq_elec)
139140
- [out\_chg](#out_chg)
140141
- [out\_pot](#out_pot)
@@ -535,7 +536,7 @@ These variables are used to control general system parameters.
535536
- ofdft: orbital-free density functional theory
536537
- tdofdft: time-dependent orbital-free density functional theory
537538
- sdft: [stochastic density functional theory](#electronic-structure-sdft)
538-
- tddft: real-time time-dependent density functional theory (TDDFT)
539+
- tddft: real-time time-dependent density functional theory (RT-TDDFT)
539540
- lj: Leonard Jones potential
540541
- dp: DeeP potential, see details in [md.md](../md.md#dpmd)
541542
- nep: Neuroevolution Potential, see details in [md.md](../md.md#nep)
@@ -1688,15 +1689,22 @@ These variables are used to control the output of properties.
16881689
### out_freq_ion
16891690

16901691
- **Type**: Integer
1691-
- **Description**: Control the interval to print information every few ion steps. These properties cover charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, Mulliken population analysis and so on.
1692+
- **Description**: Controls the output interval in **ionic steps**. When set to a positive integer $N$, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, and Mulliken population analysis is printed every $N$ ionic steps.
16921693
- **Default**: 0
1693-
- **Note**: The integer indicates to print information every 'out_freq_ion' ion steps.
1694+
- **Note**: In RT-TDDFT calculations, this parameter is temporarily inactive; output frequency is instead controlled by [`out_freq_td`](#out_freq_td)—see its description for details.
1695+
1696+
### out_freq_td
1697+
1698+
- **Type**: Integer
1699+
- **Description**: Controls the output interval in **completed electronic evolution steps** during RT-TDDFT calculations. When set to a positive integer $N$, detailed information (see [`out_freq_ion`](#out_freq_ion)) is printed every $N$ electron time-evolution steps (i.e., every $N$ `STEP OF ELECTRON EVOLVE`).
1700+
- **Default**: 0
1701+
- **Note**: This parameter is **only active in RT-TDDFT mode** (`esolver_type = tddft`). It has no effect in ground-state calculations.
16941702

16951703
### out_freq_elec
16961704

16971705
- **Type**: Integer
1698-
- **Description**: Output the charge density (only binary format, controlled by [out_chg](#out_chg)), wavefunction (controlled by [out_wfc_pw](#out_wfc_pw)) per `out_freq_elec` electronic iterations. Note that they are always output when converged or reach the maximum iterations [scf_nmax](#scf_nmax).
1699-
- **Default**: [scf_nmax](#scf_nmax)
1706+
- **Description**: Output the charge density (only binary format, controlled by [`out_chg`](#out_chg)), wavefunction (controlled by [`out_wfc_pw`](#out_wfc_pw)) per `out_freq_elec` electronic iterations. Note that they are always output when converged or reach the maximum iterations [`scf_nmax`](#scf_nmax).
1707+
- **Default**: [`scf_nmax`](#scf_nmax)
17001708

17011709
### out_chg
17021710

source/source_esolver/esolver_fp.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
9595
return;
9696
}
9797

98-
void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
98+
void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver)
9999
{
100100
ModuleBase::TITLE("ESolver_FP", "after_scf");
101101

@@ -109,9 +109,15 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
109109
CE.update_delta_rho(ucell, &(this->chr), &(this->sf));
110110

111111
//! print out charge density, potential, elf, etc.
112-
ModuleIO::ctrl_output_fp(ucell, this->pelec, this->pw_big, this->pw_rhod,
113-
this->chr, this->solvent, this->Pgrid, istep);
114-
112+
ModuleIO::ctrl_output_fp(ucell,
113+
this->pelec,
114+
this->pw_big,
115+
this->pw_rhod,
116+
this->chr,
117+
this->solvent,
118+
this->Pgrid,
119+
istep,
120+
totstep);
115121
}
116122

117123
void ESolver_FP::before_scf(UnitCell& ucell, const int istep)

source/source_esolver/esolver_fp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class ESolver_FP: public ESolver
4343
protected:
4444
virtual void before_scf(UnitCell& ucell, const int istep);
4545

46-
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver);
46+
// totstep is only used in RT-TDDFT, representing the number of completed electronic iterations
47+
// for ground-state DFT, totstep == istep
48+
virtual void after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver);
4749

4850
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool &conv_esolver);
4951

source/source_esolver/esolver_ks.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
169169
} // end scf iterations
170170

171171
// 7) after scf
172-
this->after_scf(ucell, istep, conv_esolver);
172+
this->after_scf(ucell, istep, istep, conv_esolver);
173173

174174
ModuleBase::timer::tick(this->classname, "runner");
175175
return;
@@ -306,7 +306,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
306306

307307
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
308308
template <typename T, typename Device>
309-
void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
309+
void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver)
310310
{
311311
ModuleBase::TITLE("ESolver_KS", "after_scf");
312312

@@ -320,14 +320,13 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
320320
*/
321321

322322
// 2) call after_scf() of ESolver_FP
323-
ESolver_FP::after_scf(ucell, istep, conv_esolver);
323+
ESolver_FP::after_scf(ucell, istep, totstep, conv_esolver);
324324

325325
// 3) write eigenvalues and occupations to eig_occ.txt
326-
ModuleIO::write_eig_file(this->pelec->ekb, this->pelec->wg, this->kv, istep);
326+
ModuleIO::write_eig_file(this->pelec->ekb, this->pelec->wg, this->kv, totstep);
327327

328328
// 4) write band information to band.txt
329329
ModuleIO::write_bands(PARAM.inp, this->pelec->ekb, this->kv);
330-
331330
}
332331

333332
template <typename T, typename Device>

source/source_esolver/esolver_ks.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class ESolver_KS : public ESolver_FP
4545
void hamilt2rho(UnitCell& ucell, const int istep, const int iter, const double ethr);
4646

4747
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
48-
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
48+
virtual void after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver) override;
49+
// totstep is only used in RT-TDDFT, representing the number of completed electronic iterations
50+
// for ground-state DFT, totstep == istep
4951

5052
//! Hamiltonian
5153
hamilt::Hamilt<T, Device>* p_hamilt = nullptr;

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
505505
}
506506

507507
template <typename TK, typename TR>
508-
void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
508+
void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver)
509509
{
510510
ModuleBase::TITLE("ESolver_KS_LCAO", "after_scf");
511511
ModuleBase::timer::tick("ESolver_KS_LCAO", "after_scf");
@@ -523,15 +523,32 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
523523
}
524524

525525
//! 1) call after_scf() of ESolver_KS
526-
ESolver_KS<TK>::after_scf(ucell, istep, conv_esolver);
526+
ESolver_KS<TK>::after_scf(ucell, istep, totstep, conv_esolver);
527527

528528
//! 2) output of lcao every few ionic steps
529529
ModuleIO::ctrl_scf_lcao<TK, TR>(ucell,
530-
PARAM.inp, this->kv, this->pelec, this->dmat.dm, this->pv,
531-
this->gd, this->psi, hamilt_lcao, this->dftu, this->two_center_bundle_,
532-
this->orb_, this->pw_wfc, this->pw_rho, this->pw_big, this->sf,
533-
this->rdmft_solver, this->deepks, this->exx_nao,
534-
this->conv_esolver, this->scf_nmax_flag, istep);
530+
PARAM.inp,
531+
this->kv,
532+
this->pelec,
533+
this->dmat.dm,
534+
this->pv,
535+
this->gd,
536+
this->psi,
537+
hamilt_lcao,
538+
this->dftu,
539+
this->two_center_bundle_,
540+
this->orb_,
541+
this->pw_wfc,
542+
this->pw_rho,
543+
this->pw_big,
544+
this->sf,
545+
this->rdmft_solver,
546+
this->deepks,
547+
this->exx_nao,
548+
this->conv_esolver,
549+
this->scf_nmax_flag,
550+
istep,
551+
totstep);
535552

536553
//! 3) Clean up RA, which is used to serach for adjacent atoms
537554
if (!PARAM.inp.cal_force && !PARAM.inp.cal_stress)

source/source_esolver/esolver_ks_lcao.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class ESolver_KS_LCAO : public ESolver_KS<TK>
5353

5454
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override;
5555

56-
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
56+
// totstep is only used in RT-TDDFT, representing the number of completed electronic iterations
57+
virtual void after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver) override;
5758

5859
virtual void others(UnitCell& ucell, const int istep) override;
5960

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
107107
{
108108
estep_max = PARAM.inp.estep_per_md + 1;
109109
}
110-
// reset laststep matrix and wfc, if any atom cross the boundary
110+
111+
// Reset laststep matrix and wfc, if any atom cross the boundary
112+
// Apply a phase correction to H, S, and psi to keep consistency when atoms cross periodic boundaries
111113
const size_t len_hs_ik = use_tensor && use_lapack ? PARAM.globalv.nlocal * PARAM.globalv.nlocal : this->pv.nloc;
112114
module_rt::reset_matrix_boundary(ucell,
113115
this->kv,
@@ -116,6 +118,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
116118
this->Sk_laststep,
117119
this->psi_laststep,
118120
len_hs_ik);
121+
119122
for (int estep = 0; estep < estep_max; estep++)
120123
{
121124
// calculate total time step
@@ -182,7 +185,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
182185
//----------------------------------------------------------------
183186
// 7) after_scf
184187
//----------------------------------------------------------------
185-
this->after_scf(ucell, totstep, conv_esolver);
188+
this->after_scf(ucell, istep, totstep, conv_esolver);
186189
if (!restart_done && PARAM.inp.mdp.md_restart)
187190
{
188191
restart_done = true;
@@ -458,12 +461,15 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::store_h_s_psi(UnitCell& ucell,
458461
}
459462

460463
template <typename TR, typename Device>
461-
void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
464+
void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell,
465+
const int istep,
466+
const int totstep,
467+
const bool conv_esolver)
462468
{
463469
ModuleBase::TITLE("ESolver_LCAO_TDDFT", "after_scf");
464470
ModuleBase::timer::tick(this->classname, "after_scf");
465471

466-
ESolver_KS_LCAO<std::complex<double>, TR>::after_scf(ucell, istep, conv_esolver);
472+
ESolver_KS_LCAO<std::complex<double>, TR>::after_scf(ucell, istep, totstep, conv_esolver);
467473

468474
// Output energy for sub-loop (electronic step)
469475
std::cout << " Potential (Ry): " << std::setprecision(15) << this->pelec->f_en.etot << std::endl;
@@ -473,6 +479,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell, const int ist
473479
this->chr.rho_save,
474480
this->chr.rhopw,
475481
istep,
482+
totstep,
476483
this->psi,
477484
this->pelec,
478485
this->kv,

source/source_esolver/esolver_ks_lcao_tddft.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, TR>
3535
int& iter,
3636
bool& conv_esolver);
3737

38-
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
38+
virtual void after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver) override;
3939

4040
void print_step();
4141

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
355355
}
356356

357357
template <typename T, typename Device>
358-
void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
358+
void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const int totstep, const bool conv_esolver)
359359
{
360360
ModuleBase::TITLE("ESolver_KS_PW", "after_scf");
361361
ModuleBase::timer::tick("ESolver_KS_PW", "after_scf");
@@ -370,7 +370,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
370370
}
371371

372372
// Call 'after_scf' of ESolver_KS
373-
ESolver_KS<T, Device>::after_scf(ucell, istep, conv_esolver);
373+
ESolver_KS<T, Device>::after_scf(ucell, istep, totstep, conv_esolver);
374374

375375
// Output quantities
376376
ModuleIO::ctrl_scf_pw<T, Device>(istep, ucell, this->pelec, this->chr, this->kv, this->pw_wfc,

0 commit comments

Comments
 (0)