Skip to content

Commit 35448cb

Browse files
authored
Update ABACUS output formats, accept it after 3.10 version (#6076)
* update some timers * update timer * update output formats * update print_cell * add ofs in print_tau * update print_tau * update output formats * update md outputs * beging modifying the autotests * update integrate tests * update some timers * fix total force and total stress * update integrate tests * update print_band * fix print_band * update md print out information * update print_stress * update print_stress in dp, but still has problems in lj * fix dp_test.cpp * update esolver_lj * set mulliken charge accuracy from 4 to 3 * update print force and print stress
1 parent 39b03c1 commit 35448cb

Some content is hidden

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

43 files changed

+565
-390
lines changed

source/driver.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@ Driver::~Driver()
2323

2424
void Driver::init()
2525
{
26-
ModuleBase::TITLE("Driver", "init");
26+
// 1) Let's start by printing a title.
27+
ModuleBase::TITLE("Driver", "ABACUS_begins");
2728

29+
// 2) Print the current time, since it may run a long time.
2830
time_t time_start = std::time(nullptr);
2931
ModuleBase::timer::start();
3032

31-
// (1) read the input parameters.
32-
// INPUT should be initalized here and then pass to atomic world, mohan
33-
// 2024-05-12 INPUT should not be GlobalC, mohan 2024-05-12
34-
Driver::reading();
35-
36-
// (2) welcome to the atomic world!
33+
// 3) Welcome to the atomic world! Let's do some fancy stuff here.
3734
this->atomic_world();
3835

39-
// (3) output information
36+
// 4) All timers recorders are printed.
37+
ModuleBase::timer::finish(GlobalV::ofs_running);
38+
39+
// 5) All memory recorders are printed.
40+
ModuleBase::Memory::print_all(GlobalV::ofs_running);
41+
42+
// 6) Print the final time, hopefully it will not cost too long.
4043
time_t time_finish = std::time(nullptr);
4144
ModuleIO::print_time(time_start, time_finish);
4245

43-
// (4) close all of the running logs
46+
// 7) Clean up: close all of the running logs
4447
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog,PARAM.inp.calculation);
4548

4649
}
@@ -169,16 +172,13 @@ void Driver::reading()
169172
void Driver::atomic_world()
170173
{
171174
ModuleBase::TITLE("Driver", "atomic_world");
172-
//--------------------------------------------------
173-
// choose basis sets:
174-
// pw: plane wave basis set
175-
// lcao_in_pw: LCAO expaned by plane wave basis set
176-
// lcao: linear combination of atomic orbitals
177-
//--------------------------------------------------
175+
ModuleBase::timer::tick("Driver", "atomic_world");
176+
177+
// reading information
178+
this->reading();
178179

179180
// where the actual stuff is done
180181
this->driver_run();
181182

182-
ModuleBase::timer::finish(GlobalV::ofs_running);
183-
ModuleBase::Memory::print_all(GlobalV::ofs_running);
183+
ModuleBase::timer::tick("Driver", "atomic_world");
184184
}

source/driver_run.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
*/
2626
void Driver::driver_run()
2727
{
28-
ModuleBase::TITLE("Driver", "driver_line");
28+
ModuleBase::TITLE("Driver", "driver_run");
2929

3030
//! 1: setup cell and atom information
3131
// this warning should not be here, mohan 2024-05-22
3232
#ifndef __LCAO
3333
if (PARAM.inp.basis_type == "lcao_in_pw" || PARAM.inp.basis_type == "lcao") {
34+
ModuleBase::timer::tick("Driver","driver_run");
3435
ModuleBase::WARNING_QUIT("driver",
3536
"to use LCAO basis, compile with __LCAO");
3637
}
@@ -92,5 +93,6 @@ void Driver::driver_run()
9293

9394
//! 6: output the json file
9495
Json::create_Json(&ucell, PARAM);
96+
9597
return;
9698
}

source/module_base/memory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ void Memory::print_all(std::ofstream &ofs)
385385
Parallel_Reduce::reduce_all(Memory::total_gpu);
386386
#endif
387387
#endif
388-
ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl;
389-
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
388+
ofs <<"\n NAME-------------------------|MEMORY(MB)------------------" << std::endl;
389+
ofs << std::right;
390+
ofs << std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
390391

391392
assert(n_memory>0);
392393

@@ -440,7 +441,7 @@ void Memory::print_all(std::ofstream &ofs)
440441
return;
441442
}
442443

443-
ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl;
444+
ofs <<"\n NAME-------------------------|GPU MEMORY(MB)--------------" << std::endl;
444445
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total_gpu << std::endl;
445446

446447
assert(n_memory>0);

source/module_cell/module_neighbor/sltk_atom_arrange.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ void atom_arrange::search(const bool pbc_flag,
7474
ModuleBase::WARNING_QUIT("atom_arrange::search", " search_radius_bohr < 0,forbidden");
7575
}
7676

77-
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr))", search_radius_bohr);
78-
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr))", ucell.lat0);
77+
ofs_in << " SEARCH ADJACENT ATOMS" << std::endl;
78+
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr)", search_radius_bohr);
79+
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr)", ucell.lat0);
7980

8081
assert(ucell.nat > 0);
8182

source/module_cell/module_neighbor/sltk_grid.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
195195
}
196196
}
197197
}
198-
ModuleBase::GlobalFunc::OUT(ofs_in, "Find the coordinate range of the input atom(unit:lat0).");
199-
ModuleBase::GlobalFunc::OUT(ofs_in, "min_tau", x_min, y_min, z_min);
200-
ModuleBase::GlobalFunc::OUT(ofs_in, "max_tau", x_max, y_max, z_max);
198+
199+
ofs_in << " RANGE OF ATOMIC COORDINATES (unit: lat0)" << std::endl;
200+
ModuleBase::GlobalFunc::OUT(ofs_in, "smallest coordinates of atoms", x_min, y_min, z_min);
201+
ModuleBase::GlobalFunc::OUT(ofs_in, "largest coordinates of atoms", x_max, y_max, z_max);
201202

202203
this->box_edge_length = sradius + 0.1; // To avoid edge cases, the size of the box is slightly increased.
203204

@@ -220,7 +221,7 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
220221
this->box_nx = glayerX + glayerX_minus;
221222
this->box_ny = glayerY + glayerY_minus;
222223
this->box_nz = glayerZ + glayerZ_minus;
223-
ModuleBase::GlobalFunc::OUT(ofs_in, "BoxNumber", box_nx, box_ny, box_nz);
224+
ModuleBase::GlobalFunc::OUT(ofs_in, "number of needed cells", box_nx, box_ny, box_nz);
224225

225226
atoms_in_box.resize(this->box_nx);
226227
for (int i = 0; i < this->box_nx; i++)

source/module_cell/print_cell.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace unitcell
1111
void print_tau(Atom* atoms,
1212
const std::string& Coordinate,
1313
const int ntype,
14-
const double lat0)
14+
const double lat0,
15+
std::ofstream &ofs)
1516
{
1617
ModuleBase::TITLE("UnitCell", "print_tau");
1718
// assert (direct || Coordinate == "Cartesian" || Coordinate == "Cartesian_angstrom"); // this line causes abort in unittest ReadAtomPositionsCACXY.
@@ -22,7 +23,7 @@ namespace unitcell
2223
assert(std::regex_search(Coordinate, pattern));
2324
bool direct = (Coordinate == "Direct");
2425
std::string table;
25-
table += direct? "DIRECT COORDINATES\n": FmtCore::format("CARTESIAN COORDINATES ( UNIT = %20.12f Bohr ).\n", lat0);
26+
table += direct? "DIRECT COORDINATES\n": FmtCore::format(" CARTESIAN COORDINATES ( UNIT = %15.8f Bohr ).\n", lat0);
2627
table += FmtCore::format("%8s%10s%10s%10s%8s%8s%8s%8s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz");
2728
for(int it = 0; it < ntype; it++)
2829
{
@@ -43,7 +44,7 @@ namespace unitcell
4344
}
4445
}
4546
table += "\n";
46-
GlobalV::ofs_running << table << std::endl;
47+
ofs << table << std::endl;
4748
return;
4849
}
4950

source/module_cell/print_cell.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace unitcell
88
void print_tau(Atom* atoms,
99
const std::string& Coordinate,
1010
const int ntype,
11-
const double lat0);
11+
const double lat0,
12+
std::ofstream &ofs);
1213

1314
/**
1415
* @brief UnitCell class is too heavy, this function would be moved
@@ -40,4 +41,4 @@ namespace unitcell
4041
const int& iproc = 0);
4142
}
4243

43-
#endif
44+
#endif

source/module_cell/read_atoms.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ bool read_atom_positions(UnitCell& ucell,
514514
ucell.atoms[it].m_loc_[ia].x = 1.0;
515515
ucell.atoms[it].m_loc_[ia].y = 1.0;
516516
ucell.atoms[it].m_loc_[ia].z = 1.0;
517-
ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2)+pow(ucell.atoms[it].m_loc_[ia].y,2)+pow(ucell.atoms[it].m_loc_[ia].z,2));
517+
ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2)
518+
+pow(ucell.atoms[it].m_loc_[ia].y,2)
519+
+pow(ucell.atoms[it].m_loc_[ia].z,2));
518520
ModuleBase::GlobalFunc::OUT(ofs_running,"Autoset magnetism for this atom", 1.0, 1.0, 1.0);
519521
}
520522
}
@@ -535,13 +537,14 @@ bool read_atom_positions(UnitCell& ucell,
535537
// End Autoset magnetization
536538
} // end scan_begin
537539

538-
//check if any atom can move in MD
540+
//check if any atom can move in MD
539541
if(!ucell.if_atoms_can_move() && PARAM.inp.calculation=="md" && PARAM.inp.esolver_type!="tddft")
540542
{
541543
ModuleBase::WARNING("read_atoms", "no atom can move in MD!");
542544
return false;
543545
}
544546

547+
545548
ofs_running << std::endl;
546549
ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",ucell.nat);
547550

@@ -556,7 +559,7 @@ bool read_atom_positions(UnitCell& ucell,
556559

557560
if (unitcell::check_tau(ucell.atoms, ucell.ntype, ucell.lat0))
558561
{
559-
unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0);
562+
unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,ofs_running);
560563
return true;
561564
}
562565
return false;

source/module_cell/test/unitcell_test.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,17 +1010,23 @@ TEST_F(UcellTest, PrintTauDirect)
10101010
UcellTestPrepare utp = UcellTestLib["C1H2-Index"];
10111011
PARAM.input.relax_new = utp.relax_new;
10121012
ucell = utp.SetUcellInfo();
1013-
GlobalV::ofs_running.open("print_tau_direct");
10141013
EXPECT_EQ(ucell->Coordinate, "Direct");
1015-
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0);
1016-
GlobalV::ofs_running.close();
1014+
1015+
// open a file
1016+
std::ofstream ofs("print_tau_direct");
1017+
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs);
1018+
ofs.close();
1019+
1020+
// readin the data
10171021
std::ifstream ifs;
10181022
ifs.open("print_tau_direct");
10191023
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
10201024
EXPECT_THAT(str, testing::HasSubstr("DIRECT COORDINATES"));
10211025
EXPECT_THAT(str, testing::HasSubstr(" C 0.100 0.100 0.100 0.000 0.100 0.100 0.100"));
10221026
EXPECT_THAT(str, testing::HasSubstr(" H 0.150 0.150 0.150 0.000 0.100 0.100 0.100"));
10231027
ifs.close();
1028+
1029+
// remove the file
10241030
remove("print_tau_direct");
10251031
}
10261032

@@ -1029,17 +1035,23 @@ TEST_F(UcellTest, PrintTauCartesian)
10291035
UcellTestPrepare utp = UcellTestLib["C1H2-Cartesian"];
10301036
PARAM.input.relax_new = utp.relax_new;
10311037
ucell = utp.SetUcellInfo();
1032-
GlobalV::ofs_running.open("print_tau_Cartesian");
10331038
EXPECT_EQ(ucell->Coordinate, "Cartesian");
1034-
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0);
1035-
GlobalV::ofs_running.close();
1039+
1040+
// open a file
1041+
std::ofstream ofs("print_tau_Cartesian");
1042+
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs);
1043+
ofs.close();
1044+
1045+
// readin the data
10361046
std::ifstream ifs;
10371047
ifs.open("print_tau_Cartesian");
10381048
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
10391049
EXPECT_THAT(str, testing::HasSubstr("CARTESIAN COORDINATES"));
10401050
EXPECT_THAT(str, testing::HasSubstr(" C 1.000 1.000 1.000 0.000 0.000 0.000 0.000"));
10411051
EXPECT_THAT(str, testing::HasSubstr(" H 1.500 1.500 1.500 0.000 0.000 0.000 0.000"));
10421052
ifs.close();
1053+
1054+
// remove the file
10431055
remove("print_tau_Cartesian");
10441056
}
10451057

source/module_elecstate/elecstate_print.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,16 @@ void print_band(const ModuleBase::matrix& ekb,
250250
const K_Vectors* klist,
251251
const int& ik,
252252
const int& printe,
253-
const int& iter)
253+
const int& iter,
254+
std::ofstream &ofs)
254255
{
256+
const double largest_eig = 1.0e10;
257+
255258
// check the band energy.
256259
bool wrong = false;
257260
for (int ib = 0; ib < PARAM.globalv.nbands_l; ++ib)
258261
{
259-
if (std::abs(ekb(ik, ib)) > 1.0e10)
262+
if (std::abs(ekb(ik, ib)) > largest_eig)
260263
{
261264
GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb(ik, ib) << " Ry" << std::endl;
262265
wrong = true;
@@ -271,18 +274,18 @@ void print_band(const ModuleBase::matrix& ekb,
271274
{
272275
if (printe > 0 && ((iter + 1) % printe == 0))
273276
{
274-
GlobalV::ofs_running << std::setprecision(6);
275-
GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1
276-
<< " K-point=" << ik + 1 << std::endl;
277-
GlobalV::ofs_running << std::setiosflags(std::ios::showpoint);
277+
ofs << std::setprecision(6);
278+
ofs << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1
279+
<< " k-point=" << ik + 1 << std::endl;
280+
ofs << std::setiosflags(std::ios::showpoint);
278281
for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++)
279282
{
280-
GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15)
283+
ofs << " " << std::setw(6) << ib + 1 << std::setw(15)
281284
<< ekb(ik, ib) * ModuleBase::Ry_to_eV;
282285
// for the first electron iteration, we don't have the energy
283286
// spectrum, so we can't get the occupations.
284-
GlobalV::ofs_running << std::setw(15) << wg(ik, ib);
285-
GlobalV::ofs_running << std::endl;
287+
ofs << std::setw(15) << wg(ik, ib);
288+
ofs << std::endl;
286289
}
287290
}
288291
}
@@ -317,7 +320,7 @@ void print_etot(const Magnetism& magnet,
317320

318321
GlobalV::ofs_running << std::setprecision(12);
319322
GlobalV::ofs_running << std::setiosflags(std::ios::right);
320-
GlobalV::ofs_running << "\n Density error is " << scf_thr << std::endl;
323+
GlobalV::ofs_running << " Electron density error is " << scf_thr << std::endl;
321324

322325
if (PARAM.inp.basis_type == "pw")
323326
{
@@ -327,6 +330,7 @@ void print_etot(const Magnetism& magnet,
327330
std::vector<std::string> titles;
328331
std::vector<double> energies_Ry;
329332
std::vector<double> energies_eV;
333+
330334
if (printe > 0 && ((iter + 1) % printe == 0 || converged || iter == PARAM.inp.scf_nmax))
331335
{
332336
int n_order = std::max(0, Occupy::gaussian_type);
@@ -384,7 +388,7 @@ void print_etot(const Magnetism& magnet,
384388
}
385389

386390
#ifdef __DEEPKS
387-
if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10
391+
if (PARAM.inp.deepks_scf)
388392
{
389393
titles.push_back("E_DeePKS");
390394
energies_Ry.push_back(elec.f_en.edeepks_delta);
@@ -399,6 +403,7 @@ void print_etot(const Magnetism& magnet,
399403
energies_Ry.push_back(elec.f_en.etot_harris);
400404
}
401405

406+
// print out the Fermi energy if needed
402407
if (PARAM.globalv.two_fermi)
403408
{
404409
titles.push_back("E_Fermi_up");
@@ -411,6 +416,8 @@ void print_etot(const Magnetism& magnet,
411416
titles.push_back("E_Fermi");
412417
energies_Ry.push_back(elec.eferm.ef);
413418
}
419+
420+
// print out the band gap if needed
414421
if (PARAM.inp.out_bandgap)
415422
{
416423
if (!PARAM.globalv.two_fermi)
@@ -430,14 +437,21 @@ void print_etot(const Magnetism& magnet,
430437
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) {
431438
return ener * ModuleBase::Ry_to_eV;
432439
});
440+
441+
// for each SCF step, we print out energy
433442
FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"},
434443
/*nrows=*/titles.size(),
435444
/*formats=*/{"%-14s", "%20.10f", "%20.10f"},
436445
/*indents=*/0,
437446
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
447+
// print out the titles
438448
table << titles << energies_Ry << energies_eV;
449+
439450
GlobalV::ofs_running << table.str() << std::endl;
440-
if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16
451+
452+
453+
454+
if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m")
441455
{
442456
std::vector<double> mag;
443457
switch (PARAM.inp.nspin)

0 commit comments

Comments
 (0)