Skip to content

Commit

Permalink
Fix: title of force output (#3093)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuLiu98 authored Oct 24, 2023
1 parent b1ac4a4 commit 3b99988
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace ModuleESolver
void ESolver_DP::cal_Force(ModuleBase::matrix& force)
{
force = dp_force;
ModuleIO::print_force(GlobalV::ofs_running, *ucell_, " TOTAL-FORCE (eV/Angstrom)", force, false);
ModuleIO::print_force(GlobalV::ofs_running, *ucell_, "TOTAL-FORCE (eV/Angstrom)", force, false);
}

void ESolver_DP::cal_Stress(ModuleBase::matrix& stress)
Expand Down
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_lj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace ModuleESolver
void ESolver_LJ::cal_Force(ModuleBase::matrix& force)
{
force = lj_force;
ModuleIO::print_force(GlobalV::ofs_running, *ucell_, " TOTAL-FORCE (eV/Angstrom)", force, false);
ModuleIO::print_force(GlobalV::ofs_running, *ucell_, "TOTAL-FORCE (eV/Angstrom)", force, false);
}

void ESolver_LJ::cal_Stress(ModuleBase::matrix& stress)
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void Force_Stress_LCAO<T>::getForceStress(const bool isforce,
GlobalV::ofs_running << std::setiosflags(std::ios::left);

// this->printforce_total(ry, istestf, fcs);
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, " TOTAL-FORCE (eV/Angstrom)", fcs, 0);
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, "TOTAL-FORCE (eV/Angstrom)", fcs, 0);
if (istestf)
{
GlobalV::ofs_running << "\n FORCE INVALID TABLE." << std::endl;
Expand Down
3 changes: 0 additions & 3 deletions source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class Force_Stress_LCAO
Stress_Func<double> sc_pw;
Forces<double> f_pw;

void print_force(const std::string& name, ModuleBase::matrix& f, const bool screen, bool ry) const;
void printforce_total(const bool ry, const bool istestf, ModuleBase::matrix& fcs);

void forceSymmetry(ModuleBase::matrix& fcs, ModuleSymmetry::Symmetry* symm);

void calForcePwPart(ModuleBase::matrix& fvl_dvl,
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_pw/hamilt_pwdft/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void Forces<FPTYPE, Device>::cal_force(ModuleBase::matrix& force,
if (GlobalV::imp_sol)
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, "IMP_SOL FORCE (eV/Angstrom)", forcesol, 0);
}
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, " TOTAL-FORCE (eV/Angstrom)", force, 0);
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, "TOTAL-FORCE (eV/Angstrom)", force, 0);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_pw/hamilt_stodft/sto_forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void Sto_Forces::cal_stoforce(ModuleBase::matrix& force,
force_gate,
0);
}
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, " TOTAL-FORCE (eV/Angstrom)", force, 0);
ModuleIO::print_force(GlobalV::ofs_running, GlobalC::ucell, "TOTAL-FORCE (eV/Angstrom)", force, 0);
ModuleBase::timer::tick("Sto_Force", "cal_force");
return;
}
Expand Down
5 changes: 2 additions & 3 deletions source/module_io/output_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void print_force(std::ofstream& ofs_running,
std::vector<double> force_y;
std::vector<double> force_z;
std::string table;
context.set_context({"title", "force", "force", "force"});
context.set_context({"short_title", "force", "force", "force"});
int iat = 0;
for (int it = 0; it < cell.ntype; it++)
{
Expand All @@ -67,9 +67,8 @@ void print_force(std::ofstream& ofs_running,
}

context.enable_title();
context << "atom" << atom_label << "x" << force_x << "y" << force_y << "z" << force_z;
context << name.c_str() << atom_label << "" << force_x << "" << force_y << "" << force_z;
context.center_title();
context.set_overall_title("TOTAL-FORCE (eV/Angstrom)");
table = context.str();
ofs_running << table << std::endl;
if (GlobalV::TEST_FORCE)
Expand Down
16 changes: 8 additions & 8 deletions source/module_io/test/outputlog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,22 @@ TEST(PrintForce, PrintForce)
std::ifstream ifs("test.txt");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("TOTAL-FORCE (eV/Angstrom)"));
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr("---------------------------------------------------------------------"));
testing::HasSubstr("---------------------------------------------------------------------------"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("atom x y z "));
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(" Al1 25.7110532015 51.4221064030 77.1331596044"));
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"));
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");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integrate/tools/catch_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fi
#echo $etot
#echo "hasforce:"$has_force
if ! test -z "$has_force" && [ $has_force == 1 ]; then
nn3=`echo "$natom + 4" |bc`
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
Expand Down

0 comments on commit 3b99988

Please sign in to comment.