Space: generate neighboring cells
This commit is contained in:
@@ -24,7 +24,7 @@ int main() {
|
|||||||
int numberOfCells = 5;
|
int numberOfCells = 5;
|
||||||
double temperature = 300;
|
double temperature = 300;
|
||||||
|
|
||||||
Space space(3 * 1.5);
|
Space space(3);
|
||||||
|
|
||||||
std::vector<Atom> atoms = generateFCCAtoms(lattice, numberOfCells, "Ar", 1);
|
std::vector<Atom> atoms = generateFCCAtoms(lattice, numberOfCells, "Ar", 1);
|
||||||
initMaxwellBoltzmannVelocities(atoms, temperature);
|
initMaxwellBoltzmannVelocities(atoms, temperature);
|
||||||
@@ -41,7 +41,8 @@ int main() {
|
|||||||
std::cout << "Building cells..." << std::endl;
|
std::cout << "Building cells..." << std::endl;
|
||||||
space.buildCells();
|
space.buildCells();
|
||||||
|
|
||||||
space.printCells();
|
std::cout << "Getting neighboring cells of index 0" << std::endl;
|
||||||
|
Cell neighboringCells = space.getNeighboringCells(0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -94,8 +94,9 @@ void Space::buildCells() {
|
|||||||
int j = static_cast<int>(atom.y / this->m_cutoff);
|
int j = static_cast<int>(atom.y / this->m_cutoff);
|
||||||
int k = static_cast<int>(atom.z / this->m_cutoff);
|
int k = static_cast<int>(atom.z / this->m_cutoff);
|
||||||
|
|
||||||
Cell &cell =
|
int idx = i * this->m_cellsDim.y * this->m_cellsDim.z + j * this->m_cellsDim.z + k;
|
||||||
this->m_cells[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.x.push_back(atom.x);
|
||||||
cell.y.push_back(atom.y);
|
cell.y.push_back(atom.y);
|
||||||
@@ -109,6 +110,43 @@ void Space::printCells() const {
|
|||||||
cell.printCell();
|
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 {
|
void Cell::printCell() const {
|
||||||
std::cout << "Cell " << this->m_idx << " (" << this->m_x << ", " << this->m_y << ", " << this->m_z
|
std::cout << "Cell " << this->m_idx << " (" << this->m_x << ", " << this->m_y << ", " << this->m_z
|
||||||
<< "):" << std::endl;
|
<< "):" << std::endl;
|
||||||
|
|||||||
@@ -108,4 +108,22 @@ public:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void printCells() const;
|
void printCells() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Builds a larger cell with neighboring cells of the given index
|
||||||
|
*
|
||||||
|
* @param idx
|
||||||
|
* @return Cell
|
||||||
|
*/
|
||||||
|
Cell getNeighboringCells(int idx) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Builds a larger cell with neighboring cells of the given position
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param z
|
||||||
|
* @return Cell
|
||||||
|
*/
|
||||||
|
Cell getNeighboringCells(int x, int y, int z) const;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user