i need to find a way to load an ArrayFire array from a file, the file have the format: ix iy iz val, where ( ix, iy , iz) are the coordinates in wich the value val has to be. i open the file in the c++ way ( with getline and so ) and parse the line, get correctly the indexes ix, iy ,iz and the value, val
Before i start to iterating the file, i create my array as usual
af::array af_obj(Lx,Ly,Lz, f32);
then when i'm iterating ,i use a line like this to save the values:
af_obj( ix, iy ,iz ) = val
but the array does't save the information correctly, i mean if i do the same with a simple tridimensional array, it holds correct the information.
The information in the file is a buch of 1s and 0s, representing a 3D space where, 1 represent an air region and 0s is a solid material. ( some kind of discretization to represent a sphere, the whole point is, use this array to multiply other array(holding a velocity field) so where is solid the velocity will have a zero value )
I have tried other ways, flatten the data in a 1D array and pass it to the constructor of the array, but in the best case i recover 3 spheres insted of one ( the size of the array are : Lx = 300 , Ly=Lz=100 ) but i'm not able to do what i want. I know for sure the file contain the correct data, i generate this file from other code ( if maybe changing the format of the file could help, tell me, i can modify it)
Thanks for your reading and Answers.
EDIT:
To save the data i use this:
std::ofstream file;
file.open("solidRegion.dat");
for( int iz = 0 ; iz < this->Lz; iz++ ){
for( int iy = 0 ; iy < this->Ly; iy++){
for( int ix = 0 ; ix < this->Lx ; ix++){
file << ix << " " << iy << " " << iz << " " << grid[ix][iy][iz] << "\n";
}}}
file.close();
the 3D array grid, contain the points ( 1s and 0s ) and i know it have the correct data.
And to load the file :
std::string line;
af::array af_obj(Lx,Ly,Lz,f32);
while( std::getline(file_h,line ) ){
std::stringstream linestream(line);
int x,y,z, o;
linestream >> x >> y >> z >> o;
af_obj(x,y,z) = o;
object[x][y][z] = o;
}
the object array is a classic c++ 3D array ( dimensions Lx, Ly , Lz ) and if the data is correctly saved in this array ( object ) but not in the ArrayFire object.... and i don't know why .
Edit 2 :
I try this, using a pointer of 1D memory :
int *h_o;
h_o = new int[Lx*Ly*Lz];
int i = 0;
for ( int k = 0 ; k < Lz ; k++)
for( int ix = 0 ; ix < Lx ; ix++)
for( int j = 0 ; j < Ly ; j++)
{
h_o[i] = object[ix][j][k];
i++;
}
af::array af_obj(Lx, Ly ,Lz , h_o);
Knowing that de 3D object[][][] array, has the correct information !
but the ArrayFire object af_obj not, as i said before the array represent a sphere, in the best case the ArrayFire object show 3 spheres ( no idea why ). The order of the nested fors matters, buy i try all posible combination of xyz and nothing seems to work.