allocating particles in cell

The problem I am having has to do with precision. My programme work when the x and y interval are 0.1 and the cell size is 0.2, but once the values are increase to 0.01 for x and y interval and 0.02 for cell size, the particles pattern in the cell changes, but I want it to remain the same

// Programme for cell partition and population
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <cmath>
#include<chrono>

const double h = 0.1; // The value of h(smoothing lenght)
const double X_coor_interval = 0.1; // The spacing between particles in the X idrection
const double Y_coor_interval = 0.1; // The spacing between particles in the Y idrection
const double p_Xd = 11; // Number of particles in the X direction
const double p_Yd = 11; // Number of particles in the Y direction
const double Actual_Cell_Size_x = 0.2; // The cell size in X direction
const double Actual_Cell_Size_y = 0.2;
const double Tolerence = 0.005;
const double Cell_Size_x = Actual_Cell_Size_x - Tolerence; // The cell size in X direction
const double Cell_Size_y = Actual_Cell_Size_y - Tolerence; // The cell size in Y direction

using namespace std;


struct Cell_Partition
{
double Cell_LowerCoor_x;
double Cell_LowerCoor_y;
double Cell_UpperCoor_x;
double Cell_UpperCoor_y;
int Cell_No;
};

struct particle
{
double p_Xcoor;
double p_Ycoor;
long p_ID;
};

struct Cell_particles
{
int No_Cell_particles;
};
struct Gen_Cell_Neighbour
{
int No_Cells_Ne;
};

int main()
{
//____________________________________________________________________________________________________________________________________________
double boundary = 1.0, location_x = 0, location_y = 0;
double No_Partition_x, No_Partition_y;
int Total_No_Cell;

No_Partition_x = boundary/Actual_Cell_Size_x; //Number of partitions in the X direcion
No_Partition_y = boundary/Actual_Cell_Size_y; // Number of partitions in the Y direcion
Total_No_Cell = ceil(No_Partition_x * No_Partition_y); // To determine the total number of particles in the domain
int X_Num = No_Partition_x + 1;
int Y_Num = No_Partition_y + 1;

cout << X_Num << endl;
cout << Y_Num << endl;
cout << Total_No_Cell << endl;
/*
cout << " Enter Cell_Size_x to be 0.2: " ;
cin >> Cell_Size_x; // input value to interval_x using the keyboard
cout << " Enter Cell_Size_y to be 0.2: " ;
cin >> Cell_Size_y;
*/
//____________________________________________________________________________________________________________________________________________ // input value to interval_y using the keyboard
vector<vector<Cell_Partition>> Cell_Inform; // Vecotr of cell information
Cell_Inform.resize(X_Num); // Vector Cell_Collect to collect the cell infromation
int CID = 0;
for (int i = 0; i < Y_Num; i++)
{
Cell_Inform[i].resize(Y_Num);
}
cout << setprecision(20) << fixed;
for (int i = 0; i < X_Num; i++)
{
for (int j = 0; j < Y_Num; j++)
{
Cell_Inform[i][j].Cell_LowerCoor_x = i*Cell_Size_x;
Cell_Inform[i][j].Cell_LowerCoor_y = j*Cell_Size_y;
Cell_Inform[i][j].Cell_No = CID;
CID++;
}
}

//____________________________________________________________________________________________________________________________________________
/* // To print out the Cell_partitions coordinate positions
for (int i = 0; i < X_Num; i++)
{
for (int j = 0; j < Y_Num; j++)
{
cout << Cell_Inform[i][j].Cell_LowerCoor_x << " , " << Cell_Inform[i][j].Cell_LowerCoor_y << endl;
}
}


*/
//____________________________________________________________________________________________________________________________________________

vector<particle> v_particle; // creat an empty vector
particle a; // creat a varible "a" with particle properties
int ID = 0;
// To automatically set the particles coordinates positions
for (int i = 0; i < p_Xd; i++)
{
for (int j = 0; j < p_Yd; j++)
{
a.p_Xcoor = (i*X_coor_interval); // loop to assign the vector with the particles properties using input from the keyboard to enter values
a.p_Ycoor = (j*Y_coor_interval);
a.p_ID = ID;
v_particle.push_back(a);
ID++;
}

a.p_Ycoor = 0;
}
//____________________________________________________________________________________________________________________________________________
/* // To print out the particles coordinate positions
cout << " To print out the particles coordinate positions " << endl;
cout << endl;
cout << setprecision(20) << fixed;
for (long i = 0; i < v_particle.size(); i++)
{
cout << " particle " << v_particle[i].p_ID << " is at coordinate position " << v_particle[i].p_Xcoor << " , " << v_particle[i].p_Ycoor << endl;

}
*/
//____________________________________________________________________________________________________________________________________________
// To automatically populate the cell and determine the number of particles in each cell
vector<vector<int>> Cell_population;
vector<Cell_particles> v_Cell;
Cell_particles b;
b.No_Cell_particles = 0;
int c = 0;
for (int i = 0; i < X_Num; i++)
{
for (int j = 0; j < Y_Num; j++)
{
Cell_population.push_back(vector<int> ());
for (int k = 0; k < v_particle.size(); k++)
{
if (((v_particle[k].p_Xcoor >= Cell_Inform[i][j].Cell_LowerCoor_x) && (v_particle[k].p_Ycoor >= Cell_Inform[i][j].Cell_LowerCoor_y)) && ((v_particle[k].p_Xcoor < Cell_Inform[i][j].Cell_LowerCoor_x+Cell_Size_x) && (v_particle[k].p_Ycoor < Cell_Inform[i][j].Cell_LowerCoor_y+Cell_Size_y)))
{
b.No_Cell_particles = b.No_Cell_particles + 1;
Cell_population[c].push_back(k);
}
else
{
continue;
}
}
v_Cell.push_back(b);
b.No_Cell_particles = 0;
c = c + 1;
}

}
//____________________________________________________________________________________________________________________________________________
cout << endl;
for (int i = 0; i < X_Num*Y_Num; i++)
{
cout << " Number of particles in Cell " << i << " " << v_Cell[i].No_Cell_particles << endl;
}
//____________________________________________________________________________________________________________________________________________
cout << endl;
// To print out the No_Cell_particles
for (int i = 0; i < X_Num*Y_Num; i++)
{
for (int j = 0; j < v_Cell[i].No_Cell_particles; j++)
{
cout << Cell_population[i][j] << ", " ;
}
cout << endl;
}
//____________________________________________________________________________________________________________________________________________
// To print out the x coordinate of particles using the Cell_population and No_Cell_particles in each v_Cell[i]
cout << endl;
for (int i = 0; i < X_Num*Y_Num; i++)
{

for (int j = 0; j < v_Cell[i].No_Cell_particles; j++)
{
cout << v_particle[Cell_population[i][j]].p_Xcoor << ", " ;
}
cout << endl;
}

//______________________________________________________________________________
Topic archived. No new replies allowed.