Skip to content

Commit 12d132e

Browse files
committed
Declare variables closer to their initialization
1 parent 83c7a90 commit 12d132e

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

Common/src/interface_interpolation/CInterpolator.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,11 @@ unsigned long CInterpolator::Collect_ElementInfo(int markDonor, unsigned short n
155155
void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker) {
156156
CGeometry* geom = Geometry[val_zone][INST_0][MESH_0];
157157

158-
unsigned long iVertex, kVertex;
159-
160-
unsigned long *uptr, nVertex, nElems, iDim, iPoint;
161-
162-
unsigned long nGlobalLinkedNodes, nLocalVertex, nLocalLinkedNodes;
163-
164158
const auto nDim = geom->GetnDim();
165159

166160
/*--- If this zone has no parts of the marker, it will not participate
167161
* in the first part of this function (collection). ---*/
162+
unsigned long nVertex, nElems;
168163
if (val_marker != -1) {
169164
nVertex = geom->GetnVertex(val_marker);
170165
nElems = geom->GetnElem_Bound(val_marker);
@@ -176,9 +171,9 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
176171
/*--- Get the number of domain vertices on the marker, and a mapping
177172
* (iVertex) -> (iLocalVertex, non-domain points being ignored). ---*/
178173
su2vector<unsigned long> iVertex_to_iLocalVertex(nVertex);
179-
nLocalVertex = 0;
180-
for (iVertex = 0; iVertex < nVertex; iVertex++) {
181-
iPoint = geom->vertex[val_marker][iVertex]->GetNode();
174+
unsigned long nLocalVertex = 0;
175+
for (unsigned long iVertex = 0; iVertex < nVertex; iVertex++) {
176+
const auto iPoint = geom->vertex[val_marker][iVertex]->GetNode();
182177
if (geom->nodes->GetDomain(iPoint)) {
183178
iVertex_to_iLocalVertex[iVertex] = nLocalVertex;
184179
nLocalVertex++;
@@ -197,12 +192,12 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
197192
unordered_map<unsigned long, set<unsigned long> > neighbors;
198193

199194
/*--- Define or initialize them. ---*/
200-
for (iVertex = 0; iVertex < nVertex; iVertex++) {
201-
iPoint = geom->vertex[val_marker][iVertex]->GetNode();
195+
for (unsigned long iVertex = 0; iVertex < nVertex; iVertex++) {
196+
const auto iPoint = geom->vertex[val_marker][iVertex]->GetNode();
202197
if (geom->nodes->GetDomain(iPoint)) {
203198
unsigned long iLocalVertex = iVertex_to_iLocalVertex[iVertex];
204199
Buffer_Send_GlobalPoint[iLocalVertex] = geom->nodes->GetGlobalIndex(iPoint);
205-
for (iDim = 0; iDim < nDim; iDim++) Buffer_Send_Coord[iLocalVertex][iDim] = geom->nodes->GetCoord(iPoint, iDim);
200+
for (unsigned long iDim = 0; iDim < nDim; iDim++) Buffer_Send_Coord[iLocalVertex][iDim] = geom->nodes->GetCoord(iPoint, iDim);
206201
neighbors.insert(pair<unsigned long, set<unsigned long> >(iPoint, set<unsigned long>()));
207202
}
208203
}
@@ -211,7 +206,7 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
211206
for (unsigned long iElem = 0; iElem < nElems; iElem++) {
212207
CPrimalGrid* elem = geom->bound[val_marker][iElem];
213208
for (unsigned short iNode = 0; iNode < elem->GetnNodes(); iNode++) {
214-
iPoint = elem->GetNode(iNode);
209+
const auto iPoint = elem->GetNode(iNode);
215210
if (geom->nodes->GetDomain(iPoint)) {
216211
set<unsigned long>& neighb = neighbors.at(iPoint);
217212
for (unsigned short iNeighbor = 0; iNeighbor < elem->GetnNeighbor_Nodes(iNode); iNeighbor++) {
@@ -227,9 +222,9 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
227222
su2vector<unsigned long> Buffer_Send_nLinkedNodes(nLocalVertex);
228223
// cumsum of Buffer_Send_nLinkedNodes
229224
su2vector<unsigned long> Buffer_Send_StartLinkedNodes(nLocalVertex);
230-
nLocalLinkedNodes = 0;
231-
for (iVertex = 0; iVertex < nVertex; iVertex++) {
232-
iPoint = geom->vertex[val_marker][iVertex]->GetNode();
225+
unsigned long nLocalLinkedNodes = 0;
226+
for (unsigned long iVertex = 0; iVertex < nVertex; iVertex++) {
227+
const auto iPoint = geom->vertex[val_marker][iVertex]->GetNode();
233228
if (geom->nodes->GetDomain(iPoint)) {
234229
unsigned long iLocalVertex = iVertex_to_iLocalVertex[iVertex];
235230
Buffer_Send_nLinkedNodes[iLocalVertex] = neighbors.at(iPoint).size();
@@ -240,8 +235,8 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
240235
// global point IDs of surface-neighbors of all domain vertices on the marker
241236
su2vector<unsigned long> Buffer_Send_LinkedNodes(nLocalLinkedNodes);
242237
unsigned long index = 0;
243-
for (iVertex = 0; iVertex < nVertex; iVertex++) {
244-
iPoint = geom->vertex[val_marker][iVertex]->GetNode();
238+
for (unsigned long iVertex = 0; iVertex < nVertex; iVertex++) {
239+
const auto iPoint = geom->vertex[val_marker][iVertex]->GetNode();
245240
if (geom->nodes->GetDomain(iPoint)) {
246241
for (unsigned long jPoint_global : neighbors.at(iPoint)) {
247242
Buffer_Send_LinkedNodes[index] = jPoint_global;
@@ -256,6 +251,7 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
256251
* For this, the master process collects the data from all processes, joins them and broadcasts them again. ---*/
257252

258253
/*--- Allocate global arrays. ---*/
254+
unsigned long nGlobalLinkedNodes;
259255
SU2_MPI::Allreduce(&nLocalVertex, &nGlobalVertex, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
260256
SU2_MPI::Allreduce(&nLocalLinkedNodes, &nGlobalLinkedNodes, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
261257

@@ -278,14 +274,14 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
278274
for (unsigned long iDim = 0; iDim < nDim; iDim++)
279275
Buffer_Receive_Coord(iVertex, iDim) = Buffer_Send_Coord(iVertex, iDim);
280276

281-
for (iVertex = 0; iVertex < nLocalVertex; iVertex++) {
277+
for (unsigned long iVertex = 0; iVertex < nLocalVertex; iVertex++) {
282278
Buffer_Receive_GlobalPoint[iVertex] = Buffer_Send_GlobalPoint[iVertex];
283279
Buffer_Receive_Proc[iVertex] = MASTER_NODE;
284280
Buffer_Receive_nLinkedNodes[iVertex] = Buffer_Send_nLinkedNodes[iVertex];
285281
Buffer_Receive_StartLinkedNodes[iVertex] = Buffer_Send_StartLinkedNodes[iVertex];
286282
}
287283

288-
for (iVertex = 0; iVertex < nLocalLinkedNodes; iVertex++)
284+
for (unsigned long iVertex = 0; iVertex < nLocalLinkedNodes; iVertex++)
289285
Buffer_Receive_LinkedNodes[iVertex] = Buffer_Send_LinkedNodes[iVertex];
290286

291287
unsigned long received_nLocalVertex_sum = nLocalVertex;
@@ -309,7 +305,7 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
309305
SU2_MPI::Recv(&Buffer_Receive_StartLinkedNodes[received_nLocalVertex_sum], received_nLocalVertex,
310306
MPI_UNSIGNED_LONG, iRank, 1, SU2_MPI::GetComm(), MPI_STATUS_IGNORE);
311307

312-
for (iVertex = 0; iVertex < received_nLocalVertex; iVertex++) {
308+
for (unsigned long iVertex = 0; iVertex < received_nLocalVertex; iVertex++) {
313309
Buffer_Receive_Proc[received_nLocalVertex_sum + iVertex] = iRank;
314310
Buffer_Receive_StartLinkedNodes[received_nLocalVertex_sum + iVertex] += received_nLocalLinkedNodes_sum;
315311
}
@@ -333,27 +329,27 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
333329
for (unsigned long iDim = 0; iDim < nDim; iDim++)
334330
Buffer_Receive_Coord(iVertex, iDim) = Buffer_Send_Coord(iVertex, iDim);
335331

336-
for (iVertex = 0; iVertex < nGlobalVertex; iVertex++) {
332+
for (unsigned long iVertex = 0; iVertex < nGlobalVertex; iVertex++) {
337333
Buffer_Receive_GlobalPoint[iVertex] = Buffer_Send_GlobalPoint[iVertex];
338334
Buffer_Receive_Proc[iVertex] = MASTER_NODE;
339335
Buffer_Receive_nLinkedNodes[iVertex] = Buffer_Send_nLinkedNodes[iVertex];
340336
Buffer_Receive_StartLinkedNodes[iVertex] = Buffer_Send_StartLinkedNodes[iVertex];
341337
}
342338

343-
for (iVertex = 0; iVertex < nGlobalLinkedNodes; iVertex++)
339+
for (unsigned long iVertex = 0; iVertex < nGlobalLinkedNodes; iVertex++)
344340
Buffer_Receive_LinkedNodes[iVertex] = Buffer_Send_LinkedNodes[iVertex];
345341
#endif
346342

347-
/*--- Master process replaced global point indices in Buffer_Receive_LinkedNodes by their indices in
343+
/*--- Master process replaces global point indices in Buffer_Receive_LinkedNodes by their indices in
348344
* Buffer_Receive_GlobalPoint, Buffer_Receive_nLinkedNodes etc. ---*/
349345
if (rank == MASTER_NODE) {
350-
for (iVertex = 0; iVertex < nGlobalVertex; iVertex++) {
351-
uptr = &Buffer_Receive_LinkedNodes[Buffer_Receive_StartLinkedNodes[iVertex]];
346+
for (unsigned long iVertex = 0; iVertex < nGlobalVertex; iVertex++) {
347+
unsigned long *uptr = &Buffer_Receive_LinkedNodes[Buffer_Receive_StartLinkedNodes[iVertex]];
352348

353349
for (unsigned long jLinkedNode = 0; jLinkedNode < Buffer_Receive_nLinkedNodes[iVertex]; jLinkedNode++) {
354350
unsigned long jPoint = uptr[jLinkedNode];
355351
bool found = false; // Global point index has been found
356-
for (kVertex = 0; kVertex < nGlobalVertex; kVertex++) {
352+
for (unsigned long kVertex = 0; kVertex < nGlobalVertex; kVertex++) {
357353
if (Buffer_Receive_GlobalPoint[kVertex] == jPoint) {
358354
uptr[jLinkedNode] = kVertex;
359355
found = true;
@@ -362,7 +358,7 @@ void CInterpolator::ReconstructBoundary(unsigned long val_zone, int val_marker)
362358
}
363359

364360
if (!found) { // remove from list
365-
for (kVertex = jLinkedNode; kVertex < Buffer_Receive_nLinkedNodes[iVertex] - 1; kVertex++) {
361+
for (unsigned long kVertex = jLinkedNode; kVertex < Buffer_Receive_nLinkedNodes[iVertex] - 1; kVertex++) {
366362
uptr[kVertex] = uptr[kVertex + 1];
367363
}
368364
Buffer_Receive_nLinkedNodes[iVertex]--;

0 commit comments

Comments
 (0)