Skip to content

Commit db8a9dd

Browse files
authored
2026PKUCourseHW5: Fix C-style cast in source/source_cell/module_symmetry/symmetry_basic.cpp (#7064)
* Fix magic number and C-style cast in sto_wf.cpp * Fix C-style cast in source/source_cell/module_symmetry/symmetry_basic.cpp
1 parent 7d641c1 commit db8a9dd

1 file changed

Lines changed: 42 additions & 42 deletions

File tree

source/source_cell/module_symmetry/symmetry_basic.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ void Symmetry_Basic::order_atoms(double* pos, const int& nat, const int* index)
110110
return;
111111
}
112112

113-
// convert a set of vectors (va) represented in the basis vectors old1, old2, old3
113+
// convert a set of vectors (va) represented in the basis vectors old1, old2, old3
114114
// to a set of vectors (vb) represented in the basis vectors new1, new2, new3
115115
void Symmetry_Basic::veccon(
116-
double *carpos,
117-
double *rotpos,
118-
const int num,
119-
const ModuleBase::Vector3<double> &old1,
120-
const ModuleBase::Vector3<double> &old2,
121-
const ModuleBase::Vector3<double> &old3,
122-
const ModuleBase::Vector3<double> &new1,
123-
const ModuleBase::Vector3<double> &new2,
116+
double *carpos,
117+
double *rotpos,
118+
const int num,
119+
const ModuleBase::Vector3<double> &old1,
120+
const ModuleBase::Vector3<double> &old2,
121+
const ModuleBase::Vector3<double> &old3,
122+
const ModuleBase::Vector3<double> &new1,
123+
const ModuleBase::Vector3<double> &new2,
124124
const ModuleBase::Vector3<double> &new3
125125
)
126126
{
@@ -156,14 +156,14 @@ void Symmetry_Basic::veccon(
156156
newlat.e33 = new3.z;
157157

158158
ModuleBase::Matrix3 GT = newlat.Inverse();
159-
159+
160160
ModuleBase::Vector3<double> car;
161161
ModuleBase::Vector3<double> direct_old;
162162
ModuleBase::Vector3<double> direct_new;
163163

164164
//calculate the reciprocal vectors rb1, rb2, rb3 for the vectors new1, new2, new3
165165
//this->recip(1.0, new1, new2, new3, rb1, rb2, rb3);
166-
166+
167167
for(int i = 0; i < num; ++i)
168168
{
169169
direct_old.x = carpos[i * 3 + 0];
@@ -222,8 +222,8 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul
222222
}
223223
// otherwise
224224

225-
// determine the order of the operation: by which power will the operation return
226-
// to the identity operation.
225+
// determine the order of the operation: by which power will the operation return
226+
// to the identity operation.
227227
temp1 = sig;
228228
for (int j = 1; j < 100; ++j)
229229
{
@@ -236,7 +236,7 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul
236236
}
237237
now = nop;
238238
for (int j = 0; j < nop; ++j)
239-
{
239+
{
240240
temp1 = symop[j];
241241
for (int k = 1; k < order; ++k)
242242
{
@@ -282,18 +282,18 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul
282282
for (int k = nop; k < n; ++k)
283283
{
284284
for (int m = m1; m < m2; ++m)
285-
{
285+
{
286286
temp1 = symop[k] * symop[m];
287287
flag = 1;
288-
for (int l = 0; l < now; ++l)
288+
for (int l = 0; l < now; ++l)
289289
{
290290
if (symop[l] == temp1)
291291
{
292292
flag = 0;
293293
break;
294294
}
295295
}
296-
if (flag == 0)
296+
if (flag == 0)
297297
{
298298
continue; //the new-found element has already existed
299299
}
@@ -320,9 +320,9 @@ void Symmetry_Basic::matrigen(ModuleBase::Matrix3 *symgen, const int ngen, Modul
320320
}
321321

322322
//--------------------------------------------------------------
323-
// set up all possible space group operators
323+
// set up all possible space group operators
324324
// (integer rotation matrices and nontrivial translations
325-
// given in crystal coordinates)
325+
// given in crystal coordinates)
326326
// of a lattice with some arbitrary basis (atomic arrangement).
327327
//--------------------------------------------------------------
328328
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
421421
this->matrigen(symgen, 1, symop, nop);
422422
break;
423423
default:
424-
ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup",
424+
ModuleBase::WARNING_QUIT("Symmetry_Basic::setgroup",
425425
"ibrav = " + std::to_string(ibrav) + " is not supported.");
426426
break;
427427
}
@@ -439,11 +439,11 @@ void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &i
439439
<< " ======================================================================\n"
440440
<< " MATRIX REPRESENTATION OF SYMMETRY OPERATION\n"
441441
<< " ======================================================================\n"
442-
<< " There are " << nop << " symmetry operation representation matrices.\n"
443-
<< " For each matrix, the elements are arranged like: \n"
444-
<< " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n"
442+
<< " There are " << nop << " symmetry operation representation matrices.\n"
443+
<< " For each matrix, the elements are arranged like: \n"
444+
<< " [[e11, e12, e13], [e21, e22, e23], [e31, e32, e33]].reshape(3, 3)\n"
445445
<< std::endl;
446-
446+
447447
// control the digits
448448
const int precision = PARAM.inp.cal_symm_repr[1];
449449
const int width = precision + 4;
@@ -466,7 +466,7 @@ void Symmetry_Basic::setgroup(ModuleBase::Matrix3* symop, int &nop, const int &i
466466
return;
467467
}
468468

469-
int Symmetry_Basic::subgroup(const int& nrot, const int& ninv,
469+
int Symmetry_Basic::subgroup(const int& nrot, const int& ninv,
470470
const int& nc2, const int& nc3, const int& nc4, const int& nc6,
471471
const int& ns1, const int& ns3, const int& ns4, const int& ns6)const
472472
{
@@ -546,7 +546,7 @@ int Symmetry_Basic::subgroup(const int& nrot, const int& ninv,
546546
}
547547

548548

549-
bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
549+
bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
550550
std::string& pgname, const ModuleBase::Matrix3* gmatrix, std::ofstream& ofs_running)const
551551
{
552552
//-------------------------------------------------------------------------
@@ -568,9 +568,9 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
568568
ModuleBase::TITLE("Symmetry_Basic", "pointgroup");
569569
}
570570

571-
std::vector<std::string> pgdict = { "none", "C_1", "S_2", "C_2", "C_1h", "C_2h",
572-
"D_2", "C_2v", "D_2h", "C_3", "S_6", "D_3", "C_3v", "D_3d", "C_4", "S_4", "C_4h",
573-
"D_4", "C_4v", "D_2d", "D_4h", "C_6", "C_3h", "C_6h", "D_6", "C_6v", "D_3h", "D_6h",
571+
std::vector<std::string> pgdict = { "none", "C_1", "S_2", "C_2", "C_1h", "C_2h",
572+
"D_2", "C_2v", "D_2h", "C_3", "S_6", "D_3", "C_3v", "D_3d", "C_4", "S_4", "C_4h",
573+
"D_4", "C_4v", "D_2d", "D_4h", "C_6", "C_3h", "C_6h", "D_6", "C_6v", "D_3h", "D_6h",
574574
"T", "T_h", "O", "T_d", "O_h" };
575575

576576
if(nrot == 1)
@@ -597,7 +597,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
597597
pgname="O_h";
598598
return true;
599599
}
600-
600+
601601
//-------------------------------------------------------------------------------
602602
//all other groups need further investigations and detailed analysis
603603
//first determine the type of elements and count them
@@ -663,7 +663,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
663663
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S4", ns4);
664664
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "S6", ns6);
665665
}
666-
666+
667667
if(nrot == 2)
668668
{
669669
if(ninv == 1)
@@ -699,7 +699,7 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
699699
pgname="D_2";
700700
return true;
701701
}
702-
if(ns1 == 2)
702+
if(ns1 == 2)
703703
{
704704
pgnumber = 7;
705705
pgname="C_2v";
@@ -858,9 +858,9 @@ bool Symmetry_Basic::pointgroup(const int& nrot, int& pgnumber,
858858
}
859859

860860

861-
void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3<double> &gtrans,
861+
void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3<double> &gtrans,
862862
int i, int j, int k, // FFT grid index.
863-
const int nr1, const int nr2, const int nr3, // dimension of FFT grid.
863+
const int nr1, const int nr2, const int nr3, // dimension of FFT grid.
864864
int &ri, int &rj, int &rk)
865865
{
866866
static ModuleBase::Matrix3 g;
@@ -880,13 +880,13 @@ void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3<d
880880
ri += 10 * nr1;
881881
}
882882
ri = ri%nr1;
883-
rj = int(g.e12 * i + g.e22 * j + g.e32 * k) + (int)(gtrans.y * nr2);
883+
rj = static_cast<int>(g.e12 * i + g.e22 * j + g.e32 * k) + static_cast<int>(gtrans.y * nr2);
884884
if (rj < 0)
885885
{
886886
rj += 10 * nr2;
887887
}
888888
rj = rj%nr2;
889-
rk = int(g.e13 * i + g.e23 * j + g.e33 * k) + (int)(gtrans.z * nr3);
889+
rk = static_cast<int>(g.e13 * i + g.e23 * j + g.e33 * k) + static_cast<int>(gtrans.z * nr3);
890890
if (rk < 0)
891891
{
892892
rk += 10 * nr3;
@@ -895,12 +895,12 @@ void Symmetry_Basic::rotate( ModuleBase::Matrix3 &gmatrix, ModuleBase::Vector3<d
895895
return;
896896
}
897897

898-
// atom ordering for each atom type
898+
// atom ordering for each atom type
899899
// by a "weighted function" f
900900
// (instead of ordering by x, y, z directly)
901901
void Symmetry_Basic::atom_ordering_new(double *posi, const int natom, int *subindex) const
902902
{
903-
//order the atomic positions inside a supercell by a unique ordering scheme
903+
//order the atomic positions inside a supercell by a unique ordering scheme
904904
subindex[0] = 0;
905905

906906
if(natom == 1)
@@ -926,7 +926,7 @@ void Symmetry_Basic::atom_ordering_new(double *posi, const int natom, int *subin
926926
double z_min = *min_element(tmpz.begin(),tmpz.end());
927927

928928
double* weighted_func = new double[natom];
929-
929+
930930
//the first time: f(x, y, z)
931931
for(int i=0; i<natom; i++)
932932
{
@@ -941,11 +941,11 @@ void Symmetry_Basic::atom_ordering_new(double *posi, const int natom, int *subin
941941
tmpz[i] = posi[i*3+2];
942942
}
943943

944-
//the second time: f(y, z) for fixed x
944+
//the second time: f(y, z) for fixed x
945945
for(int i=0; i<natom-1;)
946946
{
947947
int ix_right=i+1; //right bound is no included
948-
while(ix_right<natom && equal(tmpx[ix_right],tmpx[i]))
948+
while(ix_right<natom && equal(tmpx[ix_right],tmpx[i]))
949949
{
950950
++ix_right;
951951
}
@@ -963,7 +963,7 @@ void Symmetry_Basic::atom_ordering_new(double *posi, const int natom, int *subin
963963
}
964964
i=ix_right;
965965
}
966-
966+
967967
delete[] weighted_func;
968968
return;
969969
}

0 commit comments

Comments
 (0)