//Apply several iterations of a very simple propagation of valid velocity data in all directions void extrapolate(Array3f& grid, Array3c& valid) { Array3f temp_grid = grid; Array3c old_valid(valid.ni,valid.nj,valid.nk); for(int layers = 0; layers < 10; ++layers) { old_valid = valid; for(int k = 1; k < grid.nk-1; ++k) for(int j = 1; j < grid.nj-1; ++j) for(int i = 1; i < grid.ni-1; ++i) { float sum = 0; int count = 0; if(!old_valid(i,j,k)) { if(old_valid(i+1,j,k)) { sum += grid(i+1,j,k); ++count; } if(old_valid(i-1,j,k)) { sum += grid(i-1,j,k); ++count; } if(old_valid(i,j+1,k)) { sum += grid(i,j+1,k); ++count; } if(old_valid(i,j-1,k)) { sum += grid(i,j-1,k); ++count; } if(old_valid(i,j,k+1)) { sum += grid(i,j,k+1); ++count; } if(old_valid(i,j,k-1)) { sum += grid(i,j,k-1); ++count; } //If any of neighbour cells were valid, //assign the cell their average value and tag it as valid if(count > 0) { temp_grid(i,j,k) = sum /(float)count; valid(i,j,k) = 1; } } } grid = temp_grid; } }
//Apply several iterations of a very simple "Jacobi"-style propagation of valid velocity data in all directions void extrapolate(Array2f& grid, const Array2f& grid_weight, Array2c& valid, Array2c old_valid) { //Initialize the list of valid cells for(int j = 0; j < grid.nj; ++j) for(int i = 0; i < grid.ni; ++i) valid(i,j) = grid_weight(i,j) > 0; for(int layers = 0; layers < 5; ++layers) { old_valid = valid; Array2f temp_grid = grid; for(int j = 1; j < grid.nj-1; ++j) for(int i = 1; i < grid.ni-1; ++i) { float sum = 0; int count = 0; if(!old_valid(i,j)) { if(old_valid(i+1,j)) { sum += grid(i+1,j);\ ++count; } if(old_valid(i-1,j)) { sum += grid(i-1,j);\ ++count; } if(old_valid(i,j+1)) { sum += grid(i,j+1);\ ++count; } if(old_valid(i,j-1)) { sum += grid(i,j-1);\ ++count; } //If any of neighbour cells were valid, //assign the cell their average value and tag it as valid if(count > 0) { temp_grid(i,j) = sum /(float)count; valid(i,j) = 1; } } } grid = temp_grid; } }