Space: generate neighboring cells
This commit is contained in:
@@ -94,8 +94,9 @@ void Space::buildCells() {
|
||||
int j = static_cast<int>(atom.y / this->m_cutoff);
|
||||
int k = static_cast<int>(atom.z / this->m_cutoff);
|
||||
|
||||
Cell &cell =
|
||||
this->m_cells[i * this->m_cellsDim.y * this->m_cellsDim.z + j * this->m_cellsDim.z + k];
|
||||
int idx = i * this->m_cellsDim.y * this->m_cellsDim.z + j * this->m_cellsDim.z + k;
|
||||
|
||||
Cell &cell = this->m_cells[idx];
|
||||
|
||||
cell.x.push_back(atom.x);
|
||||
cell.y.push_back(atom.y);
|
||||
@@ -109,6 +110,43 @@ void Space::printCells() const {
|
||||
cell.printCell();
|
||||
}
|
||||
|
||||
Cell Space::getNeighboringCells(int idx) const {
|
||||
Cell neighboringCells;
|
||||
|
||||
const Cell &cell = this->m_cells[idx];
|
||||
|
||||
// For each cell adjacent to the cell of the given index, add its atoms to neighboringCells
|
||||
for (int i = -1; i <= 1; i++)
|
||||
for (int j = -1; j <= 1; j++)
|
||||
for (int k = -1; k <= 1; k++) {
|
||||
int x = cell.m_x + i * this->m_cutoff;
|
||||
int y = cell.m_y + j * this->m_cutoff;
|
||||
int z = cell.m_z + k * this->m_cutoff;
|
||||
|
||||
if (x < 0 || x >= this->m_box.x || y < 0 || y >= this->m_box.y || z < 0 ||
|
||||
z >= this->m_box.z)
|
||||
continue;
|
||||
|
||||
std::cout << "Adding cell (" << x << ", " << y << ", " << z << ") to neighboringCells"
|
||||
<< std::endl;
|
||||
|
||||
int idx = i * this->m_cellsDim.y * this->m_cellsDim.z + j * this->m_cellsDim.z + k;
|
||||
|
||||
const Cell &neighboringCell = this->m_cells[idx];
|
||||
|
||||
neighboringCells.x.insert(
|
||||
neighboringCells.x.end(), neighboringCell.x.begin(), neighboringCell.x.end());
|
||||
neighboringCells.y.insert(
|
||||
neighboringCells.y.end(), neighboringCell.y.begin(), neighboringCell.y.end());
|
||||
neighboringCells.z.insert(
|
||||
neighboringCells.z.end(), neighboringCell.z.begin(), neighboringCell.z.end());
|
||||
neighboringCells.idx.insert(
|
||||
neighboringCells.idx.end(), neighboringCell.idx.begin(), neighboringCell.idx.end());
|
||||
}
|
||||
|
||||
return neighboringCells;
|
||||
}
|
||||
|
||||
void Cell::printCell() const {
|
||||
std::cout << "Cell " << this->m_idx << " (" << this->m_x << ", " << this->m_y << ", " << this->m_z
|
||||
<< "):" << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user