From 09f1e3eedfe2ffebbb2cb6840167aadfef47c779 Mon Sep 17 00:00:00 2001 From: pxlxingliang Date: Mon, 17 Jun 2024 15:30:49 +0800 Subject: [PATCH 1/2] feature: add the output of energy for all esolver in abacus.json --- source/module_esolver/esolver_ks.cpp | 3 +-- source/module_io/json_output/output_info.cpp | 13 ++++++------- source/module_io/json_output/output_info.h | 3 ++- source/module_relax/relax_driver.cpp | 5 +++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index ded060111f..c4363847f2 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -615,9 +615,8 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) #ifdef __RAPIDJSON // 14) add Json of efermi energy converge - Json::add_output_efermi_energy_converge( + Json::add_output_efermi_converge( this->pelec->eferm.ef * ModuleBase::Ry_to_eV, - this->pelec->f_en.etot * ModuleBase::Ry_to_eV, this->conv_elec ); #endif //__RAPIDJSON diff --git a/source/module_io/json_output/output_info.cpp b/source/module_io/json_output/output_info.cpp index 02a73058f4..f8fb4971d7 100644 --- a/source/module_io/json_output/output_info.cpp +++ b/source/module_io/json_output/output_info.cpp @@ -131,15 +131,14 @@ namespace Json } - void add_output_efermi_energy_converge(double efermi, double energy ,bool scf_converge ){ + void add_output_efermi_converge(double efermi, bool scf_converge ){ Json::AbacusJson::add_json({"output",-1,"e_fermi"}, efermi,false); - Json::AbacusJson::add_json({"output",-1,"energy"}, energy,false); Json::AbacusJson::add_json({"output",-1,"scf_converge"}, scf_converge,false); - - // Json::AbacusJson::add_Json(efermi,false,"output",-1,"e_fermi"); - // Json::AbacusJson::add_Json(energy,false,"output",-1,"energy"); - // Json::AbacusJson::add_Json(scf_converge,false,"output",-1,"scf_converge"); - + } + + void add_output_energy(double energy) + { + Json::AbacusJson::add_json({"output",-1,"energy"}, energy,false); } void add_output_scf_mag( diff --git a/source/module_io/json_output/output_info.h b/source/module_io/json_output/output_info.h index 7254092ac9..e2294acb66 100644 --- a/source/module_io/json_output/output_info.h +++ b/source/module_io/json_output/output_info.h @@ -23,7 +23,8 @@ namespace Json ModuleBase::matrix stress, double unit_transform ); - void add_output_efermi_energy_converge(double efermi, double energy ,bool scf_converge ); + void add_output_efermi_converge(double efermi, bool scf_converge ); + void add_output_energy(double energy ); void add_output_scf_mag( double total_mag, double absolute_mag, diff --git a/source/module_relax/relax_driver.cpp b/source/module_relax/relax_driver.cpp index a4bea29365..57cadfeff8 100644 --- a/source/module_relax/relax_driver.cpp +++ b/source/module_relax/relax_driver.cpp @@ -132,6 +132,11 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver *p_esolver) GlobalV::ofs_running << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl; } } + +#ifdef __RAPIDJSON + // add the energy to outout + Json::add_output_energy(p_esolver->cal_energy() * ModuleBase::Ry_to_eV); +#endif } #ifdef __RAPIDJSON //add Json of cell coo stress force From 7a261bd3701a515966b777be015b2bea70fe436d Mon Sep 17 00:00:00 2001 From: pxlxingliang Date: Tue, 18 Jun 2024 09:15:26 +0800 Subject: [PATCH 2/2] using const input paramter in json output functions --- source/module_io/json_output/output_info.cpp | 10 +++++----- source/module_io/json_output/output_info.h | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/module_io/json_output/output_info.cpp b/source/module_io/json_output/output_info.cpp index f8fb4971d7..74bd3bd994 100644 --- a/source/module_io/json_output/output_info.cpp +++ b/source/module_io/json_output/output_info.cpp @@ -41,9 +41,9 @@ namespace Json } void add_output_cell_coo_stress_force( - UnitCell *ucell, - ModuleBase::matrix force, double fac, - ModuleBase::matrix stress, double unit_transform + const UnitCell *ucell, + const ModuleBase::matrix force, const double fac, + const ModuleBase::matrix stress, const double unit_transform ) { int iat = 0; const double output_acc = 1.0e-8; @@ -131,12 +131,12 @@ namespace Json } - void add_output_efermi_converge(double efermi, bool scf_converge ){ + void add_output_efermi_converge(const double efermi, const bool scf_converge ){ Json::AbacusJson::add_json({"output",-1,"e_fermi"}, efermi,false); Json::AbacusJson::add_json({"output",-1,"scf_converge"}, scf_converge,false); } - void add_output_energy(double energy) + void add_output_energy(const double energy) { Json::AbacusJson::add_json({"output",-1,"energy"}, energy,false); } diff --git a/source/module_io/json_output/output_info.h b/source/module_io/json_output/output_info.h index e2294acb66..0be4254922 100644 --- a/source/module_io/json_output/output_info.h +++ b/source/module_io/json_output/output_info.h @@ -18,17 +18,17 @@ namespace Json void init_output_array_obj(); void add_output_cell_coo_stress_force( - UnitCell *ucell, - ModuleBase::matrix force, double fac, - ModuleBase::matrix stress, double unit_transform + const UnitCell *ucell, + const ModuleBase::matrix force, const double fac, + const ModuleBase::matrix stress, const double unit_transform ); - void add_output_efermi_converge(double efermi, bool scf_converge ); - void add_output_energy(double energy ); + void add_output_efermi_converge(const double efermi, const bool scf_converge ); + void add_output_energy(const double energy ); void add_output_scf_mag( - double total_mag, double absolute_mag, - double energy, double ediff, double drho,double time + const double total_mag, const double absolute_mag, + const double energy, const double ediff, const double drho,const double time ); #endif