Skip to content

Commit

Permalink
Fixes for the clang-tidy check bugprone-implicit-widening-of-multipli…
Browse files Browse the repository at this point in the history
…cation-result (#55)

* bugprone-implicit-widening-of-multiplication-result fixes for CartGrid.C, MeshBlock.h and MeshBlock.C

* bugprone-implicit-widening-of-multiplication-result fixes for bookKeeping.C and exchangeAMRDonors.C

* bugprone-implicit-widening-of-multiplication-result fixes for exchangeBoxes.C

* bugprone-implicit-widening-of-multiplication-result fixes for exchangeDonors.C

* bugprone-implicit-widening-of-multiplication-result fixes for getCartReceptors.C

* bugprone-implicit-widening-of-multiplication-result fixes for highOrder.C

* bugprone-implicit-widening-of-multiplication-result fixes for holeMap.C

* bugprone-implicit-widening-of-multiplication-result fixes for parallelComm.C

* bugprone-implicit-widening-of-multiplication-result fixes for search.C

* bugprone-implicit-widening-of-multiplication-result fixes for searchADTrecursion.C and tioga.C
  • Loading branch information
itopcuoglu authored Aug 1, 2024
1 parent 8bd82be commit c7bf97f
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 123 deletions.
10 changes: 6 additions & 4 deletions src/CartGrid.C
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ void CartGrid::search(double* x, int* donorid, int npts)
}
}
}
if (myid == 2 && abs(x[3 * i] - 0.739573) < 1e-5 &&
if (myid == 2 && abs(x[static_cast<int>(3 * i)] - 0.739573) < 1e-5 &&
abs(x[3 * i + 1] + 0.259310) < 1e-5 &&
abs(x[3 * i + 2] + 0.639614) < 1e-5) {
printf(
"%d %d %f %f %f %d\n", myid, i, x[3 * i], x[3 * i + 1],
x[3 * i + 2], donorid[i]);
"%d %d %f %f %f %d\n", myid, i, x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], donorid[i]);
}
if (donorid[i] == -1) {
printf("%d %f %f %f\n", myid, x[3 * i], x[3 * i + 1], x[3 * i + 2]);
printf(
"%d %f %f %f\n", myid, x[static_cast<int>(3 * i)], x[3 * i + 1],
x[3 * i + 2]);
}
}
// printf("CartGrid::search Processor %d located %d of %d
Expand Down
88 changes: 52 additions & 36 deletions src/MeshBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ void MeshBlock::tagBoundaryFaces()
int nodei = wbcnode[i] - BASE;
WBC_unique_map[i] = nodei;

auto node_found = WBC_nodes.insert(Node(nodei, &x[3 * nodei]));
auto node_found =
WBC_nodes.insert(Node(nodei, &x[static_cast<int>(3 * nodei)]));
if (node_found.second == false) {
// duplicates exist
const Node n = *node_found.first;
Expand All @@ -520,7 +521,8 @@ void MeshBlock::tagBoundaryFaces()
flagduplicate = 0;
for (i = 0; i < nobc; i++) {
int nodei = obcnode[i] - BASE;
auto node_found = WBC_nodes.find(Node(nodei, &x[3 * nodei]));
auto node_found =
WBC_nodes.find(Node(nodei, &x[static_cast<int>(3 * nodei)]));

if (node_found != WBC_nodes.end()) {
// duplicates exit
Expand Down Expand Up @@ -620,11 +622,11 @@ void MeshBlock::tagBoundaryFaces()
}

// allocate wall face node list
wbcfacenode.resize(4 * nwbcface);
wbcfacenode.resize(static_cast<int>(4 * nwbcface));
wbcfacebox.resize(nwbcface);

// allocate outer face node list
obcfacenode.resize(4 * nobcface);
obcfacenode.resize(static_cast<int>(4 * nobcface));
obcfacebox.resize(nobcface);

/* ====================== */
Expand Down Expand Up @@ -771,8 +773,8 @@ void MeshBlock::writeGridFile(int bid)
ncells);
for (i = 0; i < nnodes; i++) {
fprintf(
fp, "%.14e %.14e %.14e %d\n", x[3 * i], x[3 * i + 1], x[3 * i + 2],
iblank[i]);
fp, "%.14e %.14e %.14e %d\n", x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], iblank[i]);
}

ba = 1 - BASE;
Expand All @@ -781,28 +783,32 @@ void MeshBlock::writeGridFile(int bid)
for (i = 0; i < nc[n]; i++) {
if (nvert == 4) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba);
} else if (nvert == 5) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba);
} else if (nvert == 6) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 5] + ba,
vconn[n][nvert * i + 5] + ba);
} else if (nvert == 8) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 5] + ba, vconn[n][nvert * i + 6] + ba,
Expand Down Expand Up @@ -838,7 +844,7 @@ void MeshBlock::writeCellFile(int bid)
fp,
"VARLOCATION = (1=NODAL, 2=NODAL, 3=NODAL, 4=NODAL,5=CELLCENTERED)\n");
for (i = 0; i < nnodes; i++) {
fprintf(fp, "%lf\n", x[3 * i]);
fprintf(fp, "%lf\n", x[static_cast<int>(3 * i)]);
}
for (i = 0; i < nnodes; i++) {
fprintf(fp, "%lf\n", x[3 * i + 1]);
Expand All @@ -858,28 +864,32 @@ void MeshBlock::writeCellFile(int bid)
for (i = 0; i < nc[n]; i++) {
if (nvert == 4) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba);
} else if (nvert == 5) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba);
} else if (nvert == 6) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 5] + ba,
vconn[n][nvert * i + 5] + ba);
} else if (nvert == 8) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 5] + ba, vconn[n][nvert * i + 6] + ba,
Expand Down Expand Up @@ -929,8 +939,8 @@ void MeshBlock::writeFlowFile(int bid, double* q, int nvar, int type)
if (type == 0) {
for (i = 0; i < nnodes; i++) {
fprintf(
fp, "%lf %lf %lf %d %d ", x[3 * i], x[3 * i + 1], x[3 * i + 2],
ibl[i], meshtag);
fp, "%lf %lf %lf %d %d ", x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], ibl[i], meshtag);
for (j = 0; j < nvar; j++) {
fprintf(fp, "%lf ", q[i * nvar + j]);
}
Expand All @@ -941,8 +951,8 @@ void MeshBlock::writeFlowFile(int bid, double* q, int nvar, int type)
} else {
for (i = 0; i < nnodes; i++) {
fprintf(
fp, "%lf %lf %lf %d %d ", x[3 * i], x[3 * i + 1], x[3 * i + 2],
ibl[i], meshtag);
fp, "%lf %lf %lf %d %d ", x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], ibl[i], meshtag);
for (j = 0; j < nvar; j++) {
fprintf(fp, "%lf ", q[j * nnodes + i]);
}
Expand All @@ -955,28 +965,32 @@ void MeshBlock::writeFlowFile(int bid, double* q, int nvar, int type)
for (i = 0; i < nc[n]; i++) {
if (nvert == 4) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 3] + ba);
} else if (nvert == 5) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 4] + ba);
} else if (nvert == 6) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 2] + ba, vconn[n][nvert * i + 3] + ba,
vconn[n][nvert * i + 4] + ba, vconn[n][nvert * i + 5] + ba,
vconn[n][nvert * i + 5] + ba);
} else if (nvert == 8) {
fprintf(
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][nvert * i] + ba,
fp, "%d %d %d %d %d %d %d %d\n",
vconn[n][static_cast<int>(nvert * i)] + ba,
vconn[n][nvert * i + 1] + ba, vconn[n][nvert * i + 2] + ba,
vconn[n][nvert * i + 3] + ba, vconn[n][nvert * i + 4] + ba,
vconn[n][nvert * i + 5] + ba, vconn[n][nvert * i + 6] + ba,
Expand Down Expand Up @@ -1351,13 +1365,14 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
/* possible overlap: use face intersection test */

// load face boundary nodes: set pointer to nodes
inode = &bcfacenode[4 * i]; // last node may be -1
inode =
&bcfacenode[static_cast<int>(4 * i)]; // last node may be -1

// get node indices and coordinates for this boundary face
// load 1st three nodes
double* pt1 = &x[3 * inode[0]];
double* pt2 = &x[3 * inode[1]];
double* pt3 = &x[3 * inode[2]];
double* pt1 = &x[static_cast<int>(3 * inode[0])];
double* pt2 = &x[static_cast<int>(3 * inode[1])];
double* pt3 = &x[static_cast<int>(3 * inode[2])];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1368,7 +1383,7 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
// if quad, test second triangle using last node
nvert = (inode[3] == -1) ? 3 : 4; // number of face vertices
if (nvert == 4) {
double* pt4 = &x[3 * inode[3]];
double* pt4 = &x[static_cast<int>(3 * inode[3])];
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt4) != 0) {
tagList[j] = 1;
break; // jump to next octant (break from inner BC loop)
Expand Down Expand Up @@ -1469,13 +1484,14 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
/* possible overlap: use face intersection test */

// load face boundary nodes: set pointer to nodes
inode = &bcfacenode[4 * i]; // last node may be -1
inode =
&bcfacenode[static_cast<int>(4 * i)]; // last node may be -1

// get node indices and coordinates for this boundary face
// load 1st three nodes
double* pt1 = &x[3 * inode[0]];
double* pt2 = &x[3 * inode[1]];
double* pt3 = &x[3 * inode[2]];
double* pt1 = &x[static_cast<int>(3 * inode[0])];
double* pt2 = &x[static_cast<int>(3 * inode[1])];
double* pt3 = &x[static_cast<int>(3 * inode[2])];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1486,7 +1502,7 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
// if quad, test second triangle using last node
nvert = (inode[3] == -1) ? 3 : 4; // number of face vertices
if (nvert == 4) {
double* pt4 = &x[3 * inode[3]];
double* pt4 = &x[static_cast<int>(3 * inode[3])];
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt4) != 0) {
tagList[j] = 1;
break; // jump to next octant (break from inner BC loop)
Expand Down Expand Up @@ -2214,7 +2230,7 @@ void MeshBlock::create_hex_cell_map()
double xd[3];
int idx[3];
for (int j = 0; j < 3; j++) {
int const lnode = vconn[0][8 * i] - BASE;
int const lnode = vconn[0][static_cast<int>(8 * i)] - BASE;
int const tnode = vconn[0][8 * i + 6] - BASE;
xc[j] = 0.5 * (x[3 * lnode + j] + x[3 * tnode + j]);
}
Expand Down Expand Up @@ -2260,8 +2276,8 @@ void MeshBlock::checkOrphans()
if (nodeRes[i] >= BIGVALUE) {
if (iblank[i] == 1) {
fprintf(
fp, "%f %f %f %f\n", x[3 * i], x[3 * i + 1],
x[3 * i + 2], nodeRes[i]);
fp, "%f %f %f %f\n", x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], nodeRes[i]);
norphan++;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/MeshBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ class MeshBlock
void outputOrphan(FILE* fp, int i)
{
fprintf(
fp, "%f %f %f\n", rxyz[3 * i], rxyz[3 * i + 1], rxyz[3 * i + 2]);
fp, "%f %f %f\n", rxyz[static_cast<int>(3 * i)], rxyz[3 * i + 1],
rxyz[3 * i + 2]);
}
void clearOrphans(HOLEMAP* holemap, int nmesh, const int* itmp);
void clearOrphans(ADAPTIVE_HOLEMAP* holemap, int nmesh, int* itmp);
Expand Down
Loading

0 comments on commit c7bf97f

Please sign in to comment.