Skip to content

Commit

Permalink
static_cast<ptrdiff_t>() instances in MeshBlock.C
Browse files Browse the repository at this point in the history
  • Loading branch information
itopcuoglu committed Dec 19, 2024
1 parent 7acc22c commit 3d8c2c1
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions src/MeshBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,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<ptrdiff_t>(3 * i)],
x[(3 * i) + 1], x[(3 * i) + 2], iblank[i]);
}

ba = 1 - BASE;
Expand All @@ -791,7 +791,8 @@ 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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 2] + ba,
Expand All @@ -801,7 +802,8 @@ void MeshBlock::writeGridFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 3] + ba,
Expand All @@ -811,7 +813,8 @@ void MeshBlock::writeGridFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 2] + ba,
Expand All @@ -821,7 +824,8 @@ void MeshBlock::writeGridFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 3] + ba,
Expand Down Expand Up @@ -860,7 +864,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<ptrdiff_t>(3 * i)]);
}
for (i = 0; i < nnodes; i++) {
fprintf(fp, "%lf\n", x[(3 * i) + 1]);
Expand All @@ -880,7 +884,8 @@ 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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 2] + ba,
Expand All @@ -890,7 +895,8 @@ void MeshBlock::writeCellFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 3] + ba,
Expand All @@ -900,7 +906,8 @@ void MeshBlock::writeCellFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 2] + ba,
Expand All @@ -910,7 +917,8 @@ void MeshBlock::writeCellFile(int bid)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 3] + ba,
Expand Down Expand Up @@ -963,8 +971,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<ptrdiff_t>(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 @@ -975,8 +983,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<ptrdiff_t>(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 @@ -1000,7 +1008,8 @@ void MeshBlock::writeFlowFile(int bid, double* q, int nvar, int type)
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<ptrdiff_t>(nvert * i)] + ba,
vconn[n][(nvert * i) + 1] + ba,
vconn[n][(nvert * i) + 2] + ba,
vconn[n][(nvert * i) + 3] + ba,
Expand Down Expand Up @@ -1406,9 +1415,9 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(

// 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<ptrdiff_t>(3 * inode[0])];
double* pt2 = &x[static_cast<ptrdiff_t>(3 * inode[1])];
double* pt3 = &x[static_cast<ptrdiff_t>(3 * inode[2])];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1419,7 +1428,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<ptrdiff_t>(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 @@ -1524,9 +1533,9 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(

// 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<ptrdiff_t>(3 * inode[0])];
double* pt2 = &x[static_cast<ptrdiff_t>(3 * inode[1])];
double* pt3 = &x[static_cast<ptrdiff_t>(3 * inode[2])];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1537,7 +1546,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<ptrdiff_t>(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 @@ -2265,7 +2274,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<ptrdiff_t>(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 @@ -2312,8 +2321,8 @@ void MeshBlock::checkOrphans()
if (nodeRes[i] >= std::numeric_limits<double>::max()) {
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<ptrdiff_t>(3 * i)],
x[(3 * i) + 1], x[(3 * i) + 2], nodeRes[i]);
norphan++;
}
}
Expand Down

0 comments on commit 3d8c2c1

Please sign in to comment.