Author SHA1 Message Date
joshuacoles 40cc47e07a Fix neighbours issue in off-axis walk code 2023-03-14 16:00:31 +00:00
joshuacoles 4649658a9b Add off-axis movement 2023-03-14 15:03:27 +00:00
+39 -34
View File
@@ -109,42 +109,47 @@ void DLASystem::addParticleOnAddCircle() {
cerr << "FAIL " << pos[0] << " " << pos[1] << endl;
}
const static size_t NEIGHBOURS = 26;
// send back the position of a neighbour of a given grid cell
// NOTE: there is no check that the neighbour is inside the grid,
// this has to be done separately...
void DLASystem::setPosNeighbour(double setpos[], double pos[], int val) {
switch (val) {
case 0:
setpos[0] = pos[0] + 1.0;
setpos[1] = pos[1];
setpos[2] = pos[2];
break;
case 1:
setpos[0] = pos[0] - 1.0;
setpos[1] = pos[1];
setpos[2] = pos[2];
break;
case 2:
setpos[0] = pos[0];
setpos[1] = pos[1] + 1.0;
setpos[2] = pos[2];
break;
case 3:
setpos[0] = pos[0];
setpos[1] = pos[1] - 1.0;
setpos[2] = pos[2];
break;
case 4:
setpos[0] = pos[0];
setpos[1] = pos[1];
setpos[2] = pos[2] + 1.0;
break;
case 5:
setpos[0] = pos[0];
setpos[1] = pos[1];
setpos[2] = pos[2] - 1.0;
break;
}
const static double offsets[NEIGHBOURS][3] = {
// These 6 are first to represent the 6 immediate neighbours of the cell when checking sticking
{1, 0, 0},
{-1, 0, 0},
{0, 1, 0},
{0, -1, 0},
{0, 0, 1},
{0, 0, -1},
// The off-axis neighbours
{-1, -1, -1},
{-1, -1, 0},
{-1, -1, 1},
{-1, 0, -1},
{-1, 0, 1},
{-1, 1, -1},
{-1, 1, 0},
{-1, 1, 1},
{0, -1, -1},
{0, -1, 1},
{0, 1, -1},
{0, 1, 1},
{1, -1, -1},
{1, -1, 0},
{1, -1, 1},
{1, 0, -1},
{1, 0, 1},
{1, 1, -1},
{1, 1, 0},
{1, 1, 1}
};
setpos[0] = pos[0] + offsets[val][0];
setpos[1] = pos[1] + offsets[val][1];
setpos[2] = pos[2] + offsets[val][2];
}
// when we add a particle to the cluster, we should update the cluster radius
@@ -170,7 +175,7 @@ void DLASystem::updateClusterRadius(double pos[]) {
// make a random move of the last particle in the particleList
void DLASystem::moveLastParticle() {
int rr = rgen.randomInt(6); // pick a random number in the range 0-3, which direction do we hop?
int rr = rgen.randomInt(NEIGHBOURS); // pick a random number in the range 0-3, which direction do we hop?
double newpos[3];
Particle *lastP = particleList[numParticles - 1];
@@ -227,7 +232,7 @@ DLASystem::DLASystem(const int maxParticles, const string &csvPath, const double
// allocate memory for the grid, remember to free the memory in destructor
grid = new int **[gridSize];
for (int i = 0; i < gridSize; i++) {
grid[i] = new int*[gridSize];
grid[i] = new int *[gridSize];
for (int j = 0; j < gridSize; ++j) {
grid[i][j] = new int[gridSize];