Skip to content

Commit 497fd0f

Browse files
committed
Refactor: Unify the output of BFGS, CG, and FIRE relaxation method.
1 parent 29b3abc commit 497fd0f

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

source/module_md/fire.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress)
7474
{
7575
MD_base::print_md(ofs, cal_stress);
7676

77-
ofs << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl;
77+
GlobalV::ofs_running << "\n Largest gradient in force is " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << " eV/A." << std::endl;
78+
GlobalV::ofs_running << "\n Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
7879
std::cout << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl;
7980

8081
return;

source/module_relax/relax_new/relax.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma
138138
{
139139
std::cout << " ETOT DIFF (eV) : " << etot - etot_p << std::endl;
140140
std::cout << " LARGEST GRAD (eV/A) : " << max_grad << std::endl;
141+
GlobalV::ofs_running << "\n Largest gradient in force is " << max_grad << " eV/A." << std::endl;
142+
GlobalV::ofs_running << "\n Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
141143
etot_p = etot;
142144
}
143145
//=========================================
@@ -223,8 +225,8 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma
223225
force_converged = false;
224226
}
225227

226-
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << std::endl;
227-
GlobalV::ofs_running << "\n Threshold is = " << PARAM.inp.stress_thr << std::endl;
228+
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
229+
GlobalV::ofs_running << "\n Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
228230
}
229231

230232
if(force_converged)

source/module_relax/relax_old/ions_move_basic.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ void Ions_Move_Basic::check_converged(const UnitCell &ucell, const double *grad)
147147
std::cout << " ETOT DIFF (eV) : " << Ions_Move_Basic::ediff * ModuleBase::Ry_to_eV << std::endl;
148148
std::cout << " LARGEST GRAD (eV/A) : " << Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / 0.529177
149149
<< std::endl;
150+
151+
GlobalV::ofs_running << "\n Largest gradient in force is " << largest_grad * ModuleBase::Ry_to_eV / 0.529177
152+
<< " eV/A." << std::endl;
153+
GlobalV::ofs_running << "\n Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
150154
}
151155

152156
const double etot_diff = std::abs(Ions_Move_Basic::ediff);
@@ -165,8 +169,6 @@ void Ions_Move_Basic::check_converged(const UnitCell &ucell, const double *grad)
165169
{
166170
GlobalV::ofs_running << "\n Ion relaxation is converged!" << std::endl;
167171
GlobalV::ofs_running << "\n Energy difference (Ry) = " << etot_diff << std::endl;
168-
GlobalV::ofs_running << "\n Largest gradient is (eV/A) = " << largest_grad * ModuleBase::Ry_to_eV / 0.529177
169-
<< std::endl;
170172

171173
Ions_Move_Basic::converged = true;
172174
++Ions_Move_Basic::update_iter;

source/module_relax/relax_old/lattice_change_basic.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
207207
if (Lattice_Change_Basic::largest_grad < PARAM.inp.stress_thr && stress_ii_max < PARAM.inp.stress_thr)
208208
{
209209
GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl;
210-
GlobalV::ofs_running << "\n Largest gradient is = " << largest_grad << std::endl;
210+
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
211+
GlobalV::ofs_running << "\n Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
211212
Lattice_Change_Basic::converged = true;
212213
++Lattice_Change_Basic::update_iter;
213214
}
@@ -227,7 +228,8 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
227228
if (Lattice_Change_Basic::largest_grad < 10 * PARAM.inp.stress_thr)
228229
{
229230
GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl;
230-
GlobalV::ofs_running << "\n Largest gradient is = " << largest_grad << std::endl;
231+
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
232+
GlobalV::ofs_running << "\n Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
231233
Lattice_Change_Basic::converged = true;
232234
++Lattice_Change_Basic::update_iter;
233235
}

0 commit comments

Comments
 (0)