From 00305bf4dc1249dbe7975860e3a098d63f6ec065 Mon Sep 17 00:00:00 2001 From: JohnHe233 Date: Thu, 19 Mar 2026 16:18:33 +0800 Subject: [PATCH 1/2] Fix magic number and C-style cast in sto_wf.cpp --- source/source_pw/module_stodft/sto_wf.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/source_pw/module_stodft/sto_wf.cpp b/source/source_pw/module_stodft/sto_wf.cpp index 2ba8db29086..c4cdccc48c1 100644 --- a/source/source_pw/module_stodft/sto_wf.cpp +++ b/source/source_pw/module_stodft/sto_wf.cpp @@ -64,13 +64,14 @@ void Stochastic_WF::clean_chiallorder() template void Stochastic_WF::init_sto_orbitals(const int seed_in) { + const unsigned int RANK_SEED_MULTIPLIER = 10000; if (seed_in == 0 || seed_in == -1) { - srand((unsigned)time(nullptr) + GlobalV::MY_RANK * 10000); // GlobalV global variables are reserved + srand(static_cast(time(nullptr)) + GlobalV::MY_RANK * RANK_SEED_MULTIPLIER); // GlobalV global variables are reserved } else { - srand((unsigned)std::abs(seed_in) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * 10000); + srand(static_cast(std::abs(seed_in)) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * RANK_SEED_MULTIPLIER); } this->allocate_chi0(); From 9058261091b0bce3901c7d588b81fb2d6d4eb9d9 Mon Sep 17 00:00:00 2001 From: JohnHe233 Date: Thu, 19 Mar 2026 16:39:42 +0800 Subject: [PATCH 2/2] Fix C-style cast in source/source_cell/module_symmetry/symmetry_basic.cpp --- .../module_symmetry/symmetry_basic.cpp | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/source/source_cell/module_symmetry/symmetry_basic.cpp b/source/source_cell/module_symmetry/symmetry_basic.cpp index d09a0cada7a..1c4e3e84855 100644 --- a/source/source_cell/module_symmetry/symmetry_basic.cpp +++ b/source/source_cell/module_symmetry/symmetry_basic.cpp @@ -110,17 +110,17 @@ void Symmetry_Basic::order_atoms(double* pos, const int& nat, const int* index) return; } -// convert a set of vectors (va) represented in the basis vectors old1, old2, old3 +// convert a set of vectors (va) represented in the basis vectors old1, old2, old3 // to a set of vectors (vb) represented in the basis vectors new1, new2, new3 void Symmetry_Basic::veccon( - double *carpos, - double *rotpos, - const int num, - const ModuleBase::Vector3 &old1, - const ModuleBase::Vector3 &old2, - const ModuleBase::Vector3 &old3, - const ModuleBase::Vector3 &new1, - const ModuleBase::Vector3 &new2, + double *carpos, + double *rotpos, + const int num, + const ModuleBase::Vector3 &old1, + const ModuleBase::Vector3 &old2, + const ModuleBase::Vector3 &old3, + const ModuleBase::Vector3 &new1, + const ModuleBase::Vector3 &new2, const ModuleBase::Vector3 &new3 ) { @@ -156,14 +156,14 @@ void Symmetry_Basic::veccon( newlat.e33 = new3.z; ModuleBase::Matrix3 GT = newlat.Inverse(); - + ModuleBase::Vector3 car; ModuleBase::Vector3 direct_old; ModuleBase::Vector3 direct_new; //calculate the reciprocal vectors rb1, rb2, rb3 for the vectors new1, new2, new3 //this->recip(1.0, new1, new2, new3, rb1, rb2, rb3); - + for(int i = 0; i < num; ++i) { direct_old.x = carpos[i * 3 + 0]; @@ -222,8 +222,8 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul } // otherwise - // determine the order of the operation: by which power will the operation return - // to the identity operation. + // determine the order of the operation: by which power will the operation return + // to the identity operation. temp1 = sig; for (int j = 1; j < 100; ++j) { @@ -236,7 +236,7 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul } now = nop; for (int j = 0; j < nop; ++j) - { + { temp1 = symop[j]; for (int k = 1; k < order; ++k) { @@ -282,10 +282,10 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul for (int k = nop; k < n; ++k) { for (int m = m1; m < m2; ++m) - { + { temp1 = symop[k] * symop[m]; flag = 1; - for (int l = 0; l < now; ++l) + for (int l = 0; l < now; ++l) { if (symop[l] == temp1) { @@ -293,7 +293,7 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul break; } } - if (flag == 0) + if (flag == 0) { continue; //the new-found element has already existed } @@ -320,9 +320,9 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul } //-------------------------------------------------------------- -// set up all possible space group operators +// set up all possible space group operators // (integer rotation matrices and nontrivial translations -// given in crystal coordinates) +// given in crystal coordinates) // of a lattice with some arbitrary basis (atomic arrangement). //-------------------------------------------------------------- void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &ibrav) const @@ -421,7 +421,7 @@ void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &i this->matrigen(symgen, 1, symop, nop); break; default: - ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup", + ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup", "ibrav = " + std::to_string(ibrav) + " is not supported."); break; } @@ -439,11 +439,11 @@ void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &i << " ======================================================================\n" << " MATRIX REPRESENTATION OF SYMMETRY OPERATION\n" << " ======================================================================\n" - << " There are " << nop << " symmetry operation representation matrices.\n" - << " For each matrix, the elements are arranged like: \n" - << " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n" + << " There are " << nop << " symmetry operation representation matrices.\n" + << " For each matrix, the elements are arranged like: \n" + << " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n" << std::endl; - + // control the digits const int precision = PARAM.inp.cal_symm_repr[1]; const int width = precision + 4; @@ -466,7 +466,7 @@ void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &i return; } -int Symmetry_Basic::subgroup(const int& nrot, const int& ninv, +int Symmetry_Basic::subgroup(const int& nrot, const int& ninv, const int& nc2, const int& nc3, const int& nc4, const int& nc6, const int& ns1, const int& ns3, const int& ns4, const int& ns6)const { @@ -546,7 +546,7 @@ int Symmetry_Basic::subgroup(const int& nrot, const int& ninv, } -bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, +bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, std::string& pgname, const ModuleBase::Matrix3* gmatrix, std::ofstream& ofs_running)const { //------------------------------------------------------------------------- @@ -568,9 +568,9 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, ModuleBase::TITLE("Symmetry_Basic", "pointgroup"); } - std::vector pgdict = { "none", "C_1", "S_2", "C_2", "C_1h", "C_2h", - "D_2", "C_2v", "D_2h", "C_3", "S_6", "D_3", "C_3v", "D_3d", "C_4", "S_4", "C_4h", - "D_4", "C_4v", "D_2d", "D_4h", "C_6", "C_3h", "C_6h", "D_6", "C_6v", "D_3h", "D_6h", + std::vector pgdict = { "none", "C_1", "S_2", "C_2", "C_1h", "C_2h", + "D_2", "C_2v", "D_2h", "C_3", "S_6", "D_3", "C_3v", "D_3d", "C_4", "S_4", "C_4h", + "D_4", "C_4v", "D_2d", "D_4h", "C_6", "C_3h", "C_6h", "D_6", "C_6v", "D_3h", "D_6h", "T", "T_h", "O", "T_d", "O_h" }; if(nrot == 1) @@ -597,7 +597,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, pgname="O_h"; return true; } - + //------------------------------------------------------------------------------- //all other groups need further investigations and detailed analysis //first determine the type of elements and count them @@ -663,7 +663,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S4", ns4); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S6", ns6); } - + if(nrot == 2) { if(ninv == 1) @@ -699,7 +699,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, pgname="D_2"; return true; } - if(ns1 == 2) + if(ns1 == 2) { pgnumber = 7; pgname="C_2v"; @@ -858,9 +858,9 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber, } -void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 >rans, +void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3 >rans, int i, int j, int k, // FFT grid index. - const int nr1, const int nr2, const int nr3, // dimension of FFT grid. + const int nr1, const int nr2, const int nr3, // dimension of FFT grid. int &ri, int &rj, int &rk) { static ModuleBase::Matrix3 g; @@ -880,13 +880,13 @@ void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3(g.e12 * i + g.e22 * j + g.e32 * k) + static_cast(gtrans.y * nr2); if (rj < 0) { rj += 10 * nr2; } rj = rj%nr2; - rk = int(g.e13 * i + g.e23 * j + g.e33 * k) + (int)(gtrans.z * nr3); + rk = static_cast(g.e13 * i + g.e23 * j + g.e33 * k) + static_cast(gtrans.z * nr3); if (rk < 0) { rk += 10 * nr3; @@ -895,12 +895,12 @@ void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3