diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 9f5785664f..30b9206a72 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -760,6 +760,7 @@ OBJS_SRCPW=H_Ewald_pw.o\ sto_dos.o\ onsite_projector.o\ onsite_proj_tools.o\ + onsite_proj_print.o\ vsep_pw.o OBJS_VDW=vdw.o\ diff --git a/source/source_pw/module_pwdft/CMakeLists.txt b/source/source_pw/module_pwdft/CMakeLists.txt index 9e34e9c7b4..eb8f162437 100644 --- a/source/source_pw/module_pwdft/CMakeLists.txt +++ b/source/source_pw/module_pwdft/CMakeLists.txt @@ -49,6 +49,7 @@ list(APPEND objects radial_proj.cpp onsite_projector.cpp onsite_proj_tools.cpp + onsite_proj_print.cpp vsep_pw.cpp ) diff --git a/source/source_pw/module_pwdft/onsite_proj_print.cpp b/source/source_pw/module_pwdft/onsite_proj_print.cpp new file mode 100644 index 0000000000..adb6e1246c --- /dev/null +++ b/source/source_pw/module_pwdft/onsite_proj_print.cpp @@ -0,0 +1,105 @@ +#include "source_pw/module_pwdft/onsite_proj_print.h" +#include "source_base/formatter.h" + +namespace projectors { +namespace print { + +void print_orb_chg( + const UnitCell* ucell, + const std::vector>& occs, + const std::vector& iat_nh, + const std::vector& atom_labels) +{ + // parameters for orbital charge output + FmtCore fmt_of_chg("%15.4f"); + FmtCore fmt_of_label("%-15s"); + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << "-------------------------------------------------------------------------------------------" << std::endl; + GlobalV::ofs_running << "Orbital Charge Analysis Charge Mag(x) Mag(y) Mag(z)" << std::endl; + GlobalV::ofs_running << "-------------------------------------------------------------------------------------------" << std::endl; + + // parameters for mag output + std::vector mag_x(ucell->nat, 0.0); + std::vector mag_y(ucell->nat, 0.0); + std::vector mag_z(ucell->nat, 0.0); + const std::vector title = {"Total Magnetism (uB)", "", "", ""}; + const std::vector fmts = {"%-26s", "%20.10f", "%20.10f", "%20.10f"}; + const std::vector orb_names = {"s", "p", "d", "f", "g"}; + FmtTable table(/*titles=*/title, + /*nrows=*/ucell->nat, + /*formats=*/fmts, + /*indent=*/0, + /*align=*/{/*value*/FmtTable::Align::RIGHT, /*title*/FmtTable::Align::LEFT}); + // parameters for mag output + int occ_index = 0; + for(int iat=0; iatnat; iat++) + { + const int it = ucell->iat2it[iat]; + std::string atom_label = atom_labels[it]; + int ia = ucell->iat2ia[iat]; + GlobalV::ofs_running << FmtCore::format("%-20s", atom_label+std::to_string(ia+1)) << std::endl; + std::vector sum(4, 0.0); + int current_l = 1; + std::vector charge_mag(4, 0.0); + for(int ih=0; ih& atom_labels, + const std::vector& mag_x, + const std::vector& mag_y, + const std::vector& mag_z) +{ + const std::vector title = {"Total Magnetism (uB)", "", "", ""}; + const std::vector fmts = {"%-26s", "%20.10f", "%20.10f", "%20.10f"}; + FmtTable table(/*titles=*/title, + /*nrows=*/mag_x.size(), + /*formats=*/fmts, + /*indent=*/0, + /*align=*/{/*value*/FmtTable::Align::RIGHT, /*title*/FmtTable::Align::LEFT}); + + table << atom_labels << mag_x << mag_y << mag_z; + GlobalV::ofs_running << table.str() << std::endl; +} + +void print_proj_status(int it, int nproj_it) +{ + if(nproj_it == 0) + { + std::cout << "BECP_PW >> No projectors defined for type " << it << std::endl; + } +} + +} // namespace print +} // namespace projectors diff --git a/source/source_pw/module_pwdft/onsite_proj_print.h b/source/source_pw/module_pwdft/onsite_proj_print.h new file mode 100644 index 0000000000..12e5a97743 --- /dev/null +++ b/source/source_pw/module_pwdft/onsite_proj_print.h @@ -0,0 +1,52 @@ +#ifndef MODULEHAMILTPW_ONSITE_PROJ_PRINT_H +#define MODULEHAMILTPW_ONSITE_PROJ_PRINT_H + +#include "source_cell/unitcell.h" +#include "source_base/global_variable.h" +#include +#include +#include + +namespace projectors { +namespace print { + +/** + * @brief Print orbital charge analysis + * + * @param ucell Unit cell pointer + * @param occs Occupation numbers + * @param iat_nh Number of projectors per atom + * @param atom_labels Atom labels + */ +void print_orb_chg( + const UnitCell* ucell, + const std::vector>& occs, + const std::vector& iat_nh, + const std::vector& atom_labels); + +/** + * @brief Print magnetism table + * + * @param atom_labels Atom labels + * @param mag_x Magnetic moment in x direction + * @param mag_y Magnetic moment in y direction + * @param mag_z Magnetic moment in z direction + */ +void print_mag_table( + const std::vector& atom_labels, + const std::vector& mag_x, + const std::vector& mag_y, + const std::vector& mag_z); + +/** + * @brief Print projector initialization status + * + * @param it Atom type index + * @param nproj_it Number of projectors for this type + */ +void print_proj_status(int it, int nproj_it); + +} // namespace print +} // namespace projectors + +#endif // MODULEHAMILTPW_ONSITE_PROJ_PRINT_H diff --git a/source/source_pw/module_pwdft/onsite_projector.cpp b/source/source_pw/module_pwdft/onsite_projector.cpp index 1cb7dc1440..d0574fff5a 100644 --- a/source/source_pw/module_pwdft/onsite_projector.cpp +++ b/source/source_pw/module_pwdft/onsite_projector.cpp @@ -5,6 +5,7 @@ #include #include #include "source_pw/module_pwdft/onsite_projector.h" +#include "source_pw/module_pwdft/onsite_proj_print.h" #include "source_base/projgen.h" #include "source_base/kernels/math_kernel_op.h" @@ -226,9 +227,9 @@ void projectors::OnsiteProjector::init_proj(const std::string& orbita { const int nproj_it = nproj[it]; this->it2iproj[it].resize(nproj_it); + print::print_proj_status(it, nproj_it); if(nproj_it == 0) { - std::cout << "BECP_PW >> No projectors defined for type " << it << std::endl; continue; } std::ifstream ifs(orbital_dir + orb_files[it]); @@ -573,70 +574,9 @@ void projectors::OnsiteProjector::cal_occupations( const int npool = GlobalV::KPAR * PARAM.inp.bndpar; Parallel_Reduce::reduce_double_allpool(npool, GlobalV::NPROC_IN_POOL, (double*)(&(occs[0])), occs.size()*2); // occ has been reduced and calculate mag - // parameters for orbital charge output - FmtCore fmt_of_chg("%15.4f"); - FmtCore fmt_of_label("%-15s"); - GlobalV::ofs_running << std::endl; - GlobalV::ofs_running << "-------------------------------------------------------------------------------------------" << std::endl; - GlobalV::ofs_running << "Orbital Charge Analysis Charge Mag(x) Mag(y) Mag(z)" << std::endl; - GlobalV::ofs_running << "-------------------------------------------------------------------------------------------" << std::endl; - - // parameters for orbital charge output - // parameters for mag output - std::vector mag_x(this->ucell->nat, 0.0); - std::vector mag_y(this->ucell->nat, 0.0); - std::vector mag_z(this->ucell->nat,0.0); - auto atomLabels = this->ucell->get_atomLabels(); - const std::vector title = {"Total Magnetism (uB)", "", "", ""}; - const std::vector fmts = {"%-26s", "%20.10f", "%20.10f", "%20.10f"}; - const std::vector orb_names = {"s", "p", "d", "f", "g"}; - FmtTable table(/*titles=*/title, - /*nrows=*/this->ucell->nat, - /*formats=*/fmts, - /*indent=*/0, - /*align=*/{/*value*/FmtTable::Align::RIGHT, /*title*/FmtTable::Align::LEFT}); - // parameters for mag output - int occ_index = 0; - for(int iat=0;iatucell->nat;iat++) - { - const int it = this->ucell->iat2it[iat]; - std::string atom_label = atomLabels[it]; - int ia = this->ucell->iat2ia[iat]; - GlobalV::ofs_running << FmtCore::format("%-20s", atom_label+std::to_string(ia+1)) << std::endl; - std::vector sum(4, 0.0); - int current_l = 1; - std::vector charge_mag(4, 0.0); - for(int ih=0;ihiat_nh[iat];ih++) - { - charge_mag[3] += (occs[occ_index] - occs[occ_index + 3]).real(); - charge_mag[1] += (occs[occ_index + 1] + occs[occ_index + 2]).real(); - charge_mag[2] += (occs[occ_index + 1] - occs[occ_index + 2]).imag(); - charge_mag[0] += (occs[occ_index] + occs[occ_index + 3]).real(); - if(ih == current_l * current_l - 1) - { - sum[0] += charge_mag[0]; - sum[1] += charge_mag[1]; - sum[2] += charge_mag[2]; - sum[3] += charge_mag[3]; - GlobalV::ofs_running << FmtCore::format("%20s", orb_names[current_l-1]) - << fmt_of_chg.format(charge_mag[0]) << fmt_of_chg.format(charge_mag[1]) - << fmt_of_chg.format(charge_mag[2]) << fmt_of_chg.format(charge_mag[3]) << std::endl; - current_l++; - charge_mag.assign(4, 0.0); - } - occ_index += 4; - } - mag_x[iat] = sum[1]; - mag_y[iat] = sum[2]; - mag_z[iat] = sum[3]; - GlobalV::ofs_running << FmtCore::format("%20s", std::string("Sum")) << "" - << fmt_of_chg.format(sum[0]) << fmt_of_chg.format(sum[1]) - << fmt_of_chg.format(sum[2]) << fmt_of_chg.format(sum[3]) << std::endl; - } - GlobalV::ofs_running << "-------------------------------------------------------------------------------------------" << std::endl; - GlobalV::ofs_running << std::endl; - table << atomLabels << mag_x << mag_y << mag_z; - GlobalV::ofs_running << table.str() << std::endl; + // Print orbital charge analysis + auto atom_labels = this->ucell->get_atomLabels(); + print::print_orb_chg(this->ucell, occs, this->iat_nh, atom_labels); // print charge ModuleBase::timer::end("OnsiteProj", "cal_occupation");