Skip to content

Commit d48a646

Browse files
authored
Update the output formats of rt-TDDFT (#6381)
* update the output formats of rt-TDDFT * update the output formats of rt-TDDFT * fix a bug * update initialized velocities * found some output information is still lacking in MD module
1 parent 9cfddf3 commit d48a646

File tree

6 files changed

+33
-109
lines changed

6 files changed

+33
-109
lines changed

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,8 @@ template <typename TR, typename Device>
229229
void ESolver_KS_LCAO_TDDFT<TR, Device>::print_step()
230230
{
231231
std::cout << " -------------------------------------------" << std::endl;
232-
GlobalV::ofs_running << "\n -------------------------------------------" << std::endl;
233232
std::cout << " STEP OF ELECTRON EVOLVE : " << unsigned(totstep) << std::endl;
234-
GlobalV::ofs_running << " STEP OF ELECTRON EVOLVE : " << unsigned(totstep) << std::endl;
235233
std::cout << " -------------------------------------------" << std::endl;
236-
GlobalV::ofs_running << " -------------------------------------------" << std::endl;
237234
}
238235
template <typename TR, typename Device>
239236
void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
@@ -321,10 +318,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
321318
// print occupation of each band
322319
if (iter == 1 && istep <= 2)
323320
{
324-
GlobalV::ofs_running << " ---------------------------------------------------------"
325-
<< std::endl;
326-
GlobalV::ofs_running << " occupations of electrons" << std::endl;
327-
GlobalV::ofs_running << " k-point state occupation" << std::endl;
321+
GlobalV::ofs_running << " k-point State Occupations" << std::endl;
328322
GlobalV::ofs_running << std::setiosflags(std::ios::showpoint);
329323
GlobalV::ofs_running << std::left;
330324
std::setprecision(6);
@@ -337,8 +331,6 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
337331
<< std::setw(12) << this->pelec->wg(ik, ib) << std::endl;
338332
}
339333
}
340-
GlobalV::ofs_running << " ---------------------------------------------------------"
341-
<< std::endl;
342334
}
343335

344336
ESolver_KS_LCAO<std::complex<double>, TR>::iter_finish(ucell, istep, iter, conv_esolver);
@@ -471,32 +463,6 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::update_pot(UnitCell& ucell,
471463
}
472464
}
473465

474-
// print "eigen value" for tddft
475-
// it seems uncessary to print out E_ii because the band energies are printed
476-
/*
477-
if (conv_esolver)
478-
{
479-
GlobalV::ofs_running << "----------------------------------------------------------"
480-
<< std::endl;
481-
GlobalV::ofs_running << " Print E=<psi_i|H|psi_i> " << std::endl;
482-
GlobalV::ofs_running << " k-point state energy (eV)" << std::endl;
483-
GlobalV::ofs_running << "----------------------------------------------------------"
484-
<< std::endl;
485-
GlobalV::ofs_running << std::setprecision(6);
486-
GlobalV::ofs_running << std::setiosflags(std::ios::showpoint);
487-
488-
for (int ik = 0; ik < this->kv.get_nks(); ik++)
489-
{
490-
for (int ib = 0; ib < PARAM.inp.nbands; ib++)
491-
{
492-
GlobalV::ofs_running << " " << std::setw(7) << ik + 1
493-
<< std::setw(7) << ib + 1
494-
<< std::setw(10) << this->pelec->ekb(ik, ib) * ModuleBase::Ry_to_eV
495-
<< std::endl;
496-
}
497-
}
498-
}
499-
*/
500466
}
501467

502468
template <typename TR, typename Device>
@@ -555,7 +521,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell, const int ist
555521
}
556522
}
557523
// (3) output energy for sub loop
558-
std::cout << "Potential (Ry): " << std::setprecision(15) << this->pelec->f_en.etot <<std::endl;
524+
std::cout << " Potential (Ry): " << std::setprecision(15) << this->pelec->f_en.etot <<std::endl;
559525

560526
// (4) output file for restart
561527
if(istep % PARAM.inp.out_interval == 0)

source/source_estate/elecstate_print.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ void print_etot(const Magnetism& magnet,
175175
const int nrxx = elec.charge->nrxx;
176176
const int nxyz = elec.charge->nxyz;
177177

178-
GlobalV::ofs_running << std::setprecision(12);
178+
GlobalV::ofs_running << std::setprecision(6);
179179
GlobalV::ofs_running << std::setiosflags(std::ios::right);
180180

181-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron density deviation",scf_thr);
181+
GlobalV::ofs_running << " Electron density deviation " << scf_thr << std::endl;
182182

183183
if (PARAM.inp.basis_type == "pw")
184184
{

source/source_estate/test/elecstate_print_test.cpp

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ TEST_F(ElecStatePrintTest, PrintEtot)
184184
GlobalV::ofs_running.close();
185185
ifs.open("test.dat", std::ios::in);
186186
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
187-
EXPECT_THAT(str, testing::HasSubstr("Electron density deviation = 0.1"));
187+
EXPECT_THAT(str, testing::HasSubstr("Electron density deviation 0.1"));
188188
EXPECT_THAT(str, testing::HasSubstr("Diago Threshold = 0.1"));
189189
EXPECT_THAT(str, testing::HasSubstr("E_KohnSham"));
190190
EXPECT_THAT(str, testing::HasSubstr("E_vdwD2"));
@@ -198,49 +198,6 @@ TEST_F(ElecStatePrintTest, PrintEtot)
198198
std::remove("test.dat");
199199
}
200200

201-
/*
202-
TEST_F(ElecStatePrintTest, PrintEtot2)
203-
{
204-
GlobalV::ofs_running.open("test.dat", std::ios::out);
205-
bool converged = false;
206-
int iter = 1;
207-
double scf_thr = 0.1;
208-
double scf_thr_kin = 0.0;
209-
double duration = 2.0;
210-
double pw_diag_thr = 0.1;
211-
int avg_iter = 2;
212-
bool print = true;
213-
PARAM.input.out_freq_elec = 0;
214-
elecstate.charge = new Charge;
215-
elecstate.charge->nrxx = 100;
216-
elecstate.charge->nxyz = 1000;
217-
PARAM.input.imp_sol = true;
218-
PARAM.input.efield_flag = true;
219-
PARAM.input.gate_flag = true;
220-
PARAM.sys.two_fermi = false;
221-
PARAM.input.out_bandgap = true;
222-
GlobalV::MY_RANK = 0;
223-
PARAM.input.basis_type = "pw";
224-
PARAM.input.scf_nmax = 100;
225-
226-
elecstate::print_etot(ucell.magnet,elecstate,converged, iter, scf_thr, scf_thr_kin, duration,
227-
pw_diag_thr, avg_iter, print);
228-
229-
GlobalV::ofs_running.close();
230-
ifs.open("test.dat", std::ios::in);
231-
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
232-
EXPECT_THAT(str, testing::HasSubstr("Electron density deviation = 0.1"));
233-
EXPECT_THAT(str, testing::HasSubstr("Diago Threshold = 0.1"));
234-
EXPECT_THAT(str, testing::HasSubstr("E_KohnSham"));
235-
EXPECT_THAT(str, testing::HasSubstr("E_Harris"));
236-
EXPECT_THAT(str, testing::HasSubstr("E_Fermi"));
237-
EXPECT_THAT(str, testing::HasSubstr("E_bandgap"));
238-
ifs.close();
239-
delete elecstate.charge;
240-
std::remove("test.dat");
241-
}
242-
*/
243-
244201
TEST_F(ElecStatePrintTest, PrintEtotColorS2)
245202
{
246203
bool converged = false;

source/source_io/output_log.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ void print_force(std::ofstream& ofs_running,
249249
force_x.push_back(fx);
250250
force_y.push_back(fy);
251251
force_z.push_back(fz);
252-
253252
iat++;
254253
}
255254
}
@@ -258,16 +257,17 @@ void print_force(std::ofstream& ofs_running,
258257
FmtTable fmt(/*titles=*/titles,
259258
/*nrows=*/atom_label.size(),
260259
/*formats=*/{"%8s", "%20.10f", "%20.10f", "%20.10f"},
261-
0,
260+
/*indent*/1,
262261
{FmtTable::Align::RIGHT,FmtTable::Align::RIGHT});
263262

263+
264264
fmt << atom_label << force_x << force_y << force_z;
265265
table = fmt.str();
266-
ofs_running << table << std::endl;
266+
ofs_running << table;
267267

268268
if (PARAM.inp.test_force)
269269
{
270-
std::cout << table << std::endl;
270+
std::cout << table;
271271
}
272272
}
273273

@@ -311,9 +311,11 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs,
311311

312312
FmtTable fmt(/*titles=*/titles,
313313
/*nrows=*/3,
314-
/*formats=*/{"%20.10f", "%20.10f", "%20.10f"}, 0,
314+
/*formats=*/{"%20.10f", "%20.10f", "%20.10f"},
315+
/*indent*/1,
315316
{FmtTable::Align::RIGHT,FmtTable::Align::RIGHT});
316317

318+
317319
fmt << stress_x << stress_y << stress_z;
318320
table = fmt.str();
319321
ofs << table;
@@ -338,25 +340,23 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs,
338340

339341
void write_head(std::ofstream& ofs, const int& istep, const int& iter, const std::string& basisname)
340342
{
343+
ofs << std::right;
341344
ofs << "\n";
342345
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
343-
ofs << " --> IONIC RELAXATION STEP=" << std::setw(6) << istep+1
344-
<< " ELECTRONIC ITERATION STEP=" << std::setw(6) << iter << "\n";
346+
ofs << " --> #ION MOVE#" << std::setw(10) << istep+1
347+
<< " #ELEC ITER#" << std::setw(10) << iter << "\n";
345348
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
346349

347-
// ofs << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1
348-
// << " ELEC=" << std::setw(4) << iter << "--------------------------------\n";
349350
}
350351
void write_head_td(std::ofstream& ofs, const int& istep, const int& estep, const int& iter, const std::string& basisname)
351352
{
353+
ofs << std::right;
352354
ofs << "\n";
353-
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
354-
ofs << " --> IONIC RELAXATION STEP=" << std::setw(6) << istep+1
355-
<< " ELECTRON PROPAGATION STEP=" << std::setw(6) << estep
356-
<< " ELECTRONIC ITERATION STEP=" << std::setw(6) << iter << "\n";
357-
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
358-
359-
// ofs << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1
360-
// << " ELEC=" << std::setw(4) << estep << " iter=" << std::setw(4) << iter << "--------------------------------\n";
355+
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
356+
ofs << " --> #ION MOVE#" << std::setw(10) << istep+1
357+
<< " #ELEC PROP#" << std::setw(10) << estep+1
358+
<< " #ELEC ITER#" << std::setw(10) << iter << "\n";
359+
ofs << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<< std::endl;
360+
361361
}
362362
}// namespace ModuleIO

source/source_md/md_base.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#endif
66
#include "source_io/print_info.h"
77
#include "source_cell/update_cell.h"
8-
MD_base::MD_base(const Parameter& param_in, UnitCell& unit_in) : mdp(param_in.mdp), ucell(unit_in)
8+
MD_base::MD_base(const Parameter& param_in, UnitCell& unit_in)
9+
: mdp(param_in.mdp), ucell(unit_in)
910
{
1011
my_rank = param_in.globalv.myrank;
1112
cal_stress = param_in.inp.cal_stress;
@@ -159,6 +160,7 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
159160
}
160161

161162
// screen output
163+
std::cout << std::setprecision(8);
162164
std::cout << " ------------------------------------------------------------------------------------------------"
163165
<< std::endl;
164166
std::cout << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"

source/source_md/md_func.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ void init_vel(const UnitCell& unit_in,
192192
ModuleBase::Vector3<int>* ionmbl,
193193
ModuleBase::Vector3<double>* vel)
194194
{
195-
std::cout << " ----------------------------------- INIT VEL ---------------------------------------" << std::endl;
196195
ModuleBase::Vector3<int> frozen;
197196
get_mass_mbl(unit_in, allmass, frozen, ionmbl);
198197
frozen_freedom = frozen.x + frozen.y + frozen.z;
@@ -211,38 +210,38 @@ void init_vel(const UnitCell& unit_in,
211210

212211
if (unit_in.init_vel)
213212
{
214-
std::cout << " READ VEL FROM STRU" << std::endl;
213+
std::cout << " Reading velocities from STRU file" << std::endl;
215214
read_vel(unit_in, vel);
216215
double kinetic = 0.0;
217216
double t_current = MD_func::current_temp(kinetic, unit_in.nat, frozen_freedom, allmass, vel);
218217
if (restart)
219218
{
220-
std::cout << " RESTART MD, CURRENT TEMPERATURE IS " << t_current * ModuleBase::Hartree_to_K << " K"
219+
std::cout << " Restart MD, current temperature is " << t_current * ModuleBase::Hartree_to_K << " K"
221220
<< std::endl;
222221
}
223222
else if (temperature < 0)
224223
{
225-
std::cout << " UNSET INITIAL TEMPERATURE, AUTOSET TO " << t_current * ModuleBase::Hartree_to_K << " K"
224+
std::cout << " Autoset the initial tempearture to " << t_current * ModuleBase::Hartree_to_K << " K"
226225
<< std::endl;
227226
temperature = t_current;
228227
}
229228
else
230229
{
231-
std::cout << " INITIAL TEMPERATURE IN INPUT = " << temperature * ModuleBase::Hartree_to_K << " K"
230+
std::cout << " Initial temeprature from INPUT is " << temperature * ModuleBase::Hartree_to_K << " K"
232231
<< std::endl;
233-
std::cout << " READING TEMPERATURE FROM STRU = " << t_current * ModuleBase::Hartree_to_K << " K"
232+
std::cout << " Reading temperature from STRU is " << t_current * ModuleBase::Hartree_to_K << " K"
234233
<< std::endl;
235-
std::cout << " RESCALE VEL TO INITIAL TEMPERATURE" << std::endl;
234+
std::cout << " Rescale velocties to initial temperature" << std::endl;
236235
rescale_vel(unit_in.nat, temperature, allmass, frozen_freedom, vel);
237236
}
238237
}
239238
else
240239
{
241-
std::cout << " RANDOM VEL ACCORDING TO INITIAL TEMPERATURE: " << temperature * ModuleBase::Hartree_to_K << " K"
240+
std::cout << " Random velocities according to initial temperature "
241+
<< temperature * ModuleBase::Hartree_to_K << " K"
242242
<< std::endl;
243243
rand_vel(unit_in.nat, temperature, allmass, frozen_freedom, frozen, ionmbl, my_rank, vel);
244244
}
245-
std::cout << " ------------------------------------- DONE -----------------------------------------" << std::endl;
246245
}
247246

248247
void force_virial(ModuleESolver::ESolver* p_esolver,

0 commit comments

Comments
 (0)