From c7bf97f00a42833ddf0344bb7930c1153dd50080 Mon Sep 17 00:00:00 2001 From: Ilker Topcuoglu <114435459+itopcuoglu@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:49:10 -0600 Subject: [PATCH] Fixes for the clang-tidy check bugprone-implicit-widening-of-multiplication-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 --- src/CartGrid.C | 10 +++-- src/MeshBlock.C | 88 ++++++++++++++++++++++++---------------- src/MeshBlock.h | 3 +- src/bookKeeping.C | 37 +++++++++-------- src/exchangeAMRDonors.C | 13 +++--- src/exchangeBoxes.C | 7 ++-- src/exchangeDonors.C | 12 +++--- src/getCartReceptors.C | 27 +++++++----- src/highOrder.C | 16 +++++--- src/holeMap.C | 13 +++--- src/parallelComm.C | 24 +++++------ src/search.C | 2 +- src/searchADTrecursion.C | 9 ++-- src/tioga.C | 22 +++++----- 14 files changed, 160 insertions(+), 123 deletions(-) diff --git a/src/CartGrid.C b/src/CartGrid.C index 192dc32..0d62f0f 100644 --- a/src/CartGrid.C +++ b/src/CartGrid.C @@ -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(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(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(3 * i)], x[3 * i + 1], + x[3 * i + 2]); } } // printf("CartGrid::search Processor %d located %d of %d diff --git a/src/MeshBlock.C b/src/MeshBlock.C index 9cf2b5e..81c660d 100644 --- a/src/MeshBlock.C +++ b/src/MeshBlock.C @@ -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(3 * nodei)])); if (node_found.second == false) { // duplicates exist const Node n = *node_found.first; @@ -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(3 * nodei)])); if (node_found != WBC_nodes.end()) { // duplicates exit @@ -620,11 +622,11 @@ void MeshBlock::tagBoundaryFaces() } // allocate wall face node list - wbcfacenode.resize(4 * nwbcface); + wbcfacenode.resize(static_cast(4 * nwbcface)); wbcfacebox.resize(nwbcface); // allocate outer face node list - obcfacenode.resize(4 * nobcface); + obcfacenode.resize(static_cast(4 * nobcface)); obcfacebox.resize(nobcface); /* ====================== */ @@ -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(3 * i)], + x[3 * i + 1], x[3 * i + 2], iblank[i]); } ba = 1 - BASE; @@ -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(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(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(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(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, @@ -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(3 * i)]); } for (i = 0; i < nnodes; i++) { fprintf(fp, "%lf\n", x[3 * i + 1]); @@ -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(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(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(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(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, @@ -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(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]); } @@ -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(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]); } @@ -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(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(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(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(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, @@ -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(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(3 * inode[0])]; + double* pt2 = &x[static_cast(3 * inode[1])]; + double* pt3 = &x[static_cast(3 * inode[2])]; // test triangle 1: pass first 3 triangles if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) { @@ -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(3 * inode[3])]; if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt4) != 0) { tagList[j] = 1; break; // jump to next octant (break from inner BC loop) @@ -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(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(3 * inode[0])]; + double* pt2 = &x[static_cast(3 * inode[1])]; + double* pt3 = &x[static_cast(3 * inode[2])]; // test triangle 1: pass first 3 triangles if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) { @@ -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(3 * inode[3])]; if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt4) != 0) { tagList[j] = 1; break; // jump to next octant (break from inner BC loop) @@ -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(8 * i)] - BASE; int const tnode = vconn[0][8 * i + 6] - BASE; xc[j] = 0.5 * (x[3 * lnode + j] + x[3 * tnode + j]); } @@ -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(3 * i)], + x[3 * i + 1], x[3 * i + 2], nodeRes[i]); norphan++; } } diff --git a/src/MeshBlock.h b/src/MeshBlock.h index 5e6adec..9ce82b6 100644 --- a/src/MeshBlock.h +++ b/src/MeshBlock.h @@ -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(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); diff --git a/src/bookKeeping.C b/src/bookKeeping.C index cf6ad44..0dbff55 100644 --- a/src/bookKeeping.C +++ b/src/bookKeeping.C @@ -42,7 +42,7 @@ void MeshBlock::getDonorPacket(PACKET* sndPack, int nsend) const // for (i = 0; i < nsearch; i++) { if (donorId[i] > -1) { - k = isearch[2 * i]; + k = isearch[static_cast(2 * i)]; sndPack[k].nints += 3; sndPack[k].nreals++; } @@ -59,7 +59,7 @@ void MeshBlock::getDonorPacket(PACKET* sndPack, int nsend) const // for (i = 0; i < nsearch; i++) { if (donorId[i] > -1) { - k = isearch[2 * i]; + k = isearch[static_cast(2 * i)]; sndPack[k].intData[icount[k]++] = meshtag; // mesh tag sndPack[k].intData[icount[k]++] = isearch[2 * i + 1]; // point id sndPack[k].intData[icount[k]++] = i; // point id on the donor side @@ -76,7 +76,7 @@ void MeshBlock::getMBDonorPktSizes( { for (int i = 0; i < nsearch; i++) { if (donorId[i] > -1) { - int const ii = isearch[3 * i]; + int const ii = isearch[static_cast(3 * i)]; nints[ii] += 4; nreals[ii] += 2; } @@ -93,7 +93,7 @@ void MeshBlock::getMBDonorPackets( continue; } - int const k = isearch[3 * i]; + int const k = isearch[static_cast(3 * i)]; int& ix = ixOffset[k]; int& rx = rxOffset[k]; @@ -180,7 +180,9 @@ void MeshBlock::processDonors( if (verbose != 0) TRACEI(iblank[i]); if (verbose != 0) TRACED(nodeRes[i]); if (verbose != 0) { - printf("%f %f %f\n", x[3 * i], x[3 * i + 1], x[3 * i + 2]); + printf( + "%f %f %f\n", x[static_cast(3 * i)], x[3 * i + 1], + x[3 * i + 2]); } if (donorList[i] == nullptr) { if (verbose != 0) { @@ -189,8 +191,8 @@ void MeshBlock::processDonors( for (j = 0; j < nmesh; j++) { if (j != (meshtag - BASE) && (holemap[j].existWall != 0)) { if (checkHoleMap( - &x[3 * i], holemap[j].nx, holemap[j].sam, - holemap[j].extents) != 0) { + &x[static_cast(3 * i)], holemap[j].nx, + holemap[j].sam, holemap[j].extents) != 0) { iblank[i] = 0; break; } @@ -218,8 +220,8 @@ void MeshBlock::processDonors( if (j != (meshtag - BASE) && (holemap[j].existWall != 0)) { if (iflag[j] == 0) { if (checkHoleMap( - &x[3 * i], holemap[j].nx, holemap[j].sam, - holemap[j].extents) != 0) { + &x[static_cast(3 * i)], holemap[j].nx, + holemap[j].sam, holemap[j].extents) != 0) { iblank[i] = 0; break; } @@ -241,7 +243,8 @@ void MeshBlock::processDonors( myid, wbcnode[i] - BASE, donorList[wbcnode[i] - BASE]); ii = wbcnode[i] - BASE; printf( - "xloc=%e %e %e\n", x[3 * ii], x[3 * ii + 1], x[3 * ii + 2]); + "xloc=%e %e %e\n", x[static_cast(3 * ii)], + x[3 * ii + 1], x[3 * ii + 2]); printf( "Computations will continue, but may suffer from accuracy " "problems\n"); @@ -405,8 +408,8 @@ void MeshBlock::processDonors( for (j = 0; j < nmesh; j++) { if (j != (meshtag - BASE) && (holemap[j].existWall != 0U)) { - int const SB_val = - checkAdaptiveHoleMap(&x[3 * i], &holemap[j]); + int const SB_val = checkAdaptiveHoleMap( + &x[static_cast(3 * i)], &holemap[j]); if (SB_val != OUTSIDE_SB) { iblank[i] = 0; break; @@ -443,8 +446,8 @@ void MeshBlock::processDonors( if (iflag[j] == 0) { // body{j} does NOT have candidate so check if point is // INSIDE SB - int const SB_val = - checkAdaptiveHoleMap(&x[3 * i], &holemap[j]); + int const SB_val = checkAdaptiveHoleMap( + &x[static_cast(3 * i)], &holemap[j]); if (SB_val != OUTSIDE_SB) { iblank[i] = 0; break; @@ -469,8 +472,8 @@ void MeshBlock::processDonors( myid, wbcnode[i] - BASE, donorList[wbcnode[i] - BASE]); ii = wbcnode[i] - BASE; fprintf( - stderr, "xloc=%e %e %e\n", x[3 * ii], x[3 * ii + 1], - x[3 * ii + 2]); + stderr, "xloc=%e %e %e\n", x[static_cast(3 * ii)], + x[3 * ii + 1], x[3 * ii + 2]); fprintf( stderr, "Computations will continue, but may suffer from accuracy " @@ -650,7 +653,7 @@ void MeshBlock::findInterpData(int* recid, int irecord, double receptorRes2) // if (myid==63 && irecord==3224) verbose=1; // if (myid==1 && irecord==158192 && meshtag==1) verbose=1; receptorRes = fabs(receptorRes2); - procid = isearch[3 * irecord]; + procid = isearch[static_cast(3 * irecord)]; pointid = isearch[3 * irecord + 1]; blockid = isearch[3 * irecord + 2]; meshtagrecv = tagsearch[irecord]; diff --git a/src/exchangeAMRDonors.C b/src/exchangeAMRDonors.C index 3c130d1..48aa4ad 100644 --- a/src/exchangeAMRDonors.C +++ b/src/exchangeAMRDonors.C @@ -92,9 +92,10 @@ void tioga::exchangeAMRDonors() } for (i = 0; i < mb->nsearch; i++) { if (mb->donorId[i] != -1) { - assert(( - mb->isearch[3 * i] < nsend && mb->isearch[3 * i] >= 0)); - obreceptors[imap[mb->isearch[3 * i]]]++; + assert( + (mb->isearch[static_cast(3 * i)] < nsend && + mb->isearch[static_cast(3 * i)] >= 0)); + obreceptors[imap[mb->isearch[static_cast(3 * i)]]]++; } } } @@ -133,7 +134,7 @@ void tioga::exchangeAMRDonors() mb->receptorIdCart[i]; sndPack[procid].intData[intcount[procid]++] = ib; sndPack[procid].realData[realcount[procid]++] = - mb->rxyzCart[3 * i]; + mb->rxyzCart[static_cast(3 * i)]; sndPack[procid].realData[realcount[procid]++] = mb->rxyzCart[3 * i + 1]; sndPack[procid].realData[realcount[procid]++] = @@ -145,7 +146,7 @@ void tioga::exchangeAMRDonors() auto& mb = mblocks[ib]; for (i = 0; i < mb->nsearch; i++) { if (mb->donorId[i] != -1) { - procid = imap[mb->isearch[3 * i]]; + procid = imap[mb->isearch[static_cast(3 * i)]]; sndPack[procid].intData[intcount[procid]++] = mb->isearch[3 * i + 1]; sndPack[procid].intData[intcount[procid]++] = @@ -256,7 +257,7 @@ void tioga::exchangeAMRDonors() cancelledData = (int*)malloc(sizeof(int) * 4 * ncancel); cb[i].getCancellationData(cancelledData, &ncancel); for (j = 0; j < ncancel; j++) { - procid = cancelledData[4 * j]; + procid = cancelledData[static_cast(4 * j)]; ctype = cancelledData[4 * j + 1]; remoteid = cancelledData[4 * j + 2]; remoteblockid = cancelledData[4 * j + 3]; diff --git a/src/exchangeBoxes.C b/src/exchangeBoxes.C index 475d6ca..2229f0f 100644 --- a/src/exchangeBoxes.C +++ b/src/exchangeBoxes.C @@ -84,8 +84,8 @@ void tioga::exchangeBoxes() displs[i] = displs[i - 1] + nbPerProc[i - 1] * 16; } - std::vector myOBBdata(nblocks * 16); - std::vector allOBBdata(ntotalblks * 16); + std::vector myOBBdata(static_cast(nblocks * 16)); + std::vector allOBBdata(static_cast(ntotalblks * 16)); int m = 0; for (int ib = 0; ib < nblocks; ib++) { @@ -249,7 +249,8 @@ void tioga::exchangeBoxes() obblist[i].send_tag = key_send; obblist[i].recv_tag = key_recv; - sndPack[k].intData[3 * ioff] = key_send; // mb->getMeshTag(); + sndPack[k].intData[static_cast(3 * ioff)] = + key_send; // mb->getMeshTag(); sndPack[k].intData[3 * ioff + 1] = ib; sndPack[k].intData[3 * ioff + 2] = mb->getMeshTag(); // mb->getReducedOBB2(&obbRecv[ob], &(sndPack[k].realData[roff])); diff --git a/src/exchangeDonors.C b/src/exchangeDonors.C index cc2637e..b7ca20b 100644 --- a/src/exchangeDonors.C +++ b/src/exchangeDonors.C @@ -139,7 +139,7 @@ void tioga::exchangeDonors() for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].nints += 2; sndPack[k].nreals++; } @@ -153,7 +153,7 @@ void tioga::exchangeDonors() for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 1]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 2]; sndPack[k].realData[rxOffset[k]++] = receptorResolution[n][i]; @@ -213,7 +213,7 @@ void tioga::exchangeDonors() for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].nints += 2; } } @@ -223,7 +223,7 @@ void tioga::exchangeDonors() for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 1]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 2]; } @@ -264,7 +264,7 @@ void tioga::exchangeDonors() std::fill(ixOffset.begin(), ixOffset.end(), 0); for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].nints += 2; } } @@ -273,7 +273,7 @@ void tioga::exchangeDonors() } for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 1]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 2]; } diff --git a/src/getCartReceptors.C b/src/getCartReceptors.C index ef4f85b..5daf0b4 100644 --- a/src/getCartReceptors.C +++ b/src/getCartReceptors.C @@ -61,11 +61,13 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc) nsearch = 0; // for (int c = 0; c < cg->ngrids; c++) { - int const cell_count = (cg->dims[3 * c] + 2 * cg->nf) * - (cg->dims[3 * c + 1] + 2 * cg->nf) * - (cg->dims[3 * c + 2] + 2 * cg->nf); + int const cell_count = + (cg->dims[static_cast(3 * c)] + 2 * cg->nf) * + (cg->dims[3 * c + 1] + 2 * cg->nf) * + (cg->dims[3 * c + 2] + 2 * cg->nf); - int const vol = cg->dx[3 * c] * cg->dx[3 * c + 1] * cg->dx[3 * c + 2]; + int const vol = cg->dx[static_cast(3 * c)] * cg->dx[3 * c + 1] * + cg->dx[3 * c + 2]; for (int n = 0; n < 3; n++) { obcart->dxc[n] = cg->dx[3 * c + n] * (cg->dims[3 * c + n]) * 0.5; @@ -83,7 +85,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc) auto* xtm = (double*)malloc(sizeof(double) * 3); - for (int j = 0; j < cg->dims[3 * c]; j++) { + for (int j = 0; j < cg->dims[static_cast(3 * c)]; j++) { for (int k = 0; k < cg->dims[3 * c + 1]; k++) { for (int l = 0; l < cg->dims[3 * c + 2]; l++) { fillReceptorDataPtr( @@ -93,7 +95,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc) } } - for (int j = 0; j < cg->dims[3 * c] + 1; j++) { + for (int j = 0; j < cg->dims[static_cast(3 * c)] + 1; j++) { for (int k = 0; k < cg->dims[3 * c + 1] + 1; k++) { for (int l = 0; l < cg->dims[3 * c + 2] + 1; l++) { fillReceptorDataPtr( @@ -184,17 +186,20 @@ void MeshBlock::fillReceptorDataPtr( int itm = -1; if (isNodal) { itm = cart_utils::get_concatenated_node_index( - cg->dims[3 * c], cg->dims[3 * c + 1], cg->dims[3 * c + 2], cg->nf, - j, k, l); + cg->dims[static_cast(3 * c)], cg->dims[3 * c + 1], + cg->dims[3 * c + 2], cg->nf, j, k, l); - xtm[0] = cg->xlo[3 * c] + j * cg->dx[3 * c]; + xtm[0] = cg->xlo[static_cast(3 * c)] + + j * cg->dx[static_cast(3 * c)]; xtm[1] = cg->xlo[3 * c + 1] + k * cg->dx[3 * c + 1]; xtm[2] = cg->xlo[3 * c + 2] + l * cg->dx[3 * c + 2]; } else { itm = cart_utils::get_cell_index( - cg->dims[3 * c], cg->dims[3 * c + 1], cg->nf, j, k, l); + cg->dims[static_cast(3 * c)], cg->dims[3 * c + 1], cg->nf, j, + k, l); - xtm[0] = cg->xlo[3 * c] + (j + 0.5) * cg->dx[3 * c]; + xtm[0] = cg->xlo[static_cast(3 * c)] + + (j + 0.5) * cg->dx[static_cast(3 * c)]; xtm[1] = cg->xlo[3 * c + 1] + (k + 0.5) * cg->dx[3 * c + 1]; xtm[2] = cg->xlo[3 * c + 2] + (l + 0.5) * cg->dx[3 * c + 2]; } diff --git a/src/highOrder.C b/src/highOrder.C index f648390..fa426b3 100644 --- a/src/highOrder.C +++ b/src/highOrder.C @@ -159,7 +159,8 @@ void MeshBlock::clearOrphans(HOLEMAP* holemap, int nmesh, const int* itmp) if (k != (meshtag - BASE) && (holemap[k].existWall != 0)) { if (checkHoleMap( - &rxyz[3 * m], holemap[k].nx, holemap[k].sam, + &rxyz[static_cast(3 * m)], + holemap[k].nx, holemap[k].sam, holemap[k].extents) != 0) { reject = 1; break; @@ -353,14 +354,16 @@ void MeshBlock::processPointDonors() interpList2[m].inode = (int*)malloc(sizeof(int)); interpList2[m].nweights = 0; donor_frac( - &(icell), &(xsearch[3 * i]), &(interpList2[m].nweights), - &(interpList2[m].inode[0]), frac, &(rst[3 * i]), &ndim); + &(icell), &(xsearch[static_cast(3 * i)]), + &(interpList2[m].nweights), &(interpList2[m].inode[0]), + frac, &(rst[static_cast(3 * i)]), &ndim); interpList2[m].weights = (double*)malloc(sizeof(double) * interpList2[m].nweights); for (j = 0; j < interpList2[m].nweights; j++) { interpList2[m].weights[j] = frac[j]; } - interpList2[m].receptorInfo[0] = isearch[3 * i]; + interpList2[m].receptorInfo[0] = + isearch[static_cast(3 * i)]; interpList2[m].receptorInfo[1] = isearch[3 * i + 1]; interpList2[m].receptorInfo[2] = isearch[3 * i + 2]; m++; @@ -387,14 +390,15 @@ void MeshBlock::processPointDonors() xv[ivert][j] = x[i3 + j]; } } - xp[0] = xsearch[3 * i]; + xp[0] = xsearch[static_cast(3 * i)]; xp[1] = xsearch[3 * i + 1]; xp[2] = xsearch[3 * i + 2]; computeNodalWeights(xv, xp, frac2, nvert); for (j = 0; j < nvert; j++) { interpList2[m].weights[j] = frac2[j]; } - interpList2[m].receptorInfo[0] = isearch[3 * i]; + interpList2[m].receptorInfo[0] = + isearch[static_cast(3 * i)]; interpList2[m].receptorInfo[1] = isearch[3 * i + 1]; interpList2[m].receptorInfo[2] = isearch[3 * i + 2]; m++; diff --git a/src/holeMap.C b/src/holeMap.C index 7f688fa..3a74fef 100644 --- a/src/holeMap.C +++ b/src/holeMap.C @@ -126,8 +126,9 @@ void tioga::getHoleMap() MPI_Allreduce( bboxLocal, bboxGlobal, 3 * maxtag, MPI_DOUBLE, MPI_MIN, scomm); MPI_Allreduce( - &(bboxLocal[3 * maxtag]), &(bboxGlobal[3 * maxtag]), 3 * maxtag, - MPI_DOUBLE, MPI_MAX, scomm); + &(bboxLocal[static_cast(3 * maxtag)]), + &(bboxGlobal[static_cast(3 * maxtag)]), 3 * maxtag, MPI_DOUBLE, + MPI_MAX, scomm); // // find the bounding box for each mesh // from the globally reduced data @@ -975,7 +976,7 @@ void writePointsVolume( for (pt = 0, k = 0; k < npts1d; ++k) { for (j = 0; j < npts1d; ++j) { for (i = 0; i < npts1d; ++i) { - double* co = &x[3 * pt]; + double* co = &x[static_cast(3 * pt)]; fprintf( fp, "%f %f %f %d %d %d\n", co[0], co[1], co[2], type, level, id); @@ -1002,7 +1003,7 @@ void writePointsVolumeBrick( for (pt = 0, k = 0; k < npts1d; ++k) { for (j = 0; j < npts1d; ++j) { for (i = 0; i < npts1d; ++i) { - double* co = &x[3 * pt]; + double* co = &x[static_cast(3 * pt)]; fprintf(fp, "%f ", co[0]); pt++; } @@ -1014,7 +1015,7 @@ void writePointsVolumeBrick( for (pt = 0, k = 0; k < npts1d; ++k) { for (j = 0; j < npts1d; ++j) { for (i = 0; i < npts1d; ++i) { - double* co = &x[3 * pt]; + double* co = &x[static_cast(3 * pt)]; fprintf(fp, "%f ", co[1]); pt++; } @@ -1026,7 +1027,7 @@ void writePointsVolumeBrick( for (pt = 0, k = 0; k < npts1d; ++k) { for (j = 0; j < npts1d; ++j) { for (i = 0; i < npts1d; ++i) { - double* co = &x[3 * pt]; + double* co = &x[static_cast(3 * pt)]; fprintf(fp, "%f ", co[2]); pt++; } diff --git a/src/parallelComm.C b/src/parallelComm.C index 7fb3b33..aa58c02 100644 --- a/src/parallelComm.C +++ b/src/parallelComm.C @@ -215,7 +215,7 @@ void parallelComm::sendRecvPackets(PACKET* sndPack, PACKET* rcvPack) status = (MPI_Status*)malloc(sizeof(MPI_Status) * 2 * (nsend + nrecv)); // for (i = 0; i < nsend; i++) { - scount[2 * i] = sndPack[i].nints; + scount[static_cast(2 * i)] = sndPack[i].nints; scount[2 * i + 1] = sndPack[i].nreals; } // @@ -224,19 +224,19 @@ void parallelComm::sendRecvPackets(PACKET* sndPack, PACKET* rcvPack) // for (i = 0; i < nrecv; i++) { MPI_Irecv( - &(rcount[2 * i]), 2, MPI_INT, rcvMap[i], tag, scomm, - &request[irnum++]); + &(rcount[static_cast(2 * i)]), 2, MPI_INT, rcvMap[i], tag, + scomm, &request[irnum++]); } // for (i = 0; i < nsend; i++) { MPI_Isend( - &(scount[2 * i]), 2, MPI_INT, sndMap[i], tag, scomm, - &request[irnum++]); + &(scount[static_cast(2 * i)]), 2, MPI_INT, sndMap[i], tag, + scomm, &request[irnum++]); } // MPI_Waitall(irnum, request, status); for (i = 0; i < nrecv; i++) { - rcvPack[i].nints = rcount[2 * i]; + rcvPack[i].nints = rcount[static_cast(2 * i)]; rcvPack[i].nreals = rcount[2 * i + 1]; } // @@ -295,7 +295,7 @@ void parallelComm::sendRecvPacketsCheck(PACKET* sndPack, PACKET* rcvPack) status = (MPI_Status*)malloc(sizeof(MPI_Status) * 2 * (nsend + nrecv)); // for (i = 0; i < nsend; i++) { - scount[2 * i] = sndPack[i].nints; + scount[static_cast(2 * i)] = sndPack[i].nints; scount[2 * i + 1] = sndPack[i].nreals; } // @@ -304,20 +304,20 @@ void parallelComm::sendRecvPacketsCheck(PACKET* sndPack, PACKET* rcvPack) // for (i = 0; i < nrecv; i++) { MPI_Irecv( - &(rcount[2 * i]), 2, MPI_INT, rcvMap[i], tag, scomm, - &request[irnum++]); + &(rcount[static_cast(2 * i)]), 2, MPI_INT, rcvMap[i], tag, + scomm, &request[irnum++]); } // for (i = 0; i < nsend; i++) { MPI_Isend( - &(scount[2 * i]), 2, MPI_INT, sndMap[i], tag, scomm, - &request[irnum++]); + &(scount[static_cast(2 * i)]), 2, MPI_INT, sndMap[i], tag, + scomm, &request[irnum++]); } // MPI_Waitall(irnum, request, status); for (i = 0; i < nrecv; i++) { - rcvPack[i].nints = rcount[2 * i]; + rcvPack[i].nints = rcount[static_cast(2 * i)]; rcvPack[i].nreals = rcount[2 * i + 1]; } diff --git a/src/search.C b/src/search.C index eaea8c2..3cad7ac 100644 --- a/src/search.C +++ b/src/search.C @@ -349,7 +349,7 @@ void MeshBlock::search() for (i = 0; i < nsearch; i++) { if (xtag[i] == i) { // adt->searchADT(this,&(donorId[i]),&(xsearch[3*i])); - adt->searchADT(this, dId, &(xsearch[3 * i])); + adt->searchADT(this, dId, &(xsearch[static_cast(3 * i)])); // std::cout << "ADT -> (" << dId[0] << "," << dId[1] << ")\n"; donorId[i] = dId[0]; } else { diff --git a/src/searchADTrecursion.C b/src/searchADTrecursion.C index 3d21e60..436d23e 100644 --- a/src/searchADTrecursion.C +++ b/src/searchADTrecursion.C @@ -47,7 +47,8 @@ void ADT::searchADT(MeshBlock* mb, int* cellIndex, double* xsearch) flag = 1; for (i = 0; i < ndim / 2; i++) { flag = static_cast( - (flag != 0) && (xsearch[i] >= adtExtents[2 * i] - mb->searchTol)); + (flag != 0) && (xsearch[i] >= adtExtents[static_cast(2 * i)] - + mb->searchTol)); } for (i = 0; i < ndim / 2; i++) { flag = static_cast( @@ -83,7 +84,8 @@ void searchIntersections( bool flag; // for (i = 0; i < ndim; i++) { - element[i] = coord[ndim * (adtIntegers[4 * node]) + i]; + element[i] = + coord[ndim * (adtIntegers[static_cast(4 * node)]) + i]; } // flag = true; @@ -95,7 +97,8 @@ void searchIntersections( } // if (flag) { - mb->checkContainment(cellIndex, adtIntegers[4 * node], xsearch); + mb->checkContainment( + cellIndex, adtIntegers[static_cast(4 * node)], xsearch); if (cellIndex[0] > -1 && cellIndex[1] == 0) { return; } diff --git a/src/tioga.C b/src/tioga.C index b8d7c27..875f842 100644 --- a/src/tioga.C +++ b/src/tioga.C @@ -741,7 +741,7 @@ void tioga::dataUpdate_AMR() // populate the packets // for (i = 0; i < nints; i++) { - k = integerRecords[3 * i]; + k = integerRecords[static_cast(3 * i)]; if (k < 0 || k > nsend) { TRACEI(nsend); TRACEI(i); @@ -762,7 +762,7 @@ void tioga::dataUpdate_AMR() m = 0; for (i = 0; i < nints; i++) { - k = integerRecords[3 * i]; + k = integerRecords[static_cast(3 * i)]; sndPack[k].intData[icount[k]++] = integerRecords[3 * i + 1]; sndPack[k].intData[icount[k]++] = integerRecords[3 * i + 2]; for (j = 0; j < nvar; j++) { @@ -781,7 +781,7 @@ void tioga::dataUpdate_AMR() for (k = 0; k < nrecv; k++) { m = 0; for (i = 0; i < rcvPack[k].nints / 2; i++) { - bid = rcvPack[k].intData[2 * i]; + bid = rcvPack[k].intData[static_cast(2 * i)]; if (bid < 0) { int const inode = rcvPack[k].intData[2 * i + 1]; mblocks[-(bid + 1)]->updateSolnData( @@ -870,7 +870,7 @@ void tioga::dataUpdate(int nvar, int interptype, int at_points) // populate the packets // for (int i = 0; i < nints[ib]; i++) { - int const k = integerRecords[ib][3 * i]; + int const k = integerRecords[ib][static_cast(3 * i)]; sndPack[k].nints += 2; sndPack[k].nreals += nvar; } @@ -886,7 +886,7 @@ void tioga::dataUpdate(int nvar, int interptype, int at_points) for (int ib = 0; ib < nblocks; ib++) { int m = 0; for (int i = 0; i < nints[ib]; i++) { - int const k = integerRecords[ib][3 * i]; + int const k = integerRecords[ib][static_cast(3 * i)]; sndPack[k].intData[icount[k]++] = integerRecords[ib][3 * i + 1]; sndPack[k].intData[icount[k]++] = integerRecords[ib][3 * i + 2]; for (int j = 0; j < nvar; j++) { @@ -1105,7 +1105,7 @@ void tioga::getReceptorInfo(std::vector& receptors) // bytes through the int array. This makes total number of ints per // fringe data be (3 + 2) = 5 // - fringeSend[ib].resize(5 * dcount[ib]); + fringeSend[ib].resize(static_cast(5 * dcount[ib])); mblocks[ib]->getReceptorInfo(fringeSend[ib].data()); std::vector& fringeData = fringeSend[ib]; @@ -1331,7 +1331,7 @@ void tioga::reduce_fringes() // for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].nints += 2; } } @@ -1342,7 +1342,7 @@ void tioga::reduce_fringes() // for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 1]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 2]; } @@ -1382,7 +1382,7 @@ void tioga::reduce_fringes() std::fill(ixOffset.begin(), ixOffset.end(), 0); for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].nints += 2; } } @@ -1391,7 +1391,7 @@ void tioga::reduce_fringes() } for (int n = 0; n < nblocks; n++) { for (int i = 0; i < nrecords[n]; i++) { - int const k = donorRecords[n][3 * i]; + int const k = donorRecords[n][static_cast(3 * i)]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 1]; sndPack[k].intData[ixOffset[k]++] = donorRecords[n][3 * i + 2]; } @@ -1477,7 +1477,7 @@ void tioga::preprocess_amr_data(int root) // an additional parameter at the end to exchange the number of ghosts per // patch. std::vector idata(ngrids_global * nint_per_grid + 1); - std::vector rdata(ngrids_global * nreal_per_grid); + std::vector rdata(static_cast(ngrids_global * nreal_per_grid)); // On root MPI process for the AMR solver, populate the buffer for broadcast // to all processes.