diff --git a/source/source_base/matrix.cpp b/source/source_base/matrix.cpp index 7d58a7c867b..f047f48462f 100644 --- a/source/source_base/matrix.cpp +++ b/source/source_base/matrix.cpp @@ -323,35 +323,6 @@ double matrix::trace_on(void) const return tr; } -//this function is wrong, and there is no file use this function. -// void matrix::get_extreme_eigen_values(double &ev_lower, double &ev_upper)const -// { -// double *a = new double[nr]; -// double *b = new double[nr]; -// for (int i = 0; i < nr; ++i) -// { -// double sum = 0.0; -// for(int j = 0; j < nc; ++j) -// { -// sum += fabs(c[i * nc + j]); -// } -// sum -= fabs(c[i * nc + i]); -// a[i] = c[i * nc + i] - sum; -// b[i] = c[i * nc + i] + sum; -// } - -// ev_lower = a[0]; -// ev_upper = b[0]; - -// for (int i = 1; i < nr; ++i) -// { -// if (a[i] < ev_lower) ev_lower = a[i]; -// if (b[i] > ev_upper) ev_upper = b[i]; -// } -// delete[] a; -// delete[] b; -// } - // Peize Lin add 2017-05-27 void matrix::reshape( const int nr_new, const int nc_new, const bool flag_zero ) { diff --git a/source/source_base/matrix.h b/source/source_base/matrix.h index d4c9cb51b64..0a117b4ca1a 100644 --- a/source/source_base/matrix.h +++ b/source/source_base/matrix.h @@ -10,7 +10,7 @@ #include #include -#include// test +#include // test namespace ModuleBase { @@ -80,7 +80,7 @@ class matrix std::ostream & print( std::ostream & os, const double threshold=0.0 ) const; // Peize Lin add 2021.09.08 - using type=double; // Peiae Lin add 2022.08.08 for template + using type=double; // Peize Lin add 2022.08.08 for template }; diff --git a/source/source_cell/cell_index.cpp b/source/source_cell/cell_index.cpp index 75708dec76a..c147afa936f 100644 --- a/source/source_cell/cell_index.cpp +++ b/source/source_cell/cell_index.cpp @@ -2,7 +2,6 @@ #include "source_base/name_angular.h" #include "source_base/tool_quit.h" -#include CellIndex::CellIndex(const std::vector& atomLabels_in, const std::vector& atomCounts_in, @@ -18,12 +17,12 @@ CellIndex::CellIndex(const std::vector& atomLabels_in, this->cal_orbitalCounts(); } -int CellIndex::get_ntype() +int CellIndex::get_ntype() const { return this->atomCounts.size(); } -int CellIndex::get_nat() +int CellIndex::get_nat() const { int nat = 0; for (int it = 0; it < this->atomCounts.size(); ++it) @@ -33,12 +32,12 @@ int CellIndex::get_nat() return nat; } -int CellIndex::get_nat(int it) +int CellIndex::get_nat(int it) const { return this->atomCounts[it]; } -int CellIndex::get_nw() +int CellIndex::get_nw() const { int nw = 0; for (int it = 0; it < this->orbitalCounts.size(); ++it) @@ -48,13 +47,13 @@ int CellIndex::get_nw() return nw; } -int CellIndex::get_nw(int iat) +int CellIndex::get_nw(int iat) const { int it = this->iat2it(iat); return this->orbitalCounts[it]; } -int CellIndex::get_iwt(int iat, int orbital_index) +int CellIndex::get_iwt(int iat, int orbital_index) const { if (iat < 0 || iat >= this->get_nat()) { @@ -83,14 +82,14 @@ int CellIndex::get_iwt(int iat, int orbital_index) return iwt; } -int CellIndex::get_maxL(int iat) +int CellIndex::get_maxL(int iat) const { int it = this->iat2it(iat); return this->lnchiCounts[it].size() - 1; } /// @brief get nchi -int CellIndex::get_nchi(int iat, int L) +int CellIndex::get_nchi(int iat, int L) const { int it = this->iat2it(iat); if (L < 0 || L >= this->lnchiCounts[it].size()) @@ -119,7 +118,7 @@ void CellIndex::check_atomCounts() } } -std::string CellIndex::get_atom_label(int iat, bool order) +std::string CellIndex::get_atom_label(int iat, bool order) const { int it = this->iat2it(iat); int ia = this->iat2ia(iat); @@ -129,7 +128,7 @@ std::string CellIndex::get_atom_label(int iat, bool order) return atomType; } -int CellIndex::iat2it(int iat) +int CellIndex::iat2it(int iat) const { int running_iat = 0; int it = -1; // Tracks the index of the atom in atomLabels @@ -151,7 +150,7 @@ int CellIndex::iat2it(int iat) return it; } -int CellIndex::iat2ia(int iat) +int CellIndex::iat2ia(int iat) const { int it = this->iat2it(iat); // sum of atoms of previous types @@ -163,7 +162,7 @@ int CellIndex::iat2ia(int iat) return iat - running_iat; } -int CellIndex::iw2l(int iat, int iw) +int CellIndex::iw2l(int iat, int iw) const { int it = this->iat2it(iat); int maxL = this->lnchiCounts[it].size() - 1; @@ -185,10 +184,10 @@ int CellIndex::iw2l(int iat, int iw) { ModuleBase::WARNING_QUIT("CellIndex::iw2l", "localized wave funciton index out of range [0, nw)"); } - throw std::out_of_range(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + ModuleBase::WARNING_QUIT("CellIndex::iw2l", "unreachable code reached"); } -int CellIndex::iw2z(int iat, int iw) +int CellIndex::iw2z(int iat, int iw) const { int it = this->iat2it(iat); int maxL = this->lnchiCounts[it].size() - 1; @@ -208,12 +207,12 @@ int CellIndex::iw2z(int iat, int iw) } if (iw >= 0) { - ModuleBase::WARNING_QUIT("CellIndex::iw2l", "localized wave funciton index out of range [0, nw)"); + ModuleBase::WARNING_QUIT("CellIndex::iw2z", "localized wave funciton index out of range [0, nw)"); } - throw std::out_of_range(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + ModuleBase::WARNING_QUIT("CellIndex::iw2z", "unreachable code reached"); } -int CellIndex::iw2m(int iat, int iw) +int CellIndex::iw2m(int iat, int iw) const { int it = this->iat2it(iat); int maxL = this->lnchiCounts[it].size() - 1; @@ -233,9 +232,9 @@ int CellIndex::iw2m(int iat, int iw) } if (iw >= 0) { - ModuleBase::WARNING_QUIT("CellIndex::iw2l", "localized wave funciton index out of range [0, nw)"); + ModuleBase::WARNING_QUIT("CellIndex::iw2m", "localized wave funciton index out of range [0, nw)"); } - throw std::out_of_range(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + ModuleBase::WARNING_QUIT("CellIndex::iw2m", "unreachable code reached"); } bool CellIndex::check_nspin(int nspin) @@ -262,7 +261,7 @@ void CellIndex::cal_orbitalCounts() } } -void CellIndex::write_orb_info(std::string out_dir) +void CellIndex::write_orb_info(const std::string& out_dir) const { std::stringstream os; os << out_dir << "Orbital"; diff --git a/source/source_cell/cell_index.h b/source/source_cell/cell_index.h index caa2645e201..ed24e521906 100644 --- a/source/source_cell/cell_index.h +++ b/source/source_cell/cell_index.h @@ -28,25 +28,25 @@ class CellIndex public: /// @brief the total number of atoms - int get_nat(); + int get_nat() const; /// @brief the total number of atoms of a given type - int get_nat(int it); + int get_nat(int it) const; /// @brief get ntype - int get_ntype(); + int get_ntype() const; /// @brief get nw - int get_nw(); + int get_nw() const; /// @brief get nw of a given type - int get_nw(int iat); + int get_nw(int iat) const; /// @brief get iwt - int get_iwt(int iat, int orbital_index); + int get_iwt(int iat, int orbital_index) const; /// @brief get maximum L of a given atom - int get_maxL(int iat); + int get_maxL(int iat) const; /// @brief get nchi of a given atom and a give L - int get_nchi(int iat, int L); + int get_nchi(int iat, int L) const; /// @brief get atom label of a given atom - std::string get_atom_label(int iat, bool order = false); + std::string get_atom_label(int iat, bool order = false) const; /// @brief write orbital info into file - void write_orb_info(std::string out_dir); + void write_orb_info(const std::string& out_dir) const; private: /// atomCounts is a vector used to store the number of atoms for each type @@ -66,15 +66,15 @@ class CellIndex /// check if atomCounts is set ok void check_atomCounts(); /// get type of atom from total order - int iat2it(int iat); + int iat2it(int iat) const; /// get index of atom in the same type - int iat2ia(int iat); + int iat2ia(int iat) const; /// get L from iw - int iw2l(int iat, int iw); + int iw2l(int iat, int iw) const; /// get Z from iw - int iw2z(int iat, int iw); + int iw2z(int iat, int iw) const; /// get m from iw - int iw2m(int iat, int iw); + int iw2m(int iat, int iw) const; }; #endif // CELL_INDEX_H diff --git a/source/source_estate/module_dm/density_matrix.cpp b/source/source_estate/module_dm/density_matrix.cpp index e5ad1ba620b..97ca3032599 100644 --- a/source/source_estate/module_dm/density_matrix.cpp +++ b/source/source_estate/module_dm/density_matrix.cpp @@ -5,6 +5,7 @@ #include "source_base/memory.h" #include "source_base/timer.h" #include "source_base/tool_title.h" +#include "source_base/tool_quit.h" #include "source_base/constants.h" #include "source_cell/klist.h" @@ -612,7 +613,7 @@ void DensityMatrix::switch_dmr(const int mode) } break; default: - throw std::string("Unknown mode in switch_dmr"); + ModuleBase::WARNING_QUIT("density_matrix.cpp", "Unknown mode in switch_dmr"); } ModuleBase::timer::tick("DensityMatrix", "switch_dmr"); } diff --git a/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp b/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp index 0e9e01a7d28..e92f4ad3672 100644 --- a/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp +++ b/source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp @@ -3,7 +3,7 @@ namespace ModuleSymmetry { std::string mat3_fmt(const ModuleBase::Matrix3& m) { - auto s = [](auto x) { return std::to_string(x); }; + auto s = [](double x) { return std::to_string(x); }; return s(m.e11) + " " + s(m.e12) + " " + s(m.e13) + "\n" + s(m.e21) + " " + s(m.e22) + " " + s(m.e23) + "\n" + s(m.e31) + " " + s(m.e32) + " " + s(m.e33); diff --git a/source/source_md/md_base.cpp b/source/source_md/md_base.cpp index 9e5b0e7c6aa..390e1c2b082 100644 --- a/source/source_md/md_base.cpp +++ b/source/source_md/md_base.cpp @@ -62,7 +62,7 @@ void MD_base::setup(ModuleESolver::ESolver* p_esolver, const std::string& global // mohan add 2026-01-04 const int stress_step = 0; - const int force_step = 0; + const int force_step = 0; const int istep_print = step_ + step_rst_ + 1; ModuleIO::print_screen(stress_step, force_step, istep_print); diff --git a/source/source_md/md_func.cpp b/source/source_md/md_func.cpp index d57815cc33f..df76de36f57 100644 --- a/source/source_md/md_func.cpp +++ b/source/source_md/md_func.cpp @@ -195,18 +195,18 @@ void init_vel(const UnitCell& unit_in, ModuleBase::Vector3 frozen; get_mass_mbl(unit_in, allmass, frozen, ionmbl); frozen_freedom = frozen.x + frozen.y + frozen.z; - if (frozen.x == 0) - { - ++frozen_freedom; - } - if (frozen.y == 0) - { - ++frozen_freedom; - } - if (frozen.z == 0) - { - ++frozen_freedom; - } + if (frozen.x == 0) + { + ++frozen_freedom; + } + if (frozen.y == 0) + { + ++frozen_freedom; + } + if (frozen.z == 0) + { + ++frozen_freedom; + } if (unit_in.init_vel) { diff --git a/source/source_md/run_md.cpp b/source/source_md/run_md.cpp index bd39ffc6cc2..3a5ffe9f19a 100644 --- a/source/source_md/run_md.cpp +++ b/source/source_md/run_md.cpp @@ -56,8 +56,8 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet } else { - // mohan add 2026-01-04 - const int stress_step = 0; + // mohan add 2026-01-04 + const int stress_step = 0; const int force_step = 0; const int istep_print = mdrun->step_ + mdrun->step_rst_ + 1; ModuleIO::print_screen(stress_step, force_step, istep_print);