I've the following C++ code that calculate a variable t, the code is dealing with a 2D problem but it was modified to have the output printed in 1D array.
I want to add a line in the code to calculate the #of grid at a specific time or let's the # of grids with respect to time profile. For example: at t=1 or t=<1 we've three grid blocks, at t=<2 we've 5 grid block ,...etc
There are three source codes associated with it, and I'm only attaching part of the main code, the part that needs to be modified, and this part is divided int two parts
//-----your sort function goes here here--------
// Declare size of two dimensional array and initialize.
int nx,ny,nz,nt,i,j,k,initial_zero,index,inf;
cout << endl << "enter nx == " ;
cin>> nx;
for (int ii=0;ii<npixels;ii++){
permx[ii]=1;
permx_orig[ii]=1;
porosity[ii]=1;
porosity_orig[ii]=1;
}
int ii;
T= Final_T;
F=permx;
SourcePoints=source;
/* Pixels which are processed and have a final distance are frozen */
Frozen = new bool[npixels];
for(q=0;q<npixels;q++){Frozen[q]=0; T[q]=-1;}
/*Free memory to store neighbours of the (segmented) region */
neg_free = 1000000;
neg_pos=0;
neg_listx = new double [neg_free];
neg_listy = new double [neg_free];
neg_listz = new double [neg_free];
/* List parameters array */
listprop=new int [3];
/* Make jagged list to store a maximum of 2^64 values */
//listval= (double **)malloc( 64* sizeof(double *) );/// num of rows=64?
listval= new double* [64];
/* Initialize parameter list */
initialize_list(listval, listprop);
neg_listv=listval[listprop[1]-1];
for (s=0; s<num_source*num_source; s++) {
/*starting point */
x= (int)SourcePoints[0+s*3]-1;
y= (int)SourcePoints[1+s*3]-1;
z= (int)SourcePoints[2+s*3]-1;
XYZ_index=mindex3(x, y, z, dims[0], dims[1]);
Frozen[XYZ_index]=1;
T[XYZ_index]=0;
}
for (s=0; s<num_source*num_source; s++) {
/*starting point */
x= (int)SourcePoints[0+s*3]-1;
y= (int)SourcePoints[1+s*3]-1;
z= (int)SourcePoints[2+s*3]-1;
XYZ_index=mindex3(x, y, z, dims[0], dims[1]);
for (w=0; w<6; w++) {
/*Location of neighbour */
i=x+ne[w];
j=y+ne[w+6];
k=z+ne[w+12];
IJK_index=mindex3(i, j, k, dims[0], dims[1]);
/*Check if current neighbour is not yet frozen and inside the */
/*picture */
if(isntfrozen3d(i, j, k, dims, Frozen)) {
Tt=(1/(max(F[IJK_index],eps)));
/*Update distance in neigbour list or add to neigbour list */
if(T[IJK_index]>0) {
if(neg_listv[(int)T[IJK_index]]>Tt) {
listupdate(listval, listprop, (int)T[IJK_index], Tt);
}
}
else {
/*If running out of memory at a new block */
//if(neg_pos>=neg_free) {
// neg_free+=100000;
// neg_listx = (double *)realloc(neg_listx, neg_free*sizeof(double) );
// neg_listy = (double *)realloc(neg_listy, neg_free*sizeof(double) );
// neg_listz = (double *)realloc(neg_listz, neg_free*sizeof(double) );
//}
list_add(listval, listprop, Tt);
neg_listv=listval[listprop[1]-1];
neg_listx[neg_pos]=i;
neg_listy[neg_pos]=j;
neg_listz[neg_pos]=k;
T[IJK_index]=neg_pos;
neg_pos++;
}
}
}
}
/*Loop through all pixels of the image */
for (itt=0; itt<(npixels); itt++) /* */ {
/*Get the pixel from narrow list (boundary list) with smallest */
/*distance value and set it to current pixel location */
index=list_minimum(listval, listprop);
neg_listv=listval[listprop[1]-1];
/* Stop if pixel distance is infinite (all pixels are processed) */
if(IsInf(neg_listv[index])) { break; }
/*index=minarray(neg_listv, neg_pos); */
x=(int)neg_listx[index]; y=(int)neg_listy[index]; z=(int)neg_listz[index];
XYZ_index=mindex3(x, y, z, dims[0], dims[1]);
Frozen[XYZ_index]=1;
T[XYZ_index]=neg_listv[index];
//cout<< T[XYZ_index]<<endl;
//show_list(listval, listprop);
/*Remove min value by replacing it with the last value in the array */
//1- remove the min value and go up in tree by comparing it with its adjacent bothers and parent
//2- remove the last value in the list and again go up in tree
//3- replace the minimum by the last value and again go up in the tree
//- if we have extra tree delete them
list_remove_replace(listval, listprop, index) ;
//show_list(listval, listprop);
neg_listv=listval[listprop[1]-1];
if(index<(neg_pos-1)) {
neg_listx[index]=neg_listx[neg_pos-1];
neg_listy[index]=neg_listy[neg_pos-1];
neg_listz[index]=neg_listz[neg_pos-1];
T[(int)mindex3((int)neg_listx[index], (int)neg_listy[index], (int)neg_listz[index], dims[0], dims[1])]=index;
}
neg_pos =neg_pos-1;
/*Loop through all 6 neighbours of current pixel */
for (w=0;w<6;w++) {
/*Location of neighbour */
i=x+ne[w]; j=y+ne[w+6]; k=z+ne[w+12];
IJK_index=mindex3(i, j, k, dims[0], dims[1]);
/*Check if current neighbour is not yet frozen and inside the */
/*picture */
if(isntfrozen3d(i, j, k, dims, Frozen)) {
//Tt=CalculateDistance(T, F[IJK_index], dims, i, j, k, usesecond, usecross, Frozen);
Tt=CalculateDistance(T, F[IJK_index], dims, i, j, k, Frozen);
/*Update distance in neigbour list or add to neigbour list */
IJK_index=mindex3(i, j, k, dims[0], dims[1]);
if((T[IJK_index]>-1)&&T[IJK_index]<=listprop[0]) {
if(neg_listv[(int)T[IJK_index]]>Tt) {
listupdate(listval, listprop, (int)T[IJK_index], Tt);
}
}
else {
list_add(listval, listprop, Tt);
//show_list(listval, listprop);
neg_listv=listval[listprop[1]-1];
neg_listx[neg_pos]=i; neg_listy[neg_pos]=j; neg_listz[neg_pos]=k;
//==================================================================================
ofstream myfile1;
myfile1.open ("fine-time.txt");
//myfile << "Writing this to a file.\n";
double temp=0;
myfile1 << setw(16) ;
for (int k=1; k<nz+1;k++){
for (int j=1; j<ny+1;j++){
for (int i=1; i<nx+1;i++){
index= (k-1) * nx * ny +(j-1) * (nx) + (i-1) ;
/*if(Final_T[index]==inf){
Final_T[index]=1.;
}*/
myfile1 <<Final_T[index]<< setw(16) ;
// save fine scale time
time_orig[index]= Final_T[index];
//myfile1 <<F[index]<< setw(16) ;
temp=temp+Final_T[index];
> I want to add a line in the code to calculate the #of grid at a specific time
> or let's the # of grids with respect to time profile.
> For example: at t=1 or t=<1 we've three grid blocks, at t=<2 we've 5 grid block ,...etc
You have an array; and the contents of the array are modified at certain points in time.
Now, what does "# of grid" mean? What is a "grid block"?
Let's say we've some results printed in a 5x5 or 200x200 matrix,...etc . I need to sort the numeric results printed in the matrix by dividing the results, which is the variable t, into intervals.
Check the following example:
I run the same code ,that I posted part of it earlier, and I choose a 5x5 system
Here is the results of "t", after imported to matlab:
> So, since it's a 5x5 I did the sorting of the results manually
> I looked at each number of t and count how many times are repeated and record the data
So do the same thing in code now; sort the sequence and make a single pass through it, counting the number of repeats as you move through it.