Skip to content

Commit

Permalink
Removing redundant explicit casting
Browse files Browse the repository at this point in the history
  • Loading branch information
itopcuoglu committed Dec 16, 2024
1 parent 8c982f2 commit bf377b7
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 133 deletions.
19 changes: 8 additions & 11 deletions src/CartBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ void CartBlock::getInterpolatedData(
}

for (i = 0; i < listptr->nweights; i++) {
int const cell_index =
static_cast<int>(cart_utils::get_cell_index(
dims[0], dims[1], nf,
listptr->inode[static_cast<int>(3 * i)],
listptr->inode[3 * i + 1], listptr->inode[3 * i + 2]));
int const cell_index = (cart_utils::get_cell_index(
dims[0], dims[1], nf, listptr->inode[3 * i],

Check warning on line 115 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t' [bugprone-implicit-widening-of-multiplication-result]
listptr->inode[3 * i + 1], listptr->inode[3 * i + 2]));

Check warning on line 116 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

'*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]

Check warning on line 116 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

'*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
for (n = 0; n < nvar_cell; n++) {
weight = listptr->weights[i];
qq[n] += qcell[cell_index + ncell_nf * n] * weight;

Check warning on line 119 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

'*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
Expand Down Expand Up @@ -171,8 +169,7 @@ void CartBlock::preprocess(CartGrid* cg)
for (int n = 0; n < 3; n++) {
dx[n] = cg->dx[3 * global_id + n];

Check warning on line 170 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

'*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
}
dims[0] = cg->ihi[static_cast<int>(3 * global_id)] -
cg->ilo[static_cast<int>(3 * global_id)] + 1;
dims[0] = cg->ihi[3 * global_id] - cg->ilo[3 * global_id] + 1;

Check warning on line 172 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t' [bugprone-implicit-widening-of-multiplication-result]
dims[1] = cg->ihi[3 * global_id + 1] - cg->ilo[3 * global_id + 1] + 1;
dims[2] = cg->ihi[3 * global_id + 2] - cg->ilo[3 * global_id + 2] + 1;
nf = cg->nf;
Expand Down Expand Up @@ -260,10 +257,10 @@ void CartBlock::insertInInterpList(
}
if (donor_frac == nullptr) {
listptr->nweights = 8;
listptr->weights = (double*)malloc(
sizeof(double) * (static_cast<int>(listptr->nweights * 2)));
listptr->inode = (int*)malloc(
sizeof(int) * (static_cast<int>(listptr->nweights * 2 * 3)));
listptr->weights =
(double*)malloc(sizeof(double) * (listptr->nweights * 2));
listptr->inode =
(int*)malloc(sizeof(int) * (listptr->nweights * 2 * 3));

cart_interp::linear_interpolation(
nf, ix, dims, rst, &(listptr->nweights), listptr->inode,
Expand Down
10 changes: 4 additions & 6 deletions src/CartGrid.C
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,15 @@ void CartGrid::search(double* x, int* donorid, int npts)
}
}
}
if (myid == 2 && abs(x[static_cast<int>(3 * i)] - 0.739573) < 1e-5 &&
if (myid == 2 && abs(x[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[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], donorid[i]);
"%d %d %f %f %f %d\n", myid, i, x[3 * i], x[3 * i + 1],
x[3 * i + 2], donorid[i]);
}
if (donorid[i] == -1) {
printf(
"%d %f %f %f\n", myid, x[static_cast<int>(3 * i)], x[3 * i + 1],
x[3 * i + 2]);
printf("%d %f %f %f\n", myid, x[3 * i], x[3 * i + 1], x[3 * i + 2]);
}
}
// printf("CartGrid::search Processor %d located %d of %d
Expand Down
82 changes: 34 additions & 48 deletions src/MeshBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,11 @@ void MeshBlock::tagBoundaryFaces()
}

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

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

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

ba = 1 - BASE;
Expand All @@ -790,32 +790,28 @@ 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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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 @@ -851,7 +847,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[static_cast<int>(3 * i)]);
fprintf(fp, "%lf\n", x[3 * i]);
}
for (i = 0; i < nnodes; i++) {
fprintf(fp, "%lf\n", x[3 * i + 1]);
Expand All @@ -871,32 +867,28 @@ 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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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 @@ -946,8 +938,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[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], ibl[i], meshtag);
fp, "%lf %lf %lf %d %d ", x[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 @@ -958,8 +950,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[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], ibl[i], meshtag);
fp, "%lf %lf %lf %d %d ", x[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 @@ -972,32 +964,28 @@ 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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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][static_cast<int>(nvert * i)] + ba,
fp, "%d %d %d %d %d %d %d %d\n", vconn[n][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 @@ -1374,14 +1362,13 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
/* possible overlap: use face intersection test */

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

// get node indices and coordinates for this boundary face
// load 1st three nodes
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])];
double* pt1 = &x[3 * inode[0]];
double* pt2 = &x[3 * inode[1]];
double* pt3 = &x[3 * inode[2]];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1392,7 +1379,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[static_cast<int>(3 * inode[3])];
double* pt4 = &x[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 @@ -1493,14 +1480,13 @@ void MeshBlock::markBoundaryAdaptiveMapSurfaceIntersect(
/* possible overlap: use face intersection test */

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

// get node indices and coordinates for this boundary face
// load 1st three nodes
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])];
double* pt1 = &x[3 * inode[0]];
double* pt2 = &x[3 * inode[1]];
double* pt3 = &x[3 * inode[2]];

// test triangle 1: pass first 3 triangles
if (triBoxOverlap(boxcenter, halfdx, pt1, pt2, pt3) != 0) {
Expand All @@ -1511,7 +1497,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[static_cast<int>(3 * inode[3])];
double* pt4 = &x[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 @@ -2239,7 +2225,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][static_cast<int>(8 * i)] - BASE;
int const lnode = vconn[0][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 @@ -2285,8 +2271,8 @@ void MeshBlock::checkOrphans()
if (nodeRes[i] >= std::numeric_limits<double>::max()) {
if (iblank[i] == 1) {
fprintf(
fp, "%f %f %f %f\n", x[static_cast<int>(3 * i)],
x[3 * i + 1], x[3 * i + 2], nodeRes[i]);
fp, "%f %f %f %f\n", x[3 * i], x[3 * i + 1],
x[3 * i + 2], nodeRes[i]);
norphan++;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/MeshBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ class MeshBlock
void outputOrphan(FILE* fp, int i)
{
fprintf(
fp, "%f %f %f\n", rxyz[static_cast<int>(3 * i)], rxyz[3 * i + 1],
rxyz[3 * i + 2]);
fp, "%f %f %f\n", rxyz[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 bf377b7

Please sign in to comment.