diff --git a/source/driver.cpp b/source/driver.cpp index efd76ca276b..ffa2d4c2f63 100644 --- a/source/driver.cpp +++ b/source/driver.cpp @@ -23,24 +23,27 @@ Driver::~Driver() void Driver::init() { - ModuleBase::TITLE("Driver", "init"); + // 1) Let's start by printing a title. + ModuleBase::TITLE("Driver", "ABACUS_begins"); + // 2) Print the current time, since it may run a long time. time_t time_start = std::time(nullptr); ModuleBase::timer::start(); - // (1) read the input parameters. - // INPUT should be initalized here and then pass to atomic world, mohan - // 2024-05-12 INPUT should not be GlobalC, mohan 2024-05-12 - Driver::reading(); - - // (2) welcome to the atomic world! + // 3) Welcome to the atomic world! Let's do some fancy stuff here. this->atomic_world(); - // (3) output information + // 4) All timers recorders are printed. + ModuleBase::timer::finish(GlobalV::ofs_running); + + // 5) All memory recorders are printed. + ModuleBase::Memory::print_all(GlobalV::ofs_running); + + // 6) Print the final time, hopefully it will not cost too long. time_t time_finish = std::time(nullptr); ModuleIO::print_time(time_start, time_finish); - // (4) close all of the running logs + // 7) Clean up: close all of the running logs ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog,PARAM.inp.calculation); } @@ -169,16 +172,13 @@ void Driver::reading() void Driver::atomic_world() { ModuleBase::TITLE("Driver", "atomic_world"); - //-------------------------------------------------- - // choose basis sets: - // pw: plane wave basis set - // lcao_in_pw: LCAO expaned by plane wave basis set - // lcao: linear combination of atomic orbitals - //-------------------------------------------------- + ModuleBase::timer::tick("Driver", "atomic_world"); + + // reading information + this->reading(); // where the actual stuff is done this->driver_run(); - ModuleBase::timer::finish(GlobalV::ofs_running); - ModuleBase::Memory::print_all(GlobalV::ofs_running); + ModuleBase::timer::tick("Driver", "atomic_world"); } diff --git a/source/driver_run.cpp b/source/driver_run.cpp index ecf4f044055..2d24af0176d 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -25,12 +25,13 @@ */ void Driver::driver_run() { - ModuleBase::TITLE("Driver", "driver_line"); + ModuleBase::TITLE("Driver", "driver_run"); //! 1: setup cell and atom information // this warning should not be here, mohan 2024-05-22 #ifndef __LCAO if (PARAM.inp.basis_type == "lcao_in_pw" || PARAM.inp.basis_type == "lcao") { + ModuleBase::timer::tick("Driver","driver_run"); ModuleBase::WARNING_QUIT("driver", "to use LCAO basis, compile with __LCAO"); } @@ -92,5 +93,6 @@ void Driver::driver_run() //! 6: output the json file Json::create_Json(&ucell, PARAM); + return; } diff --git a/source/module_base/memory.cpp b/source/module_base/memory.cpp index 8d67f9ea4ca..3f8fe287afd 100644 --- a/source/module_base/memory.cpp +++ b/source/module_base/memory.cpp @@ -385,8 +385,9 @@ void Memory::print_all(std::ofstream &ofs) Parallel_Reduce::reduce_all(Memory::total_gpu); #endif #endif - ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl; - ofs <0); @@ -440,7 +441,7 @@ void Memory::print_all(std::ofstream &ofs) return; } - ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl; + ofs <<"\n NAME-------------------------|GPU MEMORY(MB)--------------" << std::endl; ofs <0); diff --git a/source/module_cell/module_neighbor/sltk_atom_arrange.cpp b/source/module_cell/module_neighbor/sltk_atom_arrange.cpp index 548389f55fd..b669fa3d4a5 100644 --- a/source/module_cell/module_neighbor/sltk_atom_arrange.cpp +++ b/source/module_cell/module_neighbor/sltk_atom_arrange.cpp @@ -74,8 +74,9 @@ void atom_arrange::search(const bool pbc_flag, ModuleBase::WARNING_QUIT("atom_arrange::search", " search_radius_bohr < 0,forbidden"); } - ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr))", search_radius_bohr); - ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr))", ucell.lat0); + ofs_in << " SEARCH ADJACENT ATOMS" << std::endl; + ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr)", search_radius_bohr); + ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr)", ucell.lat0); assert(ucell.nat > 0); diff --git a/source/module_cell/module_neighbor/sltk_grid.cpp b/source/module_cell/module_neighbor/sltk_grid.cpp index 4a409940fe1..73ccbcf9894 100644 --- a/source/module_cell/module_neighbor/sltk_grid.cpp +++ b/source/module_cell/module_neighbor/sltk_grid.cpp @@ -195,9 +195,10 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs } } } - ModuleBase::GlobalFunc::OUT(ofs_in, "Find the coordinate range of the input atom(unit:lat0)."); - ModuleBase::GlobalFunc::OUT(ofs_in, "min_tau", x_min, y_min, z_min); - ModuleBase::GlobalFunc::OUT(ofs_in, "max_tau", x_max, y_max, z_max); + + ofs_in << " RANGE OF ATOMIC COORDINATES (unit: lat0)" << std::endl; + ModuleBase::GlobalFunc::OUT(ofs_in, "smallest coordinates of atoms", x_min, y_min, z_min); + ModuleBase::GlobalFunc::OUT(ofs_in, "largest coordinates of atoms", x_max, y_max, z_max); this->box_edge_length = sradius + 0.1; // To avoid edge cases, the size of the box is slightly increased. @@ -220,7 +221,7 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs this->box_nx = glayerX + glayerX_minus; this->box_ny = glayerY + glayerY_minus; this->box_nz = glayerZ + glayerZ_minus; - ModuleBase::GlobalFunc::OUT(ofs_in, "BoxNumber", box_nx, box_ny, box_nz); + ModuleBase::GlobalFunc::OUT(ofs_in, "number of needed cells", box_nx, box_ny, box_nz); atoms_in_box.resize(this->box_nx); for (int i = 0; i < this->box_nx; i++) diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index d05136753cc..ecce588e084 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -11,7 +11,8 @@ namespace unitcell void print_tau(Atom* atoms, const std::string& Coordinate, const int ntype, - const double lat0) + const double lat0, + std::ofstream &ofs) { ModuleBase::TITLE("UnitCell", "print_tau"); // assert (direct || Coordinate == "Cartesian" || Coordinate == "Cartesian_angstrom"); // this line causes abort in unittest ReadAtomPositionsCACXY. @@ -22,7 +23,7 @@ namespace unitcell assert(std::regex_search(Coordinate, pattern)); bool direct = (Coordinate == "Direct"); std::string table; - table += direct? "DIRECT COORDINATES\n": FmtCore::format("CARTESIAN COORDINATES ( UNIT = %20.12f Bohr ).\n", lat0); + table += direct? "DIRECT COORDINATES\n": FmtCore::format(" CARTESIAN COORDINATES ( UNIT = %15.8f Bohr ).\n", lat0); table += FmtCore::format("%8s%10s%10s%10s%8s%8s%8s%8s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz"); for(int it = 0; it < ntype; it++) { @@ -43,7 +44,7 @@ namespace unitcell } } table += "\n"; - GlobalV::ofs_running << table << std::endl; + ofs << table << std::endl; return; } diff --git a/source/module_cell/print_cell.h b/source/module_cell/print_cell.h index d20313f2c92..84cffaf069b 100644 --- a/source/module_cell/print_cell.h +++ b/source/module_cell/print_cell.h @@ -8,7 +8,8 @@ namespace unitcell void print_tau(Atom* atoms, const std::string& Coordinate, const int ntype, - const double lat0); + const double lat0, + std::ofstream &ofs); /** * @brief UnitCell class is too heavy, this function would be moved @@ -40,4 +41,4 @@ namespace unitcell const int& iproc = 0); } -#endif \ No newline at end of file +#endif diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 545ef21a5bc..78f825281f2 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -514,7 +514,9 @@ bool read_atom_positions(UnitCell& ucell, ucell.atoms[it].m_loc_[ia].x = 1.0; ucell.atoms[it].m_loc_[ia].y = 1.0; ucell.atoms[it].m_loc_[ia].z = 1.0; - 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)); + 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)); ModuleBase::GlobalFunc::OUT(ofs_running,"Autoset magnetism for this atom", 1.0, 1.0, 1.0); } } @@ -535,13 +537,14 @@ bool read_atom_positions(UnitCell& ucell, // End Autoset magnetization } // end scan_begin -//check if any atom can move in MD + //check if any atom can move in MD if(!ucell.if_atoms_can_move() && PARAM.inp.calculation=="md" && PARAM.inp.esolver_type!="tddft") { ModuleBase::WARNING("read_atoms", "no atom can move in MD!"); return false; } + ofs_running << std::endl; ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",ucell.nat); @@ -556,7 +559,7 @@ bool read_atom_positions(UnitCell& ucell, if (unitcell::check_tau(ucell.atoms, ucell.ntype, ucell.lat0)) { - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,ofs_running); return true; } return false; diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 7d037422bd5..70d058d090b 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1010,10 +1010,14 @@ TEST_F(UcellTest, PrintTauDirect) UcellTestPrepare utp = UcellTestLib["C1H2-Index"]; PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); - GlobalV::ofs_running.open("print_tau_direct"); EXPECT_EQ(ucell->Coordinate, "Direct"); - unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0); - GlobalV::ofs_running.close(); + + // open a file + std::ofstream ofs("print_tau_direct"); + unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs); + ofs.close(); + + // readin the data std::ifstream ifs; ifs.open("print_tau_direct"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -1021,6 +1025,8 @@ TEST_F(UcellTest, PrintTauDirect) EXPECT_THAT(str, testing::HasSubstr(" C 0.100 0.100 0.100 0.000 0.100 0.100 0.100")); EXPECT_THAT(str, testing::HasSubstr(" H 0.150 0.150 0.150 0.000 0.100 0.100 0.100")); ifs.close(); + + // remove the file remove("print_tau_direct"); } @@ -1029,10 +1035,14 @@ TEST_F(UcellTest, PrintTauCartesian) UcellTestPrepare utp = UcellTestLib["C1H2-Cartesian"]; PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); - GlobalV::ofs_running.open("print_tau_Cartesian"); EXPECT_EQ(ucell->Coordinate, "Cartesian"); - unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0); - GlobalV::ofs_running.close(); + + // open a file + std::ofstream ofs("print_tau_Cartesian"); + unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs); + ofs.close(); + + // readin the data std::ifstream ifs; ifs.open("print_tau_Cartesian"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -1040,6 +1050,8 @@ TEST_F(UcellTest, PrintTauCartesian) EXPECT_THAT(str, testing::HasSubstr(" C 1.000 1.000 1.000 0.000 0.000 0.000 0.000")); EXPECT_THAT(str, testing::HasSubstr(" H 1.500 1.500 1.500 0.000 0.000 0.000 0.000")); ifs.close(); + + // remove the file remove("print_tau_Cartesian"); } diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index cd23c7f0a82..361c2c80368 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -250,13 +250,16 @@ void print_band(const ModuleBase::matrix& ekb, const K_Vectors* klist, const int& ik, const int& printe, - const int& iter) + const int& iter, + std::ofstream &ofs) { + const double largest_eig = 1.0e10; + // check the band energy. bool wrong = false; for (int ib = 0; ib < PARAM.globalv.nbands_l; ++ib) { - if (std::abs(ekb(ik, ib)) > 1.0e10) + if (std::abs(ekb(ik, ib)) > largest_eig) { GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb(ik, ib) << " Ry" << std::endl; wrong = true; @@ -271,18 +274,18 @@ void print_band(const ModuleBase::matrix& ekb, { if (printe > 0 && ((iter + 1) % printe == 0)) { - GlobalV::ofs_running << std::setprecision(6); - GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1 - << " K-point=" << ik + 1 << std::endl; - GlobalV::ofs_running << std::setiosflags(std::ios::showpoint); + ofs << std::setprecision(6); + ofs << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1 + << " k-point=" << ik + 1 << std::endl; + ofs << std::setiosflags(std::ios::showpoint); for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++) { - GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15) + ofs << " " << std::setw(6) << ib + 1 << std::setw(15) << ekb(ik, ib) * ModuleBase::Ry_to_eV; // for the first electron iteration, we don't have the energy // spectrum, so we can't get the occupations. - GlobalV::ofs_running << std::setw(15) << wg(ik, ib); - GlobalV::ofs_running << std::endl; + ofs << std::setw(15) << wg(ik, ib); + ofs << std::endl; } } } @@ -317,7 +320,7 @@ void print_etot(const Magnetism& magnet, GlobalV::ofs_running << std::setprecision(12); GlobalV::ofs_running << std::setiosflags(std::ios::right); - GlobalV::ofs_running << "\n Density error is " << scf_thr << std::endl; + GlobalV::ofs_running << " Electron density error is " << scf_thr << std::endl; if (PARAM.inp.basis_type == "pw") { @@ -327,6 +330,7 @@ void print_etot(const Magnetism& magnet, std::vector titles; std::vector energies_Ry; std::vector energies_eV; + if (printe > 0 && ((iter + 1) % printe == 0 || converged || iter == PARAM.inp.scf_nmax)) { int n_order = std::max(0, Occupy::gaussian_type); @@ -384,7 +388,7 @@ void print_etot(const Magnetism& magnet, } #ifdef __DEEPKS - if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10 + if (PARAM.inp.deepks_scf) { titles.push_back("E_DeePKS"); energies_Ry.push_back(elec.f_en.edeepks_delta); @@ -399,6 +403,7 @@ void print_etot(const Magnetism& magnet, energies_Ry.push_back(elec.f_en.etot_harris); } + // print out the Fermi energy if needed if (PARAM.globalv.two_fermi) { titles.push_back("E_Fermi_up"); @@ -411,6 +416,8 @@ void print_etot(const Magnetism& magnet, titles.push_back("E_Fermi"); energies_Ry.push_back(elec.eferm.ef); } + + // print out the band gap if needed if (PARAM.inp.out_bandgap) { if (!PARAM.globalv.two_fermi) @@ -430,14 +437,21 @@ void print_etot(const Magnetism& magnet, std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) { return ener * ModuleBase::Ry_to_eV; }); + + // for each SCF step, we print out energy FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"}, /*nrows=*/titles.size(), /*formats=*/{"%-14s", "%20.10f", "%20.10f"}, /*indents=*/0, /*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER}); + // print out the titles table << titles << energies_Ry << energies_eV; + GlobalV::ofs_running << table.str() << std::endl; - if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16 + + + + if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") { std::vector mag; switch (PARAM.inp.nspin) diff --git a/source/module_elecstate/elecstate_print.h b/source/module_elecstate/elecstate_print.h index a20c2278cc3..e1ad2fb284c 100644 --- a/source/module_elecstate/elecstate_print.h +++ b/source/module_elecstate/elecstate_print.h @@ -1,14 +1,17 @@ #ifndef ELECSATE_PRINT_H #define ELECSATE_PRINT_H + #include "module_elecstate/elecstate.h" + namespace elecstate { - void print_band(const ModuleBase::matrix& ekb, + void print_band(const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg, const K_Vectors* klist, const int& ik, const int& printe, - const int& iter); + const int& iter, + std::ofstream &ofs); void print_format(const std::string& name, const double& value); @@ -30,4 +33,4 @@ namespace elecstate const double& avg_iter = 0, bool print = true); } -#endif \ No newline at end of file +#endif diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 5b628419bdf..94d52511e06 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -163,13 +163,16 @@ TEST_F(ElecStatePrintTest, PrintBand) PARAM.input.nbands = 2; PARAM.sys.nbands_l = 2; GlobalV::MY_RANK = 0; - GlobalV::ofs_running.open("test.dat", std::ios::out); - // print eigenvalue - elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0); - GlobalV::ofs_running.close(); + + std::ofstream ofs; + ofs.open("test.dat", std::ios::out); + // print eigenvalues + elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0, ofs); + ofs.close(); + ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Energy (eV) & Occupations for spin=1 K-point=1")); + EXPECT_THAT(str, testing::HasSubstr("Energy (eV) & Occupations for spin=1 k-point=1")); EXPECT_THAT(str, testing::HasSubstr("1 13.6057 0.100000")); EXPECT_THAT(str, testing::HasSubstr("2 27.2114 0.200000")); ifs.close(); @@ -193,12 +196,19 @@ TEST_F(ElecStatePrintTest, PrintBandWarning) { elecstate.ekb(0, 0) = 1.0e11; PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); + + std::ofstream ofs; + ofs.open("test.dat", std::ios::out); testing::internal::CaptureStdout(); - EXPECT_EXIT(elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0), ::testing::ExitedWithCode(1), ""); + + EXPECT_EXIT(elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0, ofs), + ::testing::ExitedWithCode(1), ""); + output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Eigenvalues are too large!")); - GlobalV::ofs_running.close(); + + ofs.close(); + std::remove("test.dat"); } @@ -268,7 +278,7 @@ TEST_F(ElecStatePrintTest, PrintEtot) GlobalV::ofs_running.close(); ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Density error is 0.1")); + EXPECT_THAT(str, testing::HasSubstr("Electron density error is 0.1")); EXPECT_THAT(str, testing::HasSubstr("Error Threshold = 0.1")); EXPECT_THAT(str, testing::HasSubstr("E_KohnSham")); EXPECT_THAT(str, testing::HasSubstr("E_vdwD2")); @@ -310,7 +320,7 @@ TEST_F(ElecStatePrintTest, PrintEtot2) GlobalV::ofs_running.close(); ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Density error is 0.1")); + EXPECT_THAT(str, testing::HasSubstr("Electron density error is 0.1")); EXPECT_THAT(str, testing::HasSubstr("Error Threshold = 0.1")); EXPECT_THAT(str, testing::HasSubstr("E_KohnSham")); EXPECT_THAT(str, testing::HasSubstr("E_Harris")); @@ -370,4 +380,4 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) GlobalV::MY_RANK = 0; elecstate::print_etot(ucell.magnet,elecstate, converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); delete elecstate.charge; -} \ No newline at end of file +} diff --git a/source/module_esolver/esolver_dp.cpp b/source/module_esolver/esolver_dp.cpp index e1c83b367d4..1ca9939c359 100644 --- a/source/module_esolver/esolver_dp.cpp +++ b/source/module_esolver/esolver_dp.cpp @@ -28,8 +28,7 @@ #include #include -namespace ModuleESolver -{ +using namespace ModuleESolver; void ESolver_DP::before_all_runners(UnitCell& ucell, const Input_para& inp) { @@ -136,7 +135,7 @@ void ESolver_DP::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress) { stress = dp_virial; - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); + ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, GlobalV::ofs_running); // external stress double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; @@ -197,12 +196,9 @@ void ESolver_DP::type_map(const UnitCell& ucell) "The label " + ucell.atoms[it].label + " is not found in the type map."); } atype[iat] = label[ucell.atoms[it].label]; - // if (ia == 0) - // std::cout << "type: " << atype[iat] << std::endl; iat++; } } assert(ucell.nat == iat); } #endif -} // namespace ModuleESolver diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 734e1dd7399..f06a0ce125d 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -550,7 +550,8 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& i this->pelec->klist, ik, PARAM.inp.printe, - iter); + iter, + GlobalV::ofs_running); } // compute magnetization, only for LSDA(spin==2) diff --git a/source/module_esolver/esolver_lj.cpp b/source/module_esolver/esolver_lj.cpp index f4ea687517c..d1459fe4906 100644 --- a/source/module_esolver/esolver_lj.cpp +++ b/source/module_esolver/esolver_lj.cpp @@ -5,6 +5,7 @@ #include "module_io/output_log.h" #include "module_io/cif_io.h" + namespace ModuleESolver { @@ -104,7 +105,9 @@ void ESolver_LJ::runner(UnitCell& ucell, const int istep) { stress = lj_virial; - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); + const bool screen = true; + const bool ry = false; + ModuleIO::print_stress("TOTAL-STRESS", stress, screen, ry, GlobalV::ofs_running); // external stress double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp index e4c67d747e1..683420fff3a 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp @@ -729,42 +729,41 @@ void Force_Stress_LCAO::getForceStress(UnitCell& ucell, } } + const bool screen = PARAM.inp.test_stress; + GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("OVERLAP STRESS", soverlap, PARAM.inp.test_stress, ry); - // test - ModuleIO::print_stress("T STRESS", stvnl_dphi, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VNL STRESS", svnl_dbeta, PARAM.inp.test_stress, ry); - - ModuleIO::print_stress("T_VNL STRESS", stvnl, PARAM.inp.test_stress, ry); - - ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HAR STRESS", sigmahar, PARAM.inp.test_stress, ry); - - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("cc STRESS", sigmacc, PARAM.inp.test_stress, ry); - // ModuleIO::print_stress("NLCC STRESS",sigmacc,PARAM.inp.test_stress,ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("OVERLAP STRESS", soverlap, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("T STRESS", stvnl_dphi, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VNL STRESS", svnl_dbeta, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("T_VNL STRESS", stvnl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HAR STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("cc STRESS", sigmacc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); if (vdw_solver != nullptr) { - ModuleIO::print_stress("VDW STRESS", sigmaxc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("VDW STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); } if (PARAM.inp.dft_plus_u) { - ModuleIO::print_stress("DFTU STRESS", stress_dftu, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("DFTU STRESS", stress_dftu, screen, ry, GlobalV::ofs_running); } if (PARAM.inp.sc_mag_switch) { - ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, screen, ry, GlobalV::ofs_running); } - ModuleIO::print_stress("TOTAL STRESS", scs, PARAM.inp.test_stress, ry); - + ModuleIO::print_stress("TOTAL STRESS", scs, screen, ry, GlobalV::ofs_running); } // end of test + GlobalV::ofs_running << std::setiosflags(std::ios::left); + // print total stress - ModuleIO::print_stress("TOTAL-STRESS", scs, true, ry); + bool screen = false; + ModuleIO::print_stress("TOTAL-STRESS", scs, screen, ry, GlobalV::ofs_running); double unit_transform = 0.0; unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp b/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp index d1bda7fa088..0eb9b16e6ba 100644 --- a/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp +++ b/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp @@ -13,7 +13,7 @@ void cal_psir_ylm( const bool* const* const cal_flag, double* const* const psir_ylm) // cal_flag[bxyz][na_grid], whether the atom-grid distance is larger than cutoff { - ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); +// ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); std::vector ylma; const UnitCell& ucell = *gt.ucell; std::vector it_psi_uniform(gt.nwmax); @@ -107,7 +107,7 @@ void cal_psir_ylm( } // end distance<=(rcuts[it]-1.0e-15) } // end ib } // end id - ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); +// ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); return; } -} \ No newline at end of file +} diff --git a/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp b/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp index c3964be8b36..5f42c126247 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp @@ -99,22 +99,23 @@ void OF_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, p_symm->symmetrize_mat3(sigmatot, ucell.lat); } - bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool ry = false; + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress) + if (screen) { GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("OF_Stress_PW", "cal_stress"); return; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp index 827eed53ae8..98cb66b2dcc 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp @@ -145,31 +145,31 @@ void Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, p_symm->symmetrize_mat3(sigmatot, ucell.lat); } - bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool ry = false; + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress || true) + if (screen) { -// ry = true; GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); if (PARAM.inp.dft_plus_u || PARAM.inp.sc_mag_switch) { - ModuleIO::print_stress("ONSITE STRESS", sigmaonsite, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("ONSITE STRESS", sigmaonsite, screen, ry, GlobalV::ofs_running); } if (GlobalC::exx_info.info_global.cal_exx) { - ModuleIO::print_stress("EXX STRESS", sigmaexx, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("EXX STRESS", sigmaexx, screen, ry, GlobalV::ofs_running); } - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("Stress_PW", "cal_stress"); return; diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp index 4d77635139d..033a94159dc 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp @@ -77,22 +77,23 @@ void Sto_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, } bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress) + if (screen) { ry = true; GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("Sto_Stress_PW", "cal_stress"); return; @@ -237,4 +238,4 @@ void Sto_Stress_PW::sto_stress_nl(ModuleBase::matrix& sigma, template class Sto_Stress_PW; #if ((defined __CUDA) || (defined __ROCM)) template class Sto_Stress_PW; -#endif \ No newline at end of file +#endif diff --git a/source/module_io/berryphase.cpp b/source/module_io/berryphase.cpp index c27c8b0f628..9efda5a09e9 100644 --- a/source/module_io/berryphase.cpp +++ b/source/module_io/berryphase.cpp @@ -36,7 +36,6 @@ void berryphase::get_occupation_bands() ModuleBase::WARNING_QUIT("berryphase::get_occupation_bands", "not enough bands for berryphase, increase band numbers."); } - // GlobalV::ofs_running << "the berryphase's occ_nbands is " << occ_nbands << std::endl; } #ifdef __LCAO @@ -214,25 +213,6 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) nppstr = mp_z + 1; } - - // test by jingan - /* - GlobalV::ofs_running << "direction is " << direction << std::endl; - GlobalV::ofs_running << "nppstr = " << nppstr << std::endl; - GlobalV::ofs_running << "total std::string is " << total_string << std::endl; - for(int istring = 0; istring < total_string; istring++) - { - GlobalV::ofs_running << " the std::string is " << istring << std::endl; - for(int count = 0; count < nppstr; count++) - { - GlobalV::ofs_running << "(" << kv.kvec_c[ k_index[istring][count] ].x << "," - << kv.kvec_c[ k_index[istring][count] ].y << "," - << kv.kvec_c[ k_index[istring][count] ].z << ")" << std::endl; - } - - } - */ - // test by jingan } #include "../module_base/complexmatrix.h" @@ -251,7 +231,6 @@ double berryphase::stringPhase(const UnitCell& ucell, int ik_2 = 0; ModuleBase::Vector3 G(0.0, 0.0, 0.0); ModuleBase::Vector3 dk = kv.kvec_c[k_index[index_str][1]] - kv.kvec_c[k_index[index_str][0]]; - // GlobalV::ofs_running << "the std::string index is " << index_str << std::endl; for (int k_start = 0; k_start < (nppstr - 1); k_start++) { @@ -351,45 +330,11 @@ double berryphase::stringPhase(const UnitCell& ucell, { if (PARAM.inp.nspin != 4) { - // std::complex my_det = lcao_method.det_berryphase(ik_1,ik_2,dk,nbands); zeta = zeta * lcao_method.det_berryphase(ucell,ik_1, ik_2, dk, nbands, *(this->paraV), psi_in, kv); - // test by jingan - // GlobalV::ofs_running << "methon 1: det = " << my_det << std::endl; - // test by jingan } else { } - - // test by jingan - /* - for (int mb = 0; mb < nbands; mb++) - { - - for (int nb = 0; nb < nbands; nb++) - { - - mat(nb, mb) = lcao_method.unkdotp_LCAO(ik_1,ik_2,nb,mb,dk,kv); - } - } - - std::complex det(1.0,0.0); - int info = 0; - int *ipiv = new int[nbands]; - LapackConnector::zgetrf(nbands, nbands, mat, nbands, ipiv, &info); - for (int ib = 0; ib < nbands; ib++) - { - if (ipiv[ib] != (ib+1)) det = -det * mat(ib,ib); - else det = det * mat(ib,ib); - } - - zeta = zeta*det; - - GlobalV::ofs_running << "methon 2: det = " << det << std::endl; - - delete[] ipiv; - */ - // test by jingan } #endif } @@ -441,9 +386,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell, dtheta = atan2(cphik[istring].imag(), cphik[istring].real()); phik[istring] = (theta0 + dtheta) / (2 * ModuleBase::PI); phik_ave = phik_ave + wistring[istring] * phik[istring]; - // test by jingan - // GlobalV::ofs_running << "phik[" << istring << "] = " << phik[istring] << std::endl; - // test by jingan } if (PARAM.inp.nspin == 1) @@ -466,7 +408,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell, mod_elec_tot = 1; } - // GlobalV::ofs_running << "Berry_Phase end " << std::endl; } void berryphase::Macroscopic_polarization(const UnitCell& ucell, @@ -574,20 +515,16 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell, polarization_ion[2] = polarization_ion[2] - 2.0 * round(polarization_ion[2] / 2.0); } - // delete[] mod_ion; - // delete[] pdl_ion_R1; - // delete[] pdl_ion_R2; - // delete[] pdl_ion_R3; - // ion polarization end // calculate Macroscopic polarization modulus because berry phase int modulus = 0; - if ((!lodd) && (PARAM.inp.nspin == 1)) { - modulus = 2; - } else { - modulus = 1; - } + if ((!lodd) && (PARAM.inp.nspin == 1)) + { + modulus = 2; + } else { + modulus = 1; + } // test by jingan // GlobalV::ofs_running << "ion polarization end" << std::endl; @@ -736,8 +673,6 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell, } } - // GlobalV::ofs_running << "the Macroscopic_polarization is over" << std::endl; - return; } diff --git a/source/module_io/output_log.cpp b/source/module_io/output_log.cpp index bd1a1afce8b..496e7f53013 100644 --- a/source/module_io/output_log.cpp +++ b/source/module_io/output_log.cpp @@ -223,7 +223,10 @@ void print_force(std::ofstream& ofs_running, std::vector force_y; std::vector force_z; std::string table; - std::vector titles({name, "", "", ""}); + + ofs_running << " " << name << std::endl; + + std::vector titles({"Atoms", "Force_x", "Force_y", "Force_z"}); int iat = 0; for (int it = 0; it < cell.ntype; it++) { @@ -242,16 +245,25 @@ void print_force(std::ofstream& ofs_running, } } + FmtTable fmt(/*titles=*/titles, /*nrows=*/atom_label.size(), - /*formats=*/{"%10s", "%20.10f", "%20.10f", "%20.10f"}, 0); - fmt << atom_label << force_x << force_y << force_z; - table = fmt.str(); + /*formats=*/{"%8s", "%20.10f", "%20.10f", "%20.10f"}, + 0, + {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); + + fmt << atom_label << force_x << force_y << force_z; + table = fmt.str(); ofs_running << table << std::endl; - if (PARAM.inp.test_force) { std::cout << table << std::endl; -} + + if (PARAM.inp.test_force) + { + std::cout << table << std::endl; + } } -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry) + +void print_stress(const std::string& name, const ModuleBase::matrix& scs, + const bool screen, const bool ry, std::ofstream &ofs) { const double output_acc = 1.0e-8; double unit_transform = 1; @@ -272,7 +284,10 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const std::vector stress_y; std::vector stress_z; std::string table; - std::vector titles({title, "", ""}); + + ofs << " " << title << std::endl; + + std::vector titles({"Stress_x", "Stress_y", "Stress_z"}); for (int i = 0; i < 3; i++) { double sx = scs(i, 0) * unit_transform; @@ -287,14 +302,16 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const FmtTable fmt(/*titles=*/titles, /*nrows=*/3, - /*formats=*/{"%20.10f", "%20.10f", "%20.10f"}, 0); + /*formats=*/{"%20.10f", "%20.10f", "%20.10f"}, 0, + {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); + fmt << stress_x << stress_y << stress_z; table = fmt.str(); - GlobalV::ofs_running << table; + ofs << table; if (name == "TOTAL-STRESS") { - GlobalV::ofs_running << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit - << std::endl + ofs << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed + << std::setprecision(6) << pressure << unit << std::endl; } if (screen) @@ -302,16 +319,17 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const std::cout << table; if (name == "TOTAL-STRESS") { - std::cout << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit << std::endl + std::cout << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed + << std::setprecision(6) << pressure << unit << std::endl; } } return; } -void write_head(std::ofstream& ofs_running, const int& istep, const int& iter, const std::string& basisname) +void write_head(std::ofstream& ofs, const int& istep, const int& iter, const std::string& basisname) { - ofs_running << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1 + ofs << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1 << " ELEC=" << std::setw(4) << iter << "--------------------------------\n"; } diff --git a/source/module_io/output_log.h b/source/module_io/output_log.h index 2bbc90cd948..56108648638 100644 --- a/source/module_io/output_log.h +++ b/source/module_io/output_log.h @@ -54,7 +54,7 @@ void output_vacuum_level(const UnitCell* ucell, /// @param name force term name /// @param force atomic forces /// @param ry true if the unit of force is a.u. -void print_force(std::ofstream& ofs_running, +void print_force(std::ofstream& ofs, const UnitCell& cell, const std::string& name, const ModuleBase::matrix& force, @@ -64,7 +64,11 @@ void print_force(std::ofstream& ofs_running, /// @param name stress term name /// @param f stress components /// @param ry true if the unit of force is a.u. -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry); +void print_stress(const std::string& name, + const ModuleBase::matrix& scs, + const bool screen, + const bool ry, + std::ofstream &ofs); /// @brief write head for scf iteration /// @param ofs_running output stream diff --git a/source/module_io/print_info.cpp b/source/module_io/print_info.cpp index 61a5cc3b23a..6c60b7f7b5c 100644 --- a/source/module_io/print_info.cpp +++ b/source/module_io/print_info.cpp @@ -11,8 +11,13 @@ void setup_parameters(UnitCell& ucell, K_Vectors& kv) { ModuleBase::TITLE("ModuleIO", "setup_parameters"); - if(PARAM.inp.calculation=="scf" || PARAM.inp.calculation=="relax" || PARAM.inp.calculation=="cell-relax" || PARAM.inp.calculation=="nscf" - || PARAM.inp.calculation=="get_pchg" || PARAM.inp.calculation=="get_wf" || PARAM.inp.calculation=="md") + if(PARAM.inp.calculation=="scf" + || PARAM.inp.calculation=="relax" + || PARAM.inp.calculation=="cell-relax" + || PARAM.inp.calculation=="nscf" + || PARAM.inp.calculation=="get_pchg" + || PARAM.inp.calculation=="get_wf" + || PARAM.inp.calculation=="md") { std::cout << " ---------------------------------------------------------" << std::endl; if(PARAM.inp.calculation=="scf") @@ -203,7 +208,7 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, << std::endl; } - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>" << std::endl; @@ -231,10 +236,13 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, ofs << " | is 'npw' in each processor. " " |" << std::endl; + ofs << " | " + " |" + << std::endl; ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << "\n SETUP THE PLANE WAVE BASIS" << std::endl; double ecut = 4 * PARAM.inp.ecutwfc; @@ -317,7 +325,7 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, void print_wfcfft(const Input_para& inp, ModulePW::PW_Basis_K& pw_wfc, std::ofstream& ofs) { - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>" << std::endl; @@ -345,10 +353,13 @@ void print_wfcfft(const Input_para& inp, ModulePW::PW_Basis_K& pw_wfc, std::ofst ofs << " | each k-point is 'npwk[ik]' in each processor " " |" << std::endl; + ofs << " | " + " |" + << std::endl; ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << "\n SETUP PLANE WAVES FOR WAVE FUNCTIONS" << std::endl; double ecut = inp.ecutwfc; @@ -424,4 +435,4 @@ void print_screen(const int& stress_step, const int& force_step, const int& iste GlobalV::ofs_running << " -------------------------------------------" << std::endl; } -} // namespace ModuleIO \ No newline at end of file +} // namespace ModuleIO diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index 342ad14a8be..786f6017dfb 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -252,31 +252,42 @@ TEST(PrintForce, PrintForce) force(1, 1) = 0.0; force(1, 2) = 0.0; - GlobalV::ofs_running.open("test.txt"); - ModuleIO::print_force(GlobalV::ofs_running, ucell, name, force, false); - GlobalV::ofs_running.close(); + std::ofstream ofs("running_force.txt"); + ModuleIO::print_force(ofs, ucell, name, force, false); + ofs.close(); - std::ifstream ifs("test.txt"); + std::ifstream ifs("running_force.txt"); std::string output_str; + + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" test")); + getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("test")); + EXPECT_THAT(output_str, + testing::HasSubstr(" Atoms Force_x Force_y Force_z")); + getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("Al1 25.7110532015 51.4221064030 77.1331596044")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("Al2 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); + ifs.close(); - std::remove("test.txt"); + std::remove("running_force.txt"); } TEST(PrintStress, PrintStress) @@ -292,30 +303,41 @@ TEST(PrintStress, PrintStress) stress(2, 1) = 0.0; stress(2, 2) = 0.0; - GlobalV::ofs_running.open("test.txt"); - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); - GlobalV::ofs_running.close(); - std::ifstream ifs("test.txt"); + std::ofstream ofs("running_stress.txt"); + ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, ofs); + ofs.close(); + + std::ifstream ifs("running_stress.txt"); std::string output_str; + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-STRESS (KBAR)")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("TOTAL-STRESS (KBAR) ")); + EXPECT_THAT(output_str, testing::HasSubstr(" Stress_x Stress_y Stress_z")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 147105.2279754489 294210.4559508978 441315.6839263467")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-PRESSURE: 49035.075992 KBAR")); + EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): 49035.075992 KBAR")); ifs.close(); - std::remove("test.txt"); + std::remove("running_stress.txt"); } int main(int argc, char** argv) @@ -337,4 +359,4 @@ int main(int argc, char** argv) finishmpi(); #endif return result; -} \ No newline at end of file +} diff --git a/source/module_io/write_wfc_pw.cpp b/source/module_io/write_wfc_pw.cpp index d00ca6a41fd..76c461de2b7 100644 --- a/source/module_io/write_wfc_pw.cpp +++ b/source/module_io/write_wfc_pw.cpp @@ -47,9 +47,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn, } } } - // if(GlobalV::MY_RANK!=0) std::cout.clear(); - // std::cout<<"Hello"<* force) void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) { - if (my_rank) + if (my_rank!=0) { return; } @@ -158,6 +158,7 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) press += stress(i, i) / 3; } + // screen output std::cout << " ------------------------------------------------------------------------------------------------" << std::endl; std::cout << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)" @@ -182,9 +183,9 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) std::cout << " ------------------------------------------------------------------------------------------------" << std::endl; + // running_log output ofs.unsetf(std::ios::fixed); - ofs << std::setprecision(8) << std::endl; - ofs << std::endl; + ofs << std::setprecision(8); ofs << " ------------------------------------------------------------------------------------------------" << std::endl; ofs << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)" @@ -214,9 +215,6 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) MD_func::print_stress(ofs, virial, stress); } - ofs << std::endl; - ofs << std::endl; - return; } diff --git a/source/module_md/md_func.cpp b/source/module_md/md_func.cpp index 07bc1f03f21..3c1d80fbe91 100644 --- a/source/module_md/md_func.cpp +++ b/source/module_md/md_func.cpp @@ -293,16 +293,18 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo for (int i = 0; i < 3; i++) { - stress_scalar += stress(i, i) / 3; - virial_scalar += virial(i, i) / 3; + stress_scalar += stress(i, i) / 3.0; + virial_scalar += virial(i, i) / 3.0; } const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; - ofs << "Virtual Pressure is " << stress_scalar * unit_transform << " kbar " << std::endl; - ofs << "Virial Term is " << virial_scalar * unit_transform << " kbar " << std::endl; - ofs << "Kinetic Term is " << (stress_scalar - virial_scalar) * unit_transform << " kbar " << std::endl; + ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " kbar" << std::endl; + ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " kbar" << std::endl; + ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " kbar" << std::endl; + // one should use 'print_stress' function in ../source/module_io/output_log.cpp +/* ofs.unsetf(std::ios::fixed); ofs << std::setprecision(8) << std::endl; ModuleBase::GlobalFunc::NEW_PART("MD STRESS (kbar)"); @@ -312,6 +314,7 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo << std::setw(15) << stress(i, 2) * unit_transform << std::endl; } ofs << std::setiosflags(std::ios::left); +*/ return; } diff --git a/source/module_md/test/fire_test.cpp b/source/module_md/test/fire_test.cpp index 81573498ae6..6365ef2d76a 100644 --- a/source/module_md/test/fire_test.cpp +++ b/source/module_md/test/fire_test.cpp @@ -177,41 +177,54 @@ TEST_F(FIREtest, Restart) TEST_F(FIREtest, PrintMD) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_fire.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_fire.log"); std::string output_str; + + // Line 1 getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); + + // Line 2 getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " Energy (Ry) Potential (Ry) Kinetic (Ry) Temperature (K) Pressure (kbar) ")); + + // Line 3 getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " -0.015365236 -0.023915637 0.0085504016 300 1.0846391 ")); + + // Line 4 getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); - for (int i = 0; i < 11; ++i) - { - getline(ifs, output_str); - } - EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A")); + + // Line 5 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar")); + + // Line 6 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar")); + + // Line 7 getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr(" Threshold is -1 eV/A.")); + EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar")); + + // Line 8 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.049479926")); + ifs.close(); - remove("running.log"); + //remove("running_fire.log"); } diff --git a/source/module_md/test/langevin_test.cpp b/source/module_md/test/langevin_test.cpp index a06f279c4f3..baf59d3ba0c 100644 --- a/source/module_md/test/langevin_test.cpp +++ b/source/module_md/test/langevin_test.cpp @@ -163,15 +163,13 @@ TEST_F(Langevin_test, restart) TEST_F(Langevin_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_langevin.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_langevin.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -192,5 +190,5 @@ TEST_F(Langevin_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); + remove("running_langevin.log"); } diff --git a/source/module_md/test/md_func_test.cpp b/source/module_md/test/md_func_test.cpp index 54d3ef3ea4d..ddebc68bbcc 100644 --- a/source/module_md/test/md_func_test.cpp +++ b/source/module_md/test/md_func_test.cpp @@ -385,11 +385,12 @@ TEST_F(MD_func_test, print_stress) std::ifstream ifs("running.log"); std::string output_str; getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Virtual Pressure is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("MD PRESSURE (ELECTRONS+IONS) : 0 kbar")); getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Virial Term is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("ELECTRONIC PART OF STRESS: 0 kbar")); getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Kinetic Term is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("IONIC (KINETIC) PART OF STRESS: 0 kbar")); +/* getline(ifs, output_str); getline(ifs, output_str); getline(ifs, output_str); @@ -409,6 +410,7 @@ TEST_F(MD_func_test, print_stress) EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0")); getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0")); +*/ ifs.close(); remove("running.log"); @@ -438,4 +440,4 @@ TEST_F(MD_func_test, current_step_warning) int istep = 0; double temperature = 0.0; EXPECT_EXIT(MD_func::current_md_info(0, file_dir, istep, temperature), ::testing::ExitedWithCode(1), ""); -} \ No newline at end of file +} diff --git a/source/module_md/test/msst_test.cpp b/source/module_md/test/msst_test.cpp index 27b94e5a2d9..f4cf7805d41 100644 --- a/source/module_md/test/msst_test.cpp +++ b/source/module_md/test/msst_test.cpp @@ -219,15 +219,13 @@ TEST_F(MSST_test, restart) TEST_F(MSST_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_msst.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_msst.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -248,5 +246,5 @@ TEST_F(MSST_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); +// remove("running_msst.log"); } diff --git a/source/module_md/test/nhchain_test.cpp b/source/module_md/test/nhchain_test.cpp index 22f0bbf9a0b..6aaacc9869a 100644 --- a/source/module_md/test/nhchain_test.cpp +++ b/source/module_md/test/nhchain_test.cpp @@ -113,7 +113,6 @@ TEST_F(NHC_test, second_half) { mdrun->first_half(GlobalV::ofs_running); mdrun->second_half(); - ; EXPECT_NEAR(mdrun->pos[0].x, -0.00035596392702161582, doublethreshold); EXPECT_NEAR(mdrun->pos[0].y, 0.00026566987683715606, doublethreshold); @@ -146,7 +145,7 @@ TEST_F(NHC_test, write_restart) { mdrun->first_half(GlobalV::ofs_running); mdrun->second_half(); - ; + mdrun->step_ = 1; mdrun->step_rst_ = 2; mdrun->write_restart(PARAM.sys.global_out_dir); @@ -210,15 +209,13 @@ TEST_F(NHC_test, restart) TEST_F(NHC_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_nhchain.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_nhchain.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -239,5 +236,5 @@ TEST_F(NHC_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); + //remove("running_nhchain.log"); } diff --git a/source/module_md/test/setcell.h b/source/module_md/test/setcell.h index bd51bcbdd25..01010695da8 100644 --- a/source/module_md/test/setcell.h +++ b/source/module_md/test/setcell.h @@ -140,4 +140,4 @@ class Setcell }; }; -#endif \ No newline at end of file +#endif diff --git a/source/module_md/test/verlet_test.cpp b/source/module_md/test/verlet_test.cpp index 578761dcc5e..8ba61ed5e9e 100644 --- a/source/module_md/test/verlet_test.cpp +++ b/source/module_md/test/verlet_test.cpp @@ -304,15 +304,13 @@ TEST_F(Verlet_test, restart) TEST_F(Verlet_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_verlet.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_verlet.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -333,5 +331,5 @@ TEST_F(Verlet_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); +// remove("running_verlet.log"); } diff --git a/source/module_relax/relax_new/relax.cpp b/source/module_relax/relax_new/relax.cpp index 8dc081d5f92..5e563322d9f 100644 --- a/source/module_relax/relax_new/relax.cpp +++ b/source/module_relax/relax_new/relax.cpp @@ -637,7 +637,7 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) unitcell::update_pos_taud(ucell.lat,move_ion,ucell.ntype,ucell.nat,ucell.atoms); // Print the structure file. - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); // ================================================================= // Step 4 : update G,GT and other stuff @@ -699,4 +699,4 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) unitcell::setup_cell_after_vc(ucell,GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL"); } -} \ No newline at end of file +} diff --git a/source/module_relax/relax_old/ions_move_basic.cpp b/source/module_relax/relax_old/ions_move_basic.cpp index f65c925f2df..a8dabe57437 100644 --- a/source/module_relax/relax_old/ions_move_basic.cpp +++ b/source/module_relax/relax_old/ions_move_basic.cpp @@ -112,7 +112,7 @@ void Ions_Move_Basic::move_atoms(UnitCell &ucell, double *move, double *pos) //-------------------------------------------- // Print out the structure file. //-------------------------------------------- - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); return; } @@ -217,7 +217,7 @@ void Ions_Move_Basic::terminate(const UnitCell &ucell) //----------------------------------------------------------- // Print the structure. //----------------------------------------------------------- - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); return; } diff --git a/tests/integrate/README.md b/tests/integrate/README.md index 3923895a654..79ffff96d4f 100644 --- a/tests/integrate/README.md +++ b/tests/integrate/README.md @@ -1,9 +1,9 @@ -1, modify file general_info +1. Modify the file general_info -2, try this script for autotest: +2. try this script for autotest: ./Autotest.sh > check.txt -3, if want to focus on No. xxx example, such as 101_PW_OU_PL: +3. if you want to focus on No.xxx example, such as 101_PW_OU_PL: cd 101_PW_OU_PL ./../run_debug.sh $parameter @@ -20,7 +20,6 @@ NOTES: 3, if there is any bug occurs, rename the bug example path to mark it please. ####################### -################## "simple" scripts diff --git a/tests/integrate/Single_job.sh b/tests/integrate/Single_job.sh index 6b8f141d1d2..65815320e60 100755 --- a/tests/integrate/Single_job.sh +++ b/tests/integrate/Single_job.sh @@ -1,9 +1,10 @@ #!/bin/bash -#input parameter: - #none: run and check for this example; - #debug: copy the scripts to debug, then run and check this example; - #other: run this example and generate reference file. +# The note for using the script. +# input parameter: + #'none': run and check for this example; + #'debug': copy scripts to debug, then run and check this example; + #'other': run this example and generate reference file. if test -z $1 then diff --git a/tests/integrate/general_info b/tests/integrate/general_info new file mode 100644 index 00000000000..462616452fb --- /dev/null +++ b/tests/integrate/general_info @@ -0,0 +1,3 @@ +EXEC /xxx/abacus +CHECKACCURACY 2 +NUMBEROFPROCESS 4 diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index c72afea9b34..f8d25085b53 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -17,9 +17,7 @@ sum_file(){ done echo $sum } -#answer=`sum_file test.txt` -#echo $answer -#exit 0 + get_input_key_value(){ key=$1 @@ -28,8 +26,10 @@ get_input_key_value(){ echo $value } + file=$1 #echo $1 + calculation=`grep calculation INPUT | awk '{print $2}' | sed s/[[:space:]]//g` running_path=`echo "OUT.autotest/running_$calculation"".log"` natom=`grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | tail -1 | awk '{print $6}'` @@ -73,69 +73,71 @@ esolver_type=$(get_input_key_value "esolver_type" "INPUT") rdmft=$(get_input_key_value "rdmft" "INPUT") #echo $running_path base=$(get_input_key_value "basis_type" "INPUT") -word="driver_line" +word_total_time="atomic_world" symmetry=$(get_input_key_value "symmetry" "INPUT") out_current=$(get_input_key_value "out_current" "INPUT") test -e $1 && rm $1 -#-------------------------------------------- + +#------------------------------------------------------------ # if NOT non-self-consistent calculations or linear response -#-------------------------------------------- +#------------------------------------------------------------ is_lr=0 if [ ! -z $esolver_type ] && ([ $esolver_type == "lr" ] || [ $esolver_type == "ks-lr" ]); then is_lr=1 fi +#---------------------------- +# total energy information +#---------------------------- if [ $calculation != "get_wf" ]\ && [ $calculation != "get_pchg" ] && [ $calculation != "get_S" ]\ && [ $is_lr == 0 ]; then - #etot=`grep ETOT_ $running_path | awk '{print $2}'` etot=$(grep "ETOT_" "$running_path" | tail -1 | awk '{print $2}') etotperatom=`awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}'` echo "etotref $etot" >>$1 echo "etotperatomref $etotperatom" >>$1 fi - -#echo $etot -#echo "hasforce:"$has_force +#---------------------------- +# force information +# echo "hasforce:"$has_force +#---------------------------- if ! test -z "$has_force" && [ $has_force == 1 ]; then - nn3=`echo "$natom + 1" |bc` - #nn1=`echo "$natom + 1" |bc` - #nn5=`echo "$natom + 6" |bc` - #grep -A$nn3 "TOTAL-FORCE" $running_path|sed '1,5d'|sed ''$nn1','$nn5'd'|awk '{printf $2"\t"$3"\t"$4"\n"}' > force.txt - grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt #check the last step result + nn3=`echo "$natom + 3" |bc` + # echo "nn3=$nn3" + # check the last step result + grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt total_force=`sum_file force.txt` - rm force.txt + rm force.txt echo "totalforceref $total_force" >>$1 fi -#echo $total_force -#echo "has_stress:"$has_stress +#------------------------------- +# stress information +# echo "has_stress:"$has_stress +#------------------------------- if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - #grep -A6 "TOTAL-STRESS" $running_path|sed '1,4d'|sed '4,8d' >stress.txt - grep -A4 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt + grep -A6 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt total_stress=`sum_file stress.txt` rm stress.txt echo "totalstressref $total_stress" >>$1 fi -#echo $total_stress -#if ! test -z "$has_charge" && [ $has_charge == 1 ]; then -# total_charge=`sum_file OUT.autotest/SPIN1_CHG` -# echo "totalchargeref $total_charge" >>$1 -#fi - - -#echo $total_charge +#------------------------------- +# DOS information +# echo $total_charge +#------------------------------- if ! test -z "$has_dos" && [ $has_dos == 1 ]; then total_dos=`cat OUT.autotest/DOS1_smearing.dat | awk 'END {print}' | awk '{print $3}'` echo "totaldosref $total_dos" >> $1 fi -# smearing_dos=`sum_file OUT.autotest/DOS1_smearing.dat` -# echo "totaldossmearing $smearing_dos" >> $1 +#smearing_dos=`sum_file OUT.autotest/DOS1_smearing.dat` +#echo "totaldossmearing $smearing_dos" >> $1 -#echo Onsager coefficiency +#------------------------------- +# Onsager coefficiency +#------------------------------- if ! test -z "$has_cond" && [ $has_cond == 1 ]; then onref=refOnsager.txt oncal=Onsager.txt @@ -144,7 +146,9 @@ if ! test -z "$has_cond" && [ $has_cond == 1 ]; then rm -f je-je.txt Chebycoef fi -#echo $out_dm1 +#------------------------------- +# echo $out_dm1 +#------------------------------- if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then dm1ref=refdata-DMR-sparse_SPIN0.csr dm1cal=OUT.autotest/data-DMR-sparse_SPIN0.csr @@ -152,7 +156,9 @@ if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then echo "CompareDM1_pass $?" >>$1 fi -#echo $out_pot1 +#------------------------------- +# echo $out_pot1 +#------------------------------- if ! test -z "$out_pot" && [ $out_pot == 1 ]; then pot1ref=refSPIN1_POT.cube pot1cal=OUT.autotest/SPIN1_POT.cube @@ -160,7 +166,9 @@ if ! test -z "$out_pot" && [ $out_pot == 1 ]; then echo "ComparePot1_pass $?" >>$1 fi +#------------------------------- #echo $out_pot2 +#------------------------------- if ! test -z "$out_pot" && [ $out_pot == 2 ]; then pot1ref=refElecStaticPot.cube pot1cal=OUT.autotest/ElecStaticPot.cube @@ -168,7 +176,10 @@ if ! test -z "$out_pot" && [ $out_pot == 2 ]; then echo "ComparePot_pass $?" >>$1 fi -#echo $out_elf +#------------------------------- +# Electron localized function +# echo $out_elf +#------------------------------- if ! test -z "$out_elf" && [ $out_elf == 1 ]; then elf1ref=refELF.cube elf1cal=OUT.autotest/ELF.cube @@ -176,7 +187,10 @@ if ! test -z "$out_elf" && [ $out_elf == 1 ]; then echo "ComparePot1_pass $?" >>$1 fi -#echo $get_s +#------------------------------- +# Overlap matrix +# echo $get_s +#------------------------------- if ! test -z "$get_s" && [ $get_s == "get_S" ]; then sref=refSR.csr scal=OUT.autotest/SR.csr @@ -184,7 +198,10 @@ if ! test -z "$get_s" && [ $get_s == "get_S" ]; then echo "CompareS_pass $?" >>$1 fi -#echo $out_pband +#------------------------------- +# Partial band structure +# echo $out_pband +#------------------------------- if ! test -z "$out_pband" && [ $out_pband == 1 ]; then #pbandref=refPBANDS_1 #pbandcal=OUT.autotest/PBANDS_1 @@ -196,7 +213,10 @@ if ! test -z "$out_pband" && [ $out_pband == 1 ]; then echo "CompareOrb_pass $?" >>$1 fi -#echo $toW90 +#------------------------------- +# Wannier90 information +# echo $toW90 +#------------------------------- if ! test -z "$toW90" && [ $toW90 == 1 ]; then amnref=diamond.amn amncal=OUT.autotest/diamond.amn @@ -214,15 +234,23 @@ if ! test -z "$toW90" && [ $toW90 == 1 ]; then echo "CompareEIG_pass $?" >>$1 fi -#echo total_dos -#echo $has_band +#------------------------------- +# Total DOS +# echo total_dos +# echo $has_band +#------------------------------- if ! test -z "$has_band" && [ $has_band == 1 ]; then bandref=refBANDS_1.dat bandcal=OUT.autotest/BANDS_1.dat python3 ../tools/CompareFile.py $bandref $bandcal 8 echo "CompareBand_pass $?" >>$1 fi -#echo $has_hs + + +#-------------------------------- +# Hamiltonian and overlap matrix +# echo $has_hs +#-------------------------------- if ! test -z "$has_hs" && [ $has_hs == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then href=data-0-H.ref @@ -242,6 +270,9 @@ if ! test -z "$has_hs" && [ $has_hs == 1 ]; then echo "CompareS_pass $?" >>$1 fi +#-------------------------------- +# exchange-correlation potential +#-------------------------------- if ! test -z "$has_xc" && [ $has_xc == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then xcref=k-0-Vxc.ref @@ -258,6 +289,9 @@ if ! test -z "$has_xc" && [ $has_xc == 1 ]; then echo "CompareOrbXC_pass $?" >>$1 fi +#-------------------------------- +# exchange-correlation potential +#-------------------------------- if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then xc2ref=Vxc_R_spin0.ref xc2cal=OUT.autotest/Vxc_R_spin0.csr @@ -265,6 +299,9 @@ if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then echo "CompareVXC_R_pass $?" >>$1 fi +#-------------------------------- +# separate terms in band enegy +#-------------------------------- if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then ekref=kinetic_out.ref ekcal=OUT.autotest/kinetic_out.dat @@ -284,6 +321,9 @@ if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then echo "CompareOrbVHartree_pass $?" >>$1 fi +#----------------------------------- +# Hamiltonian and overlap matrices +#----------------------------------- #echo $has_hs2 if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then #python3 ../tools/CompareFile.py data-HR-sparse_SPIN0.csr.ref OUT.autotest/data-HR-sparse_SPIN0.csr 8 @@ -292,18 +332,27 @@ if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then echo "CompareSR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_r if ! test -z "$has_mat_r" && [ $has_mat_r == 1 ]; then python3 ../tools/CompareFile.py data-rR-sparse.csr.ref OUT.autotest/data-rR-sparse.csr 8 echo "ComparerR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_t if ! test -z "$has_mat_t" && [ $has_mat_t == 1 ]; then python3 ../tools/CompareFile.py data-TR-sparse_SPIN0.csr.ref OUT.autotest/data-TR-sparse_SPIN0.csr 8 echo "ComparerTR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_dh if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then python3 ../tools/CompareFile.py data-dHRx-sparse_SPIN0.csr.ref OUT.autotest/data-dHRx-sparse_SPIN0.csr 8 @@ -314,7 +363,10 @@ if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then echo "ComparerdHRz_pass $?" >>$1 fi +#--------------------------------------- +# SCAN exchange-correlation information #echo $has_scan +#--------------------------------------- if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ ! test -z "$out_chg" && [ $out_chg == 1 ]; then python3 ../tools/CompareFile.py SPIN1_CHG.cube.ref OUT.autotest/SPIN1_CHG.cube 8 @@ -323,14 +375,17 @@ if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ echo "SPIN1_TAU.cube_pass $?" >>$1 fi +#--------------------------------------- +# wave functions in real space # echo "$has_wfc_r" ## test out_wfc_r > 0 +#--------------------------------------- if ! test -z "$has_wfc_r" && [ $has_wfc_r == 1 ]; then if [[ ! -f OUT.autotest/running_scf.log ]];then echo "Can't find file OUT.autotest/running_scf.log" exit 1 fi nband=$(grep NBANDS OUT.autotest/running_scf.log|awk '{print $3}') -allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk -F "[=,\\\[\\\]]" '{print $3*$4*$5}') + allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk -F "[=,\\\[\\\]]" '{print $3*$4*$5}') for((band=0;band<$nband;band++));do if [[ -f "OUT.autotest/wfc_realspace/wfc_realspace_0_$band" ]];then variance_wfc_r=`sed -n "13,$"p OUT.autotest/wfc_realspace/wfc_realspace_0_$band | \ @@ -344,7 +399,10 @@ allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk done fi +#-------------------------------------------- +# wave functions in plane wave basis # echo "$has_wfc_pw" ## test out_wfc_pw > 0 +#-------------------------------------------- if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then if [[ ! -f OUT.autotest/WAVEFUNC1.txt ]];then echo "Can't find file OUT.autotest/WAVEFUNC1.txt" @@ -365,7 +423,11 @@ if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then }' OUT.autotest/WAVEFUNC1.txt >> $1 fi -# echo "$has_lowf" ## test out_wfc_lcao > 0 + +#-------------------------------------------- +# wave functions in LCAO basis +# echo "$has_lowf" # test out_wfc_lcao > 0 +#-------------------------------------------- if ! test -z "$has_lowf" && [ $has_lowf == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then wfc_cal=OUT.autotest/WFC_NAO_GAMMA1.txt @@ -396,6 +458,9 @@ if ! test -z "$has_lowf" && [ $has_lowf == 1 ]; then echo "Compare_wfc_lcao_pass $?" >>$1 fi +#-------------------------------------------- +# density matrix information +#-------------------------------------------- if ! test -z "$out_dm" && [ $out_dm == 1 ]; then dmfile=OUT.autotest/SPIN1_DM dmref=SPIN1_DM.ref @@ -408,11 +473,18 @@ if ! test -z "$out_dm" && [ $out_dm == 1 ]; then fi fi +#-------------------------------------------- +# mulliken charge +#-------------------------------------------- if ! test -z "$out_mul" && [ $out_mul == 1 ]; then - python3 ../tools/CompareFile.py mulliken.txt.ref OUT.autotest/mulliken.txt 4 + python3 ../tools/CompareFile.py mulliken.txt.ref OUT.autotest/mulliken.txt 3 echo "Compare_mulliken_pass $?" >>$1 fi +#-------------------------------------------- +# obtain wave functions for each electronic +# state +#-------------------------------------------- if [ $calculation == "get_wf" ]; then nfile=0 # envfiles=`ls OUT.autotest/ | grep ENV$` @@ -440,6 +512,11 @@ if [ $calculation == "get_wf" ]; then fi fi + +#-------------------------------------------- +# obtian electron charge density for each +# electronic state +#-------------------------------------------- if [ $calculation == "get_pchg" ]; then nfile=0 # chgfiles=`ls OUT.autotest/ | grep -E '_CHG$'` @@ -467,6 +544,9 @@ if [ $calculation == "get_pchg" ]; then fi fi +#-------------------------------------------- +# implicit solvation model +#-------------------------------------------- if ! test -z "$imp_sol" && [ $imp_sol == 1 ]; then esol_el=`grep E_sol_el $running_path | awk '{print $3}'` esol_cav=`grep E_sol_cav $running_path | awk '{print $3}'` @@ -474,6 +554,9 @@ if ! test -z "$imp_sol" && [ $imp_sol == 1 ]; then echo "esolcavref $esol_cav" >>$1 fi +#-------------------------------------------- +# random phase approximation +#-------------------------------------------- if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then Etot_without_rpa=`grep Etot_without_rpa log.txt | awk 'BEGIN{FS=":"} {print $2}' ` echo "Etot_without_rpa $Etot_without_rpa" >> $1 @@ -482,6 +565,9 @@ if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then python3 ../tools/CompareFile.py $onref $oncal 8 fi +#-------------------------------------------- +# deepks +#-------------------------------------------- if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then sed '/n_des/d' OUT.autotest/deepks_desc.dat > des_tmp.txt total_des=`sum_file des_tmp.txt 5` @@ -501,6 +587,9 @@ if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then fi fi +#-------------------------------------------- +# band gap information +#-------------------------------------------- if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then odelta=`python3 get_odelta.py` echo "odelta $odelta" >>$1 @@ -508,6 +597,10 @@ if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then echo "oprec $oprec" >> $1 fi + +#-------------------------------------------- +# check vdelta in deepks +#-------------------------------------------- if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 @@ -517,6 +610,9 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then echo "totalvdp $totalvdp" >> $1 fi +#-------------------------------------------- +# check vdelta in deepks +#-------------------------------------------- if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 @@ -528,6 +624,9 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then echo "total_gevdm $total_gevdm" >> $1 fi +#-------------------------------------------- +# check symmetry +#-------------------------------------------- if ! test -z "$symmetry" && [ $symmetry == 1 ]; then pointgroup=`grep 'POINT GROUP' $running_path | tail -n 2 | head -n 1 | awk '{print $4}'` spacegroup=`grep 'SPACE GROUP' $running_path | tail -n 1 | awk '{print $7}'` @@ -537,6 +636,9 @@ if ! test -z "$symmetry" && [ $symmetry == 1 ]; then echo "nksibzref $nksibz" >>$1 fi +#-------------------------------------------- +# check currents in rt-TDDFT +#-------------------------------------------- if ! test -z "$out_current" && [ $out_current ]; then current1ref=refcurrent_total.dat current1cal=OUT.autotest/current_total.dat @@ -544,6 +646,9 @@ if ! test -z "$out_current" && [ $out_current ]; then echo "CompareCurrent_pass $?" >>$1 fi +#-------------------------------------------- +# Linear response function +#-------------------------------------------- if [ $is_lr == 1 ]; then lrns=$(get_input_key_value "lr_nstates" "INPUT") lrns1=`echo "$lrns + 1" |bc` @@ -552,6 +657,9 @@ if [ $is_lr == 1 ]; then echo "totexcitationenergyref $lreig_tot" >>$1 fi +#-------------------------------------------- +# Check RDMFT method +#-------------------------------------------- if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then echo "" >>$1 echo "The following energy units are in Rydberg:" >>$1 @@ -586,6 +694,9 @@ if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then echo "" >>$1 fi +#-------------------------------------------- +# Check time information +#-------------------------------------------- #echo $total_band -ttot=`grep $word $running_path | awk '{print $3}'` +ttot=`grep $word_total_time $running_path | awk '{print $3}'` echo "totaltimeref $ttot" >>$1 diff --git a/tests/integrate/tools/run_check.sh b/tests/integrate/tools/run_check.sh index 98230887d38..d0066fd1349 100755 --- a/tests/integrate/tools/run_check.sh +++ b/tests/integrate/tools/run_check.sh @@ -1,17 +1,23 @@ #!/bin/bash - +# check_out: checking the output information +# input: result.out check_out(){ outfile=$1 worddir=`awk '{print $1}' $outfile` for word in $worddir; do + # serach result.out and get information cal=`grep "$word" $outfile | awk '{printf "%.'$CA'f\n",$2}'` + # search result.ref and get information ref=`grep "$word" result.ref | awk '{printf "%.'$CA'f\n",$2}'` + # compute the error between 'cal' and 'ref' error=`awk 'BEGIN {x='$ref';y='$cal';printf "%.'$CA'f\n",x-y}'` + # compare the total time if [ $word == "totaltimeref" ]; then echo "$word this-test: $cal ref-1core-test: $ref" break fi + # except the total time, other comparison may lead to 'wrong' results if [ $(echo "$error == 0"|bc) = 0 ]; then echo "----------Wrong!----------" echo "word cal ref error" @@ -21,34 +27,43 @@ check_out(){ done } -test -e ../general_info||echo "plese write the file general_info" -test -e ../general_info||exit 0 +test -e ../general_info|| echo "plese prepare the general_info file." + +test -e ../general_info|| exit 0 + exec_path=`grep EXEC ../general_info|awk '{printf $2}'` + test -e $exec_path || echo "Error! ABACUS path was wrong!!" + test -e $exec_path || exit 0 + CA=`grep CHECKACCURACY ../general_info | awk '{printf $2}'` + NP=`grep NUMBEROFPROCESS ../general_info | awk '{printf $2}'` - path_here=`pwd` - echo "Test in $path_here" - - echo "Begin test with $NP cores" - #parallel test - mpirun -np $NP $exec_path > log.txt - test -d OUT.autotest || echo "Some errors happened in ABACUS!" - test -d OUT.autotest || exit 0 - - #if any input parameters for this script, just generate reference file. - if test -z $1 - then - ../tools/catch_properties.sh result.out - check_out result.out - elif [ $1 == "debug" ] - then - ./catch_properties.sh result.out - check_out result.out - else - ../tools/catch_properties.sh result.ref - rm -r OUT.autotest - rm log.txt - fi +path_here=`pwd` +echo "Test in $path_here" + +echo "Begin testing the example with $NP cores" + +#parallel test +mpirun -np $NP $exec_path > log.txt + +test -d OUT.autotest || echo "Some errors occured in ABACUS!" + +test -d OUT.autotest || exit 0 + +#if any input parameters for this script, just generate reference file. +if test -z $1 +then +../tools/catch_properties.sh result.out +check_out result.out +elif [ $1 == "debug" ] +then +./catch_properties.sh result.out +check_out result.out +else +../tools/catch_properties.sh result.ref +rm -r OUT.autotest +rm log.txt +fi