Skip to content

Commit

Permalink
Changed C-style arrays in spatial_cell to c++11 std::arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoskela committed Sep 24, 2018
1 parent 79779b7 commit 0b51549
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 100 deletions.
2 changes: 1 addition & 1 deletion poisson_solver/poisson_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace poisson {

// Fetch pointers
for (size_t c=0; c<cells.size(); ++c) {
Poisson::localCellParams[c] = mpiGrid[cells[c]]->parameters;
Poisson::localCellParams[c] = mpiGrid[cells[c]]->parameters.data();
}
}

Expand Down
54 changes: 27 additions & 27 deletions poisson_solver/poisson_solver_cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace poisson {
CellCache3D<cgvar::SIZE> cache;
cache.cellID = cells[c];
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();

#ifdef DEBUG_POISSON_CG
if (cache.cell == NULL) {
Expand All @@ -205,8 +205,8 @@ namespace poisson {
case sysboundarytype::NOT_SYSBOUNDARY:
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;

if (indices[1] == 2) {
Expand All @@ -218,10 +218,10 @@ namespace poisson {
cache[3] = dummy->get_cell_parameters();
}
} else {
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
}

indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;
break;

Expand All @@ -232,11 +232,11 @@ namespace poisson {
indices[0] -= 1;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[1] = bndryCellParams;
else cache[1] = dummy->parameters;
else cache[1] = dummy->parameters.data();
indices[0] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[2] = bndryCellParams;
else cache[2] = dummy->parameters;
else cache[2] = dummy->parameters.data();
indices[0] -= 1;

// Set +/- y-neighbors both point to +y neighbor
Expand All @@ -249,7 +249,7 @@ namespace poisson {
if (dummy == NULL) {
cache[4] = bndryCellParams;
} else {
cache[4] = dummy->parameters;
cache[4] = dummy->parameters.data();
}
indices[1] -= 1;
} else {
Expand All @@ -259,7 +259,7 @@ namespace poisson {
if (dummy == NULL) {
cache[3] = bndryCellParams;
} else {
cache[3] = dummy->parameters;
cache[3] = dummy->parameters.data();
}
indices[1] += 1;
}
Expand All @@ -270,24 +270,24 @@ namespace poisson {
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
//if (dummy == NULL) cache[1] = bndryCellParams;
if (dummy == NULL) continue;
else cache[1] = dummy->parameters;
else cache[1] = dummy->parameters.data();
indices[0] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
//if (dummy == NULL) cache[2] = bndryCellParams;
if (dummy == NULL) continue;
else cache[2] = dummy->parameters;
else cache[2] = dummy->parameters.data();
indices[0] -= 1;

indices[1] -= 1;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
//if (dummy == NULL) cache[3] = bndryCellParams;
if (dummy == NULL) continue;
else cache[3] = dummy->parameters;
else cache[3] = dummy->parameters.data();
indices[1] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
//if (dummy == NULL) cache[4] = bndryCellParams;
if (dummy == NULL) continue;
else cache[4] = dummy->parameters;
else cache[4] = dummy->parameters.data();
indices[1] -= 1;
break;
}
Expand Down Expand Up @@ -316,18 +316,18 @@ namespace poisson {
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] -= 1;
redCache.push_back(cache);
Expand All @@ -340,18 +340,18 @@ namespace poisson {
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] -= 1;
blackCache.push_back(cache);
Expand Down
54 changes: 27 additions & 27 deletions poisson_solver/poisson_solver_sor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ namespace poisson {
CellCache3D<SOR_VARS> cache;
cache.cellID = cells[c];
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();

#ifdef DEBUG_POISSON_SOR
if (cache.cell == NULL) {
Expand All @@ -332,12 +332,12 @@ namespace poisson {
case sysboundarytype::NOT_SYSBOUNDARY:
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;

indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;
break;

Expand All @@ -346,11 +346,11 @@ namespace poisson {
indices[0] -= 1;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[1] = bndryCellParams;
else cache[1] = dummy->parameters;
else cache[1] = dummy->parameters.data();
indices[0] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[2] = bndryCellParams;
else cache[2] = dummy->parameters;
else cache[2] = dummy->parameters.data();
indices[0] -= 1;

// Set +/- y-neighbors both point to +y neighbor
Expand All @@ -363,7 +363,7 @@ namespace poisson {
if (dummy == NULL) {
cache[4] = bndryCellParams;
} else {
cache[4] = dummy->parameters;
cache[4] = dummy->parameters.data();
}
indices[1] -= 1;
} else {
Expand All @@ -373,7 +373,7 @@ namespace poisson {
if (dummy == NULL) {
cache[3] = bndryCellParams;
} else {
cache[3] = dummy->parameters;
cache[3] = dummy->parameters.data();
}
indices[1] += 1;
}
Expand All @@ -383,21 +383,21 @@ namespace poisson {
indices[0] -= 1;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[1] = bndryCellParams;
else cache[1] = dummy->parameters;
else cache[1] = dummy->parameters.data();
indices[0] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[2] = bndryCellParams;
else cache[2] = dummy->parameters;
else cache[2] = dummy->parameters.data();
indices[0] -= 1;

indices[1] -= 1;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[3] = bndryCellParams;
else cache[3] = dummy->parameters;
else cache[3] = dummy->parameters.data();
indices[1] += 2;
dummy = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ];
if (dummy == NULL) cache[4] = bndryCellParams;
else cache[4] = dummy->parameters;
else cache[4] = dummy->parameters.data();
indices[1] -= 1;
break;
}
Expand Down Expand Up @@ -429,18 +429,18 @@ namespace poisson {
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();

indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;

indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;

indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] -= 1;

redCache.push_back(cache);
Expand All @@ -451,18 +451,18 @@ namespace poisson {
// Fetch pointers to this cell's (cell) parameters array,
// and pointers to +/- xyz face neighbors' arrays
cache.cell = mpiGrid[cells[c]];
cache[0] = mpiGrid[cells[c]]->parameters;
cache[0] = mpiGrid[cells[c]]->parameters.data();

indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[0] -= 1; cache[1] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] += 2; cache[2] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[0] -= 1;

indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[1] -= 1; cache[3] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] += 2; cache[4] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[1] -= 1;

indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters;
indices[2] -= 1; cache[5] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] += 2; cache[6] = mpiGrid[ mpiGrid.mapping.get_cell_from_indices(indices,0) ]->parameters.data();
indices[2] -= 1;

blackCache.push_back(cache);
Expand Down
37 changes: 20 additions & 17 deletions spatial_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,26 @@ namespace spatial_cell {
velocity_block_with_no_content_list(other.velocity_block_with_no_content_list),
initialized(other.initialized),
mpiTransferEnabled(other.mpiTransferEnabled),
populations(other.populations) {

//copy parameters
for(unsigned int i=0;i< CellParams::N_SPATIAL_CELL_PARAMS;i++){
parameters[i]=other.parameters[i];
}
//copy derivatives
for(unsigned int i=0;i< fieldsolver::N_SPATIAL_CELL_DERIVATIVES;i++){
derivatives[i]=other.derivatives[i];
}
//copy BVOL derivatives
for(unsigned int i=0;i< bvolderivatives::N_BVOL_DERIVATIVES;i++){
derivativesBVOL[i]=other.derivativesBVOL[i];
}

//set null block data
for (unsigned int i=0; i<WID3; ++i) null_block_data[i] = 0.0;
populations(other.populations),
parameters(other.parameters),
derivatives(other.derivatives),
derivativesBVOL(other.derivativesBVOL),
null_block_data(std::array<Realf,WID3> {}) {

// //copy parameters
// for(unsigned int i=0;i< CellParams::N_SPATIAL_CELL_PARAMS;i++){
// parameters[i]=other.parameters[i];
// }
// //copy derivatives
// for(unsigned int i=0;i< fieldsolver::N_SPATIAL_CELL_DERIVATIVES;i++){
// derivatives[i]=other.derivatives[i];
// }
// //copy BVOL derivatives
// for(unsigned int i=0;i< bvolderivatives::N_BVOL_DERIVATIVES;i++){
// derivativesBVOL[i]=other.derivativesBVOL[i];
// }
// //set null block data
// for (unsigned int i=0; i<WID3; ++i) null_block_data[i] = 0.0;
}


Expand Down
Loading

0 comments on commit 0b51549

Please sign in to comment.